From 450a9f280cd5d5b83da7561ff0362854f5c8b204 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Thu, 19 Apr 2012 07:26:08 -0700 Subject: [PATCH] Refactor out item specific bits of the testing framework. --- libtest/framework.cc | 20 --------- libtest/framework.h | 23 +---------- libtest/main.cc | 47 +++++++++------------- tests/failure.cc | 2 - tests/libmemcached-1.0/all_tests.cc | 2 - tests/libmemcached-1.0/all_tests_socket.cc | 2 - tests/libmemcached-1.0/atomsmasher.cc | 2 - tests/libmemcached-1.0/plus.cpp | 2 - tests/libmemcached-1.0/sasl.cc | 2 - tests/libmemcached_world.h | 22 ---------- tests/libmemcached_world_socket.h | 23 ----------- tests/mem_udp.cc | 2 - 12 files changed, 21 insertions(+), 128 deletions(-) diff --git a/libtest/framework.cc b/libtest/framework.cc index 3a4d85d5..8e049e60 100644 --- a/libtest/framework.cc +++ b/libtest/framework.cc @@ -58,26 +58,6 @@ Framework::~Framework() delete _runner; } -test_return_t Framework::Item::pre(void *arg) -{ - if (pre_run) - { - return pre_run(arg); - } - - return TEST_SUCCESS; -} - -test_return_t Framework::Item::post(void *arg) -{ - if (post_run) - { - return post_run(arg); - } - - return TEST_SUCCESS; -} - test_return_t Framework::Item::flush(void* arg, test_st* run) { if (run->requires_flush and _flush) diff --git a/libtest/framework.h b/libtest/framework.h index c7341a72..04dc29da 100644 --- a/libtest/framework.h +++ b/libtest/framework.h @@ -80,20 +80,11 @@ public: */ test_callback_fn *_flush; - private: - /* - Run before and after the runnner is executed. - */ - test_callback_fn *pre_run; - test_callback_fn *post_run; - public: Item() : _startup(NULL), - _flush(NULL), - pre_run(NULL), - post_run(NULL) + _flush(NULL) { } void set_startup(test_callback_fn *arg) @@ -111,19 +102,7 @@ public: _flush= arg; } - void set_pre(test_callback_fn *arg) - { - pre_run= arg; - } - - void set_post(test_callback_fn *arg) - { - pre_run= arg; - } - - test_return_t pre(void *arg); test_return_t flush(void* arg, test_st* run); - test_return_t post(void *arg); } item; diff --git a/libtest/main.cc b/libtest/main.cc index a5d90462..dcbc50eb 100644 --- a/libtest/main.cc +++ b/libtest/main.cc @@ -310,39 +310,32 @@ int main(int argc, char *argv[]) { if (test_success(return_code= world.item.flush(creators_ptr, run))) { - // @note pre will fail is SKIPPED is returned - if (test_success(return_code= world.item.pre(creators_ptr))) - { - { // Runner Code - gettimeofday(&start_time, NULL); - assert(world.runner()); - assert(run->test_fn); - try + { // Runner Code + gettimeofday(&start_time, NULL); + assert(world.runner()); + assert(run->test_fn); + try + { + return_code= world.runner()->run(run->test_fn, creators_ptr); + } + // Special case where check for the testing of the exception + // system. + catch (libtest::fatal &e) + { + if (fatal::is_disabled()) { - return_code= world.runner()->run(run->test_fn, creators_ptr); + fatal::increment_disabled_counter(); + return_code= TEST_SUCCESS; } - // Special case where check for the testing of the exception - // system. - catch (libtest::fatal &e) + else { - if (fatal::is_disabled()) - { - fatal::increment_disabled_counter(); - return_code= TEST_SUCCESS; - } - else - { - throw; - } + throw; } - - gettimeofday(&end_time, NULL); - load_time= timedif(end_time, start_time); } - } - // @todo do something if post fails - (void)world.item.post(creators_ptr); + gettimeofday(&end_time, NULL); + load_time= timedif(end_time, start_time); + } } else if (return_code == TEST_SKIPPED) { } diff --git a/tests/failure.cc b/tests/failure.cc index 4d81ecd4..073cd17b 100644 --- a/tests/failure.cc +++ b/tests/failure.cc @@ -219,9 +219,7 @@ void get_world(Framework *world) world->_destroy= (test_callback_destroy_fn*)world_destroy; world->item._startup= (test_callback_fn*)world_test_startup; - world->item.set_pre((test_callback_fn*)world_pre_run); world->item.set_flush((test_callback_fn*)world_flush); - world->item.set_post((test_callback_fn*)world_post_run); world->_on_error= (test_callback_error_fn*)world_on_error; world->collection_startup= (test_callback_fn*)world_container_startup; diff --git a/tests/libmemcached-1.0/all_tests.cc b/tests/libmemcached-1.0/all_tests.cc index 5e2882c6..74c195d2 100644 --- a/tests/libmemcached-1.0/all_tests.cc +++ b/tests/libmemcached-1.0/all_tests.cc @@ -88,9 +88,7 @@ void get_world(Framework *world) world->_destroy= (test_callback_destroy_fn*)world_destroy; world->item._startup= (test_callback_fn*)world_test_startup; - world->item.set_pre((test_callback_fn*)world_pre_run); world->item.set_flush((test_callback_fn*)world_flush); - world->item.set_post((test_callback_fn*)world_post_run); world->_on_error= (test_callback_error_fn*)world_on_error; world->collection_startup= (test_callback_fn*)world_container_startup; diff --git a/tests/libmemcached-1.0/all_tests_socket.cc b/tests/libmemcached-1.0/all_tests_socket.cc index 6398c1eb..046bd290 100644 --- a/tests/libmemcached-1.0/all_tests_socket.cc +++ b/tests/libmemcached-1.0/all_tests_socket.cc @@ -77,9 +77,7 @@ void get_world(Framework *world) world->_destroy= (test_callback_destroy_fn*)world_destroy; world->item._startup= (test_callback_fn*)world_test_startup; - world->item.set_pre((test_callback_fn*)world_pre_run); world->item.set_flush((test_callback_fn*)world_flush); - world->item.set_post((test_callback_fn*)world_post_run); world->_on_error= (test_callback_error_fn*)world_on_error; world->collection_startup= (test_callback_fn*)world_container_startup; diff --git a/tests/libmemcached-1.0/atomsmasher.cc b/tests/libmemcached-1.0/atomsmasher.cc index 23d6dd23..2b7e9c12 100644 --- a/tests/libmemcached-1.0/atomsmasher.cc +++ b/tests/libmemcached-1.0/atomsmasher.cc @@ -286,8 +286,6 @@ void get_world(Framework *world) world->item._startup= (test_callback_fn*)world_test_startup; world->item._flush= (test_callback_fn*)world_flush; - world->item.set_pre((test_callback_fn*)world_pre_run); - world->item.set_post((test_callback_fn*)world_post_run); world->_on_error= (test_callback_error_fn*)world_on_error; world->collection_startup= (test_callback_fn*)world_container_startup; diff --git a/tests/libmemcached-1.0/plus.cpp b/tests/libmemcached-1.0/plus.cpp index 5b3f7e88..bd19feb0 100644 --- a/tests/libmemcached-1.0/plus.cpp +++ b/tests/libmemcached-1.0/plus.cpp @@ -293,8 +293,6 @@ void get_world(Framework *world) world->item._startup= reinterpret_cast(world_test_startup); world->item._flush= reinterpret_cast(world_flush); - world->item.set_pre(reinterpret_cast(world_pre_run)); - world->item.set_post(reinterpret_cast(world_post_run)); world->_on_error= reinterpret_cast(world_on_error); world->collection_startup= reinterpret_cast(world_container_startup); diff --git a/tests/libmemcached-1.0/sasl.cc b/tests/libmemcached-1.0/sasl.cc index bbf905d9..ee421300 100644 --- a/tests/libmemcached-1.0/sasl.cc +++ b/tests/libmemcached-1.0/sasl.cc @@ -107,9 +107,7 @@ void get_world(Framework *world) world->_destroy= (test_callback_destroy_fn*)world_destroy; world->item._startup= (test_callback_fn*)world_test_startup; - world->item.set_pre((test_callback_fn*)world_pre_run); world->item.set_flush((test_callback_fn*)world_flush); - world->item.set_post((test_callback_fn*)world_post_run); world->_on_error= (test_callback_error_fn*)world_on_error; world->collection_startup= (test_callback_fn*)world_container_startup; diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index c31b303f..ded47ada 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -160,28 +160,6 @@ test_return_t world_flush(libmemcached_test_container_st *container) return TEST_SUCCESS; } -static test_return_t world_pre_run(libmemcached_test_container_st *container) -{ - test_true(container->memc); - for (uint32_t loop= 0; loop < memcached_server_list_count(container->memc->servers); loop++) - { - memcached_server_instance_st instance= memcached_server_instance_by_position(container->memc, loop); - - test_compare(-1, instance->fd); - test_compare(0U, instance->cursor_active); - } - - return TEST_SUCCESS; -} - - -static test_return_t world_post_run(libmemcached_test_container_st *container) -{ - test_true(container->memc); - - return TEST_SUCCESS; -} - static test_return_t world_on_error(test_return_t , libmemcached_test_container_st *container) { test_true(container->memc); diff --git a/tests/libmemcached_world_socket.h b/tests/libmemcached_world_socket.h index 8016dba4..4080a1b0 100644 --- a/tests/libmemcached_world_socket.h +++ b/tests/libmemcached_world_socket.h @@ -141,29 +141,6 @@ test_return_t world_flush(libmemcached_test_container_st *container) return TEST_SUCCESS; } -static test_return_t world_pre_run(libmemcached_test_container_st *container) -{ - test_true(container->memc); - for (uint32_t loop= 0; loop < memcached_server_list_count(container->memc->servers); loop++) - { - memcached_server_instance_st instance= - memcached_server_instance_by_position(container->memc, loop); - - test_compare(-1, instance->fd); - test_compare(0U, instance->cursor_active); - } - - return TEST_SUCCESS; -} - - -static test_return_t world_post_run(libmemcached_test_container_st *container) -{ - test_true(container->memc); - - return TEST_SUCCESS; -} - static test_return_t world_on_error(test_return_t , libmemcached_test_container_st *container) { test_true(container->memc); diff --git a/tests/mem_udp.cc b/tests/mem_udp.cc index 3a97d849..17f9f55f 100644 --- a/tests/mem_udp.cc +++ b/tests/mem_udp.cc @@ -573,8 +573,6 @@ void get_world(Framework *world) world->item._startup= (test_callback_fn*)world_test_startup; world->item._flush= (test_callback_fn*)world_flush; - world->item.set_pre((test_callback_fn*)world_pre_run); - world->item.set_post((test_callback_fn*)world_post_run); world->_on_error= (test_callback_error_fn*)world_on_error; world->collection_startup= (test_callback_fn*)world_container_startup; -- 2.30.2