Merge working tree with build tree.
[awesomized/libmemcached] / libtest / framework.cc
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 #include <config.h>
24 #include <libtest/common.h>
25 #include <iostream>
26
27 using namespace libtest;
28
29 static test_return_t _default_callback(void *p)
30 {
31 (void)p;
32
33 return TEST_SUCCESS;
34 }
35
36 Framework::Framework() :
37 collections(NULL),
38 _create(NULL),
39 _destroy(NULL),
40 collection_startup(_default_callback),
41 collection_shutdown(_default_callback),
42 _on_error(NULL),
43 _runner(NULL),
44 _socket(false),
45 _creators_ptr(NULL)
46 {
47 }
48
49 Framework::~Framework()
50 {
51 if (_destroy and _destroy(_creators_ptr))
52 {
53 Error << "Failure in _destroy(), some resources may not have been cleaned up.";
54 }
55
56 _servers.shutdown();
57
58 delete _runner;
59 }
60
61 test_return_t Framework::Item::flush(void* arg, test_st* run)
62 {
63 if (run->requires_flush and _flush)
64 {
65 return _flush(arg);
66 }
67
68 return TEST_SUCCESS;
69 }
70
71 test_return_t Framework::on_error(const test_return_t rc, void* arg)
72 {
73 if (_on_error and test_failed(_on_error(rc, arg)))
74 {
75 return TEST_FAILURE;
76 }
77
78 return TEST_SUCCESS;
79 }
80
81 test_return_t Framework::startup(void* arg)
82 {
83 if (collection_startup)
84 {
85 return collection_startup(arg);
86 }
87
88 return TEST_SUCCESS;
89 }
90
91 test_return_t Framework::Item::startup(void* arg)
92 {
93 if (_startup)
94 {
95 return _startup(arg);
96 }
97
98 return TEST_SUCCESS;
99 }
100
101 libtest::Runner *Framework::runner()
102 {
103 if (_runner == NULL)
104 {
105 _runner= new Runner;
106 }
107 _runner->set_servers(_servers);
108
109 return _runner;
110 }
111
112 void* Framework::create(test_return_t& arg)
113 {
114 arg= TEST_SUCCESS;
115 if (_create)
116 {
117 return _creators_ptr= _create(_servers, arg);
118 }
119
120 return NULL;
121 }