iutest  1.17.1.0
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 #include "iutest_internal.hpp"
22 #include "../iutest_case.hpp"
23 
24 namespace iutest
25 {
26 
27 //======================================================================
28 // class
30 class UnitTestImpl
31 {
32 protected:
33 #if IUTEST_USE_OWN_LIST
34  typedef detail::iu_list<TestCase> iuTestCases;
35 #else
36  typedef ::std::vector<TestCase*> iuTestCases;
37 #endif
38  typedef ::std::vector<Environment*> iuEnvironmentList;
39 protected:
40  UnitTestImpl() : m_total_test_num(0), m_disable_num(0), m_should_run_num(0)
41  , m_current_testcase(NULL), m_elapsedmsec(0)
42  {
43  ptr() = this;
44  }
45  ~UnitTestImpl() { TerminateImpl(); }
46 
47 public:
51  static TestResult* current_test_result();
52 
53 public:
60  static bool ValidateTestPropertyName(const ::std::string& name)
61  {
62  const char* ban[] = {
63  "name", "tests", "failures", "disabled", "skip", "errors", "time", "timestamp", "random_seed"
64  };
65 #if !defined(IUTEST_NO_FUNCTION_TEMPLATE_ORDERING)
66  return TestProperty::ValidateName(name, ban);
67 #else
68  return TestProperty::ValidateName(name, ban, ban+IUTEST_PP_COUNTOF(ban));
69 #endif
70  }
71 
72 public:
74  template<typename T>
75  TestCase* AddTestCase(const ::std::string& testcase_name, TestTypeId id
76  , SetUpMethod setup, TearDownMethod teardown IUTEST_APPEND_EXPLICIT_TEMPLATE_TYPE_(T) )
77  {
78  TestCase* p = FindTestCase(testcase_name, id);
79  if( p == NULL )
80  {
81  p = new T (testcase_name, id, setup, teardown);
82  m_testcases.push_back(p);
83  }
84  return p;
85  }
87  void AddTestInfo(TestCase* pCase, TestInfo* pInfo);
89  static bool SkipTest();
90 
91 protected:
95  int Listup() const;
96 
100  int ListupWithWhere() const;
101 
105  bool PreRunner();
106 
110  void ClearNonAdHocTestResult();
111 
115  void ClearAdHocTestResult()
116  {
117  m_ad_hoc_testresult.Clear();
118  }
119 
120 private:
124  static void RecordProperty(const TestProperty& prop);
125 
129  TestCase* FindTestCase(const ::std::string& testcase_name, TestTypeId id);
130 
134  bool DoInfoOptions();
135 
136 private:
140  void InitializeImpl();
144  void TerminateImpl();
145 
146 private:
147 #if IUTEST_HAS_INVALID_PARAMETER_HANDLER
148 
149 IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN()
150 
151  // _invalid_parameter_handler
152  static void OnInvalidParameter(const wchar_t * expression, const wchar_t * function
153  , const wchar_t * file, unsigned int line, uintptr_t pReserved);
154 
155 IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_END()
156 
157 #endif
158 
159 private:
160  static UnitTestImpl*& ptr() IUTEST_CXX_NOEXCEPT_SPEC
161  {
162  static UnitTestImpl* ptr = NULL;
163  return ptr;
164  }
165 protected:
166  friend class UnitTestSource;
167  friend class Test::TestRecordPropertyHelper;
168 
169  int m_total_test_num;
170  int m_disable_num;
171  int m_should_run_num;
172  TestCase* m_current_testcase;
173  TimeInMillisec m_elapsedmsec;
174  iuTestCases m_testcases;
175  TestResult m_ad_hoc_testresult;
176 };
177 
178 namespace detail
179 {
180 
185 ::std::string MakeIndexName(size_t index);
186 
192 ::std::string MakeIndexTestName(const char* basename, size_t index);
193 
199 ::std::string MakeParamTestName(const ::std::string& basename, const ::std::string& parame_name);
200 
206 template<typename T>
207 ::std::string MakeIndexTypedTestName(const char* basename, size_t index)
208 {
209 #if IUTEST_HAS_RTTI
210  ::std::string name = MakeIndexTestName(basename, index);
211  name += "/";
212  name += GetTypeNameProxy<T>::GetTypeNameProxy();
213  return name;
214 #else
215  return MakeIndexTestName(basename, index);
216 #endif
217 }
218 
225 ::std::string MakePrefixedIndexTestName(const char* prefix, const char* basename, size_t index);
226 
233 template<typename T>
234 ::std::string MakePrefixedIndexTypedTestName(const char* prefix, const char* basename, size_t index)
235 {
236 #if IUTEST_HAS_RTTI
237  ::std::string name = prefix;
238  if( !name.empty() )
239  {
240  name += "/";
241  }
242  name += MakeIndexTypedTestName<T>(basename, index);
243  return name;
244 #else
245  return MakePrefixedIndexTestName(prefix, basename, index);
246 #endif
247 }
248 
249 } // end of namespace detail
250 
251 } // end of namespace iutest
252 
253 #if !IUTEST_HAS_LIB
254 # include "../impl/iutest_core_impl.ipp"
255 #endif
256 
257 #endif // INCG_IRIS_IUTEST_CORE_IMPL_HPP_D5ABC7DE_C751_4AC0_922F_547880163891_
iuutil::FindTestCase
const ::iutest::TestCase * FindTestCase(const char *testcase_name)
TestCase の検索
Definition: iutest_util_tests.hpp:85
iutest_internal.hpp
iris unit test internal definition
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
iutest root namespace
Definition: iutest_charcode.hpp:31
iutest::TestTypeId
internal::TypeId TestTypeId
テスト識別型
Definition: iutest_defs.hpp:440
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::SetUpMethod
void(* SetUpMethod)()
SetUp 関数型
Definition: iutest_defs.hpp:442
iutest_option_message.hpp
iris unit test コマンドラインメッセージ ファイル
iutest::TestProperty::ValidateName
static bool ValidateName(const ::std::string &name, Ite begin, Ite end)
有効なキーかどうかチェック
Definition: iutest_result.hpp:191