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 */
19 server_startup_st construct
;
22 } libmemcached_test_container_st
;
24 /* Prototypes for functions we will pass to test framework */
25 libmemcached_test_container_st
*world_create(test_return_t
*error
);
26 test_return_t
world_test_startup(libmemcached_test_container_st
*);
27 test_return_t
world_flush(libmemcached_test_container_st
*container
);
28 test_return_t
world_pre_run(libmemcached_test_container_st
*);
30 test_return_t
world_post_run(libmemcached_test_container_st
*);
31 test_return_t
world_on_error(test_return_t
, libmemcached_test_container_st
*);
32 test_return_t
world_destroy(libmemcached_test_container_st
*);
34 static libmemcached_test_container_st global_container
;
37 @note generic shutdown/startup for libmemcached tests.
39 test_return_t
world_container_startup(libmemcached_test_container_st
*container
);
40 test_return_t
world_container_shutdown(libmemcached_test_container_st
*container
);
42 libmemcached_test_container_st
*world_create(test_return_t
*error
)
44 memset(&global_container
, 0, sizeof(global_container
));
45 global_container
.construct
.count
= SERVERS_TO_CREATE
;
46 global_container
.construct
.udp
= 0;
47 server_startup(&global_container
.construct
);
49 if (! global_container
.construct
.servers
)
52 server_shutdown(&global_container
.construct
);
58 return &global_container
;
61 test_return_t
world_container_startup(libmemcached_test_container_st
*container
)
63 memcached_return_t rc
;
64 container
->parent
= memcached_create(NULL
);
65 test_truth((container
->parent
!= NULL
));
67 rc
= memcached_server_push(container
->parent
, container
->construct
.servers
);
68 test_truth(rc
== MEMCACHED_SUCCESS
);
73 test_return_t
world_container_shutdown(libmemcached_test_container_st
*container
)
75 memcached_free(container
->parent
);
76 container
->parent
= NULL
;
81 test_return_t
world_test_startup(libmemcached_test_container_st
*container
)
83 container
->memc
= memcached_clone(NULL
, container
->parent
);
84 test_truth((container
->memc
!= NULL
));
89 test_return_t
world_flush(libmemcached_test_container_st
*container
)
91 memcached_flush(container
->memc
, 0);
92 memcached_quit(container
->memc
);
97 test_return_t
world_pre_run(libmemcached_test_container_st
*container
)
101 for (loop
= 0; loop
< memcached_server_list_count(container
->construct
.servers
); loop
++)
103 memcached_server_st
*instance
=
104 memcached_server_instance_fetch(container
->memc
, loop
);
106 test_truth(instance
->fd
== -1);
107 test_truth(instance
->cursor_active
== 0);
114 test_return_t
world_post_run(libmemcached_test_container_st
*container
)
116 assert(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
;
133 memcached_server_st
*servers
= container
->construct
.servers
;
134 memcached_server_list_free(servers
);
136 server_shutdown(construct
);
141 typedef test_return_t (*libmemcached_test_callback_fn
)(memcached_st
*);
142 static test_return_t
_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
146 return func(container
->memc
);
160 static world_runner_st defualt_libmemcached_runner
= {
161 reinterpret_cast<test_callback_runner_fn
>(_runner_default
),
162 reinterpret_cast<test_callback_runner_fn
>(_runner_default
),
163 reinterpret_cast<test_callback_runner_fn
>(_runner_default
)
168 static world_runner_st defualt_libmemcached_runner
= {
169 (test_callback_runner_fn
)_runner_default
,
170 (test_callback_runner_fn
)_runner_default
,
171 (test_callback_runner_fn
)_runner_default