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 "chrome/test/logging/win/test_log_collector.h" | 5 #include "chrome/test/logging/win/test_log_collector.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <ios> | 10 #include <ios> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // printer with a few exceptions; see individual method comments for details. | 47 // printer with a few exceptions; see individual method comments for details. |
48 class EventListener : public testing::TestEventListener { | 48 class EventListener : public testing::TestEventListener { |
49 public: | 49 public: |
50 // Ownership of |default_result_printer| is taken by the new instance. | 50 // Ownership of |default_result_printer| is taken by the new instance. |
51 EventListener(TestLogCollector* test_log_collector, | 51 EventListener(TestLogCollector* test_log_collector, |
52 testing::TestEventListener* default_result_printer); | 52 testing::TestEventListener* default_result_printer); |
53 virtual ~EventListener(); | 53 virtual ~EventListener(); |
54 | 54 |
55 // Sets up the log collector. | 55 // Sets up the log collector. |
56 virtual void OnTestProgramStart( | 56 virtual void OnTestProgramStart( |
57 const testing::UnitTest& unit_test) OVERRIDE { | 57 const testing::UnitTest& unit_test) override { |
58 test_log_collector_->SetUp(); | 58 test_log_collector_->SetUp(); |
59 default_result_printer_->OnTestProgramStart(unit_test); | 59 default_result_printer_->OnTestProgramStart(unit_test); |
60 } | 60 } |
61 | 61 |
62 virtual void OnTestIterationStart(const testing::UnitTest& unit_test, | 62 virtual void OnTestIterationStart(const testing::UnitTest& unit_test, |
63 int iteration) OVERRIDE { | 63 int iteration) override { |
64 default_result_printer_->OnTestIterationStart(unit_test, iteration); | 64 default_result_printer_->OnTestIterationStart(unit_test, iteration); |
65 } | 65 } |
66 | 66 |
67 virtual void OnEnvironmentsSetUpStart( | 67 virtual void OnEnvironmentsSetUpStart( |
68 const testing::UnitTest& unit_test) OVERRIDE { | 68 const testing::UnitTest& unit_test) override { |
69 default_result_printer_->OnEnvironmentsSetUpStart(unit_test); | 69 default_result_printer_->OnEnvironmentsSetUpStart(unit_test); |
70 } | 70 } |
71 | 71 |
72 virtual void OnEnvironmentsSetUpEnd( | 72 virtual void OnEnvironmentsSetUpEnd( |
73 const testing::UnitTest& unit_test) OVERRIDE { | 73 const testing::UnitTest& unit_test) override { |
74 default_result_printer_->OnEnvironmentsSetUpEnd(unit_test); | 74 default_result_printer_->OnEnvironmentsSetUpEnd(unit_test); |
75 } | 75 } |
76 | 76 |
77 virtual void OnTestCaseStart(const testing::TestCase& test_case) OVERRIDE { | 77 virtual void OnTestCaseStart(const testing::TestCase& test_case) override { |
78 default_result_printer_->OnTestCaseStart(test_case); | 78 default_result_printer_->OnTestCaseStart(test_case); |
79 } | 79 } |
80 | 80 |
81 // Calls back to the collector to start collecting logs for this test. | 81 // Calls back to the collector to start collecting logs for this test. |
82 virtual void OnTestStart(const testing::TestInfo& test_info) OVERRIDE { | 82 virtual void OnTestStart(const testing::TestInfo& test_info) override { |
83 default_result_printer_->OnTestStart(test_info); | 83 default_result_printer_->OnTestStart(test_info); |
84 test_log_collector_->StartSessionForTest(test_info); | 84 test_log_collector_->StartSessionForTest(test_info); |
85 } | 85 } |
86 | 86 |
87 // Calls back to the collector with the partial result. If the collector | 87 // Calls back to the collector with the partial result. If the collector |
88 // does not handle it, it is given to the default result printer. | 88 // does not handle it, it is given to the default result printer. |
89 virtual void OnTestPartResult( | 89 virtual void OnTestPartResult( |
90 const testing::TestPartResult& test_part_result) OVERRIDE { | 90 const testing::TestPartResult& test_part_result) override { |
91 if (!test_log_collector_->LogTestPartResult(test_part_result)) | 91 if (!test_log_collector_->LogTestPartResult(test_part_result)) |
92 default_result_printer_->OnTestPartResult(test_part_result); | 92 default_result_printer_->OnTestPartResult(test_part_result); |
93 } | 93 } |
94 | 94 |
95 // Calls back to the collector to handle the collected log for the test that | 95 // Calls back to the collector to handle the collected log for the test that |
96 // has just ended. | 96 // has just ended. |
97 virtual void OnTestEnd(const testing::TestInfo& test_info) OVERRIDE { | 97 virtual void OnTestEnd(const testing::TestInfo& test_info) override { |
98 test_log_collector_->ProcessSessionForTest(test_info); | 98 test_log_collector_->ProcessSessionForTest(test_info); |
99 default_result_printer_->OnTestEnd(test_info); | 99 default_result_printer_->OnTestEnd(test_info); |
100 } | 100 } |
101 | 101 |
102 virtual void OnTestCaseEnd(const testing::TestCase& test_case) OVERRIDE { | 102 virtual void OnTestCaseEnd(const testing::TestCase& test_case) override { |
103 default_result_printer_->OnTestCaseEnd(test_case); | 103 default_result_printer_->OnTestCaseEnd(test_case); |
104 } | 104 } |
105 | 105 |
106 virtual void OnEnvironmentsTearDownStart( | 106 virtual void OnEnvironmentsTearDownStart( |
107 const testing::UnitTest& unit_test) OVERRIDE { | 107 const testing::UnitTest& unit_test) override { |
108 default_result_printer_->OnEnvironmentsTearDownStart(unit_test); | 108 default_result_printer_->OnEnvironmentsTearDownStart(unit_test); |
109 } | 109 } |
110 | 110 |
111 virtual void OnEnvironmentsTearDownEnd( | 111 virtual void OnEnvironmentsTearDownEnd( |
112 const testing::UnitTest& unit_test) OVERRIDE { | 112 const testing::UnitTest& unit_test) override { |
113 default_result_printer_->OnEnvironmentsTearDownEnd(unit_test); | 113 default_result_printer_->OnEnvironmentsTearDownEnd(unit_test); |
114 } | 114 } |
115 | 115 |
116 virtual void OnTestIterationEnd(const testing::UnitTest& unit_test, | 116 virtual void OnTestIterationEnd(const testing::UnitTest& unit_test, |
117 int iteration) OVERRIDE { | 117 int iteration) override { |
118 default_result_printer_->OnTestIterationEnd(unit_test, iteration); | 118 default_result_printer_->OnTestIterationEnd(unit_test, iteration); |
119 } | 119 } |
120 | 120 |
121 // Tears down the log collector. | 121 // Tears down the log collector. |
122 virtual void OnTestProgramEnd(const testing::UnitTest& unit_test) OVERRIDE { | 122 virtual void OnTestProgramEnd(const testing::UnitTest& unit_test) override { |
123 default_result_printer_->OnTestProgramEnd(unit_test); | 123 default_result_printer_->OnTestProgramEnd(unit_test); |
124 test_log_collector_->TearDown(); | 124 test_log_collector_->TearDown(); |
125 } | 125 } |
126 | 126 |
127 private: | 127 private: |
128 TestLogCollector* test_log_collector_; | 128 TestLogCollector* test_log_collector_; |
129 scoped_ptr<testing::TestEventListener> default_result_printer_; | 129 scoped_ptr<testing::TestEventListener> default_result_printer_; |
130 | 130 |
131 DISALLOW_COPY_AND_ASSIGN(EventListener); | 131 DISALLOW_COPY_AND_ASSIGN(EventListener); |
132 }; | 132 }; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 281 |
282 void InstallTestLogCollector(testing::UnitTest* unit_test) { | 282 void InstallTestLogCollector(testing::UnitTest* unit_test) { |
283 // Must be called before running any tests. | 283 // Must be called before running any tests. |
284 DCHECK(unit_test); | 284 DCHECK(unit_test); |
285 DCHECK(!unit_test->current_test_case()); | 285 DCHECK(!unit_test->current_test_case()); |
286 | 286 |
287 g_test_log_collector.Get().Initialize(unit_test); | 287 g_test_log_collector.Get().Initialize(unit_test); |
288 } | 288 } |
289 | 289 |
290 } // namespace logging_win | 290 } // namespace logging_win |
OLD | NEW |