iutest  1.17.99.14
iutest_legacy.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_LEGACY_HPP_E7B75232_2AB9_44F5_B9C5_CF62CD3FF958_
16 #define INCG_IRIS_IUTEST_LEGACY_HPP_E7B75232_2AB9_44F5_B9C5_CF62CD3FF958_
17 
18 // IWYU pragma: begin_exports
19 #include "internal/iutest_port.hpp"
20 // IWYU pragma: end_exports
21 
22 #if IUTEST_HAS_TESTCASE
23 
24 #if IUTEST_HAS_PARAM_TEST
25 # define IUTEST_INSTANTIATE_TEST_CASE_P IUTEST_INSTANTIATE_TEST_SUITE_P
26 #endif
27 #if IUTEST_HAS_ANY_PARAM_TEST
28 # define IUTEST_INSTANTIATE_TEST_CASE_AP IUTEST_INSTANTIATE_TEST_SUITE_AP
29 #endif
30 #if IUTEST_HAS_TYPED_TEST
31 # define IUTEST_TYPED_TEST_CASE IUTEST_TYPED_TEST_SUITE
32 # define IUTEST_VALUETMP_TEST_CASE IUTEST_VALUETMP_TEST_SUITE
33 #endif
34 #if IUTEST_HAS_TYPED_TEST_P
35 # define IUTEST_TYPED_TEST_CASE_P IUTEST_TYPED_TEST_SUITE_P
36 # define IUTEST_INSTANTIATE_TYPED_TEST_CASE_P IUTEST_INSTANTIATE_TYPED_TEST_SUITE_P
37 # define IUTEST_REGISTER_TYPED_TEST_CASE_P IUTEST_REGISTER_TYPED_TEST_SUITE_P
38 #endif
39 
40 namespace iutest
41 {
42 
43 class TestSuite;
44 class Test;
45 
46 typedef TestSuite TestCase;
47 
48 namespace detail
49 {
50 
51 ::std::string FormatCompilerIndependentFileLocation(const char* file, int line);
52 
53 }
54 
55 namespace legacy
56 {
57 
58 typedef void (*SetUpTearDownTestSuiteFuncType)();
59 
60 inline SetUpTearDownTestSuiteFuncType GetNotDefaultOrNull(SetUpTearDownTestSuiteFuncType a, SetUpTearDownTestSuiteFuncType def)
61 {
62  return a == def ? NULL : a;
63 }
64 
65 template<typename T>
66 struct SuiteApiResolver : T
67 {
68  typedef typename iutest_type_traits::enable_if<sizeof(T) != 0, ::iutest::Test>::type Tester;
69 
70  static SetUpTearDownTestSuiteFuncType GetSetUpCaseOrSuite(const char* file, int line)
71  {
72  SetUpTearDownTestSuiteFuncType testcase = GetNotDefaultOrNull(&T::SetUpTestCase, &Tester::SetUpTestCase);
73  SetUpTearDownTestSuiteFuncType testsuite = GetNotDefaultOrNull(&T::SetUpTestSuite, &Tester::SetUpTestSuite);
74 
75  IUTEST_CHECK_( testcase == NULL || testsuite == NULL )
76  << "Test can not provide both SetUpTestSuite and SetUpTestCase, please make sure there is only one present at "
77  << detail::FormatCompilerIndependentFileLocation(file, line);
78 
79  return testcase != NULL ? testcase : testsuite;
80  }
81  static SetUpTearDownTestSuiteFuncType GetTearDownCaseOrSuite(const char* file, int line)
82  {
83  SetUpTearDownTestSuiteFuncType testcase = GetNotDefaultOrNull(&T::TearDownTestCase, &Tester::TearDownTestCase);
84  SetUpTearDownTestSuiteFuncType testsuite = GetNotDefaultOrNull(&T::TearDownTestSuite, &Tester::TearDownTestSuite);
85 
86  IUTEST_CHECK_( testcase == NULL || testsuite == NULL )
87  << "Test can not provide both TearDownTestSuite and TearDownTestCase, please make sure there is only one present at "
88  << detail::FormatCompilerIndependentFileLocation(file, line);
89 
90  return testcase != NULL ? testcase : testsuite;
91  }
92 };
93 
94 } // end of namespace legacy
95 } // end of namespace iutest
96 
97 #define IUTEST_GET_SETUP_TESTSUITE(type, file, line) ::iutest::legacy::SuiteApiResolver<type>::GetSetUpCaseOrSuite(file, line)
98 #define IUTEST_GET_TEARDOWN_TESTSUITE(type, file, line) ::iutest::legacy::SuiteApiResolver<type>::GetTearDownCaseOrSuite(file, line)
99 
100 #else
101 
102 #define IUTEST_GET_SETUP_TESTSUITE(type, file, line) ((void)(file), (void)(line), type::SetUpTestSuite)
103 #define IUTEST_GET_TEARDOWN_TESTSUITE(type, file, line) ((void)(file), (void)(line), type::TearDownTestSuite)
104 
105 #endif
106 
107 #endif // INCG_IRIS_IUTEST_LEGACY_HPP_E7B75232_2AB9_44F5_B9C5_CF62CD3FF958_
テストベース
Definition: iutest_body.hpp:44
static void TearDownTestSuite()
test suite tear down
Definition: iutest_body.hpp:173
static void SetUpTestSuite()
test suite setup
Definition: iutest_body.hpp:172
#define IUTEST_CHECK_(condition)
内部エラーチェック
Definition: iutest_port.hpp:63
iutest root namespace
Definition: iutest_charcode.hpp:33