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