Tests: Make the self-rolled test framework a bit more useful and consistent.
[collectd.git] / src / tests / utils_avltree_test.c
index 260aa32..0e0b988 100644 (file)
  *   Florian octo Forster <octo at collectd.org>
  */
 
+#include "tests/macros.h"
 #include "collectd.h"
 #include "utils_avltree.h"
 
-static int fail_count = 0;
-static int check_count = 0;
-
-#define TEST(func) do { \
-  int status; \
-  printf ("Testing %s ...\n", #func); \
-  status = test_ ## func (); \
-  printf ("%s.\n", (status == 0) ? "Success" : "FAILURE"); \
-  if (status != 0) { fail_count++; } \
-} while (0);
-
-#define OK1(cond, text) do { \
-  _Bool result = (cond); \
-  printf ("%s %i - %s\n", result ? "ok" : "not ok", ++check_count, text); \
-  if (!result) { return (-1); } \
-} while (0);
-
-#define STREQ(expect, actual) do { \
-  if (strcmp (expect, actual) != 0) { \
-    printf ("not ok %i - %s incorrect: expected \"%s\", got \"%s\"\n", \
-        ++check_count, #actual, expect, actual); \
-    return (-1); \
-  } \
-  printf ("ok %i - %s evaluates to \"%s\"\n", ++check_count, #actual, expect); \
-} while (0)
-
-#define OK(cond) OK1(cond, #cond)
-
 static int compare_total_count = 0;
 #define RESET_COUNTS() do { compare_total_count = 0; } while (0)
 
@@ -68,7 +41,7 @@ static int compare_callback (void const *v0, void const *v1)
   return (strcmp (v0, v1));
 }
 
-static int test_success ()
+DEF_TEST(success)
 {
   c_avl_tree_t *t;
   char key_orig[] = "foo";
@@ -102,11 +75,9 @@ static int test_success ()
 
 int main (void)
 {
-  TEST(success);
+  RUN_TEST(success);
 
-  if (fail_count != 0)
-    exit (EXIT_FAILURE);
-  exit (EXIT_SUCCESS);
+  END_TEST;
 }
 
 /* vim: set sw=2 sts=2 et : */