group_node = g_key_file_lookup_group_node (key_file, group_name);
if (!group_node)
- g_set_error (error, G_KEY_FILE_ERROR,
- G_KEY_FILE_ERROR_GROUP_NOT_FOUND,
- _("Key file does not have group '%s'"),
- group_name);
- else
+ {
+ g_set_error (error, G_KEY_FILE_ERROR,
+ G_KEY_FILE_ERROR_GROUP_NOT_FOUND,
+ _("Key file does not have group '%s'"),
+ group_name);
+ return;
+ }
+
g_key_file_remove_group_node (key_file, group_node);
}
return;
}
- group->key_value_pairs = g_list_remove (group->key_value_pairs, key_file);
pair = g_key_file_lookup_key_value_pair (key_file, group, key);
if (!pair)
return;
}
- g_hash_table_remove (group->lookup_map, pair->key);
-
key_file->approximate_size -= strlen (pair->key) + strlen (pair->value) + 2;
+
+ group->key_value_pairs = g_list_remove (group->key_value_pairs, pair);
+ g_hash_table_remove (group->lookup_map, pair->key);
g_key_file_key_value_pair_free (pair);
}
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 */
static void
test_locale_string (void)
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);
+}
+
+/* http://bugzilla.gnome.org/show_bug.cgi?id=165980 */
+static void
+test_key_remove (void)
+{
+ GKeyFile *keyfile;
+ gchar *value;
+ GError *error = NULL;
+
+ const gchar *data =
+ "[group1]\n"
+ "key1=bla\n"
+ "key2=bla\n";
+
+ keyfile = load_data (data, 0);
+
+ check_string_value (keyfile, "group1", "key1", "bla");
+
+ g_key_file_remove_key (keyfile, "group1", "key1", &error);
+ check_no_error (&error);
+
+ value = g_key_file_get_string (keyfile, "group1", "key1", &error);
+ check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND);
+ g_free (value);
+
+ g_key_file_remove_key (keyfile, "group1", "key1", &error);
+ check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND);
+
+ g_key_file_remove_key (keyfile, "no such group", "key1", &error);
+ check_error (&error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND);
+
+ g_key_file_free (keyfile);
+}
+
+
int
main (int argc, char *argv[])
{
test_locale_string ();
test_lists ();
test_group_remove ();
+ test_key_remove ();
return 0;
}