Fix structure of test.c where we call code before/after a collection runs.
authorBrian Aker <brian@gaz>
Mon, 11 Jan 2010 21:47:22 +0000 (13:47 -0800)
committerBrian Aker <brian@gaz>
Mon, 11 Jan 2010 21:47:22 +0000 (13:47 -0800)
tests/test.c
tests/test.h

index 27f7f1b0d32f6c507fccb5743b508617cfbd0161..903ad4ee9e87610741a56bb9f1590fc16969405d 100644 (file)
@@ -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)
index 39b141250ad7d76fc10caa9c190caff9a611cd37..fc10c8d5492a94bfd28f164e9d28bac39df3fc8c 100644 (file)
@@ -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;
 
 
   /**