Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #define _CRT_SECURE_NO_WARNINGS | 5 #define _CRT_SECURE_NO_WARNINGS |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 EXPECT_TRUE(NULL != free_mem2.largest_ptr); | 407 EXPECT_TRUE(NULL != free_mem2.largest_ptr); |
| 408 } | 408 } |
| 409 | 409 |
| 410 TEST_F(ProcessUtilTest, GetAppOutput) { | 410 TEST_F(ProcessUtilTest, GetAppOutput) { |
| 411 // Let's create a decently long message. | 411 // Let's create a decently long message. |
| 412 std::string message; | 412 std::string message; |
| 413 for (int i = 0; i < 1025; i++) { // 1025 so it does not end on a kilo-byte | 413 for (int i = 0; i < 1025; i++) { // 1025 so it does not end on a kilo-byte |
| 414 // boundary. | 414 // boundary. |
| 415 message += "Hello!"; | 415 message += "Hello!"; |
| 416 } | 416 } |
| 417 // cmd.exe's echo always adds a \r\n to its output. | |
| 418 std::string expected(message); | |
| 419 expected += "\r\n"; | |
| 417 | 420 |
| 418 FilePath python_runtime; | 421 FilePath cmd(L"cmd.exe"); |
| 419 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &python_runtime)); | 422 CommandLine cmd_line(cmd); |
| 420 python_runtime = python_runtime.Append(FILE_PATH_LITERAL("third_party")) | 423 cmd_line.AppendArg("/c"); |
| 421 .Append(FILE_PATH_LITERAL("python_26")) | 424 cmd_line.AppendArg("echo " + message + ""); |
| 422 .Append(FILE_PATH_LITERAL("python.exe")); | |
| 423 | |
| 424 CommandLine cmd_line(python_runtime); | |
| 425 cmd_line.AppendArg("-c"); | |
| 426 cmd_line.AppendArg("import sys; sys.stdout.write('" + message + "');"); | |
| 427 std::string output; | 425 std::string output; |
| 428 ASSERT_TRUE(base::GetAppOutput(cmd_line, &output)); | 426 ASSERT_TRUE(base::GetAppOutput(cmd_line, &output)); |
| 429 EXPECT_EQ(message, output); | 427 EXPECT_EQ(expected, output); |
| 430 | 428 |
| 431 // Let's make sure stderr is ignored. | 429 // Let's make sure stderr is ignored. |
| 432 CommandLine other_cmd_line(python_runtime); | 430 CommandLine other_cmd_line(cmd); |
| 433 other_cmd_line.AppendArg("-c"); | 431 other_cmd_line.AppendArg("/c"); |
| 434 other_cmd_line.AppendArg("import sys; sys.stderr.write('Hello!');"); | 432 // http://msdn.microsoft.com/library/cc772622.aspx |
| 433 cmd_line.AppendArg("echo " + message + " >&2"); | |
|
jar (doing other things)
2012/03/07 22:05:35
Although a shell in cygwin or linux can handle thi
| |
| 435 output.clear(); | 434 output.clear(); |
| 436 ASSERT_TRUE(base::GetAppOutput(other_cmd_line, &output)); | 435 ASSERT_TRUE(base::GetAppOutput(other_cmd_line, &output)); |
| 437 EXPECT_EQ("", output); | 436 EXPECT_EQ("", output); |
| 438 } | 437 } |
| 439 | 438 |
| 440 TEST_F(ProcessUtilTest, LaunchAsUser) { | 439 TEST_F(ProcessUtilTest, LaunchAsUser) { |
| 441 base::UserTokenHandle token; | 440 base::UserTokenHandle token; |
| 442 ASSERT_TRUE(OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &token)); | 441 ASSERT_TRUE(OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &token)); |
| 443 std::wstring cmdline = | 442 std::wstring cmdline = |
| 444 this->MakeCmdLine("SimpleChildProcess", false).GetCommandLineString(); | 443 this->MakeCmdLine("SimpleChildProcess", false).GetCommandLineString(); |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1175 SetUpInDeathAssert(); | 1174 SetUpInDeathAssert(); |
| 1176 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} | 1175 while ((value_ = base::AllocatePsychoticallyBigObjCObject())) {} |
| 1177 }, ""); | 1176 }, ""); |
| 1178 } | 1177 } |
| 1179 | 1178 |
| 1180 #endif // !ARCH_CPU_64_BITS | 1179 #endif // !ARCH_CPU_64_BITS |
| 1181 #endif // OS_MACOSX | 1180 #endif // OS_MACOSX |
| 1182 | 1181 |
| 1183 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && | 1182 #endif // !defined(OS_ANDROID) && !defined(OS_OPENBSD) && |
| 1184 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) | 1183 // !defined(OS_WIN) && !defined(ADDRESS_SANITIZER) |
| OLD | NEW |