diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 21:44:12 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-21 21:44:12 +0000 |
commit | 1e312119668de456111dbbf3b3a8de29485f8b73 (patch) | |
tree | 4638a0c3b8908bef6953728a3f6ba3648840b220 /base/process_util_unittest.cc | |
parent | 57750f829d2a0f7850a6f2100d8db84624993bb3 (diff) | |
download | chromium_src-1e312119668de456111dbbf3b3a8de29485f8b73.zip chromium_src-1e312119668de456111dbbf3b3a8de29485f8b73.tar.gz chromium_src-1e312119668de456111dbbf3b3a8de29485f8b73.tar.bz2 |
This CL adds a utility method that lets you start a process and block until the process terminates, and retrieve what the process printed to the standard output.
That util function is needed for the new in-process test framework.
It is Windows only for now.
BUG=None
TEST=Covered by new unit test.
Review URL: http://codereview.chromium.org/87008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14135 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_unittest.cc')
-rw-r--r-- | base/process_util_unittest.cc | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index fba7b2b..76b705d 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -1,11 +1,13 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #define _CRT_SECURE_NO_WARNINGS #include "base/command_line.h" +#include "base/file_path.h" #include "base/multiprocess_test.h" +#include "base/path_service.h" #include "base/platform_thread.h" #include "base/process_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -128,6 +130,37 @@ TEST_F(ProcessUtilTest, CalcFreeMemory) { delete[] alloc; delete metrics; } + +TEST_F(ProcessUtilTest, GetAppOutput) { + // Let's create a decently long message. + std::string message; + for (int i = 0; i < 1025; i++) { // 1025 so it does not end on a kilo-byte + // boundary. + message += "Hello!"; + } + + FilePath python_runtime; + ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &python_runtime)); + python_runtime = python_runtime.Append(FILE_PATH_LITERAL("third_party")) + .Append(FILE_PATH_LITERAL("python_24")) + .Append(FILE_PATH_LITERAL("python.exe")); + + // You have to put every parameter between quotes, otherwise this won't work, + // don't ask me why. + std::wstring cmd_line = L"\"" + python_runtime.value() + L"\" " + + L"\"-c\" \"import sys; sys.stdout.write('" + ASCIIToWide(message) + + L"');\""; + std::string output; + ASSERT_TRUE(base::GetAppOutput(cmd_line, &output)); + EXPECT_EQ(message, output); + + // Let's make sure stderr is ignored. + cmd_line = L"\"" + python_runtime.value() + L"\" " + + L"\"-c\" \"import sys; sys.stderr.write('Hello!');\""; + output.clear(); + ASSERT_TRUE(base::GetAppOutput(cmd_line, &output)); + EXPECT_EQ("", output); +} #endif // defined(OS_WIN) #if defined(OS_POSIX) |