a68b5838125aed6679096e030a3527757140bac8
[mono.git] / eglib / test / hash.c
1 #include <stdio.h>
2 #include <glib.h>
3 #include "test.h"
4
5 int foreach_count = 0;
6 int foreach_fail = 0;
7
8 void foreach (gpointer key, gpointer value, gpointer user_data)
9 {
10         foreach_count++;
11         if (GPOINTER_TO_INT (user_data) != 'a')
12                 foreach_fail = 1;
13 }
14
15 char *hash_t1 (void)
16 {
17         GHashTable *t = g_hash_table_new (g_str_hash, g_str_equal);
18
19         g_hash_table_insert (t, "hello", "world");
20         g_hash_table_insert (t, "my", "god");
21
22         g_hash_table_foreach (t, foreach, GINT_TO_POINTER('a'));
23         if (foreach_count != 2)
24                 return "did not find all keys";
25         if (foreach_fail)
26                 return "failed to pass the user-data to foreach";
27         
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";
35                 
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);
41
42         return NULL;
43 }
44
45 char *hash_t2 (void)
46 {
47         
48 }