Chromium Code Reviews| Index: base/test/test_suite.cc |
| diff --git a/base/test/test_suite.cc b/base/test/test_suite.cc |
| index fb0070fc9de11b596c806a965270f6e708a77e4b..ecf4bba1dc053c65d984d8d902c5bc97f4dc67ab 100644 |
| --- a/base/test/test_suite.cc |
| +++ b/base/test/test_suite.cc |
| @@ -69,6 +69,46 @@ class TestClientInitializer : public testing::EmptyTestEventListener { |
| } // namespace |
| +namespace base { |
| + |
| +class TestWatchAtExitManager : public testing::EmptyTestEventListener { |
| + public: |
| + TestWatchAtExitManager() { } |
| + ~TestWatchAtExitManager() { } |
| + |
| + virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { |
| + base::ShadowingAtExitManager at_exit_manager; |
| + initial_top_manager_ = at_exit_manager.next_manager_; |
| + at_exit_stack_size_ = initial_top_manager_->stack_.size(); |
| + } |
| + |
| + virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { |
| + base::ShadowingAtExitManager at_exit_manager; |
| + base::AtExitManager* new_top_manager = at_exit_manager.next_manager_; |
| + size_t new_stack_size = new_top_manager->stack_.size(); |
| + |
| + if (initial_top_manager_ != new_top_manager) { |
| + LOG(ERROR) << "AtExitManager: stack changed depth across test " << |
| + test_info.test_case_name() << "." << test_info.name(); |
| + } else if (new_stack_size != at_exit_stack_size_) { |
| + // TODO(scottbyer): clean up all the errors that result from this and |
| + // turn this into a test failure with ADD_FAILURE(). |
| + ADD_FAILURE() << |
| + "AtExitManager: items added to the callback list by " << |
| + test_info.test_case_name() << "." << test_info.name() << |
| + ". Test should be surrounded by a ShadowingAtExitManager."; |
| + } |
| + } |
| + |
| + private: |
| + base::AtExitManager* initial_top_manager_; |
| + size_t at_exit_stack_size_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestWatchAtExitManager); |
| +}; |
| + |
| +} // namespace base |
| + |
| const char TestSuite::kStrictFailureHandling[] = "strict_failure_handling"; |
| TestSuite::TestSuite(int argc, char** argv) : initialized_command_line_(false) { |
| @@ -170,6 +210,13 @@ void TestSuite::ResetCommandLine() { |
| listeners.Append(new TestClientInitializer); |
| } |
| +void TestSuite::WatchAtExitManager() { |
| + 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.
|
| + testing::TestEventListeners& listeners = |
| + testing::UnitTest::GetInstance()->listeners(); |
| + listeners.Append(new TestWatchAtExitManager); |
| +} |
| + |
| // Don't add additional code to this method. Instead add it to |
| // Initialize(). See bug 6436. |
| int TestSuite::Run() { |