9 #define TEST_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
10 #if (TEST_GCC_VERSION >= 29600)
11 #define test_likely(x) __builtin_expect((long)((bool)(x)),1)
12 #define test_unlikely(x) __builtin_expect((long)((bool)(x)),0)
14 #define test_likely(x) x
15 #define test_unlikely(x) x
18 #define test_likely(x) x
19 #define test_unlikely(x) x
28 unsigned char c[
sizeof(T)];
32 static bool unittest_isNAN(T num){
38 for(
size_t i = 0; i <
sizeof(T); ++i){
39 if (orig.c[i] != sig_nan.c[i]){
44 if (isNAN)
return true;
48 for(
size_t i = 0; i <
sizeof(T); ++i){
49 if (orig.c[i] != quiet_nan.c[i]){
58 static void SelfCheck(
void);
59 static void PushFailure(
const std::string & fail);
60 static void PushSuccess(
const std::string & pass);
61 static void echo_(
const std::string & out);
62 static std::string ToString(
void);
63 static std::string ToHTML(
void);
64 static void SaveTo(
const std::string & location);
65 static void SetReturnOnFail(
bool option);
66 static bool GetReturnOnFail(
void);
67 static void SetEcho(
bool option);
68 static void SetPrefix(
const std::string & prefix);
69 static std::string GetPrefix(
void);
70 static void StartTime(
void);
71 static inline bool _floatsAreEqual(
const double & one,
const double & two){
72 return (one > two) ? (one - two) < .000001 : (one - two) > -.000001;
77 std::string pre = UnitTest::GetPrefix();\
78 if (test_unlikely(pre.empty())){\
79 std::stringstream out;\
80 out << __FILE__ << ":" << __LINE__;\
87 UnitTest::PushFailure(pre + std::string(stri));\
88 if (UnitTest::GetReturnOnFail()) return;
92 UnitTest::PushSuccess(pre + std::string(stri));\
94 #define assertUnitTest()\
95 UnitTest::SelfCheck();
97 #define assertTrue(cond)\
98 if (test_unlikely(!(cond))){\
104 #define assertFalse(cond)\
105 if (test_unlikely(cond)){\
111 #define assertTrue_Primitive(cond, leftside, rightside)\
112 if (test_unlikely(!(cond))){\
113 std::stringstream unit_out;\
115 unit_out << ", Left side: " << leftside;\
116 unit_out << ", Right side: " << rightside;\
117 FAIL(unit_out.str());\
123 #define assertNAN(type, one)\
125 type val = (type)one;\
126 std::string lag(#one);\
127 lag += " not a number";\
128 if (test_likely(unittest_isNAN<type>(one))){\
135 #define assertFloatEquals(one, two)\
136 assertTrue(UnitTest::_floatsAreEqual(one, two))
138 #define assertEquals(one, two)\
139 assertTrue((one) == (two))
141 #define assertNotEquals(one, two)\
142 assertTrue((one) != (two))
144 #define assertGreaterThan(one, two)\
145 assertTrue((one) > (two))
147 #define assertGreaterThanEqualTo(one, two)\
148 assertTrue((one) >= (two))
150 #define assertLessThan(one, two)\
151 assertTrue((one) < (two))
153 #define assertLessThanEqualTo(one, two)\
154 assertTrue((one) <= (two))
158 #define assertEquals_Primitive(one, two)\
159 assertTrue_Primitive((one) == (two), one, two)
161 #define assertNotEquals_Primitive(one, two)\
162 assertTrue_Primitive((one) != (two), one, two)
164 #define assertGreaterThan_Primitive(one, two)\
165 assertTrue_Primitive((one) > (two), one, two)
167 #define assertGreaterThanEqualTo_Primitive(one, two)\
168 assertTrue_Primitive((one) >= (two), one, two)
170 #define assertLessThan_Primitive(one, two)\
171 assertTrue_Primitive((one) < (two), one, two)
173 #define assertLessThanEqualTo_Primitive(one, two)\
174 assertTrue_Primitive((one) <= (two), one, two)
176 #define assertNull(one)\
177 assertTrue(one == NULL);
179 #define assertNotNull(one)\
180 assertTrue(one != NULL);
182 #define assertCStringEquals(one, two)\
183 if (test_unlikely(strcmp(one, two))){\
184 FAIL(std::string(#one) + "==" + #two);\
186 PASS(std::string(#one) + "==" + #two);\
189 #define assertCStringNotEquals(one, two)\
190 if (test_unlikely(!strcmp(one, two))){\
191 FAIL(std::string(#one) + "!=" + #two);\
193 PASS(std::string(#one) + "!=" + #two);\
196 #define assertCStringEqualsW(one, two)\
197 if (test_unlikely(wcscmp(one, two))){\
198 FAIL(std::string(#one) + "==" + #two);\
200 PASS(std::string(#one) + "==" + #two);\
203 #define assertCStringNotEqualsW(one, two)\
204 if (test_unlikely(!wcscmp(one, two))){\
205 FAIL(std::string(#one) + "!=" + #two);\
207 PASS(std::string(#one) + "!=" + #two);\
210 #define assertException(code, exc)\
212 bool failed = false;\
216 PASS(std::string(#exc) + " caught");\
219 if (test_unlikely(!failed)){ FAIL(std::string(#exc) + " not caught");}\
222 #define echo(something)\
224 std::stringstream somet;\
226 UnitTest::echo_(somet.str());\
Definition: UnitTest.h:56
Definition: UnitTest.h:25