nlib
testing.h
[詳解]
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_TESTING_TESTING_H_
4 #define INCLUDE_NN_NLIB_TESTING_TESTING_H_
5 
6 #include "nn/nlib/Config.h"
7 
8 #ifndef NLIB_USE_GTEST
10 #include "nn/nlib/testing/Pred.h"
14 
15 namespace testing = ::nlib_ns::testing;
16 NLIB_NAMESPACE_BEGIN
17 namespace testing {
18 inline void InitGoogleTest(int* argc, char** argv) { InitNintendoTest(argc, argv); }
19 inline void InitGoogleTest(int* argc, wchar_t** argv) { InitNintendoTest(argc, argv); }
20 #define NLIB_TESTING_OSTREAM ::nlib_ns::testing::detail_func::DummyStream
21 } // namespace testing
22 NLIB_NAMESPACE_END
23 #else
24 // See: https://code.google.com/p/googletest/
25 #include "gtest/gtest.h"
26 
27 #define NLIB_TESTING_OSTREAM std::ostream
28 namespace testing {
29 inline void InitNintendoTest(int* argc, char** argv) { InitGoogleTest(argc, argv); }
30 inline void InitNintendoTest(int* argc, wchar_t** argv) { InitGoogleTest(argc, argv); }
31 }
32 
33 #endif
34 
35 #if defined(_MSC_VER) && defined(_PREFAST_)
36 // for /analyze option
37 #include "nn/nlib/Cstring.h"
38 struct MsvcAnalyzeHelper_ {
39  template<class T>
40  MsvcAnalyzeHelper_& operator<<(T x) { return *this; }
41  operator int() const { return 1; }
42 };
43 #undef FAIL
44 #define FAIL() throw MsvcAnalyzeHelper_()
45 #undef SUCCEED
46 #define SUCCEED()
47 
48 #undef ASSERT_TRUE
49 #define ASSERT_TRUE(e) if (!(e)) throw MsvcAnalyzeHelper_()
50 #undef ASSERT_FALSE
51 #define ASSERT_FALSE(e) if (e) throw MsvcAnalyzeHelper_()
52 #undef EXPECT_TRUE
53 #define EXPECT_TRUE(e) if (!(e)) throw MsvcAnalyzeHelper_()
54 #undef EXPECT_FALSE
55 #define EXPECT_FALSE(e) if (e) throw MsvcAnalyzeHelper_()
56 
57 #undef ASSERT_EQ
58 #define ASSERT_EQ(a, b) if (!((a) == (b))) throw MsvcAnalyzeHelper_()
59 #undef EXPECT_EQ
60 #define EXPECT_EQ(a, b) if (!((a) == (b))) throw MsvcAnalyzeHelper_()
61 
62 #undef ASSERT_NE
63 #define ASSERT_NE(a, b) if ((a) == (b)) throw MsvcAnalyzeHelper_()
64 #undef EXPECT_NE
65 #define EXPECT_NE(a, b) if ((a) == (b)) throw MsvcAnalyzeHelper_()
66 
67 #undef ASSERT_LE
68 #define ASSERT_LE(a, b) if ((a) > (b)) throw MsvcAnalyzeHelper_()
69 #undef EXPECT_LE
70 #define EXPECT_LE(a, b) if ((a) > (b)) throw MsvcAnalyzeHelper_()
71 
72 #undef ASSERT_LT
73 #define ASSERT_LT(a, b) if ((a) >= (b)) throw MsvcAnalyzeHelper_()
74 #undef EXPECT_LT
75 #define EXPECT_LT(a, b) if ((a) >= (b)) throw MsvcAnalyzeHelper_()
76 
77 #undef ASSERT_GE
78 #define ASSERT_GE(a, b) if ((a) < (b)) throw MsvcAnalyzeHelper_()
79 #undef EXPECT_GE
80 #define EXPECT_GE(a, b) if ((a) < (b)) throw MsvcAnalyzeHelper_()
81 
82 #undef ASSERT_GT
83 #define ASSERT_GT(a, b) if ((a) <= (b)) throw MsvcAnalyzeHelper_()
84 #undef EXPECT_GT
85 #define EXPECT_GT(a, b) if ((a) <= (b)) throw MsvcAnalyzeHelper_()
86 
87 #undef ASSERT_STREQ
88 #define ASSERT_STREQ(a, b) if (NLIB_NS::StrCmp((a), (b)) != 0) throw MsvcAnalyzeHelper_()
89 #undef EXPECT_STREQ
90 #define EXPECT_STREQ(a, b) if (NLIB_NS::StrCmp((a), (b)) != 0) throw MsvcAnalyzeHelper_()
91 
92 #undef ASSERT_STRNE
93 #define ASSERT_STRNE(a, b) if (NLIB_NS::StrCmp((a), (b)) == 0) throw MsvcAnalyzeHelper_()
94 #undef EXPECT_STRNE
95 #define EXPECT_STRNE(a, b) if (NLIB_NS::StrCmp((a), (b)) == 0) throw MsvcAnalyzeHelper_()
96 
97 #undef ASSERT_STRCASEEQ
98 #define ASSERT_STRCASEEQ(a, b) if (NLIB_NS::StrCmp((a), (b)) != 0) throw MsvcAnalyzeHelper_()
99 #undef EXPECT_STRCASEEQ
100 #define EXPECT_STRCASEEQ(a, b) if (NLIB_NS::StrCmp((a), (b)) != 0) throw MsvcAnalyzeHelper_()
101 
102 #undef ASSERT_STRCASENE
103 #define ASSERT_STRCASENE(a, b) if (NLIB_NS::StrCmp((a), (b)) == 0) throw MsvcAnalyzeHelper_()
104 #undef EXPECT_STRCASENE
105 #define EXPECT_STRCASENE(a, b) if (NLIB_NS::StrCmp((a), (b)) == 0) throw MsvcAnalyzeHelper_()
106 
107 #undef ASSERT_FLOAT_EQ
108 #define ASSERT_FLOAT_EQ(a, b) if ((a) != (b)) throw MsvcAnalyzeHelper_()
109 #undef EXPECT_FLOAT_EQ
110 #define EXPECT_FLOAT_EQ(a, b) if ((a) != (b)) throw MsvcAnalyzeHelper_()
111 
112 #undef ASSERT_DOUBLE_EQ
113 #define ASSERT_DOUBLE_EQ(a, b) if ((a) != (b)) throw MsvcAnalyzeHelper_()
114 #undef EXPECT_DOUBLE_EQ
115 #define EXPECT_DOUBLE_EQ(a, b) if ((a) != (b)) throw MsvcAnalyzeHelper_()
116 
117 #undef ASSERT_NEAR
118 #define ASSERT_NEAR(a, b, c) if (!((a) == (b))) throw MsvcAnalyzeHelper_()
119 #undef EXPECT_NEAR
120 #define EXPECT_NEAR(a, b, c) if (!((a) == (b))) throw MsvcAnalyzeHelper_()
121 
122 #endif
123 
124 
125 #endif // INCLUDE_NN_NLIB_TESTING_TESTING_H_
テスト失敗時の表示を制御します。
値をパラメータ化したテストを定義しています。
void InitNintendoTest(int *argc, char **argv)
テストプログラムのコマンドラインオプションを処理します。
型付けテストを定義しています。
開発環境別の設定が書かれるファイルです。
基本的な単体テスト用マクロが定義されています。
strlen, strcpy等を安全に使えるようにラップしています。
述語アサーションが定義されています。