OLD | NEW |
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. |
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/debug_on_start.h" | 14 #include "base/debug_on_start.h" |
15 #include "base/i18n/icu_util.h" | 15 #include "base/i18n/icu_util.h" |
16 #include "base/multiprocess_test.h" | 16 #include "base/multiprocess_test.h" |
17 #include "base/nss_init.h" | 17 #include "base/nss_init.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/process_util.h" | 19 #include "base/process_util.h" |
20 #include "base/scoped_nsautorelease_pool.h" | 20 #include "base/scoped_nsautorelease_pool.h" |
21 #include "base/scoped_ptr.h" | 21 #include "base/scoped_ptr.h" |
22 #include "base/time.h" | 22 #include "base/time.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "testing/multiprocess_func_list.h" | 24 #include "testing/multiprocess_func_list.h" |
25 | 25 |
26 #if defined(OS_LINUX) | 26 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
27 #include <gtk/gtk.h> | 27 #include <gtk/gtk.h> |
28 #endif | 28 #endif |
29 | 29 |
30 // Match function used by the GetTestCount method. | 30 // Match function used by the GetTestCount method. |
31 typedef bool (*TestMatch)(const testing::TestInfo&); | 31 typedef bool (*TestMatch)(const testing::TestInfo&); |
32 | 32 |
33 // By setting up a shadow AtExitManager, this test event listener ensures that | 33 // By setting up a shadow AtExitManager, this test event listener ensures that |
34 // no state is carried between tests (like singletons, lazy instances, etc). | 34 // no state is carried between tests (like singletons, lazy instances, etc). |
35 // Of course it won't help if the code under test corrupts memory. | 35 // Of course it won't help if the code under test corrupts memory. |
36 class TestIsolationEnforcer : public testing::EmptyTestEventListener { | 36 class TestIsolationEnforcer : public testing::EmptyTestEventListener { |
(...skipping 11 matching lines...) Expand all Loading... |
48 private: | 48 private: |
49 scoped_ptr<base::ShadowingAtExitManager> exit_manager_; | 49 scoped_ptr<base::ShadowingAtExitManager> exit_manager_; |
50 }; | 50 }; |
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_POSIX) && !defined(OS_MACOSX) |
59 g_thread_init(NULL); | 59 g_thread_init(NULL); |
60 gtk_init_check(&argc, &argv); | 60 gtk_init_check(&argc, &argv); |
61 #endif // defined(OS_LINUX) | 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 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 #if !defined(PURIFY) | 205 #if !defined(PURIFY) |
206 // When the code in this file moved around, bug 6436 resurfaced. | 206 // When the code in this file moved around, bug 6436 resurfaced. |
207 // As a hack workaround, just #ifdef out this code for Purify builds. | 207 // As a hack workaround, just #ifdef out this code for Purify builds. |
208 logging::SetLogAssertHandler(UnitTestAssertHandler); | 208 logging::SetLogAssertHandler(UnitTestAssertHandler); |
209 #endif // !defined(PURIFY) | 209 #endif // !defined(PURIFY) |
210 } | 210 } |
211 #endif // defined(OS_WIN) | 211 #endif // defined(OS_WIN) |
212 | 212 |
213 icu_util::Initialize(); | 213 icu_util::Initialize(); |
214 | 214 |
215 #if defined(OS_LINUX) | 215 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
216 // Trying to repeatedly initialize and cleanup NSS and NSPR may result in | 216 // Trying to repeatedly initialize and cleanup NSS and NSPR may result in |
217 // a deadlock. Such repeated initialization will happen when using test | 217 // a deadlock. Such repeated initialization will happen when using test |
218 // isolation. Prevent problems by initializing NSS here, so that the cleanup | 218 // isolation. Prevent problems by initializing NSS here, so that the cleanup |
219 // will be done only on process exit. | 219 // will be done only on process exit. |
220 base::EnsureNSSInit(); | 220 base::EnsureNSSInit(); |
221 #endif // defined(OS_LINUX) | 221 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
222 } | 222 } |
223 | 223 |
224 virtual void Shutdown() { | 224 virtual void Shutdown() { |
225 } | 225 } |
226 | 226 |
227 // 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 |
228 // destroyed. | 228 // destroyed. |
229 base::AtExitManager at_exit_manager_; | 229 base::AtExitManager at_exit_manager_; |
230 }; | 230 }; |
231 | 231 |
232 #endif // BASE_TEST_SUITE_H_ | 232 #endif // BASE_TEST_SUITE_H_ |
OLD | NEW |