mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-10 03:04:05 +02:00
Merge branch 'main' into 'main'
gtestutils: Improve g_assert_cmpuint Closes #2997 See merge request GNOME/glib!3424
This commit is contained in:
@@ -3402,6 +3402,7 @@ g_test_trap_assertions
|
|||||||
g_assertion_message
|
g_assertion_message
|
||||||
g_assertion_message_expr
|
g_assertion_message_expr
|
||||||
g_assertion_message_cmpstr
|
g_assertion_message_cmpstr
|
||||||
|
g_assertion_message_cmpint
|
||||||
g_assertion_message_cmpnum
|
g_assertion_message_cmpnum
|
||||||
g_assertion_message_error
|
g_assertion_message_error
|
||||||
g_test_assert_expected_messages_internal
|
g_test_assert_expected_messages_internal
|
||||||
|
@@ -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
|
||||||
@@ -3486,6 +3487,43 @@ g_assertion_message_expr (const char *domain,
|
|||||||
g_abort ();
|
g_abort ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
g_assertion_message_cmpint (const char *domain,
|
||||||
|
const char *file,
|
||||||
|
int line,
|
||||||
|
const char *func,
|
||||||
|
const char *expr,
|
||||||
|
guint64 arg1,
|
||||||
|
const char *cmp,
|
||||||
|
guint64 arg2,
|
||||||
|
char numtype)
|
||||||
|
{
|
||||||
|
char *s = NULL;
|
||||||
|
|
||||||
|
switch (numtype)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_assertion_message_cmpnum (const char *domain,
|
g_assertion_message_cmpnum (const char *domain,
|
||||||
const char *file,
|
const char *file,
|
||||||
@@ -3501,10 +3539,16 @@ g_assertion_message_cmpnum (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 'x': s = g_strdup_printf ("assertion failed (%s): (0x%08" G_GINT64_MODIFIER "x %s 0x%08" G_GINT64_MODIFIER "x)", expr, (guint64) arg1, cmp, (guint64) arg2); break;
|
|
||||||
case 'f': s = g_strdup_printf ("assertion failed (%s): (%.9g %s %.9g)", expr, (double) arg1, cmp, (double) arg2); 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 */
|
/* 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;
|
||||||
|
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);
|
||||||
|
@@ -49,6 +49,26 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
|
|||||||
g_assertion_message_cmpstr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
g_assertion_message_cmpstr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
#s1 " " #cmp " " #s2, __s1, #cmp, __s2); \
|
#s1 " " #cmp " " #s2, __s1, #cmp, __s2); \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
#if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_78
|
||||||
|
#define g_assert_cmpint(n1, cmp, n2) G_STMT_START { \
|
||||||
|
gint64 __n1 = (n1), __n2 = (n2); \
|
||||||
|
if (__n1 cmp __n2) ; else \
|
||||||
|
g_assertion_message_cmpint (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
|
#n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); \
|
||||||
|
} G_STMT_END
|
||||||
|
#define g_assert_cmpuint(n1, cmp, n2) G_STMT_START { \
|
||||||
|
guint64 __n1 = (n1), __n2 = (n2); \
|
||||||
|
if (__n1 cmp __n2) ; else \
|
||||||
|
g_assertion_message_cmpint (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
|
#n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'u'); \
|
||||||
|
} G_STMT_END
|
||||||
|
#define g_assert_cmphex(n1, cmp, n2) G_STMT_START { \
|
||||||
|
guint64 __n1 = (n1), __n2 = (n2); \
|
||||||
|
if (__n1 cmp __n2) ; else \
|
||||||
|
g_assertion_message_cmpint (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
|
#n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'x'); \
|
||||||
|
} G_STMT_END
|
||||||
|
#else /* GLIB_VERSION_MIN_REQUIRED < GLIB_VERSION_2_78 */
|
||||||
#define g_assert_cmpint(n1, cmp, n2) G_STMT_START { \
|
#define g_assert_cmpint(n1, cmp, n2) G_STMT_START { \
|
||||||
gint64 __n1 = (n1), __n2 = (n2); \
|
gint64 __n1 = (n1), __n2 = (n2); \
|
||||||
if (__n1 cmp __n2) ; else \
|
if (__n1 cmp __n2) ; else \
|
||||||
@@ -67,6 +87,7 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
|
|||||||
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
#n1 " " #cmp " " #n2, (long double) __n1, #cmp, (long double) __n2, 'x'); \
|
#n1 " " #cmp " " #n2, (long double) __n1, #cmp, (long double) __n2, 'x'); \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
#endif /* GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_78 */
|
||||||
#define g_assert_cmpfloat(n1,cmp,n2) G_STMT_START { \
|
#define g_assert_cmpfloat(n1,cmp,n2) G_STMT_START { \
|
||||||
long double __n1 = (long double) (n1), __n2 = (long double) (n2); \
|
long double __n1 = (long double) (n1), __n2 = (long double) (n2); \
|
||||||
if (__n1 cmp __n2) ; else \
|
if (__n1 cmp __n2) ; else \
|
||||||
@@ -80,6 +101,25 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
|
|||||||
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
#n1 " == " #n2 " (+/- " #epsilon ")", __n1, "==", __n2, 'f'); \
|
#n1 " == " #n2 " (+/- " #epsilon ")", __n1, "==", __n2, 'f'); \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
#if GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_78
|
||||||
|
#define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
|
||||||
|
gconstpointer __m1 = m1, __m2 = m2; \
|
||||||
|
size_t __l1 = (size_t) l1, __l2 = (size_t) l2; \
|
||||||
|
if (__l1 != 0 && __m1 == NULL) \
|
||||||
|
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
|
"assertion failed (" #l1 " == 0 || " #m1 " != NULL)"); \
|
||||||
|
else if (__l2 != 0 && __m2 == NULL) \
|
||||||
|
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
|
"assertion failed (" #l2 " == 0 || " #m2 " != NULL)"); \
|
||||||
|
else if (__l1 != __l2) \
|
||||||
|
g_assertion_message_cmpint (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
|
#l1 " (len(" #m1 ")) == " #l2 " (len(" #m2 "))", \
|
||||||
|
__l1, "==", __l2, 'u'); \
|
||||||
|
else if (__l1 != 0 && __m2 != NULL && memcmp (__m1, __m2, __l1) != 0) \
|
||||||
|
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
|
"assertion failed (" #m1 " == " #m2 ")"); \
|
||||||
|
} G_STMT_END
|
||||||
|
#else /* GLIB_VERSION_MIN_REQUIRED < GLIB_VERSION_2_78 */
|
||||||
#define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
|
#define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
|
||||||
gconstpointer __m1 = m1, __m2 = m2; \
|
gconstpointer __m1 = m1, __m2 = m2; \
|
||||||
size_t __l1 = (size_t) l1, __l2 = (size_t) l2; \
|
size_t __l1 = (size_t) l1, __l2 = (size_t) l2; \
|
||||||
@@ -97,6 +137,7 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
|
|||||||
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
"assertion failed (" #m1 " == " #m2 ")"); \
|
"assertion failed (" #m1 " == " #m2 ")"); \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
#endif /* GLIB_VERSION_MIN_REQUIRED >= GLIB_VERSION_2_78 */
|
||||||
#define g_assert_cmpvariant(v1, v2) \
|
#define g_assert_cmpvariant(v1, v2) \
|
||||||
G_STMT_START \
|
G_STMT_START \
|
||||||
{ \
|
{ \
|
||||||
@@ -567,6 +608,16 @@ void g_assertion_message_cmpstrv (const char *domain,
|
|||||||
const char * const *arg1,
|
const char * const *arg1,
|
||||||
const char * const *arg2,
|
const char * const *arg2,
|
||||||
gsize first_wrong_idx) G_ANALYZER_NORETURN;
|
gsize first_wrong_idx) G_ANALYZER_NORETURN;
|
||||||
|
GLIB_AVAILABLE_IN_2_78
|
||||||
|
void g_assertion_message_cmpint (const char *domain,
|
||||||
|
const char *file,
|
||||||
|
int line,
|
||||||
|
const char *func,
|
||||||
|
const char *expr,
|
||||||
|
guint64 arg1,
|
||||||
|
const char *cmp,
|
||||||
|
guint64 arg2,
|
||||||
|
char numtype) G_ANALYZER_NORETURN;
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_ALL
|
||||||
void g_assertion_message_cmpnum (const char *domain,
|
void g_assertion_message_cmpnum (const char *domain,
|
||||||
const char *file,
|
const char *file,
|
||||||
|
@@ -4,13 +4,13 @@
|
|||||||
#define g_assert_cmpflags(type,n1, cmp, n2) G_STMT_START { \
|
#define g_assert_cmpflags(type,n1, cmp, n2) G_STMT_START { \
|
||||||
type __n1 = (n1), __n2 = (n2); \
|
type __n1 = (n1), __n2 = (n2); \
|
||||||
if (__n1 cmp __n2) ; else \
|
if (__n1 cmp __n2) ; else \
|
||||||
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
g_assertion_message_cmpint (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
#n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); \
|
#n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
#define g_assert_cmpenum(type,n1, cmp, n2) G_STMT_START { \
|
#define g_assert_cmpenum(type,n1, cmp, n2) G_STMT_START { \
|
||||||
type __n1 = (n1), __n2 = (n2); \
|
type __n1 = (n1), __n2 = (n2); \
|
||||||
if (__n1 cmp __n2) ; else \
|
if (__n1 cmp __n2) ; else \
|
||||||
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
g_assertion_message_cmpint (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
|
||||||
#n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); \
|
#n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); \
|
||||||
} G_STMT_END
|
} G_STMT_END
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user