github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/webp/libwebp/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  #include <string>
     9  #include <vector>
    10  
    11  #define INIT(x, y) \
    12  	static void _init_##x##y(void); \
    13  	static TestRegisterer _r_init_##x##y(_init_##x##y, # x "." # y , "init"); \
    14  	static void _init_##x##y(void)
    15  
    16  #define EXIT(x, y) \
    17  	static void _exit_##x##y(void); \
    18  	static TestRegisterer _r_exit_##x##y(_exit_##x##y, # x "." # y , "exit"); \
    19  	static void _exit_##x##y(void)
    20  
    21  #define TEST(x, y) \
    22  	static void _test_##x##y(void); \
    23  	static TestRegisterer _r_test_##x##y(_test_##x##y, # x "." # y , "test"); \
    24  	static void _test_##x##y(void)
    25  
    26  #define BENCH(x, y) \
    27  	static void _bench_##x##y(void); \
    28  	static TestRegisterer _r_bench_##x##y(_bench_##x##y, # x "." # y , "bench"); \
    29  	static void _bench_##x##y(void)
    30  
    31  #define ASSERT_TRUE(x) TestAssertTrue((x), __FILE__, __LINE__, "")
    32  #define ASSERT_EQ(x, y) TestAssertEQ((x), (y), __FILE__, __LINE__, "")
    33  #define ASSERT_STREQ(x, y) TestAssertStrEQ((x), (y), __FILE__, __LINE__, "")
    34  #define ASSERT_NEAR(x, y, abs_error) TestAssertNear((x), (y), (abs_error), __FILE__, __LINE__, "")
    35  
    36  #if !defined(_MSC_VER) || (_MSC_VER >= 1600)
    37  #	define ASSERT_TRUE_MSG(x, fmt, ...) TestAssertTrue((x), __FILE__, __LINE__, (fmt), __VA_ARGS__)
    38  #	define ASSERT_EQ_MSG(x, y, fmt, ...) TestAssertEQ((x), (y), __FILE__, __LINE__, (fmt), __VA_ARGS__)
    39  #	define ASSERT_STREQ_MSG(x, y, fmt, ...) TestAssertStrEQ((x), (y), __FILE__, __LINE__, (fmt), __VA_ARGS__)
    40  #	define ASSERT_NEAR_MSG(x, y, abs_error, fmt, ...) TestAssertNear((x), (y), (abs_error), __FILE__, __LINE__, (fmt), __VA_ARGS__)
    41  #endif
    42  
    43  const std::vector<std::string>& TestArgs();
    44  
    45  void RegisterTest(void (*fn)(void), const char *name, const char *type);
    46  
    47  void TestAssertTrue(bool condition, const char* fname, int lineno, const char* fmt, ...);
    48  void TestAssertEQ(int a, int b, const char* fname, int lineno, const char* fmt, ...);
    49  void TestAssertStrEQ(const char* a, const char* b, const char* fname, int lineno, const char* fmt, ...);
    50  void TestAssertNear(float a, float b, float abs_error, const char* fname, int lineno, const char* fmt, ...);
    51  
    52  int  BenchN();
    53  void BenchResetTimer();
    54  void BenchStartTimer();
    55  void BenchStopTimer();
    56  
    57  struct TestRegisterer {
    58  	TestRegisterer(void (*fn)(void), const char *name, const char* type) {
    59  		RegisterTest(fn, name, type);
    60  	}
    61  };
    62  
    63  #endif  // TEST_H_