Fix test system to error correctly on interrupt/shutdown servers.
[awesomized/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 /* This is called a the beginning of any collection run. */
25 test_callback_fn *collection_startup;
26
27 test_return_t startup(void*);
28
29 /* This is called a the end of any collection run. */
30 test_callback_fn *collection_shutdown;
31
32 test_return_t shutdown(void* arg)
33 {
34 if (collection_shutdown)
35 {
36 return collection_shutdown(arg);
37 }
38
39 return TEST_SUCCESS;
40 }
41
42 /**
43 These are run before/after the test. If implemented. Their execution is not controlled
44 by the test.
45 */
46 struct Item {
47 /* This is called a the beginning of any run. */
48 test_callback_fn *_startup;
49
50 test_return_t startup(void*);
51
52 /*
53 This called on a test if the test requires a flush call (the bool is
54 from test_st)
55 */
56 test_callback_fn *_flush;
57
58 /*
59 Run before and after the runnner is executed.
60 */
61 test_callback_fn *pre_run;
62 test_callback_fn *post_run;
63
64 Item() :
65 _startup(NULL),
66 _flush(NULL),
67 pre_run(NULL),
68 post_run(NULL)
69 { }
70
71 test_return_t flush(void* arg, test_st* run);
72
73 void set_pre(test_callback_fn *arg)
74 {
75 pre_run= arg;
76 }
77
78 void set_post(test_callback_fn *arg)
79 {
80 pre_run= arg;
81 }
82
83 test_return_t pre(void *arg)
84 {
85 if (pre_run)
86 {
87 return pre_run(arg);
88 }
89
90 return TEST_SUCCESS;
91 }
92
93 test_return_t post(void *arg)
94 {
95 if (post_run)
96 {
97 return post_run(arg);
98 }
99
100 return TEST_SUCCESS;
101 }
102
103 } item;
104
105 /**
106 If an error occurs during the test, this is called.
107 */
108 test_callback_error_fn *_on_error;
109
110 test_return_t on_error(const enum test_return_t, void *);
111
112 /**
113 Runner represents the callers for the tests. If not implemented we will use
114 a set of default implementations.
115 */
116 Runner *runner;
117
118 Framework();
119
120 virtual ~Framework();
121
122 Framework(const Framework&);
123
124 private:
125 Framework& operator=(const Framework&);
126 void *_creators_ptr;
127 };