16 #ifndef INCLUDE_NN_NLIB_TESTING_TESTING_H_ 17 #define INCLUDE_NN_NLIB_TESTING_TESTING_H_ 21 #ifndef NLIB_USE_GTEST 28 namespace testing = ::nlib_ns::testing;
31 inline void InitGoogleTest(
int* argc,
char** argv) {
34 inline void InitGoogleTest(
int* argc,
wchar_t** argv) {
37 #define NLIB_TESTING_OSTREAM ::nlib_ns::testing::detail_func::DummyStream 42 #include "gtest/gtest.h" 44 #define NLIB_TESTING_OSTREAM std::ostream 47 InitGoogleTest(argc, argv);
50 InitGoogleTest(argc, argv);
57 #define EXPECT_ERR(e1, e2) EXPECT_STREQ(nlib_error_string(e1), nlib_error_string(e2)) 58 #define ASSERT_ERR(e1, e2) ASSERT_STREQ(nlib_error_string(e1), nlib_error_string(e2)) 59 #define EXPECT_NOERR(e) EXPECT_STREQ("OK", nlib_error_string(e)) 60 #define ASSERT_NOERR(e) ASSERT_STREQ("OK", nlib_error_string(e)) 79 #define NLIB_CONCAT_(sym, l) sym##l 80 #define NLIB_CONCAT(sym, l) NLIB_CONCAT_(sym, l) 82 #define EXPECT_ERR(e1, e2) \ 86 if (::nlib_ns::testing::NlibErrHelper NLIB_CONCAT(noerr, l) = \ 87 ::nlib_ns::testing::NlibErrHelper(e1, e2)) \ 90 EXPECT_STREQ(nlib_error_string(NLIB_CONCAT(noerr, l).GetE1()), \ 91 nlib_error_string(NLIB_CONCAT(noerr, l).GetE2())) 93 #define ASSERT_ERR(e1, e2) \ 97 if (::nlib_ns::testing::NlibErrHelper NLIB_CONCAT(noerr, l) = \ 98 ::nlib_ns::testing::NlibErrHelper(e1, e2)) \ 101 ASSERT_STREQ(nlib_error_string(NLIB_CONCAT(noerr, l).GetE1()), \ 102 nlib_error_string(NLIB_CONCAT(noerr, l).GetE2())) 104 #define EXPECT_NOERR(e) \ 108 if (::nlib_ns::testing::NlibErrHelper NLIB_CONCAT(noerr, l) = \ 109 ::nlib_ns::testing::NlibErrHelper(0, e)) \ 112 EXPECT_STREQ("OK", nlib_error_string(NLIB_CONCAT(noerr, l).GetE2())) 114 #define ASSERT_NOERR(e) \ 118 if (::nlib_ns::testing::NlibErrHelper NLIB_CONCAT(noerr, l) = \ 119 ::nlib_ns::testing::NlibErrHelper(0, e)) \ 122 ASSERT_STREQ("OK", nlib_error_string(NLIB_CONCAT(noerr, l).GetE2())) 126 #if defined(_MSC_VER) && defined(_PREFAST_) 129 struct MsvcAnalyzeHelper_ {
131 MsvcAnalyzeHelper_& operator<<(T x) {
134 operator int()
const {
return 1; }
137 #define FAIL() throw MsvcAnalyzeHelper_() 142 #define ASSERT_TRUE(e) \ 143 if (!(e)) throw MsvcAnalyzeHelper_() 145 #define ASSERT_FALSE(e) \ 146 if (e) throw MsvcAnalyzeHelper_() 148 #define EXPECT_TRUE(e) \ 149 if (!(e)) throw MsvcAnalyzeHelper_() 151 #define EXPECT_FALSE(e) \ 152 if (e) throw MsvcAnalyzeHelper_() 155 #define ASSERT_EQ(a, b) \ 156 if (!((a) == (b))) throw MsvcAnalyzeHelper_() 158 #define EXPECT_EQ(a, b) \ 159 if (!((a) == (b))) throw MsvcAnalyzeHelper_() 162 #define ASSERT_NE(a, b) \ 163 if ((a) == (b)) throw MsvcAnalyzeHelper_() 165 #define EXPECT_NE(a, b) \ 166 if ((a) == (b)) throw MsvcAnalyzeHelper_() 169 #define ASSERT_LE(a, b) \ 170 if ((a) > (b)) throw MsvcAnalyzeHelper_() 172 #define EXPECT_LE(a, b) \ 173 if ((a) > (b)) throw MsvcAnalyzeHelper_() 176 #define ASSERT_LT(a, b) \ 177 if ((a) >= (b)) throw MsvcAnalyzeHelper_() 179 #define EXPECT_LT(a, b) \ 180 if ((a) >= (b)) throw MsvcAnalyzeHelper_() 183 #define ASSERT_GE(a, b) \ 184 if ((a) < (b)) throw MsvcAnalyzeHelper_() 186 #define EXPECT_GE(a, b) \ 187 if ((a) < (b)) throw MsvcAnalyzeHelper_() 190 #define ASSERT_GT(a, b) \ 191 if ((a) <= (b)) throw MsvcAnalyzeHelper_() 193 #define EXPECT_GT(a, b) \ 194 if ((a) <= (b)) throw MsvcAnalyzeHelper_() 197 #define ASSERT_STREQ(a, b) \ 198 if (NLIB_NS::StrCmp((a), (b)) != 0) throw MsvcAnalyzeHelper_() 200 #define EXPECT_STREQ(a, b) \ 201 if (NLIB_NS::StrCmp((a), (b)) != 0) throw MsvcAnalyzeHelper_() 204 #define ASSERT_STRNE(a, b) \ 205 if (NLIB_NS::StrCmp((a), (b)) == 0) throw MsvcAnalyzeHelper_() 207 #define EXPECT_STRNE(a, b) \ 208 if (NLIB_NS::StrCmp((a), (b)) == 0) throw MsvcAnalyzeHelper_() 210 #undef ASSERT_STRCASEEQ 211 #define ASSERT_STRCASEEQ(a, b) \ 212 if (NLIB_NS::StrCmp((a), (b)) != 0) throw MsvcAnalyzeHelper_() 213 #undef EXPECT_STRCASEEQ 214 #define EXPECT_STRCASEEQ(a, b) \ 215 if (NLIB_NS::StrCmp((a), (b)) != 0) throw MsvcAnalyzeHelper_() 217 #undef ASSERT_STRCASENE 218 #define ASSERT_STRCASENE(a, b) \ 219 if (NLIB_NS::StrCmp((a), (b)) == 0) throw MsvcAnalyzeHelper_() 220 #undef EXPECT_STRCASENE 221 #define EXPECT_STRCASENE(a, b) \ 222 if (NLIB_NS::StrCmp((a), (b)) == 0) throw MsvcAnalyzeHelper_() 224 #undef ASSERT_FLOAT_EQ 225 #define ASSERT_FLOAT_EQ(a, b) \ 226 if ((a) != (b)) throw MsvcAnalyzeHelper_() 227 #undef EXPECT_FLOAT_EQ 228 #define EXPECT_FLOAT_EQ(a, b) \ 229 if ((a) != (b)) throw MsvcAnalyzeHelper_() 231 #undef ASSERT_DOUBLE_EQ 232 #define ASSERT_DOUBLE_EQ(a, b) \ 233 if ((a) != (b)) throw MsvcAnalyzeHelper_() 234 #undef EXPECT_DOUBLE_EQ 235 #define EXPECT_DOUBLE_EQ(a, b) \ 236 if ((a) != (b)) throw MsvcAnalyzeHelper_() 239 #define ASSERT_NEAR(a, b, c) \ 240 if (!((a) == (b))) throw MsvcAnalyzeHelper_() 242 #define EXPECT_NEAR(a, b, c) \ 243 if (!((a) == (b))) throw MsvcAnalyzeHelper_() 247 #endif // INCLUDE_NN_NLIB_TESTING_TESTING_H_
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
void InitNintendoTest(int *argc, char **argv)
テストプログラムのコマンドラインオプションを処理します。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
strlen, strcpy等を安全に使えるようにラップしています。