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 18 matching lines...) Expand all Loading... |
29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "testing/multiprocess_func_list.h" | 30 #include "testing/multiprocess_func_list.h" |
31 | 31 |
32 #if defined(OS_MACOSX) | 32 #if defined(OS_MACOSX) |
33 #include "base/mac/scoped_nsautorelease_pool.h" | 33 #include "base/mac/scoped_nsautorelease_pool.h" |
34 #if defined(OS_IOS) | 34 #if defined(OS_IOS) |
35 #include "base/test/test_listener_ios.h" | 35 #include "base/test/test_listener_ios.h" |
36 #endif // OS_IOS | 36 #endif // OS_IOS |
37 #endif // OS_MACOSX | 37 #endif // OS_MACOSX |
38 | 38 |
39 #if !defined(OS_WIN) | |
40 #include "base/i18n/rtl.h" | 39 #include "base/i18n/rtl.h" |
41 #if !defined(OS_IOS) | 40 #if !defined(OS_IOS) |
42 #include "base/strings/string_util.h" | 41 #include "base/strings/string_util.h" |
43 #include "third_party/icu/source/common/unicode/uloc.h" | 42 #include "third_party/icu/source/common/unicode/uloc.h" |
44 #endif | 43 #endif |
45 #endif | |
46 | 44 |
47 #if defined(OS_ANDROID) | 45 #if defined(OS_ANDROID) |
48 #include "base/test/test_support_android.h" | 46 #include "base/test/test_support_android.h" |
49 #endif | 47 #endif |
50 | 48 |
51 #if defined(OS_IOS) | 49 #if defined(OS_IOS) |
52 #include "base/test/test_support_ios.h" | 50 #include "base/test/test_support_ios.h" |
53 #endif | 51 #endif |
54 | 52 |
55 namespace base { | 53 namespace base { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 TestSuite test_suite(argc, argv); | 90 TestSuite test_suite(argc, argv); |
93 return LaunchUnitTests(argc, argv, | 91 return LaunchUnitTests(argc, argv, |
94 Bind(&TestSuite::Run, Unretained(&test_suite))); | 92 Bind(&TestSuite::Run, Unretained(&test_suite))); |
95 } | 93 } |
96 | 94 |
97 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { | 95 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { |
98 PreInitialize(true); | 96 PreInitialize(true); |
99 InitializeFromCommandLine(argc, argv); | 97 InitializeFromCommandLine(argc, argv); |
100 } | 98 } |
101 | 99 |
102 #if defined(OS_WIN) | |
103 TestSuite::TestSuite(int argc, wchar_t** argv) | |
104 : initialized_command_line_(false) { | |
105 PreInitialize(true); | |
106 InitializeFromCommandLine(argc, argv); | |
107 } | |
108 #endif // defined(OS_WIN) | |
109 | |
110 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) | 100 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) |
111 : initialized_command_line_(false) { | 101 : initialized_command_line_(false) { |
112 PreInitialize(create_at_exit_manager); | 102 PreInitialize(create_at_exit_manager); |
113 InitializeFromCommandLine(argc, argv); | 103 InitializeFromCommandLine(argc, argv); |
114 } | 104 } |
115 | 105 |
116 TestSuite::~TestSuite() { | 106 TestSuite::~TestSuite() { |
117 if (initialized_command_line_) | 107 if (initialized_command_line_) |
118 CommandLine::Reset(); | 108 CommandLine::Reset(); |
119 } | 109 } |
120 | 110 |
121 void TestSuite::InitializeFromCommandLine(int argc, char** argv) { | 111 void TestSuite::InitializeFromCommandLine(int argc, char** argv) { |
122 initialized_command_line_ = CommandLine::Init(argc, argv); | 112 initialized_command_line_ = CommandLine::Init(argc, argv); |
123 testing::InitGoogleTest(&argc, argv); | 113 testing::InitGoogleTest(&argc, argv); |
124 testing::InitGoogleMock(&argc, argv); | 114 testing::InitGoogleMock(&argc, argv); |
125 | 115 |
126 #if defined(OS_IOS) | 116 #if defined(OS_IOS) |
127 InitIOSRunHook(this, argc, argv); | 117 InitIOSRunHook(this, argc, argv); |
128 #endif | 118 #endif |
129 } | 119 } |
130 | 120 |
131 #if defined(OS_WIN) | |
132 void TestSuite::InitializeFromCommandLine(int argc, wchar_t** argv) { | |
133 // Windows CommandLine::Init ignores argv anyway. | |
134 initialized_command_line_ = CommandLine::Init(argc, NULL); | |
135 testing::InitGoogleTest(&argc, argv); | |
136 testing::InitGoogleMock(&argc, argv); | |
137 } | |
138 #endif // defined(OS_WIN) | |
139 | |
140 void TestSuite::PreInitialize(bool create_at_exit_manager) { | 121 void TestSuite::PreInitialize(bool create_at_exit_manager) { |
141 #if defined(OS_WIN) | |
142 testing::GTEST_FLAG(catch_exceptions) = false; | |
143 #endif | |
144 EnableTerminationOnHeapCorruption(); | 122 EnableTerminationOnHeapCorruption(); |
145 #if defined(OS_LINUX) && defined(USE_AURA) | 123 #if defined(OS_LINUX) && defined(USE_AURA) |
146 // When calling native char conversion functions (e.g wrctomb) we need to | 124 // When calling native char conversion functions (e.g wrctomb) we need to |
147 // have the locale set. In the absence of such a call the "C" locale is the | 125 // have the locale set. In the absence of such a call the "C" locale is the |
148 // default. In the gtk code (below) gtk_init() implicitly sets a locale. | 126 // default. In the gtk code (below) gtk_init() implicitly sets a locale. |
149 setlocale(LC_ALL, ""); | 127 setlocale(LC_ALL, ""); |
150 #endif // defined(OS_LINUX) && defined(USE_AURA) | 128 #endif // defined(OS_LINUX) && defined(USE_AURA) |
151 | 129 |
152 // On Android, AtExitManager is created in | 130 // On Android, AtExitManager is created in |
153 // testing/android/native_test_wrapper.cc before main() is called. | 131 // testing/android/native_test_wrapper.cc before main() is called. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 fflush(stderr); | 233 fflush(stderr); |
256 } | 234 } |
257 #endif // defined(OS_ANDROID) | 235 #endif // defined(OS_ANDROID) |
258 | 236 |
259 // The logging system actually prints the message before calling the assert | 237 // The logging system actually prints the message before calling the assert |
260 // handler. Just exit now to avoid printing too many stack traces. | 238 // handler. Just exit now to avoid printing too many stack traces. |
261 _exit(1); | 239 _exit(1); |
262 } | 240 } |
263 | 241 |
264 void TestSuite::SuppressErrorDialogs() { | 242 void TestSuite::SuppressErrorDialogs() { |
265 #if defined(OS_WIN) | |
266 UINT new_flags = SEM_FAILCRITICALERRORS | | |
267 SEM_NOGPFAULTERRORBOX | | |
268 SEM_NOOPENFILEERRORBOX; | |
269 | |
270 // Preserve existing error mode, as discussed at | |
271 // http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx | |
272 UINT existing_flags = SetErrorMode(new_flags); | |
273 SetErrorMode(existing_flags | new_flags); | |
274 | |
275 #if defined(_DEBUG) && defined(_HAS_EXCEPTIONS) && (_HAS_EXCEPTIONS == 1) | |
276 // Suppress the "Debug Assertion Failed" dialog. | |
277 // TODO(hbono): remove this code when gtest has it. | |
278 // http://groups.google.com/d/topic/googletestframework/OjuwNlXy5ac/discussion | |
279 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG); | |
280 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); | |
281 #endif // defined(_DEBUG) && defined(_HAS_EXCEPTIONS) && (_HAS_EXCEPTIONS == 1) | |
282 #endif // defined(OS_WIN) | |
283 } | 243 } |
284 | 244 |
285 void TestSuite::Initialize() { | 245 void TestSuite::Initialize() { |
286 #if !defined(OS_IOS) | 246 #if !defined(OS_IOS) |
287 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kWaitForDebugger)) { | 247 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kWaitForDebugger)) { |
288 debug::WaitForDebugger(60, true); | 248 debug::WaitForDebugger(60, true); |
289 } | 249 } |
290 #endif | 250 #endif |
291 | 251 |
292 #if defined(OS_IOS) | 252 #if defined(OS_IOS) |
(...skipping 11 matching lines...) Expand all Loading... |
304 settings.logging_dest = logging::LOG_TO_ALL; | 264 settings.logging_dest = logging::LOG_TO_ALL; |
305 settings.log_file = log_filename.value().c_str(); | 265 settings.log_file = log_filename.value().c_str(); |
306 settings.delete_old = logging::DELETE_OLD_LOG_FILE; | 266 settings.delete_old = logging::DELETE_OLD_LOG_FILE; |
307 logging::InitLogging(settings); | 267 logging::InitLogging(settings); |
308 // We want process and thread IDs because we may have multiple processes. | 268 // We want process and thread IDs because we may have multiple processes. |
309 // Note: temporarily enabled timestamps in an effort to catch bug 6361. | 269 // Note: temporarily enabled timestamps in an effort to catch bug 6361. |
310 logging::SetLogItems(true, true, true, true); | 270 logging::SetLogItems(true, true, true, true); |
311 #endif // else defined(OS_ANDROID) | 271 #endif // else defined(OS_ANDROID) |
312 | 272 |
313 CHECK(debug::EnableInProcessStackDumping()); | 273 CHECK(debug::EnableInProcessStackDumping()); |
314 #if defined(OS_WIN) | |
315 // Make sure we run with high resolution timer to minimize differences | |
316 // between production code and test code. | |
317 Time::EnableHighResolutionTimer(true); | |
318 #endif // defined(OS_WIN) | |
319 | 274 |
320 // In some cases, we do not want to see standard error dialogs. | 275 // In some cases, we do not want to see standard error dialogs. |
321 if (!debug::BeingDebugged() && | 276 if (!debug::BeingDebugged() && |
322 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { | 277 !CommandLine::ForCurrentProcess()->HasSwitch("show-error-dialogs")) { |
323 SuppressErrorDialogs(); | 278 SuppressErrorDialogs(); |
324 debug::SetSuppressDebugUI(true); | 279 debug::SetSuppressDebugUI(true); |
325 logging::SetLogAssertHandler(UnitTestAssertHandler); | 280 logging::SetLogAssertHandler(UnitTestAssertHandler); |
326 } | 281 } |
327 | 282 |
328 i18n::InitializeICU(); | 283 i18n::InitializeICU(); |
329 // On the Mac OS X command line, the default locale is *_POSIX. In Chromium, | 284 // On the Mac OS X command line, the default locale is *_POSIX. In Chromium, |
330 // the locale is set via an OS X locale API and is never *_POSIX. | 285 // the locale is set via an OS X locale API and is never *_POSIX. |
331 // Some tests (such as those involving word break iterator) will behave | 286 // Some tests (such as those involving word break iterator) will behave |
332 // differently and fail if we use *POSIX locale. Setting it to en_US here | 287 // differently and fail if we use *POSIX locale. Setting it to en_US here |
333 // does not affect tests that explicitly overrides the locale for testing. | 288 // does not affect tests that explicitly overrides the locale for testing. |
334 // This can be an issue on all platforms other than Windows. | 289 // This can be an issue on all platforms other than Windows. |
335 // TODO(jshin): Should we set the locale via an OS X locale API here? | 290 // TODO(jshin): Should we set the locale via an OS X locale API here? |
336 #if !defined(OS_WIN) | |
337 #if defined(OS_IOS) | 291 #if defined(OS_IOS) |
338 i18n::SetICUDefaultLocale("en_US"); | 292 i18n::SetICUDefaultLocale("en_US"); |
339 #else | 293 #else |
340 std::string default_locale(uloc_getDefault()); | 294 std::string default_locale(uloc_getDefault()); |
341 if (EndsWith(default_locale, "POSIX", false)) | 295 if (EndsWith(default_locale, "POSIX", false)) |
342 i18n::SetICUDefaultLocale("en_US"); | 296 i18n::SetICUDefaultLocale("en_US"); |
343 #endif | 297 #endif |
344 #endif | |
345 | 298 |
346 CatchMaybeTests(); | 299 CatchMaybeTests(); |
347 ResetCommandLine(); | 300 ResetCommandLine(); |
348 AddTestLauncherResultPrinter(); | 301 AddTestLauncherResultPrinter(); |
349 | 302 |
350 TestTimeouts::Initialize(); | 303 TestTimeouts::Initialize(); |
351 | 304 |
352 trace_to_file_.BeginTracingFromCommandLineOptions(); | 305 trace_to_file_.BeginTracingFromCommandLineOptions(); |
353 } | 306 } |
354 | 307 |
355 void TestSuite::Shutdown() { | 308 void TestSuite::Shutdown() { |
356 } | 309 } |
357 | 310 |
358 } // namespace base | 311 } // namespace base |
OLD | NEW |