From: Florian Forster Date: Fri, 21 Aug 2015 11:37:30 +0000 (+0200) Subject: src/testing.h: Rewrite the EXPECT_EQ_UINT64() macro. X-Git-Tag: collectd-5.6.0~609 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=55d2ddae29c2ba150d5b1f97015cd9593e5f66c6;p=collectd.git src/testing.h: Rewrite the EXPECT_EQ_UINT64() macro. Cast the input to uint64_t, so we don't need to do this when calling the macro. This results in cleaner log messages and prevents macros to be expanded in the log output. --- diff --git a/src/daemon/utils_time_test.c b/src/daemon/utils_time_test.c index eaf72a6c..994b9bc0 100644 --- a/src/daemon/utils_time_test.c +++ b/src/daemon/utils_time_test.c @@ -71,18 +71,18 @@ DEF_TEST(conversion) struct timespec ts; // cdtime -> s - EXPECT_EQ ((unsigned long) cases[i].tt, (unsigned long) CDTIME_T_TO_TIME_T (cases[i].t), "%lu"); + EXPECT_EQ_UINT64 (cases[i].tt, CDTIME_T_TO_TIME_T (cases[i].t)); // cdtime -> ms - EXPECT_EQ_UINT64 ((uint64_t) cases[i].ms, CDTIME_T_TO_MS (cases[i].t)); + EXPECT_EQ_UINT64(cases[i].ms, CDTIME_T_TO_MS (cases[i].t)); // cdtime -> us CDTIME_T_TO_TIMEVAL (cases[i].t, &tv); - EXPECT_EQ_UINT64 ((uint64_t) cases[i].tv.tv_usec, (uint64_t) tv.tv_usec); + EXPECT_EQ_UINT64 (cases[i].tv.tv_usec, tv.tv_usec); // cdtime -> ns CDTIME_T_TO_TIMESPEC (cases[i].t, &ts); - EXPECT_EQ_UINT64 ((uint64_t) cases[i].ts.tv_nsec, (uint64_t) ts.tv_nsec); + EXPECT_EQ_UINT64 (cases[i].ts.tv_nsec, ts.tv_nsec); // cdtime -> double DBLEQ (cases[i].d, CDTIME_T_TO_DOUBLE (cases[i].t)); @@ -108,8 +108,7 @@ DEF_TEST(ns_to_cdtime) size_t i; for (i = 0; i < (sizeof (cases) / sizeof (cases[0])); i++) { - cdtime_t got = NS_TO_CDTIME_T (cases[i].ns); - EXPECT_EQ_UINT64 ((uint64_t) cases[i].want, (uint64_t) got); + EXPECT_EQ_UINT64 (cases[i].want, NS_TO_CDTIME_T (cases[i].ns)); } return 0; diff --git a/src/testing.h b/src/testing.h index 1bbe8009..5d4d61b5 100644 --- a/src/testing.h +++ b/src/testing.h @@ -79,7 +79,16 @@ static int check_count__ = 0; printf ("ok %i - %s evaluates to %d\n", ++check_count__, #actual, expect); \ } while (0) -#define EXPECT_EQ_UINT64(expect, actual) EXPECT_EQ((expect), (actual), "%"PRIu64) +#define EXPECT_EQ_UINT64(expect, actual) do { \ + uint64_t want__ = (uint64_t) expect; \ + uint64_t got__ = (uint64_t) actual; \ + if (got__ != want__) { \ + printf ("not ok %i - %s = %"PRIu64", want %"PRIu64"\n", \ + ++check_count__, #actual, got__, want__); \ + return (-1); \ + } \ + printf ("ok %i - %s = %"PRIu64"\n", ++check_count__, #actual, got__); \ +} while (0) #define DBLEQ(expect, actual) do { \ double e = (expect); double a = (actual); \