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/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { | 69 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { |
70 *CommandLine::ForCurrentProcess() = old_command_line_; | 70 *CommandLine::ForCurrentProcess() = old_command_line_; |
71 } | 71 } |
72 | 72 |
73 private: | 73 private: |
74 CommandLine old_command_line_; | 74 CommandLine old_command_line_; |
75 | 75 |
76 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); | 76 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); |
77 }; | 77 }; |
78 | 78 |
79 // This class forces the destruction of all Singletons and LazyInstances | |
80 // between tests. Deleting singletons between each test prevents state from | |
81 // being shared amongst tests, which can lead to subtle bugs in tests. | |
82 class SingletonDestructor : public testing::EmptyTestEventListener { | |
83 public: | |
84 SingletonDestructor() {} | |
85 virtual ~SingletonDestructor() {} | |
86 | |
87 // testing::EmptyTestEventListener: | |
88 virtual void OnTestStart( | |
89 const testing::TestInfo& test_info) OVERRIDE { | |
90 at_exit_manager_.reset(new base::ShadowingAtExitManager); | |
91 } | |
92 | |
93 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { | |
94 at_exit_manager_.reset(); | |
95 } | |
96 | |
97 private: | |
98 scoped_ptr<base::ShadowingAtExitManager> at_exit_manager_; | |
99 | |
100 DISALLOW_COPY_AND_ASSIGN(SingletonDestructor); | |
101 }; | |
102 | |
103 } // namespace | 79 } // namespace |
104 | 80 |
105 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { | 81 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { |
106 PreInitialize(argc, argv, true); | 82 PreInitialize(argc, argv, true); |
107 } | 83 } |
108 | 84 |
109 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) | 85 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) |
110 : initialized_command_line_(false) { | 86 : initialized_command_line_(false) { |
111 PreInitialize(argc, argv, create_at_exit_manager); | 87 PreInitialize(argc, argv, create_at_exit_manager); |
112 } | 88 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 SuppressErrorDialogs(); | 245 SuppressErrorDialogs(); |
270 base::debug::SetSuppressDebugUI(true); | 246 base::debug::SetSuppressDebugUI(true); |
271 logging::SetLogAssertHandler(UnitTestAssertHandler); | 247 logging::SetLogAssertHandler(UnitTestAssertHandler); |
272 } | 248 } |
273 | 249 |
274 icu_util::Initialize(); | 250 icu_util::Initialize(); |
275 | 251 |
276 CatchMaybeTests(); | 252 CatchMaybeTests(); |
277 ResetCommandLine(); | 253 ResetCommandLine(); |
278 | 254 |
279 // Add a listener to destroy all Singletons and LazyInstances between each | |
280 // test. See SingletonDestructor for more information. | |
281 testing::TestEventListeners& listeners = | |
282 testing::UnitTest::GetInstance()->listeners(); | |
283 listeners.Append(new SingletonDestructor); | |
284 | |
285 TestTimeouts::Initialize(); | 255 TestTimeouts::Initialize(); |
286 } | 256 } |
287 | 257 |
288 void TestSuite::Shutdown() { | 258 void TestSuite::Shutdown() { |
289 } | 259 } |
OLD | NEW |