オープンソース・ソフトウェアの開発とダウンロード

Subversion リポジトリの参照

Contents of /trunk/include/iutest_spi.hpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1443 - (show annotations) (download) (as text)
Sat Sep 3 12:44:07 2022 UTC (21 months ago) by srz_zumix
File MIME type: text/x-c++hdr
File size: 9363 byte(s)
Merge pull request #679 from srz-zumix/develop

Develop
git@1a5e5ea7ec123d3d90d4d0165c89faf4d285da29
https://github.com/srz-zumix/iutest/commit/1a5e5ea7ec123d3d90d4d0165c89faf4d285da29
---------------
Merge remote-tracking branch 'origin/develop'

git@953f9adfa059990885e5ec9211b256528d1717d8

---------------
fix gtest head (wa) (#652)


git@76d490c61419e6eb853548434bc78f1ec7cc3bab

---------------
Merge remote-tracking branch 'origin/develop'

git@a312dc550a658aa7857d3f60ef26f033f10e371c

---------------
update version

git@5baa060f947c27d8f93a0ae2148855650caa5d85

---------------
Merge pull request #650 from srz-zumix/circleci/machine_ubuntu-2004-current

machine ubuntu-2004:current
git@17b939c4d82a909aa2ad6df38ebdb24bcdef146d

---------------
machine ubuntu-2004:current

git@a713897dbd56b1d54b5aed84d124165923b7d13d

---------------
fix iwyu (#647)


git@e56ae1a288b2f2ecf177b21cdfddfd6fb5c0c18a

---------------
Merge pull request #649 from srz-zumix/feature/checkout@v3

checkout@v3
git@0ddaf4f939898567bbf3e4343dbf063f9ca8a971

---------------
Merge pull request #648 from srz-zumix/feature/remove_shippable_badge

remove shippable badge
git@893da50104ce734c17ba65c1aa7c5d75da0cc15c

---------------
checkout@v3

git@33cd92eddf79de839aa6ac520f9fbd196f73760d

---------------
remove shippable badge

git@0a5e8f99a0df7180c1e7dda43c5ae5a2eebc37b4

---------------
fix AzurePipelines set-locale (#645)


git@e444f55f04ad83ca233f434ca2a8c695136e1a04

---------------
Merge remote-tracking branch 'origin/develop'

git@55ee55537b1b3c1af8d09373e2a6414391594d95

---------------
travisci focal and gcc -fanalyzer (#644)


git@81c68b20757fdbae57c4751ffeeebe81e60863be

---------------
pre-configuration gcc -fanalyzer (#564)


git@a0cb0ff60fcbe99e37677079b7fa98ece3d84263

---------------
CentOS EoL (#641)


git@f4c5ea9373310dbd2e8d1abd7c7aad7f9d56e7e2

---------------
update wandbox compiler (#634)


git@68808e35b786e56161aa51d18a464f0e1f23e8ca

---------------
update buddy workspace (#637)


git@7d59f6e77353d7835795b6668fde7d3d540e8239

---------------
Merge pull request #640 from srz-zumix/fix/googletest_compat

fix googletest setup testcase failure comaptible
git@67dfd73cecda10d61aeef20f0c30cf89378784ca

---------------
Merge pull request #639 from srz-zumix/feature/auto_labeler

add labeler
git@b58611be73f882cff185722d28964fec99d69e8a

---------------
fix googletest setup testcase failure comaptible

git@588600c116dfbb8937833735dfb81e3ac8364ad5

---------------
add labeler

git@c4c5c7397c25274ced6e5f1aa850373606cca3b5

---------------
Merge remote-tracking branch 'origin/develop'

git@53cba19a2ae6cffa6376b54b3f7292e8ca9d9866

---------------
Merge pull request #632 from srz-zumix/feature/fix_inferconfig

fix reviewdog-action-infer
git@416b2e15da2ff9103136cde620330166615278e7

---------------
fix rename

git@f5cbe58587d907fea1e83fd3657b75a3e58720d3


1 //======================================================================
2 //-----------------------------------------------------------------------
3 /**
4 * @file iutest_spi.hpp
5 * @brief iris unit test spi 対応用 ファイル
6 *
7 * @author t.shirayanagi
8 * @par copyright
9 * Copyright (C) 2012-2022, Takazumi Shirayanagi\n
10 * This software is released under the new BSD License,
11 * see LICENSE
12 */
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_SPI_HPP_
16 #define INCG_IRIS_IUTEST_SPI_HPP_
17
18 //======================================================================
19 // include
20 // IWYU pragma: begin_exports
21 #include "iutest.hpp"
22 // IWYU pragma: end_exports
23
24 #if !defined(IUTEST_USE_GTEST)
25
26 #if defined(_MSC_VER) && !defined(__clang__)
27 // /ZI オプションだと __LINE__ が __LINE__Var+N(Nは番号) になりコンパイルエラーになるための対応
28 # ifndef __LINE__Var
29 # define __LINE__Var 0
30 # endif
31 #endif
32
33 //======================================================================
34 // define
35 /**
36 * @ingroup IUTEST_ASSERT_
37 * @brief Fatal Failure 発生確認テスト
38 */
39 #define IUTEST_ASSERT_FATAL_FAILURE(statement, substr) \
40 IUTEST_TEST_FATAL_FAILURE_(statement, #statement, substr, IUTEST_ASSERT_FAILURE)
41
42 /**
43 * @ingroup IUTEST_ASSERT_
44 * @brief Non Fatal Failure 発生確認テスト
45 */
46 #define IUTEST_ASSERT_NONFATAL_FAILURE(statement, substr) \
47 IUTEST_TEST_NONFATAL_FAILURE_(statement, #statement, substr, IUTEST_ASSERT_FAILURE)
48
49 /**
50 * @ingroup IUTEST_EXPECT_
51 * @brief Fatal Failure 発生確認テスト
52 */
53 #define IUTEST_EXPECT_FATAL_FAILURE(statement, substr) \
54 IUTEST_TEST_FATAL_FAILURE_(statement, #statement, substr, IUTEST_EXPECT_FAILURE)
55
56 /**
57 * @ingroup IUTEST_EXPECT_
58 * @brief Non Fatal Failure 発生確認テスト
59 */
60 #define IUTEST_EXPECT_NONFATAL_FAILURE(statement, substr) \
61 IUTEST_TEST_NONFATAL_FAILURE_(statement, #statement, substr, IUTEST_EXPECT_FAILURE)
62
63
64 /**
65 * @private
66 * @{
67 */
68
69 #if IUTEST_HAS_SPI_LAMBDA_SUPPORT
70
71 #if IUTEST_HAS_EXCEPTIONS && IUTEST_USE_THROW_ON_ASSERTION_FAILURE
72 # define IIUT_SPI_STATEMENT_EXECUTER(statement) [&](){ try { \
73 ::iutest::detail::ScopedSPITestFlag guard; \
74 statement; \
75 } catch(...) {} \
76 }()
77 #else
78 # define IIUT_SPI_STATEMENT_EXECUTER(statement) \
79 [&](){ ::iutest::detail::ScopedSPITestFlag guard; statement; }()
80 #endif
81
82 #define IUTEST_TEST_FATAL_FAILURE_(statement, text, substr, on_failure) \
83 IUTEST_AMBIGUOUS_ELSE_BLOCKER_ \
84 if( ::iutest::AssertionResult iutest_spi_ar = [&]() -> ::iutest::AssertionResult { \
85 ::iutest::detail::SPIFailureChecker iutest_failure_checker(::iutest::TestPartResult::kFatalFailure); \
86 IIUT_SPI_STATEMENT_EXECUTER(statement); \
87 return iutest_failure_checker.GetResult(substr); \
88 }() ) \
89 ; \
90 else \
91 on_failure(iutest_spi_ar.message())
92
93 #define IUTEST_TEST_NONFATAL_FAILURE_(statement, text, substr, on_failure) \
94 IUTEST_AMBIGUOUS_ELSE_BLOCKER_ \
95 if( ::iutest::AssertionResult iutest_spi_ar = [&]() -> ::iutest::AssertionResult { \
96 ::iutest::detail::SPIFailureChecker iutest_failure_checker(::iutest::TestPartResult::kNonFatalFailure); \
97 IIUT_SPI_STATEMENT_EXECUTER(statement); \
98 return iutest_failure_checker.GetResult(substr); \
99 }() ) \
100 ; \
101 else \
102 on_failure(iutest_spi_ar.message())
103
104 #else
105
106 #if IUTEST_HAS_EXCEPTIONS && IUTEST_USE_THROW_ON_ASSERTION_FAILURE
107 # define IIUT_SPI_STATEMENT_EXECUTER(statement) struct IUTestFatalFailureStatement { \
108 static void Execute() { ::iutest::detail::ScopedSPITestFlag guard; \
109 try { statement; } catch(...) {} } \
110 }; \
111 IUTestFatalFailureStatement::Execute()
112 #else
113 # define IIUT_SPI_STATEMENT_EXECUTER(statement) struct IUTestFatalFailureStatement { \
114 static void Execute() { ::iutest::detail::ScopedSPITestFlag guard; statement; } \
115 }; \
116 IUTestFatalFailureStatement::Execute()
117 #endif
118
119 #define IUTEST_TEST_FATAL_FAILURE_(statement, text, substr, on_failure) \
120 IUTEST_AMBIGUOUS_ELSE_BLOCKER_ \
121 if( ::iutest::AssertionResult iutest_spi_ar = ::iutest::AssertionSuccess() ) { \
122 ::iutest::detail::SPIFailureChecker iutest_failure_checker(::iutest::TestPartResult::kFatalFailure); \
123 IIUT_SPI_STATEMENT_EXECUTER(statement); \
124 ::iutest::AssertionResult ar = iutest_failure_checker.GetResult(substr); \
125 if( !ar ) { \
126 iutest_spi_ar << ar.message(); \
127 goto IUTEST_PP_CAT(iutest_label_test_fatalfailure_, __LINE__); \
128 } \
129 } else \
130 IUTEST_PP_CAT(iutest_label_test_fatalfailure_, __LINE__): \
131 on_failure(iutest_spi_ar.message())
132
133 #define IUTEST_TEST_NONFATAL_FAILURE_(statement, text, substr, on_failure) \
134 IUTEST_AMBIGUOUS_ELSE_BLOCKER_ \
135 if( ::iutest::AssertionResult iutest_spi_ar = ::iutest::AssertionSuccess() ) { \
136 ::iutest::detail::SPIFailureChecker iutest_failure_checker(::iutest::TestPartResult::kNonFatalFailure); \
137 IIUT_SPI_STATEMENT_EXECUTER(statement); \
138 ::iutest::AssertionResult ar = iutest_failure_checker.GetResult(substr); \
139 if( !ar ) { \
140 iutest_spi_ar << ar.message(); \
141 goto IUTEST_PP_CAT(iutest_label_test_fatalfailure_, __LINE__); \
142 } \
143 } else \
144 IUTEST_PP_CAT(iutest_label_test_fatalfailure_, __LINE__): \
145 on_failure(iutest_spi_ar.message())
146
147 // IUTEST_SUPPRESS_UNREACHABLE_CODE_WARNING(statement);
148
149 #endif
150
151 /**
152 * @}
153 */
154
155 namespace iutest {
156 namespace detail
157 {
158
159 //======================================================================
160 // class
161
162 /**
163 * @brief SPI チェッカー
164 */
165 class SPIFailureChecker
166 : public NewTestPartResultCheckHelper::Collector<NoTestPartResultReporter>
167 {
168 public:
169 explicit SPIFailureChecker(TestPartResult::Type type) : m_Type(type) {}
170 public:
171 AssertionResult GetResult(const ::std::string& substr)
172 {
173 const char* expected =
174 (m_Type == TestPartResult::kFatalFailure) ? "1 fatal failure" : "1 non-fatal failure";
175 const size_t num = count();
176 if( num != 1 )
177 {
178 AssertionResult ar = AssertionFailure() << "error: Expected: " << expected
179 << "\n Actual: " << num << " failures\n";
180 for( size_t i=0; i < num; ++i )
181 {
182 ar << GetTestPartResult(i);
183 }
184 return ar;
185 }
186
187 const TestPartResult& tr = GetTestPartResult(0);
188 if( tr.type() != m_Type )
189 {
190 return AssertionFailure() << "error: Expected: " << expected
191 << "\"\n Actual:\n" << tr;
192 }
193
194 if( strstr(tr.message(), substr.c_str()) == NULL )
195 {
196 return AssertionFailure() << "error: Expected: " << expected
197 << " containing \"" << substr
198 << "\"\n Actual:\n" << tr;
199 }
200 return AssertionSuccess();
201 }
202 private:
203 TestPartResult::Type m_Type;
204 };
205
206 /**
207 * @brief フラグ変更スコープ
208 */
209 class ScopedSPITestFlag : public TestFlag::ScopedGuard
210 {
211 public:
212 ScopedSPITestFlag()
213 {
214 IUTEST_FLAG(throw_on_failure) = false;
215 IUTEST_FLAG(break_on_failure) = false;
216 }
217 };
218
219 } // end of namespace detail
220 } // end of namespace iutest
221
222 #else
223
224 #include "gtest/iutest_spi_switch.hpp"
225
226 #endif
227
228 #endif // INCG_IRIS_IUTEST_SPI_HPP_

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26