File: | bld/../collection/collection_ut.c |
Location: | line 1719, column 5 |
Description: | Value stored to 'error' is never read |
1 | /* |
2 | COLLECTION LIBRARY |
3 | |
4 | Collection unit test. |
5 | |
6 | Copyright (C) Dmitri Pal <dpal@redhat.com> 2009 |
7 | |
8 | Collection Library is free software: you can redistribute it and/or modify |
9 | it under the terms of the GNU Lesser General Public License as published by |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. |
12 | |
13 | Collection Library is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU Lesser General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Lesser General Public License |
19 | along with Collection Library. If not, see <http://www.gnu.org/licenses/>. |
20 | */ |
21 | |
22 | #include "config.h" |
23 | #include <stdio.h> |
24 | #include <string.h> |
25 | #include <errno(*__errno_location ()).h> |
26 | #define TRACE_HOME |
27 | #include "trace.h" |
28 | #include "collection.h" |
29 | #include "collection_tools.h" |
30 | |
31 | typedef int (*test_fn)(void); |
32 | |
33 | int verbose = 0; |
34 | |
35 | #define COLOUT(foo)do { if (verbose) foo; } while(0) \ |
36 | do { \ |
37 | if (verbose) foo; \ |
38 | } while(0) |
39 | |
40 | |
41 | |
42 | int ref_collection_test(void) |
43 | { |
44 | struct collection_item *peer = NULL((void*)0); |
45 | struct collection_item *socket = NULL((void*)0); |
46 | struct collection_item *socket2 = NULL((void*)0); |
47 | char binary_dump[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; |
48 | |
49 | int error = EOK0; |
50 | |
51 | TRACE_FLOW_STRING("ref_collection_test", "Entry."); |
52 | |
53 | COLOUT(printf("\n\nREF TEST!!!.\n\n\n"))do { if (verbose) printf("\n\nREF TEST!!!.\n\n\n"); } while(0 ); |
54 | COLOUT(printf("Creating PEER collection.\n"))do { if (verbose) printf("Creating PEER collection.\n"); } while (0); |
55 | |
56 | if ((error = col_create_collection(&peer, "peer", 0)) || |
57 | (error = col_add_str_property(peer, NULL((void*)0), "hostname", "peerhost.mytest.com", 0)) || |
58 | /* Expect trailing zero to be truncated */ |
59 | (error = col_add_str_property(peer, NULL((void*)0), "IPv4", "10.10.10.10", 12)) || |
60 | (error = col_add_str_property(peer, NULL((void*)0), "IPv6", "bla:bla:bla:bla:bla:bla", 0))) { |
61 | printf("Failed to add property. Error %d\n", error); |
62 | col_destroy_collection(peer); |
63 | return error; |
64 | } |
65 | |
66 | COLOUT(printf("Creating SOCKET collection.\n"))do { if (verbose) printf("Creating SOCKET collection.\n"); } while (0); |
67 | |
68 | if ((error = col_create_collection(&socket, "socket", 0)) || |
69 | (error = col_add_int_property(socket, NULL((void*)0), "id", 1)) || |
70 | (error = col_add_long_property(socket, NULL((void*)0), "packets", 100000000L)) || |
71 | (error = col_add_binary_property(socket, NULL((void*)0), "stack", binary_dump, sizeof(binary_dump)))) { |
72 | col_destroy_collection(peer); |
73 | col_destroy_collection(socket); |
74 | printf("Failed to add property. Error %d\n", error); |
75 | return error; |
76 | } |
77 | |
78 | COLOUT(col_debug_collection(socket, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket, 0x00000000); } while(0); |
79 | COLOUT(col_debug_collection(peer, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(peer, 0x00000000); } while (0); |
80 | |
81 | COLOUT(printf("Adding PEER collection to SOCKET collection as a reference named PEER\n"))do { if (verbose) printf("Adding PEER collection to SOCKET collection as a reference named PEER\n" ); } while(0); |
82 | |
83 | /* Embed peer host into the socket2 as reference */ |
84 | error = col_add_collection_to_collection(socket, NULL((void*)0), "peer", peer, COL_ADD_MODE_REFERENCE0); |
85 | if (error) { |
86 | col_destroy_collection(peer); |
87 | col_destroy_collection(socket); |
88 | printf("Failed to add collection to collection. Error %d\n", error); |
89 | return error; |
90 | } |
91 | |
92 | COLOUT(col_debug_collection(socket, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket, 0x00000000); } while(0); |
93 | COLOUT(col_debug_collection(peer, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(peer, 0x00000000); } while (0); |
94 | |
95 | COLOUT(printf("About to destroy PEER\n"))do { if (verbose) printf("About to destroy PEER\n"); } while( 0); |
96 | col_destroy_collection(peer); |
97 | COLOUT(col_debug_collection(socket, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket, 0x00000000); } while(0); |
98 | |
99 | COLOUT(printf("About to extract PEER\n"))do { if (verbose) printf("About to extract PEER\n"); } while( 0); |
100 | error = col_get_collection_reference(socket, &peer, "peer"); |
101 | if (error) { |
102 | col_destroy_collection(socket); |
103 | printf("Failed to extract collection. Error %d\n", error); |
104 | return error; |
105 | } |
106 | |
107 | COLOUT(col_debug_collection(socket, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket, 0x00000000); } while(0); |
108 | COLOUT(col_debug_collection(peer, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(peer, 0x00000000); } while (0); |
109 | col_destroy_collection(peer); |
110 | |
111 | COLOUT(col_debug_collection(socket, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket, 0x00000000); } while(0); |
112 | |
113 | error = col_get_collection_reference(socket, &socket2, NULL((void*)0)); |
114 | if (error) { |
115 | col_destroy_collection(socket); |
116 | printf("Failed to extract collection. Error %d\n", error); |
117 | return error; |
118 | } |
119 | |
120 | COLOUT(col_debug_collection(socket2, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket2, 0x00000000); } while(0); |
121 | col_destroy_collection(socket); |
122 | COLOUT(col_debug_collection(socket2, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket2, 0x00000000); } while(0); |
123 | col_destroy_collection(socket2); |
124 | |
125 | TRACE_FLOW_NUMBER("ref_collection_test. Returning", error); |
126 | |
127 | COLOUT(printf("\n\nEND OF REF TEST!!!.\n\n\n"))do { if (verbose) printf("\n\nEND OF REF TEST!!!.\n\n\n"); } while (0); |
128 | |
129 | return error; |
130 | |
131 | } |
132 | |
133 | |
134 | int single_collection_test(void) |
135 | { |
136 | struct collection_item *handle = NULL((void*)0); |
137 | int error = EOK0; |
138 | |
139 | TRACE_FLOW_STRING("single_collection_test", "Entry."); |
140 | |
141 | if ((error = col_create_collection(&handle, "string_test", 0)) || |
142 | (error = col_add_str_property(handle, NULL((void*)0), "property_1", "some data", 0)) || |
143 | (error = col_add_str_property(handle, NULL((void*)0), "property_2", "some other data", 2)) || |
144 | (error = col_add_str_property(handle, NULL((void*)0), "property_3", "more data", 7))) { |
145 | printf("Failed to add property. Error %d\n", error); |
146 | col_destroy_collection(handle); |
147 | return error; |
148 | } |
149 | |
150 | error = col_add_str_property(handle, NULL((void*)0), "property 1!", "some data", 0); |
151 | if (error) { |
152 | COLOUT(printf("Expected error adding bad property to collection %d\n", error))do { if (verbose) printf("Expected error adding bad property to collection %d\n" , error); } while(0); |
153 | } |
154 | else { |
155 | printf("Expected error but got success\n"); |
156 | return -1; |
157 | } |
158 | |
159 | error = col_add_double_property(handle, NULL((void*)0), "double", 0.253545); |
160 | if (error) { |
161 | printf("Failed to add double property. Error %d\n", error); |
162 | col_destroy_collection(handle); |
163 | return error; |
164 | } |
165 | |
166 | error = col_update_double_property(handle, "double", COL_TRAVERSE_DEFAULT0x00000000, 1.999999); |
167 | if (error) { |
168 | printf("Failed to update double property. Error %d\n", error); |
169 | col_destroy_collection(handle); |
170 | return error; |
171 | } |
172 | |
173 | COLOUT(printf("Created collection\n"))do { if (verbose) printf("Created collection\n"); } while(0); |
174 | |
175 | /* Traverse collection */ |
176 | if (verbose) { |
177 | error = col_debug_collection(handle, COL_TRAVERSE_DEFAULT0x00000000); |
178 | if (error) { |
179 | printf("Error debugging collection %d\n", error); |
180 | return error; |
181 | } |
182 | error = col_print_collection(handle); |
183 | if (error) { |
184 | printf("Error printing collection %d\n", error); |
185 | return error; |
186 | } |
187 | } |
188 | |
189 | col_destroy_collection(handle); |
190 | |
191 | TRACE_FLOW_NUMBER("single_collection_test. Error: ", error); |
192 | return error; |
193 | } |
194 | |
195 | int add_collection_test(void) |
196 | { |
197 | struct collection_item *peer = NULL((void*)0); |
198 | struct collection_item *socket = NULL((void*)0); |
199 | char binary_dump[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; |
200 | |
201 | int error = EOK0; |
202 | |
203 | TRACE_FLOW_STRING("add_collection_test", "Entry."); |
204 | |
205 | COLOUT(printf("\n\nADD TEST!!!.\n\n\n"))do { if (verbose) printf("\n\nADD TEST!!!.\n\n\n"); } while(0 ); |
206 | COLOUT(printf("Creating PEER collection.\n"))do { if (verbose) printf("Creating PEER collection.\n"); } while (0); |
207 | |
208 | if ((error = col_create_collection(&peer, "peer", 0)) || |
209 | (error = col_add_str_property(peer, NULL((void*)0), "hostname", "peerhost.mytest.com", 0)) || |
210 | /* Expect trailing zero to be truncated */ |
211 | (error = col_add_str_property(peer, NULL((void*)0), "IPv4", "10.10.10.10", 12)) || |
212 | (error = col_add_str_property(peer, NULL((void*)0), "IPv6", "bla:bla:bla:bla:bla:bla", 0))) { |
213 | printf("Failed to add property. Error %d", error); |
214 | col_destroy_collection(peer); |
215 | return error; |
216 | } |
217 | |
218 | COLOUT(printf("Creating SOCKET collection.\n"))do { if (verbose) printf("Creating SOCKET collection.\n"); } while (0); |
219 | |
220 | if ((error = col_create_collection(&socket, "socket", 0)) || |
221 | (error = col_add_int_property(socket, NULL((void*)0), "id", 1)) || |
222 | (error = col_add_long_property(socket, NULL((void*)0), "packets", 100000000L)) || |
223 | (error = col_add_binary_property(socket, NULL((void*)0), "stack", binary_dump, sizeof(binary_dump)))) { |
224 | col_destroy_collection(peer); |
225 | col_destroy_collection(socket); |
226 | printf("Failed to add property. Error %d\n", error); |
227 | return error; |
228 | } |
229 | |
230 | COLOUT(col_debug_collection(socket, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket, 0x00000000); } while(0); |
231 | COLOUT(col_debug_collection(peer, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(peer, 0x00000000); } while (0); |
232 | |
233 | COLOUT(printf("Adding PEER collection to SOCKET collection as a reference named PEER\n"))do { if (verbose) printf("Adding PEER collection to SOCKET collection as a reference named PEER\n" ); } while(0); |
234 | |
235 | /* Embed peer host into the socket2 as reference */ |
236 | error = col_add_collection_to_collection(socket, NULL((void*)0), "peer", peer, COL_ADD_MODE_REFERENCE0); |
237 | if (error) { |
238 | col_destroy_collection(peer); |
239 | col_destroy_collection(socket); |
240 | printf("Failed to create collection. Error %d\n", error); |
241 | return error; |
242 | } |
243 | |
244 | COLOUT(col_debug_collection(socket, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket, 0x00000000); } while(0); |
245 | COLOUT(col_debug_collection(peer, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(peer, 0x00000000); } while (0); |
246 | col_destroy_collection(peer); |
247 | COLOUT(col_debug_collection(socket, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket, 0x00000000); } while(0); |
248 | col_destroy_collection(socket); |
249 | TRACE_FLOW_NUMBER("add_collection_test. Returning", error); |
250 | return error; |
251 | } |
252 | |
253 | int copy_cb(struct collection_item *item, |
254 | void *ext_data, |
255 | int *skip) |
256 | { |
257 | COLOUT(printf("INSIDE Copy Callback\n"))do { if (verbose) printf("INSIDE Copy Callback\n"); } while(0 ); |
258 | COLOUT(col_debug_item(item))do { if (verbose) col_debug_item(item); } while(0); |
259 | COLOUT(printf("Passed in data: %s\n", (char *) ext_data))do { if (verbose) printf("Passed in data: %s\n", (char *) ext_data ); } while(0); |
260 | if (strcmp(col_get_item_property(item, NULL((void*)0)), "id") == 0) *skip = 1; |
261 | return EOK0; |
262 | } |
263 | |
264 | |
265 | int mixed_collection_test(void) |
266 | { |
267 | struct collection_item *peer; |
268 | struct collection_item *socket1; |
269 | struct collection_item *socket2; |
270 | struct collection_item *socket3; |
271 | struct collection_item *event; |
272 | struct collection_item *host; |
273 | char binary_dump[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; |
274 | int found = 0; |
275 | unsigned int class = 0; |
276 | char foo[] = "foo"; |
277 | |
278 | int error = EOK0; |
279 | |
280 | TRACE_FLOW_STRING("mixed_collection_test", "Entry."); |
281 | |
282 | COLOUT(printf("\n\nMIXED TEST!!!.\n\n\n"))do { if (verbose) printf("\n\nMIXED TEST!!!.\n\n\n"); } while (0); |
283 | COLOUT(printf("Creating PEER collection.\n"))do { if (verbose) printf("Creating PEER collection.\n"); } while (0); |
284 | |
285 | if ((error = col_create_collection(&peer, "peer", 0)) || |
286 | (error = col_add_str_property(peer, NULL((void*)0), "hostname", "peerhost.mytest.com", 0)) || |
287 | /* Expect trailing zero to be truncated */ |
288 | (error = col_add_str_property(peer, NULL((void*)0), "IPv4", "10.10.10.10", 12)) || |
289 | (error = col_add_str_property(peer, NULL((void*)0), "IPv6", "bla:bla:bla:bla:bla:bla", 0))) { |
290 | printf("Failed to add property. Error %d", error); |
291 | col_destroy_collection(peer); |
292 | return error; |
293 | } |
294 | |
295 | COLOUT(col_debug_collection(peer, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(peer, 0x00000000); } while (0); |
296 | |
297 | COLOUT(printf("Creating HOST collection.\n"))do { if (verbose) printf("Creating HOST collection.\n"); } while (0); |
298 | |
299 | if ((error = col_create_collection(&host, "host", 0)) || |
300 | (error = col_add_str_property(host, NULL((void*)0), "hostname", "myhost.mytest.com", 0)) || |
301 | (error = col_add_str_property(host, NULL((void*)0), "IPv4", "20.20.20.20", 13)) || |
302 | (error = col_add_str_property(host, NULL((void*)0), "IPv6", "bla:bla:bla:bla:bla:bla", 0)) || |
303 | (error = col_add_double_property(host, NULL((void*)0), "double", 0.253545))) { |
304 | printf("Failed to add property. Error %d", error); |
305 | col_destroy_collection(peer); |
306 | col_destroy_collection(host); |
307 | return error; |
308 | } |
309 | |
310 | COLOUT(col_debug_collection(host, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(host, 0x00000000); } while (0); |
311 | |
312 | COLOUT(printf("Creating SOCKET1 collection.\n"))do { if (verbose) printf("Creating SOCKET1 collection.\n"); } while(0); |
313 | |
314 | if ((error = col_create_collection(&socket1, "socket1", 0)) || |
315 | (error = col_add_int_property(socket1, NULL((void*)0), "id", 1)) || |
316 | (error = col_add_long_property(socket1, NULL((void*)0), "packets", 100000000L)) || |
317 | (error = col_add_binary_property(socket1, NULL((void*)0), "stack", binary_dump, sizeof(binary_dump)))) { |
318 | col_destroy_collection(peer); |
319 | col_destroy_collection(host); |
320 | col_destroy_collection(socket1); |
321 | printf("Failed to add property. Error %d\n", error); |
322 | return error; |
323 | } |
324 | |
325 | COLOUT(col_debug_collection(socket1, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket1, 0x00000000); } while(0); |
326 | COLOUT(printf("Creating a copy of SOCKET1 collection named SOCKET2.\n"))do { if (verbose) printf("Creating a copy of SOCKET1 collection named SOCKET2.\n" ); } while(0); |
327 | |
328 | error = col_copy_collection(&socket2, socket1, "socket2", COL_COPY_NORMAL0); |
329 | if (error) { |
330 | col_destroy_collection(peer); |
331 | col_destroy_collection(host); |
332 | col_destroy_collection(socket1); |
333 | printf("Failed to copy collection. Error %d\n", error); |
334 | return error; |
335 | } |
336 | |
337 | COLOUT(col_debug_collection(socket2, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket2, 0x00000000); } while(0); |
338 | COLOUT(col_debug_collection(peer, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(peer, 0x00000000); } while (0); |
339 | |
340 | error = col_copy_collection_with_cb(&socket3, socket1, "socket3", |
341 | COL_COPY_FLATDOT2, copy_cb, (void *)foo); |
342 | if (error) { |
343 | col_destroy_collection(peer); |
344 | col_destroy_collection(host); |
345 | col_destroy_collection(socket1); |
346 | col_destroy_collection(socket2); |
347 | printf("Failed to copy collection. Error %d\n", error); |
348 | return error; |
349 | } |
350 | |
351 | COLOUT(col_debug_collection(socket3, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket3, 0x00000000); } while(0); |
352 | col_destroy_collection(socket3); |
353 | |
354 | COLOUT(printf("Adding PEER collection to SOCKET2 collection as a reference named PEER2\n"))do { if (verbose) printf("Adding PEER collection to SOCKET2 collection as a reference named PEER2\n" ); } while(0); |
355 | |
356 | /* Embed peer host into the socket2 as reference */ |
357 | error = col_add_collection_to_collection(socket2, NULL((void*)0), "peer2", peer, COL_ADD_MODE_REFERENCE0); |
358 | if (error) { |
359 | col_destroy_collection(peer); |
360 | col_destroy_collection(host); |
361 | col_destroy_collection(socket1); |
362 | col_destroy_collection(socket2); |
363 | printf("Failed to create collection. Error %d\n", error); |
364 | return error; |
365 | } |
366 | |
367 | COLOUT(col_debug_collection(socket2, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket2, 0x00000000); } while(0); |
368 | |
369 | COLOUT(printf("Creating an EVENT collection.\n"))do { if (verbose) printf("Creating an EVENT collection.\n"); } while(0); |
370 | |
371 | /* Construct event */ |
372 | error = col_create_collection(&event, "event", 0); |
373 | if (error) { |
374 | col_destroy_collection(peer); |
375 | col_destroy_collection(host); |
376 | col_destroy_collection(socket1); |
377 | col_destroy_collection(socket2); |
378 | printf("Failed to create collection. Error %d\n", error); |
379 | return error; |
380 | } |
381 | |
382 | COLOUT(col_debug_collection(event, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(event, 0x00000000); } while (0); |
383 | |
384 | COLOUT(printf("Adding HOST to EVENT.\n"))do { if (verbose) printf("Adding HOST to EVENT.\n"); } while( 0); |
385 | |
386 | /* Add host to event */ |
387 | error = col_add_collection_to_collection(event, NULL((void*)0), NULL((void*)0), host, COL_ADD_MODE_REFERENCE0); |
388 | if (error) { |
389 | col_destroy_collection(peer); |
390 | col_destroy_collection(host); |
391 | col_destroy_collection(socket1); |
392 | col_destroy_collection(socket2); |
393 | col_destroy_collection(event); |
394 | printf("Failed to add collections. Error %d\n", error); |
395 | return error; |
396 | } |
397 | |
398 | COLOUT(col_debug_collection(event, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(event, 0x00000000); } while (0); |
399 | |
400 | COLOUT(printf("Embed SOCKET1 into EVENT.\n"))do { if (verbose) printf("Embed SOCKET1 into EVENT.\n"); } while (0); |
401 | /* Donate socket1 to event */ |
402 | /* Socket1 should not be used after this */ |
403 | error = col_add_collection_to_collection(event, NULL((void*)0), NULL((void*)0), socket1, COL_ADD_MODE_EMBED1); |
404 | if (error) { |
405 | col_destroy_collection(peer); |
406 | col_destroy_collection(host); |
407 | col_destroy_collection(socket1); |
408 | col_destroy_collection(socket2); |
409 | col_destroy_collection(event); |
410 | printf("Failed to add collections. Error %d\n", error); |
411 | return error; |
412 | } |
413 | |
414 | COLOUT(printf("Traverse one level:\n"))do { if (verbose) printf("Traverse one level:\n"); } while(0); |
415 | COLOUT(col_debug_collection(event, COL_TRAVERSE_ONELEVEL))do { if (verbose) col_debug_collection(event, 0x00000001); } while (0); |
416 | COLOUT(printf("Traverse ignore subcollections:\n"))do { if (verbose) printf("Traverse ignore subcollections:\n") ; } while(0); |
417 | COLOUT(col_debug_collection(event, COL_TRAVERSE_IGNORE))do { if (verbose) col_debug_collection(event, 0x00000004); } while (0); |
418 | COLOUT(printf("Traverse normal:\n"))do { if (verbose) printf("Traverse normal:\n"); } while(0); |
419 | COLOUT(col_debug_collection(event, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(event, 0x00000000); } while (0); |
420 | COLOUT(col_debug_collection(socket1, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket1, 0x00000000); } while(0); |
421 | |
422 | COLOUT(printf("SOCKET1 MUST NOT BE USED AFTER THIS POINT!!!\n"))do { if (verbose) printf("SOCKET1 MUST NOT BE USED AFTER THIS POINT!!!\n" ); } while(0); |
423 | socket1 = NULL((void*)0); |
424 | |
425 | COLOUT(printf("Add collection PEER as PEER1 to subcollection SOCKET1 of the EVENT.\n"))do { if (verbose) printf("Add collection PEER as PEER1 to subcollection SOCKET1 of the EVENT.\n" ); } while(0); |
426 | |
427 | COLOUT(col_debug_collection(peer, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(peer, 0x00000000); } while (0); |
428 | |
429 | error = col_add_collection_to_collection(event, "socket1", "peer1", peer, COL_ADD_MODE_CLONE2); |
430 | if (error) { |
431 | col_destroy_collection(peer); |
432 | col_destroy_collection(host); |
433 | /* No socket1 any more :) */ |
434 | col_destroy_collection(socket2); |
435 | col_destroy_collection(event); |
436 | printf("Failed to add collections. Error %d\n", error); |
437 | return error; |
438 | } |
439 | |
440 | COLOUT(col_debug_collection(event, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(event, 0x00000000); } while (0); |
441 | |
442 | COLOUT(printf("Add property named TIMEOUT to PEER collection.\n"))do { if (verbose) printf("Add property named TIMEOUT to PEER collection.\n" ); } while(0); |
443 | |
444 | /* Add new property to the peer collection */ |
445 | error = col_add_int_property(peer, NULL((void*)0), "timeout", 5); |
446 | if (error) { |
447 | col_destroy_collection(peer); |
448 | col_destroy_collection(host); |
449 | /* No socket1 any more :) */ |
450 | col_destroy_collection(socket2); |
451 | col_destroy_collection(event); |
452 | printf("Failed to add property. Error %d\n", error); |
453 | return error; |
454 | } |
455 | |
456 | COLOUT(col_debug_collection(socket2, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(socket2, 0x00000000); } while(0); |
457 | |
458 | COLOUT(printf("Add property named DELAY to PEER1 collection.\n"))do { if (verbose) printf("Add property named DELAY to PEER1 collection.\n" ); } while(0); |
459 | |
460 | error = col_add_int_property(event, "peer1", "delay", 10); |
461 | if (error) { |
462 | col_destroy_collection(peer); |
463 | col_destroy_collection(host); |
464 | /* No socket1 any more :) */ |
465 | col_destroy_collection(socket2); |
466 | col_destroy_collection(event); |
467 | printf("Failed to add property. Error %d\n", error); |
468 | return error; |
469 | } |
470 | |
471 | COLOUT(col_debug_collection(event, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(event, 0x00000000); } while (0); |
472 | COLOUT(col_debug_collection(host, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(host, 0x00000000); } while (0); |
473 | |
474 | COLOUT(printf("Check if property PEER1.DELAY is in the EVENT collection.\n"))do { if (verbose) printf("Check if property PEER1.DELAY is in the EVENT collection.\n" ); } while(0); |
475 | |
476 | /* Check if the property in the collection */ |
477 | found = 0; |
478 | error = col_is_item_in_collection(event, "peer1!delay", COL_TYPE_ANY0x0FFFFFFF, COL_TRAVERSE_DEFAULT0x00000000, &found); |
479 | if (error) { |
480 | col_destroy_collection(peer); |
481 | col_destroy_collection(host); |
482 | /* No socket1 any more :) */ |
483 | col_destroy_collection(socket2); |
484 | col_destroy_collection(event); |
485 | printf("Failed to check property. Error %d\n", error); |
486 | return error; |
487 | } |
488 | |
489 | if (found == 1) { |
490 | COLOUT(printf("Property is found!\n"))do { if (verbose) printf("Property is found!\n"); } while(0); |
491 | } |
492 | else { |
493 | COLOUT(printf("Error property is not found!\n"))do { if (verbose) printf("Error property is not found!\n"); } while(0); |
494 | } |
495 | |
496 | |
497 | COLOUT(col_print_item(event, "peer1!IPv6"))do { if (verbose) col_print_item(event, "peer1!IPv6"); } while (0); |
498 | COLOUT(col_print_item(event, "event!socket1!peer1!IPv6"))do { if (verbose) col_print_item(event, "event!socket1!peer1!IPv6" ); } while(0); |
499 | COLOUT(col_print_item(event, "event!peer1!IPv6"))do { if (verbose) col_print_item(event, "event!peer1!IPv6"); } while(0); |
500 | COLOUT(col_print_item(event, "speer1!IPv6"))do { if (verbose) col_print_item(event, "speer1!IPv6"); } while (0); |
501 | COLOUT(col_print_item(event, "eer1!IPv6"))do { if (verbose) col_print_item(event, "eer1!IPv6"); } while (0); |
502 | COLOUT(col_print_item(event, "!peer1!IPv6"))do { if (verbose) col_print_item(event, "!peer1!IPv6"); } while (0); |
503 | COLOUT(col_print_item(event, "t!peer1!IPv6"))do { if (verbose) col_print_item(event, "t!peer1!IPv6"); } while (0); |
504 | |
505 | /* Traverse collection */ |
506 | if (verbose) { |
507 | error = col_print_collection2(event); |
508 | if (error) { |
509 | col_destroy_collection(peer); |
510 | col_destroy_collection(host); |
511 | /* No socket1 any more :) */ |
512 | col_destroy_collection(socket2); |
513 | col_destroy_collection(event); |
514 | printf("Error printing collection %d\n", error); |
515 | return error; |
516 | } |
517 | } |
518 | |
519 | COLOUT(printf("Delete property PEER1!DELAY from the EVENT collection.\n"))do { if (verbose) printf("Delete property PEER1!DELAY from the EVENT collection.\n" ); } while(0); |
520 | |
521 | error = col_delete_property(event, "peer1!delay", COL_TYPE_ANY0x0FFFFFFF, COL_TRAVERSE_DEFAULT0x00000000); |
522 | if (error) { |
523 | col_destroy_collection(peer); |
524 | col_destroy_collection(host); |
525 | /* No socket1 any more :) */ |
526 | col_destroy_collection(socket2); |
527 | col_destroy_collection(event); |
528 | printf("Failed to delete property. Error %d\n", error); |
529 | return error; |
530 | } |
531 | |
532 | COLOUT(printf("Printing EVENT.\n"))do { if (verbose) printf("Printing EVENT.\n"); } while(0); |
533 | |
534 | /* Traverse collection */ |
535 | if (verbose) { |
536 | error = col_print_collection2(event); |
537 | if (error) { |
538 | col_destroy_collection(peer); |
539 | col_destroy_collection(host); |
540 | /* No socket1 any more :) */ |
541 | col_destroy_collection(socket2); |
542 | col_destroy_collection(event); |
543 | printf("Error printing collection %d\n", error); |
544 | return error; |
545 | } |
546 | } |
547 | |
548 | COLOUT(printf("Debugging EVENT.\n"))do { if (verbose) printf("Debugging EVENT.\n"); } while(0); |
549 | if (verbose) { |
550 | error = col_debug_collection(event, COL_TRAVERSE_DEFAULT0x00000000); |
551 | if (error) { |
552 | col_destroy_collection(peer); |
553 | col_destroy_collection(host); |
554 | /* No socket1 any more :) */ |
555 | col_destroy_collection(socket2); |
556 | col_destroy_collection(event); |
557 | printf("Error printing collection %d\n", error); |
558 | return error; |
559 | } |
560 | } |
561 | COLOUT(printf("Cleanup of the collections PEER, HOST and SOCKET2.\n"))do { if (verbose) printf("Cleanup of the collections PEER, HOST and SOCKET2.\n" ); } while(0); |
562 | |
563 | /* Destroy a referenced collection */ |
564 | col_destroy_collection(peer); |
565 | col_destroy_collection(host); |
566 | col_destroy_collection(socket2); |
567 | |
568 | COLOUT(printf("Printing EVENT again.\n"))do { if (verbose) printf("Printing EVENT again.\n"); } while( 0); |
569 | |
570 | /* Traverse collection again - peer should still be there */ |
571 | if (verbose) { |
572 | error = col_print_collection(event); |
573 | if (error) { |
574 | col_destroy_collection(event); |
575 | printf("Error printing collection %d\n", error); |
576 | return error; |
577 | } |
578 | } |
579 | |
580 | COLOUT(printf("Debugging EVENT again.\n"))do { if (verbose) printf("Debugging EVENT again.\n"); } while (0); |
581 | |
582 | if (verbose) { |
583 | error = col_debug_collection(event, COL_TRAVERSE_DEFAULT0x00000000); |
584 | if (error) { |
585 | col_destroy_collection(event); |
586 | printf("Error printing collection %d\n", error); |
587 | return error; |
588 | } |
589 | } |
590 | |
591 | COLOUT(printf("Attempt to add property to a referenced collection.\n"))do { if (verbose) printf("Attempt to add property to a referenced collection.\n" ); } while(0); |
592 | |
593 | error = col_add_int_property(event, "host", "session", 500); |
594 | if (error) { |
595 | col_destroy_collection(event); |
596 | printf("Error was NOT able to add property to a referenced collection %d.\n", error); |
597 | return error; |
598 | } |
599 | |
600 | COLOUT(printf("Attempt to delete non-existent property.\n"))do { if (verbose) printf("Attempt to delete non-existent property.\n" ); } while(0); |
601 | |
602 | /* Can't delete non exitent property */ |
603 | error = col_delete_property(event, "host.host", COL_TYPE_ANY0x0FFFFFFF, COL_TRAVERSE_DEFAULT0x00000000); |
604 | if (error == 0) { |
605 | col_destroy_collection(event); |
606 | printf("Error was able to delete property that does not exist.\n"); |
607 | return -1; |
608 | } |
609 | else COLOUT(printf("Expected error %d\n", error))do { if (verbose) printf("Expected error %d\n", error); } while (0); |
610 | |
611 | /* Set collection class */ |
612 | error = col_set_collection_class(event, 2); |
613 | if (error != 0) { |
614 | col_destroy_collection(event); |
615 | printf("Error was NOT able to set class.\n"); |
616 | return error; |
617 | } |
618 | |
619 | error = col_get_collection_class(event, &class); |
620 | if (error != 0) { |
621 | col_destroy_collection(event); |
622 | printf("Error was NOT able to get class.\n"); |
623 | return error; |
624 | } |
625 | else COLOUT(printf("Class = %d\n", class))do { if (verbose) printf("Class = %d\n", class); } while(0); |
626 | |
627 | if (col_is_of_class(event, 2)) { |
628 | COLOUT(printf("Class mathced!\n"))do { if (verbose) printf("Class mathced!\n"); } while(0); |
629 | } |
630 | else { |
631 | col_destroy_collection(event); |
632 | printf("Error - bad class.\n"); |
633 | return -1; |
634 | } |
635 | |
636 | COLOUT(printf("Done. Cleaning...\n"))do { if (verbose) printf("Done. Cleaning...\n"); } while(0); |
637 | |
638 | col_destroy_collection(event); |
639 | |
640 | COLOUT(printf("Exit.\n"))do { if (verbose) printf("Exit.\n"); } while(0); |
641 | TRACE_FLOW_NUMBER("add_collection_test. Returning", EOK); |
642 | return EOK0; |
643 | } |
644 | |
645 | |
646 | int iterator_test(void) |
647 | { |
648 | struct collection_item *peer = NULL((void*)0); |
649 | struct collection_item *initial = NULL((void*)0); |
650 | |
651 | struct collection_item *socket1 = NULL((void*)0); |
652 | struct collection_item *socket2 = NULL((void*)0); |
653 | struct collection_item *socket3 = NULL((void*)0); |
654 | struct collection_iterator *iterator = NULL((void*)0); |
655 | int error = EOK0; |
656 | struct collection_item *item = NULL((void*)0); |
657 | char binary_dump[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; |
658 | int depth = 0; |
659 | int idepth = 0; |
660 | int len = 0; |
661 | int i; |
662 | uint64_t hash1, hash2; |
663 | int rwnd = 0; |
664 | |
665 | COLOUT(printf("\n\n==== ITERATOR TEST ====\n\n"))do { if (verbose) printf("\n\n==== ITERATOR TEST ====\n\n"); } while(0); |
666 | |
667 | if ((error = col_create_collection(&initial, "strater", 0)) || |
668 | (error = col_create_collection(&peer, "peer", 0)) || |
669 | (error = col_add_str_property(initial, NULL((void*)0), "hostname", "peerhost.mytest.com", 0)) || |
670 | /* Expect trailing zero to be truncated */ |
671 | (error = col_add_str_property(initial, NULL((void*)0), "IPv4", "10.10.10.10", 12)) || |
672 | (error = col_add_str_property(initial, NULL((void*)0), "IPv6", "bla:bla:bla:bla:bla:bla", 0)) || |
673 | (error = col_add_collection_to_collection(peer, NULL((void*)0), NULL((void*)0), initial, COL_ADD_MODE_FLAT3))) { |
674 | printf("Failed to add property. Error %d", error); |
675 | col_destroy_collection(peer); |
676 | col_destroy_collection(initial); |
677 | return error; |
678 | } |
679 | |
680 | col_destroy_collection(initial); |
681 | |
682 | if ((error = col_create_collection(&socket1, "socket", 0)) || |
683 | (error = col_add_int_property(socket1, NULL((void*)0), "id", 1)) || |
684 | (error = col_add_long_property(socket1, NULL((void*)0), "packets", 100000000L)) || |
685 | (error = col_add_binary_property(socket1, NULL((void*)0), "stack", binary_dump, sizeof(binary_dump)))) { |
686 | col_destroy_collection(peer); |
687 | col_destroy_collection(socket1); |
688 | printf("Failed to add property. Error %d\n", error); |
689 | return error; |
690 | } |
691 | |
692 | if ((error = col_create_collection(&socket2, "socket", 0)) || |
693 | (error = col_add_int_property(socket2, NULL((void*)0), "id", 2)) || |
694 | (error = col_add_long_property(socket2, NULL((void*)0), "packets", 200000000L)) || |
695 | (error = col_add_binary_property(socket2, NULL((void*)0), "queue", binary_dump, sizeof(binary_dump)))) { |
696 | col_destroy_collection(peer); |
697 | col_destroy_collection(socket1); |
698 | col_destroy_collection(socket2); |
699 | printf("Failed to add property. Error %d\n", error); |
700 | return error; |
701 | } |
702 | |
703 | if ((error = col_create_collection(&socket3, "socket", 0))) { |
704 | col_destroy_collection(peer); |
705 | col_destroy_collection(socket1); |
706 | col_destroy_collection(socket2); |
707 | printf("Failed to add property. Error %d\n", error); |
708 | return error; |
709 | } |
710 | |
711 | error = col_add_collection_to_collection(peer, NULL((void*)0), "first", socket1, COL_ADD_MODE_REFERENCE0); |
712 | if (error) { |
713 | col_destroy_collection(peer); |
714 | col_destroy_collection(socket1); |
715 | col_destroy_collection(socket2); |
716 | col_destroy_collection(socket3); |
717 | printf("Failed to add collection to collection. Error %d\n", error); |
718 | return error; |
719 | } |
720 | |
721 | error = col_add_collection_to_collection(peer, NULL((void*)0), "second", socket2, COL_ADD_MODE_EMBED1); |
722 | if (error) { |
723 | col_destroy_collection(peer); |
724 | col_destroy_collection(socket1); |
725 | col_destroy_collection(socket2); |
726 | col_destroy_collection(socket3); |
727 | printf("Failed to add collection to collection. Error %d\n", error); |
728 | return error; |
729 | } |
730 | |
731 | error = col_add_collection_to_collection(peer, NULL((void*)0), "third", socket3, COL_ADD_MODE_EMBED1); |
732 | if (error) { |
733 | col_destroy_collection(peer); |
734 | col_destroy_collection(socket1); |
735 | col_destroy_collection(socket3); |
736 | printf("Failed to add collection to collection. Error %d\n", error); |
737 | return error; |
738 | } |
739 | |
740 | error = col_add_collection_to_collection(peer, NULL((void*)0), "forth", socket1, COL_ADD_MODE_FLATDOT4); |
741 | if (error) { |
742 | col_destroy_collection(peer); |
743 | col_destroy_collection(socket1); |
744 | printf("Failed to add collection to collection. Error %d\n", error); |
745 | return error; |
746 | } |
747 | |
748 | error = col_add_collection_to_collection(peer, NULL((void*)0), NULL((void*)0), socket1, COL_ADD_MODE_FLATDOT4); |
749 | if (error) { |
750 | col_destroy_collection(peer); |
751 | col_destroy_collection(socket1); |
752 | printf("Failed to add collection to collection. Error %d\n", error); |
753 | return error; |
754 | } |
755 | |
756 | col_destroy_collection(socket1); |
757 | |
758 | /* Bind iterator */ |
759 | error = col_bind_iterator(&iterator, peer, COL_TRAVERSE_DEFAULT0x00000000); |
760 | if (error) { |
761 | printf("Error (bind): %d\n", error); |
762 | col_destroy_collection(peer); |
763 | return error; |
764 | } |
765 | |
766 | COLOUT(printf("\n\nCollection (traverse default):\n\n"))do { if (verbose) printf("\n\nCollection (traverse default):\n\n" ); } while(0); |
767 | COLOUT(col_debug_collection(peer, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(peer, 0x00000000); } while (0); |
768 | |
769 | COLOUT(printf("\n\nCollection (traverse flat):\n\n"))do { if (verbose) printf("\n\nCollection (traverse flat):\n\n" ); } while(0); |
770 | COLOUT(col_debug_collection(peer, COL_TRAVERSE_FLAT | COL_TRAVERSE_END))do { if (verbose) col_debug_collection(peer, 0x00000008 | 0x00000002 ); } while(0); |
771 | |
772 | COLOUT(printf("\n\nIteration (1):\n\n"))do { if (verbose) printf("\n\nIteration (1):\n\n"); } while(0 ); |
773 | |
774 | do { |
775 | |
776 | |
777 | /* Loop through a collection */ |
778 | error = col_iterate_collection(iterator, &item); |
779 | if (error) { |
780 | printf("Error (iterate): %d\n", error); |
781 | col_unbind_iterator(iterator); |
782 | col_destroy_collection(peer); |
783 | return error; |
784 | } |
785 | |
786 | /* Are we done ? */ |
787 | if (item == NULL((void*)0)) break; |
788 | |
789 | depth = 0; |
790 | col_get_item_depth(iterator, &depth); |
791 | idepth = 0; |
792 | col_get_iterator_depth(iterator, &idepth); |
793 | |
794 | |
795 | COLOUT(printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n",do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0) |
796 | depth * 4, "",do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0) |
797 | col_get_item_property(item, NULL),do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0) |
798 | col_get_item_type(item),do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0) |
799 | col_get_item_length(item),do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0) |
800 | depth,do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0) |
801 | idepth))do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0); |
802 | |
803 | if ((strcmp(col_get_item_property(item, NULL((void*)0)), "id")==0) && |
804 | (*((int *)(col_get_item_data(item))) == 1)) { |
805 | COLOUT(printf("\n\nFound property we need - go up!!!\n\n\n"))do { if (verbose) printf("\n\nFound property we need - go up!!!\n\n\n" ); } while(0); |
806 | |
807 | /* This should work! */ |
808 | error = col_iterate_up(iterator, 1); |
809 | if (error) { |
810 | printf("We expected success but got error %d\n", error); |
811 | col_unbind_iterator(iterator); |
812 | col_destroy_collection(peer); |
813 | return error; |
814 | } |
815 | |
816 | if ((error = col_modify_str_item(item, "id2", "test", 0)) || |
817 | ((verbose) && (error = col_debug_item(item))) || |
818 | (error = col_modify_str_item(item, NULL((void*)0), "test", 2)) || |
819 | ((verbose) && (error = col_debug_item(item))) || |
820 | (error = col_modify_binary_item(item, NULL((void*)0), binary_dump, sizeof(binary_dump))) || |
821 | ((verbose) && (error = col_debug_item(item))) || |
822 | (error = col_modify_bool_item(item, NULL((void*)0), 1)) || |
823 | ((verbose) && (error = col_debug_item(item))) || |
824 | (error = col_modify_int_item(item, "int", 1)) || |
825 | ((verbose) && (error = col_debug_item(item))) || |
826 | (error = col_modify_long_item(item, "long", 1000000000L)) || |
827 | ((verbose) && (error = col_debug_item(item))) || |
828 | (error = col_modify_ulong_item(item, "ulong", 4000000000UL)) || |
829 | ((verbose) && (error = col_debug_item(item))) || |
830 | (error = col_modify_unsigned_item(item, "unsigned", 4000000000U)) || |
831 | ((verbose) && (error = col_debug_item(item))) || |
832 | (error = col_modify_double_item(item, "double", -1.1)) || |
833 | ((verbose) && (error = col_debug_item(item)))) { |
834 | printf("Failed to change property.\n"); |
835 | col_unbind_iterator(iterator); |
836 | col_destroy_collection(peer); |
837 | return error; |
838 | } |
839 | |
840 | COLOUT(printf("Item name: %s\n", col_get_item_property(item, NULL)))do { if (verbose) printf("Item name: %s\n", col_get_item_property (item, ((void*)0))); } while(0); |
841 | COLOUT(printf("Item hash: %lu\n", (unsigned long int)col_get_item_hash(item)))do { if (verbose) printf("Item hash: %lu\n", (unsigned long int )col_get_item_hash(item)); } while(0); |
842 | error = col_modify_item_property(item, "new_name"); |
843 | if (error) { |
844 | printf("We expected success but got error %d\n", error); |
845 | col_unbind_iterator(iterator); |
846 | col_destroy_collection(peer); |
847 | return error; |
848 | } |
849 | len = 0; |
850 | COLOUT(printf("Item name: %s\n", col_get_item_property(item, &len)))do { if (verbose) printf("Item name: %s\n", col_get_item_property (item, &len)); } while(0); |
851 | COLOUT(printf("Item hash: %lu\n", (unsigned long int)col_get_item_hash(item)))do { if (verbose) printf("Item hash: %lu\n", (unsigned long int )col_get_item_hash(item)); } while(0); |
852 | COLOUT(printf("Item length: %d\n", len))do { if (verbose) printf("Item length: %d\n", len); } while(0 ); |
853 | |
854 | len = 0; |
855 | hash1 = col_make_hash("new_name", 0, &len); |
856 | COLOUT(printf("String name: %s\n", "new_name"))do { if (verbose) printf("String name: %s\n", "new_name"); } while (0); |
857 | COLOUT(printf("String hash: %lu\n", (unsigned long int)hash1))do { if (verbose) printf("String hash: %lu\n", (unsigned long int)hash1); } while(0); |
858 | COLOUT(printf("String length: %d\n", len))do { if (verbose) printf("String length: %d\n", len); } while (0); |
859 | |
860 | len = 0; |
861 | hash2 = col_make_hash("new_name_suffix", 8, &len); |
862 | COLOUT(printf("String name: %.*s\n", len, "new_name_suffix"))do { if (verbose) printf("String name: %.*s\n", len, "new_name_suffix" ); } while(0); |
863 | COLOUT(printf("String hash: %lu\n", (unsigned long int)hash2))do { if (verbose) printf("String hash: %lu\n", (unsigned long int)hash2); } while(0); |
864 | COLOUT(printf("String length: %d\n", len))do { if (verbose) printf("String length: %d\n", len); } while (0); |
865 | if (hash1 != hash2) { |
866 | printf("Hash calculation failed\n"); |
867 | col_unbind_iterator(iterator); |
868 | col_destroy_collection(peer); |
869 | return EINVAL22; |
870 | } |
871 | |
872 | hash2 = col_make_hash("new_name", 8, &len); |
873 | COLOUT(printf("String name: %.*s\n", len, "new_name"))do { if (verbose) printf("String name: %.*s\n", len, "new_name" ); } while(0); |
874 | COLOUT(printf("String hash: %lu\n", (unsigned long int)hash2))do { if (verbose) printf("String hash: %lu\n", (unsigned long int)hash2); } while(0); |
875 | COLOUT(printf("String length: %d\n", len))do { if (verbose) printf("String length: %d\n", len); } while (0); |
876 | if (hash1 != hash2) { |
877 | printf("Hash calculation failed\n"); |
878 | col_unbind_iterator(iterator); |
879 | col_destroy_collection(peer); |
880 | return EINVAL22; |
881 | } |
882 | |
883 | } |
884 | } |
885 | while(1); |
886 | |
887 | col_unbind_iterator(iterator); |
888 | |
889 | /* Bind iterator again in flat mode */ |
890 | error = col_bind_iterator(&iterator, peer, COL_TRAVERSE_FLAT0x00000008); |
891 | if (error) { |
892 | printf("Error (bind): %d\n", error); |
893 | col_destroy_collection(peer); |
894 | return error; |
895 | } |
896 | |
897 | COLOUT(printf("\n\nIteration (2 - flat):\n\n"))do { if (verbose) printf("\n\nIteration (2 - flat):\n\n"); } while (0); |
898 | |
899 | do { |
900 | |
901 | /* Loop through a collection */ |
902 | error = col_iterate_collection(iterator, &item); |
903 | if (error) { |
904 | printf("Error (iterate): %d\n", error); |
905 | col_destroy_collection(peer); |
906 | col_unbind_iterator(iterator); |
907 | return error; |
908 | } |
909 | |
910 | /* Are we done ? */ |
911 | if (item == NULL((void*)0)) break; |
912 | |
913 | depth = 0; |
914 | col_get_item_depth(iterator, &depth); |
915 | COLOUT(printf("%*s", depth * 4, ""))do { if (verbose) printf("%*s", depth * 4, ""); } while(0); |
916 | COLOUT(col_debug_item(item))do { if (verbose) col_debug_item(item); } while(0); |
917 | |
918 | if ((strcmp(col_get_item_property(item, NULL((void*)0)), "queue") == 0) && |
919 | (rwnd == 0)) { |
920 | COLOUT(printf("Rewinding iterator...\n"))do { if (verbose) printf("Rewinding iterator...\n"); } while( 0); |
921 | col_rewind_iterator(iterator); |
922 | rwnd++; |
923 | } |
924 | |
925 | } |
926 | while(1); |
927 | |
928 | /* Do not forget to unbind iterator - otherwise there will be a leak */ |
929 | col_unbind_iterator(iterator); |
930 | |
931 | /* Bind iterator again in flat mode */ |
932 | error = col_bind_iterator(&iterator, peer, COL_TRAVERSE_FLAT0x00000008 | COL_TRAVERSE_END0x00000002); |
933 | if (error) { |
934 | printf("Error (bind): %d\n", error); |
935 | col_destroy_collection(peer); |
936 | return error; |
937 | } |
938 | |
939 | COLOUT(printf("\n\nIteration (3 flat with end):\n\n"))do { if (verbose) printf("\n\nIteration (3 flat with end):\n\n" ); } while(0); |
940 | |
941 | do { |
942 | |
943 | /* Loop through a collection */ |
944 | error = col_iterate_collection(iterator, &item); |
945 | if (error) { |
946 | printf("Error (iterate): %d\n", error); |
947 | col_destroy_collection(peer); |
948 | col_unbind_iterator(iterator); |
949 | return error; |
950 | } |
951 | |
952 | /* Are we done ? */ |
953 | if (item == NULL((void*)0)) break; |
954 | |
955 | depth = 0; |
956 | col_get_item_depth(iterator, &depth); |
957 | COLOUT(printf("%*s", depth * 4, ""))do { if (verbose) printf("%*s", depth * 4, ""); } while(0); |
958 | COLOUT(col_debug_item(item))do { if (verbose) col_debug_item(item); } while(0); |
959 | |
960 | } |
961 | while(1); |
962 | |
963 | /* Do not forget to unbind iterator - otherwise there will be a leak */ |
964 | col_unbind_iterator(iterator); |
965 | |
966 | /* Bind iterator again in flat mode */ |
967 | error = col_bind_iterator(&iterator, peer, COL_TRAVERSE_DEFAULT0x00000000 | COL_TRAVERSE_END0x00000002); |
968 | if (error) { |
969 | printf("Error (bind): %d\n", error); |
970 | col_destroy_collection(peer); |
971 | return error; |
972 | } |
973 | |
974 | COLOUT(printf("\n\nIteration (4 default with end):\n\n"))do { if (verbose) printf("\n\nIteration (4 default with end):\n\n" ); } while(0); |
975 | |
976 | do { |
977 | |
978 | /* Loop through a collection */ |
979 | error = col_iterate_collection(iterator, &item); |
980 | if (error) { |
981 | printf("Error (iterate): %d\n", error); |
982 | col_destroy_collection(peer); |
983 | col_unbind_iterator(iterator); |
984 | return error; |
985 | } |
986 | |
987 | /* Are we done ? */ |
988 | if (item == NULL((void*)0)) break; |
989 | |
990 | depth = 0; |
991 | col_get_item_depth(iterator, &depth); |
992 | COLOUT(printf("%*s", depth * 4, ""))do { if (verbose) printf("%*s", depth * 4, ""); } while(0); |
993 | COLOUT(col_debug_item(item))do { if (verbose) col_debug_item(item); } while(0); |
994 | |
995 | } |
996 | while(1); |
997 | |
998 | /* Do not forget to unbind iterator - otherwise there will be a leak */ |
999 | col_unbind_iterator(iterator); |
1000 | |
1001 | /* Bind iterator again in flat mode */ |
1002 | error = col_bind_iterator(&iterator, peer, COL_TRAVERSE_SHOWSUB0x00010000 | COL_TRAVERSE_END0x00000002); |
1003 | if (error) { |
1004 | printf("Error (bind): %d\n", error); |
1005 | col_destroy_collection(peer); |
1006 | return error; |
1007 | } |
1008 | |
1009 | |
1010 | COLOUT(printf("\n\nIteration (5 show headers and references with end):\n\n"))do { if (verbose) printf("\n\nIteration (5 show headers and references with end):\n\n" ); } while(0); |
1011 | |
1012 | do { |
1013 | |
1014 | /* Loop through a collection */ |
1015 | error = col_iterate_collection(iterator, &item); |
1016 | if (error) { |
1017 | printf("Error (iterate): %d\n", error); |
1018 | col_destroy_collection(peer); |
1019 | col_unbind_iterator(iterator); |
1020 | return error; |
1021 | } |
1022 | |
1023 | /* Are we done ? */ |
1024 | if (item == NULL((void*)0)) break; |
1025 | |
1026 | depth = 0; |
1027 | col_get_item_depth(iterator, &depth); |
1028 | COLOUT(printf("%*s", depth * 4, ""))do { if (verbose) printf("%*s", depth * 4, ""); } while(0); |
1029 | COLOUT(col_debug_item(item))do { if (verbose) col_debug_item(item); } while(0); |
1030 | |
1031 | } |
1032 | while(1); |
1033 | |
1034 | /* Do not forget to unbind iterator - otherwise there will be a leak */ |
1035 | col_unbind_iterator(iterator); |
1036 | |
1037 | /* Bind iterator again in flat mode */ |
1038 | error = col_bind_iterator(&iterator, peer, COL_TRAVERSE_SHOWSUB0x00010000); |
1039 | if (error) { |
1040 | printf("Error (bind): %d\n", error); |
1041 | col_destroy_collection(peer); |
1042 | return error; |
1043 | } |
1044 | |
1045 | |
1046 | COLOUT(printf("\n\nIteration (6 show headers and references no END):\n\n"))do { if (verbose) printf("\n\nIteration (6 show headers and references no END):\n\n" ); } while(0); |
1047 | |
1048 | do { |
1049 | |
1050 | /* Loop through a collection */ |
1051 | error = col_iterate_collection(iterator, &item); |
1052 | if (error) { |
1053 | printf("Error (iterate): %d\n", error); |
1054 | col_destroy_collection(peer); |
1055 | col_unbind_iterator(iterator); |
1056 | return error; |
1057 | } |
1058 | |
1059 | /* Are we done ? */ |
1060 | if (item == NULL((void*)0)) break; |
1061 | |
1062 | depth = 0; |
1063 | col_get_item_depth(iterator, &depth); |
1064 | COLOUT(printf("%*s", depth * 4, ""))do { if (verbose) printf("%*s", depth * 4, ""); } while(0); |
1065 | COLOUT(col_debug_item(item))do { if (verbose) col_debug_item(item); } while(0); |
1066 | |
1067 | } |
1068 | while(1); |
1069 | |
1070 | /* Do not forget to unbind iterator - otherwise there will be a leak */ |
1071 | col_unbind_iterator(iterator); |
1072 | |
1073 | /* Bind iterator again in flat mode */ |
1074 | error = col_bind_iterator(&iterator, peer, COL_TRAVERSE_ONLYSUB0x00020000); |
1075 | if (error) { |
1076 | printf("Error (bind): %d\n", error); |
1077 | col_destroy_collection(peer); |
1078 | return error; |
1079 | } |
1080 | |
1081 | COLOUT(printf("\n\nIteration (7 show headers only no END):\n\n"))do { if (verbose) printf("\n\nIteration (7 show headers only no END):\n\n" ); } while(0); |
1082 | |
1083 | do { |
1084 | |
1085 | /* Loop through a collection */ |
1086 | error = col_iterate_collection(iterator, &item); |
1087 | if (error) { |
1088 | printf("Error (iterate): %d\n", error); |
1089 | col_destroy_collection(peer); |
1090 | col_unbind_iterator(iterator); |
1091 | return error; |
1092 | } |
1093 | |
1094 | /* Are we done ? */ |
1095 | if (item == NULL((void*)0)) break; |
1096 | |
1097 | depth = 0; |
1098 | col_get_item_depth(iterator, &depth); |
1099 | COLOUT(printf("%*s", depth * 4, ""))do { if (verbose) printf("%*s", depth * 4, ""); } while(0); |
1100 | COLOUT(col_debug_item(item))do { if (verbose) col_debug_item(item); } while(0); |
1101 | |
1102 | } |
1103 | while(1); |
1104 | |
1105 | /* Do not forget to unbind iterator - otherwise there will be a leak */ |
1106 | col_unbind_iterator(iterator); |
1107 | |
1108 | |
1109 | /* Bind iterator */ |
1110 | error = col_bind_iterator(&iterator, peer, COL_TRAVERSE_DEFAULT0x00000000); |
1111 | if (error) { |
1112 | printf("Error (bind): %d\n", error); |
1113 | col_destroy_collection(peer); |
1114 | return error; |
1115 | } |
1116 | |
1117 | COLOUT(printf("\n\nIterate up test:\n\n"))do { if (verbose) printf("\n\nIterate up test:\n\n"); } while (0); |
1118 | |
1119 | do { |
1120 | |
1121 | /* Loop through a collection */ |
1122 | error = col_iterate_collection(iterator, &item); |
1123 | if (error) { |
1124 | printf("Error (iterate): %d\n", error); |
1125 | col_unbind_iterator(iterator); |
1126 | col_destroy_collection(peer); |
1127 | return error; |
1128 | } |
1129 | |
1130 | /* Are we done ? */ |
1131 | if (item == NULL((void*)0)) break; |
1132 | |
1133 | depth = 0; |
1134 | col_get_item_depth(iterator, &depth); |
1135 | idepth = 0; |
1136 | col_get_iterator_depth(iterator, &idepth); |
1137 | |
1138 | |
1139 | COLOUT(printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n",do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0) |
1140 | depth * 4, "",do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0) |
1141 | col_get_item_property(item, NULL),do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0) |
1142 | col_get_item_type(item),do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0) |
1143 | col_get_item_length(item),do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0) |
1144 | depth,do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0) |
1145 | idepth))do { if (verbose) printf("%*sProperty (%s), type = %d, data size = %d depth = %d idepth = %d\n" , depth * 4, "", col_get_item_property(item, ((void*)0)), col_get_item_type (item), col_get_item_length(item), depth, idepth); } while(0); |
1146 | |
1147 | if (strcmp(col_get_item_property(item, NULL((void*)0)), "queue") == 0) { |
1148 | |
1149 | COLOUT(printf("\n\nFound property we need - go up!!!\n"))do { if (verbose) printf("\n\nFound property we need - go up!!!\n" ); } while(0); |
1150 | COLOUT(printf("Expect bail out of collection processing.\n\n"))do { if (verbose) printf("Expect bail out of collection processing.\n\n" ); } while(0); |
1151 | |
1152 | /* This should work! */ |
1153 | error = col_iterate_up(iterator, 10); |
1154 | if (error) { |
1155 | printf("We expected success but got error %d\n", error); |
1156 | col_unbind_iterator(iterator); |
1157 | col_destroy_collection(peer); |
1158 | return error; |
1159 | } |
1160 | |
1161 | } |
1162 | } |
1163 | while(1); |
1164 | |
1165 | col_unbind_iterator(iterator); |
1166 | |
1167 | /* Bind iterator again in flat mode */ |
1168 | error = col_bind_iterator(&iterator, peer, COL_TRAVERSE_FLAT0x00000008 | COL_TRAVERSE_END0x00000002); |
1169 | if (error) { |
1170 | printf("Error (bind): %d\n", error); |
1171 | col_destroy_collection(peer); |
1172 | return error; |
1173 | } |
1174 | |
1175 | COLOUT(printf("\n\nCircled looping:\n\n"))do { if (verbose) printf("\n\nCircled looping:\n\n"); } while (0); |
1176 | |
1177 | for (i = 0; i < 200; i++) { |
1178 | /* Loop through a collection */ |
1179 | error = col_iterate_collection(iterator, &item); |
1180 | if (error) { |
1181 | printf("Error (iterate): %d\n", error); |
1182 | col_destroy_collection(peer); |
1183 | col_unbind_iterator(iterator); |
1184 | return error; |
1185 | } |
1186 | |
1187 | /* Are we done ? */ |
1188 | if (item == NULL((void*)0)) { |
1189 | COLOUT(printf("Reached end.\n\n"))do { if (verbose) printf("Reached end.\n\n"); } while(0); |
1190 | } |
1191 | else { |
1192 | depth = 0; |
1193 | col_get_item_depth(iterator, &depth); |
1194 | COLOUT(printf("%*s", depth * 4, ""))do { if (verbose) printf("%*s", depth * 4, ""); } while(0); |
1195 | COLOUT(col_debug_item(item))do { if (verbose) col_debug_item(item); } while(0); |
1196 | } |
1197 | } |
1198 | |
1199 | /* Do not forget to unbind iterator - otherwise there will be a leak */ |
1200 | col_unbind_iterator(iterator); |
1201 | |
1202 | /* Bind iterator again in flat mode */ |
1203 | error = col_bind_iterator(&iterator, peer, COL_TRAVERSE_FLAT0x00000008 | COL_TRAVERSE_END0x00000002); |
1204 | if (error) { |
1205 | printf("Error (bind): %d\n", error); |
1206 | col_destroy_collection(peer); |
1207 | return error; |
1208 | } |
1209 | |
1210 | COLOUT(printf("\n\nCircled looping with pin:\n\n"))do { if (verbose) printf("\n\nCircled looping with pin:\n\n") ; } while(0); |
1211 | |
1212 | do { |
1213 | /* Loop through a collection */ |
1214 | error = col_iterate_collection(iterator, &item); |
1215 | if (error) { |
1216 | printf("Error (iterate): %d\n", error); |
1217 | col_destroy_collection(peer); |
1218 | col_unbind_iterator(iterator); |
1219 | return error; |
1220 | } |
1221 | |
1222 | if (strcmp(col_get_item_property(item, NULL((void*)0)), "queue") == 0) { |
1223 | /* Make it a new looping point */ |
1224 | col_pin_iterator(iterator); |
1225 | COLOUT(printf("Found pin point.\n\n"))do { if (verbose) printf("Found pin point.\n\n"); } while(0); |
1226 | break; |
1227 | } |
1228 | /* Are we done ? */ |
1229 | if (item == NULL((void*)0)) { |
1230 | printf("Unexpected end.\n\n"); |
1231 | col_destroy_collection(peer); |
1232 | col_unbind_iterator(iterator); |
1233 | return EINVAL22; |
1234 | } |
1235 | else { |
1236 | depth = 0; |
1237 | col_get_item_depth(iterator, &depth); |
1238 | COLOUT(printf("%*s", depth * 4, ""))do { if (verbose) printf("%*s", depth * 4, ""); } while(0); |
1239 | COLOUT(col_debug_item(item))do { if (verbose) col_debug_item(item); } while(0); |
1240 | } |
1241 | } |
1242 | while(1); |
1243 | |
1244 | /* Second loop around the pin point */ |
1245 | for (i = 0; i < 200; i++) { |
1246 | /* Loop through a collection */ |
1247 | error = col_iterate_collection(iterator, &item); |
1248 | if (error) { |
1249 | printf("Error (iterate): %d\n", error); |
1250 | col_destroy_collection(peer); |
1251 | col_unbind_iterator(iterator); |
1252 | return error; |
1253 | } |
1254 | |
1255 | /* Are we done ? */ |
1256 | if (item == NULL((void*)0)) { |
1257 | COLOUT(printf("Reached end.\n\n"))do { if (verbose) printf("Reached end.\n\n"); } while(0); |
1258 | } |
1259 | else { |
1260 | depth = 0; |
1261 | col_get_item_depth(iterator, &depth); |
1262 | COLOUT(printf("%*s", depth * 4, ""))do { if (verbose) printf("%*s", depth * 4, ""); } while(0); |
1263 | COLOUT(col_debug_item(item))do { if (verbose) col_debug_item(item); } while(0); |
1264 | } |
1265 | } |
1266 | |
1267 | /* Do not forget to unbind iterator - otherwise there will be a leak */ |
1268 | col_unbind_iterator(iterator); |
1269 | |
1270 | |
1271 | /* Bind iterator again in flat mode */ |
1272 | error = col_bind_iterator(&iterator, peer, COL_TRAVERSE_DEFAULT0x00000000 | COL_TRAVERSE_END0x00000002); |
1273 | if (error) { |
1274 | printf("Error (bind): %d\n", error); |
1275 | col_destroy_collection(peer); |
1276 | return error; |
1277 | } |
1278 | |
1279 | COLOUT(printf("\n\nCircled looping with pin (default):\n\n"))do { if (verbose) printf("\n\nCircled looping with pin (default):\n\n" ); } while(0); |
1280 | |
1281 | do { |
1282 | /* Loop through a collection */ |
1283 | error = col_iterate_collection(iterator, &item); |
1284 | if (error) { |
1285 | printf("Error (iterate): %d\n", error); |
1286 | col_destroy_collection(peer); |
1287 | col_unbind_iterator(iterator); |
1288 | return error; |
1289 | } |
1290 | |
1291 | if (strcmp(col_get_item_property(item, NULL((void*)0)), "queue") == 0) { |
1292 | /* Make it a new looping point */ |
1293 | col_pin_iterator(iterator); |
1294 | COLOUT(printf("Found pin point.\n\n"))do { if (verbose) printf("Found pin point.\n\n"); } while(0); |
1295 | break; |
1296 | } |
1297 | /* Are we done ? */ |
1298 | if (item == NULL((void*)0)) { |
1299 | printf("Unexpected end.\n\n"); |
1300 | col_destroy_collection(peer); |
1301 | col_unbind_iterator(iterator); |
1302 | return EINVAL22; |
1303 | } |
1304 | else { |
1305 | depth = 0; |
1306 | col_get_item_depth(iterator, &depth); |
1307 | COLOUT(printf("%*s", depth * 4, ""))do { if (verbose) printf("%*s", depth * 4, ""); } while(0); |
1308 | COLOUT(col_debug_item(item))do { if (verbose) col_debug_item(item); } while(0); |
1309 | } |
1310 | } |
1311 | while(1); |
1312 | |
1313 | /* Second loop around the pin point */ |
1314 | for (i = 0; i < 200; i++) { |
1315 | /* Loop through a collection */ |
1316 | error = col_iterate_collection(iterator, &item); |
1317 | if (error) { |
1318 | printf("Error (iterate): %d\n", error); |
1319 | col_destroy_collection(peer); |
1320 | col_unbind_iterator(iterator); |
1321 | return error; |
1322 | } |
1323 | |
1324 | /* Are we done ? */ |
1325 | if (item == NULL((void*)0)) { |
1326 | COLOUT(printf("Reached end.\n\n"))do { if (verbose) printf("Reached end.\n\n"); } while(0); |
1327 | } |
1328 | else { |
1329 | depth = 0; |
1330 | col_get_item_depth(iterator, &depth); |
1331 | COLOUT(printf("%*s", depth * 4, ""))do { if (verbose) printf("%*s", depth * 4, ""); } while(0); |
1332 | COLOUT(col_debug_item(item))do { if (verbose) col_debug_item(item); } while(0); |
1333 | } |
1334 | } |
1335 | |
1336 | /* Do not forget to unbind iterator - otherwise there will be a leak */ |
1337 | col_unbind_iterator(iterator); |
1338 | col_destroy_collection(peer); |
1339 | |
1340 | return EOK0; |
1341 | } |
1342 | |
1343 | |
1344 | int insert_extract_test(void) |
1345 | { |
1346 | struct collection_item *col; |
1347 | struct collection_item *col2; |
1348 | int error = EOK0; |
1349 | struct collection_item *item = NULL((void*)0); |
1350 | |
1351 | COLOUT(printf("\n\n==== INSERTION TEST ====\n\n"))do { if (verbose) printf("\n\n==== INSERTION TEST ====\n\n"); } while(0); |
1352 | |
1353 | if ((error = col_create_collection(&col, "insertion", 0)) || |
1354 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_END0, |
1355 | NULL((void*)0), 0, COL_INSERT_NOCHECK0, |
1356 | "property1", "value1", 0)) || |
1357 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_INDEX4, |
1358 | NULL((void*)0), 1, COL_INSERT_NOCHECK0, |
1359 | "second", "second", 0)) || |
1360 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_END0, |
1361 | NULL((void*)0), 0, COL_INSERT_NOCHECK0, |
1362 | "property2", "value2", 0)) || |
1363 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_FRONT1, |
1364 | NULL((void*)0), 0, COL_INSERT_NOCHECK0, |
1365 | "property0", "value0", 0)) || |
1366 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_BEFORE2, |
1367 | "property0", 0, COL_INSERT_NOCHECK0, |
1368 | "property_-1", "value_-1", 0)) || |
1369 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_BEFORE2, |
1370 | "property1", 0, COL_INSERT_NOCHECK0, |
1371 | "property0_5", "value0_5", 0)) || |
1372 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_BEFORE2, |
1373 | "property2", 0, COL_INSERT_NOCHECK0, |
1374 | "property1_5", "value1_5", 0)) || |
1375 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_AFTER3, |
1376 | "property_-1", 0, COL_INSERT_NOCHECK0, |
1377 | "property_-0_5", "value_-0_5", 0)) || |
1378 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_AFTER3, |
1379 | "property1_5", 0, COL_INSERT_NOCHECK0, |
1380 | "property1_6", "value1_6", 0)) || |
1381 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_INDEX4, |
1382 | NULL((void*)0), 10, COL_INSERT_NOCHECK0, |
1383 | "property10", "value10", 0)) || |
1384 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_INDEX4, |
1385 | NULL((void*)0), 0, COL_INSERT_NOCHECK0, |
1386 | "property_-2", "value_-2", 0)) || |
1387 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_INDEX4, |
1388 | NULL((void*)0), 1, COL_INSERT_NOCHECK0, |
1389 | "property_-1_5", "value_-1_5", 0)) || |
1390 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_FIRSTDUP5, |
1391 | NULL((void*)0), 0, COL_INSERT_NOCHECK0, |
1392 | "property0", "value0firstdup", 0)) || |
1393 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_LASTDUP6, |
1394 | NULL((void*)0), 0, COL_INSERT_NOCHECK0, |
1395 | "property0", "value0lastdup", 0)) || |
1396 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_NDUP7, |
1397 | NULL((void*)0), 1, COL_INSERT_NOCHECK0, |
1398 | "property0", "value0middledup", 0)) || |
1399 | (error = col_insert_str_property(col, NULL((void*)0), 0, |
1400 | NULL((void*)0), 0, COL_INSERT_DUPOVER1 , |
1401 | "property0", "value0firstdupupdate", 0)) || |
1402 | (error = col_insert_str_property(col, NULL((void*)0), 0, |
1403 | NULL((void*)0), 0, COL_INSERT_DUPOVERT2, |
1404 | "property1", "value1update", 0)) || |
1405 | ((error = col_insert_str_property(col, NULL((void*)0), 0, |
1406 | NULL((void*)0), 0, COL_INSERT_DUPERROR3, |
1407 | "property0", "does not matter", 0)) != EEXIST17) || |
1408 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_NDUP7, |
1409 | NULL((void*)0), 5, COL_INSERT_NOCHECK0, |
1410 | "property10", "value10dup", 0)) || |
1411 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_LASTDUP6, |
1412 | NULL((void*)0), 0, COL_INSERT_NOCHECK0, |
1413 | "property10", "value10lastdup", 0)) || |
1414 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_END0, |
1415 | NULL((void*)0), 0, COL_INSERT_DUPMOVET6, |
1416 | "property_-2", "value-2moved_to_bottom", 0)) || |
1417 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_FRONT1, |
1418 | NULL((void*)0), 0, COL_INSERT_DUPMOVE5, |
1419 | "property1_6", "value_1_6_moved_moved_to_front", 0))) { |
1420 | |
1421 | printf("ERROR in the ITERATION TEST\n"); |
1422 | col_debug_collection(col, COL_TRAVERSE_DEFAULT0x00000000); |
1423 | col_destroy_collection(col); |
1424 | return error; |
1425 | } |
1426 | |
1427 | COLOUT(printf("\n\nCollection:\n\n"))do { if (verbose) printf("\n\nCollection:\n\n"); } while(0); |
1428 | COLOUT(col_debug_collection(col, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(col, 0x00000000); } while (0); |
1429 | |
1430 | |
1431 | COLOUT(printf("\n\n==== EXTRACTION TEST ====\n\n"))do { if (verbose) printf("\n\n==== EXTRACTION TEST ====\n\n") ; } while(0); |
1432 | |
1433 | if ((error = col_create_collection(&col2, "extraction", 0)) || |
1434 | |
1435 | (error = col_extract_item(col, NULL((void*)0), COL_DSP_FRONT1, |
1436 | NULL((void*)0), 0, 0, &item)) || |
1437 | |
1438 | (error = col_insert_item(col2, NULL((void*)0), item, COL_DSP_FRONT1, |
1439 | NULL((void*)0), 0, COL_INSERT_NOCHECK0)) || |
1440 | |
1441 | ((verbose) && (error = col_debug_collection(col2, COL_TRAVERSE_DEFAULT0x00000000))) || |
1442 | |
1443 | (error = col_extract_item(col, NULL((void*)0), COL_DSP_FRONT1, |
1444 | NULL((void*)0), 0, 0, &item)) || |
1445 | |
1446 | (error = col_insert_item(col2, NULL((void*)0), item, COL_DSP_FRONT1, |
1447 | NULL((void*)0), 0, COL_INSERT_NOCHECK0)) || |
1448 | |
1449 | ((verbose) && (error = col_debug_collection(col2, COL_TRAVERSE_DEFAULT0x00000000))) || |
1450 | |
1451 | (error = col_extract_item(col, NULL((void*)0), COL_DSP_END0, |
1452 | NULL((void*)0), 0, 0, &item)) || |
1453 | |
1454 | (error = col_insert_item(col2, NULL((void*)0), item, COL_DSP_END0, |
1455 | NULL((void*)0), 0, COL_INSERT_NOCHECK0)) || |
1456 | |
1457 | ((verbose) && (error = col_debug_collection(col2, COL_TRAVERSE_DEFAULT0x00000000))) || |
1458 | |
1459 | (error = col_insert_str_property(col, NULL((void*)0), COL_DSP_INDEX4, |
1460 | NULL((void*)0), 100, COL_INSERT_NOCHECK0, |
1461 | "property100", "value100", 0)) || |
1462 | |
1463 | (error = col_extract_item(col, NULL((void*)0), COL_DSP_AFTER3, |
1464 | "property10", 0, COL_TYPE_STRING0x00000001, &item)) || |
1465 | |
1466 | (error = col_insert_item(col2, NULL((void*)0), item, COL_DSP_END0, |
1467 | NULL((void*)0), 0, COL_INSERT_NOCHECK0)) || |
1468 | |
1469 | ((verbose) && (error = col_debug_collection(col2, COL_TRAVERSE_DEFAULT0x00000000))) || |
1470 | |
1471 | (error = col_extract_item(col, NULL((void*)0), COL_DSP_BEFORE2, |
1472 | "property0", 0, COL_TYPE_STRING0x00000001, &item)) || |
1473 | |
1474 | (error = col_insert_item(col2, NULL((void*)0), item, COL_DSP_END0, |
1475 | NULL((void*)0), 0, COL_INSERT_NOCHECK0)) || |
1476 | |
1477 | ((verbose) && (error = col_debug_collection(col2, COL_TRAVERSE_DEFAULT0x00000000))) || |
1478 | |
1479 | (error = col_extract_item(col, NULL((void*)0), COL_DSP_INDEX4, |
1480 | NULL((void*)0), 1, 0, &item)) || |
1481 | |
1482 | (error = col_insert_item(col2, NULL((void*)0), item, COL_DSP_END0, |
1483 | NULL((void*)0), 0, COL_INSERT_NOCHECK0)) || |
1484 | |
1485 | ((verbose) && (error = col_debug_collection(col2, COL_TRAVERSE_DEFAULT0x00000000))) || |
1486 | |
1487 | (error = col_extract_item(col, NULL((void*)0), COL_DSP_NDUP7, |
1488 | "property0", 1, 0, &item)) || |
1489 | |
1490 | (error = col_insert_item(col2, NULL((void*)0), item, COL_DSP_END0, |
1491 | NULL((void*)0), 0, COL_INSERT_NOCHECK0)) || |
1492 | |
1493 | ((verbose) && (error = col_debug_collection(col2, COL_TRAVERSE_DEFAULT0x00000000))) || |
1494 | |
1495 | (error = col_extract_item(col, NULL((void*)0), COL_DSP_LASTDUP6, |
1496 | "property0", 0, 0, &item)) || |
1497 | |
1498 | (error = col_insert_item(col2, NULL((void*)0), item, COL_DSP_END0, |
1499 | NULL((void*)0), 0, COL_INSERT_NOCHECK0)) || |
1500 | |
1501 | ((verbose) && (error = col_debug_collection(col2, COL_TRAVERSE_DEFAULT0x00000000))) || |
1502 | |
1503 | (error = col_extract_item(col, NULL((void*)0), COL_DSP_FIRSTDUP5, |
1504 | "property0", 0, 0, &item)) || |
1505 | |
1506 | (error = col_insert_item(col2, NULL((void*)0), item, COL_DSP_END0, |
1507 | NULL((void*)0), 0, COL_INSERT_NOCHECK0)) || |
1508 | |
1509 | ((verbose) && (error = col_debug_collection(col2, COL_TRAVERSE_DEFAULT0x00000000)))) { |
1510 | |
1511 | COLOUT(printf("ERROR in the EXTRACTION TEST\n"))do { if (verbose) printf("ERROR in the EXTRACTION TEST\n"); } while(0); |
1512 | COLOUT(printf("Collection 1\n"))do { if (verbose) printf("Collection 1\n"); } while(0); |
1513 | COLOUT(col_debug_collection(col, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(col, 0x00000000); } while (0); |
1514 | COLOUT(printf("Collection 2\n"))do { if (verbose) printf("Collection 2\n"); } while(0); |
1515 | COLOUT(col_debug_collection(col2, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(col2, 0x00000000); } while (0); |
1516 | col_destroy_collection(col); |
1517 | col_destroy_collection(col2); |
1518 | return error; |
1519 | } |
1520 | |
1521 | COLOUT(printf("Collection 1\n"))do { if (verbose) printf("Collection 1\n"); } while(0); |
1522 | COLOUT(col_debug_collection(col, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(col, 0x00000000); } while (0); |
1523 | COLOUT(printf("Collection 2\n"))do { if (verbose) printf("Collection 2\n"); } while(0); |
1524 | COLOUT(col_debug_collection(col2, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(col2, 0x00000000); } while (0); |
1525 | |
1526 | col_destroy_collection(col2); |
1527 | col_destroy_collection(col); |
1528 | |
1529 | |
1530 | return EOK0; |
1531 | } |
1532 | |
1533 | /* Cleanup collback */ |
1534 | void cb(const char *property, |
1535 | int property_len, |
1536 | int type, |
1537 | void *data, |
1538 | int length, |
1539 | void *ext_data) |
1540 | { |
1541 | COLOUT(printf("%s\n", *((const char **)ext_data)))do { if (verbose) printf("%s\n", *((const char **)ext_data)); } while(0); |
1542 | COLOUT(printf("Property: %s\n", property))do { if (verbose) printf("Property: %s\n", property); } while (0); |
1543 | COLOUT(printf("Length: %d\n", property_len))do { if (verbose) printf("Length: %d\n", property_len); } while (0); |
1544 | COLOUT(printf("Type: %d\n", type))do { if (verbose) printf("Type: %d\n", type); } while(0); |
1545 | COLOUT(printf("Data len: %d\n", length))do { if (verbose) printf("Data len: %d\n", length); } while(0 ); |
1546 | } |
1547 | |
1548 | int delete_test(void) |
1549 | { |
1550 | |
1551 | struct collection_item *col; |
1552 | int error = EOK0; |
1553 | const char *str = "Cleanup Callback Test"; |
1554 | |
1555 | COLOUT(printf("\n\n==== DELETION TEST 1====\n\n"))do { if (verbose) printf("\n\n==== DELETION TEST 1====\n\n"); } while(0); |
1556 | |
1557 | if ((error = col_create_collection(&col, "test", 0)) || |
1558 | (error = col_add_int_property(col, NULL((void*)0), "tt", 1)) || |
1559 | ((verbose) && (error = col_debug_collection(col, COL_TRAVERSE_DEFAULT0x00000000))) || |
1560 | (error = col_add_int_property(col, NULL((void*)0), "test", 1)) || |
1561 | ((verbose) && (error = col_debug_collection(col, COL_TRAVERSE_DEFAULT0x00000000))) || |
1562 | (error = col_delete_property(col, "test", COL_TYPE_ANY0x0FFFFFFF, COL_TRAVERSE_DEFAULT0x00000000)) || |
1563 | ((verbose) && (error = col_debug_collection(col, COL_TRAVERSE_DEFAULT0x00000000))) || |
1564 | (error = col_add_int_property(col, NULL((void*)0), "test", 1)) || |
1565 | ((verbose) && (error = col_debug_collection(col, COL_TRAVERSE_DEFAULT0x00000000))) || |
1566 | (error = col_delete_property(col, "test", COL_TYPE_ANY0x0FFFFFFF, COL_TRAVERSE_DEFAULT0x00000000)) || |
1567 | ((verbose) && (error = col_debug_collection(col, COL_TRAVERSE_DEFAULT0x00000000))) || |
1568 | (error = col_add_int_property(col, NULL((void*)0), "test", 1))) { |
1569 | printf("Error in delete test %d\n", error); |
1570 | col_destroy_collection(col); |
1571 | return error; |
1572 | } |
1573 | |
1574 | COLOUT(col_debug_collection(col, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(col, 0x00000000); } while (0); |
1575 | col_destroy_collection(col); |
1576 | |
1577 | COLOUT(printf("\n\n==== DELETION TEST 1 END ====\n\n"))do { if (verbose) printf("\n\n==== DELETION TEST 1 END ====\n\n" ); } while(0); |
1578 | COLOUT(printf("\n\n==== DELETION TEST 2====\n\n"))do { if (verbose) printf("\n\n==== DELETION TEST 2====\n\n"); } while(0); |
1579 | |
1580 | if ((error = col_create_collection(&col, "test2", 0)) || |
1581 | (error = col_add_int_property(col, NULL((void*)0), "tt", 1)) || |
1582 | ((verbose) && (error = col_debug_collection(col, COL_TRAVERSE_DEFAULT0x00000000))) || |
1583 | (error = col_add_int_property(col, NULL((void*)0), "test", 1)) || |
1584 | ((verbose) && (error = col_debug_collection(col, COL_TRAVERSE_DEFAULT0x00000000))) || |
1585 | (error = col_remove_item(col, NULL((void*)0), COL_DSP_END0, NULL((void*)0), 0, COL_TYPE_ANY0x0FFFFFFF)) || |
1586 | ((verbose) && (error = col_debug_collection(col, COL_TRAVERSE_DEFAULT0x00000000))) || |
1587 | (error = col_add_int_property(col, NULL((void*)0), "test", 1)) || |
1588 | ((verbose) && (error = col_debug_collection(col, COL_TRAVERSE_DEFAULT0x00000000))) || |
1589 | (error = col_remove_item_from_current(col, COL_DSP_AFTER3, "tt", 0, COL_TYPE_ANY0x0FFFFFFF)) || |
1590 | ((verbose) && (error = col_debug_collection(col, COL_TRAVERSE_DEFAULT0x00000000))) || |
1591 | (error = col_add_int_property(col, NULL((void*)0), "test", 1))) { |
1592 | printf("Error in delete test %d\n", error); |
1593 | col_destroy_collection(col); |
1594 | return error; |
1595 | } |
1596 | |
1597 | COLOUT(col_debug_collection(col, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(col, 0x00000000); } while (0); |
1598 | |
1599 | COLOUT(printf("\n\n==== DELETION TEST 2 END ====\n\n"))do { if (verbose) printf("\n\n==== DELETION TEST 2 END ====\n\n" ); } while(0); |
1600 | |
1601 | |
1602 | col_destroy_collection_with_cb(col, cb, (void *)(&str)); |
1603 | |
1604 | return error; |
1605 | } |
1606 | |
1607 | /* Search test */ |
1608 | int search_test(void) |
1609 | { |
1610 | struct collection_item *level1 = NULL((void*)0); |
1611 | struct collection_item *level2 = NULL((void*)0); |
1612 | struct collection_item *level3 = NULL((void*)0); |
1613 | struct collection_item *level4 = NULL((void*)0); |
1614 | char binary_dump[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; |
1615 | int found = 0; |
1616 | int error = 0; |
1617 | |
1618 | COLOUT(printf("\n\n==== SEARCH TEST ====\n\n"))do { if (verbose) printf("\n\n==== SEARCH TEST ====\n\n"); } while (0); |
1619 | |
1620 | if ((error = col_create_collection(&level1, "level1", 0)) || |
1621 | (error = col_create_collection(&level2, "level2", 0)) || |
1622 | (error = col_add_collection_to_collection(level1, NULL((void*)0), NULL((void*)0), level2, COL_ADD_MODE_REFERENCE0)) || |
1623 | (error = col_create_collection(&level3, "level3", 0)) || |
1624 | (error = col_add_collection_to_collection(level1, "level2", NULL((void*)0), level3, COL_ADD_MODE_REFERENCE0)) || |
1625 | (error = col_create_collection(&level4, "leveL4", 0)) || |
1626 | (error = col_add_collection_to_collection(level1, "level3", NULL((void*)0), level4, COL_ADD_MODE_REFERENCE0)) || |
1627 | (error = col_add_int_property(level1, "leveL4", "id", 1)) || |
1628 | (error = col_add_long_property(level1, "level3", "packets", 100000000L)) || |
1629 | (error = col_add_binary_property(level1, "level2", "stack", binary_dump, sizeof(binary_dump)))) { |
1630 | col_destroy_collection(level1); |
1631 | col_destroy_collection(level2); |
1632 | col_destroy_collection(level3); |
1633 | col_destroy_collection(level4); |
1634 | printf("Failed to build test. Error %d\n", error); |
1635 | return error; |
1636 | } |
1637 | |
1638 | COLOUT(col_debug_collection(level1, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(level1, 0x00000000); } while(0); |
1639 | |
1640 | error = col_is_item_in_collection(level1, "level1!level2!level3!level4!", COL_TYPE_ANY0x0FFFFFFF, COL_TRAVERSE_DEFAULT0x00000000, &found); |
1641 | if (!error) { |
1642 | col_destroy_collection(level1); |
1643 | col_destroy_collection(level2); |
1644 | col_destroy_collection(level3); |
1645 | col_destroy_collection(level4); |
1646 | printf("Expected error here since the search data is illegal but got success\n"); |
1647 | return EINVAL22; |
1648 | } |
1649 | |
1650 | found = 0; |
1651 | error = 0; |
1652 | error = col_is_item_in_collection(level1, "level1!level2!level3!level4!id", COL_TYPE_ANY0x0FFFFFFF, COL_TRAVERSE_DEFAULT0x00000000, &found); |
1653 | if ((error) || (!found)) { |
1654 | col_destroy_collection(level1); |
1655 | col_destroy_collection(level2); |
1656 | col_destroy_collection(level3); |
1657 | col_destroy_collection(level4); |
1658 | printf("Failed to find item [level1!level2!level3!level4!id]. Error %d\n", error); |
1659 | return error ? error : ENOENT2; |
1660 | } |
1661 | else COLOUT(printf("Expected item is found\n"))do { if (verbose) printf("Expected item is found\n"); } while (0); |
1662 | |
1663 | |
1664 | found = 0; |
1665 | error = 0; |
1666 | error = col_is_item_in_collection(level1, NULL((void*)0), COL_TYPE_INTEGER0x00000004, COL_TRAVERSE_DEFAULT0x00000000, &found); |
1667 | if ((error) || (!found)) { |
1668 | col_destroy_collection(level1); |
1669 | col_destroy_collection(level2); |
1670 | col_destroy_collection(level3); |
1671 | col_destroy_collection(level4); |
1672 | printf("Failed to find first int item [level1!level2!level3!level4!id]. Error %d\n", error); |
1673 | return error ? error : ENOENT2; |
1674 | } |
1675 | else COLOUT(printf("Expected item is found\n"))do { if (verbose) printf("Expected item is found\n"); } while (0); |
1676 | |
1677 | |
1678 | found = 0; |
1679 | error = 0; |
1680 | error = col_is_item_in_collection(level1, "", COL_TYPE_INTEGER0x00000004, COL_TRAVERSE_DEFAULT0x00000000, &found); |
1681 | if ((error) || (!found)) { |
1682 | col_destroy_collection(level1); |
1683 | col_destroy_collection(level2); |
1684 | col_destroy_collection(level3); |
1685 | col_destroy_collection(level4); |
1686 | printf("Failed to find first int item [level1!level2!level3!level4!id]. Error %d\n", error); |
1687 | return error ? error : ENOENT2; |
1688 | } |
1689 | else COLOUT(printf("Expected item is found\n"))do { if (verbose) printf("Expected item is found\n"); } while (0); |
1690 | |
1691 | |
1692 | found = 0; |
1693 | error = 0; |
1694 | error = col_is_item_in_collection(level1, "level3!level4!id", COL_TYPE_ANY0x0FFFFFFF, COL_TRAVERSE_DEFAULT0x00000000, &found); |
1695 | if ((error) || (!found)) { |
1696 | col_destroy_collection(level1); |
1697 | col_destroy_collection(level2); |
1698 | col_destroy_collection(level3); |
1699 | col_destroy_collection(level4); |
1700 | printf("Failed to find item [level3!level4!id]. Error %d\n", error); |
1701 | return error ? error : ENOENT2; |
1702 | } |
1703 | else COLOUT(printf("Expected item is found\n"))do { if (verbose) printf("Expected item is found\n"); } while (0); |
1704 | |
1705 | found = 0; |
1706 | error = 0; |
1707 | error = col_is_item_in_collection(level1, "level3!packets", COL_TYPE_ANY0x0FFFFFFF, COL_TRAVERSE_DEFAULT0x00000000, &found); |
1708 | if ((error) || (!found)) { |
1709 | col_destroy_collection(level1); |
1710 | col_destroy_collection(level2); |
1711 | col_destroy_collection(level3); |
1712 | col_destroy_collection(level4); |
1713 | printf("Failed to find item [level3.packets]. Error %d\n", error); |
1714 | return error ? error : ENOENT2; |
1715 | } |
1716 | else COLOUT(printf("Expected item is found\n"))do { if (verbose) printf("Expected item is found\n"); } while (0); |
1717 | |
1718 | found = 0; |
1719 | error = 0; |
Value stored to 'error' is never read | |
1720 | error = col_is_item_in_collection(level1, "level1!level2!stack", COL_TYPE_ANY0x0FFFFFFF, COL_TRAVERSE_DEFAULT0x00000000, &found); |
1721 | if ((error) || (!found)) { |
1722 | col_destroy_collection(level1); |
1723 | col_destroy_collection(level2); |
1724 | col_destroy_collection(level3); |
1725 | col_destroy_collection(level4); |
1726 | printf("Failed to find item [level1!level2!stack]. Error %d\n", error); |
1727 | return error ? error : ENOENT2; |
1728 | } |
1729 | else COLOUT(printf("Expected item is found\n"))do { if (verbose) printf("Expected item is found\n"); } while (0); |
1730 | |
1731 | found = 0; |
1732 | error = 0; |
1733 | error = col_is_item_in_collection(level1, "level1!level2!level3", COL_TYPE_ANY0x0FFFFFFF, COL_TRAVERSE_DEFAULT0x00000000, &found); |
1734 | if ((error) || (!found)) { |
1735 | col_destroy_collection(level1); |
1736 | col_destroy_collection(level2); |
1737 | col_destroy_collection(level3); |
1738 | col_destroy_collection(level4); |
1739 | printf("Failed to find item [level1!level2!level3]. Error %d\n", error); |
1740 | return error ? error : ENOENT2; |
1741 | } |
1742 | else COLOUT(printf("Expected item is found\n"))do { if (verbose) printf("Expected item is found\n"); } while (0); |
1743 | |
1744 | /* Negative tests */ |
1745 | found = 0; |
1746 | error = 0; |
1747 | error = col_is_item_in_collection(level1, NULL((void*)0), 0, COL_TRAVERSE_DEFAULT0x00000000, &found); |
1748 | if ((error != ENOENT2) || (found)) { |
1749 | col_destroy_collection(level1); |
1750 | col_destroy_collection(level2); |
1751 | col_destroy_collection(level3); |
1752 | col_destroy_collection(level4); |
1753 | if (error) { |
1754 | printf("Unexpected error with NULL & 0 test %d\n", error); |
1755 | } |
1756 | else { |
1757 | printf("Found unexpected item with NULL & 0. Error %d\n", error); |
1758 | error = EINVAL22; |
1759 | } |
1760 | return error; |
1761 | } |
1762 | else COLOUT(printf("No item is found as expected.\n"))do { if (verbose) printf("No item is found as expected.\n"); } while(0); |
1763 | |
1764 | found = 0; |
1765 | error = 0; |
1766 | error = col_is_item_in_collection(level1, "", 0, COL_TRAVERSE_DEFAULT0x00000000, &found); |
1767 | if ((error != ENOENT2) || (found)) { |
1768 | col_destroy_collection(level1); |
1769 | col_destroy_collection(level2); |
1770 | col_destroy_collection(level3); |
1771 | col_destroy_collection(level4); |
1772 | if (error) { |
1773 | printf("Unexpected error with \"\" & 0 tests %d\n", error); |
1774 | } |
1775 | else { |
1776 | printf("Found unexpected item with \"\" & 0. Error %d\n", error); |
1777 | error = EINVAL22; |
1778 | } |
1779 | return error; |
1780 | } |
1781 | else COLOUT(printf("No item is found as expected.\n"))do { if (verbose) printf("No item is found as expected.\n"); } while(0); |
1782 | |
1783 | col_destroy_collection(level1); |
1784 | col_destroy_collection(level2); |
1785 | col_destroy_collection(level3); |
1786 | col_destroy_collection(level4); |
1787 | |
1788 | COLOUT(printf("\n\n==== SEARCH TEST END ====\n\n"))do { if (verbose) printf("\n\n==== SEARCH TEST END ====\n\n") ; } while(0); |
1789 | |
1790 | return EOK0; |
1791 | } |
1792 | |
1793 | /* Sort test */ |
1794 | int sort_test(void) |
1795 | { |
1796 | struct collection_item *level1 = NULL((void*)0); |
1797 | struct collection_item *level2a = NULL((void*)0); |
1798 | struct collection_item *level2b = NULL((void*)0); |
1799 | struct collection_item *level3 = NULL((void*)0); |
1800 | int error = 0; |
1801 | |
1802 | COLOUT(printf("\n\n==== SORT TEST ====\n\n"))do { if (verbose) printf("\n\n==== SORT TEST ====\n\n"); } while (0); |
1803 | |
1804 | if ((error = col_create_collection(&level1, "level1", 0)) || |
1805 | (error = col_create_collection(&level2a, "level2a", 0)) || |
1806 | (error = col_add_collection_to_collection(level1, NULL((void*)0), NULL((void*)0), level2a, COL_ADD_MODE_REFERENCE0)) || |
1807 | (error = col_create_collection(&level2b, "level2b", 0)) || |
1808 | (error = col_add_collection_to_collection(level1, NULL((void*)0), NULL((void*)0), level2b, COL_ADD_MODE_REFERENCE0)) || |
1809 | (error = col_create_collection(&level3, "level3", 0)) || |
1810 | (error = col_add_collection_to_collection(level1, "level2a", NULL((void*)0), level3, COL_ADD_MODE_REFERENCE0)) || |
1811 | (error = col_add_collection_to_collection(level1, "level2b", NULL((void*)0), level3, COL_ADD_MODE_REFERENCE0)) || |
1812 | (error = col_add_int_property(level1, NULL((void*)0), "int3", 1)) || |
1813 | (error = col_add_int_property(level1, NULL((void*)0), "int2", 2)) || |
1814 | (error = col_add_int_property(level1, NULL((void*)0), "int1", 3)) || |
1815 | (error = col_add_bool_property(level1, NULL((void*)0), "bool3", 1)) || |
1816 | (error = col_add_bool_property(level1, NULL((void*)0), "bool2", 1)) || |
1817 | (error = col_add_bool_property(level1, NULL((void*)0), "bool1", 0)) || |
1818 | (error = col_add_unsigned_property(level1, NULL((void*)0), "unsigned1", 2)) || |
1819 | (error = col_add_unsigned_property(level1, NULL((void*)0), "unsigned3", 1)) || |
1820 | (error = col_add_unsigned_property(level1, NULL((void*)0), "unsigned2", 3)) || |
1821 | (error = col_add_long_property(level1, NULL((void*)0), "long3", 1)) || |
1822 | (error = col_add_long_property(level1, NULL((void*)0), "long2", 2)) || |
1823 | (error = col_add_long_property(level1, NULL((void*)0), "long1", 3)) || |
1824 | (error = col_add_ulong_property(level1, NULL((void*)0), "ulong1", 2)) || |
1825 | (error = col_add_ulong_property(level1, NULL((void*)0), "ulong3", 1)) || |
1826 | (error = col_add_ulong_property(level1, NULL((void*)0), "ulong2", 3)) || |
1827 | (error = col_add_double_property(level1, NULL((void*)0), "double1", 2.2)) || |
1828 | (error = col_add_double_property(level1, NULL((void*)0), "double3", 1.1)) || |
1829 | (error = col_add_double_property(level1, NULL((void*)0), "double2", 3.3)) || |
1830 | (error = col_add_int_property(level3, NULL((void*)0), "int3L3", 1)) || |
1831 | (error = col_add_int_property(level3, NULL((void*)0), "int2L3", 2)) || |
1832 | (error = col_add_int_property(level3, NULL((void*)0), "int1L3", 3)) || |
1833 | (error = col_add_unsigned_property(level1, "level2a!level3", "unsigned1L3", 2)) || |
1834 | (error = col_add_unsigned_property(level1, "level2a!level3", "unsigned3L3", 1)) || |
1835 | (error = col_add_unsigned_property(level1, "level2a!level3", "unsigned2L3", 3)) || |
1836 | (error = col_add_long_property(level1, "level2b!level3", "long3L3", 1)) || |
1837 | (error = col_add_long_property(level1, "level2b!level3", "long2L3", 2)) || |
1838 | (error = col_add_long_property(level1, "level2b!level3", "long1L3", 3)) || |
1839 | (error = col_add_ulong_property(level1, "level3", "ulong1L3", 2)) || |
1840 | (error = col_add_ulong_property(level1, "level3", "ulong3L3", 1)) || |
1841 | (error = col_add_ulong_property(level1, "level3", "ulong2L3", 3)) || |
1842 | (error = col_add_bool_property(level3, NULL((void*)0), "bool3", 1)) || |
1843 | (error = col_add_bool_property(level3, NULL((void*)0), "bool2", 1)) || |
1844 | (error = col_add_bool_property(level3, NULL((void*)0), "bool1", 0)) || |
1845 | (error = col_add_double_property(level3, NULL((void*)0), "double1L3", 2.2)) || |
1846 | (error = col_add_double_property(level3, NULL((void*)0), "double3L3", 1.1)) || |
1847 | (error = col_add_double_property(level3, NULL((void*)0), "double2L3", 3.3))) { |
1848 | col_destroy_collection(level1); |
1849 | col_destroy_collection(level2a); |
1850 | col_destroy_collection(level2b); |
1851 | col_destroy_collection(level3); |
1852 | printf("Failed to build test. Error %d\n", error); |
1853 | return error; |
1854 | } |
1855 | |
1856 | COLOUT(printf("\nUNSORTED COLLECTION\n\n"))do { if (verbose) printf("\nUNSORTED COLLECTION\n\n"); } while (0); |
1857 | COLOUT(col_debug_collection(level1, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(level1, 0x00000000); } while(0); |
1858 | |
1859 | error = col_sort_collection(level1, COL_CMPIN_PROP_EQU0x000000004, COL_SORT_SUB0x00000002 | COL_SORT_MYSUB0x00000004); |
1860 | if (error) { |
1861 | col_destroy_collection(level1); |
1862 | col_destroy_collection(level2a); |
1863 | col_destroy_collection(level2b); |
1864 | col_destroy_collection(level3); |
1865 | printf("Failed sort. Error %d\n", error); |
1866 | return error; |
1867 | } |
1868 | |
1869 | COLOUT(printf("\nSORTED BUT SKIPPING REFERENCES\n\n"))do { if (verbose) printf("\nSORTED BUT SKIPPING REFERENCES\n\n" ); } while(0); |
1870 | COLOUT(col_debug_collection(level1, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(level1, 0x00000000); } while(0); |
1871 | |
1872 | error = col_sort_collection(level1, COL_CMPIN_PROP_EQU0x000000004, COL_SORT_SUB0x00000002); |
1873 | if (error) { |
1874 | col_destroy_collection(level1); |
1875 | col_destroy_collection(level2a); |
1876 | col_destroy_collection(level2b); |
1877 | col_destroy_collection(level3); |
1878 | printf("Failed sort. Error %d\n", error); |
1879 | return error; |
1880 | } |
1881 | |
1882 | COLOUT(printf("\nSORTED BUT NOT SKIPPING REFERENCES\n\n"))do { if (verbose) printf("\nSORTED BUT NOT SKIPPING REFERENCES\n\n" ); } while(0); |
1883 | COLOUT(col_debug_collection(level1, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(level1, 0x00000000); } while(0); |
1884 | |
1885 | error = col_sort_collection(level1, COL_CMPIN_DATA_LEN0x000000040, COL_SORT_SUB0x00000002 | COL_SORT_DESC0x00000001); |
1886 | if (error) { |
1887 | col_destroy_collection(level1); |
1888 | col_destroy_collection(level2a); |
1889 | col_destroy_collection(level2b); |
1890 | col_destroy_collection(level3); |
1891 | printf("Failed sort. Error %d\n", error); |
1892 | return error; |
1893 | } |
1894 | |
1895 | COLOUT(printf("\nSORTED DESC NOT SKIPPING BY LENGTH OF DATA\n\n"))do { if (verbose) printf("\nSORTED DESC NOT SKIPPING BY LENGTH OF DATA\n\n" ); } while(0); |
1896 | COLOUT(col_debug_collection(level1, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(level1, 0x00000000); } while(0); |
1897 | |
1898 | error = col_sort_collection(level1, COL_CMPIN_PROP_LEN0x000000010, COL_SORT_SUB0x00000002 | COL_SORT_DESC0x00000001); |
1899 | if (error) { |
1900 | col_destroy_collection(level1); |
1901 | col_destroy_collection(level2a); |
1902 | col_destroy_collection(level2b); |
1903 | col_destroy_collection(level3); |
1904 | printf("Failed sort. Error %d\n", error); |
1905 | return error; |
1906 | } |
1907 | |
1908 | COLOUT(printf("\nSORTED DESC NOT SKIPPING BY LENGTH OF PROPERTY\n\n"))do { if (verbose) printf("\nSORTED DESC NOT SKIPPING BY LENGTH OF PROPERTY\n\n" ); } while(0); |
1909 | COLOUT(col_debug_collection(level1, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(level1, 0x00000000); } while(0); |
1910 | |
1911 | error = col_sort_collection(level1, COL_CMPIN_DATA0x000000080, COL_SORT_SUB0x00000002 | COL_SORT_DESC0x00000001); |
1912 | if (error) { |
1913 | col_destroy_collection(level1); |
1914 | col_destroy_collection(level2a); |
1915 | col_destroy_collection(level2b); |
1916 | col_destroy_collection(level3); |
1917 | printf("Failed sort. Error %d\n", error); |
1918 | return error; |
1919 | } |
1920 | |
1921 | COLOUT(printf("\nSORTED DESC NOT SKIPPING BY DATA\n\n"))do { if (verbose) printf("\nSORTED DESC NOT SKIPPING BY DATA\n\n" ); } while(0); |
1922 | COLOUT(col_debug_collection(level1, COL_TRAVERSE_DEFAULT))do { if (verbose) col_debug_collection(level1, 0x00000000); } while(0); |
1923 | |
1924 | col_destroy_collection(level1); |
1925 | col_destroy_collection(level2a); |
1926 | col_destroy_collection(level2b); |
1927 | col_destroy_collection(level3); |
1928 | |
1929 | COLOUT(printf("\n\n==== SORT TEST END ====\n\n"))do { if (verbose) printf("\n\n==== SORT TEST END ====\n\n"); } while(0); |
1930 | |
1931 | return EOK0; |
1932 | } |
1933 | |
1934 | /* Main function of the unit test */ |
1935 | |
1936 | int main(int argc, char *argv[]) |
1937 | { |
1938 | int error = 0; |
1939 | test_fn tests[] = { ref_collection_test, |
1940 | single_collection_test, |
1941 | add_collection_test, |
1942 | mixed_collection_test, |
1943 | iterator_test, |
1944 | insert_extract_test, |
1945 | delete_test, |
1946 | search_test, |
1947 | sort_test, |
1948 | NULL((void*)0) }; |
1949 | test_fn t; |
1950 | int i = 0; |
1951 | |
1952 | if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = 1; |
1953 | |
1954 | printf("Start\n"); |
1955 | |
1956 | while ((t = tests[i++])) { |
1957 | error = t(); |
1958 | if (error) { |
1959 | printf("Failed!\n"); |
1960 | return error; |
1961 | } |
1962 | } |
1963 | |
1964 | printf("Success!\n"); |
1965 | return 0; |
1966 | |
1967 | } |