iutest  1.17.1.0
iutest_result_reporter.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_RESULT_REPORTER_HPP_803FD1F7_1FD2_4D1E_9AFC_A5851284316F_
16 #define INCG_IRIS_IUTEST_RESULT_REPORTER_HPP_803FD1F7_1FD2_4D1E_9AFC_A5851284316F_
17 
18 //======================================================================
19 // include
20 #include "iutest_core_impl.hpp"
21 
22 namespace iutest {
23 namespace detail
24 {
25 
26 //======================================================================
27 // class
31 class DefaultGlobalTestPartResultReporter : public TestPartResultReporterInterface
32 {
33 public:
34  virtual ~DefaultGlobalTestPartResultReporter() IUTEST_CXX_OVERRIDE {}
35  virtual void ReportTestPartResult(const TestPartResult& test_part_result) IUTEST_CXX_OVERRIDE
36  {
37  DefaultReportTestPartResult(test_part_result);
38  }
39  static void DefaultReportTestPartResult(const TestPartResult& test_part_result)
40  {
41  TestResult* result = UnitTestImpl::current_test_result();
42  if( result )
43  {
44  result->AddTestPartResult(test_part_result);
45  }
46  else
47  {
48  iuConsole::output("%s", test_part_result.make_newline_message().c_str());
49  }
50  TestEnv::event_listeners().OnTestPartResult(test_part_result);
51  }
52 };
53 
57 class NoTestPartResultReporter : public TestPartResultReporterInterface
58 {
59 public:
60  virtual ~NoTestPartResultReporter() IUTEST_CXX_OVERRIDE {}
61  virtual void ReportTestPartResult(const TestPartResult& result) IUTEST_CXX_OVERRIDE
62  {
63  IUTEST_UNUSED_VAR(result);
64  }
65 };
66 
70 class NewTestPartResultCheckHelper
71 {
72 public:
73  template<TestPartResult::Type Type>
74  struct CondEq
75  {
76  bool operator ()(const TestPartResult& result)
77  {
78  return result.type() == Type;
79  }
80  };
81 
82  template<TestPartResult::Type Type>
83  struct CondNe
84  {
85  bool operator ()(const TestPartResult& result)
86  {
87  return result.type() != Type;
88  }
89  };
90 
91  template<TestPartResult::Type Type>
92  struct CondGt
93  {
94  bool operator ()(const TestPartResult& result)
95  {
96  return result.type() > Type;
97  }
98  };
99 public:
100  class ReporterHolder
101  {
102  public:
103  ReporterHolder() : m_origin(NULL) {}
104  virtual ~ReporterHolder()
105  {
106  Detach();
107  }
108  void Attach(TestPartResultReporterInterface* p)
109  {
110  m_origin = TestEnv::GetGlobalTestPartResultReporter();
111  TestEnv::SetGlobalTestPartResultReporter(p);
112  }
113  void Detach()
114  {
115  TestEnv::SetGlobalTestPartResultReporter(m_origin);
116  }
117  public:
118  void ReportTestPartResultOrigin(const TestPartResult& result)
119  {
120  if( m_origin )
121  {
122  m_origin->ReportTestPartResult(result);
123  }
124  }
125  private:
126  TestPartResultReporterInterface* m_origin;
127  };
128 
129 public:
130  template<typename COND, typename REPORTER=DefaultGlobalTestPartResultReporter>
131  class Counter : public REPORTER
132  {
133  typedef REPORTER _Mybase;
134  public:
135  Counter() : m_count(0)
136  {
137  m_holder.Attach(this);
138  }
139  virtual void ReportTestPartResult(const TestPartResult& result) IUTEST_CXX_OVERRIDE
140  {
141  if( m_cond(result) )
142  {
143  ++m_count;
144  }
145  _Mybase::ReportTestPartResult(result);
146  }
147  public:
148  int count() const IUTEST_CXX_NOEXCEPT_SPEC { return m_count; }
149  private:
150  ReporterHolder m_holder;
151  COND m_cond;
152  int m_count;
153 
155  };
156  template<typename REPORTER=DefaultGlobalTestPartResultReporter>
157  class Collector : public REPORTER
158  {
159  typedef REPORTER _Mybase;
160  typedef ::std::vector<TestPartResult> TestPartResults;
161  public:
162  Collector()
163  {
164  m_holder.Attach(this);
165  }
166  public:
167  virtual void ReportTestPartResult(const TestPartResult& result) IUTEST_CXX_OVERRIDE
168  {
169  m_results.push_back(result);
170  _Mybase::ReportTestPartResult(result);
171  }
172  public:
173  size_t count() const IUTEST_CXX_NOEXCEPT_SPEC { return m_results.size(); }
174  const TestPartResult& GetTestPartResult(size_t index) const { return m_results[index]; }
175 
176  void ReportTestPartResult()
177  {
178  for( TestPartResults::iterator it=m_results.begin(); it != m_results.end(); ++it )
179  {
180  m_holder.ReportTestPartResultOrigin(*it);
181  }
182  }
183  private:
184  ReporterHolder m_holder;
185  TestPartResults m_results;
186  };
187 };
188 
189 //======================================================================
190 // function
194 inline void DefaultReportTestPartResult(const TestPartResult& test_part_result)
195 {
196  DefaultGlobalTestPartResultReporter::DefaultReportTestPartResult(test_part_result);
197 }
198 
199 } // end of namespace detail
200 } // end of namespace iutest
201 
202 #endif // INCG_IRIS_IUTEST_RESULT_REPORTER_HPP_803FD1F7_1FD2_4D1E_9AFC_A5851284316F_
iutest::TestPartResultReporterInterface::ReportTestPartResult
virtual void ReportTestPartResult(const TestPartResult &result)=0
テスト結果通知受け取り関数
iutest_config.hpp
iris unit test config
IUTEST_CXX_NOEXCEPT_SPEC
#define IUTEST_CXX_NOEXCEPT_SPEC
noexcept specification definition
Definition: iutest_compiler.hpp:734
iutest
iutest root namespace
Definition: iutest_charcode.hpp:31
iutest_core_impl.hpp
iris unit test UnitTest 実装 ファイル
IUTEST_CXX_OVERRIDE
#define IUTEST_CXX_OVERRIDE
override definition
Definition: iutest_compiler.hpp:670
IUTEST_PP_DISALLOW_COPY_AND_ASSIGN
#define IUTEST_PP_DISALLOW_COPY_AND_ASSIGN(TypeName)
コピー禁止定義
Definition: iutest_pp.hpp:25