check: Add fail_unless_matches_string() and assert macros

Add string check macros for checking expected strings against
a regular expression instead of just a direct literal match
as provided by the existing fail_unless_equals_string()

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7365>
This commit is contained in:
Jan Schmidt 2024-08-16 08:53:39 +10:00 committed by GStreamer Marge Bot
parent 701165227f
commit 807dbfbebf

View file

@ -452,6 +452,37 @@ G_STMT_START { \
*/
#define assert_equals_string(a, b) fail_unless_equals_string(a, b)
/**
* fail_unless_matches_string:
* @a: a string literal or expression
* @b: a regular expression pattern string literal or expression
*
* This macro checks that @a matches the regular expression in @b 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.26
*/
#define fail_unless_matches_string(a, b) \
G_STMT_START { \
const gchar * first = a; \
const gchar * second = b; \
fail_unless(g_regex_match_simple (second, first, 0, 0), \
"'" #a "' (%s) does not match pattern '" #b"' (%s)", first, second); \
} G_STMT_END;
/**
* assert_matches_string:
* @a: a string literal or expression
* @b: a regular expression pattern string literal or expression
*
* This macro checks that @a matches the regular expression in @b 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.26
*/
#define assert_matches_string(a, b) fail_unless_matches_string(a, b)
/**
* fail_unless_equals_float:
* @a: a #gdouble or #gfloat value or expression