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
*);
44 @note generic shutdown/startup for libmemcached tests.
46 test_return_t
world_container_startup(libmemcached_test_container_st
*container
);
47 test_return_t
world_container_shutdown(libmemcached_test_container_st
*container
);
49 libmemcached_test_container_st
*world_create(test_return_t
*error
)
51 libmemcached_test_container_st
*global_container
= new libmemcached_test_container_st();
52 if (not server_startup(&global_container
->construct
))
60 return global_container
;
63 test_return_t
world_container_startup(libmemcached_test_container_st
*container
)
67 test_compare_got(MEMCACHED_SUCCESS
,
68 libmemcached_check_configuration(container
->construct
.server_list
.c_str(), container
->construct
.server_list
.size(),
69 buffer
, sizeof(buffer
)),
72 assert(not container
->parent
);
73 container
->parent
= memcached(container
->construct
.server_list
.c_str(), container
->construct
.server_list
.size());
74 test_true(container
->parent
);
79 test_return_t
world_container_shutdown(libmemcached_test_container_st
*container
)
81 memcached_free(container
->parent
);
82 container
->parent
= NULL
;
87 test_return_t
world_test_startup(libmemcached_test_container_st
*container
)
90 assert(not container
->memc
);
91 assert(container
->parent
);
92 container
->memc
= memcached_clone(NULL
, container
->parent
);
93 test_true(container
->memc
);
98 test_return_t
world_flush(libmemcached_test_container_st
*container
)
100 assert(container
->memc
);
101 memcached_flush(container
->memc
, 0);
102 memcached_quit(container
->memc
);
107 test_return_t
world_pre_run(libmemcached_test_container_st
*container
)
109 assert(container
->memc
);
110 for (uint32_t loop
= 0; loop
< memcached_server_list_count(container
->memc
->servers
); loop
++)
112 memcached_server_instance_st instance
=
113 memcached_server_instance_by_position(container
->memc
, loop
);
115 test_compare(-1, instance
->fd
);
116 test_compare(0, instance
->cursor_active
);
123 test_return_t
world_post_run(libmemcached_test_container_st
*container
)
125 test_true(container
->memc
);
130 test_return_t
world_on_error(test_return_t test_state
, libmemcached_test_container_st
*container
)
133 assert(container
->memc
);
134 memcached_free(container
->memc
);
135 container
->memc
= NULL
;
140 test_return_t
world_destroy(libmemcached_test_container_st
*container
)
142 server_startup_st
*construct
= &container
->construct
;
144 server_shutdown(construct
);
146 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
155 typedef test_return_t (*libmemcached_test_callback_fn
)(memcached_st
*);
156 static test_return_t
_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
161 assert(container
->memc
);
162 return func(container
->memc
);
170 static test_return_t
_pre_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
174 return func(container
->parent
);
182 static test_return_t
_post_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
186 return func(container
->parent
);
200 static Runner defualt_libmemcached_runner
= {
201 reinterpret_cast<test_callback_runner_fn
*>(_pre_runner_default
),
202 reinterpret_cast<test_callback_runner_fn
*>(_runner_default
),
203 reinterpret_cast<test_callback_runner_fn
*>(_post_runner_default
)
208 static Runner defualt_libmemcached_runner
= {
209 (test_callback_runner_fn
)_pre_runner_default
,
210 (test_callback_runner_fn
)_runner_default
,
211 (test_callback_runner_fn
)_post_runner_default