10 #ifndef TEST_MANAGER_H_
11 #define TEST_MANAGER_H_
19 #include <type_traits>
22 #ifdef __cpp_impl_three_way_comparison
30 #if (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1600)
32 # include <unordered_map>
33 # include <unordered_set>
34 # define UTILS_TEST_ENV_AUTO_MAP(...) std::unordered_map<__VA_ARGS__>
35 # define UTILS_TEST_ENV_AUTO_SET(...) std::unordered_set<__VA_ARGS__>
36 # define UTILS_TEST_ENV_AUTO_UNORDERED 1
41 # define UTILS_TEST_ENV_AUTO_MAP(...) std::map<__VA_ARGS__>
42 # define UTILS_TEST_ENV_AUTO_SET(...) std::set<__VA_ARGS__>
54 typedef std::vector<std::pair<std::string, case_ptr_type> >
test_type;
71 void set_cases(
const std::vector<std::string> &case_names);
77 #ifdef UTILS_TEST_MACRO_TEST_ENABLE_BOOST_TEST
78 static boost::unit_test::test_suite *&test_suit();
87 #ifdef __cpp_impl_three_way_comparison
98 template <
typename TL,
typename TR,
bool has_po
inter,
bool has_
integer,
bool all_
integer>
102 template <
typename TL,
typename TR>
104 template <
typename T>
106 return (uintptr_t)(t);
111 template <
typename TL,
typename TR>
115 template <
typename T>
117 return static_cast<int64_t
>(t);
121 template <
typename TL,
typename TR,
bool has_po
inter,
bool has_
integer,
bool all_
integer>
126 template <
typename T>
133 template <
typename TL,
typename TR>
134 bool expect_eq(
const TL &l,
const TR &r,
const char *lexpr,
const char *rexpr,
const char *file,
size_t line) {
136 std::is_integral<TL>::value || std::is_integral<TR>::value,
137 std::is_integral<TL>::value && std::is_integral<TR>::value>
139 if (pp(l) == pp(r)) {
146 <<
"Expected: " << lexpr <<
" == " << rexpr << std::endl
147 << lexpr <<
": " << l << std::endl
148 << rexpr <<
": " << r << std::endl;
154 template <
typename TL,
typename TR>
155 bool expect_ne(
const TL &l,
const TR &r,
const char *lexpr,
const char *rexpr,
const char *file,
size_t line) {
157 std::is_integral<TL>::value || std::is_integral<TR>::value,
158 std::is_integral<TL>::value && std::is_integral<TR>::value>
161 if (pp(l) != pp(r)) {
168 <<
"Expected: " << lexpr <<
" != " << rexpr << std::endl
169 << lexpr <<
": " << l << std::endl
170 << rexpr <<
": " << r << std::endl;
176 template <
typename TL,
typename TR>
177 bool expect_lt(
const TL &l,
const TR &r,
const char *lexpr,
const char *rexpr,
const char *file,
size_t line) {
179 std::is_integral<TL>::value || std::is_integral<TR>::value,
180 std::is_integral<TL>::value && std::is_integral<TR>::value>
190 <<
"Expected: " << lexpr <<
" < " << rexpr << std::endl
191 << lexpr <<
": " << l << std::endl
192 << rexpr <<
": " << r << std::endl;
198 template <
typename TL,
typename TR>
199 bool expect_le(
const TL &l,
const TR &r,
const char *lexpr,
const char *rexpr,
const char *file,
size_t line) {
201 std::is_integral<TL>::value || std::is_integral<TR>::value,
202 std::is_integral<TL>::value && std::is_integral<TR>::value>
205 if (pp(l) <= pp(r)) {
212 <<
"Expected: " << lexpr <<
" <= " << rexpr << std::endl
213 << lexpr <<
": " << l << std::endl
214 << rexpr <<
": " << r << std::endl;
220 template <
typename TL,
typename TR>
221 bool expect_gt(
const TL &l,
const TR &r,
const char *lexpr,
const char *rexpr,
const char *file,
size_t line) {
223 std::is_integral<TL>::value || std::is_integral<TR>::value,
224 std::is_integral<TL>::value && std::is_integral<TR>::value>
234 <<
"Expected: " << lexpr <<
" > " << rexpr << std::endl
235 << lexpr <<
": " << l << std::endl
236 << rexpr <<
": " << r << std::endl;
242 template <
typename TL,
typename TR>
243 bool expect_ge(
const TL &l,
const TR &r,
const char *lexpr,
const char *rexpr,
const char *file,
size_t line) {
245 std::is_integral<TL>::value || std::is_integral<TR>::value,
246 std::is_integral<TL>::value && std::is_integral<TR>::value>
249 if (pp(l) >= pp(r)) {
256 <<
"Expected: " << lexpr <<
" >= " << rexpr << std::endl
257 << lexpr <<
": " << l << std::endl
258 << rexpr <<
": " << r << std::endl;
264 template <
typename TL>
265 bool expect_true(
const TL &l,
const char *expr,
const char *file,
size_t line) {
273 <<
"Expected true: " << expr << std::endl
274 << expr <<
": " << l << std::endl;
280 template <
typename TL>
281 bool expect_false(
const TL &l,
const char *expr,
const char *file,
size_t line) {
289 <<
"Expected false: " << expr << std::endl
290 << expr <<
": " << l << std::endl;
296 static void set_counter_ptr(
int *success_counter_ptr,
int *failed_counter_ptr);
UTILS_TEST_ENV_AUTO_SET(std::string) run_groups_
static std::string get_expire_time(clock_t begin, clock_t end)
bool expect_lt(const TL &l, const TR &r, const char *lexpr, const char *rexpr, const char *file, size_t line)
test_on_exit_base * on_exit_ptr_type
std::vector< std::pair< std::string, case_ptr_type > > test_type
void set_cases(const std::vector< std::string > &case_names)
static test_manager & me()
test_on_start_base * on_start_ptr_type
bool expect_false(const TL &l, const char *expr, const char *file, size_t line)
void append_event_on_start(const std::string &event_name, on_start_ptr_type)
std::vector< std::pair< std::string, on_start_ptr_type > > event_on_start_type
event_on_exit_type evt_on_exits_
bool expect_ne(const TL &l, const TR &r, const char *lexpr, const char *rexpr, const char *file, size_t line)
test_case_base * case_ptr_type
std::vector< std::pair< std::string, on_exit_ptr_type > > event_on_exit_type
static void set_counter_ptr(int *success_counter_ptr, int *failed_counter_ptr)
bool expect_gt(const TL &l, const TR &r, const char *lexpr, const char *rexpr, const char *file, size_t line)
event_on_start_type evt_on_starts_
void append_event_on_exit(const std::string &event_name, on_exit_ptr_type)
bool expect_true(const TL &l, const char *expr, const char *file, size_t line)
static void inc_failed_counter()
UTILS_TEST_ENV_AUTO_SET(std::string) run_cases_
static void inc_success_counter()
bool expect_le(const TL &l, const TR &r, const char *lexpr, const char *rexpr, const char *file, size_t line)
typedef UTILS_TEST_ENV_AUTO_MAP(std::string, test_type) test_data_type
bool expect_eq(const TL &l, const TR &r, const char *lexpr, const char *rexpr, const char *file, size_t line)
void append_test_case(const std::string &test_name, const std::string &case_name, case_ptr_type)
bool expect_ge(const TL &l, const TR &r, const char *lexpr, const char *rexpr, const char *file, size_t line)
int64_t operator()(const T &t)
uintptr_t operator()(const T &t)
bool operator>=(const pick_param_str_t &other) const
bool operator!=(const pick_param_str_t &other) const
pick_param_str_t(const char *in)
bool operator==(const pick_param_str_t &other) const
bool operator>(const pick_param_str_t &other) const
bool operator<=(const pick_param_str_t &other) const
bool operator<(const pick_param_str_t &other) const
const T & operator()(const T &t)
pick_param_str_t operator()(const std::string &t)
pick_param_str_t operator()(const char *t)
int run_tests(int argc, char *argv[])