diff options
author | vladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925> | 2011-10-05 05:51:10 +0000 |
---|---|---|
committer | vladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925> | 2011-10-05 05:51:10 +0000 |
commit | e35019652516ad3b4e9bd8c49dbcfca9d443d7e4 (patch) | |
tree | f5bc8a2924ea70d5edf2cfb2bbd39c02bf0c8d68 | |
parent | 5f4d53c8ef453c82f87095711dd072370d496c0b (diff) | |
download | googletest-e35019652516ad3b4e9bd8c49dbcfca9d443d7e4.tar.gz |
Adds ability to inject death test child arguments for test purposes.
git-svn-id: http://googletest.googlecode.com/svn/trunk@599 861a406c-534a-0410-8894-cb66d6ee9925
-rw-r--r-- | include/gtest/internal/gtest-port.h | 11 | ||||
-rw-r--r-- | src/gtest-death-test.cc | 7 | ||||
-rw-r--r-- | src/gtest-port.cc | 18 |
3 files changed, 27 insertions, 9 deletions
diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index 16be48d..f3b7b62 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -177,7 +177,7 @@ // GTEST_FLAG() - references a flag. // GTEST_DECLARE_*() - declares a flag. // GTEST_DEFINE_*() - defines a flag. -// GetArgvs() - returns the command line as a vector of strings. +// GetInjectableArgvs() - returns the command line as a vector of strings. // // Environment variable utilities: // GetEnv() - gets the value of an environment variable. @@ -1069,11 +1069,12 @@ GTEST_API_ String GetCapturedStderr(); #if GTEST_HAS_DEATH_TEST -// A copy of all command line arguments. Set by InitGoogleTest(). -extern ::std::vector<String> g_argvs; +const ::std::vector<testing::internal::string>& GetInjectableArgvs(); +void SetInjectableArgvs(const ::std::vector<testing::internal::string>* + new_argvs); -// GTEST_HAS_DEATH_TEST implies we have ::std::string. -const ::std::vector<String>& GetArgvs(); +// A copy of all command line arguments. Set by InitGoogleTest(). +extern ::std::vector<testing::internal::string> g_argvs; #endif // GTEST_HAS_DEATH_TEST diff --git a/src/gtest-death-test.cc b/src/gtest-death-test.cc index 2f0b0e3..76aa168 100644 --- a/src/gtest-death-test.cc +++ b/src/gtest-death-test.cc @@ -844,6 +844,11 @@ class ExecDeathTest : public ForkingDeathTest { ForkingDeathTest(a_statement, a_regex), file_(file), line_(line) { } virtual TestRole AssumeRole(); private: + static ::std::vector<testing::internal::string> + GetArgvsForDeathTestChildProcess() { + ::std::vector<testing::internal::string> args = GetInjectableArgvs(); + return args; + } // The name of the file in which the death test is located. const char* const file_; // The line number on which the death test is located. @@ -1082,7 +1087,7 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { GTEST_FLAG_PREFIX_, kInternalRunDeathTestFlag, file_, line_, death_test_index, pipe_fd[1]); Arguments args; - args.AddArguments(GetArgvs()); + args.AddArguments(GetArgvsForDeathTestChildProcess()); args.AddArgument(filter_flag.c_str()); args.AddArgument(internal_flag.c_str()); diff --git a/src/gtest-port.cc b/src/gtest-port.cc index 3206914..6e8dca2 100644 --- a/src/gtest-port.cc +++ b/src/gtest-port.cc @@ -653,11 +653,23 @@ String GetCapturedStderr() { return GetCapturedStream(&g_captured_stderr); } #if GTEST_HAS_DEATH_TEST // A copy of all command line arguments. Set by InitGoogleTest(). -::std::vector<String> g_argvs; +::std::vector<testing::internal::string> g_argvs; -// Returns the command line as a vector of strings. -const ::std::vector<String>& GetArgvs() { return g_argvs; } +static const ::std::vector<testing::internal::string>* g_injected_test_argvs = + NULL; // Owned. +void SetInjectableArgvs(const ::std::vector<testing::internal::string>* argvs) { + if (g_injected_test_argvs != argvs) + delete g_injected_test_argvs; + g_injected_test_argvs = argvs; +} + +const ::std::vector<testing::internal::string>& GetInjectableArgvs() { + if (g_injected_test_argvs != NULL) { + return *g_injected_test_argvs; + } + return g_argvs; +} #endif // GTEST_HAS_DEATH_TEST #if GTEST_OS_WINDOWS_MOBILE |