iutest  1.17.1.0
iutest_case.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_CASE_HPP_F57C9B7E_7CAA_4429_BE75_FCAAEED1B220_
16 #define INCG_IRIS_IUTEST_CASE_HPP_F57C9B7E_7CAA_4429_BE75_FCAAEED1B220_
17 
18 //======================================================================
19 // include
20 #include "iutest_info.hpp"
21 
22 namespace iutest
23 {
24 
25 //======================================================================
26 // class
30 class TestCase
32  : public detail::iu_list_node<TestCase>
33 #endif
34 {
35 protected:
37 #if IUTEST_USE_OWN_LIST
38  typedef detail::iu_list<TestInfo> iuTestInfos;
39 #else
40  typedef ::std::vector<TestInfo*> iuTestInfos;
41 #endif
42 
43 protected:
51  TestCase(const ::std::string& testcase_name, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
52  : m_testcase_name(testcase_name)
53  , m_setup(setup)
54  , m_teardown(teardown)
55  , m_id(id)
56  , m_disable_num(0)
57  , m_should_run_num(0)
58  , m_elapsedmsec(0)
59  , m_start_timestamp(0)
60  , m_disable(detail::IsDisableTestName(testcase_name))
61  {
62  }
63 
64 public:
68  virtual ~TestCase() {}
69 
70 public:
72  const char* name() const { return m_testcase_name.c_str(); }
73 
75  int total_test_count() const IUTEST_CXX_NOEXCEPT_SPEC { return static_cast<int>(m_testinfos.size()); }
77  int reportable_test_count() const;
79  int test_to_run_count() const IUTEST_CXX_NOEXCEPT_SPEC { return m_should_run_num; }
81  int failed_test_count() const;
83  int disabled_test_count() const IUTEST_CXX_NOEXCEPT_SPEC { return m_disable_num; }
87  int successful_test_count() const;
89  int skip_test_count() const;
91  int reportable_skip_test_count() const;
93  int test_run_skipped_count() const;
97  TimeInMillisec elapsed_time() const IUTEST_CXX_NOEXCEPT_SPEC { return m_elapsedmsec; }
99  TimeInMillisec start_timestamp() const IUTEST_CXX_NOEXCEPT_SPEC{ return m_start_timestamp; }
100 
102  const TestInfo* GetTestInfo(int index) const { return m_testinfos[index]; }
104  bool should_run() const IUTEST_CXX_NOEXCEPT_SPEC { return m_should_run_num != 0; }
105 
107  bool Passed() const { return failed_test_count() == 0 && m_ad_hoc_testresult.Passed(); }
109  bool Failed() const { return !Passed(); }
110 
112  virtual const char* type_param() const { return NULL; }
113 
115  ::std::string testcase_name_with_where() const
116  {
117  ::std::string str = m_testcase_name;
118  if( type_param() != NULL )
119  {
120  str += ", where TypeParam = ";
121  str += type_param();
122  }
123  return str;
124  }
125 
127  ::std::string testcase_name_with_default_package_name() const
128  {
130  }
131 
137  {
138  return ad_hoc_test_result();
139  }
140 
145  {
146  return &m_ad_hoc_testresult;
147  }
148 
149 public:
156  static bool ValidateTestPropertyName(const ::std::string& name)
157  {
158  const char* ban[] = { "name", "tests", "failures", "disabled", "skip", "errors", "time" };
159 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
160  return TestProperty::ValidateName(name, ban);
161 #else
162  return TestProperty::ValidateName(name, ban, ban+IUTEST_PP_COUNTOF(ban));
163 #endif
164  }
165 
166 private:
171  bool Run();
172 
177  bool RunImpl();
178 
179 private:
183  bool CheckSetUpSkipped();
184 
185 public:
190  struct FindOp
191  {
192  TestTypeId m_id;
193  const char* m_name;
194 
195  bool operator () (const TestCase* p) const
196  {
197  if( p->get_typeid() == m_id && detail::IsStringEqual(p->m_testcase_name, m_name) )
198  {
199  return true;
200  }
201  return false;
202  }
203  };
204 private:
208  void clear();
209  /*
210  * @brief テストのフィルタリング
211  * @return 実行する場合は真
212  */
213  bool filter();
214 
215 private:
216  friend bool operator == (const TestCase& lhs, const TestCase& rhs)
217  {
218  return (lhs.m_id == rhs.m_id) && (strcmp(lhs.name(), rhs.name()) == 0);
219  }
220 
221  void push_back(TestInfo* p) { m_testinfos.push_back(p); }
222 
223 private:
224  iuTestInfos::const_iterator begin() const { return m_testinfos.begin(); }
225  iuTestInfos::const_iterator end() const { return m_testinfos.end(); }
226  TestTypeId get_typeid() const IUTEST_CXX_NOEXCEPT_SPEC { return m_id; }
227 
228 private:
229  bool HasWarning() const { return m_ad_hoc_testresult.HasWarning() || detail::AnyOverList(m_testinfos, &TestInfo::HasWarning); }
230 
231 private:
232  static bool IsSuccessfulTest(const TestInfo* p) { return p->is_ran() && p->Passed(); }
233  static bool IsFailedTest(const TestInfo* p) { return p->should_run() && p->HasFailure(); }
234  static bool IsSkipTest(const TestInfo* p) { return !p->is_ran() || p->is_skipped(); }
235  static bool IsReportableSkipTest(const TestInfo* p) { return p->is_reportable() && IsSkipTest(p); }
236  static bool IsRunSkippedTest(const TestInfo* p) { return p->should_run() && p->is_skipped(); }
237  static bool IsReportableRunSkippedTest(const TestInfo* p) { return p->is_reportable() && IsRunSkippedTest(p); }
238  static bool IsReportableDisabledTest(const TestInfo* p) { return p->is_reportable() && p->is_disabled_test(); }
239 
240 private:
241  friend class UnitTestImpl;
242  friend class UnitTest;
243 
244 #if defined(IUTEST_NO_PRIVATE_IN_AGGREGATE)
245  friend struct FindOp;
246 #endif
247 
248  ::std::string m_testcase_name;
249  iuTestInfos m_testinfos;
250  SetUpMethod m_setup;
251  TearDownMethod m_teardown;
252  TestTypeId m_id;
253  int m_disable_num;
254  int m_should_run_num;
255  TimeInMillisec m_elapsedmsec;
256  TimeInMillisec m_start_timestamp;
257  bool m_disable;
258  TestResult m_ad_hoc_testresult;
259 
261 };
262 
266 template<typename T>
267 class TypedTestCase : public TestCase
268 {
269 public:
270  typedef T TypeParam;
271 
272 protected:
280  TypedTestCase(const ::std::string& testcase_name, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
281  : TestCase(testcase_name, id, setup, teardown)
282  , m_type_param(detail::GetTypeNameProxy<TypeParam>::GetTypeName())
283  {
284  }
285 
286 public:
288  virtual const char* type_param() const IUTEST_CXX_OVERRIDE
289  {
290  return m_type_param.empty() ? NULL : m_type_param.c_str();
291  }
292 
293 private:
294  friend class UnitTestImpl;
295 
296  ::std::string m_type_param;
297 };
298 
299 namespace detail
300 {
301 
305 class TestCaseMediator IUTEST_CXX_FINAL : public detail::iuITestCaseMediator
306 {
307 public:
308  explicit TestCaseMediator(TestCase* p) IUTEST_CXX_NOEXCEPT_SPEC : iuITestCaseMediator(p) {}
309 public:
310  virtual const char* test_case_name() const IUTEST_CXX_OVERRIDE { return m_test_case->name(); }
311  virtual const char* type_param() const IUTEST_CXX_OVERRIDE { return m_test_case->type_param(); }
312 };
313 
314 } // end of namespace detail
315 } // end of namespace iutest
316 
317 #if !IUTEST_HAS_LIB
318 # include "impl/iutest_case.ipp"
319 #endif
320 
321 #endif // INCG_IRIS_IUTEST_CASE_HPP_F57C9B7E_7CAA_4429_BE75_FCAAEED1B220_
iutest::TestCase::ad_hoc_test_result
const TestResult * ad_hoc_test_result() const IUTEST_CXX_NOEXCEPT_SPEC
テスト実行中じゃないときのリザルトの取得
Definition: iutest_case.hpp:145
iutest::TestResult
テスト結果を示すクラス
Definition: iutest_result.hpp:213
iutest::TestCase::reportable_skip_test_count
int reportable_skip_test_count() const
iutest::TestCase::successful_test_count
int successful_test_count() const
iutest::TestEnv::AddDefaultPackageName
::std::string AddDefaultPackageName(const char *testcase_name)
default package name を追加
iutest::TestCase::type_param
virtual const char * type_param() const
Definition: iutest_case.hpp:113
iutest::TestInfo
テスト情報クラス
Definition: iutest_info.hpp:32
iutest::TestInfo::HasWarning
bool HasWarning() const
警告があるかどうか
Definition: iutest_info.hpp:119
iutest_config.hpp
iris unit test config
IUTEST_USE_OWN_LIST
#define IUTEST_USE_OWN_LIST
テストの所持を独自リストクラスで行う
Definition: iutest_config.hpp:700
iutest::TestCase::Passed
bool Passed() const
Definition: iutest_case.hpp:108
iutest::TestCase::reportable_disabled_test_count
int reportable_disabled_test_count() const
IUTEST_CXX_NOEXCEPT_SPEC
#define IUTEST_CXX_NOEXCEPT_SPEC
noexcept specification definition
Definition: iutest_compiler.hpp:734
iutest::TestCase::failed_test_count
int failed_test_count() const
iutest::TestCase::testcase_name_with_default_package_name
::std::string testcase_name_with_default_package_name() const
Definition: iutest_case.hpp:128
iutest::TypedTestCase::TypeParam
T TypeParam
Definition: iutest_case.hpp:271
iutest::TestCase::test_run_skipped_count
int test_run_skipped_count() const
iutest
iutest root namespace
Definition: iutest_charcode.hpp:31
iutest::TestCase::iuTestInfos
::std::vector< TestInfo * > iuTestInfos
TestInfo リスト
Definition: iutest_case.hpp:41
IUTEST_CXX_FINAL
#define IUTEST_CXX_FINAL
final definition
Definition: iutest_compiler.hpp:679
iutest::TestCase::disabled_test_count
int disabled_test_count() const IUTEST_CXX_NOEXCEPT_SPEC
Definition: iutest_case.hpp:84
iutest::TypedTestCase
型つきテストケース
Definition: iutest_case.hpp:268
iutest::TestResult::HasWarning
bool HasWarning() const
警告があるかどうか
Definition: iutest_result.hpp:281
iutest::TypedTestCase::TypedTestCase
TypedTestCase(const ::std::string &testcase_name, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
コンストラクタ
Definition: iutest_case.hpp:281
iutest::TestCase::testcase_name_with_where
::std::string testcase_name_with_where() const
Definition: iutest_case.hpp:116
iutest::TestCase::GetTestInfo
const TestInfo * GetTestInfo(int index) const
Definition: iutest_case.hpp:103
iutest::TestTypeId
internal::TypeId TestTypeId
テスト識別型
Definition: iutest_defs.hpp:440
iutest::TestCase::~TestCase
virtual ~TestCase()
デストラクタ
Definition: iutest_case.hpp:69
iutest::TestCase::ad_hoc_testresult
const TestResult * ad_hoc_testresult() const IUTEST_CXX_NOEXCEPT_SPEC
テスト実行中じゃないときのリザルトの取得
Definition: iutest_case.hpp:137
IUTEST_CXX_OVERRIDE
#define IUTEST_CXX_OVERRIDE
override definition
Definition: iutest_compiler.hpp:670
iutest::TestCase::start_timestamp
TimeInMillisec start_timestamp() const IUTEST_CXX_NOEXCEPT_SPEC
Definition: iutest_case.hpp:100
iutest::TestCase::TestCase
TestCase(const ::std::string &testcase_name, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
コンストラクタ
Definition: iutest_case.hpp:52
iutest::TestCase::skip_test_count
int skip_test_count() const
iutest::TestCase::reportable_test_count
int reportable_test_count() const
iutest::TestCase::reportable_test_run_skipped_count
int reportable_test_run_skipped_count() const
IUTEST_PP_DISALLOW_COPY_AND_ASSIGN
#define IUTEST_PP_DISALLOW_COPY_AND_ASSIGN(TypeName)
コピー禁止定義
Definition: iutest_pp.hpp:25
iutest::TypedTestCase::type_param
virtual const char * type_param() const IUTEST_CXX_OVERRIDE
Definition: iutest_case.hpp:289
iutest::TestCase::Failed
bool Failed() const
Definition: iutest_case.hpp:110
iutest::TestCase::elapsed_time
TimeInMillisec elapsed_time() const IUTEST_CXX_NOEXCEPT_SPEC
Definition: iutest_case.hpp:98
iutest::TestCase::ValidateTestPropertyName
static bool ValidateTestPropertyName(const ::std::string &name)
有効なプロパティ名かどうかチェック
Definition: iutest_case.hpp:157
iutest::TimeInMillisec
detail::type_least_t< 8 >::UInt TimeInMillisec
ミリ秒単位を扱う型
Definition: iutest_defs.hpp:445
iutest::TearDownMethod
void(* TearDownMethod)()
TearDown 関数型
Definition: iutest_defs.hpp:443
iutest::TestCase::should_run
bool should_run() const IUTEST_CXX_NOEXCEPT_SPEC
Definition: iutest_case.hpp:105
iutest::SetUpMethod
void(* SetUpMethod)()
SetUp 関数型
Definition: iutest_defs.hpp:442
iutest::TestProperty::ValidateName
static bool ValidateName(const ::std::string &name, Ite begin, Ite end)
有効なキーかどうかチェック
Definition: iutest_result.hpp:191
iutest::TestCase::total_test_count
int total_test_count() const IUTEST_CXX_NOEXCEPT_SPEC
Definition: iutest_case.hpp:76
iutest::TestCase::name
const char * name() const
Definition: iutest_case.hpp:73
iutest_info.hpp
iris unit test info
iutest::TestCase
テストケース
Definition: iutest_case.hpp:31
iutest::TestCase::test_to_run_count
int test_to_run_count() const IUTEST_CXX_NOEXCEPT_SPEC
Definition: iutest_case.hpp:80
iutest::TestResult::Passed
bool Passed() const
成功したかどうか
Definition: iutest_result.hpp:225