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
);
55 if (not global_container
.construct
.servers
)
58 server_shutdown(&global_container
.construct
);
64 return &global_container
;
67 test_return_t
world_container_startup(libmemcached_test_container_st
*container
)
69 container
->parent
= memcached_create(NULL
);
70 test_true((container
->parent
!= NULL
));
72 test_compare(MEMCACHED_SUCCESS
,
73 memcached_server_push(container
->parent
, container
->construct
.servers
));
78 test_return_t
world_container_shutdown(libmemcached_test_container_st
*container
)
80 memcached_free(container
->parent
);
81 container
->parent
= NULL
;
86 test_return_t
world_test_startup(libmemcached_test_container_st
*container
)
88 container
->memc
= memcached_clone(NULL
, container
->parent
);
89 test_true((container
->memc
!= NULL
));
94 test_return_t
world_flush(libmemcached_test_container_st
*container
)
96 memcached_flush(container
->memc
, 0);
97 memcached_quit(container
->memc
);
102 test_return_t
world_pre_run(libmemcached_test_container_st
*container
)
104 for (uint32_t loop
= 0; loop
< memcached_server_list_count(container
->memc
->servers
); loop
++)
106 memcached_server_instance_st instance
=
107 memcached_server_instance_by_position(container
->memc
, loop
);
109 test_compare(-1, instance
->fd
);
110 test_compare(0, instance
->cursor_active
);
117 test_return_t
world_post_run(libmemcached_test_container_st
*container
)
119 test_true(container
->memc
);
124 test_return_t
world_on_error(test_return_t test_state
, libmemcached_test_container_st
*container
)
127 memcached_free(container
->memc
);
128 container
->memc
= NULL
;
133 test_return_t
world_destroy(libmemcached_test_container_st
*container
)
135 server_startup_st
*construct
= &container
->construct
;
136 memcached_server_st
*servers
= container
->construct
.servers
;
137 memcached_server_list_free(servers
);
139 server_shutdown(construct
);
141 #ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
148 typedef test_return_t (*libmemcached_test_callback_fn
)(memcached_st
*);
149 static test_return_t
_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
153 return func(container
->memc
);
161 static test_return_t
_pre_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
165 return func(container
->parent
);
173 static test_return_t
_post_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
177 return func(container
->parent
);
191 static Runner defualt_libmemcached_runner
= {
192 reinterpret_cast<test_callback_runner_fn
*>(_pre_runner_default
),
193 reinterpret_cast<test_callback_runner_fn
*>(_runner_default
),
194 reinterpret_cast<test_callback_runner_fn
*>(_post_runner_default
)
199 static Runner defualt_libmemcached_runner
= {
200 (test_callback_runner_fn
)_pre_runner_default
,
201 (test_callback_runner_fn
)_runner_default
,
202 (test_callback_runner_fn
)_post_runner_default