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 <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2021-03-14 17:02:16 +00:00
parent d2e5c61104
commit e8a6d0b54e

View File

@ -1675,21 +1675,32 @@ test_limbo (void)
static void static void
test_utf8 (void) test_utf8 (void)
{ {
GKeyFile *file; const gchar *invalid_encoding_names[] =
static const char data[] = {
"[group]\n" "non-UTF-8",
"Encoding=non-UTF-8\n"; "UTF",
gboolean ok; "UTF-9",
GError *error; };
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; g_test_message ("Testing invalid encoding %s", invalid_encoding_names[i]);
ok = g_key_file_load_from_data (file, data, strlen (data), 0, &error);
g_assert_false (ok); file = g_key_file_new ();
g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_UNKNOWN_ENCODING); data = g_strdup_printf ("[group]\n"
g_clear_error (&error); "Encoding=%s\n", invalid_encoding_names[i]);
g_key_file_free (file); 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 static void