libcopp 2.3.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_case_base.h
Go to the documentation of this file.
1/*
2 * test_case_base.h
3 *
4 * Created on: 2014年3月11日
5 * Author: owent
6 *
7 * Released under the MIT license
8 */
9
10#ifndef TEST_CASE_BASE_H_
11#define TEST_CASE_BASE_H_
12
13#pragma once
14
15#include <string>
16
17#ifdef UTILS_TEST_MACRO_TEST_ENABLE_BOOST_TEST
18# include <boost/test/unit_test.hpp>
19#endif
20
21#if (defined(__cplusplus) && __cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1600)
22
23# include <unordered_map>
24# include <unordered_set>
25# define UTIL_UNIT_TEST_MACRO_AUTO_MAP(...) std::unordered_map<__VA_ARGS__>
26# define UTIL_UNIT_TEST_MACRO_AUTO_SET(...) std::unordered_set<__VA_ARGS__>
27# define UTIL_UNIT_TEST_MACRO_AUTO_UNORDERED 1
28#else
29
30# include <map>
31# include <set>
32# define UTIL_UNIT_TEST_MACRO_AUTO_MAP(...) std::map<__VA_ARGS__>
33# define UTIL_UNIT_TEST_MACRO_AUTO_SET(...) std::set<__VA_ARGS__>
34
35#endif
36
38 public:
39 typedef void (*test_func)();
40
41 public:
42 test_case_base(const std::string& test_name, const std::string& case_name, test_func func);
43 virtual ~test_case_base();
44
45 virtual int run();
46
49
51};
52
54 public:
55 typedef UTIL_UNIT_TEST_MACRO_AUTO_SET(std::string) after_set_t;
56 typedef void (*on_start_func)();
57
58 public:
59 template <typename... T>
60 test_on_start_base(const std::string& n, on_start_func func, T&&... deps) : name(n), func_(func) {
61 after.reserve(sizeof...(T));
62 expand(after.insert(after.end(), std::forward<T>(deps))...);
64 }
65
66 template <typename... T>
67 void expand(T&&...) {}
68
69 virtual ~test_on_start_base();
70
71 virtual int run();
72
73 std::string name;
75 after_set_t after;
76
77 private:
78 void register_self();
79};
80
82 public:
83 typedef UTIL_UNIT_TEST_MACRO_AUTO_SET(std::string) before_set_t;
84 typedef void (*on_exit_func)();
85
86 public:
87 template <typename... T>
88 test_on_exit_base(const std::string& n, on_exit_func func, T&&... deps) : name(n), func_(func) {
89 before.reserve(sizeof...(T));
90 expand(before.insert(before.end(), std::forward<T>(deps))...);
92 }
93
94 template <typename... T>
95 void expand(T&&...) {}
96
97 virtual ~test_on_exit_base();
98
99 virtual int run();
100
101 std::string name;
103 before_set_t before;
104
105 private:
106 void register_self();
107};
108
109#endif /* TEST_CASE_BASE_H_ */
virtual ~test_case_base()
virtual int run()
void(* test_func)()
virtual ~test_on_exit_base()
test_on_exit_base(const std::string &n, on_exit_func func, T &&... deps)
before_set_t before
typedef UTIL_UNIT_TEST_MACRO_AUTO_SET(std::string) before_set_t
void expand(T &&...)
void expand(T &&...)
on_start_func func_
typedef UTIL_UNIT_TEST_MACRO_AUTO_SET(std::string) after_set_t
virtual ~test_on_start_base()
test_on_start_base(const std::string &n, on_start_func func, T &&... deps)