iutest  1.17.99.14
iutest_suite.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_SUITE_HPP_0534E0BE_6BC4_4E99_80C0_56F441AD34ED_
16 #define INCG_IRIS_IUTEST_SUITE_HPP_0534E0BE_6BC4_4E99_80C0_56F441AD34ED_
17 
18 //======================================================================
19 // include
20 // IWYU pragma: begin_exports
21 #include "iutest_info.hpp"
22 // IWYU pragma: end_exports
23 
24 namespace iutest
25 {
26 
27 //======================================================================
28 // class
32 class TestSuite
34  : public detail::iu_list_node<TestSuite>
35 #endif
36 {
37 protected:
39 #if IUTEST_USE_OWN_LIST
40  typedef detail::iu_list<TestInfo> iuTestInfos;
41 #else
42  typedef ::std::vector<TestInfo*> iuTestInfos;
43 #endif
44 
45 protected:
53  TestSuite(const ::std::string& testsuite_name, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
54  : m_testsuite_name(testsuite_name)
55  , m_setup(setup)
56  , m_teardown(teardown)
57  , m_id(id)
58  , m_disable_num(0)
59  , m_should_run_num(0)
60  , m_elapsedmsec(0)
61  , m_start_timestamp(0)
62  , m_disable(detail::IsDisableTestName(testsuite_name))
63  {
64  }
65 
66 public:
70  virtual ~TestSuite() {}
71 
72 public:
74  const char* name() const { return m_testsuite_name.c_str(); }
75 
77  int total_test_count() const IUTEST_CXX_NOEXCEPT_SPEC { return static_cast<int>(m_testinfos.size()); }
79  int reportable_test_count() const;
81  int test_to_run_count() const IUTEST_CXX_NOEXCEPT_SPEC { return m_should_run_num; }
83  int failed_test_count() const;
85  int disabled_test_count() const IUTEST_CXX_NOEXCEPT_SPEC { return m_disable_num; }
89  int successful_test_count() const;
91  int skip_test_count() const;
93  int reportable_skip_test_count() const;
95  int test_run_skipped_count() const;
99  TimeInMillisec elapsed_time() const IUTEST_CXX_NOEXCEPT_SPEC { return m_elapsedmsec; }
101  TimeInMillisec start_timestamp() const IUTEST_CXX_NOEXCEPT_SPEC{ return m_start_timestamp; }
102 
104  const TestInfo* GetTestInfo(int index) const { return m_testinfos[index]; }
106  bool should_run() const IUTEST_CXX_NOEXCEPT_SPEC { return m_should_run_num != 0; }
107 
109  bool Passed() const { return failed_test_count() == 0 && m_ad_hoc_testresult.Passed(); }
111  bool Failed() const { return !Passed(); }
112 
114  virtual const char* type_param() const { return NULL; }
115 
117  ::std::string testsuite_name_with_where() const
118  {
119  ::std::string str = m_testsuite_name;
120  if( type_param() != NULL )
121  {
122  str += ", where TypeParam = ";
123  str += type_param();
124  }
125  return str;
126  }
127 
129  ::std::string testsuite_name_with_default_package_name() const
130  {
132  }
133 
139  {
140  return ad_hoc_test_result();
141  }
142 
147  {
148  return &m_ad_hoc_testresult;
149  }
150 
151 public:
158  static bool ValidateTestPropertyName(const ::std::string& name)
159  {
160  const char* ban[] = { "name", "tests", "failures", "disabled", "skip", "errors", "time" };
161 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
162  return TestProperty::ValidateName(name, ban);
163 #else
164  return TestProperty::ValidateName(name, ban, ban+IUTEST_PP_COUNTOF(ban));
165 #endif
166  }
167 
168 private:
173  bool Run();
174 
179  bool RunImpl();
180 
181 private:
185  bool CheckSetUpSkipped();
186 
187 public:
192  struct FindOp
193  {
194  TestTypeId m_id;
195  const char* m_name;
196 
197  bool operator () (const TestSuite* p) const
198  {
199  if( p->get_typeid() == m_id && detail::IsStringEqual(p->m_testsuite_name, m_name) )
200  {
201  return true;
202  }
203  return false;
204  }
205  };
206 private:
210  void clear();
211  /*
212  * @brief テストのフィルタリング
213  * @return 実行する場合は真
214  */
215  bool filter();
216 
217 private:
218  friend bool operator == (const TestSuite& lhs, const TestSuite& rhs)
219  {
220  return (lhs.m_id == rhs.m_id) && (strcmp(lhs.name(), rhs.name()) == 0);
221  }
222 
223  void push_back(TestInfo* p) { m_testinfos.push_back(p); }
224 
225 private:
226  iuTestInfos::const_iterator begin() const { return m_testinfos.begin(); }
227  iuTestInfos::const_iterator end() const { return m_testinfos.end(); }
228  TestTypeId get_typeid() const IUTEST_CXX_NOEXCEPT_SPEC { return m_id; }
229 
230 private:
231  bool HasWarning() const { return m_ad_hoc_testresult.HasWarning() || detail::AnyOverList(m_testinfos, &TestInfo::HasWarning); }
232 
233 private:
234  static bool IsSuccessfulTest(const TestInfo* p) { return p->is_ran() && p->Passed(); }
235  static bool IsFailedTest(const TestInfo* p) { return p->should_run() && p->HasFailure(); }
236  static bool IsSkipTest(const TestInfo* p) { return !p->is_ran() || p->is_skipped(); }
237  static bool IsReportableSkipTest(const TestInfo* p) { return p->is_reportable() && IsSkipTest(p); }
238  static bool IsRunSkippedTest(const TestInfo* p) { return p->should_run() && p->is_skipped(); }
239  static bool IsReportableRunSkippedTest(const TestInfo* p) { return p->is_reportable() && IsRunSkippedTest(p); }
240  static bool IsReportableDisabledTest(const TestInfo* p) { return p->is_reportable() && p->is_disabled_test(); }
241 
242 private:
243  friend class UnitTestImpl;
244  friend class UnitTest;
245 
246 #if defined(IUTEST_NO_PRIVATE_IN_AGGREGATE)
247  friend struct FindOp;
248 #endif
249 
250  ::std::string m_testsuite_name;
251  iuTestInfos m_testinfos;
252  SetUpMethod m_setup;
253  TearDownMethod m_teardown;
254  TestTypeId m_id;
255  int m_disable_num;
256  int m_should_run_num;
257  TimeInMillisec m_elapsedmsec;
258  TimeInMillisec m_start_timestamp;
259  bool m_disable;
260  TestResult m_ad_hoc_testresult;
261 
263 };
264 
268 template<typename T>
269 class TypedTestSuite IUTEST_CXX_FINAL : public TestSuite
270 {
271 public:
272  typedef T TypeParam;
273 
274 protected:
282  TypedTestSuite(const ::std::string& testsuite_name, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
283  : TestSuite(testsuite_name, id, setup, teardown)
284  , m_type_param(detail::GetTypeNameProxy<TypeParam>::GetTypeName())
285  {
286  }
287 
288 public:
290  virtual const char* type_param() const IUTEST_CXX_OVERRIDE
291  {
292  return m_type_param.empty() ? NULL : m_type_param.c_str();
293  }
294 
295 private:
296  friend class UnitTestImpl;
297 
298  ::std::string m_type_param;
299 };
300 
301 namespace detail
302 {
303 
307 class TestSuiteMediator IUTEST_CXX_FINAL : public detail::iuITestSuiteMediator
308 {
309 public:
310  explicit TestSuiteMediator(TestSuite* p) IUTEST_CXX_NOEXCEPT_SPEC : iuITestSuiteMediator(p) {}
311 public:
312  virtual const char* test_suite_name() const IUTEST_CXX_OVERRIDE { return m_test_suite->name(); }
313  virtual const char* type_param() const IUTEST_CXX_OVERRIDE { return m_test_suite->type_param(); }
314 };
315 
316 } // end of namespace detail
317 } // end of namespace iutest
318 
319 #if !IUTEST_HAS_LIB
320 # include "impl/iutest_suite.ipp" // IWYU pragma: export
321 #endif
322 
323 #endif // INCG_IRIS_IUTEST_SUITE_HPP_0534E0BE_6BC4_4E99_80C0_56F441AD34ED_
T TypeParam
Definition: iutest_suite.hpp:273
::std::string AddDefaultPackageName(const char *testsuite_name)
default package name を追加
テスト情報クラス
Definition: iutest_info.hpp:38
bool HasWarning() const
警告があるかどうか
Definition: iutest_info.hpp:124
static bool ValidateName(const ::std::string &name, Ite begin, Ite end)
有効なキーかどうかチェック
Definition: iutest_result.hpp:193
テスト結果を示すクラス
Definition: iutest_result.hpp:216
bool Passed() const
成功したかどうか
Definition: iutest_result.hpp:227
bool HasWarning() const
警告があるかどうか
Definition: iutest_result.hpp:283
TestSuite
Definition: iutest_suite.hpp:37
::std::string testsuite_name_with_default_package_name() const
Definition: iutest_suite.hpp:130
int test_to_run_count() const IUTEST_CXX_NOEXCEPT_SPEC
Definition: iutest_suite.hpp:82
bool should_run() const IUTEST_CXX_NOEXCEPT_SPEC
Definition: iutest_suite.hpp:107
::std::vector< TestInfo * > iuTestInfos
TestInfo リスト
Definition: iutest_suite.hpp:43
int successful_test_count() const
int reportable_test_run_skipped_count() const
const TestInfo * GetTestInfo(int index) const
Definition: iutest_suite.hpp:105
int test_run_skipped_count() const
virtual const char * type_param() const
Definition: iutest_suite.hpp:115
TimeInMillisec start_timestamp() const IUTEST_CXX_NOEXCEPT_SPEC
Definition: iutest_suite.hpp:102
int failed_test_count() const
int reportable_test_count() const
int reportable_skip_test_count() const
bool Passed() const
Definition: iutest_suite.hpp:110
virtual ~TestSuite()
デストラクタ
Definition: iutest_suite.hpp:71
const char * name() const
Definition: iutest_suite.hpp:75
int disabled_test_count() const IUTEST_CXX_NOEXCEPT_SPEC
Definition: iutest_suite.hpp:86
TestSuite(const ::std::string &testsuite_name, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
コンストラクタ
Definition: iutest_suite.hpp:54
const TestResult * ad_hoc_testresult() const IUTEST_CXX_NOEXCEPT_SPEC
テスト実行中じゃないときのリザルトの取得
Definition: iutest_suite.hpp:139
TimeInMillisec elapsed_time() const IUTEST_CXX_NOEXCEPT_SPEC
Definition: iutest_suite.hpp:100
const TestResult * ad_hoc_test_result() const IUTEST_CXX_NOEXCEPT_SPEC
テスト実行中じゃないときのリザルトの取得
Definition: iutest_suite.hpp:147
int skip_test_count() const
int total_test_count() const IUTEST_CXX_NOEXCEPT_SPEC
Definition: iutest_suite.hpp:78
static bool ValidateTestPropertyName(const ::std::string &name)
有効なプロパティ名かどうかチェック
Definition: iutest_suite.hpp:159
bool Failed() const
Definition: iutest_suite.hpp:112
::std::string testsuite_name_with_where() const
Definition: iutest_suite.hpp:118
int reportable_disabled_test_count() const
#define IUTEST_USE_OWN_LIST
テストの所持を独自リストクラスで行う
Definition: iutest_config.hpp:697
#define IUTEST_CXX_FINAL
final definition
Definition: iutest_compiler.hpp:756
#define IUTEST_CXX_OVERRIDE
override definition
Definition: iutest_compiler.hpp:747
#define IUTEST_CXX_NOEXCEPT_SPEC
noexcept specification definition
Definition: iutest_compiler.hpp:811
iris unit test info
#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
void(* SetUpMethod)()
SetUp 関数型
Definition: iutest_defs.hpp:523
void(* TearDownMethod)()
TearDown 関数型
Definition: iutest_defs.hpp:524
internal::TypeId TestTypeId
テスト識別型
Definition: iutest_defs.hpp:521