X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Ftesting.h;fp=src%2Ftesting.h;h=0c415e48909f96db0d8844e3f422cdd7325d86a1;hb=67ea18d2b08da3c5442cb2bb2c7b2059e3da94a8;hp=5d4d61b51412f4f44924b6461edc0d51a9896ed4;hpb=55d2ddae29c2ba150d5b1f97015cd9593e5f66c6;p=collectd.git diff --git a/src/testing.h b/src/testing.h index 5d4d61b5..0c415e48 100644 --- a/src/testing.h +++ b/src/testing.h @@ -52,31 +52,24 @@ static int check_count__ = 0; } while (0) #define OK(cond) OK1(cond, #cond) -#define STREQ(expect, actual) do { \ +#define EXPECT_EQ_STR(expect, actual) do { \ if (strcmp (expect, actual) != 0) { \ - printf ("not ok %i - %s incorrect: expected \"%s\", got \"%s\"\n", \ - ++check_count__, #actual, expect, actual); \ + printf ("not ok %i - %s = \"%s\", want \"%s\"\n", \ + ++check_count__, #actual, actual, expect); \ return (-1); \ } \ - printf ("ok %i - %s evaluates to \"%s\"\n", ++check_count__, #actual, expect); \ + printf ("ok %i - %s = \"%s\"\n", ++check_count__, #actual, actual); \ } while (0) -#define EXPECT_EQ(expect, actual, format) do { \ - if ((expect) != (actual)) {\ - printf ("not ok %i - %s incorrect: expected " format ", got " format "\n", \ - ++check_count__, #actual, expect, actual); \ - return (-1); \ - } \ - printf ("ok %i - %s evaluates to " format "\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); \ +#define EXPECT_EQ_INT(expect, actual) do { \ + int want__ = (int) expect; \ + int got__ = (int) actual; \ + if (got__ != want__) { \ + printf ("not ok %i - %s = %d, want %d\n", \ + ++check_count__, #actual, got__, want__); \ return (-1); \ } \ - printf ("ok %i - %s evaluates to %d\n", ++check_count__, #actual, expect); \ + printf ("ok %i - %s = %d\n", ++check_count__, #actual, got__); \ } while (0) #define EXPECT_EQ_UINT64(expect, actual) do { \ @@ -90,18 +83,19 @@ static int check_count__ = 0; printf ("ok %i - %s = %"PRIu64"\n", ++check_count__, #actual, got__); \ } 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); \ +#define EXPECT_EQ_DOUBLE(expect, actual) do { \ + double want__ = (double) expect; \ + double got__ = (double) actual; \ + if (isnan (want__) && !isnan (got__)) { \ + printf ("not ok %i - %s = %.15g, want %.15g\n", \ + ++check_count__, #actual, got__, want__); \ 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); \ + } else if (!isnan (want__) && (((want__-got__) < -DBL_PRECISION) || ((want__-got__) > DBL_PRECISION))) { \ + printf ("not ok %i - %s = %.15g, want %.15g\n", \ + ++check_count__, #actual, got__, want__); \ return (-1); \ } \ - printf ("ok %i - %s evaluates to %.15g\n", ++check_count__, #actual, e); \ + printf ("ok %i - %s = %.15g\n", ++check_count__, #actual, got__); \ } while (0) #define CHECK_NOT_NULL(expr) do { \