Revision | 149 (tree) |
---|---|
Time | 2011-07-01 18:52:18 |
Author | shirayanagi |
iutest 更新
doxygen ファイル追加
ログ出力修正
時間計測を一部対応
@@ -25,10 +25,10 @@ | ||
25 | 25 | |
26 | 26 | //====================================================================== |
27 | 27 | // define |
28 | -#define IUTEST_VER 0x00010000 //!< iutest version 0.1.0.0 | |
28 | +#define IUTEST_VER 0x00010100 //!< iutest version 0.1.1.0 | |
29 | 29 | #define IUTEST_MAJORVER 0x00 |
30 | 30 | #define IUTEST_MINORVER 0x01 |
31 | -#define IUTEST_REVISION 0x00 | |
31 | +#define IUTEST_REVISION 0x01 | |
32 | 32 | #define IUTEST_BUILD 0x00 |
33 | 33 | |
34 | 34 |
@@ -64,7 +64,7 @@ | ||
64 | 64 | if( val1 op val2 ) return TestResult::Success(); \ |
65 | 65 | else { \ |
66 | 66 | return TestResult::Failure() << expr1 << " " #op " " << expr2 \ |
67 | - << "\nExpected: " << val1 << "\nactual: " << val2; \ | |
67 | + << "\n Expected: " << val1 << "\n actual: " << val2; \ | |
68 | 68 | } \ |
69 | 69 | } |
70 | 70 |
@@ -80,7 +80,7 @@ | ||
80 | 80 | { |
81 | 81 | if( val ) return TestResult::Success(); |
82 | 82 | return TestResult::Failure() << expr |
83 | - << "\nExpected: " << val << "\nactual: true"; | |
83 | + << "\n Expected: " << val << "\n actual: true"; | |
84 | 84 | } |
85 | 85 | |
86 | 86 | template<typename T> |
@@ -88,9 +88,38 @@ | ||
88 | 88 | { |
89 | 89 | if( !val ) return TestResult::Success(); |
90 | 90 | return TestResult::Failure() << expr |
91 | - << "\nExpected: " << val << "\nactual: false"; | |
91 | + << "\n Expected: " << val << "\n actual: false"; | |
92 | 92 | } |
93 | 93 | |
94 | +TestResult CompareHelperSTREQ(const char* expr1, const char* expr2 | |
95 | + , const char* val1, const char* val2) | |
96 | +{ | |
97 | + if( strcmp(val1, val2) == 0 ) return TestResult::Success(); | |
98 | + return TestResult::Failure() << expr1 << " == " << expr2 | |
99 | + << "\n Expected: " << val1 << "\n actual: " << val2; | |
100 | +} | |
101 | +TestResult CompareHelperSTREQ(const char* expr1, const char* expr2 | |
102 | + , const wchar_t* val1, const wchar_t* val2) | |
103 | +{ | |
104 | + if( wcscmp(val1, val2) == 0 ) return TestResult::Success(); | |
105 | + return TestResult::Failure() << expr1 << " == " << expr2 | |
106 | + << "\n Expected: " << val1 << "\n actual: " << val2; | |
107 | +} | |
108 | +TestResult CompareHelperSTRNE(const char* expr1, const char* expr2 | |
109 | + , const char* val1, const char* val2) | |
110 | +{ | |
111 | + if( strcmp(val1, val2) != 0 ) return TestResult::Success(); | |
112 | + return TestResult::Failure() << expr1 << " != " << expr2 | |
113 | + << "\n Expected: " << val1 << "\n actual: " << val2; | |
114 | +} | |
115 | +TestResult CompareHelperSTRNE(const char* expr1, const char* expr2 | |
116 | + , const wchar_t* val1, const wchar_t* val2) | |
117 | +{ | |
118 | + if( wcscmp(val1, val2) != 0 ) return TestResult::Success(); | |
119 | + return TestResult::Failure() << expr1 << " != " << expr2 | |
120 | + << "\n Expected: " << val1 << "\n actual: " << val2; | |
121 | +} | |
122 | + | |
94 | 123 | } // end of namespace iutest |
95 | 124 | |
96 | 125 | #endif |
@@ -50,7 +50,8 @@ | ||
50 | 50 | #define IUTEST_RUN_ALL_TESTS() ::iutest::UnitTest::Run() |
51 | 51 | |
52 | 52 | /** |
53 | - * @brief テスト | |
53 | + * @brief ASSERT テスト | |
54 | + * @{ | |
54 | 55 | */ |
55 | 56 | #define IUTEST_ASSERT_EQ(v1, v2) IUTEST_ASSERT_EQ_(v1, v2) |
56 | 57 | #define IUTEST_ASSERT_NE(v1, v2) IUTEST_ASSERT_NE_(v1, v2) |
@@ -62,4 +63,32 @@ | ||
62 | 63 | #define IUTEST_ASSERT_TRUE(v) IUTEST_ASSERT_TRUE_(v) |
63 | 64 | #define IUTEST_ASSERT_FALSE(v) IUTEST_ASSERT_FALSE_(v) |
64 | 65 | |
66 | +#define IUTEST_ASSERT_STREQ(v1, v2) IUTEST_ASSERT_STREQ_(v1, v2) | |
67 | +#define IUTEST_ASSERT_STRNE(v1, v2) IUTEST_ASSERT_STRNE_(v1, v2) | |
68 | + | |
69 | +/** | |
70 | + * @} | |
71 | +*/ | |
72 | + | |
73 | +/** | |
74 | + * @brief EXPECT テスト | |
75 | + * @{ | |
76 | +*/ | |
77 | +#define IUTEST_EXPECT_EQ(v1, v2) IUTEST_EXPECT_EQ_(v1, v2) | |
78 | +#define IUTEST_EXPECT_NE(v1, v2) IUTEST_EXPECT_NE_(v1, v2) | |
79 | +#define IUTEST_EXPECT_LE(v1, v2) IUTEST_EXPECT_LE_(v1, v2) | |
80 | +#define IUTEST_EXPECT_LT(v1, v2) IUTEST_EXPECT_LT_(v1, v2) | |
81 | +#define IUTEST_EXPECT_GE(v1, v2) IUTEST_EXPECT_GE_(v1, v2) | |
82 | +#define IUTEST_EXPECT_GT(v1, v2) IUTEST_EXPECT_GT_(v1, v2) | |
83 | + | |
84 | +#define IUTEST_EXPECT_TRUE(v) IUTEST_EXPECT_TRUE_(v) | |
85 | +#define IUTEST_EXPECT_FALSE(v) IUTEST_EXPECT_FALSE_(v) | |
86 | + | |
87 | +#define IUTEST_EXPECT_STREQ(v1, v2) IUTEST_EXPECT_STREQ_(v1, v2) | |
88 | +#define IUTEST_EXPECT_STRNE(v1, v2) IUTEST_EXPECT_STRNE_(v1, v2) | |
89 | + | |
90 | +/** | |
91 | + * @} | |
92 | +*/ | |
93 | + | |
65 | 94 | #endif |
@@ -24,12 +24,54 @@ | ||
24 | 24 | { |
25 | 25 | |
26 | 26 | //====================================================================== |
27 | -// include | |
27 | +// struct | |
28 | +/** | |
29 | + * @internal | |
30 | + * @brief type_least_t | |
31 | +*/ | |
32 | +template<int SIZE> | |
33 | +struct type_least_t {}; | |
34 | + | |
35 | +template<> | |
36 | +struct type_least_t<1> | |
37 | +{ | |
38 | + typedef char Int; | |
39 | + typedef unsigned char UInt; | |
40 | +}; | |
41 | +template<> | |
42 | +struct type_least_t<2> | |
43 | +{ | |
44 | + typedef short Int; | |
45 | + typedef unsigned short UInt; | |
46 | +}; | |
47 | +template<> | |
48 | +struct type_least_t<4> | |
49 | +{ | |
50 | + typedef int Int; | |
51 | + typedef unsigned int UInt; | |
52 | +}; | |
53 | +template<> | |
54 | +struct type_least_t<8> | |
55 | +{ | |
56 | +#if defined(_WIN32) | |
57 | + typedef __int64 Int; | |
58 | + typedef unsigned __int64 UInt; | |
59 | +#else | |
60 | + typedef long long Int; | |
61 | + typedef unsigned long long UInt; | |
62 | +#endif | |
63 | +}; | |
64 | + | |
65 | +//====================================================================== | |
66 | +// typedef | |
28 | 67 | typedef void* TestTypeId; |
29 | 68 | |
30 | 69 | typedef void (*SetupMethod)(void); |
31 | 70 | typedef void (*TearDownMethod)(void); |
32 | 71 | |
72 | +typedef type_least_t<8>::UInt TimeInMillsec; | |
73 | + | |
74 | + | |
33 | 75 | } // end of namespace iutest |
34 | 76 | |
35 | 77 | #endif |
@@ -28,60 +28,108 @@ | ||
28 | 28 | |
29 | 29 | //====================================================================== |
30 | 30 | // class |
31 | -class UnitTest | |
31 | +class UnitTestImpl | |
32 | 32 | { |
33 | + friend class UnitTest; | |
33 | 34 | typedef detail::iu_list<TestCase> collection; |
35 | +public: | |
36 | + UnitTestImpl(void) : m_testnum(0) {} | |
34 | 37 | |
35 | 38 | public: |
36 | - static void Run(void) { UnitTestImpl::GetInstance().Run(); } | |
37 | - static void AddInfo(TestCase* pCase, TestInfo* pInfo) { UnitTestImpl::GetInstance().AddInfo(pCase, pInfo); } | |
38 | - | |
39 | -private: | |
40 | - class UnitTestImpl | |
39 | + int Run(void) | |
41 | 40 | { |
42 | - public: | |
43 | - UnitTestImpl(void) : m_testnum(0) {} | |
44 | - | |
45 | - public: | |
46 | - int Run(void) | |
41 | + bool result = true; | |
47 | 42 | { |
48 | - bool result = true; | |
49 | 43 | collection it = m_collection; |
50 | 44 | detail::iuConsole::color_output(detail::iuConsole::green, "[==========] "); |
51 | 45 | detail::iuConsole::output("%d tests from %d testcase\n", m_testnum, m_collection.count() ); |
52 | 46 | while(it != NULL) |
53 | 47 | { |
54 | - if( !it->Run() ) result = false; | |
48 | + if( it->Run() ) | |
49 | + { | |
50 | + result = false; | |
51 | + } | |
55 | 52 | ++it; |
56 | 53 | } |
57 | 54 | detail::iuConsole::color_output(detail::iuConsole::green, "[==========] "); |
58 | 55 | detail::iuConsole::output("%d tests from %d testcase run\n", m_testnum, m_collection.count() ); |
59 | - | |
60 | - return result ? 0 : 1; | |
61 | 56 | } |
62 | 57 | |
63 | - void AddInfo(TestCase* pCase, TestInfo* pInfo) | |
64 | 58 | { |
65 | - collection& list = m_collection; | |
66 | - TestCase* p = list.find(pCase, collection::EqualOp()); | |
67 | - if( p == NULL ) | |
59 | + int passed = 0; | |
60 | + int failed = 0; | |
68 | 61 | { |
69 | - p = pCase; | |
70 | - list.push_back(p); | |
62 | + collection it = m_collection; | |
63 | + while(it != NULL) | |
64 | + { | |
65 | + TestCase::collection it2 = it->m_collection; | |
66 | + while( it2 != NULL ) | |
67 | + { | |
68 | + if( it2->m_result ) | |
69 | + ++passed; | |
70 | + else | |
71 | + ++failed; | |
72 | + ++it2; | |
73 | + } | |
74 | + ++it; | |
75 | + } | |
76 | + detail::iuConsole::color_output(detail::iuConsole::green, "[ PASSED ] "); | |
77 | + detail::iuConsole::output("%d tests.\n", passed ); | |
71 | 78 | } |
72 | - ++m_testnum; | |
73 | - p->push_back(pInfo); | |
79 | + if( failed ) | |
80 | + { | |
81 | + detail::iuConsole::color_output(detail::iuConsole::red, "[ FAILED ] "); | |
82 | + detail::iuConsole::output("%d tests.\n", failed ); | |
83 | + | |
84 | + collection it = m_collection; | |
85 | + while(it != NULL && failed ) | |
86 | + { | |
87 | + TestCase::collection it2 = it->m_collection; | |
88 | + while( it2 != NULL ) | |
89 | + { | |
90 | + if( !it2->m_result ) | |
91 | + { | |
92 | + --failed; | |
93 | + detail::iuConsole::color_output(detail::iuConsole::red, "[ FAILED ] "); | |
94 | + detail::iuConsole::output("%s.%s\n", it2->m_testcase.c_str(), it2->m_testname.c_str()); | |
95 | + } | |
96 | + ++it2; | |
97 | + } | |
98 | + ++it; | |
99 | + } | |
100 | + } | |
74 | 101 | } |
102 | + return result ? 0 : 1; | |
103 | + } | |
75 | 104 | |
76 | - public: | |
77 | - static UnitTestImpl& GetInstance(void) { static UnitTestImpl inst; return inst; } | |
105 | + void AddInfo(TestCase* pCase, TestInfo* pInfo) | |
106 | + { | |
107 | + collection& list = m_collection; | |
108 | + TestCase* p = list.find(pCase, collection::EqualOp()); | |
109 | + if( p == NULL ) | |
110 | + { | |
111 | + p = pCase; | |
112 | + list.push_back(p); | |
113 | + } | |
114 | + ++m_testnum; | |
115 | + p->push_back(pInfo); | |
116 | + } | |
78 | 117 | |
79 | - private: | |
80 | - int m_testnum; | |
81 | - collection m_collection; | |
82 | - }; | |
118 | +public: | |
119 | + static UnitTestImpl& GetInstance(void) { static UnitTestImpl inst; return inst; } | |
120 | + | |
121 | +private: | |
122 | + int m_testnum; | |
123 | + collection m_collection; | |
83 | 124 | }; |
84 | 125 | |
126 | +class UnitTest | |
127 | +{ | |
128 | +public: | |
129 | + static void Run(void) { UnitTestImpl::GetInstance().Run(); } | |
130 | + static void AddInfo(TestCase* pCase, TestInfo* pInfo) { UnitTestImpl::GetInstance().AddInfo(pCase, pInfo); } | |
131 | +}; | |
132 | + | |
85 | 133 | template<class Tester> |
86 | 134 | class TestInstance |
87 | 135 | { |
@@ -25,11 +25,13 @@ | ||
25 | 25 | //====================================================================== |
26 | 26 | // define |
27 | 27 | /** |
28 | + * @internal | |
28 | 29 | * @brief テスト名作成マクロ |
29 | 30 | */ |
30 | 31 | #define IUTEST_TEST_CLASS_NAME_(tester_, testname_) iu_##tester_##_##testname_##_Test |
31 | 32 | |
32 | 33 | /** |
34 | + * @internal | |
33 | 35 | * @brief テストクラス定義マクロ |
34 | 36 | */ |
35 | 37 | #define IUTEST_TEST_(tester_, parent_, testname_) \ |
@@ -44,7 +46,8 @@ | ||
44 | 46 | |
45 | 47 | |
46 | 48 | /** |
47 | - * @brief テスト | |
49 | + * @internal | |
50 | + * @brief ASSERT メッセージ処理 | |
48 | 51 | */ |
49 | 52 | #define ASSERT_FAILER(msg) do { \ |
50 | 53 | IUTEST_BREAK(); \ |
@@ -56,6 +59,22 @@ | ||
56 | 59 | } while(0) |
57 | 60 | |
58 | 61 | |
62 | +/** | |
63 | + * @internal | |
64 | + * @brief EXPECT メッセージ処理 | |
65 | +*/ | |
66 | +#define EXPECT_FAILER(msg) do { \ | |
67 | + IUTEST_BREAK(); \ | |
68 | + iutest::detail::iuConsole::output(__FILE__ ":" IUTEST_PP_TOSTRING(__LINE__) ": "); \ | |
69 | + iutest::detail::iuConsole::output(msg); \ | |
70 | + iutest::detail::iuConsole::output("\n"); \ | |
71 | + iutest::Test::CommitFailed(); \ | |
72 | + } while(0) | |
73 | + | |
74 | +/** | |
75 | + * @internal | |
76 | + * @biref 比較検証マクロ | |
77 | +*/ | |
59 | 78 | #define IUTEST_TEST_IMPL_(comp, on_failer) do { \ |
60 | 79 | const iutest::TestResult tr = (comp); \ |
61 | 80 | if( !tr ) \ |
@@ -63,7 +82,9 @@ | ||
63 | 82 | } while(0) |
64 | 83 | |
65 | 84 | /** |
66 | - * @brief テスト | |
85 | + * @internal | |
86 | + * @brief ASSERT テスト | |
87 | + * @{ | |
67 | 88 | */ |
68 | 89 | #define IUTEST_ASSERT_EQ_(v1, v2) IUTEST_TEST_IMPL_( (iutest::CompareHelperEQ(#v1, #v2, v1, v2)), ASSERT_FAILER) |
69 | 90 | #define IUTEST_ASSERT_NE_(v1, v2) IUTEST_TEST_IMPL_( (iutest::CompareHelperNE(#v1, #v2, v1, v2)), ASSERT_FAILER) |
@@ -75,4 +96,34 @@ | ||
75 | 96 | #define IUTEST_ASSERT_TRUE_(v) IUTEST_TEST_IMPL_( (iutest::CompareHelperTrue(#v, v)) , ASSERT_FAILER) |
76 | 97 | #define IUTEST_ASSERT_FALSE_(v) IUTEST_TEST_IMPL_( (iutest::CompareHelperFalse(#v, v)), ASSERT_FAILER) |
77 | 98 | |
99 | +#define IUTEST_ASSERT_STREQ_(v1, v2) IUTEST_TEST_IMPL_( (iutest::CompareHelperSTREQ(#v1, #v2, v1, v2)), ASSERT_FAILER) | |
100 | +#define IUTEST_ASSERT_STRNE_(v1, v2) IUTEST_TEST_IMPL_( (iutest::CompareHelperSTRNE(#v1, #v2, v1, v2)), ASSERT_FAILER) | |
101 | + | |
102 | +/** | |
103 | + * @} | |
104 | +*/ | |
105 | + | |
106 | +/** | |
107 | + * @internal | |
108 | + * @brief EXPECT テスト | |
109 | + * @{ | |
110 | +*/ | |
111 | +#define IUTEST_EXPECT_EQ_(v1, v2) IUTEST_TEST_IMPL_( (iutest::CompareHelperEQ(#v1, #v2, v1, v2)), EXPECT_FAILER) | |
112 | +#define IUTEST_EXPECT_NE_(v1, v2) IUTEST_TEST_IMPL_( (iutest::CompareHelperNE(#v1, #v2, v1, v2)), EXPECT_FAILER) | |
113 | +#define IUTEST_EXPECT_LE_(v1, v2) IUTEST_TEST_IMPL_( (iutest::CompareHelperLE(#v1, #v2, v1, v2)), EXPECT_FAILER) | |
114 | +#define IUTEST_EXPECT_LT_(v1, v2) IUTEST_TEST_IMPL_( (iutest::CompareHelperLT(#v1, #v2, v1, v2)), EXPECT_FAILER) | |
115 | +#define IUTEST_EXPECT_GE_(v1, v2) IUTEST_TEST_IMPL_( (iutest::CompareHelperGE(#v1, #v2, v1, v2)), EXPECT_FAILER) | |
116 | +#define IUTEST_EXPECT_GT_(v1, v2) IUTEST_TEST_IMPL_( (iutest::CompareHelperGT(#v1, #v2, v1, v2)), EXPECT_FAILER) | |
117 | + | |
118 | +#define IUTEST_EXPECT_TRUE_(v) IUTEST_TEST_IMPL_( (iutest::CompareHelperTrue(#v, v)) , EXPECT_FAILER) | |
119 | +#define IUTEST_EXPECT_FALSE_(v) IUTEST_TEST_IMPL_( (iutest::CompareHelperFalse(#v, v)), EXPECT_FAILER) | |
120 | + | |
121 | +#define IUTEST_EXPECT_STREQ_(v1, v2) IUTEST_TEST_IMPL_( (iutest::CompareHelperSTREQ(#v1, #v2, v1, v2)), EXPECT_FAILER) | |
122 | +#define IUTEST_EXPECT_STRNE_(v1, v2) IUTEST_TEST_IMPL_( (iutest::CompareHelperSTRNE(#v1, #v2, v1, v2)), EXPECT_FAILER) | |
123 | + | |
124 | +/** | |
125 | + * @} | |
126 | +*/ | |
127 | + | |
128 | + | |
78 | 129 | #endif |
@@ -0,0 +1,84 @@ | ||
1 | +//====================================================================== | |
2 | +//----------------------------------------------------------------------- | |
3 | +/** | |
4 | + * @file iutest_stopwatch.h | |
5 | + * @brief iris unit test 時間計測 ファイル | |
6 | + * | |
7 | + * @author t.sirayanagi | |
8 | + * @version 1.0 | |
9 | + * | |
10 | + * @par copyright | |
11 | + * Copyright (C) 2011 Takazumi Shirayanagi\n | |
12 | + * The new BSD License is applied to this software. | |
13 | + * see LICENSE | |
14 | +*/ | |
15 | +//----------------------------------------------------------------------- | |
16 | +//====================================================================== | |
17 | +#ifndef INCG_IRIS_iutest_stopwatch_H_ | |
18 | +#define INCG_IRIS_iutest_stopwatch_H_ | |
19 | + | |
20 | +//====================================================================== | |
21 | +// include | |
22 | +#include <time.h> | |
23 | +#include "iutest_util.h" | |
24 | +#include "../iutest_types.h" | |
25 | + | |
26 | +namespace iutest { | |
27 | +namespace detail | |
28 | +{ | |
29 | + | |
30 | + | |
31 | +//====================================================================== | |
32 | +// class | |
33 | +/** | |
34 | + * @internal | |
35 | + * @brief ストップウォッチクラス | |
36 | +*/ | |
37 | +class iuStopWatch | |
38 | +{ | |
39 | +private: | |
40 | + TimeInMillsec m_begin; | |
41 | +public: | |
42 | + iuStopWatch(void) : m_begin(0) {} | |
43 | + | |
44 | +public: | |
45 | + static TimeInMillsec get_millsec(void) | |
46 | + { | |
47 | +#if defined(_IUTEST_NOT_SUPPORT_STOPWATCH) | |
48 | + return 0; | |
49 | +#else | |
50 | + | |
51 | +#if defined(_IUTEST_SUPPORT_GETTIMEOFDAY) | |
52 | + timeval tv; | |
53 | + gettimeofday(&tv, NULL); | |
54 | + return static_cast<TimeInMillsec>(tv.tv_sec) * 1000 + static_cast<TimeInMillsec>(tv.tv_usec) / 1000; | |
55 | +#elif defined(_IUTEST_SUPPORT_CLOCK) | |
56 | + return clock() * 1000 / CLOCKS_PER_SEC; | |
57 | + | |
58 | +#else | |
59 | + | |
60 | +#if defined(_IUTEST_OS_WINDOWS) | |
61 | + return GetTickCount(); | |
62 | +#else | |
63 | + return 0; | |
64 | +#endif | |
65 | + | |
66 | +#endif | |
67 | + | |
68 | +#endif | |
69 | + } | |
70 | +public: | |
71 | + void start(void) | |
72 | + { | |
73 | + m_begin = get_millsec(); | |
74 | + } | |
75 | + TimeInMillsec stop(void) | |
76 | + { | |
77 | + return get_millsec() - m_begin; | |
78 | + } | |
79 | +}; | |
80 | + | |
81 | +} // end of namespace detail | |
82 | +} // end of namespace iutest | |
83 | + | |
84 | +#endif |
@@ -43,8 +43,21 @@ | ||
43 | 43 | #define IUTEST_PP_TOSTRING(z) IUTEST_PP_TOSTRING_(z) |
44 | 44 | #define IUTEST_PP_TOSTRING_(z) #z |
45 | 45 | |
46 | +#if defined(_WIN32) | |
47 | +# define _IUTEST_OS_WINDOWS | |
48 | +#endif | |
49 | + | |
50 | +#if defined(_IUTEST_OS_WINDOWS) | |
51 | +# if defined(__CYGWIN__) | |
52 | +# include <sys/time.h> | |
53 | +# define _IUTEST_SUPPORT_GETTIMEOFDAY | |
54 | +# endif | |
55 | +#endif | |
56 | + | |
46 | 57 | #if defined(_WIN32_WCE) |
58 | +# define _IUTEST_OS_WINDOWS_MOBILE | |
47 | 59 | # define _IUTEST_NOT_COLORCONSOLE |
60 | +# undef _IUTEST_SUPPORT_GETTIMEOFDAY | |
48 | 61 | #endif |
49 | 62 | |
50 | 63 | namespace iutest { |
@@ -56,6 +69,10 @@ | ||
56 | 69 | |
57 | 70 | //====================================================================== |
58 | 71 | // struct |
72 | +/** | |
73 | + * @internal | |
74 | + * @brief TypeId Generator Implementation | |
75 | +*/ | |
59 | 76 | template<typename TN> |
60 | 77 | struct TestTypeIdHelper { public: static bool _dummy; }; |
61 | 78 |
@@ -66,6 +83,10 @@ | ||
66 | 83 | |
67 | 84 | //====================================================================== |
68 | 85 | // function |
86 | +/** | |
87 | + * @internal | |
88 | + * @brief TypeId Generator | |
89 | +*/ | |
69 | 90 | template<typename TN> |
70 | 91 | TestTypeId GetTestTypeId(void) |
71 | 92 | { |
@@ -72,6 +93,10 @@ | ||
72 | 93 | return &(helper::TestTypeIdHelper<TN>::_dummy); |
73 | 94 | } |
74 | 95 | |
96 | +/** | |
97 | + * @internal | |
98 | + * @brief auto_ptr | |
99 | +*/ | |
75 | 100 | template<typename TN> |
76 | 101 | class auto_ptr |
77 | 102 | { |
@@ -20,7 +20,7 @@ | ||
20 | 20 | //====================================================================== |
21 | 21 | // include |
22 | 22 | #include "iutest_util.h" |
23 | -#if defined(_WIN32) | |
23 | +#if defined(_IUTEST_OS_WINDOWS) | |
24 | 24 | # include <windows.h> |
25 | 25 | #endif |
26 | 26 | #include <stdio.h> |
@@ -37,6 +37,7 @@ | ||
37 | 37 | //====================================================================== |
38 | 38 | // class |
39 | 39 | /** |
40 | + * @internal | |
40 | 41 | * @brief コンソールクラス |
41 | 42 | */ |
42 | 43 | class iuConsole |
@@ -69,7 +70,7 @@ | ||
69 | 70 | #if defined(_IUTEST_NOT_COLORCONSOLE) |
70 | 71 | IUTEST_VPRINTF(fmt, va); |
71 | 72 | #else |
72 | -#if defined(_WIN32) | |
73 | +#if defined(_IUTEST_OS_WINDOWS) | |
73 | 74 | { |
74 | 75 | WORD attr[] = { |
75 | 76 | 0, |
@@ -35,7 +35,8 @@ | ||
35 | 35 | //====================================================================== |
36 | 36 | // class |
37 | 37 | /** |
38 | - * @brief テスト生成クラス | |
38 | + * @internal | |
39 | + * @brief テスト生成クラスインターフェース | |
39 | 40 | */ |
40 | 41 | class iuFactoryBase |
41 | 42 | { |
@@ -42,6 +43,11 @@ | ||
42 | 43 | public: |
43 | 44 | virtual auto_ptr<Test> Create(void) = 0; |
44 | 45 | }; |
46 | + | |
47 | +/** | |
48 | + * @internal | |
49 | + * @brief テスト生成クラス | |
50 | +*/ | |
45 | 51 | template<class Tester> |
46 | 52 | class iuFactory : public iuFactoryBase |
47 | 53 | { |
@@ -26,6 +26,10 @@ | ||
26 | 26 | |
27 | 27 | //====================================================================== |
28 | 28 | // class |
29 | +/** | |
30 | + * @internal | |
31 | + * @brief リストノード | |
32 | +*/ | |
29 | 33 | template<typename TN> |
30 | 34 | class iu_list_node |
31 | 35 | { |
@@ -41,6 +45,10 @@ | ||
41 | 45 | value_ptr operator -> (void) { return next; } |
42 | 46 | }; |
43 | 47 | |
48 | +/** | |
49 | + * @internal | |
50 | + * @brief リストクラス | |
51 | +*/ | |
44 | 52 | template<typename NODE> |
45 | 53 | class iu_list |
46 | 54 | { |
@@ -29,6 +29,9 @@ | ||
29 | 29 | // class |
30 | 30 | class TestCase : public detail::iu_list_node<TestCase> |
31 | 31 | { |
32 | + friend class UnitTest; | |
33 | + friend class UnitTestImpl; | |
34 | + | |
32 | 35 | typedef detail::iu_list<TestInfo> collection; |
33 | 36 | public: |
34 | 37 | TestCase(const char* testcase, TestTypeId id, SetupMethod setup, TearDownMethod teardown) |
@@ -21,6 +21,7 @@ | ||
21 | 21 | // include |
22 | 22 | #include "internal/iutest_factory.h" |
23 | 23 | #include "internal/iutest_console.h" |
24 | +#include "internal/iutest_stopwatch.h" | |
24 | 25 | #include "iutest_types.h" |
25 | 26 | #include <string> |
26 | 27 |
@@ -34,6 +35,8 @@ | ||
34 | 35 | */ |
35 | 36 | class TestInfo : public detail::iu_list_node<TestInfo> |
36 | 37 | { |
38 | + friend class UnitTest; | |
39 | + friend class UnitTestImpl; | |
37 | 40 | public: |
38 | 41 | /** |
39 | 42 | * @brief コンストラクタ |
@@ -60,13 +63,18 @@ | ||
60 | 63 | detail::iuConsole::output("%s.%s\n", m_testcase.c_str(), m_testname.c_str() ); |
61 | 64 | |
62 | 65 | m_result = true; |
66 | + detail::iuStopWatch sw; | |
67 | + TimeInMillsec elapsed = 0; | |
63 | 68 | try |
64 | 69 | { |
65 | 70 | detail::auto_ptr<Test> p = m_factory->Create(); |
71 | + sw.start(); | |
66 | 72 | m_result = p->Run(); |
73 | + elapsed = sw.stop(); | |
67 | 74 | } |
68 | 75 | catch (...) |
69 | 76 | { |
77 | + elapsed = sw.stop(); | |
70 | 78 | m_result = false; |
71 | 79 | } |
72 | 80 |
@@ -73,13 +81,16 @@ | ||
73 | 81 | if( m_result ) |
74 | 82 | { |
75 | 83 | detail::iuConsole::color_output(detail::iuConsole::green, "[ OK ] "); |
76 | - detail::iuConsole::output("%s.%s\n", m_testcase.c_str(), m_testname.c_str() ); | |
77 | 84 | } |
78 | 85 | else |
79 | 86 | { |
80 | 87 | detail::iuConsole::color_output(detail::iuConsole::red, "[ FAILED ] "); |
81 | - detail::iuConsole::output("%s.%s\n", m_testcase.c_str(), m_testname.c_str() ); | |
82 | 88 | } |
89 | +#if defined(_IUTEST_NOT_SUPPORT_STOPWATCH) | |
90 | + detail::iuConsole::output("%s.%s (--ms)\n", m_testcase.c_str(), m_testname.c_str() ); | |
91 | +#else | |
92 | + detail::iuConsole::output("%s.%s (%dms)\n", m_testcase.c_str(), m_testname.c_str(), elapsed ); | |
93 | +#endif | |
83 | 94 | m_should_run = true; |
84 | 95 | |
85 | 96 | return m_result; |
@@ -110,6 +110,18 @@ | ||
110 | 110 | IUTEST_ASSERT_GT(y, x); |
111 | 111 | } |
112 | 112 | |
113 | +IUTEST(TestOp, STREQ) | |
114 | +{ | |
115 | + const char e[] = "test"; | |
116 | + IUTEST_ASSERT_STREQ(e, "test"); | |
117 | +} | |
118 | + | |
119 | +IUTEST(TestOp, STRNE) | |
120 | +{ | |
121 | + const wchar_t e[] = L"test"; | |
122 | + IUTEST_ASSERT_STRNE(e, L"tset"); | |
123 | +} | |
124 | + | |
113 | 125 | #endif |
114 | 126 | |
115 | 127 | #if defined(SHOW_FAILER) // Failer Test |
@@ -142,6 +154,19 @@ | ||
142 | 154 | IUTEST_ASSERT_FALSE(true); |
143 | 155 | } |
144 | 156 | |
157 | +IUTEST(TestExpectFailer, EQ) | |
158 | +{ | |
159 | + IUTEST_EXPECT_EQ(0.1, 1); | |
160 | + IUTEST_EXPECT_NE(0, 0); | |
161 | + IUTEST_EXPECT_LE(2, 0); | |
162 | + IUTEST_EXPECT_LT(0, 0); | |
163 | + IUTEST_EXPECT_GE(0, 2); | |
164 | + IUTEST_EXPECT_GT(0, 0); | |
165 | + IUTEST_EXPECT_TRUE(0); | |
166 | + IUTEST_EXPECT_FALSE(1); | |
167 | +} | |
168 | + | |
169 | + | |
145 | 170 | #endif |
146 | 171 | |
147 | 172 |
@@ -0,0 +1,8 @@ | ||
1 | +doxygen.exe Doxyfile | |
2 | +if errorlevel 1 goto error | |
3 | + | |
4 | +exit | |
5 | + | |
6 | +:error | |
7 | +pause | |
8 | + |
@@ -0,0 +1,8 @@ | ||
1 | +<html> | |
2 | +<head> | |
3 | +<title>マニュアル</title> | |
4 | +</head> | |
5 | +<frameset frameborder=1> | |
6 | +<frame src="html/index.html"></frame> | |
7 | +</frameset> | |
8 | +</html> | |
\ No newline at end of file |