summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8eecec1)
raw | patch | inline | side by side (parent: 8eecec1)
author | Florian Forster <octo@collectd.org> | |
Fri, 21 Aug 2015 11:37:30 +0000 (13:37 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 21 Aug 2015 11:37:30 +0000 (13:37 +0200) |
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.
macro. This results in cleaner log messages and prevents macros to be
expanded in the log output.
src/daemon/utils_time_test.c | patch | blob | history | |
src/testing.h | patch | blob | history |
index eaf72a6c611052a400db979f277b7a892534c4df..994b9bc0f07b033208f084047530248ccb882efa 100644 (file)
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));
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 1bbe800913315d798530fb9d0390541443f35c7c..5d4d61b51412f4f44924b6461edc0d51a9896ed4 100644 (file)
--- a/src/testing.h
+++ b/src/testing.h
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); \