Update all of libtest around runner.
[m6w6/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 public:
41 void* create(test_return_t& arg);
42
43 /**
44 If an error occurs during the test, this is called.
45 */
46 test_callback_error_fn *_on_error;
47
48 void set_on_error(test_callback_error_fn *arg)
49 {
50 _on_error= arg;
51 }
52
53 test_return_t on_error(const enum test_return_t, void *);
54
55 void set_socket()
56 {
57 _servers.set_socket();
58 }
59
60 void set_sasl(const std::string& username_arg, const std::string& password_arg)
61 {
62 _servers.set_sasl(username_arg, password_arg);
63 }
64
65 libtest::server_startup_st& servers()
66 {
67 return _servers;
68 }
69
70 /**
71 Runner represents the callers for the tests. If not implemented we will use
72 a set of default implementations.
73 */
74 libtest::Runner *_runner;
75
76 void set_runner(libtest::Runner *arg)
77 {
78 _runner= arg;
79 }
80
81 libtest::Runner *runner();
82
83
84 Framework();
85
86 virtual ~Framework();
87
88 Framework(const Framework&);
89
90 private:
91 Framework& operator=(const Framework&);
92 libtest::server_startup_st _servers;
93 bool _socket;
94 void *_creators_ptr;
95 unsigned long int _servers_to_run;
96 };