mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 18:52:09 +01:00
tests: Add tests for UTF-8 checks for g_variant_new_string()
Brings the test coverage from the previous commit back up to 100% of lines of those functions. Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
parent
db77480d97
commit
4a72791181
@ -2886,6 +2886,15 @@ test_container (void)
|
||||
g_free (s1);
|
||||
}
|
||||
|
||||
static void
|
||||
do_failed_test (const char *test,
|
||||
const gchar *pattern)
|
||||
{
|
||||
g_test_trap_subprocess (test, 1000000, G_TEST_SUBPROCESS_DEFAULT);
|
||||
g_test_trap_assert_failed ();
|
||||
g_test_trap_assert_stderr (pattern);
|
||||
}
|
||||
|
||||
static void
|
||||
test_string (void)
|
||||
{
|
||||
@ -2937,6 +2946,35 @@ test_utf8 (void)
|
||||
g_variant_unref (value);
|
||||
}
|
||||
|
||||
static void
|
||||
test_utf8_bad_new_string (void)
|
||||
{
|
||||
g_variant_new_string ("hello\xffworld");
|
||||
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
static void
|
||||
test_utf8_bad_new_take_string (void)
|
||||
{
|
||||
g_variant_new_take_string (g_strdup ("hello\xffworld"));
|
||||
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
static void
|
||||
test_utf8_new_strings (void)
|
||||
{
|
||||
if (g_test_undefined ())
|
||||
{
|
||||
do_failed_test ("/gvariant/utf8/subprocess/bad-new-string",
|
||||
"*g_variant_new_string(): requires valid UTF-8*");
|
||||
|
||||
do_failed_test ("/gvariant/utf8/subprocess/bad-new-take-string",
|
||||
"*g_variant_new_take_string(): requires valid UTF-8*");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_containers (void)
|
||||
{
|
||||
@ -2998,15 +3036,6 @@ test_format_strings (void)
|
||||
g_assert_null (type);
|
||||
}
|
||||
|
||||
static void
|
||||
do_failed_test (const char *test,
|
||||
const gchar *pattern)
|
||||
{
|
||||
g_test_trap_subprocess (test, 1000000, G_TEST_SUBPROCESS_DEFAULT);
|
||||
g_test_trap_assert_failed ();
|
||||
g_test_trap_assert_stderr (pattern);
|
||||
}
|
||||
|
||||
static void
|
||||
test_invalid_varargs (void)
|
||||
{
|
||||
@ -5863,6 +5892,9 @@ main (int argc, char **argv)
|
||||
|
||||
g_test_add_func ("/gvariant/string", test_string);
|
||||
g_test_add_func ("/gvariant/utf8", test_utf8);
|
||||
g_test_add_func ("/gvariant/utf8/subprocess/bad-new-string", test_utf8_bad_new_string);
|
||||
g_test_add_func ("/gvariant/utf8/subprocess/bad-new-take-string", test_utf8_bad_new_take_string);
|
||||
g_test_add_func ("/gvariant/utf8-new-strings", test_utf8_new_strings);
|
||||
g_test_add_func ("/gvariant/containers", test_containers);
|
||||
g_test_add_func ("/gvariant/format-strings", test_format_strings);
|
||||
g_test_add_func ("/gvariant/invalid-varargs", test_invalid_varargs);
|
||||
|
Loading…
x
Reference in New Issue
Block a user