From 171bcd524aa0ca0587bd55b26ac4e709fb4bd5cf Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 9 May 2023 08:42:37 -0500 Subject: gtestutils: Style touchup Use more modern styling to the code added in the previous patch: - split 'label: stmt; stmt;' into multiple lines - add default: label with g_assert_not_reached() [yes, it's a bit weird adding an assertion inside code that handles assertions, but we should be okay since g_assertion_message_* are not public functions and should only be used by our macros] - use for shorter format strings Note, however, that using uint64_t in gtestutils.h is not feasible, since it would require adding an '#include ' with potential unintended namespace pollution to older clients. Signed-off-by: Eric Blake --- glib/gtestutils.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/glib/gtestutils.c b/glib/gtestutils.c index 0164804a9..0f0853259 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef HAVE_SYS_RESOURCE_H #include #endif @@ -3501,9 +3502,23 @@ g_assertion_message_cmpint (const char *domain, switch (numtype) { - case 'i': s = g_strdup_printf ("assertion failed (%s): (%" G_GINT64_MODIFIER "i %s %" G_GINT64_MODIFIER "i)", expr, (gint64) arg1, cmp, (gint64) arg2); break; - case 'u': s = g_strdup_printf ("assertion failed (%s): (%" G_GINT64_MODIFIER "u %s %" G_GINT64_MODIFIER "u)", expr, arg1, cmp, arg2); break; - case 'x': s = g_strdup_printf ("assertion failed (%s): (0x%08" G_GINT64_MODIFIER "x %s 0x%08" G_GINT64_MODIFIER "x)", expr, arg1, cmp, arg2); break; + case 'i': + s = g_strdup_printf ("assertion failed (%s): " + "(%" PRIi64 " %s %" PRIi64 ")", + expr, (int64_t) arg1, cmp, (int64_t) arg2); + break; + case 'u': + s = g_strdup_printf ("assertion failed (%s): " + "(%" PRIu64 " %s %" PRIu64 ")", + expr, (uint64_t) arg1, cmp, (uint64_t) arg2); + break; + case 'x': + s = g_strdup_printf ("assertion failed (%s): " + "(0x%08" PRIx64 " %s 0x%08" PRIx64 ")", + expr, (uint64_t) arg1, cmp, (uint64_t) arg2); + break; + default: + g_assert_not_reached (); } g_assertion_message (domain, file, line, func, s); g_free (s); @@ -3524,12 +3539,16 @@ g_assertion_message_cmpnum (const char *domain, switch (numtype) { + case 'f': s = g_strdup_printf ("assertion failed (%s): (%.9g %s %.9g)", expr, (double) arg1, cmp, (double) arg2); break; + /* ideally use: floats=%.7g double=%.17g */ case 'i': case 'x': /* Backwards compatibility to apps compiled before 2.78 */ - g_assertion_message_cmpint (domain, file, line, func, expr, (guint64) arg1, cmp, (guint64) arg2, numtype); break; - case 'f': s = g_strdup_printf ("assertion failed (%s): (%.9g %s %.9g)", expr, (double) arg1, cmp, (double) arg2); break; - /* ideally use: floats=%.7g double=%.17g */ + g_assertion_message_cmpint (domain, file, line, func, expr, + (guint64) arg1, cmp, (guint64) arg2, numtype); + break; + default: + g_assert_not_reached (); } g_assertion_message (domain, file, line, func, s); g_free (s); -- cgit v1.2.1