Go to the documentation of this file.
10 #ifndef TEST_MACROS_H_
11 #define TEST_MACROS_H_
20 # ifndef WIN32_LEAN_AND_MEAN
21 # define WIN32_LEAN_AND_MEAN
26 #ifdef UTILS_TEST_MACRO_TEST_ENABLE_GTEST
27 # include "gtest/gtest.h"
29 # define CASE_TEST(test_name, case_name) TEST(test_name, case_name)
31 # define CASE_EXPECT_TRUE(c) EXPECT_TRUE(c)
32 # define CASE_EXPECT_FALSE(c) EXPECT_FALSE(c)
33 # define CASE_EXPECT_EQ(l, r) EXPECT_EQ(l, r)
34 # define CASE_EXPECT_NE(l, r) EXPECT_NE(l, r)
35 # define CASE_EXPECT_LT(l, r) EXPECT_LT(l, r)
36 # define CASE_EXPECT_LE(l, r) EXPECT_LE(l, r)
37 # define CASE_EXPECT_GT(l, r) EXPECT_GT(l, r)
38 # define CASE_EXPECT_GE(l, r) EXPECT_GE(l, r)
43 # define test_case_func_name(test_name, case_name) test_func_test_##test_name##_case_##case_name##_
44 # define test_case_obj_name(test_name, case_name) test_obj_test_##test_name##_case_##case_name##_
46 # define CASE_TEST(test_name, case_name) \
47 static void test_case_func_name(test_name, case_name)(); \
48 static test_case_base test_case_obj_name(test_name, case_name)(#test_name, #case_name, \
49 test_case_func_name(test_name, case_name)); \
50 void test_case_func_name(test_name, case_name)()
52 # define test_event_on_start_func_name(event_name) test_func_event_on_start_##event_name##_
53 # define test_event_on_start_obj_name(event_name) test_obj_event_on_start_##event_name##_
54 # define test_event_on_exit_func_name(event_name) test_func_event_on_exit_##event_name##_
55 # define test_event_on_exit_obj_name(event_name) test_obj_event_on_exit_##event_name##_
58 # define CASE_TEST_EVENT_ON_START(event_name, ...) \
59 static void test_event_on_start_func_name(event_name)(); \
60 static test_on_start_base test_event_on_start_obj_name(event_name)( \
61 #event_name, test_event_on_start_func_name(event_name), __VA_ARGS__); \
62 void test_event_on_start_func_name(event_name)()
64 # define CASE_TEST_EVENT_ON_EXIT(event_name, ...) \
65 static void test_event_on_exit_func_name(event_name)(); \
66 static test_on_exit_base test_event_on_exit_obj_name(event_name)( \
67 #event_name, test_event_on_exit_func_name(event_name), __VA_ARGS__); \
68 void test_event_on_exit_func_name(event_name)()
70 # define CASE_TEST_EVENT_ON_START(event_name, args...) \
71 static void test_event_on_start_func_name(event_name)(); \
72 static test_on_start_base test_event_on_start_obj_name(event_name)( \
73 #event_name, test_event_on_start_func_name(event_name), ##args); \
74 void test_event_on_start_func_name(event_name)()
76 # define CASE_TEST_EVENT_ON_EXIT(event_name, args...) \
77 static void test_event_on_exit_func_name(event_name)(); \
78 static test_on_exit_base test_event_on_exit_obj_name(event_name)( \
79 #event_name, test_event_on_exit_func_name(event_name), ##args); \
80 void test_event_on_exit_func_name(event_name)()
83 # ifdef UTILS_TEST_MACRO_TEST_ENABLE_BOOST_TEST
84 # define CASE_EXPECT_TRUE(c) BOOST_CHECK(c)
85 # define CASE_EXPECT_FALSE(c) BOOST_CHECK(!(c))
86 # define CASE_EXPECT_EQ(l, r) BOOST_CHECK_EQUAL(l, r)
87 # define CASE_EXPECT_NE(l, r) BOOST_CHECK_NE(l, r)
88 # define CASE_EXPECT_LT(l, r) BOOST_CHECK_LT(l, r)
89 # define CASE_EXPECT_LE(l, r) BOOST_CHECK_LE(l, r)
90 # define CASE_EXPECT_GT(l, r) BOOST_CHECK_GT(l, r)
91 # define CASE_EXPECT_GE(l, r) BOOST_CHECK_GE(l, r)
94 # define CASE_EXPECT_TRUE(c) test_manager::me().expect_true((c), # c, __FILE__, __LINE__)
95 # define CASE_EXPECT_FALSE(c) test_manager::me().expect_false((c), # c, __FILE__, __LINE__)
96 # define CASE_EXPECT_EQ(l, r) test_manager::me().expect_eq((l), (r), # l, # r, __FILE__, __LINE__)
97 # define CASE_EXPECT_NE(l, r) test_manager::me().expect_ne((l), (r), # l, # r, __FILE__, __LINE__)
98 # define CASE_EXPECT_LT(l, r) test_manager::me().expect_lt((l), (r), # l, # r, __FILE__, __LINE__)
99 # define CASE_EXPECT_LE(l, r) test_manager::me().expect_le((l), (r), # l, # r, __FILE__, __LINE__)
100 # define CASE_EXPECT_GT(l, r) test_manager::me().expect_gt((l), (r), # l, # r, __FILE__, __LINE__)
101 # define CASE_EXPECT_GE(l, r) test_manager::me().expect_ge((l), (r), # l, # r, __FILE__, __LINE__)
108 #define CASE_MSG_FCOLOR(x) util::cli::shell_font_style::SHELL_FONT_COLOR_##x
110 #define CASE_MSG_BCOLOR(x) util::cli::shell_font_style::SHELL_FONT_BACKGROUND_COLOR_##x
112 #define CASE_MSG_STYLE(x) util::cli::shell_font_style::SHELL_FONT_SPEC_##x
114 #define CASE_MSG_INFO() util::cli::shell_stream(std::cout)() << "[ RUNNING ] "
115 #define CASE_MSG_ERROR() util::cli::shell_stream(std::cerr)() << "[ RUNNING ] "
118 #if (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
120 # define CASE_THREAD_SLEEP_MS(x) std::this_thread::sleep_for(std::chrono::milliseconds(x))
121 # define CASE_THREAD_YIELD() std::this_thread::yield()
123 #elif defined(_MSC_VER)
124 # ifndef WIN32_LEAN_AND_MEAN
125 # define WIN32_LEAN_AND_MEAN
127 # include <Windows.h>
128 # define CASE_THREAD_SLEEP_MS(x) Sleep(x)
129 # define CASE_THREAD_YIELD() YieldProcessor()
134 # define CASE_THREAD_SLEEP_MS(x) \
135 ((x > 1000) ? sleep(x / 1000) : usleep(0)); \
136 usleep((x % 1000) * 1000)
137 # if defined(__linux__) || defined(__unix__)
139 # define CASE_THREAD_YIELD() sched_yield()
140 # elif defined(__GNUC__) || defined(__clang__)
141 # if defined(__i386__) || defined(__x86_64__)
147 # define CASE_THREAD_YIELD() __asm__ __volatile__("pause")
148 # elif defined(__ia64__) || defined(__ia64)
154 # define CASE_THREAD_YIELD() __asm__ __volatile__("hint @pause")
155 # elif defined(__arm__) && !defined(__ANDROID__)
160 # define CASE_THREAD_YIELD() __asm__ __volatile__("yield")
162 # define CASE_THREAD_YIELD()
165 # define CASE_THREAD_YIELD()