From: Brian Aker Date: Sat, 19 Dec 2009 09:13:26 +0000 (-0800) Subject: Test updates. X-Git-Tag: 0.37~47 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=287c4d7cd3873c6ae9f7908bd4f34d6fbc9efcd4;p=awesomized%2Flibmemcached Test updates. --- diff --git a/tests/hashkit_functions.c b/tests/hashkit_functions.c index fd6185a1..2990b233 100644 --- a/tests/hashkit_functions.c +++ b/tests/hashkit_functions.c @@ -329,21 +329,41 @@ collection_st collection[] ={ }; /* Prototypes for functions we will pass to test framework */ -void *world_create(void); +void *world_create(test_return_t *error); test_return_t world_destroy(hashkit_st *hashk); -void *world_create(void) +void *world_create(test_return_t *error) { hashkit_st *hashk_ptr; hashk_ptr= hashkit_create(&global_hashk); - assert(hashk_ptr == &global_hashk); + if (hashk_ptr != &global_hashk) + { + *error= TEST_FAILURE; + return NULL; + } // First we test if hashk is even valid - assert(hashkit_is_initialized(hashk_ptr) == true); - assert(hashkit_is_allocated(hashk_ptr) == false); - assert(hashk_ptr->continuum == NULL); + if (hashkit_is_initialized(hashk_ptr) == false) + { + *error= TEST_FAILURE; + return NULL; + } + + if (hashkit_is_allocated(hashk_ptr) == true) + { + *error= TEST_FAILURE; + return NULL; + } + + if (hashk_ptr->continuum != NULL) + { + *error= TEST_FAILURE; + return NULL; + } + + *error= TEST_SUCCESS; return hashk_ptr; } diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index c2632311..a88b24cd 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -4,7 +4,7 @@ * * Use and distribution licensed under the BSD license. See * the COPYING file in the parent directory for full text. - * + * * Description: This is the startup bits for any libmemcached test. * */ @@ -21,7 +21,7 @@ typedef struct } libmemcached_test_container_st; /* Prototypes for functions we will pass to test framework */ -libmemcached_test_container_st *world_create(void); +libmemcached_test_container_st *world_create(test_return_t *error); test_return_t world_collection_startup(libmemcached_test_container_st *); test_return_t world_flush(libmemcached_test_container_st *container); test_return_t world_pre_run(libmemcached_test_container_st *); @@ -32,14 +32,21 @@ test_return_t world_destroy(libmemcached_test_container_st *); static libmemcached_test_container_st global_container; -libmemcached_test_container_st *world_create(void) +libmemcached_test_container_st *world_create(test_return_t *error) { memset(&global_container, 0, sizeof(global_container)); global_container.construct.count= SERVERS_TO_CREATE; global_container.construct.udp= 0; server_startup(&global_container.construct); - assert(global_container.construct.servers); + if (! global_container.construct.servers) + { + *error= TEST_FAILURE; + server_shutdown(&global_container.construct); + return NULL; + } + + *error= TEST_SUCCESS; return &global_container; } @@ -90,7 +97,7 @@ test_return_t world_on_error(test_return_t test_state, libmemcached_test_contain { (void)test_state; memcached_free(container->memc); - + return TEST_SUCCESS; } diff --git a/tests/test.c b/tests/test.c index 7cfb8395..653cc731 100644 --- a/tests/test.c +++ b/tests/test.c @@ -124,9 +124,16 @@ int main(int argc, char *argv[]) collection= world.collections; if (world.create) - world_ptr= world.create(); + { + test_return_t error; + world_ptr= world.create(&error); + if (error != TEST_SUCCESS) + exit(1); + } else + { world_ptr= NULL; + } if (argc > 1) collection_to_run= argv[1]; @@ -234,7 +241,16 @@ error: fprintf(stderr, "All tests completed successfully\n\n"); if (world.destroy) - world.destroy(world_ptr); + { + test_return_t error; + error= world.destroy(world_ptr); + + if (error != TEST_SUCCESS) + { + fprintf(stderr, "Failure during shutdown.\n"); + stats.failed++; // We do this to make our exit code return 1 + } + } world_stats_print(&stats); diff --git a/tests/test.h b/tests/test.h index 05126291..9f0f47e3 100644 --- a/tests/test.h +++ b/tests/test.h @@ -29,7 +29,7 @@ typedef enum { TEST_MAXIMUM_RETURN /* Always add new error code before */ } test_return_t; -typedef void *(*test_callback_create_fn)(void); +typedef void *(*test_callback_create_fn)(test_return_t *error); typedef test_return_t (*test_callback_fn)(void *); typedef test_return_t (*test_callback_runner_fn)(test_callback_fn, void *); typedef test_return_t (*test_callback_error_fn)(test_return_t, void *);