4 test_quark_basic (void)
7 const gchar
*orig
= "blargh";
11 quark
= g_quark_try_string ("no-such-quark");
12 g_assert (quark
== 0);
14 copy
= g_strdup (orig
);
15 quark
= g_quark_from_static_string (orig
);
16 g_assert (quark
!= 0);
17 g_assert (g_quark_from_string (orig
) == quark
);
18 g_assert (g_quark_from_string (copy
) == quark
);
19 g_assert (g_quark_try_string (orig
) == quark
);
21 str
= g_quark_to_string (quark
);
22 g_assert_cmpstr (str
, ==, orig
);
28 test_quark_string (void)
30 const gchar
*orig
= "string1";
35 copy
= g_strdup (orig
);
37 str1
= g_intern_static_string (orig
);
38 str2
= g_intern_string (copy
);
39 g_assert (str1
== str2
);
40 g_assert (str1
== orig
);
46 test_dataset_basic (void)
48 gpointer location
= (gpointer
)test_dataset_basic
;
49 gpointer other
= (gpointer
)test_quark_basic
;
50 gpointer data
= "test1";
53 g_dataset_set_data (location
, "test1", data
);
55 ret
= g_dataset_get_data (location
, "test1");
56 g_assert (ret
== data
);
58 ret
= g_dataset_get_data (location
, "test2");
59 g_assert (ret
== NULL
);
61 ret
= g_dataset_get_data (other
, "test1");
62 g_assert (ret
== NULL
);
64 g_dataset_set_data (location
, "test1", "new-value");
65 ret
= g_dataset_get_data (location
, "test1");
66 g_assert (ret
!= data
);
68 g_dataset_remove_data (location
, "test1");
69 ret
= g_dataset_get_data (location
, "test1");
70 g_assert (ret
== NULL
);
73 static gint destroy_count
;
76 notify (gpointer data
)
82 test_dataset_full (void)
84 gpointer location
= (gpointer
)test_dataset_full
;
86 g_dataset_set_data_full (location
, "test1", "test1", notify
);
89 g_dataset_set_data (location
, "test1", NULL
);
90 g_assert (destroy_count
== 1);
92 g_dataset_set_data_full (location
, "test1", "test1", notify
);
95 g_dataset_remove_data (location
, "test1");
96 g_assert (destroy_count
== 1);
98 g_dataset_set_data_full (location
, "test1", "test1", notify
);
101 g_dataset_remove_no_notify (location
, "test1");
102 g_assert (destroy_count
== 0);
110 gint
*counter
= user_data
;
116 test_dataset_foreach (void)
118 gpointer location
= (gpointer
)test_dataset_foreach
;
122 g_dataset_set_data_full (location
, "test1", "test1", notify
);
123 g_dataset_set_data_full (location
, "test2", "test2", notify
);
124 g_dataset_set_data_full (location
, "test3", "test3", notify
);
125 g_dataset_foreach (location
, foreach
, &my_count
);
126 g_assert (my_count
== 3);
130 test_dataset_destroy (void)
132 gpointer location
= (gpointer
)test_dataset_destroy
;
135 g_dataset_set_data_full (location
, "test1", "test1", notify
);
136 g_dataset_set_data_full (location
, "test2", "test2", notify
);
137 g_dataset_set_data_full (location
, "test3", "test3", notify
);
138 g_dataset_destroy (location
);
139 g_assert (destroy_count
== 3);
143 test_dataset_id (void)
145 gpointer location
= (gpointer
)test_dataset_id
;
146 gpointer other
= (gpointer
)test_quark_basic
;
147 gpointer data
= "test1";
151 quark
= g_quark_from_string ("test1");
153 g_dataset_id_set_data (location
, quark
, data
);
155 ret
= g_dataset_id_get_data (location
, quark
);
156 g_assert (ret
== data
);
158 ret
= g_dataset_id_get_data (location
, g_quark_from_string ("test2"));
159 g_assert (ret
== NULL
);
161 ret
= g_dataset_id_get_data (other
, quark
);
162 g_assert (ret
== NULL
);
164 g_dataset_id_set_data (location
, quark
, "new-value");
165 ret
= g_dataset_id_get_data (location
, quark
);
166 g_assert (ret
!= data
);
168 g_dataset_id_remove_data (location
, quark
);
169 ret
= g_dataset_id_get_data (location
, quark
);
170 g_assert (ret
== NULL
);
174 main (int argc
, char *argv
[])
176 g_test_init (&argc
, &argv
, NULL
);
178 g_test_add_func ("/quark/basic", test_quark_basic
);
179 g_test_add_func ("/quark/string", test_quark_string
);
180 g_test_add_func ("/dataset/basic", test_dataset_basic
);
181 g_test_add_func ("/dataset/id", test_dataset_id
);
182 g_test_add_func ("/dataset/full", test_dataset_full
);
183 g_test_add_func ("/dataset/foreach", test_dataset_foreach
);
184 g_test_add_func ("/dataset/destroy", test_dataset_destroy
);
186 return g_test_run ();