9 void foreach (gpointer key, gpointer value, gpointer user_data)
12 if (GPOINTER_TO_INT (user_data) != 'a')
18 GHashTable *t = g_hash_table_new (g_str_hash, g_str_equal);
20 g_hash_table_insert (t, "hello", "world");
21 g_hash_table_insert (t, "my", "god");
23 g_hash_table_foreach (t, foreach, GINT_TO_POINTER('a'));
24 if (foreach_count != 2)
25 return "did not find all keys";
27 return "failed to pass the user-data to foreach";
29 if (!g_hash_table_remove (t, "my"))
30 return "did not find known key";
31 if (g_hash_table_size (t) != 1)
32 return "unexpected size";
33 g_hash_table_insert(t, "hello", "moon");
34 if (strcmp (g_hash_table_lookup (t, "hello"), "moon") != 0)
35 return "did not replace world with moon";
37 if (!g_hash_table_remove (t, "hello"))
38 return "did not find known key";
39 if (g_hash_table_size (t) != 0)
40 return "unexpected size";
41 g_hash_table_destroy (t);
51 static Test hashtable_tests [] = {
57 DEFINE_TEST_GROUP_INIT(hashtable_tests_init, hashtable_tests)