Merge working tree with build tree.
[awesomized/libmemcached] / libtest / framework.h
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * libtest
4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22
23
24 #pragma once
25
26 /**
27 Framework is the structure which is passed to the test implementation to be filled.
28 This must be implemented in order for the test framework to load the tests. We call
29 get_world() in order to fill this structure.
30 */
31
32 class Framework {
33 public:
34 collection_st *collections;
35
36 /* These methods are called outside of any collection call. */
37 test_callback_create_fn *_create;
38 test_callback_destroy_fn *_destroy;
39
40 /* This is called a the beginning of any collection run. */
41 test_callback_fn *collection_startup;
42
43 /* This is called a the end of any collection run. */
44 test_callback_fn *collection_shutdown;
45
46 void set_collection_shutdown(test_callback_error_fn *arg)
47 {
48 _on_error= arg;
49 }
50
51 public:
52 void* create(test_return_t& arg);
53
54 test_return_t startup(void*);
55
56 test_return_t shutdown(void* arg)
57 {
58 if (collection_shutdown)
59 {
60 return collection_shutdown(arg);
61 }
62
63 return TEST_SUCCESS;
64 }
65
66 /**
67 These are run before/after the test. If implemented. Their execution is not controlled
68 by the test.
69 */
70 class Item {
71 public:
72 /* This is called a the beginning of any run. */
73 test_callback_fn *_startup;
74
75 test_return_t startup(void*);
76
77 /*
78 This called on a test if the test requires a flush call (the bool is
79 from test_st)
80 */
81 test_callback_fn *_flush;
82
83 public:
84
85 Item() :
86 _startup(NULL),
87 _flush(NULL)
88 { }
89
90 void set_startup(test_callback_fn *arg)
91 {
92 _startup= arg;
93 }
94
95 void set_collection(test_callback_fn *arg)
96 {
97 _flush= arg;
98 }
99
100 void set_flush(test_callback_fn *arg)
101 {
102 _flush= arg;
103 }
104
105 test_return_t flush(void* arg, test_st* run);
106
107 } item;
108
109 /**
110 If an error occurs during the test, this is called.
111 */
112 test_callback_error_fn *_on_error;
113
114 void set_on_error(test_callback_error_fn *arg)
115 {
116 _on_error= arg;
117 }
118
119 test_return_t on_error(const enum test_return_t, void *);
120
121 void set_socket()
122 {
123 _servers.set_socket();
124 }
125
126 void set_sasl(const std::string& username_arg, const std::string& password_arg)
127 {
128 _servers.set_sasl(username_arg, password_arg);
129 }
130
131 libtest::server_startup_st& servers()
132 {
133 return _servers;
134 }
135
136 /**
137 Runner represents the callers for the tests. If not implemented we will use
138 a set of default implementations.
139 */
140 libtest::Runner *_runner;
141
142 void set_runner(libtest::Runner *arg)
143 {
144 _runner= arg;
145 }
146
147 libtest::Runner *runner();
148
149
150 Framework();
151
152 virtual ~Framework();
153
154 Framework(const Framework&);
155
156 private:
157 Framework& operator=(const Framework&);
158 libtest::server_startup_st _servers;
159 bool _socket;
160 void *_creators_ptr;
161 unsigned long int _servers_to_run;
162 };