1 /*******************************/
2 /* GENERATED FILE, DO NOT EDIT */
3 /*******************************/
6 /*******************************/
7 /* GENERATED FILE, DO NOT EDIT */
8 /*******************************/
19 unsigned int name_len;
23 } s_my_elem_t,*my_elem_t;
26 static void my_elem_free(void *e) {
27 my_elem_t elm=(my_elem_t)e;
36 static void debuged_add(xbt_set_t set,
41 elm = xbt_new(s_my_elem_t,1);
42 elm->name=xbt_strdup(name);
45 elm->data=xbt_strdup(data);
47 xbt_test_log2("Add %s (->%s)",name,data);
48 xbt_set_add(set, (xbt_set_elm_t)elm, &my_elem_free);
51 static void fill(xbt_set_t *set) {
52 xbt_test_add0("Fill in the data set");
55 debuged_add(*set,"12", "12");
56 debuged_add(*set,"12a", "12a");
57 debuged_add(*set,"12b", "12b");
58 debuged_add(*set,"123", "123");
59 debuged_add(*set,"123456", "123456");
60 xbt_test_log0("Child becomes child of what to add");
61 debuged_add(*set,"1234", "1234");
62 xbt_test_log0("Need of common ancestor");
63 debuged_add(*set,"123457", "123457");
66 static void search_name(xbt_set_t head,const char*key) {
69 xbt_test_add1("Search by name %s",key);
70 elm = (my_elem_t)xbt_set_get_by_name(head,key);
71 xbt_test_log2(" Found %s (under ID %d)\n",
72 elm? elm->data:"(null)",
74 if (strcmp(key,elm->name))
75 THROW2(mismatch_error,0,"The key (%s) is not the one expected (%s)",
77 if (strcmp(elm->name,elm->data))
78 THROW2(mismatch_error,0,"The name (%s) != data (%s)",
83 static void search_id(xbt_set_t head,int id,const char*key) {
86 xbt_test_add1("Search by id %d",id);
87 elm = (my_elem_t) xbt_set_get_by_id(head,id);
88 xbt_test_log2("Found %s (data %s)",
89 elm? elm->name:"(null)",
90 elm? elm->data:"(null)");
92 THROW2(mismatch_error,0,"The found ID (%d) is not the one expected (%d)",
94 if (strcmp(key,elm->name))
95 THROW2(mismatch_error,0,"The key (%s) is not the one expected (%s)",
97 if (strcmp(elm->name,elm->data))
98 THROW2(mismatch_error,0,"The name (%s) != data (%s)",
103 static void traverse(xbt_set_t set) {
104 xbt_set_cursor_t cursor=NULL;
107 xbt_set_foreach(set,cursor,elm) {
108 xbt_test_assert0(elm,"Dude ! Got a null elm during traversal!");
109 xbt_test_log3("Id(%d): %s->%s\n",elm->ID,elm->name,elm->data);
110 xbt_test_assert2(!strcmp(elm->name,elm->data),
111 "Key(%s) != value(%s). Abording",
112 elm->name,elm->data);
116 static void search_not_found(xbt_set_t set, const char *data) {
119 xbt_test_add1("Search %s (expected not to be found)",data);
121 xbt_set_get_by_name(set,data);
122 THROW1(unknown_error,0,"Found something which shouldn't be there (%s)",data);
124 if (e.category != not_found_error)
125 xbt_test_exception(e);
130 xbt_set_t set = NULL;
133 XBT_TEST_UNIT("basic",test_set_basic,"Basic usage") {
136 xbt_test_add0("Traverse the empty set");
139 xbt_test_add0("Free a data set");
143 xbt_test_add0("Free the NULL data set");
148 XBT_TEST_UNIT("change",test_set_change,"Changing some values") {
151 xbt_test_add0("Change 123 to 'Changed 123'");
152 debuged_add(set,"123","Changed 123");
154 xbt_test_add0("Change 123 back to '123'");
155 debuged_add(set,"123","123");
157 xbt_test_add0("Change 12a to 'Dummy 12a'");
158 debuged_add(set,"12a","Dummy 12a");
160 xbt_test_add0("Change 12a to '12a'");
161 debuged_add(set,"12a","12a");
163 /* xbt_dict_dump(head,(void (*)(void*))&printf); */
164 xbt_test_add0("Traverse the resulting data set");
168 XBT_TEST_UNIT("retrieve",test_set_retrieve,"Retrieving some values") {
171 xbt_test_add0("Search 123");
172 elm = (my_elem_t) xbt_set_get_by_name(set,"123");
173 xbt_test_assert0(elm,"elm must be there");
174 xbt_assert(!strcmp("123",elm->data));
176 search_not_found(set,"Can't be found");
177 search_not_found(set,"123 Can't be found");
178 search_not_found(set,"12345678 NOT");
180 search_name(set,"12");
181 search_name(set,"12a");
182 search_name(set,"12b");
183 search_name(set,"123");
184 search_name(set,"123456");
185 search_name(set,"1234");
186 search_name(set,"123457");
188 search_id(set,0,"12");
189 search_id(set,1,"12a");
190 search_id(set,2,"12b");
191 search_id(set,3,"123");
192 search_id(set,4,"123456");
193 search_id(set,5,"1234");
194 search_id(set,6,"123457");
196 xbt_test_add0("Traverse the resulting data set");
199 /* xbt_dict_dump(head,(void (*)(void*))&printf); */
201 xbt_test_add0("Free the data set (twice)");
205 xbt_test_add0("Traverse the resulting data set");
209 XBT_TEST_UNIT("remove",test_set_remove,"Removing some values") {
215 xbt_set_remove_by_name(set, "12a");
216 search_not_found(set, "12a");
218 search_name(set,"12");
219 search_name(set,"12b");
220 search_name(set,"123");
221 search_name(set,"123456");
222 search_name(set,"1234");
223 search_name(set,"123457");
225 search_id(set,0,"12");
226 search_id(set,2,"12b");
227 search_id(set,3,"123");
228 search_id(set,4,"123456");
229 search_id(set,5,"1234");
230 search_id(set,6,"123457");
232 debuged_add(set, "12anew", "12anew");
233 elm = (my_elem_t) xbt_set_get_by_id(set, 1);
234 xbt_test_assert1(elm->ID == 1, "elm->ID is %d but should be 1", elm->ID);
237 /*******************************/
238 /* GENERATED FILE, DO NOT EDIT */
239 /*******************************/