diff options
author | Eric Blake <eblake@redhat.com> | 2023-05-09 08:42:37 -0500 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2023-05-09 09:29:16 -0500 |
commit | 171bcd524aa0ca0587bd55b26ac4e709fb4bd5cf (patch) | |
tree | 5b1f0d1465cc0f5c665191f33e1b403072009cb7 | |
parent | 2ab2ce57e665d77932348b6489836e5c31e9896b (diff) | |
download | glib-171bcd524aa0ca0587bd55b26ac4e709fb4bd5cf.tar.gz |
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 <inttypes.h> for shorter format strings
Note, however, that using uint64_t in gtestutils.h is not feasible,
since it would require adding an '#include <stdint.h>' with potential
unintended namespace pollution to older clients.
Signed-off-by: Eric Blake <eblake@redhat.com>
-rw-r--r-- | glib/gtestutils.c | 31 |
1 files 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 <string.h> #include <stdlib.h> #include <stdio.h> +#include <inttypes.h> #ifdef HAVE_SYS_RESOURCE_H #include <sys/resource.h> #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); |