X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Ftesting.h;h=84a1242953284309fe015df0ee6c43d95e6ba434;hb=6c89e681d7e3d65d6f680a11e3a36b609363bd88;hp=5df1b83a3e0f076b3a35bff53df09b021b9a0ea5;hpb=81a5fd5046c6a39f580a8fc1a3af837fd5f5aa5c;p=collectd.git diff --git a/src/testing.h b/src/testing.h index 5df1b83a..84a12429 100644 --- a/src/testing.h +++ b/src/testing.h @@ -1,6 +1,6 @@ /** * collectd - src/tests/macros.h - * Copyright (C) 2013 Florian octo Forster + * Copyright (C) 2013-2015 Florian octo Forster * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -27,6 +27,10 @@ static int fail_count__ = 0; static int check_count__ = 0; +#ifndef DBL_PRECISION +# define DBL_PRECISION 1e-12 +#endif + #define DEF_TEST(func) static int test_##func () #define RUN_TEST(func) do { \ @@ -42,6 +46,7 @@ static int check_count__ = 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 OK(cond) OK1(cond, #cond) @@ -54,6 +59,29 @@ static int check_count__ = 0; printf ("ok %i - %s evaluates to \"%s\"\n", ++check_count__, #actual, expect); \ } while (0) +#define EXPECT_INTEQ(expect, actual) do { \ + if ((expect) != (actual)) {\ + printf ("not ok %i - %s incorrect: expected %d, got %d\n", \ + ++check_count__, #actual, expect, actual); \ + return (-1); \ + } \ + printf ("ok %i - %s evaluates to %d\n", ++check_count__, #actual, expect); \ +} while (0) + +#define DBLEQ(expect, actual) do { \ + double e = (expect); double a = (actual); \ + if (isnan (e) && !isnan (a)) { \ + printf ("not ok %i - %s incorrect: expected %.15g, got %.15g\n", \ + ++check_count__, #actual, e, a); \ + return (-1); \ + } else if (!isnan (e) && (((e-a) < -DBL_PRECISION) || ((e-a) > DBL_PRECISION))) { \ + printf ("not ok %i - %s incorrect: expected %.15g, got %.15g\n", \ + ++check_count__, #actual, e, a); \ + return (-1); \ + } \ + printf ("ok %i - %s evaluates to %.15g\n", ++check_count__, #actual, e); \ +} while (0) + #define CHECK_NOT_NULL(expr) do { \ void *ptr_; \ ptr_ = (expr); \