1 /* libMemcached Functions Test
2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
8 * Description: This is the startup bits for any libmemcached test.
16 /* The structure we use for the test system */
17 struct libmemcached_test_container_st
19 server_startup_st construct
;
23 libmemcached_test_container_st() :
33 /* Prototypes for functions we will pass to test framework */
34 libmemcached_test_container_st
*world_create(test_return_t
*error
);
35 test_return_t
world_test_startup(libmemcached_test_container_st
*);
36 test_return_t
world_flush(libmemcached_test_container_st
*container
);
37 test_return_t
world_pre_run(libmemcached_test_container_st
*);
39 test_return_t
world_post_run(libmemcached_test_container_st
*);
40 test_return_t
world_on_error(test_return_t
, libmemcached_test_container_st
*);
41 test_return_t
world_destroy(libmemcached_test_container_st
*);
43 static libmemcached_test_container_st global_container
;
46 @note generic shutdown/startup for libmemcached tests.
48 test_return_t
world_container_startup(libmemcached_test_container_st
*container
);
49 test_return_t
world_container_shutdown(libmemcached_test_container_st
*container
);
51 libmemcached_test_container_st
*world_create(test_return_t
*error
)
53 global_container
.construct
.count
= SERVERS_TO_CREATE
;
54 global_container
.construct
.udp
= 0;
55 if (not server_startup(&global_container
.construct
))
63 return &global_container
;
66 test_return_t
world_container_startup(libmemcached_test_container_st
*container
)
70 test_compare_got(MEMCACHED_SUCCESS
,
71 libmemcached_check_configuration(container
->construct
.server_list
.c_str(), container
->construct
.server_list
.size(),
72 buffer
, sizeof(buffer
)),
75 assert(not container
->parent
);
76 container
->parent
= memcached(container
->construct
.server_list
.c_str(), container
->construct
.server_list
.size());
77 test_true(container
->parent
);
82 test_return_t
world_container_shutdown(libmemcached_test_container_st
*container
)
84 memcached_free(container
->parent
);
85 container
->parent
= NULL
;
90 test_return_t
world_test_startup(libmemcached_test_container_st
*container
)
93 assert(not container
->memc
);
94 assert(container
->parent
);
95 container
->memc
= memcached_clone(NULL
, container
->parent
);
96 test_true(container
->memc
);
101 test_return_t
world_flush(libmemcached_test_container_st
*container
)
103 assert(container
->memc
);
104 memcached_flush(container
->memc
, 0);
105 memcached_quit(container
->memc
);
110 test_return_t
world_pre_run(libmemcached_test_container_st
*container
)
112 assert(container
->memc
);
113 for (uint32_t loop
= 0; loop
< memcached_server_list_count(container
->memc
->servers
); loop
++)
115 memcached_server_instance_st instance
=
116 memcached_server_instance_by_position(container
->memc
, loop
);
118 test_compare(-1, instance
->fd
);
119 test_compare(0, instance
->cursor_active
);
126 test_return_t
world_post_run(libmemcached_test_container_st
*container
)
128 test_true(container
->memc
);
133 test_return_t
world_on_error(test_return_t test_state
, libmemcached_test_container_st
*container
)
136 assert(container
->memc
);
137 memcached_free(container
->memc
);
138 container
->memc
= NULL
;
143 test_return_t
world_destroy(libmemcached_test_container_st
*container
)
145 server_startup_st
*construct
= &container
->construct
;
147 server_shutdown(construct
);
149 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
156 typedef test_return_t (*libmemcached_test_callback_fn
)(memcached_st
*);
157 static test_return_t
_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
162 assert(container
->memc
);
163 return func(container
->memc
);
171 static test_return_t
_pre_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
175 return func(container
->parent
);
183 static test_return_t
_post_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
187 return func(container
->parent
);
201 static Runner defualt_libmemcached_runner
= {
202 reinterpret_cast<test_callback_runner_fn
*>(_pre_runner_default
),
203 reinterpret_cast<test_callback_runner_fn
*>(_runner_default
),
204 reinterpret_cast<test_callback_runner_fn
*>(_post_runner_default
)
209 static Runner defualt_libmemcached_runner
= {
210 (test_callback_runner_fn
)_pre_runner_default
,
211 (test_callback_runner_fn
)_runner_default
,
212 (test_callback_runner_fn
)_post_runner_default