mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 19:36:18 +01:00
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>
This commit is contained in:
parent
2ab2ce57e6
commit
171bcd524a
@ -33,6 +33,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#ifdef HAVE_SYS_RESOURCE_H
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#endif
|
#endif
|
||||||
@ -3501,9 +3502,23 @@ g_assertion_message_cmpint (const char *domain,
|
|||||||
|
|
||||||
switch (numtype)
|
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 'i':
|
||||||
case 'u': s = g_strdup_printf ("assertion failed (%s): (%" G_GINT64_MODIFIER "u %s %" G_GINT64_MODIFIER "u)", expr, arg1, cmp, arg2); break;
|
s = g_strdup_printf ("assertion failed (%s): "
|
||||||
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;
|
"(%" 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_assertion_message (domain, file, line, func, s);
|
||||||
g_free (s);
|
g_free (s);
|
||||||
@ -3524,12 +3539,16 @@ g_assertion_message_cmpnum (const char *domain,
|
|||||||
|
|
||||||
switch (numtype)
|
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 'i':
|
||||||
case 'x':
|
case 'x':
|
||||||
/* Backwards compatibility to apps compiled before 2.78 */
|
/* Backwards compatibility to apps compiled before 2.78 */
|
||||||
g_assertion_message_cmpint (domain, file, line, func, expr, (guint64) arg1, cmp, (guint64) arg2, numtype); break;
|
g_assertion_message_cmpint (domain, file, line, func, expr,
|
||||||
case 'f': s = g_strdup_printf ("assertion failed (%s): (%.9g %s %.9g)", expr, (double) arg1, cmp, (double) arg2); break;
|
(guint64) arg1, cmp, (guint64) arg2, numtype);
|
||||||
/* ideally use: floats=%.7g double=%.17g */
|
break;
|
||||||
|
default:
|
||||||
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
g_assertion_message (domain, file, line, func, s);
|
g_assertion_message (domain, file, line, func, s);
|
||||||
g_free (s);
|
g_free (s);
|
||||||
|
Loading…
Reference in New Issue
Block a user