From 22b7c0bf584ee06f880aa968dfdc06e9559262ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Tue, 19 Feb 2013 17:36:50 +0000 Subject: [PATCH] check: add some more fail_unless_*() macros for convenience API: fail_unless_equals_int_hex API: assert_equals_int_hex API: fail_unless_equals_int64_hex API: assert_equals_int64_hex API: fail_unless_equals_uint64_hex API: assert_equals_uint64_hex API: fail_unless_equals_pointer API: assert_equals_pointer --- docs/libs/gstreamer-libs-sections.txt | 9 ++ libs/gst/check/gstcheck.h | 125 ++++++++++++++++++++++++++ tests/check/gst/gstutils.c | 16 ---- 3 files changed, 134 insertions(+), 16 deletions(-) diff --git a/docs/libs/gstreamer-libs-sections.txt b/docs/libs/gstreamer-libs-sections.txt index 5c683ac0eb..f82a565c8d 100644 --- a/docs/libs/gstreamer-libs-sections.txt +++ b/docs/libs/gstreamer-libs-sections.txt @@ -872,6 +872,11 @@ fail_unless_equals_float fail_unless_equals_string fail_unless_equals_uint64 fail_unless_equals_int64 +fail_unless_equals_int_hex +fail_unless_equals_int64_hex +fail_unless_equals_uint64_hex +fail_unless_equals_pointer + fail_unless_message_error assert_equals_int @@ -879,6 +884,10 @@ assert_equals_float assert_equals_string assert_equals_uint64 assert_equals_int64 +assert_equals_int_hex +assert_equals_int64_hex +assert_equals_uint64_hex +assert_equals_pointer assert_message_error gst_check_init diff --git a/libs/gst/check/gstcheck.h b/libs/gst/check/gstcheck.h index 0ff3c6bae1..fe3011efbc 100644 --- a/libs/gst/check/gstcheck.h +++ b/libs/gst/check/gstcheck.h @@ -149,6 +149,38 @@ G_STMT_START { \ */ #define assert_equals_int(a, b) fail_unless_equals_int(a, b) +/** + * fail_unless_equals_int_hex: + * @a: a #gint value or expression + * @b: a #gint value or expression + * + * This macro checks that @a and @b are equal and aborts if this is not the + * case, printing both expressions and the values they evaluated to in + * hexadecimal format. This macro is for use in unit tests. + * + * Since: 1.2 + */ +#define fail_unless_equals_int_hex(a, b) \ +G_STMT_START { \ + int first = a; \ + int second = b; \ + fail_unless(first == second, \ + "'" #a "' (0x%08x) is not equal to '" #b"' (0x%08x)", first, second);\ +} G_STMT_END; + +/** + * assert_equals_int_hex: + * @a: a #gint value or expression + * @b: a #gint value or expression + * + * This macro checks that @a and @b are equal and aborts if this is not the + * case, printing both expressions and the values they evaluated to in + * hexadecimal format. This macro is for use in unit tests. + * + * Since: 1.2 + */ +#define assert_equals_int_hex(a, b) fail_unless_equals_int_hex(a, b) + /** * fail_unless_equals_int64: * @a: a #gint64 value or expression @@ -177,6 +209,37 @@ G_STMT_START { \ */ #define assert_equals_int64(a, b) fail_unless_equals_int64(a, b) +/** + * fail_unless_equals_int64_hex: + * @a: a #gint64 value or expression + * @b: a #gint64 value or expression + * + * This macro checks that @a and @b are equal and aborts if this is not the + * case, printing both expressions and the values they evaluated to in + * hexadecimal format. This macro is for use in unit tests. + * + * Since: 1.2 + */ +#define fail_unless_equals_int64_hex(a, b) \ +G_STMT_START { \ + gint64 first = a; \ + gint64 second = b; \ + fail_unless(first == second, \ + "'" #a "' (0x%016x) is not equal to '" #b"' (0x%016x)", first, second);\ +} G_STMT_END; +/** + * assert_equals_int64_hex: + * @a: a #gint64 value or expression + * @b: a #gint64 value or expression + * + * This macro checks that @a and @b are equal and aborts if this is not the + * case, printing both expressions and the values they evaluated to in + * hexadecimal format. This macro is for use in unit tests. + * + * Since: 1.2 + */ +#define assert_equals_int64_hex(a,b) fail_unless_equals_int64_hex(a,b) + /** * fail_unless_equals_uint64: * @a: a #guint64 value or expression @@ -205,6 +268,37 @@ G_STMT_START { \ */ #define assert_equals_uint64(a, b) fail_unless_equals_uint64(a, b) +/** + * fail_unless_equals_uint64_hex: + * @a: a #gint64 value or expression + * @b: a #gint64 value or expression + * + * This macro checks that @a and @b are equal and aborts if this is not the + * case, printing both expressions and the values they evaluated to in + * hexadecimal format. This macro is for use in unit tests. + * + * Since: 1.2 + */ +#define fail_unless_equals_uint64_hex(a, b) \ +G_STMT_START { \ + guint64 first = a; \ + guint64 second = b; \ + fail_unless(first == second, \ + "'" #a "' (0x%016x) is not equal to '" #b"' (0x%016x)", first, second);\ +} G_STMT_END; +/** + * assert_equals_uint64_hex: + * @a: a #guint64 value or expression + * @b: a #guint64 value or expression + * + * This macro checks that @a and @b are equal and aborts if this is not the + * case, printing both expressions and the values they evaluated to in + * hexadecimal format. This macro is for use in unit tests. + * + * Since: 1.2 + */ +#define assert_equals_uint64_hex(a,b) fail_unless_equals_uint64_hex(a,b) + /** * fail_unless_equals_string: * @a: a string literal or expression @@ -262,6 +356,37 @@ G_STMT_START { \ */ #define assert_equals_float(a, b) fail_unless_equals_float(a, b) +/** + * fail_unless_equals_pointer: + * @a: a pointer value or expression + * @b: a pointer value or expression + * + * This macro checks that @a and @b are equal and aborts if this + * is not the case, printing both expressions and the values they + * evaluated to. This macro is for use in unit tests. + * + * Since: 1.2 + */ +#define fail_unless_equals_pointer(a, b) \ +G_STMT_START { \ + gpointer first = a; \ + gpointer second = b; \ + fail_unless(first == second, \ + "'" #a "' (%p) is not equal to '" #b "' (%p)", first, second);\ +} G_STMT_END; + +/** + * assert_equals_pointer: + * @a: a pointer value or expression + * @b: a pointer value or expression + * + * This macro checks that @a and @b are equal and aborts if this + * is not the case, printing both expressions and the values they + * evaluated to. This macro is for use in unit tests. + * + * Since: 1.2 + */ +#define assert_equals_pointer(a, b) fail_unless_equals_pointer(a, b) /*** * thread test macros and variables diff --git a/tests/check/gst/gstutils.c b/tests/check/gst/gstutils.c index 227fddcce8..35045f096f 100644 --- a/tests/check/gst/gstutils.c +++ b/tests/check/gst/gstutils.c @@ -1089,22 +1089,6 @@ GST_START_TEST (test_read_macros) guint32 uarray[2]; guint8 *cpointer; -#define fail_unless_equals_int_hex(a, b) \ -G_STMT_START { \ - int first = a; \ - int second = b; \ - fail_unless(first == second, \ - "'" #a "' (0x%08x) is not equal to '" #b"' (0x%08x)", first, second); \ -} G_STMT_END; - -#define fail_unless_equals_int64_hex(a, b) \ -G_STMT_START { \ - gint64 first = a; \ - gint64 second = b; \ - fail_unless(first == second, \ - "'" #a "' (0x%016x) is not equal to '" #b"' (0x%016x)", first, second); \ -} G_STMT_END; - memcpy (uarray, carray, 8); cpointer = carray;