From e8a6d0b54e9ac80bf99857d6a238d87ff723d352 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sun, 14 Mar 2021 17:02:16 +0000 Subject: [PATCH] tests: Test various different invalid encoding names for key files These exercise different branches in `g_key_file_parse_key_value_pair()`. Signed-off-by: Philip Withnall --- glib/tests/keyfile.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/glib/tests/keyfile.c b/glib/tests/keyfile.c index 213da8278..04c0fd962 100644 --- a/glib/tests/keyfile.c +++ b/glib/tests/keyfile.c @@ -1675,21 +1675,32 @@ test_limbo (void) static void test_utf8 (void) { - GKeyFile *file; - static const char data[] = -"[group]\n" -"Encoding=non-UTF-8\n"; - gboolean ok; - GError *error; + const gchar *invalid_encoding_names[] = + { + "non-UTF-8", + "UTF", + "UTF-9", + }; + gsize i; - file = g_key_file_new (); + for (i = 0; i < G_N_ELEMENTS (invalid_encoding_names); i++) + { + GKeyFile *file = NULL; + gchar *data = NULL; + gboolean ok; + GError *error = NULL; - error = NULL; - ok = g_key_file_load_from_data (file, data, strlen (data), 0, &error); - g_assert_false (ok); - g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_UNKNOWN_ENCODING); - g_clear_error (&error); - g_key_file_free (file); + g_test_message ("Testing invalid encoding ā€˜%sā€™", invalid_encoding_names[i]); + + file = g_key_file_new (); + data = g_strdup_printf ("[group]\n" + "Encoding=%s\n", invalid_encoding_names[i]); + ok = g_key_file_load_from_data (file, data, strlen (data), 0, &error); + g_assert_false (ok); + g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_UNKNOWN_ENCODING); + g_clear_error (&error); + g_key_file_free (file); + } } static void