New stats output for collection information.
[m6w6/libmemcached] / tests / libmemcached_world.h
1 /* libMemcached Functions Test
2 * Copyright (C) 2006-2009 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 *
8 * Description: This is the startup bits for any libmemcached test.
9 *
10 */
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 /* The structure we use for the test system */
17 typedef struct
18 {
19 server_startup_st construct;
20 memcached_st *memc;
21 } libmemcached_test_container_st;
22
23 /* Prototypes for functions we will pass to test framework */
24 libmemcached_test_container_st *world_create(test_return_t *error);
25 test_return_t world_test_startup(libmemcached_test_container_st *);
26 test_return_t world_flush(libmemcached_test_container_st *container);
27 test_return_t world_pre_run(libmemcached_test_container_st *);
28
29 test_return_t world_post_run(libmemcached_test_container_st *);
30 test_return_t world_on_error(test_return_t, libmemcached_test_container_st *);
31 test_return_t world_destroy(libmemcached_test_container_st *);
32
33 static libmemcached_test_container_st global_container;
34
35 libmemcached_test_container_st *world_create(test_return_t *error)
36 {
37 memset(&global_container, 0, sizeof(global_container));
38 global_container.construct.count= SERVERS_TO_CREATE;
39 global_container.construct.udp= 0;
40 server_startup(&global_container.construct);
41
42 if (! global_container.construct.servers)
43 {
44 *error= TEST_FAILURE;
45 server_shutdown(&global_container.construct);
46 return NULL;
47 }
48
49 *error= TEST_SUCCESS;
50
51 return &global_container;
52 }
53
54
55 test_return_t world_test_startup(libmemcached_test_container_st *container)
56 {
57 memcached_return_t rc;
58 container->memc= memcached_create(NULL);
59 test_truth((container->memc != NULL));
60
61 rc= memcached_server_push(container->memc, container->construct.servers);
62 test_truth(rc == MEMCACHED_SUCCESS);
63
64 return TEST_SUCCESS;
65 }
66
67 test_return_t world_flush(libmemcached_test_container_st *container)
68 {
69 memcached_flush(container->memc, 0);
70 memcached_quit(container->memc);
71
72 return TEST_SUCCESS;
73 }
74
75 test_return_t world_pre_run(libmemcached_test_container_st *container)
76 {
77 uint32_t loop;
78
79 for (loop= 0; loop < memcached_server_list_count(container->construct.servers); loop++)
80 {
81 test_truth(container->memc->hosts[loop].fd == -1);
82 test_truth(container->memc->hosts[loop].cursor_active == 0);
83 }
84
85 return TEST_SUCCESS;
86 }
87
88
89 test_return_t world_post_run(libmemcached_test_container_st *container)
90 {
91 assert(container->memc);
92
93 return TEST_SUCCESS;
94 }
95
96 test_return_t world_on_error(test_return_t test_state, libmemcached_test_container_st *container)
97 {
98 (void)test_state;
99 memcached_free(container->memc);
100
101 return TEST_SUCCESS;
102 }
103
104 test_return_t world_destroy(libmemcached_test_container_st *container)
105 {
106 server_startup_st *construct= &container->construct;
107 memcached_server_st *servers= container->construct.servers;
108 memcached_server_list_free(servers);
109
110 server_shutdown(construct);
111
112 return TEST_SUCCESS;
113 }
114
115 typedef test_return_t (*libmemcached_test_callback_fn)(memcached_st *);
116 static test_return_t _runner_default(libmemcached_test_callback_fn func, libmemcached_test_container_st *container)
117 {
118 if (func)
119 {
120 return func(container->memc);
121 }
122 else
123 {
124 return TEST_SUCCESS;
125 }
126 }
127
128 #ifdef __cplusplus
129 }
130 #endif
131
132 #ifdef __cplusplus
133
134 static world_runner_st defualt_libmemcached_runner= {
135 reinterpret_cast<test_callback_runner_fn>(_runner_default),
136 reinterpret_cast<test_callback_runner_fn>(_runner_default),
137 reinterpret_cast<test_callback_runner_fn>(_runner_default)
138 };
139
140 #else
141
142 static world_runner_st defualt_libmemcached_runner= {
143 (test_callback_runner_fn)_runner_default,
144 (test_callback_runner_fn)_runner_default,
145 (test_callback_runner_fn)_runner_default
146 };
147
148 #endif