| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "base/process/memory.h" | 26 #include "base/process/memory.h" |
| 27 #include "base/test/gtest_xml_unittest_result_printer.h" | 27 #include "base/test/gtest_xml_unittest_result_printer.h" |
| 28 #include "base/test/gtest_xml_util.h" | 28 #include "base/test/gtest_xml_util.h" |
| 29 #include "base/test/icu_test_util.h" | 29 #include "base/test/icu_test_util.h" |
| 30 #include "base/test/launcher/unit_test_launcher.h" | 30 #include "base/test/launcher/unit_test_launcher.h" |
| 31 #include "base/test/multiprocess_test.h" | 31 #include "base/test/multiprocess_test.h" |
| 32 #include "base/test/test_switches.h" | 32 #include "base/test/test_switches.h" |
| 33 #include "base/test/test_timeouts.h" | 33 #include "base/test/test_timeouts.h" |
| 34 #include "base/time/time.h" | 34 #include "base/time/time.h" |
| 35 #include "build/build_config.h" | 35 #include "build/build_config.h" |
| 36 #include "testing/gmock/include/gmock/gmock.h" | 36 //#include "testing/gmock/include/gmock/gmock.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 38 #include "testing/multiprocess_func_list.h" | 38 #include "testing/multiprocess_func_list.h" |
| 39 | 39 |
| 40 #if defined(OS_MACOSX) | 40 #if defined(OS_MACOSX) |
| 41 #include "base/mac/scoped_nsautorelease_pool.h" | 41 #include "base/mac/scoped_nsautorelease_pool.h" |
| 42 #if defined(OS_IOS) | 42 #if defined(OS_IOS) |
| 43 #include "base/test/test_listener_ios.h" | 43 #include "base/test/test_listener_ios.h" |
| 44 #endif // OS_IOS | 44 #endif // OS_IOS |
| 45 #endif // OS_MACOSX | 45 #endif // OS_MACOSX |
| 46 | 46 |
| 47 #if !defined(OS_WIN) | 47 #if !defined(OS_WIN) |
| 48 #include "base/i18n/rtl.h" | 48 #include "base/i18n/rtl.h" |
| 49 #if !defined(OS_IOS) | 49 #if !defined(OS_IOS) |
| 50 #include "base/strings/string_util.h" | 50 #include "base/strings/string_util.h" |
| 51 #include "third_party/icu/source/common/unicode/uloc.h" | 51 //#include "third_party/icu/source/common/unicode/uloc.h" |
| 52 #endif | 52 #endif |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 #if defined(OS_ANDROID) | 55 #if defined(OS_ANDROID) |
| 56 #include "base/test/test_support_android.h" | 56 #include "base/test/test_support_android.h" |
| 57 #endif | 57 #endif |
| 58 | 58 |
| 59 #if defined(OS_IOS) | 59 #if defined(OS_IOS) |
| 60 #include "base/test/test_support_ios.h" | 60 #include "base/test/test_support_ios.h" |
| 61 #endif | 61 #endif |
| (...skipping 29 matching lines...) Expand all Loading... |
| 91 private: | 91 private: |
| 92 CommandLine old_command_line_; | 92 CommandLine old_command_line_; |
| 93 | 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); | 94 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 std::string GetProfileName() { | 97 std::string GetProfileName() { |
| 98 static const char kDefaultProfileName[] = "test-profile-{pid}"; | 98 static const char kDefaultProfileName[] = "test-profile-{pid}"; |
| 99 CR_DEFINE_STATIC_LOCAL(std::string, profile_name, ()); | 99 CR_DEFINE_STATIC_LOCAL(std::string, profile_name, ()); |
| 100 if (profile_name.empty()) { | 100 if (profile_name.empty()) { |
| 101 const base::CommandLine& command_line = | 101 //const base::CommandLine& command_line = |
| 102 *base::CommandLine::ForCurrentProcess(); | 102 //*base::CommandLine::ForCurrentProcess(); |
| 103 if (command_line.HasSwitch(switches::kProfilingFile)) | 103 //if (command_line.HasSwitch(switches::kProfilingFile)) |
| 104 profile_name = command_line.GetSwitchValueASCII(switches::kProfilingFile); | 104 //profile_name = command_line.GetSwitchValueASCII(switches::kProfilingFile
); |
| 105 else | 105 //else |
| 106 profile_name = std::string(kDefaultProfileName); | 106 profile_name = std::string(kDefaultProfileName); |
| 107 } | 107 } |
| 108 return profile_name; | 108 return profile_name; |
| 109 } | 109 } |
| 110 | 110 |
| 111 } // namespace | 111 } // namespace |
| 112 | 112 |
| 113 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { | 113 int RunUnitTestsUsingBaseTestSuite(int argc, char **argv) { |
| 114 TestSuite test_suite(argc, argv); | 114 TestSuite test_suite(argc, argv); |
| 115 return LaunchUnitTests(argc, argv, | 115 return LaunchUnitTests(argc, argv, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 131 #endif // defined(OS_WIN) | 131 #endif // defined(OS_WIN) |
| 132 | 132 |
| 133 TestSuite::~TestSuite() { | 133 TestSuite::~TestSuite() { |
| 134 if (initialized_command_line_) | 134 if (initialized_command_line_) |
| 135 CommandLine::Reset(); | 135 CommandLine::Reset(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void TestSuite::InitializeFromCommandLine(int argc, char** argv) { | 138 void TestSuite::InitializeFromCommandLine(int argc, char** argv) { |
| 139 initialized_command_line_ = CommandLine::Init(argc, argv); | 139 initialized_command_line_ = CommandLine::Init(argc, argv); |
| 140 testing::InitGoogleTest(&argc, argv); | 140 testing::InitGoogleTest(&argc, argv); |
| 141 testing::InitGoogleMock(&argc, argv); | 141 //testing::InitGoogleMock(&argc, argv); |
| 142 | 142 |
| 143 #if defined(OS_IOS) | 143 #if defined(OS_IOS) |
| 144 InitIOSRunHook(this, argc, argv); | 144 InitIOSRunHook(this, argc, argv); |
| 145 #endif | 145 #endif |
| 146 } | 146 } |
| 147 | 147 |
| 148 #if defined(OS_WIN) | 148 #if defined(OS_WIN) |
| 149 void TestSuite::InitializeFromCommandLine(int argc, wchar_t** argv) { | 149 void TestSuite::InitializeFromCommandLine(int argc, wchar_t** argv) { |
| 150 // Windows CommandLine::Init ignores argv anyway. | 150 // Windows CommandLine::Init ignores argv anyway. |
| 151 initialized_command_line_ = CommandLine::Init(argc, NULL); | 151 initialized_command_line_ = CommandLine::Init(argc, NULL); |
| 152 testing::InitGoogleTest(&argc, argv); | 152 testing::InitGoogleTest(&argc, argv); |
| 153 testing::InitGoogleMock(&argc, argv); | 153 //testing::InitGoogleMock(&argc, argv); |
| 154 } | 154 } |
| 155 #endif // defined(OS_WIN) | 155 #endif // defined(OS_WIN) |
| 156 | 156 |
| 157 void TestSuite::PreInitialize() { | 157 void TestSuite::PreInitialize() { |
| 158 #if defined(OS_WIN) | 158 #if defined(OS_WIN) |
| 159 testing::GTEST_FLAG(catch_exceptions) = false; | 159 testing::GTEST_FLAG(catch_exceptions) = false; |
| 160 #endif | 160 #endif |
| 161 EnableTerminationOnHeapCorruption(); | 161 EnableTerminationOnHeapCorruption(); |
| 162 #if defined(OS_LINUX) && defined(USE_AURA) | 162 #if defined(OS_LINUX) && defined(USE_AURA) |
| 163 // When calling native char conversion functions (e.g wrctomb) we need to | 163 // When calling native char conversion functions (e.g wrctomb) we need to |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 206 |
| 207 // Do not add the result printer if output path already exists. It's an | 207 // Do not add the result printer if output path already exists. It's an |
| 208 // indicator there is a process printing to that file, and we're likely | 208 // indicator there is a process printing to that file, and we're likely |
| 209 // its child. Do not clobber the results in that case. | 209 // its child. Do not clobber the results in that case. |
| 210 if (PathExists(output_path)) { | 210 if (PathExists(output_path)) { |
| 211 LOG(WARNING) << "Test launcher output path " << output_path.AsUTF8Unsafe() | 211 LOG(WARNING) << "Test launcher output path " << output_path.AsUTF8Unsafe() |
| 212 << " exists. Not adding test launcher result printer."; | 212 << " exists. Not adding test launcher result printer."; |
| 213 return; | 213 return; |
| 214 } | 214 } |
| 215 | 215 |
| 216 XmlUnitTestResultPrinter* printer = new XmlUnitTestResultPrinter; | 216 //XmlUnitTestResultPrinter* printer = new XmlUnitTestResultPrinter; |
| 217 CHECK(printer->Initialize(output_path)); | 217 //CHECK(printer->Initialize(output_path)); |
| 218 testing::TestEventListeners& listeners = | 218 //testing::TestEventListeners& listeners = |
| 219 testing::UnitTest::GetInstance()->listeners(); | 219 //testing::UnitTest::GetInstance()->listeners(); |
| 220 listeners.Append(printer); | 220 //listeners.Append(printer); |
| 221 } | 221 } |
| 222 | 222 |
| 223 // Don't add additional code to this method. Instead add it to | 223 // Don't add additional code to this method. Instead add it to |
| 224 // Initialize(). See bug 6436. | 224 // Initialize(). See bug 6436. |
| 225 int TestSuite::Run() { | 225 int TestSuite::Run() { |
| 226 #if defined(OS_IOS) | 226 #if defined(OS_IOS) |
| 227 RunTestsFromIOSApp(); | 227 RunTestsFromIOSApp(); |
| 228 #endif | 228 #endif |
| 229 | 229 |
| 230 #if defined(OS_MACOSX) | 230 #if defined(OS_MACOSX) |
| 231 mac::ScopedNSAutoreleasePool scoped_pool; | 231 mac::ScopedNSAutoreleasePool scoped_pool; |
| 232 #endif | 232 #endif |
| 233 | 233 |
| 234 Initialize(); | 234 Initialize(); |
| 235 std::string client_func = | 235 //std::string client_func = |
| 236 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 236 //CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 237 switches::kTestChildProcess); | 237 //switches::kTestChildProcess); |
| 238 | 238 |
| 239 // Check to see if we are being run as a client process. | 239 // Check to see if we are being run as a client process. |
| 240 if (!client_func.empty()) | 240 //if (!client_func.empty()) |
| 241 return multi_process_function_list::InvokeChildProcessTest(client_func); | 241 //return multi_process_function_list::InvokeChildProcessTest(client_func); |
| 242 #if defined(OS_IOS) | 242 #if defined(OS_IOS) |
| 243 test_listener_ios::RegisterTestEndListener(); | 243 test_listener_ios::RegisterTestEndListener(); |
| 244 #endif | 244 #endif |
| 245 | 245 |
| 246 int result = RUN_ALL_TESTS(); | 246 int result = RUN_ALL_TESTS(); |
| 247 | 247 |
| 248 #if defined(OS_MACOSX) | 248 #if defined(OS_MACOSX) |
| 249 // This MUST happen before Shutdown() since Shutdown() tears down | 249 // This MUST happen before Shutdown() since Shutdown() tears down |
| 250 // objects (such as NotificationService::current()) that Cocoa | 250 // objects (such as NotificationService::current()) that Cocoa |
| 251 // objects use to remove themselves as observers. | 251 // objects use to remove themselves as observers. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 // TODO(hbono): remove this code when gtest has it. | 294 // TODO(hbono): remove this code when gtest has it. |
| 295 // http://groups.google.com/d/topic/googletestframework/OjuwNlXy5ac/discussion | 295 // http://groups.google.com/d/topic/googletestframework/OjuwNlXy5ac/discussion |
| 296 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); | 296 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); |
| 297 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); | 297 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); |
| 298 #endif // defined(_DEBUG) && defined(_HAS_EXCEPTIONS) && (_HAS_EXCEPTIONS == 1) | 298 #endif // defined(_DEBUG) && defined(_HAS_EXCEPTIONS) && (_HAS_EXCEPTIONS == 1) |
| 299 #endif // defined(OS_WIN) | 299 #endif // defined(OS_WIN) |
| 300 } | 300 } |
| 301 | 301 |
| 302 void TestSuite::Initialize() { | 302 void TestSuite::Initialize() { |
| 303 #if !defined(OS_IOS) | 303 #if !defined(OS_IOS) |
| 304 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kWaitForDebugger)) { | 304 //if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kWaitForDebugger))
{ |
| 305 debug::WaitForDebugger(60, true); | 305 //debug::WaitForDebugger(60, true); |
| 306 } | 306 //} |
| 307 #endif | 307 #endif |
| 308 | 308 |
| 309 // Set up a FeatureList instance, so that code using that API will not hit a | 309 // Set up a FeatureList instance, so that code using that API will not hit a |
| 310 // an error that it's not set. If a FeatureList was created in this way (i.e. | 310 // an error that it's not set. If a FeatureList was created in this way (i.e. |
| 311 // one didn't exist previously), it will be cleared in Shutdown() via | 311 // one didn't exist previously), it will be cleared in Shutdown() via |
| 312 // ClearInstanceForTesting(). | 312 // ClearInstanceForTesting(). |
| 313 created_feature_list_ = | 313 created_feature_list_ = |
| 314 FeatureList::InitializeInstance(std::string(), std::string()); | 314 FeatureList::InitializeInstance(std::string(), std::string()); |
| 315 | 315 |
| 316 #if defined(OS_IOS) | 316 #if defined(OS_IOS) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 343 #endif // defined(OS_WIN) | 343 #endif // defined(OS_WIN) |
| 344 | 344 |
| 345 // In some cases, we do not want to see standard error dialogs. | 345 // In some cases, we do not want to see standard error dialogs. |
| 346 if (!debug::BeingDebugged() && | 346 if (!debug::BeingDebugged() && |
| 347 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { | 347 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { |
| 348 SuppressErrorDialogs(); | 348 SuppressErrorDialogs(); |
| 349 debug::SetSuppressDebugUI(true); | 349 debug::SetSuppressDebugUI(true); |
| 350 logging::SetLogAssertHandler(UnitTestAssertHandler); | 350 logging::SetLogAssertHandler(UnitTestAssertHandler); |
| 351 } | 351 } |
| 352 | 352 |
| 353 base::test::InitializeICUForTesting(); | 353 //base::test::InitializeICUForTesting(); |
| 354 | 354 |
| 355 // On the Mac OS X command line, the default locale is *_POSIX. In Chromium, | 355 // On the Mac OS X command line, the default locale is *_POSIX. In Chromium, |
| 356 // the locale is set via an OS X locale API and is never *_POSIX. | 356 // the locale is set via an OS X locale API and is never *_POSIX. |
| 357 // Some tests (such as those involving word break iterator) will behave | 357 // Some tests (such as those involving word break iterator) will behave |
| 358 // differently and fail if we use *POSIX locale. Setting it to en_US here | 358 // differently and fail if we use *POSIX locale. Setting it to en_US here |
| 359 // does not affect tests that explicitly overrides the locale for testing. | 359 // does not affect tests that explicitly overrides the locale for testing. |
| 360 // This can be an issue on all platforms other than Windows. | 360 // This can be an issue on all platforms other than Windows. |
| 361 // TODO(jshin): Should we set the locale via an OS X locale API here? | 361 // TODO(jshin): Should we set the locale via an OS X locale API here? |
| 362 #if !defined(OS_WIN) | 362 #if !defined(OS_WIN) |
| 363 #if defined(OS_IOS) | 363 #if defined(OS_IOS) |
| 364 i18n::SetICUDefaultLocale("en_US"); | 364 //i18n::SetICUDefaultLocale("en_US"); |
| 365 #else | 365 #else |
| 366 std::string default_locale(uloc_getDefault()); | 366 //std::string default_locale(uloc_getDefault()); |
| 367 if (EndsWith(default_locale, "POSIX", CompareCase::INSENSITIVE_ASCII)) | 367 //if (EndsWith(default_locale, "POSIX", CompareCase::INSENSITIVE_ASCII)) |
| 368 i18n::SetICUDefaultLocale("en_US"); | 368 //i18n::SetICUDefaultLocale("en_US"); |
| 369 #endif | 369 #endif |
| 370 #endif | 370 #endif |
| 371 | 371 |
| 372 CatchMaybeTests(); | 372 CatchMaybeTests(); |
| 373 ResetCommandLine(); | 373 ResetCommandLine(); |
| 374 AddTestLauncherResultPrinter(); | 374 AddTestLauncherResultPrinter(); |
| 375 | 375 |
| 376 TestTimeouts::Initialize(); | 376 TestTimeouts::Initialize(); |
| 377 | 377 |
| 378 trace_to_file_.BeginTracingFromCommandLineOptions(); | 378 //trace_to_file_.BeginTracingFromCommandLineOptions(); |
| 379 | 379 |
| 380 base::debug::StartProfiling(GetProfileName()); | 380 base::debug::StartProfiling(GetProfileName()); |
| 381 } | 381 } |
| 382 | 382 |
| 383 void TestSuite::Shutdown() { | 383 void TestSuite::Shutdown() { |
| 384 base::debug::StopProfiling(); | 384 base::debug::StopProfiling(); |
| 385 | 385 |
| 386 // Clear the FeatureList that was created by Initialize(). | 386 // Clear the FeatureList that was created by Initialize(). |
| 387 if (created_feature_list_) | 387 if (created_feature_list_) |
| 388 FeatureList::ClearInstanceForTesting(); | 388 FeatureList::ClearInstanceForTesting(); |
| 389 } | 389 } |
| 390 | 390 |
| 391 } // namespace base | 391 } // namespace base |
| OLD | NEW |