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

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

Issue 8947021: Destroy all Singletons and LazyInstances between each test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove override Created 7 years, 7 months 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
OLDNEW
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
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.
Paweł Hajdan Jr. 2013/05/08 16:32:25 nit: Let's add some text here that it helps preven
Robert Sesek 2013/05/08 16:42:11 Done.
81 class SingletonDestructor : public testing::EmptyTestEventListener {
82 public:
83 SingletonDestructor() {}
84 virtual ~SingletonDestructor() {}
85
86 // testing::EmptyTestEventListener:
87 virtual void OnTestStart(
88 const testing::TestInfo& test_info) OVERRIDE {
89 at_exit_manager_.reset(new base::ShadowingAtExitManager);
90 }
91
92 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE {
93 at_exit_manager_.reset();
94 }
95
96 private:
97 scoped_ptr<base::ShadowingAtExitManager> at_exit_manager_;
98
99 DISALLOW_COPY_AND_ASSIGN(SingletonDestructor);
100 };
101
79 } // namespace 102 } // namespace
80 103
81 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { 104 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) {
82 PreInitialize(argc, argv, true); 105 PreInitialize(argc, argv, true);
83 } 106 }
84 107
85 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) 108 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager)
86 : initialized_command_line_(false) { 109 : initialized_command_line_(false) {
87 PreInitialize(argc, argv, create_at_exit_manager); 110 PreInitialize(argc, argv, create_at_exit_manager);
88 } 111 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 SuppressErrorDialogs(); 268 SuppressErrorDialogs();
246 base::debug::SetSuppressDebugUI(true); 269 base::debug::SetSuppressDebugUI(true);
247 logging::SetLogAssertHandler(UnitTestAssertHandler); 270 logging::SetLogAssertHandler(UnitTestAssertHandler);
248 } 271 }
249 272
250 icu_util::Initialize(); 273 icu_util::Initialize();
251 274
252 CatchMaybeTests(); 275 CatchMaybeTests();
253 ResetCommandLine(); 276 ResetCommandLine();
254 277
278 // Add a listener to destroy all Singletons and LazyInstances between each
279 // test.
Paweł Hajdan Jr. 2013/05/08 16:32:25 nit: Also expand this comment. To avoid duplicatio
Robert Sesek 2013/05/08 16:42:11 Done.
280 testing::TestEventListeners& listeners =
281 testing::UnitTest::GetInstance()->listeners();
282 listeners.Append(new SingletonDestructor);
283
255 TestTimeouts::Initialize(); 284 TestTimeouts::Initialize();
256 } 285 }
257 286
258 void TestSuite::Shutdown() { 287 void TestSuite::Shutdown() {
259 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698