iutest  1.17.99.14
iutest_core_impl.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_CORE_IMPL_HPP_D5ABC7DE_C751_4AC0_922F_547880163891_
16 #define INCG_IRIS_IUTEST_CORE_IMPL_HPP_D5ABC7DE_C751_4AC0_922F_547880163891_
17 
18 //======================================================================
19 // include
20 // IWYU pragma: begin_exports
21 #include "iutest_internal.hpp"
23 #include "../iutest_suite.hpp"
24 // IWYU pragma: end_exports
25 
26 namespace iutest
27 {
28 
29 //======================================================================
30 // class
32 class UnitTestImpl
33 {
34 protected:
35 #if IUTEST_USE_OWN_LIST
36  typedef detail::iu_list<TestSuite> iuTestSuites;
37 #else
38  typedef ::std::vector<TestSuite*> iuTestSuites;
39 #endif
40  typedef ::std::vector<Environment*> iuEnvironmentList;
41 protected:
42  UnitTestImpl() : m_total_test_num(0), m_disable_num(0), m_should_run_num(0)
43  , m_current_testsuite(NULL), m_elapsedmsec(0)
44  {
45  ptr() = this;
46  }
47  ~UnitTestImpl() { TerminateImpl(); }
48 
49 public:
53  static TestResult* current_test_result();
54 
55 public:
62  static bool ValidateTestPropertyName(const ::std::string& name)
63  {
64  const char* ban[] = {
65  "name", "tests", "failures", "disabled", "skip", "errors", "time", "timestamp", "random_seed"
66  };
67 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
68  return TestProperty::ValidateName(name, ban);
69 #else
70  return TestProperty::ValidateName(name, ban, ban+IUTEST_PP_COUNTOF(ban));
71 #endif
72  }
73 
74 public:
76  template<typename T>
77  TestSuite* AddTestSuite(const ::std::string& testsuite_name, TestTypeId id
78  , SetUpMethod setup, TearDownMethod teardown IUTEST_APPEND_EXPLICIT_TEMPLATE_TYPE_(T) )
79  {
80  TestSuite* p = FindTestSuite(testsuite_name, id);
81  if( p == NULL )
82  {
83  p = new T (testsuite_name, id, setup, teardown);
84  m_testsuites.push_back(p);
85  }
86  return p;
87  }
89  void AddTestInfo(TestSuite* pCase, TestInfo* pInfo);
91  static bool SkipTest();
92 
93 protected:
97  int Listup() const;
98 
102  int ListupWithWhere() const;
103 
107  bool PreRunner();
108 
112  void ClearNonAdHocTestResult();
113 
117  void ClearAdHocTestResult()
118  {
119  m_ad_hoc_testresult.Clear();
120  }
121 
122 private:
126  static void RecordProperty(const TestProperty& prop);
127 
131  TestSuite* FindTestSuite(const ::std::string& testsuite_name, TestTypeId id);
132 
136  bool DoInfoOptions();
137 
138 private:
142  void InitializeImpl();
146  void TerminateImpl();
147 
148 private:
149 #if IUTEST_HAS_INVALID_PARAMETER_HANDLER
150 
151 IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN()
152 
153  // _invalid_parameter_handler
154  IUTEST_ATTRIBUTE_NORETURN_ static void OnInvalidParameter(const wchar_t * expression, const wchar_t * function
155  , const wchar_t * file, unsigned int line, uintptr_t pReserved);
156 
157 IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_END()
158 
159 #endif
160 
161 private:
162  static UnitTestImpl*& ptr() IUTEST_CXX_NOEXCEPT_SPEC
163  {
164  static UnitTestImpl* ptr = NULL;
165  return ptr;
166  }
167 protected:
168  friend class UnitTestSource;
169  friend class Test::TestRecordPropertyHelper;
170 
171  int m_total_test_num;
172  int m_disable_num;
173  int m_should_run_num;
174  TestSuite* m_current_testsuite;
175  TimeInMillisec m_elapsedmsec;
176  iuTestSuites m_testsuites;
177  TestResult m_ad_hoc_testresult;
178 };
179 
180 namespace detail
181 {
182 
187 ::std::string MakeIndexName(size_t index);
188 
194 ::std::string MakeIndexTestName(const char* basename, size_t index);
195 
201 ::std::string MakeParamTestName(const ::std::string& basename, const ::std::string& parame_name);
202 
208 template<typename T>
209 ::std::string MakeIndexTypedTestName(const char* basename, size_t index)
210 {
211 #if IUTEST_HAS_RTTI
212  ::std::string name = MakeIndexTestName(basename, index);
213  name += "/";
214  name += GetTypeNameProxy<T>::GetTypeNameProxy();
215  return name;
216 #else
217  return MakeIndexTestName(basename, index);
218 #endif
219 }
220 
227 ::std::string MakePrefixedIndexTestName(const char* prefix, const char* basename, size_t index);
228 
235 template<typename T>
236 ::std::string MakePrefixedIndexTypedTestName(const char* prefix, const char* basename, size_t index)
237 {
238 #if IUTEST_HAS_RTTI
239  ::std::string name = prefix;
240  if( !name.empty() )
241  {
242  name += "/";
243  }
244  name += MakeIndexTypedTestName<T>(basename, index);
245  return name;
246 #else
247  return MakePrefixedIndexTestName(prefix, basename, index);
248 #endif
249 }
250 
251 } // end of namespace detail
252 
253 } // end of namespace iutest
254 
255 #if !IUTEST_HAS_LIB
256 # include "../impl/iutest_core_impl.ipp" // IWYU pragma: export
257 #endif
258 
259 #endif // INCG_IRIS_IUTEST_CORE_IMPL_HPP_D5ABC7DE_C751_4AC0_922F_547880163891_
static bool ValidateName(const ::std::string &name, Ite begin, Ite end)
有効なキーかどうかチェック
Definition: iutest_result.hpp:193
#define IUTEST_CXX_NOEXCEPT_SPEC
noexcept specification definition
Definition: iutest_compiler.hpp:811
#define IUTEST_ATTRIBUTE_NORETURN_
noreturn
Definition: iutest_compiler.hpp:1433
iris unit test internal definition
iris unit test commandline option message
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
const ::iutest::TestSuite * FindTestSuite(const char *testsuite_name)
TestSuite の検索
Definition: iutest_util_tests.hpp:220