Lightmetrica  0.0.1.50dbee3 (yosakoi)
 All Classes Functions Variables Typedefs Enumerations Enumerator
proxylistener.h
1 /*
2  Lightmetrica : A research-oriented renderer
3 
4  Copyright (c) 2014 Hisanari Otsu
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 #ifndef LIB_LIGHTMETRICA_TEST_LIB_PROXY_LISTENER_H
22 #define LIB_LIGHTMETRICA_TEST_LIB_PROXY_LISTENER_H
23 
24 #include "common.h"
25 #include <gtest/gtest.h>
26 #include <lightmetrica/logger.h>
27 
28 LM_NAMESPACE_BEGIN
29 LM_TEST_NAMESPACE_BEGIN
30 
31 class ProxyTestEventListener : public ::testing::TestEventListener
32 {
33 public:
34 
35  ProxyTestEventListener(TestEventListener* listener)
36  : TestEventListener()
37  , listener(listener)
38  {
39 
40  }
41 
42 public:
43 
44  virtual void OnTestProgramStart( const ::testing::UnitTest& unit_test ) { listener->OnTestProgramStart(unit_test); }
45  virtual void OnTestIterationStart( const ::testing::UnitTest& unit_test, int iteration ) { listener->OnTestIterationStart(unit_test, iteration); }
46  virtual void OnEnvironmentsSetUpStart( const ::testing::UnitTest& unit_test ) { /*listener->OnEnvironmentsSetUpStart(unit_test);*/ }
47  virtual void OnEnvironmentsSetUpEnd( const ::testing::UnitTest& unit_test ) { /*listener->OnEnvironmentsSetUpEnd(unit_test);*/ }
48  virtual void OnTestCaseStart( const ::testing::TestCase& test_case ) { /*listener->OnTestCaseStart(test_case);*/ }
49 
50  virtual void OnTestStart( const ::testing::TestInfo& test_info )
51  {
52  // Reset logger
53  Logger::Reset();
57 
58  listener->OnTestStart(test_info);
59  }
60 
61  virtual void OnTestPartResult( const ::testing::TestPartResult& test_part_result )
62  {
63  if (test_part_result.failed())
64  {
65  // Print logs if the test failed
67  }
68  else
69  {
70  // Otherwise clear log entries
71  Logger::Clear();
72  }
73 
74  listener->OnTestPartResult(test_part_result);
75  }
76 
77  virtual void OnTestEnd( const ::testing::TestInfo& test_info )
78  {
79  if (test_info.result()->Failed())
80  {
82  listener->OnTestEnd(test_info);
83  }
84  }
85 
86  virtual void OnTestCaseEnd( const ::testing::TestCase& test_case ) { /*listener->OnTestCaseEnd(test_case);*/ }
87  virtual void OnEnvironmentsTearDownStart( const ::testing::UnitTest& unit_test ) { /*listener->OnEnvironmentsTearDownStart(unit_test);*/ }
88  virtual void OnEnvironmentsTearDownEnd( const ::testing::UnitTest& unit_test ) { /*listener->OnEnvironmentsTearDownEnd(unit_test);*/ }
89  virtual void OnTestIterationEnd( const ::testing::UnitTest& unit_test, int iteration ) { listener->OnTestIterationEnd(unit_test, iteration); }
90  virtual void OnTestProgramEnd( const ::testing::UnitTest& unit_test ) { listener->OnTestProgramEnd(unit_test); }
91 
92 private:
93 
94  TestEventListener* listener;
95 
96 };
97 
98 LM_TEST_NAMESPACE_END
99 LM_NAMESPACE_END
100 
101 #endif // LIB_LIGHTMETRICA_TEST_LIB_PROXY_LISTENER_H
static void Clear()
Definition: logger.cpp:443
static void Reset()
Definition: logger.cpp:437
static void ProcessOutput()
Definition: logger.cpp:413
Output to standard output.
Definition: logger.h:48
static void SetUpdateMode(LogUpdateMode mode)
Definition: logger.cpp:461
static void SetOutputFrequency(int freq)
Definition: logger.cpp:419
Processes the entries in ProcessOutput function.
static void SetOutputMode(int mode)
Definition: logger.cpp:407
Definition: proxylistener.h:31