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
;
21 } libmemcached_test_container_st
;
23 /* Prototypes for functions we will pass to test framework */
24 libmemcached_test_container_st
*world_create(void);
25 test_return_t
world_collection_startup(libmemcached_test_container_st
*);
26 test_return_t
world_flush(libmemcached_test_container_st
*container
);
27 test_return_t
world_pre_run(libmemcached_test_container_st
*);
29 test_return_t
world_post_run(libmemcached_test_container_st
*);
30 test_return_t
world_on_error(test_return_t
, libmemcached_test_container_st
*);
31 test_return_t
world_destroy(libmemcached_test_container_st
*);
33 static libmemcached_test_container_st global_container
;
35 libmemcached_test_container_st
*world_create(void)
37 memset(&global_container
, 0, sizeof(global_container
));
38 global_container
.construct
.count
= SERVERS_TO_CREATE
;
39 global_container
.construct
.udp
= 0;
40 server_startup(&global_container
.construct
);
42 assert(global_container
.construct
.servers
);
44 return &global_container
;
48 test_return_t
world_collection_startup(libmemcached_test_container_st
*container
)
50 memcached_return_t rc
;
51 container
->memc
= memcached_create(NULL
);
52 test_truth((container
->memc
!= NULL
));
54 rc
= memcached_server_push(container
->memc
, container
->construct
.servers
);
55 test_truth(rc
== MEMCACHED_SUCCESS
);
60 test_return_t
world_flush(libmemcached_test_container_st
*container
)
62 memcached_flush(container
->memc
, 0);
63 memcached_quit(container
->memc
);
68 test_return_t
world_pre_run(libmemcached_test_container_st
*container
)
72 for (loop
= 0; loop
< memcached_server_list_count(container
->construct
.servers
); loop
++)
74 test_truth(container
->memc
->hosts
[loop
].fd
== -1);
75 test_truth(container
->memc
->hosts
[loop
].cursor_active
== 0);
82 test_return_t
world_post_run(libmemcached_test_container_st
*container
)
84 assert(container
->memc
);
89 test_return_t
world_on_error(test_return_t test_state
, libmemcached_test_container_st
*container
)
92 memcached_free(container
->memc
);
97 test_return_t
world_destroy(libmemcached_test_container_st
*container
)
99 server_startup_st
*construct
= &container
->construct
;
100 memcached_server_st
*servers
= container
->construct
.servers
;
101 memcached_server_list_free(servers
);
103 server_shutdown(construct
);
108 typedef test_return_t (*libmemcached_test_callback_fn
)(memcached_st
*);
109 static test_return_t
_runner_default(libmemcached_test_callback_fn func
, libmemcached_test_container_st
*container
)
113 return func(container
->memc
);
127 static world_runner_st defualt_libmemcached_runner
= {
128 reinterpret_cast<test_callback_runner_fn
>(_runner_default
),
129 reinterpret_cast<test_callback_runner_fn
>(_runner_default
),
130 reinterpret_cast<test_callback_runner_fn
>(_runner_default
)
135 static world_runner_st defualt_libmemcached_runner
= {
136 (test_callback_runner_fn
)_runner_default
,
137 (test_callback_runner_fn
)_runner_default
,
138 (test_callback_runner_fn
)_runner_default