| 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 |
| 79 } // namespace | 103 } // namespace |
| 80 | 104 |
| 81 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { | 105 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { |
| 82 PreInitialize(argc, argv, true); | 106 PreInitialize(argc, argv, true); |
| 83 } | 107 } |
| 84 | 108 |
| 85 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) | 109 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) |
| 86 : initialized_command_line_(false) { | 110 : initialized_command_line_(false) { |
| 87 PreInitialize(argc, argv, create_at_exit_manager); | 111 PreInitialize(argc, argv, create_at_exit_manager); |
| 88 } | 112 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 SuppressErrorDialogs(); | 268 SuppressErrorDialogs(); |
| 245 base::debug::SetSuppressDebugUI(true); | 269 base::debug::SetSuppressDebugUI(true); |
| 246 logging::SetLogAssertHandler(UnitTestAssertHandler); | 270 logging::SetLogAssertHandler(UnitTestAssertHandler); |
| 247 } | 271 } |
| 248 | 272 |
| 249 icu_util::Initialize(); | 273 icu_util::Initialize(); |
| 250 | 274 |
| 251 CatchMaybeTests(); | 275 CatchMaybeTests(); |
| 252 ResetCommandLine(); | 276 ResetCommandLine(); |
| 253 | 277 |
| 278 // Add a listener to destroy all Singletons and LazyInstances between each |
| 279 // test. See SingletonDestructor for more information. |
| 280 testing::TestEventListeners& listeners = |
| 281 testing::UnitTest::GetInstance()->listeners(); |
| 282 listeners.Append(new SingletonDestructor); |
| 283 |
| 254 TestTimeouts::Initialize(); | 284 TestTimeouts::Initialize(); |
| 255 } | 285 } |
| 256 | 286 |
| 257 void TestSuite::Shutdown() { | 287 void TestSuite::Shutdown() { |
| 258 } | 288 } |
| OLD | NEW |