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) {
InitNintendoTest(argc, argv); }
32 inline void InitGoogleTest(
int* argc,
wchar_t** argv) {
InitNintendoTest(argc, argv); }
33 #define NLIB_TESTING_OSTREAM ::nlib_ns::testing::detail_func::DummyStream 38 #include "gtest/gtest.h" 40 #define NLIB_TESTING_OSTREAM std::ostream 42 inline void InitNintendoTest(
int* argc,
char** argv) { InitGoogleTest(argc, argv); }
43 inline void InitNintendoTest(
int* argc,
wchar_t** argv) { InitGoogleTest(argc, argv); }
49 #define EXPECT_ERR(e1, e2) EXPECT_STREQ(nlib_error_string(e1), nlib_error_string(e2)) 50 #define ASSERT_ERR(e1, e2) ASSERT_STREQ(nlib_error_string(e1), nlib_error_string(e2)) 51 #define EXPECT_NOERR(e) EXPECT_STREQ("OK", nlib_error_string(e)) 52 #define ASSERT_NOERR(e) ASSERT_STREQ("OK", nlib_error_string(e)) 70 #define NLIB_CONCAT_(sym, l) sym##l 71 #define NLIB_CONCAT(sym, l) NLIB_CONCAT_(sym, l) 73 #define EXPECT_ERR(e1, e2) \ 77 if (::nlib_ns::testing::NlibErrHelper NLIB_CONCAT(noerr, l) = \ 78 ::nlib_ns::testing::NlibErrHelper(e1, e2)) \ 81 EXPECT_STREQ(nlib_error_string(NLIB_CONCAT(noerr, l).GetE1()), \ 82 nlib_error_string(NLIB_CONCAT(noerr, l).GetE2())) 85 #define ASSERT_ERR(e1, e2) \ 89 if (::nlib_ns::testing::NlibErrHelper NLIB_CONCAT(noerr, l) = \ 90 ::nlib_ns::testing::NlibErrHelper(e1, e2)) \ 93 ASSERT_STREQ(nlib_error_string(NLIB_CONCAT(noerr, l).GetE1()), \ 94 nlib_error_string(NLIB_CONCAT(noerr, l).GetE2())) 96 #define EXPECT_NOERR(e) \ 100 if (::nlib_ns::testing::NlibErrHelper NLIB_CONCAT(noerr, l) = \ 101 ::nlib_ns::testing::NlibErrHelper(0, e)) \ 104 EXPECT_STREQ("OK", nlib_error_string(NLIB_CONCAT(noerr, l).GetE2())) 106 #define ASSERT_NOERR(e) \ 110 if (::nlib_ns::testing::NlibErrHelper NLIB_CONCAT(noerr, l) = \ 111 ::nlib_ns::testing::NlibErrHelper(0, e)) \ 114 ASSERT_STREQ("OK", nlib_error_string(NLIB_CONCAT(noerr, l).GetE2())) 118 #if defined(_MSC_VER) && defined(_PREFAST_) 121 struct MsvcAnalyzeHelper_ {
123 MsvcAnalyzeHelper_& operator<<(T x) {
return *
this; }
124 operator int()
const {
return 1; }
127 #define FAIL() throw MsvcAnalyzeHelper_() 132 #define ASSERT_TRUE(e) if (!(e)) throw MsvcAnalyzeHelper_() 134 #define ASSERT_FALSE(e) if (e) throw MsvcAnalyzeHelper_() 136 #define EXPECT_TRUE(e) if (!(e)) throw MsvcAnalyzeHelper_() 138 #define EXPECT_FALSE(e) if (e) throw MsvcAnalyzeHelper_() 141 #define ASSERT_EQ(a, b) if (!((a) == (b))) throw MsvcAnalyzeHelper_() 143 #define EXPECT_EQ(a, b) if (!((a) == (b))) throw MsvcAnalyzeHelper_() 146 #define ASSERT_NE(a, b) if ((a) == (b)) throw MsvcAnalyzeHelper_() 148 #define EXPECT_NE(a, b) if ((a) == (b)) throw MsvcAnalyzeHelper_() 151 #define ASSERT_LE(a, b) if ((a) > (b)) throw MsvcAnalyzeHelper_() 153 #define EXPECT_LE(a, b) if ((a) > (b)) throw MsvcAnalyzeHelper_() 156 #define ASSERT_LT(a, b) if ((a) >= (b)) throw MsvcAnalyzeHelper_() 158 #define EXPECT_LT(a, b) if ((a) >= (b)) throw MsvcAnalyzeHelper_() 161 #define ASSERT_GE(a, b) if ((a) < (b)) throw MsvcAnalyzeHelper_() 163 #define EXPECT_GE(a, b) if ((a) < (b)) throw MsvcAnalyzeHelper_() 166 #define ASSERT_GT(a, b) if ((a) <= (b)) throw MsvcAnalyzeHelper_() 168 #define EXPECT_GT(a, b) if ((a) <= (b)) throw MsvcAnalyzeHelper_() 171 #define ASSERT_STREQ(a, b) if (NLIB_NS::StrCmp((a), (b)) != 0) throw MsvcAnalyzeHelper_() 173 #define EXPECT_STREQ(a, b) if (NLIB_NS::StrCmp((a), (b)) != 0) throw MsvcAnalyzeHelper_() 176 #define ASSERT_STRNE(a, b) if (NLIB_NS::StrCmp((a), (b)) == 0) throw MsvcAnalyzeHelper_() 178 #define EXPECT_STRNE(a, b) if (NLIB_NS::StrCmp((a), (b)) == 0) throw MsvcAnalyzeHelper_() 180 #undef ASSERT_STRCASEEQ 181 #define ASSERT_STRCASEEQ(a, b) if (NLIB_NS::StrCmp((a), (b)) != 0) throw MsvcAnalyzeHelper_() 182 #undef EXPECT_STRCASEEQ 183 #define EXPECT_STRCASEEQ(a, b) if (NLIB_NS::StrCmp((a), (b)) != 0) throw MsvcAnalyzeHelper_() 185 #undef ASSERT_STRCASENE 186 #define ASSERT_STRCASENE(a, b) if (NLIB_NS::StrCmp((a), (b)) == 0) throw MsvcAnalyzeHelper_() 187 #undef EXPECT_STRCASENE 188 #define EXPECT_STRCASENE(a, b) if (NLIB_NS::StrCmp((a), (b)) == 0) throw MsvcAnalyzeHelper_() 190 #undef ASSERT_FLOAT_EQ 191 #define ASSERT_FLOAT_EQ(a, b) if ((a) != (b)) throw MsvcAnalyzeHelper_() 192 #undef EXPECT_FLOAT_EQ 193 #define EXPECT_FLOAT_EQ(a, b) if ((a) != (b)) throw MsvcAnalyzeHelper_() 195 #undef ASSERT_DOUBLE_EQ 196 #define ASSERT_DOUBLE_EQ(a, b) if ((a) != (b)) throw MsvcAnalyzeHelper_() 197 #undef EXPECT_DOUBLE_EQ 198 #define EXPECT_DOUBLE_EQ(a, b) if ((a) != (b)) throw MsvcAnalyzeHelper_() 201 #define ASSERT_NEAR(a, b, c) if (!((a) == (b))) throw MsvcAnalyzeHelper_() 203 #define EXPECT_NEAR(a, b, c) if (!((a) == (b))) throw MsvcAnalyzeHelper_() 208 #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等を安全に使えるようにラップしています。