8 void foreach (gpointer key, gpointer value, gpointer user_data)
11 if (GPOINTER_TO_INT (user_data) != 'a')
17 GHashTable *t = g_hash_table_new (g_str_hash, g_str_equal);
19 g_hash_table_insert (t, "hello", "world");
20 g_hash_table_insert (t, "my", "god");
22 g_hash_table_foreach (t, foreach, GINT_TO_POINTER('a'));
23 if (foreach_count != 2)
24 return "did not find all keys";
26 return "failed to pass the user-data to foreach";
28 if (!g_hash_table_remove (t, "my"))
29 return "did not find known key";
30 if (g_hash_table_size (t) != 1)
31 return "unexpected size";
32 g_hash_table_insert(t, "hello", "moon");
33 if (strcmp (g_hash_table_lookup (t, "hello"), "moon") != 0)
34 return "did not replace world with moon";
36 if (!g_hash_table_remove (t, "hello"))
37 return "did not find known key";
38 if (g_hash_table_size (t) != 0)
39 return "unexpected size";
40 g_hash_table_destroy (t);