1 /*******************************/
2 /* GENERATED FILE, DO NOT EDIT */
3 /*******************************/
7 /*******************************/
8 /* GENERATED FILE, DO NOT EDIT */
9 /*******************************/
20 unsigned int name_len;
24 } s_my_elem_t,*my_elem_t;
27 static void my_elem_free(void *e) {
28 my_elem_t elm=(my_elem_t)e;
37 static void debuged_add(xbt_set_t set,
42 elm = xbt_new(s_my_elem_t,1);
43 elm->name=xbt_strdup(name);
46 elm->data=xbt_strdup(data);
48 xbt_test_log2("Add %s (->%s)",name,data);
49 xbt_set_add(set, (xbt_set_elm_t)elm, &my_elem_free);
52 static void fill(xbt_set_t *set) {
53 xbt_test_add0("Fill in the data set");
56 debuged_add(*set,"12", "12");
57 debuged_add(*set,"12a", "12a");
58 debuged_add(*set,"12b", "12b");
59 debuged_add(*set,"123", "123");
60 debuged_add(*set,"123456", "123456");
61 xbt_test_log0("Child becomes child of what to add");
62 debuged_add(*set,"1234", "1234");
63 xbt_test_log0("Need of common ancestor");
64 debuged_add(*set,"123457", "123457");
67 static void search_name(xbt_set_t head,const char*key) {
70 xbt_test_add1("Search by name %s",key);
71 elm = (my_elem_t)xbt_set_get_by_name(head,key);
72 xbt_test_log2(" Found %s (under ID %d)\n",
73 elm? elm->data:"(null)",
75 if (strcmp(key,elm->name))
76 THROW2(mismatch_error,0,"The key (%s) is not the one expected (%s)",
78 if (strcmp(elm->name,elm->data))
79 THROW2(mismatch_error,0,"The name (%s) != data (%s)",
84 static void search_id(xbt_set_t head,int id,const char*key) {
87 xbt_test_add1("Search by id %d",id);
88 elm = (my_elem_t) xbt_set_get_by_id(head,id);
89 xbt_test_log2("Found %s (data %s)",
90 elm? elm->name:"(null)",
91 elm? elm->data:"(null)");
93 THROW2(mismatch_error,0,"The found ID (%d) is not the one expected (%d)",
95 if (strcmp(key,elm->name))
96 THROW2(mismatch_error,0,"The key (%s) is not the one expected (%s)",
98 if (strcmp(elm->name,elm->data))
99 THROW2(mismatch_error,0,"The name (%s) != data (%s)",
100 elm->name,elm->data);
104 static void traverse(xbt_set_t set) {
105 xbt_set_cursor_t cursor=NULL;
108 xbt_set_foreach(set,cursor,elm) {
109 xbt_test_assert0(elm,"Dude ! Got a null elm during traversal!");
110 xbt_test_log3("Id(%d): %s->%s\n",elm->ID,elm->name,elm->data);
111 xbt_test_assert2(!strcmp(elm->name,elm->data),
112 "Key(%s) != value(%s). Abording",
113 elm->name,elm->data);
117 static void search_not_found(xbt_set_t set, const char *data) {
120 xbt_test_add1("Search %s (expected not to be found)",data);
122 xbt_set_get_by_name(set,data);
123 THROW1(unknown_error,0,"Found something which shouldn't be there (%s)",data);
125 if (e.category != not_found_error)
126 xbt_test_exception(e);
131 xbt_set_t set = NULL;
134 XBT_TEST_UNIT("basic",test_set_basic,"Basic usage") {
137 xbt_test_add0("Traverse the empty set");
140 xbt_test_add0("Free a data set");
144 xbt_test_add0("Free the NULL data set");
149 XBT_TEST_UNIT("change",test_set_change,"Changing some values") {
152 xbt_test_add0("Change 123 to 'Changed 123'");
153 debuged_add(set,"123","Changed 123");
155 xbt_test_add0("Change 123 back to '123'");
156 debuged_add(set,"123","123");
158 xbt_test_add0("Change 12a to 'Dummy 12a'");
159 debuged_add(set,"12a","Dummy 12a");
161 xbt_test_add0("Change 12a to '12a'");
162 debuged_add(set,"12a","12a");
164 /* xbt_dict_dump(head,(void (*)(void*))&printf); */
165 xbt_test_add0("Traverse the resulting data set");
169 XBT_TEST_UNIT("retrieve",test_set_retrieve,"Retrieving some values") {
172 xbt_test_add0("Search 123");
173 elm = (my_elem_t) xbt_set_get_by_name(set,"123");
174 xbt_test_assert0(elm,"elm must be there");
175 xbt_assert(!strcmp("123",elm->data));
177 search_not_found(set,"Can't be found");
178 search_not_found(set,"123 Can't be found");
179 search_not_found(set,"12345678 NOT");
181 search_name(set,"12");
182 search_name(set,"12a");
183 search_name(set,"12b");
184 search_name(set,"123");
185 search_name(set,"123456");
186 search_name(set,"1234");
187 search_name(set,"123457");
189 search_id(set,0,"12");
190 search_id(set,1,"12a");
191 search_id(set,2,"12b");
192 search_id(set,3,"123");
193 search_id(set,4,"123456");
194 search_id(set,5,"1234");
195 search_id(set,6,"123457");
197 xbt_test_add0("Traverse the resulting data set");
200 /* xbt_dict_dump(head,(void (*)(void*))&printf); */
202 xbt_test_add0("Free the data set (twice)");
206 xbt_test_add0("Traverse the resulting data set");
210 XBT_TEST_UNIT("remove",test_set_remove,"Removing some values") {
216 xbt_set_remove_by_name(set, "12a");
217 search_not_found(set, "12a");
219 search_name(set,"12");
220 search_name(set,"12b");
221 search_name(set,"123");
222 search_name(set,"123456");
223 search_name(set,"1234");
224 search_name(set,"123457");
226 search_id(set,0,"12");
227 search_id(set,2,"12b");
228 search_id(set,3,"123");
229 search_id(set,4,"123456");
230 search_id(set,5,"1234");
231 search_id(set,6,"123457");
233 debuged_add(set, "12anew", "12anew");
234 elm = (my_elem_t) xbt_set_get_by_id(set, 1);
235 xbt_test_assert1(elm->ID == 1, "elm->ID is %d but should be 1", elm->ID);
238 /*******************************/
239 /* GENERATED FILE, DO NOT EDIT */
240 /*******************************/