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