Revision | 199 (tree) |
---|---|
Time | 2011-10-05 23:13:50 |
Author | shirayanagi |
iutest 更新
+ 大文字小文字区別なし
+ throw
+ 明示的な失敗
@@ -39,6 +39,5 @@ | ||
39 | 39 | srand((unsigned int)time(nullptr)); |
40 | 40 | int argc = ::__argc; |
41 | 41 | GT_INIT(&argc, ::__targv); |
42 | - RUN_ALL_TESTS(); | |
43 | - return 0; | |
42 | + return RUN_ALL_TESTS(); | |
44 | 43 | } |
@@ -9,9 +9,6 @@ | ||
9 | 9 | |
10 | 10 | rem python があるかどうか |
11 | 11 | SET PYTHON=python |
12 | -if not exist c:\cygwin\bin\python.exe ( | |
13 | - SET PYTHON=python2.5.exe | |
14 | -) | |
15 | 12 | %PYTHON% -h > NUL |
16 | 13 | if errorlevel 1 ( |
17 | 14 | goto py_err |
@@ -4,9 +4,6 @@ | ||
4 | 4 | if "x%~1" == "x" SET NPORT=5103 |
5 | 5 | |
6 | 6 | SET PYTHON=python |
7 | -if not exist c:\cygwin\bin\python.exe ( | |
8 | - SET PYTHON=python2.5.exe | |
9 | -) | |
10 | 7 | |
11 | 8 | @echo root:%CD% |
12 | 9 | SET HTTPSERVER_NAME=LocalServer %NPORT% |
@@ -19,11 +19,7 @@ | ||
19 | 19 | |
20 | 20 | SET PYTHONPATH=%NACL_SDK_ROOT%/third_party/scons-2.0.1/engine |
21 | 21 | |
22 | -rem python -> !<symlink>python2.5.exe の実行の仕方がわからない | |
23 | 22 | SET PYTHON=python |
24 | -if not exist c:\cygwin\bin\python.exe ( | |
25 | - SET PYTHON=python2.5.exe | |
26 | -) | |
27 | 23 | %PYTHON% -O -OO "%NACL_SDK_ROOT%/third_party/scons-2.0.1/script/scons" ^ |
28 | 24 | --warn no-visual-c-missing ^ |
29 | 25 | --file=build.scons ^ |
@@ -25,10 +25,10 @@ | ||
25 | 25 | |
26 | 26 | //====================================================================== |
27 | 27 | // define |
28 | -#define IUTEST_VER 0x00030100 //!< iutest version 0.3.1.0 | |
28 | +#define IUTEST_VER 0x00030200 //!< iutest version 0.3.2.0 | |
29 | 29 | #define IUTEST_MAJORVER 0x00 |
30 | 30 | #define IUTEST_MINORVER 0x03 |
31 | -#define IUTEST_BUILD 0x01 | |
31 | +#define IUTEST_BUILD 0x02 | |
32 | 32 | #define IUTEST_REVISION 0x00 |
33 | 33 | |
34 | 34 |
@@ -19,6 +19,7 @@ | ||
19 | 19 | |
20 | 20 | //====================================================================== |
21 | 21 | // include |
22 | +#include "iutest_result.h" | |
22 | 23 | |
23 | 24 | namespace iutest |
24 | 25 | { |
@@ -40,9 +41,31 @@ | ||
40 | 41 | static TestImpl& GetInstance(void) { static TestImpl inst; return inst; } |
41 | 42 | }; |
42 | 43 | public: |
43 | - Test(void) { TestImpl::GetInstance().m_pCurrent = this; } | |
44 | + Test(void) | |
45 | + : m_result(true), m_type(TestResult::eNoFailer) | |
46 | + { TestImpl::GetInstance().m_pCurrent = this; } | |
47 | + | |
44 | 48 | virtual ~Test(void) { TestImpl::GetInstance().m_pCurrent = NULL; } |
45 | 49 | |
50 | +public: | |
51 | + /** | |
52 | + * @brief 致命的なエラーが出たかどうか | |
53 | + * @return 真偽値 | |
54 | + */ | |
55 | + bool HasFatalFailure(void) | |
56 | + { | |
57 | + return m_type == TestResult::eFatalFailer; | |
58 | + } | |
59 | + | |
60 | + /** | |
61 | + * @brief エラーが出たかどうか | |
62 | + * @return 真偽値 | |
63 | + */ | |
64 | + bool HasFailure(void) | |
65 | + { | |
66 | + return m_type != TestResult::eNoFailer; | |
67 | + } | |
68 | + | |
46 | 69 | protected: |
47 | 70 | /** |
48 | 71 | * @brief インターフェース |
@@ -62,9 +85,10 @@ | ||
62 | 85 | /** |
63 | 86 | * @private |
64 | 87 | */ |
65 | - void OnFailer(void) | |
88 | + void OnFailer(TestResult::eType type) | |
66 | 89 | { |
67 | 90 | m_result = false; |
91 | + if( m_type < type ) m_type = type; | |
68 | 92 | } |
69 | 93 | |
70 | 94 | public: |
@@ -78,6 +102,7 @@ | ||
78 | 102 | bool Run(void) |
79 | 103 | { |
80 | 104 | m_result = true; |
105 | + m_type = TestResult::eNoFailer; | |
81 | 106 | SetUp(); |
82 | 107 | Body(); |
83 | 108 | TearDown(); |
@@ -85,16 +110,17 @@ | ||
85 | 110 | } |
86 | 111 | |
87 | 112 | public: |
88 | - static void CommitFailed(void) | |
113 | + static void CommitFailed(TestResult::eType type) | |
89 | 114 | { |
90 | 115 | if( TestImpl::GetInstance().m_pCurrent != NULL ) |
91 | 116 | { |
92 | - TestImpl::GetInstance().m_pCurrent->OnFailer(); | |
117 | + TestImpl::GetInstance().m_pCurrent->OnFailer(type); | |
93 | 118 | } |
94 | 119 | } |
95 | 120 | |
96 | 121 | private: |
97 | 122 | bool m_result; |
123 | + TestResult::eType m_type; | |
98 | 124 | }; |
99 | 125 | |
100 | 126 | /** |
@@ -20,7 +20,9 @@ | ||
20 | 20 | //====================================================================== |
21 | 21 | // include |
22 | 22 | #include "iutest_types.h" |
23 | +#include "internal/iutest_util.h" | |
23 | 24 | #include "internal/iutest_string.h" |
25 | +#include "internal/iutest_console.h" | |
24 | 26 | |
25 | 27 | namespace iutest |
26 | 28 | { |
@@ -32,8 +34,9 @@ | ||
32 | 34 | public: |
33 | 35 | enum eType |
34 | 36 | { |
35 | - eFatalFailer, | |
36 | - eNotFatalFailer | |
37 | + eNoFailer, | |
38 | + eNotFatalFailer, | |
39 | + eFatalFailer | |
37 | 40 | }; |
38 | 41 | private: |
39 | 42 | bool m_result; |
@@ -42,7 +45,7 @@ | ||
42 | 45 | |
43 | 46 | public: |
44 | 47 | TestResult(bool result) : m_result(result) {} |
45 | - TestResult(const TestResult& rhs) : m_result(rhs.m_result), m_message(rhs.m_message.c_str()) {} | |
48 | + TestResult(const TestResult& rhs) : m_result(rhs.m_result), m_message(rhs.m_message) {} | |
46 | 49 | |
47 | 50 | const char* message(void) const { return m_message.c_str(); } |
48 | 51 |
@@ -132,6 +135,35 @@ | ||
132 | 135 | << "\n actual : " << val2 << "\n Expected: " << val1 ; |
133 | 136 | } |
134 | 137 | |
138 | +static TestResult CompareHelperSTRCASEEQ(const char* expr1, const char* expr2 | |
139 | + , const char* val1, const char* val2) | |
140 | +{ | |
141 | + if( iutest_stricmp(val1, val2) == 0 ) return TestResult::Success(); | |
142 | + return TestResult::Failure() << "error: Value of: " << expr1 << " == " << expr2 | |
143 | + << "\n actual : " << val2 << "\n Expected: " << val1 ; | |
144 | +} | |
145 | +static TestResult CompareHelperSTRCASEEQ(const char* expr1, const char* expr2 | |
146 | + , const wchar_t* val1, const wchar_t* val2) | |
147 | +{ | |
148 | + if( iutest_wcsicmp(val1, val2) == 0 ) return TestResult::Success(); | |
149 | + return TestResult::Failure() << "error: Value of: " << expr1 << " == " << expr2 | |
150 | + << "\n actual : " << val2 << "\n Expected: " << val1 ; | |
151 | +} | |
152 | +static TestResult CompareHelperSTRCASENE(const char* expr1, const char* expr2 | |
153 | + , const char* val1, const char* val2) | |
154 | +{ | |
155 | + if( iutest_stricmp(val1, val2) != 0 ) return TestResult::Success(); | |
156 | + return TestResult::Failure() << "error: Value of: " << expr1 << " != " << expr2 | |
157 | + << "\n actual : " << val2 << "\n Expected: " << val1 ; | |
158 | +} | |
159 | +static TestResult CompareHelperSTRCASENE(const char* expr1, const char* expr2 | |
160 | + , const wchar_t* val1, const wchar_t* val2) | |
161 | +{ | |
162 | + if( iutest_wcsicmp(val1, val2) != 0 ) return TestResult::Success(); | |
163 | + return TestResult::Failure() << "error: Value of: " << expr1 << " != " << expr2 | |
164 | + << "\n actual : " << val2 << "\n Expected: " << val1 ; | |
165 | +} | |
166 | + | |
135 | 167 | static TestResult CompareHelperSTRLNEQ(const char* expr1, const char* expr2 |
136 | 168 | , size_t len1, const char* val2) |
137 | 169 | { |
@@ -13,6 +13,9 @@ | ||
13 | 13 | * see LICENSE |
14 | 14 | * |
15 | 15 | * @par release note |
16 | + * @li v0.3.2.0 : 大文字小文字区別しない文字列の比較テストマクロを追加\n | |
17 | + * 例外キャッチテストマクロを追加\n | |
18 | + * 明示的な失敗マクロを追加\n | |
16 | 19 | * @li v0.3.1.0 : public でないマクロのプリフィクス名を変更\n |
17 | 20 | * IUTEST_***_PRED* マクロを追加\n |
18 | 21 | * IUTEST_ASSERT_STRLNEQ マクロを追加\n |
@@ -47,7 +50,6 @@ | ||
47 | 50 | //====================================================================== |
48 | 51 | // include |
49 | 52 | #include "iutest_ver.h" |
50 | -#include "iutest_result.h" | |
51 | 53 | #include "iutest_core.h" |
52 | 54 | #include "iutest_params.h" |
53 | 55 |
@@ -204,6 +206,21 @@ | ||
204 | 206 | |
205 | 207 | /** |
206 | 208 | * @ingroup IUTEST_ASSERT_ |
209 | + * @brief 文字列の一致(大文字小文字区別なし) テスト | |
210 | +*/ | |
211 | +#ifndef IUTEST_ASSERT_STRCASEEQ | |
212 | +# define IUTEST_ASSERT_STRCASEEQ(v1, v2) IIUT_ASSERT_STRCASEEQ_(v1, v2) | |
213 | +#endif | |
214 | +/** | |
215 | + * @ingroup IUTEST_ASSERT_ | |
216 | + * @brief 文字列の不一致(大文字小文字区別なし) テスト | |
217 | +*/ | |
218 | +#ifndef IUTEST_ASSERT_STRCASENE | |
219 | +# define IUTEST_ASSERT_STRCASENE(v1, v2) IIUT_ASSERT_STRCASENE_(v1, v2) | |
220 | +#endif | |
221 | + | |
222 | +/** | |
223 | + * @ingroup IUTEST_ASSERT_ | |
207 | 224 | * @brief 文字列長の一致 テスト |
208 | 225 | */ |
209 | 226 | #ifndef IUTEST_ASSERT_STRLNEQ |
@@ -225,9 +242,44 @@ | ||
225 | 242 | # define IUTEST_ASSERT_HRESULT_FAILED(hr) IIUT_ASSERT_HRESULT_FAILED_(hr) |
226 | 243 | #endif |
227 | 244 | |
245 | +#if !defined(IUTEST_NOT_SUPPORT_EXCEPTION) | |
228 | 246 | |
247 | +/** | |
248 | + * @ingroup IUTEST_ASSERT_ | |
249 | + * @brief throw テスト | |
250 | +*/ | |
251 | +#ifndef IUTEST_ASSERT_THROW | |
252 | +# define IUTEST_ASSERT_THROW(statement, expected_exception) IIUT_ASSERT_THROW(statement, expected_exception) | |
253 | +#endif | |
229 | 254 | |
230 | 255 | /** |
256 | + * @ingroup IUTEST_ASSERT_ | |
257 | + * @brief any throw テスト | |
258 | +*/ | |
259 | +#ifndef IUTEST_ASSERT_ANY_THROW | |
260 | +# define IUTEST_ASSERT_ANY_THROW(statement) IIUT_ASSERT_ANY_THROW(statement) | |
261 | +#endif | |
262 | + | |
263 | +/** | |
264 | + * @ingroup IUTEST_ASSERT_ | |
265 | + * @brief no throw テスト | |
266 | +*/ | |
267 | +#ifndef IUTEST_ASSERT_NO_THROW | |
268 | +# define IUTEST_ASSERT_NO_THROW(statement) IIUT_ASSERT_NO_THROW(statement) | |
269 | +#endif | |
270 | + | |
271 | +/** | |
272 | + * @ingroup IUTEST_ASSERT_ | |
273 | + * @brief 明示的な失敗 | |
274 | +*/ | |
275 | +#ifndef IUTEST_ASSERT_FAIL | |
276 | +# define IUTEST_ASSERT_FAIL() IIUT_FAIL() | |
277 | +#endif | |
278 | + | |
279 | + | |
280 | +#endif | |
281 | + | |
282 | +/** | |
231 | 283 | * @defgroup IUTEST_EXPECT_ |
232 | 284 | * @brief テスト記述マクロ |
233 | 285 | * @details 失敗した場合でも、テストを続行します。 |
@@ -352,5 +404,49 @@ | ||
352 | 404 | # define IUTEST_EXPECT_HRESULT_FAILED(hr) IIUT_EXPECT_HRESULT_FAILED_(hr) |
353 | 405 | #endif |
354 | 406 | |
407 | +#if !defined(IUTEST_NOT_SUPPORT_EXCEPTION) | |
355 | 408 | |
409 | +/** | |
410 | + * @ingroup IUTEST_EXPECT_ | |
411 | + * @brief throw テスト | |
412 | +*/ | |
413 | +#ifndef IUTEST_EXPECT_THROW | |
414 | +# define IUTEST_EXPECT_THROW(statement, expected_exception) IIUT_EXPECT_THROW(statement, expected_exception) | |
356 | 415 | #endif |
416 | + | |
417 | +/** | |
418 | + * @ingroup IUTEST_EXPECT_ | |
419 | + * @brief no throw テスト | |
420 | +*/ | |
421 | +#ifndef IUTEST_EXPECT_ANY_THROW | |
422 | +# define IUTEST_EXPECT_ANY_THROW(statement) IIUT_EXPECT_ANY_THROW(statement) | |
423 | +#endif | |
424 | + | |
425 | +/** | |
426 | + * @ingroup IUTEST_EXPECT_ | |
427 | + * @brief no throw テスト | |
428 | +*/ | |
429 | +#ifndef IUTEST_EXPECT_NO_THROW | |
430 | +# define IUTEST_EXPECT_NO_THROW(statement) IIUT_EXPECT_NO_THROW(statement) | |
431 | +#endif | |
432 | + | |
433 | +/** | |
434 | + * @ingroup IUTEST_EXPECT_ | |
435 | + * @brief 明示的な失敗 | |
436 | +*/ | |
437 | +#ifndef IUTEST_EXPECT_FAIL | |
438 | +# define IUTEST_EXPECT_FAIL() IIUT_ADD_FAILURE() | |
439 | +#endif | |
440 | + | |
441 | +/** | |
442 | + * @ingroup IUTEST_EXPECT_ | |
443 | + * @brief 明示的な失敗 | |
444 | +*/ | |
445 | +#ifndef IUTEST_EXPECT_FAIL_AT | |
446 | +# define IUTEST_EXPECT_FAIL_AT(file, line) IIUT_ADD_FAILURE_AT(file, line) | |
447 | +#endif | |
448 | + | |
449 | +#endif | |
450 | + | |
451 | + | |
452 | +#endif |
@@ -0,0 +1,62 @@ | ||
1 | +//====================================================================== | |
2 | +//----------------------------------------------------------------------- | |
3 | +/** | |
4 | + * @file iutest_assertion.h | |
5 | + * @brief iris unit test assertion 定義 ファイル | |
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_assertion_H_ | |
18 | +#define INCG_IRIS_iutest_assertion_H_ | |
19 | + | |
20 | +//====================================================================== | |
21 | +// include | |
22 | +#include "iutest_body.h" | |
23 | + | |
24 | +namespace iutest | |
25 | +{ | |
26 | + | |
27 | +/** | |
28 | + * @brief Assertion 構築クラス | |
29 | +*/ | |
30 | +class AssertionHelper | |
31 | +{ | |
32 | +public: | |
33 | + class Fixed { | |
34 | + }; | |
35 | +private: | |
36 | + const char* m_file; | |
37 | + int m_line; | |
38 | + std::string m_message; | |
39 | + TestResult::eType m_type; | |
40 | +public: | |
41 | + AssertionHelper(const char* file, int line, const char* message, TestResult::eType type) | |
42 | + : m_file(file) | |
43 | + , m_line(line) | |
44 | + , m_message(message) | |
45 | + , m_type(type) | |
46 | + { | |
47 | + } | |
48 | +public: | |
49 | + AssertionHelper& operator = (const Fixed&) | |
50 | + { | |
51 | + detail::iuConsole::output(m_file); | |
52 | + detail::iuConsole::output(":%d: ", m_line); | |
53 | + detail::iuConsole::output(m_message.c_str()); | |
54 | + detail::iuConsole::output("\n"); | |
55 | + Test::CommitFailed(m_type); | |
56 | + return *this; | |
57 | + } | |
58 | +}; | |
59 | + | |
60 | +} // end of namespace iutest | |
61 | + | |
62 | +#endif |
@@ -20,7 +20,7 @@ | ||
20 | 20 | //====================================================================== |
21 | 21 | // include |
22 | 22 | #include "internal/iutest_internal.h" |
23 | -#include "iutest_body.h" | |
23 | +#include "iutest_assertion.h" | |
24 | 24 | #include "iutest_case.h" |
25 | 25 | |
26 | 26 | namespace iutest |
@@ -75,14 +75,20 @@ | ||
75 | 75 | |
76 | 76 | /** |
77 | 77 | * @internal |
78 | + * @brief ASSERTION メッセージ処理 | |
79 | +*/ | |
80 | +#define IUTEST_MESSAGE_AT(file_, line_, msg_, result_type_) iutest::AssertionHelper(file_, line_, msg_, result_type_) = iutest::AssertionHelper::Fixed() | |
81 | +#define IUTEST_MESSAGE(msg_, result_type_) IUTEST_MESSAGE_AT(__FILE__, __LINE__, msg_, result_type_) | |
82 | + | |
83 | +/** | |
84 | + * @internal | |
78 | 85 | * @brief ASSERT メッセージ処理 |
79 | 86 | */ |
80 | -#define IUTEST_ASSERT_FAILER(msg) do { \ | |
87 | +#define IUTEST_ASSERT_FAILER(msg) IUTEST_ASSERT_FAILER_AT(msg, __FILE__, __LINE__) | |
88 | + | |
89 | +#define IUTEST_ASSERT_FAILER_AT(msg, file, line) do { \ | |
81 | 90 | IUTEST_BREAK(); \ |
82 | - iutest::detail::iuConsole::output(__FILE__ ":" IUTEST_PP_TOSTRING(__LINE__) ": "); \ | |
83 | - iutest::detail::iuConsole::output(msg); \ | |
84 | - iutest::detail::iuConsole::output("\n"); \ | |
85 | - iutest::Test::CommitFailed(); \ | |
91 | + IUTEST_MESSAGE_AT(file, line, msg, iutest::TestResult::eFatalFailer); \ | |
86 | 92 | IUTEST_THROW(iutest::TestResult::eFatalFailer); \ |
87 | 93 | } while(0) |
88 | 94 |
@@ -91,12 +97,11 @@ | ||
91 | 97 | * @internal |
92 | 98 | * @brief EXPECT メッセージ処理 |
93 | 99 | */ |
94 | -#define IUTEST_EXPECT_FAILER(msg) do { \ | |
95 | - IUTEST_BREAK(); \ | |
96 | - iutest::detail::iuConsole::output(__FILE__ ":" IUTEST_PP_TOSTRING(__LINE__) ": "); \ | |
97 | - iutest::detail::iuConsole::output(msg); \ | |
98 | - iutest::detail::iuConsole::output("\n"); \ | |
99 | - iutest::Test::CommitFailed(); \ | |
100 | +#define IUTEST_EXPECT_FAILER(msg) IUTEST_EXPECT_FAILER_AT(msg, __FILE__, __LINE__) | |
101 | + | |
102 | +#define IUTEST_EXPECT_FAILER_AT(msg, file, line) do { \ | |
103 | + IUTEST_BREAK(); \ | |
104 | + IUTEST_MESSAGE_AT(file, line, msg, iutest::TestResult::eNotFatalFailer); \ | |
100 | 105 | } while(0) |
101 | 106 | |
102 | 107 | /** |
@@ -109,10 +114,70 @@ | ||
109 | 114 | on_failer(tr.message()); \ |
110 | 115 | } while(0) |
111 | 116 | |
117 | + | |
118 | +#if !defined(IUTEST_NOT_SUPPORT_EXCEPTION) | |
119 | +/** | |
120 | + * @internal | |
121 | + * @brief throw テスト用マクロ | |
122 | +*/ | |
123 | +#define IUTEST_TEST_THROW_(statement, expected_exception, on_failer) do { \ | |
124 | + iutest::TestResult result = iutest::TestResult::Success(); \ | |
125 | + try { \ | |
126 | + statement; \ | |
127 | + result = iutest::TestResult::Failure() << "\nExpected: " #statement " throws an exception of type " \ | |
128 | + #expected_exception ".\n Actual: it throws nothing."; \ | |
129 | + } catch( expected_exception const& ) { \ | |
130 | + } catch( ... ) { \ | |
131 | + result = iutest::TestResult::Failure() << "\nExpected: " #statement " throws an exception of type " \ | |
132 | + #expected_exception ".\n Actual: it throws a different type."; \ | |
133 | + } \ | |
134 | + IUTEST_TEST_ASSERT_(result, on_failer); \ | |
135 | + } while(0) | |
136 | + | |
137 | +/** | |
138 | + * @internal | |
139 | + * @brief any throw テスト用マクロ | |
140 | +*/ | |
141 | +#define IUTEST_TEST_ANY_THROW_(statement, on_failer) do { \ | |
142 | + iutest::TestResult result = iutest::TestResult::Success(); \ | |
143 | + try { \ | |
144 | + statement; \ | |
145 | + result = iutest::TestResult::Failure() << "\nExpected: " #statement \ | |
146 | + " throws an exception.\n Actual: it doesn's throws."; \ | |
147 | + } catch( ... ) { \ | |
148 | + } \ | |
149 | + IUTEST_TEST_ASSERT_(result, on_failer); \ | |
150 | + } while(0) | |
151 | + | |
152 | +/** | |
153 | + * @internal | |
154 | + * @brief no throw テスト用マクロ | |
155 | +*/ | |
156 | +#define IUTEST_TEST_NO_THROW_(statement, on_failer) do { \ | |
157 | + iutest::TestResult result = iutest::TestResult::Success(); \ | |
158 | + try { \ | |
159 | + statement; \ | |
160 | + } catch( ... ) { \ | |
161 | + result = iutest::TestResult::Failure() << "\nExpected: " #statement \ | |
162 | + " doesn't throw an exception.\n Actual: it throws."; \ | |
163 | + } \ | |
164 | + IUTEST_TEST_ASSERT_(result, on_failer); \ | |
165 | + } while(0) | |
166 | + | |
167 | +#endif | |
168 | + | |
112 | 169 | #include "iutest_pred.h" |
113 | 170 | |
114 | 171 | /** |
115 | 172 | * @internal |
173 | + * @brief 明示的な失敗 | |
174 | +*/ | |
175 | +#define IIUT_FAIL() IUTEST_ASSERT_FAILER("Failed") | |
176 | +#define IIUT_ADD_FAILURE() IUTEST_EXPECT_FAILER("Failed") | |
177 | +#define IIUT_ADD_FAILURE_AT(file_, line_) IUTEST_EXPECT_FAILER_AT("Failed", file_, line_) | |
178 | + | |
179 | +/** | |
180 | + * @internal | |
116 | 181 | * @brief ASSERT テスト |
117 | 182 | * @{ |
118 | 183 | */ |
@@ -133,6 +198,8 @@ | ||
133 | 198 | |
134 | 199 | #define IIUT_ASSERT_STREQ_(v1, v2) IUTEST_ASSERT_PRED_FORMAT2( iutest::CompareHelperSTREQ, v1, v2 ) |
135 | 200 | #define IIUT_ASSERT_STRNE_(v1, v2) IUTEST_ASSERT_PRED_FORMAT2( iutest::CompareHelperSTRNE, v1, v2 ) |
201 | +#define IIUT_ASSERT_STRCASEEQ_(v1, v2) IUTEST_ASSERT_PRED_FORMAT2( iutest::CompareHelperSTRCASEEQ, v1, v2 ) | |
202 | +#define IIUT_ASSERT_STRCASENE_(v1, v2) IUTEST_ASSERT_PRED_FORMAT2( iutest::CompareHelperSTRCASENE, v1, v2 ) | |
136 | 203 | |
137 | 204 | #define IIUT_ASSERT_STRLNEQ_(len, v2) IUTEST_ASSERT_PRED_FORMAT2( iutest::CompareHelperSTRLNEQ, len, v2 ) |
138 | 205 |
@@ -139,6 +206,14 @@ | ||
139 | 206 | #define IIUT_ASSERT_HRESULT_SUCCEEDED_(hr) IUTEST_ASSERT_PRED_FORMAT1( iutest::CompareHelperHRTrue , hr ) |
140 | 207 | #define IIUT_ASSERT_HRESULT_FAILED_(hr) IUTEST_ASSERT_PRED_FORMAT1( iutest::CompareHelperHRFalse, hr ) |
141 | 208 | |
209 | +#if !defined(IUTEST_NOT_SUPPORT_EXCEPTION) | |
210 | + | |
211 | +#define IIUT_ASSERT_THROW(statement, expected_exception) IUTEST_TEST_THROW_(statement, expected_exception, IUTEST_ASSERT_FAILER) | |
212 | +#define IIUT_ASSERT_ANY_THROW(statement) IUTEST_TEST_ANY_THROW_(statement, IUTEST_ASSERT_FAILER) | |
213 | +#define IIUT_ASSERT_NO_THROW(statement) IUTEST_TEST_NO_THROW_(statement, IUTEST_ASSERT_FAILER) | |
214 | + | |
215 | +#endif | |
216 | + | |
142 | 217 | /** |
143 | 218 | * @} |
144 | 219 | */ |
@@ -165,6 +240,8 @@ | ||
165 | 240 | |
166 | 241 | #define IIUT_EXPECT_STREQ_(v1, v2) IUTEST_EXPECT_PRED_FORMAT2( iutest::CompareHelperSTREQ, v1, v2 ) |
167 | 242 | #define IIUT_EXPECT_STRNE_(v1, v2) IUTEST_EXPECT_PRED_FORMAT2( iutest::CompareHelperSTRNE, v1, v2 ) |
243 | +#define IIUT_EXPECT_STRCASEEQ_(v1, v2) IUTEST_EXPECT_PRED_FORMAT2( iutest::CompareHelperSTRCASEEQ, v1, v2 ) | |
244 | +#define IIUT_EXPECT_STRCASENE_(v1, v2) IUTEST_EXPECT_PRED_FORMAT2( iutest::CompareHelperSTRCASENE, v1, v2 ) | |
168 | 245 | |
169 | 246 | #define IIUT_EXPECT_STRLNEQ_(len, v2) IUTEST_EXPECT_PRED_FORMAT2( iutest::CompareHelperSTRLNEQ, len, v2 ) |
170 | 247 |
@@ -171,6 +248,14 @@ | ||
171 | 248 | #define IIUT_EXPECT_HRESULT_SUCCEEDED_(hr) IUTEST_EXPECT_PRED_FORMAT1( iutest::CompareHelperHRTrue , hr ) |
172 | 249 | #define IIUT_EXPECT_HRESULT_FAILED_(hr) IUTEST_EXPECT_PRED_FORMAT1( iutest::CompareHelperHRFalse, hr ) |
173 | 250 | |
251 | +#if !defined(IUTEST_NOT_SUPPORT_EXCEPTION) | |
252 | + | |
253 | +#define IIUT_EXPECT_THROW(statement, expected_exception) IUTEST_TEST_THROW_(statement, expected_exception, IUTEST_EXPECT_FAILER) | |
254 | +#define IIUT_EXPECT_ANY_THROW(statement) IUTEST_TEST_ANY_THROW_(statement, IUTEST_EXPECT_FAILER) | |
255 | +#define IIUT_EXPECT_NO_THROW(statement) IUTEST_TEST_NO_THROW_(statement, IUTEST_EXPECT_FAILER) | |
256 | + | |
257 | +#endif | |
258 | + | |
174 | 259 | /** |
175 | 260 | * @} |
176 | 261 | */ |
@@ -43,6 +43,15 @@ | ||
43 | 43 | #define IUTEST_PP_TOSTRING(z) IUTEST_PP_TOSTRING_(z) |
44 | 44 | #define IUTEST_PP_TOSTRING_(z) #z |
45 | 45 | |
46 | +#if defined(_MSC_VER) | |
47 | +# define iutest_stricmp _stricmp | |
48 | +# define iutest_wcsicmp _wcsicmp | |
49 | +#else | |
50 | +# define iutest_stricmp stricmp | |
51 | +# define iutest_wcsicmp wcsicmp | |
52 | +#endif | |
53 | + | |
54 | + | |
46 | 55 | namespace iutest { |
47 | 56 | namespace detail |
48 | 57 | { |
@@ -20,7 +20,6 @@ | ||
20 | 20 | //====================================================================== |
21 | 21 | // include |
22 | 22 | #include "iutest_info.h" |
23 | -#include "internal/iutest_console.h" | |
24 | 23 | |
25 | 24 | namespace iutest |
26 | 25 | { |
@@ -11,7 +11,7 @@ | ||
11 | 11 | |
12 | 12 | int main(int argc, const char* argv[]) |
13 | 13 | { |
14 | - IUTEST_RUN_ALL_TESTS(); // run all | |
14 | + return IUTEST_RUN_ALL_TESTS(); // run all | |
15 | 15 | } |
16 | 16 | |
17 | 17 | //#define SHOW_FAILER |
@@ -194,8 +194,36 @@ | ||
194 | 194 | IUTEST_ASSERT_PRED2(IsGreater, 3, 1); |
195 | 195 | } |
196 | 196 | |
197 | +#if !defined(IUTEST_NOT_SUPPORT_EXCEPTION) | |
198 | + | |
199 | +static void Exception(int i) | |
200 | +{ | |
201 | + switch( i ) | |
202 | + { | |
203 | + case 0: | |
204 | + return; | |
205 | + case 1: | |
206 | + throw 2; | |
207 | + break; | |
208 | + case 2: | |
209 | + throw std::bad_exception(); | |
210 | + break; | |
211 | + default: | |
212 | + break; | |
213 | + } | |
214 | +} | |
215 | + | |
216 | +IUTEST(TestOp, Exception) | |
217 | +{ | |
218 | + IUTEST_ASSERT_THROW(Exception(2), std::bad_exception); | |
219 | + IUTEST_ASSERT_ANY_THROW(Exception(1)); | |
220 | + IUTEST_ASSERT_NO_THROW(Exception(0)); | |
221 | +} | |
222 | + | |
197 | 223 | #endif |
198 | 224 | |
225 | +#endif | |
226 | + | |
199 | 227 | #if defined(SHOW_FAILER) // Failer Test |
200 | 228 | |
201 | 229 |
@@ -226,6 +254,11 @@ | ||
226 | 254 | IUTEST_ASSERT_FALSE(true); |
227 | 255 | } |
228 | 256 | |
257 | +IUTEST(TestFailer, Fail) | |
258 | +{ | |
259 | + IUTEST_ASSERT_FAIL(); | |
260 | +} | |
261 | + | |
229 | 262 | IUTEST(TestExpectFailer, Pred) |
230 | 263 | { |
231 | 264 | int x=4, y=5, z=6; |
@@ -233,6 +266,15 @@ | ||
233 | 266 | IUTEST_EXPECT_PRED2(IsGreater, x, y); |
234 | 267 | } |
235 | 268 | |
269 | +#if !defined(IUTEST_NOT_SUPPORT_EXCEPTION) | |
270 | +IUTEST(TestExpectFailer, Exception) | |
271 | +{ | |
272 | + IUTEST_EXPECT_THROW(Exception(0), int); | |
273 | + IUTEST_EXPECT_ANY_THROW(Exception(0)); | |
274 | + IUTEST_EXPECT_NO_THROW(Exception(2)); | |
275 | +} | |
276 | +#endif | |
277 | + | |
236 | 278 | IUTEST(TestExpectFailer, Mix) |
237 | 279 | { |
238 | 280 | IUTEST_EXPECT_EQ(0.1, 1); |
@@ -246,6 +288,7 @@ | ||
246 | 288 | IUTEST_EXPECT_FLOAT_EQ(0.0f, 0.1f); |
247 | 289 | IUTEST_EXPECT_DOUBLE_EQ(0.0, 0.1); |
248 | 290 | IUTEST_EXPECT_NEAR(0, 100, 2); |
291 | + IUTEST_EXPECT_FAIL(); | |
249 | 292 | } |
250 | 293 | |
251 | 294 |