5 test_quark_basic (void)
8 const gchar *orig = "blargh";
12 quark = g_quark_try_string ("no-such-quark");
13 g_assert (quark == 0);
15 copy = g_strdup (orig);
16 quark = g_quark_from_static_string (orig);
17 g_assert (quark != 0);
18 g_assert (g_quark_from_string (orig) == quark);
19 g_assert (g_quark_from_string (copy) == quark);
20 g_assert (g_quark_try_string (orig) == quark);
22 str = g_quark_to_string (quark);
23 g_assert_cmpstr (str, ==, orig);
29 test_quark_string (void)
31 const gchar *orig = "string1";
36 copy = g_strdup (orig);
38 str1 = g_intern_static_string (orig);
39 str2 = g_intern_string (copy);
40 g_assert (str1 == str2);
41 g_assert (str1 == orig);
47 test_dataset_basic (void)
49 gpointer location = (gpointer)test_dataset_basic;
50 gpointer other = (gpointer)test_quark_basic;
51 gpointer data = "test1";
54 g_dataset_set_data (location, "test1", data);
56 ret = g_dataset_get_data (location, "test1");
57 g_assert (ret == data);
59 ret = g_dataset_get_data (location, "test2");
60 g_assert (ret == NULL);
62 ret = g_dataset_get_data (other, "test1");
63 g_assert (ret == NULL);
65 g_dataset_set_data (location, "test1", "new-value");
66 ret = g_dataset_get_data (location, "test1");
67 g_assert (ret != data);
69 g_dataset_remove_data (location, "test1");
70 ret = g_dataset_get_data (location, "test1");
71 g_assert (ret == NULL);
74 static gint destroy_count;
77 notify (gpointer data)
83 test_dataset_full (void)
85 gpointer location = (gpointer)test_dataset_full;
87 g_dataset_set_data_full (location, "test1", "test1", notify);
90 g_dataset_set_data (location, "test1", NULL);
91 g_assert (destroy_count == 1);
93 g_dataset_set_data_full (location, "test1", "test1", notify);
96 g_dataset_remove_data (location, "test1");
97 g_assert (destroy_count == 1);
99 g_dataset_set_data_full (location, "test1", "test1", notify);
102 g_dataset_remove_no_notify (location, "test1");
103 g_assert (destroy_count == 0);
111 gint *counter = user_data;
117 test_dataset_foreach (void)
119 gpointer location = (gpointer)test_dataset_foreach;
123 g_dataset_set_data_full (location, "test1", "test1", notify);
124 g_dataset_set_data_full (location, "test2", "test2", notify);
125 g_dataset_set_data_full (location, "test3", "test3", notify);
126 g_dataset_foreach (location, foreach, &my_count);
127 g_assert (my_count == 3);
131 test_dataset_destroy (void)
133 gpointer location = (gpointer)test_dataset_destroy;
136 g_dataset_set_data_full (location, "test1", "test1", notify);
137 g_dataset_set_data_full (location, "test2", "test2", notify);
138 g_dataset_set_data_full (location, "test3", "test3", notify);
139 g_dataset_destroy (location);
140 g_assert (destroy_count == 3);
144 test_dataset_id (void)
146 gpointer location = (gpointer)test_dataset_id;
147 gpointer other = (gpointer)test_quark_basic;
148 gpointer data = "test1";
152 quark = g_quark_from_string ("test1");
154 g_dataset_id_set_data (location, quark, data);
156 ret = g_dataset_id_get_data (location, quark);
157 g_assert (ret == data);
159 ret = g_dataset_id_get_data (location, g_quark_from_string ("test2"));
160 g_assert (ret == NULL);
162 ret = g_dataset_id_get_data (other, quark);
163 g_assert (ret == NULL);
165 g_dataset_id_set_data (location, quark, "new-value");
166 ret = g_dataset_id_get_data (location, quark);
167 g_assert (ret != data);
169 g_dataset_id_remove_data (location, quark);
170 ret = g_dataset_id_get_data (location, quark);
171 g_assert (ret == NULL);
177 free_one (gpointer data)
180 g_datalist_clear (&list);
184 test_datalist_clear (void)
186 if (g_test_trap_fork (500000, 0))
188 g_datalist_init (&list);
189 g_datalist_set_data_full (&list, "one", GINT_TO_POINTER (1), free_one);
190 g_datalist_set_data_full (&list, "two", GINT_TO_POINTER (2), NULL);
191 g_datalist_clear (&list);
192 g_assert (list == NULL);
195 g_test_trap_assert_passed ();
199 main (int argc, char *argv[])
201 g_test_init (&argc, &argv, NULL);
203 g_test_add_func ("/quark/basic", test_quark_basic);
204 g_test_add_func ("/quark/string", test_quark_string);
205 g_test_add_func ("/dataset/basic", test_dataset_basic);
206 g_test_add_func ("/dataset/id", test_dataset_id);
207 g_test_add_func ("/dataset/full", test_dataset_full);
208 g_test_add_func ("/dataset/foreach", test_dataset_foreach);
209 g_test_add_func ("/dataset/destroy", test_dataset_destroy);
210 g_test_add_func ("/datalist/recursive-clear", test_datalist_clear);
212 return g_test_run ();