iutest  1.17.1.0
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
21 
22 namespace iutest
23 {
24 
25 //======================================================================
26 // declare
27 namespace detail
28 {
29 
30 class DefaultGlobalTestPartResultReporter;
31 
32 } // end of namespace detail
33 
34 //======================================================================
35 // class
39 class TestPartResultReporterInterface
40 {
41 public:
47  virtual void ReportTestPartResult(const TestPartResult& result) = 0;
48 };
49 
53 class TestPartResult : public detail::iuCodeMessage
54 {
55 public:
59  enum Type
60  {
61  kAssumeFailure = -3,
62  kSkip = -2,
63  kWarning = -1,
67  };
68 public:
76  TestPartResult(const char* file, int line, const char* message, Type type)
77  : detail::iuCodeMessage(file, line, message), m_type(type) {}
78 
79 public:
84  {
85  if( iutest::IUTEST_FLAG(warning_into_error) )
86  {
87  if( type == kWarning )
88  {
89  return true;
90  }
91  }
92  return type > kSuccess;
93  }
94 
95 public:
99  bool failed() const IUTEST_CXX_NOEXCEPT_SPEC { return type_is_failed(m_type);; }
103  bool passed() const IUTEST_CXX_NOEXCEPT_SPEC { return !failed(); }
107  bool warning() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type == kWarning; }
111  bool skipped() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type == kSkip; }
115  bool assume_failed() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type == kAssumeFailure; }
119  bool succeeded() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type == kSuccess; }
120 
124  bool nonfatally_failed() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type == kNonFatalFailure; }
125 
129  bool fatally_failed() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type == kFatalFailure; }
130 
134  const char* summary() const { return message(); }
135 
139  Type type() const IUTEST_CXX_NOEXCEPT_SPEC { return m_type; }
140 
141 private:
142  Type m_type;
143 };
144 
146 inline iu_ostream& operator << (iu_ostream& os, const TestPartResult& result)
147 {
148  return os << result.make_message();
149 }
150 
155 class TestProperty
156 {
157 public:
163  TestProperty(const ::std::string& key, const ::std::string& value)
164  : m_key(key), m_value(value) {}
165 
166 public:
170  void SetValue(const ::std::string& value) { m_value = value; }
171  const char* key() const { return m_key.c_str(); }
172  const char* value() const { return m_value.c_str(); }
173 
174 public:
180  bool Validate(const char** ban_list, size_t size) const
181  {
182  return ValidateName(m_key, ban_list, ban_list+size);
183  }
189  template<typename Ite>
190  static bool ValidateName(const ::std::string& name, Ite begin, Ite end)
191  {
192  return ::std::find(begin, end, name) == end;
193  }
194 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
195 
196  template<typename T, size_t N>
197  static bool ValidateName(const ::std::string& name, T (&ar)[N])
198  {
199  return ValidateName(name, ar, ar + N);
200  }
201 #endif
202 
203 private:
204  friend class TestResult;
205  ::std::string m_key;
206  ::std::string m_value;
207 };
208 
212 class TestResult
213 {
214  typedef ::std::vector<TestPartResult> TestPartResults;
215  typedef ::std::vector<TestProperty> TestPropertys;
216 public:
217  TestResult() : m_elapsedmsec(0) {}
218 
219 public:
224  bool Passed() const { return !Failed(); }
229  bool Failed() const
230  {
231  for( TestPartResults::const_iterator it=m_test_part_results.begin()
232  , end=m_test_part_results.end(); it != end; ++it )
233  {
234  if( it->failed() )
235  {
236  return true;
237  }
238  }
239  return false;
240  }
245  bool Skipped() const
246  {
247  for( TestPartResults::const_iterator it=m_test_part_results.begin()
248  , end=m_test_part_results.end(); it != end; ++it )
249  {
250  if( it->skipped() || it->assume_failed() )
251  {
252  return Passed();
253  }
254  }
255  return false;
256  }
257 
262  bool HasFatalFailure() const { return HasResult(TestPartResult::kFatalFailure); }
263 
268  bool HasNonfatalFailure() const { return HasResult(TestPartResult::kNonFatalFailure); }
269 
274  bool HasAssumeFailure() const { return HasResult(TestPartResult::kAssumeFailure); }
275 
280  bool HasWarning() const { return HasResult(TestPartResult::kWarning); }
281 
286  TimeInMillisec elapsed_time() const IUTEST_CXX_NOEXCEPT_SPEC { return m_elapsedmsec; }
287 
292  int total_part_count() const { return static_cast<int>(m_test_part_results.size()); }
293 
298  int test_property_count() const { return static_cast<int>(m_test_propertys.size()); }
299 
305  const TestPartResult& GetTestPartResult(int index) const { return m_test_part_results[index]; }
306 
312  const TestProperty& GetTestProperty(int index) const { return m_test_propertys[index]; }
313 
314 public:
319  int total_error_count() const
320  {
321  int count = 0;
322  for( TestPartResults::const_iterator it=m_test_part_results.begin()
323  , end=m_test_part_results.end(); it != end; ++it )
324  {
325  if( it->failed() )
326  {
327  ++count;
328  }
329  }
330  return count;
331  }
332 
333 private:
334  void AddTestPartResult(const TestPartResult& result) { m_test_part_results.push_back(result); }
335  void set_elapsed_time(TimeInMillisec time) IUTEST_CXX_NOEXCEPT_SPEC { m_elapsedmsec = time; }
336 
337 private:
338  void RecordProperty(const TestProperty& prop)
339  {
340  for( TestPropertys::iterator it=m_test_propertys.begin()
341  , end=m_test_propertys.end(); it != end; ++it )
342  {
343  if( detail::IsStringEqual(it->key(), prop.key()) )
344  {
345  it->m_value = prop.m_value;
346  return;
347  }
348  }
349  m_test_propertys.push_back(prop);
350  }
351 
352  void ClearResult()
353  {
354  m_test_part_results.clear();
355  }
356  void Clear()
357  {
358  m_test_part_results.clear();
359  m_test_propertys.clear();
360  m_elapsedmsec = 0;
361  }
362  bool HasResult(TestPartResult::Type eType) const
363  {
364  for( TestPartResults::const_iterator it=m_test_part_results.begin()
365  , end=m_test_part_results.end(); it != end; ++it )
366  {
367  if( it->type() == eType )
368  {
369  return true;
370  }
371  }
372  return false;
373  }
374 private:
375  friend class UnitTestImpl;
376  friend class TestInfo;
377  friend class TestCase;
378  friend class detail::DefaultGlobalTestPartResultReporter;
379 
380  TestPartResults m_test_part_results;
381  TestPropertys m_test_propertys;
382  TimeInMillisec m_elapsedmsec;
383 
385 };
386 
387 } // end of namespace iutest
388 
389 #endif // INCG_IRIS_IUTEST_RESULT_HPP_D27B1599_F42F_4E2D_B3EB_FACE24C2B921_
iutest::TestResult
テスト結果を示すクラス
Definition: iutest_result.hpp:213
iutest::TestProperty::SetValue
void SetValue(const ::std::string &value)
値の設定
Definition: iutest_result.hpp:171
iutest_message.hpp
iris unit test メッセージ ファイル
iutest::TestPartResultReporterInterface::ReportTestPartResult
virtual void ReportTestPartResult(const TestPartResult &result)=0
テスト結果通知受け取り関数
iutest::TestPartResultReporterInterface
テスト結果の通知処理インターフェイス
Definition: iutest_result.hpp:40
iutest::TestResult::HasNonfatalFailure
bool HasNonfatalFailure() const
致命的でないエラーがあるかどうか
Definition: iutest_result.hpp:269
iutest::TestProperty::TestProperty
TestProperty(const ::std::string &key, const ::std::string &value)
コンストラクタ
Definition: iutest_result.hpp:164
iutest::TestResult::elapsed_time
TimeInMillisec elapsed_time() const IUTEST_CXX_NOEXCEPT_SPEC
テストの実行時間の取得
Definition: iutest_result.hpp:287
iutest::TestPartResult::kNonFatalFailure
@ kNonFatalFailure
致命的ではない失敗
Definition: iutest_result.hpp:66
iutest::TestPartResult::nonfatally_failed
bool nonfatally_failed() const IUTEST_CXX_NOEXCEPT_SPEC
致命的ではない失敗かどうか
Definition: iutest_result.hpp:125
iutest::TestPartResult::summary
const char * summary() const
理由
Definition: iutest_result.hpp:135
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::TestPartResult::Type
Type
結果のタイプ
Definition: iutest_result.hpp:60
iutest
iutest root namespace
Definition: iutest_charcode.hpp:31
iutest::TestProperty::ValidateName
static bool ValidateName(const ::std::string &name, T(&ar)[N])
Definition: iutest_result.hpp:198
iutest::TestPartResult::kWarning
@ kWarning
警告
Definition: iutest_result.hpp:64
iutest::TestPartResult::type_is_failed
static bool type_is_failed(Type type) IUTEST_CXX_NOEXCEPT_SPEC
失敗かどうか
Definition: iutest_result.hpp:84
iutest::TestResult::HasWarning
bool HasWarning() const
警告があるかどうか
Definition: iutest_result.hpp:281
IUTEST_FLAG
#define IUTEST_FLAG(name)
フラグセット
Definition: iutest_env.hpp:55
iutest::TestResult::Failed
bool Failed() const
失敗したかどうか
Definition: iutest_result.hpp:230
iutest::TestResult::test_property_count
int test_property_count() const
プロパティ総数の取得
Definition: iutest_result.hpp:299
iutest::TestResult::GetTestPartResult
const TestPartResult & GetTestPartResult(int index) const
テスト結果の取得
Definition: iutest_result.hpp:306
iutest::TestResult::HasAssumeFailure
bool HasAssumeFailure() const
前提条件エラーがあるかどうか
Definition: iutest_result.hpp:275
iutest::TestPartResult::TestPartResult
TestPartResult(const char *file, int line, const char *message, Type type)
コンストラクタ
Definition: iutest_result.hpp:77
iutest::TestPartResult::fatally_failed
bool fatally_failed() const IUTEST_CXX_NOEXCEPT_SPEC
致命的な失敗かどうか
Definition: iutest_result.hpp:130
IUTEST_PP_DISALLOW_COPY_AND_ASSIGN
#define IUTEST_PP_DISALLOW_COPY_AND_ASSIGN(TypeName)
コピー禁止定義
Definition: iutest_pp.hpp:25
iutest::TestPartResult::type
Type type() const IUTEST_CXX_NOEXCEPT_SPEC
結果のタイプ取得
Definition: iutest_result.hpp:140
iutest::TestPartResult::kAssumeFailure
@ kAssumeFailure
前提条件エラー
Definition: iutest_result.hpp:62
iutest::TestPartResult::succeeded
bool succeeded() const IUTEST_CXX_NOEXCEPT_SPEC
成功かどうか(警告を除く)
Definition: iutest_result.hpp:120
iutest::TestPartResult::kSkip
@ kSkip
スキップ
Definition: iutest_result.hpp:63
iutest::TimeInMillisec
detail::type_least_t< 8 >::UInt TimeInMillisec
ミリ秒単位を扱う型
Definition: iutest_defs.hpp:445
iutest::TestResult::HasFatalFailure
bool HasFatalFailure() const
致命的なエラーがあるかどうか
Definition: iutest_result.hpp:263
iutest::TestPartResult::assume_failed
bool assume_failed() const IUTEST_CXX_NOEXCEPT_SPEC
前提条件エラーかどうか
Definition: iutest_result.hpp:116
iutest::TestProperty
テストプロパティ
Definition: iutest_result.hpp:156
iutest::TestPartResult::skipped
bool skipped() const IUTEST_CXX_NOEXCEPT_SPEC
スキップかどうか
Definition: iutest_result.hpp:112
iutest::TestProperty::ValidateName
static bool ValidateName(const ::std::string &name, Ite begin, Ite end)
有効なキーかどうかチェック
Definition: iutest_result.hpp:191
iutest::TestPartResult::kFatalFailure
@ kFatalFailure
致命的な失敗
Definition: iutest_result.hpp:67
iutest::TestPartResult::passed
bool passed() const IUTEST_CXX_NOEXCEPT_SPEC
成功かどうか
Definition: iutest_result.hpp:104
iutest::TestResult::GetTestProperty
const TestProperty & GetTestProperty(int index) const
プロパティの取得
Definition: iutest_result.hpp:313
iutest::TestPartResult::failed
bool failed() const IUTEST_CXX_NOEXCEPT_SPEC
失敗かどうか
Definition: iutest_result.hpp:100
iutest::TestProperty::Validate
bool Validate(const char **ban_list, size_t size) const
有効なキーかどうかチェック
Definition: iutest_result.hpp:181
iutest::TestPartResult::kSuccess
@ kSuccess
成功
Definition: iutest_result.hpp:65
iutest::TestResult::Skipped
bool Skipped() const
スキップしたかどうか
Definition: iutest_result.hpp:246
iutest::TestPartResult
テスト結果を示すクラス
Definition: iutest_result.hpp:54
iutest::TestResult::total_error_count
int total_error_count() const
失敗の数を取得
Definition: iutest_result.hpp:320
iutest::TestPartResult::warning
bool warning() const IUTEST_CXX_NOEXCEPT_SPEC
警告かどうか
Definition: iutest_result.hpp:108
iutest::TestResult::total_part_count
int total_part_count() const
結果の数を取得
Definition: iutest_result.hpp:293
iutest::TestResult::Passed
bool Passed() const
成功したかどうか
Definition: iutest_result.hpp:225