| 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 #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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 ASSERT_FALSE(TestSuite::IsMarkedMaybe(test_info)) | 53 ASSERT_FALSE(TestSuite::IsMarkedMaybe(test_info)) |
| 54 << "Probably the OS #ifdefs don't include all of the necessary " | 54 << "Probably the OS #ifdefs don't include all of the necessary " |
| 55 "platforms.\nPlease ensure that no tests have the MAYBE_ prefix " | 55 "platforms.\nPlease ensure that no tests have the MAYBE_ prefix " |
| 56 "after the code is preprocessed."; | 56 "after the code is preprocessed."; |
| 57 } | 57 } |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 class TestClientInitializer : public testing::EmptyTestEventListener { | 60 class TestClientInitializer : public testing::EmptyTestEventListener { |
| 61 public: | 61 public: |
| 62 TestClientInitializer() | 62 TestClientInitializer() |
| 63 : old_command_line_(CommandLine::NO_PROGRAM) { | 63 : old_command_line_(base::CommandLine::NO_PROGRAM) { |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual void OnTestStart(const testing::TestInfo& test_info) override { | 66 virtual void OnTestStart(const testing::TestInfo& test_info) override { |
| 67 old_command_line_ = *CommandLine::ForCurrentProcess(); | 67 old_command_line_ = *base::CommandLine::ForCurrentProcess(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual void OnTestEnd(const testing::TestInfo& test_info) override { | 70 virtual void OnTestEnd(const testing::TestInfo& test_info) override { |
| 71 *CommandLine::ForCurrentProcess() = old_command_line_; | 71 *base::CommandLine::ForCurrentProcess() = old_command_line_; |
| 72 } | 72 } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 CommandLine old_command_line_; | 75 base::CommandLine old_command_line_; |
| 76 | 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); | 77 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 } // namespace | 80 } // namespace |
| 81 | 81 |
| 82 namespace base { | 82 namespace base { |
| 83 | 83 |
| 84 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { | 84 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { |
| 85 TestSuite test_suite(argc, argv); | 85 TestSuite test_suite(argc, argv); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 103 #endif // defined(OS_WIN) | 103 #endif // defined(OS_WIN) |
| 104 | 104 |
| 105 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) | 105 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) |
| 106 : initialized_command_line_(false) { | 106 : initialized_command_line_(false) { |
| 107 PreInitialize(create_at_exit_manager); | 107 PreInitialize(create_at_exit_manager); |
| 108 InitializeFromCommandLine(argc, argv); | 108 InitializeFromCommandLine(argc, argv); |
| 109 } | 109 } |
| 110 | 110 |
| 111 TestSuite::~TestSuite() { | 111 TestSuite::~TestSuite() { |
| 112 if (initialized_command_line_) | 112 if (initialized_command_line_) |
| 113 CommandLine::Reset(); | 113 base::CommandLine::Reset(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void TestSuite::InitializeFromCommandLine(int argc, char** argv) { | 116 void TestSuite::InitializeFromCommandLine(int argc, char** argv) { |
| 117 initialized_command_line_ = CommandLine::Init(argc, argv); | 117 initialized_command_line_ = base::CommandLine::Init(argc, argv); |
| 118 testing::InitGoogleTest(&argc, argv); | 118 testing::InitGoogleTest(&argc, argv); |
| 119 testing::InitGoogleMock(&argc, argv); | 119 testing::InitGoogleMock(&argc, argv); |
| 120 | 120 |
| 121 #if defined(OS_IOS) | 121 #if defined(OS_IOS) |
| 122 InitIOSRunHook(this, argc, argv); | 122 InitIOSRunHook(this, argc, argv); |
| 123 #endif | 123 #endif |
| 124 } | 124 } |
| 125 | 125 |
| 126 #if defined(OS_WIN) | 126 #if defined(OS_WIN) |
| 127 void TestSuite::InitializeFromCommandLine(int argc, wchar_t** argv) { | 127 void TestSuite::InitializeFromCommandLine(int argc, wchar_t** argv) { |
| 128 // Windows CommandLine::Init ignores argv anyway. | 128 // Windows CommandLine::Init ignores argv anyway. |
| 129 initialized_command_line_ = CommandLine::Init(argc, NULL); | 129 initialized_command_line_ = base::CommandLine::Init(argc, NULL); |
| 130 testing::InitGoogleTest(&argc, argv); | 130 testing::InitGoogleTest(&argc, argv); |
| 131 testing::InitGoogleMock(&argc, argv); | 131 testing::InitGoogleMock(&argc, argv); |
| 132 } | 132 } |
| 133 #endif // defined(OS_WIN) | 133 #endif // defined(OS_WIN) |
| 134 | 134 |
| 135 void TestSuite::PreInitialize(bool create_at_exit_manager) { | 135 void TestSuite::PreInitialize(bool create_at_exit_manager) { |
| 136 #if defined(OS_WIN) | 136 #if defined(OS_WIN) |
| 137 testing::GTEST_FLAG(catch_exceptions) = false; | 137 testing::GTEST_FLAG(catch_exceptions) = false; |
| 138 #endif | 138 #endif |
| 139 base::EnableTerminationOnHeapCorruption(); | 139 base::EnableTerminationOnHeapCorruption(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 169 | 169 |
| 170 void TestSuite::ResetCommandLine() { | 170 void TestSuite::ResetCommandLine() { |
| 171 testing::TestEventListeners& listeners = | 171 testing::TestEventListeners& listeners = |
| 172 testing::UnitTest::GetInstance()->listeners(); | 172 testing::UnitTest::GetInstance()->listeners(); |
| 173 listeners.Append(new TestClientInitializer); | 173 listeners.Append(new TestClientInitializer); |
| 174 } | 174 } |
| 175 | 175 |
| 176 #if !defined(OS_IOS) | 176 #if !defined(OS_IOS) |
| 177 void TestSuite::AddTestLauncherResultPrinter() { | 177 void TestSuite::AddTestLauncherResultPrinter() { |
| 178 // Only add the custom printer if requested. | 178 // Only add the custom printer if requested. |
| 179 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 179 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 180 switches::kTestLauncherOutput)) { | 180 switches::kTestLauncherOutput)) { |
| 181 return; | 181 return; |
| 182 } | 182 } |
| 183 | 183 |
| 184 FilePath output_path(CommandLine::ForCurrentProcess()->GetSwitchValuePath( | 184 FilePath output_path(base::CommandLine::ForCurrentProcess()-> |
| 185 switches::kTestLauncherOutput)); | 185 GetSwitchValuePath(switches::kTestLauncherOutput)); |
| 186 | 186 |
| 187 // Do not add the result printer if output path already exists. It's an | 187 // Do not add the result printer if output path already exists. It's an |
| 188 // indicator there is a process printing to that file, and we're likely | 188 // indicator there is a process printing to that file, and we're likely |
| 189 // its child. Do not clobber the results in that case. | 189 // its child. Do not clobber the results in that case. |
| 190 if (PathExists(output_path)) { | 190 if (PathExists(output_path)) { |
| 191 LOG(WARNING) << "Test launcher output path " << output_path.AsUTF8Unsafe() | 191 LOG(WARNING) << "Test launcher output path " << output_path.AsUTF8Unsafe() |
| 192 << " exists. Not adding test launcher result printer."; | 192 << " exists. Not adding test launcher result printer."; |
| 193 return; | 193 return; |
| 194 } | 194 } |
| 195 | 195 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 207 #if defined(OS_IOS) | 207 #if defined(OS_IOS) |
| 208 RunTestsFromIOSApp(); | 208 RunTestsFromIOSApp(); |
| 209 #endif | 209 #endif |
| 210 | 210 |
| 211 #if defined(OS_MACOSX) | 211 #if defined(OS_MACOSX) |
| 212 base::mac::ScopedNSAutoreleasePool scoped_pool; | 212 base::mac::ScopedNSAutoreleasePool scoped_pool; |
| 213 #endif | 213 #endif |
| 214 | 214 |
| 215 Initialize(); | 215 Initialize(); |
| 216 std::string client_func = | 216 std::string client_func = |
| 217 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 217 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 218 switches::kTestChildProcess); | 218 switches::kTestChildProcess); |
| 219 | 219 |
| 220 // Check to see if we are being run as a client process. | 220 // Check to see if we are being run as a client process. |
| 221 if (!client_func.empty()) | 221 if (!client_func.empty()) |
| 222 return multi_process_function_list::InvokeChildProcessTest(client_func); | 222 return multi_process_function_list::InvokeChildProcessTest(client_func); |
| 223 #if defined(OS_IOS) | 223 #if defined(OS_IOS) |
| 224 base::test_listener_ios::RegisterTestEndListener(); | 224 base::test_listener_ios::RegisterTestEndListener(); |
| 225 #endif | 225 #endif |
| 226 int result = RUN_ALL_TESTS(); | 226 int result = RUN_ALL_TESTS(); |
| 227 | 227 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 315 |
| 316 CHECK(base::debug::EnableInProcessStackDumping()); | 316 CHECK(base::debug::EnableInProcessStackDumping()); |
| 317 #if defined(OS_WIN) | 317 #if defined(OS_WIN) |
| 318 // Make sure we run with high resolution timer to minimize differences | 318 // Make sure we run with high resolution timer to minimize differences |
| 319 // between production code and test code. | 319 // between production code and test code. |
| 320 base::Time::EnableHighResolutionTimer(true); | 320 base::Time::EnableHighResolutionTimer(true); |
| 321 #endif // defined(OS_WIN) | 321 #endif // defined(OS_WIN) |
| 322 | 322 |
| 323 // In some cases, we do not want to see standard error dialogs. | 323 // In some cases, we do not want to see standard error dialogs. |
| 324 if (!base::debug::BeingDebugged() && | 324 if (!base::debug::BeingDebugged() && |
| 325 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { | 325 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 326 "show-error-dialogs")) { |
| 326 SuppressErrorDialogs(); | 327 SuppressErrorDialogs(); |
| 327 base::debug::SetSuppressDebugUI(true); | 328 base::debug::SetSuppressDebugUI(true); |
| 328 logging::SetLogAssertHandler(UnitTestAssertHandler); | 329 logging::SetLogAssertHandler(UnitTestAssertHandler); |
| 329 } | 330 } |
| 330 | 331 |
| 331 base::i18n::InitializeICU(); | 332 base::i18n::InitializeICU(); |
| 332 | 333 |
| 333 CatchMaybeTests(); | 334 CatchMaybeTests(); |
| 334 ResetCommandLine(); | 335 ResetCommandLine(); |
| 335 #if !defined(OS_IOS) | 336 #if !defined(OS_IOS) |
| 336 AddTestLauncherResultPrinter(); | 337 AddTestLauncherResultPrinter(); |
| 337 #endif // !defined(OS_IOS) | 338 #endif // !defined(OS_IOS) |
| 338 | 339 |
| 339 TestTimeouts::Initialize(); | 340 TestTimeouts::Initialize(); |
| 340 | 341 |
| 341 trace_to_file_.BeginTracingFromCommandLineOptions(); | 342 trace_to_file_.BeginTracingFromCommandLineOptions(); |
| 342 } | 343 } |
| 343 | 344 |
| 344 void TestSuite::Shutdown() { | 345 void TestSuite::Shutdown() { |
| 345 } | 346 } |
| OLD | NEW |