Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 } | 62 } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 CommandLine old_command_line_; | 65 CommandLine old_command_line_; |
| 66 | 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); | 67 DISALLOW_COPY_AND_ASSIGN(TestClientInitializer); |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 namespace base { | |
| 73 | |
| 74 class TestWatchAtExitManager : public testing::EmptyTestEventListener { | |
| 75 public: | |
| 76 TestWatchAtExitManager() { } | |
| 77 ~TestWatchAtExitManager() { } | |
| 78 | |
| 79 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { | |
| 80 base::ShadowingAtExitManager at_exit_manager; | |
| 81 initial_top_manager_ = at_exit_manager.next_manager_; | |
| 82 at_exit_stack_size_ = initial_top_manager_->stack_.size(); | |
| 83 } | |
| 84 | |
| 85 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { | |
| 86 base::ShadowingAtExitManager at_exit_manager; | |
| 87 base::AtExitManager* new_top_manager = at_exit_manager.next_manager_; | |
| 88 size_t new_stack_size = new_top_manager->stack_.size(); | |
| 89 | |
| 90 if (initial_top_manager_ != new_top_manager) { | |
| 91 LOG(ERROR) << "AtExitManager: stack changed depth across test " << | |
| 92 test_info.test_case_name() << "." << test_info.name(); | |
| 93 } else if (new_stack_size != at_exit_stack_size_) { | |
| 94 // TODO(scottbyer): clean up all the errors that result from this and | |
| 95 // turn this into a test failure with ADD_FAILURE(). | |
| 96 ADD_FAILURE() << | |
| 97 "AtExitManager: items added to the callback list by " << | |
| 98 test_info.test_case_name() << "." << test_info.name() << | |
| 99 ". Test should be surrounded by a ShadowingAtExitManager."; | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 private: | |
| 104 base::AtExitManager* initial_top_manager_; | |
| 105 size_t at_exit_stack_size_; | |
| 106 | |
| 107 DISALLOW_COPY_AND_ASSIGN(TestWatchAtExitManager); | |
| 108 }; | |
| 109 | |
| 110 } // namespace base | |
| 111 | |
| 72 const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling"; | 112 const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling"; |
| 73 | 113 |
| 74 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { | 114 TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { |
| 75 PreInitialize(argc, argv, true); | 115 PreInitialize(argc, argv, true); |
| 76 } | 116 } |
| 77 | 117 |
| 78 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) | 118 TestSuite::TestSuite(int argc, char** argv, bool create_at_exit_manager) |
| 79 : initialized_command_line_(false) { | 119 : initialized_command_line_(false) { |
| 80 PreInitialize(argc, argv, create_at_exit_manager); | 120 PreInitialize(argc, argv, create_at_exit_manager); |
| 81 } | 121 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 testing::UnitTest::GetInstance()->listeners(); | 203 testing::UnitTest::GetInstance()->listeners(); |
| 164 listeners.Append(new MaybeTestDisabler); | 204 listeners.Append(new MaybeTestDisabler); |
| 165 } | 205 } |
| 166 | 206 |
| 167 void TestSuite::ResetCommandLine() { | 207 void TestSuite::ResetCommandLine() { |
| 168 testing::TestEventListeners& listeners = | 208 testing::TestEventListeners& listeners = |
| 169 testing::UnitTest::GetInstance()->listeners(); | 209 testing::UnitTest::GetInstance()->listeners(); |
| 170 listeners.Append(new TestClientInitializer); | 210 listeners.Append(new TestClientInitializer); |
| 171 } | 211 } |
| 172 | 212 |
| 213 void TestSuite::WatchAtExitManager() { | |
| 214 LOG(INFO) << "Adding watcher for AtExitManager."; | |
|
Paweł Hajdan Jr.
2012/06/20 07:47:13
This shouldn't be needed.
Scott Byer
2012/06/21 00:05:41
Oops. Was doing local diagnostics and left it in.
| |
| 215 testing::TestEventListeners& listeners = | |
| 216 testing::UnitTest::GetInstance()->listeners(); | |
| 217 listeners.Append(new TestWatchAtExitManager); | |
| 218 } | |
| 219 | |
| 173 // Don't add additional code to this method. Instead add it to | 220 // Don't add additional code to this method. Instead add it to |
| 174 // Initialize(). See bug 6436. | 221 // Initialize(). See bug 6436. |
| 175 int TestSuite::Run() { | 222 int TestSuite::Run() { |
| 176 #if defined(OS_MACOSX) | 223 #if defined(OS_MACOSX) |
| 177 base::mac::ScopedNSAutoreleasePool scoped_pool; | 224 base::mac::ScopedNSAutoreleasePool scoped_pool; |
| 178 #endif | 225 #endif |
| 179 | 226 |
| 180 Initialize(); | 227 Initialize(); |
| 181 std::string client_func = | 228 std::string client_func = |
| 182 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 229 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 icu_util::Initialize(); | 332 icu_util::Initialize(); |
| 286 | 333 |
| 287 CatchMaybeTests(); | 334 CatchMaybeTests(); |
| 288 ResetCommandLine(); | 335 ResetCommandLine(); |
| 289 | 336 |
| 290 TestTimeouts::Initialize(); | 337 TestTimeouts::Initialize(); |
| 291 } | 338 } |
| 292 | 339 |
| 293 void TestSuite::Shutdown() { | 340 void TestSuite::Shutdown() { |
| 294 } | 341 } |
| OLD | NEW |