Merge in trunk. Updates to manual/update to latest libtest.
[m6w6/libmemcached] / libtest / framework.h
1 /* uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/
2 *
3 * Use and distribution licensed under the BSD license. See
4 * the COPYING file in the parent directory for full text.
5 */
6
7 #pragma once
8
9 /**
10 Framework is the structure which is passed to the test implementation to be filled.
11 This must be implemented in order for the test framework to load the tests. We call
12 get_world() in order to fill this structure.
13 */
14
15 struct Framework {
16 collection_st *collections;
17
18 /* These methods are called outside of any collection call. */
19 test_callback_create_fn *_create;
20 test_callback_fn *_destroy;
21
22 void* create(test_return_t* arg)
23 {
24 if (_create)
25 {
26 return _create(arg);
27 }
28
29 return NULL;
30 }
31
32 test_return_t destroy(void*);
33
34 /* This is called a the beginning of any collection run. */
35 test_callback_fn *collection_startup;
36
37 test_return_t startup(void*);
38
39 /* This is called a the end of any collection run. */
40 test_callback_fn *collection_shutdown;
41
42 test_return_t shutdown(void* arg)
43 {
44 if (collection_shutdown)
45 {
46 return collection_shutdown(arg);
47 }
48
49 return TEST_SUCCESS;
50 }
51
52 /**
53 These are run before/after the test. If implemented. Their execution is not controlled
54 by the test.
55 */
56 struct Item {
57 /* This is called a the beginning of any run. */
58 test_callback_fn *_startup;
59
60 test_return_t startup(void*);
61
62 /*
63 This called on a test if the test requires a flush call (the bool is
64 from test_st)
65 */
66 test_callback_fn *_flush;
67
68 /*
69 Run before and after the runnner is executed.
70 */
71 test_callback_fn *pre_run;
72 test_callback_fn *post_run;
73
74 Item() :
75 _startup(NULL),
76 _flush(NULL),
77 pre_run(NULL),
78 post_run(NULL)
79 { }
80
81 test_return_t flush(void* arg, test_st* run);
82
83 void set_pre(test_callback_fn *arg)
84 {
85 pre_run= arg;
86 }
87
88 void set_post(test_callback_fn *arg)
89 {
90 pre_run= arg;
91 }
92
93 test_return_t pre(void *arg)
94 {
95 if (pre_run)
96 {
97 return pre_run(arg);
98 }
99
100 return TEST_SUCCESS;
101 }
102
103 test_return_t post(void *arg)
104 {
105 if (post_run)
106 {
107 return post_run(arg);
108 }
109
110 return TEST_SUCCESS;
111 }
112
113 } item;
114
115 /**
116 If an error occurs during the test, this is called.
117 */
118 test_callback_error_fn *_on_error;
119
120 test_return_t on_error(const enum test_return_t, void *);
121
122 /**
123 Runner represents the callers for the tests. If not implemented we will use
124 a set of default implementations.
125 */
126 Runner *runner;
127
128 Framework();
129
130 virtual ~Framework()
131 { }
132
133 Framework(const Framework&);
134
135 private:
136 Framework& operator=(const Framework&);
137 };