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() :
27 memset(&construct
, 0, sizeof(server_startup_st
));
31 /* Prototypes for functions we will pass to test framework */
32 libmemcached_test_container_st
*world_create(test_return_t
*error
);
33 test_return_t
world_test_startup(libmemcached_test_container_st
*);
34 test_return_t
world_flush(libmemcached_test_container_st
*container
);
35 test_return_t
world_pre_run(libmemcached_test_container_st
*);
37 test_return_t
world_post_run(libmemcached_test_container_st
*);
38 test_return_t
world_on_error(test_return_t
, libmemcached_test_container_st
*);
39 test_return_t
world_destroy(libmemcached_test_container_st
*);
41 static libmemcached_test_container_st global_container
;
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 global_container
.construct
.count
= SERVERS_TO_CREATE
;
52 global_container
.construct
.udp
= 0;
53 server_startup(&global_container
.construct
);
57 return &global_container
;
60 test_return_t
world_container_startup(libmemcached_test_container_st
*container
)
64 test_compare_got(MEMCACHED_SUCCESS
,
65 libmemcached_check_configuration(container
->construct
.server_list
, strlen(container
->construct
.server_list
),
66 buffer
, sizeof(buffer
)),
69 container
->parent
= memcached(container
->construct
.server_list
, strlen(container
->construct
.server_list
));
70 test_true(container
->parent
);
75 test_return_t
world_container_shutdown(libmemcached_test_container_st
*container
)
77 memcached_free(container
->parent
);
78 container
->parent
= NULL
;
83 test_return_t
world_test_startup(libmemcached_test_container_st
*container
)
85 container
->memc
= memcached_clone(NULL
, container
->parent
);
86 test_true(container
->memc
);
91 test_return_t
world_flush(libmemcached_test_container_st
*container
)
93 memcached_flush(container
->memc
, 0);
94 memcached_quit(container
->memc
);
99 test_return_t
world_pre_run(libmemcached_test_container_st
*container
)
101 for (uint32_t loop
= 0; loop
< memcached_server_list_count(container
->memc
->servers
); loop
++)
103 memcached_server_instance_st instance
=
104 memcached_server_instance_by_position(container
->memc
, loop
);
106 test_compare(-1, instance
->fd
);
107 test_compare(0, instance
->cursor_active
);
114 test_return_t
world_post_run(libmemcached_test_container_st
*container
)
116 test_true(container
->memc
);
121 test_return_t
world_on_error(test_return_t test_state
, libmemcached_test_container_st
*container
)
124 memcached_free(container
->memc
);
125 container
->memc
= NULL
;
130 test_return_t
world_destroy(libmemcached_test_container_st
*container
)
132 server_startup_st
*construct
= &container
->construct
;
134 server_shutdown(construct
);
136 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
143 typedef test_return_t (*libmemcached_test_callback_fn
)(memcached_st
*);
144 static test_return_t
_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
148 return func(container
->memc
);
156 static test_return_t
_pre_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
160 return func(container
->parent
);
168 static test_return_t
_post_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
172 return func(container
->parent
);
186 static Runner defualt_libmemcached_runner
= {
187 reinterpret_cast<test_callback_runner_fn
*>(_pre_runner_default
),
188 reinterpret_cast<test_callback_runner_fn
*>(_runner_default
),
189 reinterpret_cast<test_callback_runner_fn
*>(_post_runner_default
)
194 static Runner defualt_libmemcached_runner
= {
195 (test_callback_runner_fn
)_pre_runner_default
,
196 (test_callback_runner_fn
)_runner_default
,
197 (test_callback_runner_fn
)_post_runner_default