From: Brian Aker Date: Mon, 11 Jan 2010 21:47:22 +0000 (-0800) Subject: Fix structure of test.c where we call code before/after a collection runs. X-Git-Tag: 0.37~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=274253df134ea2cd4bf051d947b6c6a464c7bac6;p=awesomized%2Flibmemcached Fix structure of test.c where we call code before/after a collection runs. --- diff --git a/tests/test.c b/tests/test.c index 27f7f1b0..903ad4ee 100644 --- a/tests/test.c +++ b/tests/test.c @@ -105,6 +105,34 @@ static world_runner_st defualt_runners= { _runner_default }; +static test_return_t _default_callback(void *p) +{ + (void)p; + + return TEST_SUCCESS; +} + +static inline void set_default_fn(test_callback_fn *fn) +{ + if (*fn == NULL) + { + *fn= _default_callback; + } +} + +static collection_st *init_world(world_st *world) +{ + if (! world->runner) + { + world->runner= &defualt_runners; + } + + set_default_fn(&world->collection.startup); + set_default_fn(&world->collection.shutdown); + + return world->collections; +} + int main(int argc, char *argv[]) { @@ -123,12 +151,7 @@ int main(int argc, char *argv[]) memset(&world, 0, sizeof(world)); get_world(&world); - if (! world.runner) - { - world.runner= &defualt_runners; - } - - collection= world.collections; + collection= init_world(&world); if (world.create) { @@ -161,10 +184,7 @@ int main(int argc, char *argv[]) stats.collection_total++; - if (world.collection_startup) - { - collection_rc= world.collection_startup(world_ptr); - } + collection_rc= world.collection.startup(world_ptr); switch (collection_rc) { @@ -295,10 +315,7 @@ error: stats.collection_success++; } - if (world.collection_shutdown) - { - world.collection_shutdown(world_ptr); - } + world.collection.shutdown(world_ptr); } if (stats.collection_failed || stats.collection_skipped) diff --git a/tests/test.h b/tests/test.h index 39b14125..fc10c8d5 100644 --- a/tests/test.h +++ b/tests/test.h @@ -102,11 +102,13 @@ struct world_st { test_callback_error_fn on_error; } test; - /* This is called a the beginning of any collection run. */ - test_callback_fn collection_startup; + struct { + /* This is called a the beginning of any collection run. */ + test_callback_fn startup; - /* This is called a the beginning of any collection run. */ - test_callback_fn collection_shutdown; + /* This is called at the end of any collection run. */ + test_callback_fn shutdown; + } collection; /**