| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); |
| 86 return base::LaunchUnitTests( | 86 return base::LaunchUnitTests( |
| 87 argc, argv, Bind(&TestSuite::Run, Unretained(&test_suite))); | 87 argc, argv, Bind(&TestSuite::Run, Unretained(&test_suite))); |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace base | 90 } // namespace base |
| 91 | 91 |
| 92 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { | 92 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { |
| 93 PreInitialize(argc, argv, true); | 93 PreInitialize(true); |
| 94 InitializeFromCommandLine(argc, argv); |
| 94 } | 95 } |
| 95 | 96 |
| 97 #if defined(OS_WIN) |
| 98 TestSuite::TestSuite(int argc, wchar_t** argv) |
| 99 : initialized_command_line_(false) { |
| 100 PreInitialize(true); |
| 101 InitializeFromCommandLine(argc, argv); |
| 102 } |
| 103 #endif // defined(OS_WIN) |
| 104 |
| 96 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) | 105 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) |
| 97 : initialized_command_line_(false) { | 106 : initialized_command_line_(false) { |
| 98 PreInitialize(argc, argv, create_at_exit_manager); | 107 PreInitialize(create_at_exit_manager); |
| 108 InitializeFromCommandLine(argc, argv); |
| 99 } | 109 } |
| 100 | 110 |
| 101 TestSuite::~TestSuite() { | 111 TestSuite::~TestSuite() { |
| 102 if (initialized_command_line_) | 112 if (initialized_command_line_) |
| 103 CommandLine::Reset(); | 113 CommandLine::Reset(); |
| 104 } | 114 } |
| 105 | 115 |
| 106 void TestSuite::PreInitialize(int argc, char** argv, | 116 void TestSuite::InitializeFromCommandLine(int argc, char** argv) { |
| 107 bool create_at_exit_manager) { | 117 initialized_command_line_ = CommandLine::Init(argc, argv); |
| 118 testing::InitGoogleTest(&argc, argv); |
| 119 testing::InitGoogleMock(&argc, argv); |
| 120 |
| 121 #if defined(OS_IOS) |
| 122 InitIOSRunHook(this, argc, argv); |
| 123 #endif |
| 124 } |
| 125 |
| 126 #if defined(OS_WIN) |
| 127 void TestSuite::InitializeFromCommandLine(int argc, wchar_t** argv) { |
| 128 // Windows CommandLine::Init ignores argv anyway. |
| 129 initialized_command_line_ = CommandLine::Init(argc, NULL); |
| 130 testing::InitGoogleTest(&argc, argv); |
| 131 testing::InitGoogleMock(&argc, argv); |
| 132 } |
| 133 #endif // defined(OS_WIN) |
| 134 |
| 135 void TestSuite::PreInitialize(bool create_at_exit_manager) { |
| 108 #if defined(OS_WIN) | 136 #if defined(OS_WIN) |
| 109 testing::GTEST_FLAG(catch_exceptions) = false; | 137 testing::GTEST_FLAG(catch_exceptions) = false; |
| 110 base::TimeTicks::SetNowIsHighResNowIfSupported(); | 138 base::TimeTicks::SetNowIsHighResNowIfSupported(); |
| 111 #endif | 139 #endif |
| 112 base::EnableTerminationOnHeapCorruption(); | 140 base::EnableTerminationOnHeapCorruption(); |
| 113 initialized_command_line_ = CommandLine::Init(argc, argv); | |
| 114 testing::InitGoogleTest(&argc, argv); | |
| 115 testing::InitGoogleMock(&argc, argv); | |
| 116 #if defined(OS_LINUX) && defined(USE_AURA) | 141 #if defined(OS_LINUX) && defined(USE_AURA) |
| 117 // When calling native char conversion functions (e.g wrctomb) we need to | 142 // When calling native char conversion functions (e.g wrctomb) we need to |
| 118 // have the locale set. In the absence of such a call the "C" locale is the | 143 // have the locale set. In the absence of such a call the "C" locale is the |
| 119 // default. In the gtk code (below) gtk_init() implicitly sets a locale. | 144 // default. In the gtk code (below) gtk_init() implicitly sets a locale. |
| 120 setlocale(LC_ALL, ""); | 145 setlocale(LC_ALL, ""); |
| 121 #endif // defined(OS_LINUX) && defined(USE_AURA) | 146 #endif // defined(OS_LINUX) && defined(USE_AURA) |
| 122 | 147 |
| 123 // On Android, AtExitManager is created in | 148 // On Android, AtExitManager is created in |
| 124 // testing/android/native_test_wrapper.cc before main() is called. | 149 // testing/android/native_test_wrapper.cc before main() is called. |
| 125 #if !defined(OS_ANDROID) | 150 #if !defined(OS_ANDROID) |
| 126 if (create_at_exit_manager) | 151 if (create_at_exit_manager) |
| 127 at_exit_manager_.reset(new base::AtExitManager); | 152 at_exit_manager_.reset(new base::AtExitManager); |
| 128 #endif | 153 #endif |
| 129 | 154 |
| 130 #if defined(OS_IOS) | |
| 131 InitIOSRunHook(this, argc, argv); | |
| 132 #endif | |
| 133 | |
| 134 // Don't add additional code to this function. Instead add it to | 155 // Don't add additional code to this function. Instead add it to |
| 135 // Initialize(). See bug 6436. | 156 // Initialize(). See bug 6436. |
| 136 } | 157 } |
| 137 | 158 |
| 138 | 159 |
| 139 // static | 160 // static |
| 140 bool TestSuite::IsMarkedMaybe(const testing::TestInfo& test) { | 161 bool TestSuite::IsMarkedMaybe(const testing::TestInfo& test) { |
| 141 return strncmp(test.name(), "MAYBE_", 6) == 0; | 162 return strncmp(test.name(), "MAYBE_", 6) == 0; |
| 142 } | 163 } |
| 143 | 164 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 ResetCommandLine(); | 328 ResetCommandLine(); |
| 308 #if !defined(OS_IOS) | 329 #if !defined(OS_IOS) |
| 309 AddTestLauncherResultPrinter(); | 330 AddTestLauncherResultPrinter(); |
| 310 #endif // !defined(OS_IOS) | 331 #endif // !defined(OS_IOS) |
| 311 | 332 |
| 312 TestTimeouts::Initialize(); | 333 TestTimeouts::Initialize(); |
| 313 } | 334 } |
| 314 | 335 |
| 315 void TestSuite::Shutdown() { | 336 void TestSuite::Shutdown() { |
| 316 } | 337 } |
| OLD | NEW |