iutest  1.17.99.14
iutest_result.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_RESULT_HPP_D27B1599_F42F_4E2D_B3EB_FACE24C2B921_
16 #define INCG_IRIS_IUTEST_RESULT_HPP_D27B1599_F42F_4E2D_B3EB_FACE24C2B921_
17 
18 //======================================================================
19 // include
20 // IWYU pragma: begin_exports
22 // IWYU pragma: end_exports
23 
24 namespace iutest
25 {
26 
27 //======================================================================
28 // declare
29 namespace detail
30 {
31 
32 class DefaultGlobalTestPartResultReporter;
33 
34 } // end of namespace detail
35 
36 //======================================================================
37 // class
41 class TestPartResultReporterInterface
42 {
43 public:
49  virtual void ReportTestPartResult(const TestPartResult& result) = 0;
50 };
51 
55 class TestPartResult : public detail::iuCodeMessage
56 {
57 public:
61  enum Type
62  {
63  kAssumeFailure = -3,
64  kSkip = -2,
65  kWarning = -1,
69  };
70 public:
78  TestPartResult(const char* file, int line, const char* message, Type type)
79  : detail::iuCodeMessage(file, line, message), m_type(type) {}
80 
81 public:
86  {
87  if( iutest::IUTEST_FLAG(warning_into_error) )
88  {
89  if( type == kWarning )
90  {
91  return true;
92  }
93  }
94  return type > kSuccess;
95  }
96 
97 public:
101  bool failed() const IUTEST_CXX_NOEXCEPT_SPEC { return type_is_failed(m_type); }
105  bool passed() const IUTEST_CXX_NOEXCEPT_SPEC { return !failed(); }
109  bool warning() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type == kWarning; }
113  bool skipped() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type == kSkip; }
117  bool assume_failed() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type == kAssumeFailure; }
121  bool succeeded() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type == kSuccess; }
122 
126  bool nonfatally_failed() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type == kNonFatalFailure; }
127 
131  bool fatally_failed() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type == kFatalFailure; }
132 
136  const char* summary() const { return message(); }
137 
141  Type type() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type; }
142 
143 private:
144  Type m_type;
145 };
146 
148 inline iu_ostream& operator << (iu_ostream& os, const TestPartResult& result)
149 {
150  return os << result.make_message();
151 }
152 
157 class TestProperty
158 {
159 public:
165  TestProperty(const ::std::string& key, const ::std::string& value)
166  : m_key(key), m_value(value) {}
167 
168 public:
172  void SetValue(const ::std::string& value) { m_value = value; }
173  const char* key() const { return m_key.c_str(); }
174  const char* value() const { return m_value.c_str(); }
175 
176 public:
182  bool Validate(const char** ban_list, size_t size) const
183  {
184  return ValidateName(m_key, ban_list, ban_list+size);
185  }
191  template<typename Ite>
192  static bool ValidateName(const ::std::string& name, Ite begin, Ite end)
193  {
194  return ::std::find(begin, end, name) == end;
195  }
196 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
198  template<typename T, size_t N>
199  static bool ValidateName(const ::std::string& name, T (&ar)[N])
200  {
201  return ValidateName(name, ar, ar + N);
202  }
203 #endif
204 
205 private:
206  friend class TestResult;
207  ::std::string m_key;
208  ::std::string m_value;
209 };
210 
214 class TestResult
215 {
216  typedef ::std::vector<TestPartResult> TestPartResults;
217  typedef ::std::vector<TestProperty> TestPropertys;
218 public:
219  TestResult() : m_elapsedmsec(0) {}
220 
221 public:
226  bool Passed() const { return !Failed(); }
231  bool Failed() const
232  {
233  for( TestPartResults::const_iterator it=m_test_part_results.begin()
234  , end=m_test_part_results.end(); it != end; ++it )
235  {
236  if( it->failed() )
237  {
238  return true;
239  }
240  }
241  return false;
242  }
247  bool Skipped() const
248  {
249  for( TestPartResults::const_iterator it=m_test_part_results.begin()
250  , end=m_test_part_results.end(); it != end; ++it )
251  {
252  if( it->skipped() || it->assume_failed() )
253  {
254  return Passed();
255  }
256  }
257  return false;
258  }
259 
264  bool HasFatalFailure() const { return HasResult(TestPartResult::kFatalFailure); }
265 
270  bool HasNonfatalFailure() const { return HasResult(TestPartResult::kNonFatalFailure); }
271 
276  bool HasAssumeFailure() const { return HasResult(TestPartResult::kAssumeFailure); }
277 
282  bool HasWarning() const { return HasResult(TestPartResult::kWarning); }
283 
288  TimeInMillisec elapsed_time() const IUTEST_CXX_NOEXCEPT_SPEC { return m_elapsedmsec; }
289 
294  int total_part_count() const { return static_cast<int>(m_test_part_results.size()); }
295 
300  int test_property_count() const { return static_cast<int>(m_test_propertys.size()); }
301 
307  const TestPartResult& GetTestPartResult(int index) const { return m_test_part_results[index]; }
308 
314  const TestProperty& GetTestProperty(int index) const { return m_test_propertys[index]; }
315 
316 public:
321  int total_error_count() const
322  {
323  int count = 0;
324  for( TestPartResults::const_iterator it=m_test_part_results.begin()
325  , end=m_test_part_results.end(); it != end; ++it )
326  {
327  if( it->failed() )
328  {
329  ++count;
330  }
331  }
332  return count;
333  }
334 
335 private:
336  void AddTestPartResult(const TestPartResult& result) { m_test_part_results.push_back(result); }
337  void set_elapsed_time(TimeInMillisec time) IUTEST_CXX_NOEXCEPT_SPEC { m_elapsedmsec = time; }
338 
339 private:
340  void RecordProperty(const TestProperty& prop)
341  {
342  for( TestPropertys::iterator it=m_test_propertys.begin()
343  , end=m_test_propertys.end(); it != end; ++it )
344  {
345  if( detail::IsStringEqual(it->key(), prop.key()) )
346  {
347  it->m_value = prop.m_value;
348  return;
349  }
350  }
351  m_test_propertys.push_back(prop);
352  }
353 
354  void ClearResult()
355  {
356  m_test_part_results.clear();
357  }
358  void Clear()
359  {
360  m_test_part_results.clear();
361  m_test_propertys.clear();
362  m_elapsedmsec = 0;
363  }
364  bool HasResult(TestPartResult::Type eType) const
365  {
366  for( TestPartResults::const_iterator it=m_test_part_results.begin()
367  , end=m_test_part_results.end(); it != end; ++it )
368  {
369  if( it->type() == eType )
370  {
371  return true;
372  }
373  }
374  return false;
375  }
376 private:
377  friend class UnitTestImpl;
378  friend class TestInfo;
379  friend class TestSuite;
380  friend class detail::DefaultGlobalTestPartResultReporter;
381 
382  TestPartResults m_test_part_results;
383  TestPropertys m_test_propertys;
384  TimeInMillisec m_elapsedmsec;
385 
387 };
388 
389 } // end of namespace iutest
390 
391 #endif // INCG_IRIS_IUTEST_RESULT_HPP_D27B1599_F42F_4E2D_B3EB_FACE24C2B921_
テスト結果を示すクラス
Definition: iutest_result.hpp:57
const char * summary() const
理由
Definition: iutest_result.hpp:137
bool failed() const IUTEST_CXX_NOEXCEPT_SPEC
失敗かどうか
Definition: iutest_result.hpp:102
bool skipped() const IUTEST_CXX_NOEXCEPT_SPEC
スキップかどうか
Definition: iutest_result.hpp:114
Type
結果のタイプ
Definition: iutest_result.hpp:63
@ kNonFatalFailure
致命的ではない失敗
Definition: iutest_result.hpp:68
@ kSkip
スキップ
Definition: iutest_result.hpp:65
@ kAssumeFailure
前提条件エラー
Definition: iutest_result.hpp:64
@ kSuccess
成功
Definition: iutest_result.hpp:67
@ kWarning
警告
Definition: iutest_result.hpp:66
@ kFatalFailure
致命的な失敗
Definition: iutest_result.hpp:69
bool nonfatally_failed() const IUTEST_CXX_NOEXCEPT_SPEC
致命的ではない失敗かどうか
Definition: iutest_result.hpp:127
bool succeeded() const IUTEST_CXX_NOEXCEPT_SPEC
成功かどうか(警告を除く)
Definition: iutest_result.hpp:122
bool fatally_failed() const IUTEST_CXX_NOEXCEPT_SPEC
致命的な失敗かどうか
Definition: iutest_result.hpp:132
bool assume_failed() const IUTEST_CXX_NOEXCEPT_SPEC
前提条件エラーかどうか
Definition: iutest_result.hpp:118
bool passed() const IUTEST_CXX_NOEXCEPT_SPEC
成功かどうか
Definition: iutest_result.hpp:106
TestPartResult(const char *file, int line, const char *message, Type type)
コンストラクタ
Definition: iutest_result.hpp:79
Type type() const IUTEST_CXX_NOEXCEPT_SPEC
結果のタイプ取得
Definition: iutest_result.hpp:142
bool warning() const IUTEST_CXX_NOEXCEPT_SPEC
警告かどうか
Definition: iutest_result.hpp:110
static bool type_is_failed(Type type) IUTEST_CXX_NOEXCEPT_SPEC
失敗かどうか
Definition: iutest_result.hpp:86
テスト結果の通知処理インターフェイス
Definition: iutest_result.hpp:43
virtual void ReportTestPartResult(const TestPartResult &result)=0
テスト結果通知受け取り関数
テストプロパティ
Definition: iutest_result.hpp:159
const char * key() const
キーの取得
Definition: iutest_result.hpp:174
TestProperty(const ::std::string &key, const ::std::string &value)
コンストラクタ
Definition: iutest_result.hpp:166
bool Validate(const char **ban_list, size_t size) const
有効なキーかどうかチェック
Definition: iutest_result.hpp:183
static bool ValidateName(const ::std::string &name, Ite begin, Ite end)
有効なキーかどうかチェック
Definition: iutest_result.hpp:193
void SetValue(const ::std::string &value)
値の設定
Definition: iutest_result.hpp:173
const char * value() const
値の取得
Definition: iutest_result.hpp:175
テスト結果を示すクラス
Definition: iutest_result.hpp:216
bool HasAssumeFailure() const
前提条件エラーがあるかどうか
Definition: iutest_result.hpp:277
int test_property_count() const
プロパティ総数の取得
Definition: iutest_result.hpp:301
TimeInMillisec elapsed_time() const IUTEST_CXX_NOEXCEPT_SPEC
テストの実行時間の取得
Definition: iutest_result.hpp:289
int total_part_count() const
結果の数を取得
Definition: iutest_result.hpp:295
bool Passed() const
成功したかどうか
Definition: iutest_result.hpp:227
const TestProperty & GetTestProperty(int index) const
プロパティの取得
Definition: iutest_result.hpp:315
bool HasWarning() const
警告があるかどうか
Definition: iutest_result.hpp:283
int total_error_count() const
失敗の数を取得
Definition: iutest_result.hpp:322
bool HasFatalFailure() const
致命的なエラーがあるかどうか
Definition: iutest_result.hpp:265
const TestPartResult & GetTestPartResult(int index) const
テスト結果の取得
Definition: iutest_result.hpp:308
bool Failed() const
失敗したかどうか
Definition: iutest_result.hpp:232
bool Skipped() const
スキップしたかどうか
Definition: iutest_result.hpp:248
bool HasNonfatalFailure() const
致命的でないエラーがあるかどうか
Definition: iutest_result.hpp:271
#define IUTEST_FLAG(name)
フラグセット
Definition: iutest_env.hpp:57
#define IUTEST_CXX_NOEXCEPT_SPEC
noexcept specification definition
Definition: iutest_compiler.hpp:811
iris unit test メッセージ ファイル
#define IUTEST_PP_DISALLOW_COPY_AND_ASSIGN(TypeName)
コピー禁止定義
Definition: iutest_pp.hpp:31
iutest root namespace
Definition: iutest_charcode.hpp:33
detail::type_least_t< 8 >::UInt TimeInMillisec
ミリ秒単位を扱う型
Definition: iutest_defs.hpp:526