iutest  1.17.1.0
iutest_util_tests.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_UTIL_TESTS_HPP_4095FF9B_D6B8_4CD3_BF86_43DFED1760EA_
16 #define INCG_IRIS_IUTEST_UTIL_TESTS_HPP_4095FF9B_D6B8_4CD3_BF86_43DFED1760EA_
17 
18 //======================================================================
19 // include
20 namespace iuutil
21 {
22 
23 //======================================================================
24 // function
25 
29 inline ::std::string TestFullName(const ::iutest::TestInfo* test_info)
30 {
31  ::std::string fullname = test_info->test_case_name();
32  fullname += ".";
33  fullname += test_info->name();
34  return fullname;
35 }
36 
40 inline ::std::string TestNameRemoveIndexName(const char* name)
41 {
42  const char* const p = strrchr(name, '/');
43  if( p == NULL )
44  {
45  return name;
46  }
47  return ::std::string(name, p);
48 }
49 
53 inline ::std::string TestCaseNameRemoveIndexName(const char* name)
54 {
55  return TestNameRemoveIndexName(name);
56 }
57 
61 inline ::std::string TestCaseNameRemoveInstantiateAndIndexName(const char* name)
62 {
63  // パッケージ名があれば取得
64  const char* const pkg = strrchr(name, '.');
65  // 先頭にインスタンス名がある
66  const char* const p1 = strchr(name, '/');
67  if( p1 == NULL )
68  {
69  return name;
70  }
71  if( pkg == NULL )
72  {
73  return TestCaseNameRemoveIndexName(p1 + 1);
74  }
75  else
76  {
77  return ::std::string(name, pkg + 1) + TestCaseNameRemoveIndexName(p1 + 1);
78  }
79 }
80 
84 inline const ::iutest::TestCase* FindTestCase(const char* testcase_name)
85 {
86  if( testcase_name == NULL )
87  {
88  return NULL;
89  }
90  const int testcase_count = ::iutest::UnitTest::GetInstance()->total_test_case_count();
91  for( int i=0; i < testcase_count; ++i )
92  {
93  const ::iutest::TestCase* testcase = ::iutest::UnitTest::GetInstance()->GetTestCase(i);
94  if( strcmp(testcase->name(), testcase_name) == 0 )
95  {
96  return testcase;
97  }
98  }
99  return NULL;
100 }
101 
105 inline const ::iutest::TestCase* FindParamTestCase(const char* testcase_name, const ::iutest::TestCase* begin=NULL)
106 {
107  if( testcase_name == NULL )
108  {
109  return NULL;
110  }
111  const int testcase_count = ::iutest::UnitTest::GetInstance()->total_test_case_count();
112  int i=0;
113  if( begin != NULL )
114  {
115  for( ; i < testcase_count; ++i )
116  {
117  const ::iutest::TestCase* testcase = ::iutest::UnitTest::GetInstance()->GetTestCase(i);
118  if( testcase == begin )
119  {
120  break;
121  }
122  }
123  ++i;
124  }
125  for( ; i < testcase_count; ++i )
126  {
127  const ::iutest::TestCase* testcase = ::iutest::UnitTest::GetInstance()->GetTestCase(i);
128  const char* testcase_origin_name = strchr(testcase->name(), '/');
129  if( testcase_origin_name != NULL )
130  {
131  if( strcmp(testcase_origin_name+1, testcase_name) == 0 )
132  {
133  return testcase;
134  }
135  }
136  }
137  return NULL;
138 }
139 
143 inline const ::iutest::TestCase* FindTypedTestCase(const char* testcase_name, const ::iutest::TestCase* begin=NULL)
144 {
145  if( testcase_name == NULL )
146  {
147  return NULL;
148  }
149  const int testcase_count = ::iutest::UnitTest::GetInstance()->total_test_case_count();
150  int i=0;
151  if( begin != NULL )
152  {
153  for( ; i < testcase_count; ++i )
154  {
155  const ::iutest::TestCase* testcase = ::iutest::UnitTest::GetInstance()->GetTestCase(i);
156  if( testcase == begin )
157  {
158  break;
159  }
160  }
161  ++i;
162  }
163  for( ; i < testcase_count; ++i )
164  {
165  const ::iutest::TestCase* testcase = ::iutest::UnitTest::GetInstance()->GetTestCase(i);
166  if( testcase != NULL )
167  {
168  const char* name = testcase->name();
169  if( name != NULL
170  && strstr(name, testcase_name) == name
171  && name[strlen(testcase_name)] == '/' )
172  {
173  return testcase;
174  }
175  }
176  }
177  return NULL;
178 }
179 
183 inline const ::iutest::TestCase* FindParamTypedTestCase(const char* testcase_name, const ::iutest::TestCase* begin=NULL)
184 {
185  if( testcase_name == NULL )
186  {
187  return NULL;
188  }
189  const int testcase_count = ::iutest::UnitTest::GetInstance()->total_test_case_count();
190  int i=0;
191  if( begin != NULL )
192  {
193  for( ; i < testcase_count; ++i )
194  {
195  const ::iutest::TestCase* testcase = ::iutest::UnitTest::GetInstance()->GetTestCase(i);
196  if( testcase == begin )
197  {
198  break;
199  }
200  }
201  ++i;
202  }
203  for( ; i < testcase_count; ++i )
204  {
205  const ::iutest::TestCase* testcase = ::iutest::UnitTest::GetInstance()->GetTestCase(i);
206  const char* name = strchr(testcase->name(), '/');
207  if( name != NULL )
208  {
209  ++name;
210  if( strstr(name, testcase_name) == name
211  && name[strlen(testcase_name)] == '/' )
212  {
213  return testcase;
214  }
215  }
216  }
217  return NULL;
218 }
219 
223 inline const ::iutest::TestInfo* FindTestInfo(const ::iutest::TestCase* testcase, const char* testinfo_name)
224 {
225  if( testcase == NULL || testinfo_name == NULL )
226  {
227  return NULL;
228  }
229 
230  const int testinfo_count = testcase->total_test_count();
231  for( int i=0; i < testinfo_count; ++i )
232  {
233  const ::iutest::TestInfo* testinfo = testcase->GetTestInfo(i);
234  if( strcmp(testinfo->name(), testinfo_name) == 0 )
235  {
236  return testinfo;
237  }
238  }
239  return NULL;
240 }
241 
245 inline const ::iutest::TestInfo* FindTestInfo(const char* testcase_name, const char* testinfo_name)
246 {
247  if( testcase_name == NULL || testinfo_name == NULL )
248  {
249  return NULL;
250  }
251  const ::iutest::TestCase* testcase = FindTestCase(testcase_name);
252  return FindTestInfo(testcase, testinfo_name);
253 }
254 
258 inline const ::iutest::TestInfo* FindParamTestInfo(const ::iutest::TestCase* testcase, const char* testinfo_name
259  , const ::iutest::TestInfo* begin=NULL)
260 {
261  if( testcase == NULL || testinfo_name == NULL )
262  {
263  return NULL;
264  }
265 
266  const int testinfo_count = testcase->total_test_count();
267  int i=0;
268  if( begin != NULL )
269  {
270  for( ; i < testinfo_count; ++i )
271  {
272  const ::iutest::TestInfo* testinfo = testcase->GetTestInfo(i);
273  if( testinfo == begin )
274  {
275  break;
276  }
277  }
278  ++i;
279  }
280 
281  for( ; i < testinfo_count; ++i )
282  {
283  const ::iutest::TestInfo* testinfo = testcase->GetTestInfo(i);
284  if( testinfo != NULL )
285  {
286  const char* name = testinfo->name();
287  if( name != NULL
288  && strstr(name, testinfo_name) == name
289  && name[strlen(testinfo_name)] == '/' )
290  {
291  return testinfo;
292  }
293  }
294  }
295  return NULL;
296 }
297 
301 inline const ::iutest::TestResult* TestResultPointer(const ::iutest::TestResult* result)
302 {
303  return result;
304 }
308 inline const ::iutest::TestResult* TestResultPointer(const ::iutest::TestResult& result)
309 {
310  return &result;
311 }
312 
316 inline const ::iutest::TestResult* GetAdHocTestResult()
317 {
318 #if !defined(IUTEST_NO_UNITEST_AD_HOC_TEST_RESULT_ACCESSOR)
319  return TestResultPointer(::iutest::UnitTest::GetInstance()->ad_hoc_test_result());
320 #else
321  return NULL;
322 #endif
323 }
324 
328 inline const ::iutest::TestResult* GetTestCaseAdHocResult(const ::iutest::TestCase* test_case)
329 {
330 #if !defined(IUTEST_NO_TESTCASE_AD_HOC_TEST_RESULT_ACCESSOR)
331  return TestResultPointer(test_case->ad_hoc_test_result());
332 #else
333  IUTEST_UNUSED_VAR(test_case);
334  return GetAdHocTestResult();
335 #endif
336 }
337 
341 inline const ::iutest::TestResult* GetCurrentTestCaseAdHocResult()
342 {
343  return GetTestCaseAdHocResult(::iutest::UnitTest::GetInstance()->current_test_case());
344 }
345 
349 inline const ::iutest::TestResult* GetTestResult(const ::iutest::TestInfo* test_info)
350 {
351  return TestResultPointer(test_info->result());
352 }
353 
357 inline const ::iutest::TestResult* GetCurrentTestResult()
358 {
359  return GetTestResult(::iutest::UnitTest::GetInstance()->current_test_info());
360 }
361 
362 } // end of namespace iuutil
363 
364 #endif // INCG_IRIS_IUTEST_UTIL_TESTS_HPP_4095FF9B_D6B8_4CD3_BF86_43DFED1760EA_
iuutil::FindTestCase
const ::iutest::TestCase * FindTestCase(const char *testcase_name)
TestCase の検索
Definition: iutest_util_tests.hpp:85
iutest::UnitTest::GetInstance
static UnitTest * GetInstance()
UnitTest インスタンスの取得
Definition: iutest_core.hpp:41
iuutil::GetTestResult
const ::iutest::TestResult * GetTestResult(const ::iutest::TestInfo *test_info)
get test result
Definition: iutest_util_tests.hpp:350
iutest_config.hpp
iris unit test config
iuutil::TestCaseNameRemoveInstantiateAndIndexName
inline ::std::string TestCaseNameRemoveInstantiateAndIndexName(const char *name)
インスタンス名とインデックスを除いたテストケース名を取得
Definition: iutest_util_tests.hpp:62
iuutil::GetAdHocTestResult
const ::iutest::TestResult * GetAdHocTestResult()
ad_hoc_test_result の取得
Definition: iutest_util_tests.hpp:317
iuutil::TestNameRemoveIndexName
inline ::std::string TestNameRemoveIndexName(const char *name)
インデックスを除いたテスト名を取得
Definition: iutest_util_tests.hpp:41
iutest::UnitTest::total_test_case_count
int total_test_case_count() const
Definition: iutest_core.hpp:89
iuutil::FindParamTypedTestCase
const ::iutest::TestCase * FindParamTypedTestCase(const char *testcase_name, const ::iutest::TestCase *begin=NULL)
Type Parameter Test の TestCase の検索
Definition: iutest_util_tests.hpp:184
iuutil::GetCurrentTestResult
const ::iutest::TestResult * GetCurrentTestResult()
get test result
Definition: iutest_util_tests.hpp:358
iuutil::GetTestCaseAdHocResult
const ::iutest::TestResult * GetTestCaseAdHocResult(const ::iutest::TestCase *test_case)
TestCase の ad_hoc_test_result の取得
Definition: iutest_util_tests.hpp:329
iuutil::TestCaseNameRemoveIndexName
inline ::std::string TestCaseNameRemoveIndexName(const char *name)
インデックスを除いたテストケース名を取得
Definition: iutest_util_tests.hpp:54
iuutil::GetCurrentTestCaseAdHocResult
const ::iutest::TestResult * GetCurrentTestCaseAdHocResult()
TestCase の ad_hoc_test_result の取得
Definition: iutest_util_tests.hpp:342
iuutil::FindParamTestCase
const ::iutest::TestCase * FindParamTestCase(const char *testcase_name, const ::iutest::TestCase *begin=NULL)
TestCase の検索
Definition: iutest_util_tests.hpp:106
iutest::UnitTest::GetTestCase
const TestCase * GetTestCase(int index) const
Definition: iutest_core.hpp:113
iuutil
iutest utility namespace
Definition: iutest_util.hpp:33
iuutil::FindParamTestInfo
const ::iutest::TestInfo * FindParamTestInfo(const ::iutest::TestCase *testcase, const char *testinfo_name, const ::iutest::TestInfo *begin=NULL)
TestInfo の検索
Definition: iutest_util_tests.hpp:259
iuutil::TestFullName
inline ::std::string TestFullName(const ::iutest::TestInfo *test_info)
テスト名を取得
Definition: iutest_util_tests.hpp:30
iuutil::FindTypedTestCase
const ::iutest::TestCase * FindTypedTestCase(const char *testcase_name, const ::iutest::TestCase *begin=NULL)
Typed Test の TestCase の検索
Definition: iutest_util_tests.hpp:144
iutest::TestCase::name
const char * name() const
Definition: iutest_case.hpp:73
iuutil::FindTestInfo
const ::iutest::TestInfo * FindTestInfo(const ::iutest::TestCase *testcase, const char *testinfo_name)
TestInfo の検索
Definition: iutest_util_tests.hpp:224