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