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