Updating to latest libtest.
[m6w6/libmemcached] / libtest / framework.h
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * uTest, libtest
4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37
38 #pragma once
39
40 /**
41 Framework is the structure which is passed to the test implementation to be filled.
42 This must be implemented in order for the test framework to load the tests. We call
43 get_world() in order to fill this structure.
44 */
45
46 class Framework {
47 public:
48 collection_st *collections;
49
50 /* These methods are called outside of any collection call. */
51 test_callback_create_fn *_create;
52 test_callback_destroy_fn *_destroy;
53
54 /* This is called a the beginning of any collection run. */
55 test_callback_fn *collection_startup;
56
57 /* This is called a the end of any collection run. */
58 test_callback_fn *collection_shutdown;
59
60 void set_collection_shutdown(test_callback_error_fn *arg)
61 {
62 _on_error= arg;
63 }
64
65 public:
66 void* create(test_return_t& arg);
67
68 test_return_t startup(void*);
69
70 test_return_t shutdown(void* arg)
71 {
72 if (collection_shutdown)
73 {
74 return collection_shutdown(arg);
75 }
76
77 return TEST_SUCCESS;
78 }
79
80 /**
81 These are run before/after the test. If implemented. Their execution is not controlled
82 by the test.
83 */
84 class Item {
85 public:
86 /* This is called a the beginning of any run. */
87 test_callback_fn *_startup;
88
89 test_return_t startup(void*);
90
91 /*
92 This called on a test if the test requires a flush call (the bool is
93 from test_st)
94 */
95 test_callback_fn *_flush;
96
97 private:
98 /*
99 Run before and after the runnner is executed.
100 */
101 test_callback_fn *pre_run;
102 test_callback_fn *post_run;
103
104 public:
105
106 Item() :
107 _startup(NULL),
108 _flush(NULL),
109 pre_run(NULL),
110 post_run(NULL)
111 { }
112
113 void set_startup(test_callback_fn *arg)
114 {
115 _startup= arg;
116 }
117
118 void set_collection(test_callback_fn *arg)
119 {
120 _flush= arg;
121 }
122
123 void set_flush(test_callback_fn *arg)
124 {
125 _flush= arg;
126 }
127
128 void set_pre(test_callback_fn *arg)
129 {
130 pre_run= arg;
131 }
132
133 void set_post(test_callback_fn *arg)
134 {
135 pre_run= arg;
136 }
137
138 test_return_t pre(void *arg);
139 test_return_t flush(void* arg, test_st* run);
140 test_return_t post(void *arg);
141
142 } item;
143
144 /**
145 If an error occurs during the test, this is called.
146 */
147 test_callback_error_fn *_on_error;
148
149 void set_on_error(test_callback_error_fn *arg)
150 {
151 _on_error= arg;
152 }
153
154 test_return_t on_error(const enum test_return_t, void *);
155
156 /**
157 Runner represents the callers for the tests. If not implemented we will use
158 a set of default implementations.
159 */
160 libtest::Runner *_runner;
161
162 void set_runner(libtest::Runner *arg)
163 {
164 _runner= arg;
165 }
166
167 libtest::Runner *runner();
168
169
170 Framework();
171
172 virtual ~Framework();
173
174 Framework(const Framework&);
175
176 private:
177 Framework& operator=(const Framework&);
178 libtest::server_startup_st _servers;
179 void *_creators_ptr;
180 };