github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/database/leveldb.chai2010/capi/test/test.h (about) 1 // Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #ifndef TEST_H_ 6 #define TEST_H_ 7 8 #define TEST(x, y) \ 9 void x##y(void); \ 10 TestRegisterer r##x##y(x##y, # x "." # y); \ 11 void x##y(void) 12 13 void RegisterTest(void (*fn)(void), const char *tname); 14 void TestAssertTrue(bool condition, const char* fname, int lineno); 15 void TestAssertEQ(int a, int b, const char* fname, int lineno); 16 void TestAssertStrEQ(const char* a, const char* b, const char* fname, int lineno); 17 void TestAssertNear(float a, float b, float abs_error, const char* fname, int lineno); 18 19 struct TestRegisterer { 20 TestRegisterer(void (*fn)(void), const char *s) { 21 RegisterTest(fn, s); 22 } 23 }; 24 25 #define DIM(x) (sizeof(x)/sizeof((x)[0])) 26 #define ASSERT_TRUE(x) TestAssertTrue((x), __FILE__, __LINE__) 27 #define ASSERT_EQ(x, y) TestAssertEQ((x), (y), __FILE__, __LINE__) 28 #define ASSERT_STREQ(x, y)TestAssertStrEQ((x), (y), __FILE__, __LINE__) 29 #define ASSERT_NEAR(x, y, abs_error) TestAssertNear((x), (y), (abs_error), __FILE__, __LINE__) 30 31 #endif // TEST_H_