Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(624)

Side by Side Diff: base/test/test_suite.h

Issue 482001: Force failing CHECK/DCHECKs to end the process on Windows.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/cancellation_flag_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 class TestSuite { 52 class TestSuite {
53 public: 53 public:
54 TestSuite(int argc, char** argv) { 54 TestSuite(int argc, char** argv) {
55 base::EnableTerminationOnHeapCorruption(); 55 base::EnableTerminationOnHeapCorruption();
56 CommandLine::Init(argc, argv); 56 CommandLine::Init(argc, argv);
57 testing::InitGoogleTest(&argc, argv); 57 testing::InitGoogleTest(&argc, argv);
58 #if defined(OS_LINUX) 58 #if defined(OS_LINUX)
59 g_thread_init(NULL); 59 g_thread_init(NULL);
60 gtk_init_check(&argc, &argv); 60 gtk_init_check(&argc, &argv);
61 #endif 61 #endif // defined(OS_LINUX)
62 // Don't add additional code to this constructor. Instead add it to 62 // Don't add additional code to this constructor. Instead add it to
63 // Initialize(). See bug 6436. 63 // Initialize(). See bug 6436.
64 } 64 }
65 65
66 virtual ~TestSuite() { 66 virtual ~TestSuite() {
67 CommandLine::Reset(); 67 CommandLine::Reset();
68 } 68 }
69 69
70 // Returns true if a string starts with FLAKY_. 70 // Returns true if a string starts with FLAKY_.
71 static bool IsFlaky(const char* name) { 71 static bool IsFlaky(const char* name) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // objects (such as NotificationService::current()) that Cocoa 139 // objects (such as NotificationService::current()) that Cocoa
140 // objects use to remove themselves as observers. 140 // objects use to remove themselves as observers.
141 scoped_pool.Recycle(); 141 scoped_pool.Recycle();
142 142
143 Shutdown(); 143 Shutdown();
144 144
145 return result; 145 return result;
146 } 146 }
147 147
148 protected: 148 protected:
149 // All fatal log messages (e.g. DCHECK failures) imply unit test failures. 149 #if defined(OS_WIN)
150 // TODO(phajdan.jr): Clean up the windows-specific hacks.
151 // See http://crbug.com/29997
152
153 // By default, base::LogMessage::~LogMessage calls DebugUtil::BreakDebugger()
M-A Ruel 2009/12/10 18:49:35 Thanks for the doc.
154 // when severity is LOG_FATAL. On Windows, this results in error dialogs
155 // which are not friendly to buildbots.
156 // To avoid these problems, we override the LogMessage behaviour by
157 // replacing the assert handler with UnitTestAssertHandler.
150 static void UnitTestAssertHandler(const std::string& str) { 158 static void UnitTestAssertHandler(const std::string& str) {
159 // FAIL is a googletest macro, it marks the current test as failed.
160 // If throw_on_failure is set to true, it also ends the process.
161 ::testing::FLAGS_gtest_throw_on_failure = true;
151 FAIL() << str; 162 FAIL() << str;
152 } 163 }
153 164
154 #if defined(OS_WIN)
155 // Disable crash dialogs so that it doesn't gum up the buildbot 165 // Disable crash dialogs so that it doesn't gum up the buildbot
156 virtual void SuppressErrorDialogs() { 166 virtual void SuppressErrorDialogs() {
157 UINT new_flags = SEM_FAILCRITICALERRORS | 167 UINT new_flags = SEM_FAILCRITICALERRORS |
158 SEM_NOGPFAULTERRORBOX | 168 SEM_NOGPFAULTERRORBOX |
159 SEM_NOOPENFILEERRORBOX; 169 SEM_NOOPENFILEERRORBOX;
160 170
161 // Preserve existing error mode, as discussed at 171 // Preserve existing error mode, as discussed at
162 // http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx 172 // http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx
163 UINT existing_flags = SetErrorMode(new_flags); 173 UINT existing_flags = SetErrorMode(new_flags);
164 SetErrorMode(existing_flags | new_flags); 174 SetErrorMode(existing_flags | new_flags);
165 } 175 }
166 #endif 176 #endif // defined(OS_WIN)
167 177
168 // Override these for custom initialization and shutdown handling. Use these 178 // Override these for custom initialization and shutdown handling. Use these
169 // instead of putting complex code in your constructor/destructor. 179 // instead of putting complex code in your constructor/destructor.
170 180
171 virtual void Initialize() { 181 virtual void Initialize() {
172 // Initialize logging. 182 // Initialize logging.
173 FilePath exe; 183 FilePath exe;
174 PathService::Get(base::FILE_EXE, &exe); 184 PathService::Get(base::FILE_EXE, &exe);
175 FilePath log_filename = exe.ReplaceExtension(FILE_PATH_LITERAL("log")); 185 FilePath log_filename = exe.ReplaceExtension(FILE_PATH_LITERAL("log"));
176 logging::InitLogging(log_filename.value().c_str(), 186 logging::InitLogging(log_filename.value().c_str(),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 223
214 virtual void Shutdown() { 224 virtual void Shutdown() {
215 } 225 }
216 226
217 // Make sure that we setup an AtExitManager so Singleton objects will be 227 // Make sure that we setup an AtExitManager so Singleton objects will be
218 // destroyed. 228 // destroyed.
219 base::AtExitManager at_exit_manager_; 229 base::AtExitManager at_exit_manager_;
220 }; 230 };
221 231
222 #endif // BASE_TEST_SUITE_H_ 232 #endif // BASE_TEST_SUITE_H_
OLDNEW
« no previous file with comments | « base/cancellation_flag_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698