• R/O
  • SSH
  • HTTPS

iutest: Commit


Commit MetaInfo

Revision1341 (tree)
Time2018-09-04 12:52:25
Authorsrz_zumix

Log Message

Merge pull request #91 from srz-zumix/feature/refactoring_for_memory_sanitizer

refactoring for memory sanitizer
git@18ebe4c60b92a42cf867191601d93300d55cc376
https://github.com/srz-zumix/iutest/commit/18ebe4c60b92a42cf867191601d93300d55cc376

Change Summary

Incremental Difference

--- trunk/.travis.yml (revision 1340)
+++ trunk/.travis.yml (revision 1341)
@@ -96,6 +96,7 @@
9696 fi
9797
9898 script:
99+ - if [ -n "${CUSTOM_COMMANDS}" ]; then echo "${CUSTOM_COMMANDS}" && eval ${CUSTOM_COMMANDS}; fi
99100 - if [ "${USE_LIB}" == '1' ]; then cd projects/make && make && cd -; fi
100101 - if [ "${USE_CMAKE}" == '1' ]; then
101102 mkdir ./cmake-build && cd ./cmake-build && cmake ../projects/cmake && cmake --build . && ctest -C Debug -V && cd ..;
@@ -230,7 +231,19 @@
230231 branch_pattern: master
231232 - os: osx
232233 env: OSX=1 STDFLAG=-std=c++11
233-
234+ # Sanitize
235+ #- compiler: clang
236+ # env:
237+ # - STDFLAG=-std=c++11
238+ # - DEFS="-DIUTEST_USE_OWN_IS_MEMBER_FUNCTION_POINTER=1 -DIUTEST_CHECK_STRICT=0 -DIUTEST_HAS_HDR_CXXABI=0"
239+ # - CXXFLAGS="-stdlib=libc++ -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer"
240+ # #- CUSTOM_COMMANDS="clang++-6.0 -Wall -Wextra -std=c++14 -stdlib=libc++ -g -fsanitize=memory -fsanitize-memory-track-origins=2 -fno-omit-frame-pointer -O1 samples/simple.cpp samples/main.cpp && ./a.out && ./a.out --feature --spec"
241+ #- compiler: gcc
242+ # env:
243+ # - STDFLAG=-std=c++11
244+ # - DEFS="-DIUTEST_USE_OWN_IS_MEMBER_FUNCTION_POINTER=1 -DIUTEST_CHECK_STRICT=0 -DIUTEST_HAS_HDR_CXXABI=0"
245+ # - CXXFLAGS="-lasan -fsanitize=address -fno-omit-frame-pointer"
246+
234247 notifications:
235248 webhooks:
236249 urls:
--- trunk/include/internal/iutest_compiler.hpp (revision 1340)
+++ trunk/include/internal/iutest_compiler.hpp (revision 1341)
@@ -1255,9 +1255,9 @@
12551255 #if !defined(IUTEST_ATTRIBUTE_NO_SANITIZE_MEMORY)
12561256 # if IUTEST_HAS_MEMORY_SANITIZER
12571257 # if defined(__clang__)
1258-# define IUTEST_ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory")))
1258+# define IUTEST_ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
12591259 # elif defined(__GNUC__) && !defined(COMPILER_ICC)
1260-# define IUTEST_ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory")))
1260+# define IUTEST_ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
12611261 # endif
12621262 # endif
12631263 #endif
@@ -1266,7 +1266,71 @@
12661266 # define IUTEST_ATTRIBUTE_NO_SANITIZE_MEMORY
12671267 #endif
12681268
1269+//! AddressSanitizer
1270+#if !defined(IUTEST_HAS_ADDRESS_SANITIZER)
1271+# if defined(__has_feature)
1272+# if __has_feature(address_sanitizer)
1273+# define IUTEST_HAS_ADDRESS_SANITIZER 1
1274+# endif
1275+# endif
1276+#endif
12691277
1278+#if !defined(IUTEST_HAS_ADDRESS_SANITIZER)
1279+# define IUTEST_HAS_ADDRESS_SANITIZER 0
1280+#endif
1281+
1282+#if !defined(IUTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS)
1283+# if IUTEST_HAS_ADDRESS_SANITIZER
1284+# if defined(__clang__)
1285+# define IUTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
1286+# elif defined(__GNUC__) && !defined(COMPILER_ICC)
1287+# define IUTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
1288+# endif
1289+# endif
1290+#endif
1291+
1292+#if !defined(IUTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS)
1293+# define IUTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS
1294+#endif
1295+
1296+//! ThreadSanitizer
1297+#if !defined(IUTEST_HAS_THREAD_SANITIZER)
1298+# if defined(__has_feature)
1299+# if __has_feature(thread_sanitizer)
1300+# define IUTEST_HAS_THREAD_SANITIZER 1
1301+# endif
1302+# endif
1303+#endif
1304+
1305+#if !defined(IUTEST_HAS_THREAD_SANITIZER)
1306+# define IUTEST_HAS_THREAD_SANITIZER 0
1307+#endif
1308+
1309+#if !defined(IUTEST_ATTRIBUTE_NO_SANITIZE_THREAD)
1310+# if IUTEST_HAS_THREAD_SANITIZER
1311+# if defined(__clang__)
1312+# define IUTEST_ATTRIBUTE_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
1313+# elif defined(__GNUC__) && !defined(COMPILER_ICC)
1314+# define IUTEST_ATTRIBUTE_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
1315+# endif
1316+# endif
1317+#endif
1318+
1319+#if !defined(IUTEST_ATTRIBUTE_NO_SANITIZE_THREAD)
1320+# define IUTEST_ATTRIBUTE_NO_SANITIZE_THREAD
1321+#endif
1322+
1323+#if !defined(IUTEST_ATTRIBUTE_NO_SANITIZE_ALL)
1324+# define IUTEST_ATTRIBUTE_NO_SANITIZE_ALL \
1325+ IUTEST_ATTRIBUTE_NO_SANITIZE_MEMORY \
1326+ IUTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS \
1327+ IUTEST_ATTRIBUTE_NO_SANITIZE_THREAD
1328+#endif
1329+
1330+#if !defined(IUTEST_ATTRIBUTE_NO_SANITIZE_ALL)
1331+# define IUTEST_ATTRIBUTE_NO_SANITIZE_ALL
1332+#endif
1333+
12701334 // workaround
12711335 /**
12721336 * @private
--- trunk/include/internal/iutest_core_impl.hpp (revision 1340)
+++ trunk/include/internal/iutest_core_impl.hpp (revision 1341)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2011-2017, Takazumi Shirayanagi\n
9+ * Copyright (C) 2011-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -69,7 +69,7 @@
6969 public:
7070 /** @private */
7171 template<typename T>
72- TestCase* AddTestCase(const char* testcase_name, TestTypeId id
72+ TestCase* AddTestCase(const ::std::string& testcase_name, TestTypeId id
7373 , SetUpMethod setup, TearDownMethod teardown IUTEST_APPEND_EXPLICIT_TEMPLATE_TYPE_(T) )
7474 {
7575 TestCase* p = FindTestCase(testcase_name, id);
@@ -123,7 +123,7 @@
123123 /**
124124 * @brief FindTestCase
125125 */
126- TestCase* FindTestCase(const char* testcase_name, TestTypeId id);
126+ TestCase* FindTestCase(const ::std::string& testcase_name, TestTypeId id);
127127
128128 /**
129129 * @brief Do information options
--- trunk/include/internal/iutest_internal_defs.hpp (revision 1340)
+++ trunk/include/internal/iutest_internal_defs.hpp (revision 1341)
@@ -325,7 +325,7 @@
325325 using abi::__cxa_demangle;
326326 int status=1;
327327 char* const read_name = __cxa_demangle(name, 0, 0, &status);
328- ::std::string str = status == 0 ? read_name : name;
328+ ::std::string str(status == 0 ? read_name : name);
329329 free(read_name);
330330 return str;
331331 #else
--- trunk/include/internal/iutest_params_util.hpp (revision 1340)
+++ trunk/include/internal/iutest_params_util.hpp (revision 1341)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2011-2016, Takazumi Shirayanagi\n
9+ * Copyright (C) 2011-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -46,8 +46,8 @@
4646 public:
4747 explicit IParamTestInfoData(const char* name) : m_name(name) {}
4848 virtual ~IParamTestInfoData() IUTEST_CXX_DEFAULT_FUNCTION
49- virtual TestCase* MakeTestCase(const char* , TestTypeId , SetUpMethod , TearDownMethod ) const = 0;
50- virtual EachTestBase* RegisterTest(TestCase* , const char* ) const = 0;
49+ virtual TestCase* MakeTestCase(const ::std::string& , TestTypeId , SetUpMethod , TearDownMethod ) const = 0;
50+ virtual EachTestBase* RegisterTest(TestCase* , const ::std::string& ) const = 0;
5151 const char* GetName() const { return m_name.c_str(); }
5252 protected:
5353 ::std::string m_name;
@@ -63,6 +63,8 @@
6363 protected:
6464 IParamTestCaseInfo(const ::std::string& base_name, const ::std::string& package_name)
6565 : m_testcase_base_name(base_name), m_package_name(package_name) {}
66+ IParamTestCaseInfo(const char* base_name, const char* package_name)
67+ : m_testcase_base_name(base_name), m_package_name(package_name) {}
6668
6769 public:
6870 /**
@@ -90,6 +92,10 @@
9092 {
9193 return m_testcase_base_name == base_name && m_package_name == package_name;
9294 }
95+ bool is_same(const char* base_name, const char* package_name)
96+ {
97+ return m_testcase_base_name == base_name && m_package_name == package_name;
98+ }
9399
94100 private:
95101 virtual void OnRegisterTests(IParamTestInfoData*) const = 0;
@@ -136,6 +142,10 @@
136142 : IParamTestCaseInfo(testcase_name, package_name)
137143 {
138144 }
145+ ParamTestCaseInfo(const char* testcase_name, const char* package_name)
146+ : IParamTestCaseInfo(testcase_name, package_name)
147+ {
148+ }
139149 virtual ~ParamTestCaseInfo() {}
140150
141151 /**
@@ -163,14 +173,8 @@
163173 // パラメータ生成器の作成
164174 detail::scoped_ptr<ParamGenerator> p((gen_it->second.CreateGen)());
165175
166- ::std::string testcase_name = m_package_name;
167- if( !gen_it->first.empty() )
168- {
169- testcase_name += gen_it->first;
170- testcase_name += "/";
171- }
172- testcase_name += m_testcase_base_name;
173- TestCase* testcase = infodata->MakeTestCase(testcase_name.c_str()
176+ const ::std::string testcase_name = CreateTestCaseName(gen_it->first);
177+ TestCase* testcase = infodata->MakeTestCase(testcase_name
174178 , internal::GetTypeId<Tester>()
175179 , Tester::SetUpTestCase
176180 , Tester::TearDownTestCase);
@@ -188,7 +192,7 @@
188192 IUTEST_LOG_(WARNING) << testcase_name << "." << name << " is already exist.";
189193 }
190194 #endif
191- EachTest* test = static_cast<EachTest*>(infodata->RegisterTest(testcase, name.c_str()));
195+ EachTest* test = static_cast<EachTest*>(infodata->RegisterTest(testcase, name));
192196 test->SetParam(p->GetCurrent());
193197 ++i;
194198 }
@@ -213,6 +217,18 @@
213217 }
214218
215219 private:
220+ ::std::string CreateTestCaseName(const ::std::string& generator_name) const
221+ {
222+ ::std::string testcase_name = m_package_name;
223+ if( !generator_name.empty() )
224+ {
225+ testcase_name += generator_name;
226+ testcase_name += "/";
227+ }
228+ testcase_name += m_testcase_base_name;
229+ return testcase_name;
230+ }
231+private:
216232 static bool CheckTestName(const TestCase* testcase, const::std::string& name)
217233 {
218234 const int count = testcase->total_test_count();
@@ -245,21 +261,33 @@
245261 delete *it;
246262 }
247263 }
264+
248265 public:
249266 template<typename T>
250267 ParamTestCaseInfo<T>* GetTestCasePatternHolder(const ::std::string& testcase
251268 , const ::std::string& package IUTEST_APPEND_EXPLICIT_TEMPLATE_TYPE_(T) )
252269 {
270+ ParamTestCaseInfo<T>* p = static_cast<ParamTestCaseInfo<T>*>(FindTestCasePatternHolder(testcase, package));
271+ if( p == NULL )
272+ {
273+ p = new ParamTestCaseInfo<T>(testcase, package);
274+ m_testcase_infos.push_back(p);
275+ }
276+ return p;
277+ }
278+
279+private:
280+ template<typename T>
281+ IParamTestCaseInfo* FindTestCasePatternHolder(const T& testcase, const T& package)
282+ {
253283 for( TestCaseInfoContainer::iterator it=m_testcase_infos.begin(), end=m_testcase_infos.end(); it != end; ++it )
254284 {
255285 if( (*it)->is_same(testcase, package) )
256286 {
257- return static_cast<ParamTestCaseInfo<T>*>(*it);
287+ return (*it);
258288 }
259289 }
260- ParamTestCaseInfo<T>* p = new ParamTestCaseInfo<T>(testcase, package);
261- m_testcase_infos.push_back(p);
262- return p;
290+ return NULL;
263291 }
264292
265293 public:
--- trunk/include/internal/iutest_string.hpp (revision 1340)
+++ trunk/include/internal/iutest_string.hpp (revision 1341)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2011-2017, Takazumi Shirayanagi\n
9+ * Copyright (C) 2011-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -193,8 +193,15 @@
193193 return (p == NULL || *p == '\0') ? NULL : ((*p == ',') ? p : FindComma(++p));
194194 }
195195 inline bool IsStringEqual(const char* str1, const char* str2) { return strcmp(str1, str2) == 0; }
196+inline bool IsStringEqual(const ::std::string& str1, const char* str2) { return str1.compare(str2) == 0; }
197+inline bool IsStringEqual(const ::std::string& str1, const ::std::string& str2) { return str1.compare(str2) == 0; }
196198 inline bool IsStringCaseEqual(const char* str1, const char* str2) { return iu_stricmp(str1, str2) == 0; }
197199 inline bool IsStringForwardMatching(const char* str1, const char* str2) { return strstr(str1, str2) == str1; }
200+inline bool IsStringForwardMatching(const ::std::string& str1, const char* str2) { return str1.find(str2) == 0; }
201+inline bool IsStringForwardMatching(const ::std::string& str1, const std::string& str2) { return str1.find(str2) == 0; }
202+inline bool IsStringContains(const char* str1, const char* str2) { return strstr(str1, str2) != NULL; }
203+inline bool IsStringContains(const ::std::string& str1, const char* str2) { return str1.find(str2) != ::std::string::npos; }
204+inline bool IsStringContains(const ::std::string& str1, const ::std::string& str2) { return str1.find(str2) != ::std::string::npos; }
198205
199206 inline void StringReplace(::std::string& str, char a, const char* to)
200207 {
--- trunk/include/iutest_body.hpp (revision 1340)
+++ trunk/include/iutest_body.hpp (revision 1341)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2011-2016, Takazumi Shirayanagi\n
9+ * Copyright (C) 2011-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -336,6 +336,16 @@
336336
337337 #endif
338338
339+inline bool IsDisableTestName(const ::std::string& name)
340+{
341+ if( detail::IsStringForwardMatching(name, "DISABLED_")
342+ || detail::IsStringContains(name, "/DISABLED_") )
343+ {
344+ return true;
345+ }
346+ return false;
347+}
348+
339349 } // end of namespace detail
340350
341351 } // end of namespace iutest
--- trunk/include/iutest_case.hpp (revision 1340)
+++ trunk/include/iutest_case.hpp (revision 1341)
@@ -41,20 +41,17 @@
4141 * @param [in] setup = テスト事前実行関数
4242 * @param [in] teardown = テスト事後実行関数
4343 */
44- TestCase(const char* testcase_name, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
44+ TestCase(const ::std::string& testcase_name, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
4545 : m_testcase_name(testcase_name)
46- , m_setup(setup), m_teardown(teardown)
47- , m_id(id), m_disable_num(0)
46+ , m_setup(setup)
47+ , m_teardown(teardown)
48+ , m_id(id)
49+ , m_disable_num(0)
4850 , m_should_run_num(0)
4951 , m_elapsedmsec(0)
5052 , m_start_timestamp(0)
51- , m_disable(false)
53+ , m_disable(detail::IsDisableTestName(testcase_name))
5254 {
53- if( detail::IsStringForwardMatching(testcase_name, "DISABLED_")
54- || (strstr(testcase_name, "/DISABLED_") != NULL) )
55- {
56- m_disable = true;
57- }
5855 }
5956
6057 public:
@@ -190,7 +187,7 @@
190187
191188 bool operator () (const TestCase* p) const
192189 {
193- if( p->get_typeid() == m_id && (strcmp(p->name(), m_name) == 0) )
190+ if( p->get_typeid() == m_id && detail::IsStringEqual(p->m_testcase_name, m_name) )
194191 {
195192 return true;
196193 }
@@ -273,10 +270,11 @@
273270 * @param [in] setup = テスト事前実行関数
274271 * @param [in] teardown = テスト事後実行関数
275272 */
276- TypedTestCase(const char* testcase_name, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
273+ TypedTestCase(const ::std::string& testcase_name, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
277274 : TestCase(testcase_name, id, setup, teardown)
278275 , m_type_param(detail::GetTypeName<TypeParam>())
279- {}
276+ {
277+ }
280278
281279 public:
282280 /** type param 文字列の取得 */
--- trunk/include/iutest_core.hpp (revision 1340)
+++ trunk/include/iutest_core.hpp (revision 1341)
@@ -239,6 +239,14 @@
239239 UnitTest::instance().AddTestInfo(m_mediator.ptr(), &m_info);
240240 }
241241 /** コンストラクタ */
242+ TestInstance(const ::std::string& testcase, const char* name, TestTypeId id
243+ , SetUpMethod setup, TearDownMethod teardown)
244+ : m_mediator(AddTestCase(testcase, id, setup, teardown))
245+ , m_info(&m_mediator, name, &m_factory)
246+ {
247+ UnitTest::instance().AddTestInfo(m_mediator.ptr(), &m_info);
248+ }
249+ /** コンストラクタ */
242250 TestInstance(const char* testcase, const char* name, const char* value_params, TestTypeId id
243251 , SetUpMethod setup, TearDownMethod teardown)
244252 : m_mediator(AddTestCase(testcase, id, setup, teardown))
@@ -247,6 +255,15 @@
247255 m_info.set_value_param(value_params);
248256 UnitTest::instance().AddTestInfo(m_mediator.ptr(), &m_info);
249257 }
258+ /** コンストラクタ */
259+ TestInstance(const ::std::string& testcase, const char* name, const char* value_params, TestTypeId id
260+ , SetUpMethod setup, TearDownMethod teardown)
261+ : m_mediator(AddTestCase(testcase, id, setup, teardown))
262+ , m_info(&m_mediator, name, &m_factory)
263+ {
264+ m_info.set_value_param(value_params);
265+ UnitTest::instance().AddTestInfo(m_mediator.ptr(), &m_info);
266+ }
250267
251268 private:
252269 TestCase* AddTestCase(const char* testcase, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
@@ -257,6 +274,15 @@
257274 return UnitTest::instance().AddTestCase(testcase, id, setup, teardown, detail::explicit_type<TestCase>());
258275 #endif
259276 }
277+ TestCase* AddTestCase(const ::std::string& testcase, TestTypeId id, SetUpMethod setup, TearDownMethod teardown)
278+ {
279+#if !defined(IUTEST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS)
280+ return UnitTest::instance().AddTestCase<TestCase>(testcase, id, setup, teardown);
281+#else
282+ return UnitTest::instance().AddTestCase(testcase, id, setup, teardown, detail::explicit_type<TestCase>());
283+#endif
284+ }
285+
260286 private:
261287 TestCaseMediator m_mediator;
262288 TestInfo m_info;
--- trunk/include/iutest_info.hpp (revision 1340)
+++ trunk/include/iutest_info.hpp (revision 1341)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2011-2017, Takazumi Shirayanagi\n
9+ * Copyright (C) 2011-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -38,22 +38,17 @@
3838 * @param [in] name = テスト名
3939 * @param [in] factory = テスト生成器
4040 */
41- TestInfo(detail::iuITestCaseMediator* testcase, const char* name, detail::iuFactoryBase* factory)
41+ TestInfo(detail::iuITestCaseMediator* testcase, const ::std::string& name, detail::iuFactoryBase* factory)
4242 : m_testname(name)
4343 , m_factory(factory)
4444 , m_testcase(testcase)
4545 , m_should_run(true)
4646 , m_ran(false)
47- , m_disable(false)
47+ , m_disable(detail::IsDisableTestName(name))
4848 , m_skip(false)
4949 , m_matches_filter(true)
5050 {
5151 m_mediator.SetPointer(this);
52- if( detail::IsStringForwardMatching(name, "DISABLED_")
53- || (strstr(name, "/DISABLED_") != NULL) )
54- {
55- m_disable = true;
56- }
5752 }
5853
5954 public:
--- trunk/include/iutest_package.hpp (revision 1340)
+++ trunk/include/iutest_package.hpp (revision 1341)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2011-2016, Takazumi Shirayanagi\n
9+ * Copyright (C) 2011-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -31,7 +31,7 @@
3131
3232 #if IUTEST_HAS_PACKAGE
3333
34-#define IUTEST_CONCAT_PACKAGE_(testcase_name) IIUT_CONCAT_PACKAGE_I(testcase_name).c_str()
34+#define IUTEST_CONCAT_PACKAGE_(testcase_name) IIUT_CONCAT_PACKAGE_I(testcase_name)
3535 #define IIUT_CONCAT_PACKAGE_I(testcase_name) \
3636 iuTest_ConcatTestCaseName( iuTest_GetTestCasePackageName( \
3737 static_cast<iuTest_TestCasePackage*>(NULL)) \
--- trunk/include/iutest_param_tests.hpp (revision 1340)
+++ trunk/include/iutest_param_tests.hpp (revision 1341)
@@ -272,7 +272,7 @@
272272 class EachTest IUTEST_CXX_FINAL : public IParamTestInfoData::ParamEachTestBase<ParamType>
273273 {
274274 public:
275- EachTest(TestCase* testcase, const char* name)
275+ EachTest(TestCase* testcase, const ::std::string& name)
276276 : m_mediator(testcase)
277277 , m_info(&m_mediator, name, &m_factory)
278278 {
@@ -294,7 +294,7 @@
294294
295295 private:
296296 // テストケースの作成
297- virtual TestCase* MakeTestCase(const char* testcase_name, TestTypeId id
297+ virtual TestCase* MakeTestCase(const ::std::string& testcase_name, TestTypeId id
298298 , SetUpMethod setup, TearDownMethod teardown) const IUTEST_CXX_OVERRIDE
299299 {
300300 #if !defined(IUTEST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS)
@@ -307,7 +307,7 @@
307307
308308 // テストの作成登録
309309 virtual IParamTestInfoData::EachTestBase* RegisterTest(TestCase* testcase
310- , const char* name) const IUTEST_CXX_OVERRIDE
310+ , const ::std::string& name) const IUTEST_CXX_OVERRIDE
311311 {
312312 EachTest* test = new EachTest(testcase, name);
313313 // new オブジェクトを管理してもらう
--- trunk/include/iutest_typed_tests.hpp (revision 1340)
+++ trunk/include/iutest_typed_tests.hpp (revision 1341)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2011-2016, Takazumi Shirayanagi\n
9+ * Copyright (C) 2011-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -294,6 +294,12 @@
294294 , m_next(testcase, name, index+1)
295295 {
296296 }
297+ EachTest(const ::std::string& testcase, const char* name, size_t index)
298+ : m_mediator(AddTestCase(testcase, index))
299+ , m_info(&m_mediator, name, &m_factory)
300+ , m_next(testcase, name, index+1)
301+ {
302+ }
297303
298304 private:
299305 static TestCase* AddTestCase(const char* testcase, size_t index)
@@ -304,9 +310,9 @@
304310 return UnitTest::instance().AddTestCase(
305311 #endif
306312 #if IUTEST_HAS_TYPED_TEST_APPEND_TYPENAME
307- detail::MakeIndexTypedTestName<TypeParam>(testcase, index).c_str()
313+ detail::MakeIndexTypedTestName<TypeParam>(testcase, index)
308314 #else
309- detail::MakeIndexTestName(testcase, index).c_str()
315+ detail::MakeIndexTestName(testcase, index)
310316 #endif
311317 , internal::GetTypeId<detail::None>() // TypeId を統一するためダミー引数を渡す
312318 , TestBody::SetUpTestCase
@@ -316,6 +322,10 @@
316322 #endif
317323 );
318324 }
325+ static TestCase* AddTestCase(const ::std::string& testcase, size_t index)
326+ {
327+ return AddTestCase(testcase.c_str(), index);
328+ }
319329
320330 public:
321331 // テストの登録
@@ -339,6 +349,7 @@
339349 {
340350 public:
341351 EachTest(const char* /*testcase*/, const char* /*name*/, size_t /*index*/) {}
352+ EachTest(const ::std::string& /*testcase*/, const char* /*name*/, size_t /*index*/) {}
342353 void AddTest() {}
343354 };
344355
@@ -349,6 +360,11 @@
349360 {
350361 m_tests.AddTest();
351362 }
363+ TypeParamTestInstance(const std::string& testcase, const char* name)
364+ : m_tests(testcase, name, 0)
365+ {
366+ m_tests.AddTest();
367+ }
352368
353369 private:
354370 EachTest<TypeParams, void> m_tests;
@@ -449,7 +465,7 @@
449465 typedef detail::iuFactory<TestBody> Factory;
450466 typedef EachTest<TypeParam, TestsList> _Myt;
451467
452- EachTest(TestCase* testcase, const char* name)
468+ EachTest(TestCase* testcase, const ::std::string& name)
453469 : m_mediator(testcase)
454470 , m_info(&m_mediator, name, &m_factory)
455471 {
@@ -473,7 +489,7 @@
473489 test_name = ::std::string(str, static_cast<size_t>(comma - str));
474490 ++comma;
475491 }
476- _Myt* test = new EachTest(testcase, StripTrailingSpace(test_name).c_str());
492+ _Myt* test = new EachTest(testcase, StripTrailingSpace(test_name));
477493 // new オブジェクトを管理してもらう
478494 detail::iuPool::GetInstance().push(test);
479495
@@ -528,6 +544,13 @@
528544 typedef typename Tests::Head Head;
529545 typedef Fixture<Head> FixtureClass;
530546 typedef TypedTestCase<TypeParam> _MyTestCase;
547+ ::std::string full_testcase_name = package_name;
548+ full_testcase_name +=
549+#if IUTEST_HAS_TYPED_TEST_APPEND_TYPENAME
550+ detail::MakePrefixedIndexTypedTestName<TypeParam>(prefix, testcase_name, index);
551+#else
552+ detail::MakePrefixedIndexTestName(prefix, testcase_name, index);
553+#endif
531554 TestCase* testcase =
532555 #if !defined(IUTEST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS)
533556 UnitTest::instance().AddTestCase<_MyTestCase>(
@@ -534,15 +557,10 @@
534557 #else
535558 UnitTest::instance().AddTestCase(
536559 #endif
537- (package_name +
538-#if IUTEST_HAS_TYPED_TEST_APPEND_TYPENAME
539- detail::MakePrefixedIndexTypedTestName<TypeParam>(prefix, testcase_name, index)
540-#else
541- detail::MakePrefixedIndexTestName(prefix, testcase_name, index)
542-#endif
543- ).c_str()
560+ full_testcase_name
544561 , internal::GetTypeId<FixtureClass>()
545- , FixtureClass::SetUpTestCase, FixtureClass::TearDownTestCase
562+ , FixtureClass::SetUpTestCase
563+ , FixtureClass::TearDownTestCase
546564 #if defined(IUTEST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS)
547565 , detail::explicit_type<_MyTestCase>()
548566 #endif
Show on old repository browser