Add test case for group removal.

2005-02-01  Matthias Clasen  <mclasen@redhat.com>

	* tests/keyfile-test.c (test_group_remove): Add test case for
	group removal.

	* glib/gkeyfile.c (g_key_file_remove_group): Don't segfault
	if the group doesn't exist.  (#165887, Mathias Hasselmann)
This commit is contained in:
Matthias Clasen 2005-02-01 14:10:46 +00:00 committed by Matthias Clasen
parent 0e93338bc0
commit df59e8e19b
6 changed files with 104 additions and 2 deletions

View File

@ -1,3 +1,11 @@
2005-02-01 Matthias Clasen <mclasen@redhat.com>
* tests/keyfile-test.c (test_group_remove): Add test case for
group removal.
* glib/gkeyfile.c (g_key_file_remove_group): Don't segfault
if the group doesn't exist. (#165887, Mathias Hasselmann)
2005-01-30 Matthias Clasen <mclasen@redhat.com>
* tests/keyfile-test.c: Some more unit tests.

View File

@ -1,3 +1,11 @@
2005-02-01 Matthias Clasen <mclasen@redhat.com>
* tests/keyfile-test.c (test_group_remove): Add test case for
group removal.
* glib/gkeyfile.c (g_key_file_remove_group): Don't segfault
if the group doesn't exist. (#165887, Mathias Hasselmann)
2005-01-30 Matthias Clasen <mclasen@redhat.com>
* tests/keyfile-test.c: Some more unit tests.

View File

@ -1,3 +1,11 @@
2005-02-01 Matthias Clasen <mclasen@redhat.com>
* tests/keyfile-test.c (test_group_remove): Add test case for
group removal.
* glib/gkeyfile.c (g_key_file_remove_group): Don't segfault
if the group doesn't exist. (#165887, Mathias Hasselmann)
2005-01-30 Matthias Clasen <mclasen@redhat.com>
* tests/keyfile-test.c: Some more unit tests.

View File

@ -1,3 +1,11 @@
2005-02-01 Matthias Clasen <mclasen@redhat.com>
* tests/keyfile-test.c (test_group_remove): Add test case for
group removal.
* glib/gkeyfile.c (g_key_file_remove_group): Don't segfault
if the group doesn't exist. (#165887, Mathias Hasselmann)
2005-01-30 Matthias Clasen <mclasen@redhat.com>
* tests/keyfile-test.c: Some more unit tests.

View File

@ -2768,7 +2768,7 @@ g_key_file_remove_group (GKeyFile *key_file,
G_KEY_FILE_ERROR_GROUP_NOT_FOUND,
_("Key file does not have group '%s'"),
group_name);
else
g_key_file_remove_group_node (key_file, group_node);
}

View File

@ -519,6 +519,8 @@ test_boolean (void)
g_key_file_get_boolean (keyfile, "invalid", "key4", &error);
check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
g_key_file_free (keyfile);
}
/* check parsing of integer values */
@ -562,6 +564,73 @@ test_integer (void)
g_key_file_get_integer (keyfile, "invalid", "key4", &error);
check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
g_key_file_free (keyfile);
}
/* http://bugzilla.gnome.org/show_bug.cgi?id=165887 */
static void
test_group_remove (void)
{
GKeyFile *keyfile;
gchar **names;
gsize len;
GError *error = NULL;
const gchar *data =
"[group1]\n"
"[group2]\n"
"key1=bla\n"
"key2=bla\n"
"[group3]\n"
"key1=bla\n"
"key2=bla\n";
keyfile = load_data (data, 0);
names = g_key_file_get_groups (keyfile, &len);
if (names == NULL)
{
g_print ("Error listing groups\n");
exit (1);
}
check_length ("groups", g_strv_length (names), len, 3);
check_name ("group name", names[0], "group1", 0);
check_name ("group name", names[1], "group2", 1);
check_name ("group name", names[2], "group3", 2);
g_key_file_remove_group (keyfile, "group1", &error);
check_no_error (&error);
names = g_key_file_get_groups (keyfile, &len);
if (names == NULL)
{
g_print ("Error listing groups\n");
exit (1);
}
check_length ("groups", g_strv_length (names), len, 2);
check_name ("group name", names[0], "group2", 0);
check_name ("group name", names[1], "group3", 1);
g_key_file_remove_group (keyfile, "group2", &error);
check_no_error (&error);
names = g_key_file_get_groups (keyfile, &len);
if (names == NULL)
{
g_print ("Error listing groups\n");
exit (1);
}
check_length ("groups", g_strv_length (names), len, 1);
check_name ("group name", names[0], "group3", 0);
g_key_file_remove_group (keyfile, "no such group", &error);
check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND);
g_key_file_free (keyfile);
}
/* check handling of translated strings */
@ -680,6 +749,7 @@ main (int argc, char *argv[])
test_integer ();
test_locale_string ();
test_lists ();
test_group_remove ();
return 0;
}