Fix test system to error correctly on interrupt/shutdown servers.
[m6w6/libmemcached] / libtest / framework.cc
1 /* uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/
2 *
3 * Use and distribution licensed under the BSD license. See
4 * the COPYING file in the parent directory for full text.
5 */
6
7 #include <libtest/common.h>
8 #include <iostream>
9
10 static test_return_t _runner_default(test_callback_fn func, void *p)
11 {
12 if (func)
13 {
14 return func(p);
15 }
16
17 return TEST_SUCCESS;
18 }
19
20 static Runner defualt_runners= {
21 _runner_default,
22 _runner_default,
23 _runner_default
24 };
25
26 static test_return_t _default_callback(void *p)
27 {
28 (void)p;
29
30 return TEST_SUCCESS;
31 }
32
33 Framework::Framework() :
34 collections(NULL),
35 _create(NULL),
36 _destroy(NULL),
37 collection_startup(_default_callback),
38 collection_shutdown(_default_callback),
39 _on_error(NULL),
40 runner(&defualt_runners),
41 _creators_ptr(NULL)
42 {
43 }
44
45 Framework::~Framework()
46 {
47 if (_destroy)
48 {
49 if (test_failed(_destroy(_creators_ptr)))
50 {
51 std::cerr << "Failure in _destroy(), some resources may not have been cleaned up." << std::endl;
52 }
53 }
54 }
55
56 test_return_t Framework::Item::flush(void* arg, test_st* run)
57 {
58 if (run->requires_flush and _flush)
59 {
60 return _flush(arg);
61 }
62
63 return TEST_SUCCESS;
64 }
65
66 test_return_t Framework::on_error(const test_return_t rc, void* arg)
67 {
68 if (_on_error and test_failed(_on_error(rc, arg)))
69 {
70 return TEST_FAILURE;
71 }
72
73 return TEST_SUCCESS;
74 }
75
76 test_return_t Framework::startup(void* arg)
77 {
78 if (collection_startup)
79 {
80 return collection_startup(arg);
81 }
82
83 return TEST_SUCCESS;
84 }
85
86 test_return_t Framework::Item::startup(void* arg)
87 {
88 if (_startup)
89 {
90 return _startup(arg);
91 }
92
93 return TEST_SUCCESS;
94 }
95
96 void* Framework::create(test_return_t* arg)
97 {
98 if (_create)
99 {
100 return _creators_ptr= _create(arg);
101 }
102
103 return NULL;
104 }