OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/test/test_suite.h" | 5 #include "base/test/test_suite.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 class MaybeTestDisabler : public testing::EmptyTestEventListener { | 40 class MaybeTestDisabler : public testing::EmptyTestEventListener { |
41 public: | 41 public: |
42 virtual void OnTestStart(const testing::TestInfo& test_info) { | 42 virtual void OnTestStart(const testing::TestInfo& test_info) { |
43 ASSERT_FALSE(TestSuite::IsMarkedMaybe(test_info)) | 43 ASSERT_FALSE(TestSuite::IsMarkedMaybe(test_info)) |
44 << "Probably the OS #ifdefs don't include all of the necessary " | 44 << "Probably the OS #ifdefs don't include all of the necessary " |
45 "platforms.\nPlease ensure that no tests have the MAYBE_ prefix " | 45 "platforms.\nPlease ensure that no tests have the MAYBE_ prefix " |
46 "after the code is preprocessed."; | 46 "after the code is preprocessed."; |
47 } | 47 } |
48 }; | 48 }; |
49 | 49 |
| 50 class TestClientInitializer : public testing::EmptyTestEventListener { |
| 51 public: |
| 52 TestClientInitializer() |
| 53 : old_command_line_(CommandLine::NO_PROGRAM) { |
| 54 } |
| 55 |
| 56 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { |
| 57 old_command_line_ = *CommandLine::ForCurrentProcess(); |
| 58 } |
| 59 |
| 60 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { |
| 61 *CommandLine::ForCurrentProcess() = old_command_line_; |
| 62 } |
| 63 |
| 64 private: |
| 65 CommandLine old_command_line_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); |
| 68 }; |
| 69 |
50 } // namespace | 70 } // namespace |
51 | 71 |
52 const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling"; | 72 const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling"; |
53 | 73 |
54 TestSuite::TestSuite(int argc, char** argv) { | 74 TestSuite::TestSuite(int argc, char** argv) { |
55 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
56 testing::GTEST_FLAG(catch_exceptions) = false; | 76 testing::GTEST_FLAG(catch_exceptions) = false; |
57 #endif | 77 #endif |
58 base::EnableTerminationOnHeapCorruption(); | 78 base::EnableTerminationOnHeapCorruption(); |
59 CommandLine::Init(argc, argv); | 79 CommandLine::Init(argc, argv); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 132 |
113 return count; | 133 return count; |
114 } | 134 } |
115 | 135 |
116 void TestSuite::CatchMaybeTests() { | 136 void TestSuite::CatchMaybeTests() { |
117 testing::TestEventListeners& listeners = | 137 testing::TestEventListeners& listeners = |
118 testing::UnitTest::GetInstance()->listeners(); | 138 testing::UnitTest::GetInstance()->listeners(); |
119 listeners.Append(new MaybeTestDisabler); | 139 listeners.Append(new MaybeTestDisabler); |
120 } | 140 } |
121 | 141 |
| 142 void TestSuite::ResetCommandLine() { |
| 143 testing::TestEventListeners& listeners = |
| 144 testing::UnitTest::GetInstance()->listeners(); |
| 145 listeners.Append(new TestClientInitializer); |
| 146 } |
| 147 |
122 // Don't add additional code to this method. Instead add it to | 148 // Don't add additional code to this method. Instead add it to |
123 // Initialize(). See bug 6436. | 149 // Initialize(). See bug 6436. |
124 int TestSuite::Run() { | 150 int TestSuite::Run() { |
125 #if defined(OS_MACOSX) | 151 #if defined(OS_MACOSX) |
126 base::mac::ScopedNSAutoreleasePool scoped_pool; | 152 base::mac::ScopedNSAutoreleasePool scoped_pool; |
127 #endif | 153 #endif |
128 | 154 |
129 Initialize(); | 155 Initialize(); |
130 std::string client_func = | 156 std::string client_func = |
131 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 157 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 logging::SetLogAssertHandler(UnitTestAssertHandler); | 248 logging::SetLogAssertHandler(UnitTestAssertHandler); |
223 } | 249 } |
224 | 250 |
225 #if !defined(OS_ANDROID) | 251 #if !defined(OS_ANDROID) |
226 // TODO(michaelbai): The icu can not be compiled in Android now, this should | 252 // TODO(michaelbai): The icu can not be compiled in Android now, this should |
227 // be enabled once icu is ready. http://b/5406077. | 253 // be enabled once icu is ready. http://b/5406077. |
228 icu_util::Initialize(); | 254 icu_util::Initialize(); |
229 #endif | 255 #endif |
230 | 256 |
231 CatchMaybeTests(); | 257 CatchMaybeTests(); |
| 258 ResetCommandLine(); |
232 | 259 |
233 TestTimeouts::Initialize(); | 260 TestTimeouts::Initialize(); |
234 } | 261 } |
235 | 262 |
236 void TestSuite::Shutdown() { | 263 void TestSuite::Shutdown() { |
237 } | 264 } |
OLD | NEW |