iutest  1.17.1.0
iutest_package.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_PACKAGE_HPP_F57C9B7E_7CAA_4429_BE75_FCAAEED1B220_
16 #define INCG_IRIS_IUTEST_PACKAGE_HPP_F57C9B7E_7CAA_4429_BE75_FCAAEED1B220_
17 
18 //======================================================================
19 // define
25 #define IUTEST_PACKAGE(name) IIUT_PACKAGE_(name)
26 
32 #if IUTEST_HAS_PACKAGE
33 
34 #define IUTEST_CONCAT_PACKAGE_(testcasename_) IIUT_CONCAT_PACKAGE_I(testcasename_)
35 #define IIUT_CONCAT_PACKAGE_I(testcasename_) \
36  iuTest_ConcatTestCaseName( iuTest_GetTestCasePackageName( \
37  static_cast<iuTest_TestCasePackage*>(NULL)) \
38  , #testcasename_)
39 
40 #define IUTEST_GET_PACKAGENAME_() \
41  iuTest_GetTestCasePackageName( static_cast<iuTest_TestCasePackage*>(NULL) )
42 
43 
44 #if IUTEST_HAS_IF_EXISTS
45 
46 #define IIUT_PACKAGE_DECL_NAME_FUNC(name) \
47  static ::std::string IUTEST_ATTRIBUTE_UNUSED_ \
48  iuTest_GetTestCasePackageName(const iuTest_TestCasePackage*) { \
49  return iuTest_GetTestCaseParentPackageName( \
50  static_cast<iuTest_TestCaseParentPackage*>(NULL)) + #name "."; \
51  }
52 
53 #define IIUT_PACKAGE_DECL_PARENT_NAME_FUNC(name) \
54  static ::std::string IUTEST_ATTRIBUTE_UNUSED_ \
55  iuTest_GetTestCaseParentPackageName(const iuTest_TestCaseParentPackage*) { \
56  return iuTest_GetTestCasePackageName(static_cast<iuTest_TestCasePackage*>(NULL)); \
57  }
58 
59 
60 #define IIUT_PACKAGE_CURRENT_NAMESPACE_(name) \
61  class iuTest_TestCasePackage; \
62  __if_not_exists(name::iuTest_GetTestCasePackageName) { \
63  IIUT_PACKAGE_DECL_NAME_FUNC(name) \
64  }
65 
66 #define IIUT_PACKAGE_PARENT_NAMESPACE_(name) \
67  class iuTest_TestCaseParentPackage; \
68  __if_not_exists(name::iuTest_GetTestCaseParentPackageName) { \
69  IUTEST_PRAGMA_MSC_WARN_PUSH() \
70  IUTEST_PRAGMA_MSC_WARN_DISABLE(4505) \
71  IIUT_PACKAGE_DECL_PARENT_NAME_FUNC(name) \
72  IUTEST_PRAGMA_MSC_WARN_POP() \
73  }
74 
75 #else
76 
77 #define IIUT_PACKAGE_CURRENT_NAMESPACE_(name) \
78  class iuTest_TestCasePackage; \
79  namespace { const int IUTEST_PP_CAT(k_iutest_package_##name##_dummy_, IUTEST_PP_UNIQUEID) \
80  IUTEST_ATTRIBUTE_UNUSED_ = ::iutest::detail::package_name_server< \
81  iuTest_TestCasePackage>::setname(iuTest_GetTestCaseParentPackageName( \
82  static_cast<iuTest_TestCaseParentPackage*>(NULL)) + #name "."); \
83  }
84 
85 #define IIUT_PACKAGE_PARENT_NAMESPACE_(name) \
86  class iuTest_TestCaseParentPackage; \
87  namespace { const int IUTEST_PP_CAT(k_iutest_package_##name##_parent_dummy_, IUTEST_PP_UNIQUEID) \
88  IUTEST_ATTRIBUTE_UNUSED_ = ::iutest::detail::package_name_server<iuTest_TestCaseParentPackage> \
89  ::setname(iuTest_GetTestCasePackageName(static_cast<iuTest_TestCasePackage*>(NULL))); \
90  }
91 
92 #endif
93 
94 #define IIUT_PACKAGE_(name) \
95  namespace name { \
96  IIUT_PACKAGE_CURRENT_NAMESPACE_(name) \
97  IIUT_PACKAGE_PARENT_NAMESPACE_(name) \
98  } \
99  namespace name
100 
101 #else
102 
103 #define IUTEST_CONCAT_PACKAGE_(testcasename_) IIUT_CONCAT_PACKAGE_I(testcasename_)
104 #define IIUT_CONCAT_PACKAGE_I(testcasename_) #testcasename_
105 #define IIUT_PACKAGE_(name) namespace name
106 #define IUTEST_GET_PACKAGENAME_() ""
107 
108 #endif
109 
114 #if IUTEST_HAS_PACKAGE
115 
116 class iuTest_TestCasePackage;
117 class iuTest_TestCaseParentPackage;
118 
119 #if IUTEST_HAS_IF_EXISTS
120 
125 inline ::std::string IUTEST_ATTRIBUTE_UNUSED_ iuTest_GetTestCasePackageName(const iuTest_TestCasePackage*)
126 {
127  return "";
128 }
129 
134 inline ::std::string IUTEST_ATTRIBUTE_UNUSED_ iuTest_GetTestCaseParentPackageName(const iuTest_TestCaseParentPackage*)
135 {
136  return "";
137 }
138 
139 #else
140 
141 namespace iutest {
142 namespace detail
143 {
144 
149 template<typename T>
150 class package_name_server
151 {
152  static ::std::string& getname_() { static ::std::string s; return s; }
153 public:
154  static ::std::string getname() { return getname_(); }
155  static int setname(const ::std::string& s)
156  {
157  ::std::string& name = getname_();
158  if( name.empty() )
159  {
160  name = s;
161  }
162  return 0;
163  }
164 };
165 
166 } // end of namespace detail
167 } // end of namespace iutest
168 
173 template<typename T>
174 ::std::string iuTest_GetTestCasePackageName(T*) // NOLINT
175 {
176  return ::iutest::detail::package_name_server<T>::getname();
177 }
178 
183 template<typename T>
184 ::std::string iuTest_GetTestCaseParentPackageName(T*) // NOLINT
185 {
186  return ::iutest::detail::package_name_server<T>::getname();
187 }
188 
189 #endif
190 
195 inline ::std::string IUTEST_ATTRIBUTE_UNUSED_ iuTest_ConcatTestCaseName(const ::std::string& package, const char* testcase_name)
196 {
197  return package + testcase_name;
198 }
199 
200 #endif
201 
202 #endif // INCG_IRIS_IUTEST_PACKAGE_HPP_F57C9B7E_7CAA_4429_BE75_FCAAEED1B220_
iuTest_GetTestCasePackageName
::std::string iuTest_GetTestCasePackageName(T *)
パッケージ名の取得
Definition: iutest_package.hpp:175
iutest_config.hpp
iris unit test config
iuTest_GetTestCaseParentPackageName
::std::string iuTest_GetTestCaseParentPackageName(T *)
親空間のパッケージ名の取得
Definition: iutest_package.hpp:185
iutest
iutest root namespace
Definition: iutest_charcode.hpp:31
iuTest_ConcatTestCaseName
inline ::std::string IUTEST_ATTRIBUTE_UNUSED_ iuTest_ConcatTestCaseName(const ::std::string &package, const char *testcase_name)
テストケース名との結合
Definition: iutest_package.hpp:196