OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef BASE_TEST_SUITE_H_ | 5 #ifndef BASE_TEST_SUITE_H_ |
6 #define BASE_TEST_SUITE_H_ | 6 #define BASE_TEST_SUITE_H_ |
7 | 7 |
8 // Defines a basic test suite framework for running gtest based tests. You can | 8 // Defines a basic test suite framework for running gtest based tests. You can |
9 // instantiate this class in your main function and call its Run method to run | 9 // instantiate this class in your main function and call its Run method to run |
10 // any gtest based tests that are linked into your executable. | 10 // any gtest based tests that are linked into your executable. |
11 | 11 |
12 #include "base/at_exit.h" | 12 #include "base/at_exit.h" |
13 #include "base/base_paths.h" | 13 #include "base/base_paths.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/debug_on_start.h" | 15 #include "base/debug_on_start.h" |
16 #include "base/file_path.h" | 16 #include "base/file_path.h" |
17 #include "base/icu_util.h" | 17 #include "base/icu_util.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/multiprocess_test.h" | 19 #include "base/multiprocess_test.h" |
20 #include "base/scoped_nsautorelease_pool.h" | 20 #include "base/scoped_nsautorelease_pool.h" |
21 #include "base/time.h" | 21 #include "base/time.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "testing/multiprocess_func_list.h" | 23 #include "testing/multiprocess_func_list.h" |
24 | 24 |
25 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
26 #include <windows.h> | 26 #include <windows.h> |
27 #elif defined(OS_LINUX) | 27 #endif |
| 28 |
| 29 #if defined(OS_POSIX) |
| 30 #include <signal.h> |
| 31 #endif |
| 32 |
| 33 #if defined(OS_LINUX) |
28 #include <gtk/gtk.h> | 34 #include <gtk/gtk.h> |
29 #endif | 35 #endif |
30 | 36 |
31 class TestSuite { | 37 class TestSuite { |
32 public: | 38 public: |
33 TestSuite(int argc, char** argv) { | 39 TestSuite(int argc, char** argv) { |
34 base::EnableTerminationOnHeapCorruption(); | 40 base::EnableTerminationOnHeapCorruption(); |
35 CommandLine::Init(argc, argv); | 41 CommandLine::Init(argc, argv); |
36 testing::InitGoogleTest(&argc, argv); | 42 testing::InitGoogleTest(&argc, argv); |
37 #if defined(OS_LINUX) | 43 #if defined(OS_LINUX) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 PathService::Get(base::FILE_EXE, &exe); | 107 PathService::Get(base::FILE_EXE, &exe); |
102 FilePath log_filename = exe.ReplaceExtension(FILE_PATH_LITERAL("log")); | 108 FilePath log_filename = exe.ReplaceExtension(FILE_PATH_LITERAL("log")); |
103 logging::InitLogging(log_filename.value().c_str(), | 109 logging::InitLogging(log_filename.value().c_str(), |
104 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, | 110 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, |
105 logging::LOCK_LOG_FILE, | 111 logging::LOCK_LOG_FILE, |
106 logging::DELETE_OLD_LOG_FILE); | 112 logging::DELETE_OLD_LOG_FILE); |
107 // We want process and thread IDs because we may have multiple processes. | 113 // We want process and thread IDs because we may have multiple processes. |
108 // Note: temporarily enabled timestamps in an effort to catch bug 6361. | 114 // Note: temporarily enabled timestamps in an effort to catch bug 6361. |
109 logging::SetLogItems(true, true, true, true); | 115 logging::SetLogItems(true, true, true, true); |
110 | 116 |
| 117 #if defined(OS_POSIX) |
| 118 // When running in an application, our code typically expects SIGPIPE |
| 119 // to be ignored. Therefore, when testing that same code, it should run |
| 120 // with SIGPIPE ignored as well. |
| 121 struct sigaction action; |
| 122 action.sa_handler = SIG_IGN; |
| 123 action.sa_flags = 0; |
| 124 sigemptyset(&action.sa_mask); |
| 125 CHECK(sigaction(SIGPIPE, &action, NULL) == 0); |
| 126 #endif // OS_POSIX |
| 127 |
111 #if defined(OS_WIN) | 128 #if defined(OS_WIN) |
112 // For unit tests we turn on the high resolution timer and disable | 129 // For unit tests we turn on the high resolution timer and disable |
113 // base::Time's use of SystemMonitor. Tests create and destroy the message | 130 // base::Time's use of SystemMonitor. Tests create and destroy the message |
114 // loop, which causes a crash with SystemMonitor (http://crbug.com/12187). | 131 // loop, which causes a crash with SystemMonitor (http://crbug.com/12187). |
115 base::Time::EnableHiResClockForTests(); | 132 base::Time::EnableHiResClockForTests(); |
116 | 133 |
117 // In some cases, we do not want to see standard error dialogs. | 134 // In some cases, we do not want to see standard error dialogs. |
118 if (!IsDebuggerPresent() && | 135 if (!IsDebuggerPresent() && |
119 !CommandLine::ForCurrentProcess()->HasSwitch(L"show-error-dialogs")) { | 136 !CommandLine::ForCurrentProcess()->HasSwitch(L"show-error-dialogs")) { |
120 SuppressErrorDialogs(); | 137 SuppressErrorDialogs(); |
(...skipping 10 matching lines...) Expand all Loading... |
131 | 148 |
132 virtual void Shutdown() { | 149 virtual void Shutdown() { |
133 } | 150 } |
134 | 151 |
135 // Make sure that we setup an AtExitManager so Singleton objects will be | 152 // Make sure that we setup an AtExitManager so Singleton objects will be |
136 // destroyed. | 153 // destroyed. |
137 base::AtExitManager at_exit_manager_; | 154 base::AtExitManager at_exit_manager_; |
138 }; | 155 }; |
139 | 156 |
140 #endif // BASE_TEST_SUITE_H_ | 157 #endif // BASE_TEST_SUITE_H_ |
OLD | NEW |