gwenhywfar  5.1.2
idlist64-t.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Mon Mar 01 2004
3  copyright : (C) 2020 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU Lesser General Public *
10  * License as published by the Free Software Foundation; either *
11  * version 2.1 of the License, or (at your option) any later version. *
12  * *
13  * This 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 GNU *
16  * Lesser General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU Lesser General Public *
19  * License along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  * *
23  ***************************************************************************/
24 
25 
26 /* This file is included by "idlist64.c" */
27 
28 
29 #if GWENHYWFAR_ENABLE_TESTCODE
30 
31 
32 
33 /* ------------------------------------------------------------------------------------------------
34  * forward declarations
35  * ------------------------------------------------------------------------------------------------
36  */
37 
38 
39 static int GWENHYWFAR_CB test1(GWEN_TEST_MODULE *mod);
40 static int GWENHYWFAR_CB test2(GWEN_TEST_MODULE *mod);
41 static int GWENHYWFAR_CB test3(GWEN_TEST_MODULE *mod);
42 static int GWENHYWFAR_CB test4(GWEN_TEST_MODULE *mod);
43 static int GWENHYWFAR_CB test5(GWEN_TEST_MODULE *mod);
44 static int GWENHYWFAR_CB test6(GWEN_TEST_MODULE *mod);
45 static int GWENHYWFAR_CB test7(GWEN_TEST_MODULE *mod);
46 static int GWENHYWFAR_CB test8(GWEN_TEST_MODULE *mod);
47 static int GWENHYWFAR_CB test9(GWEN_TEST_MODULE *mod);
48 static int GWENHYWFAR_CB test10(GWEN_TEST_MODULE *mod);
49 static int GWENHYWFAR_CB test11(GWEN_TEST_MODULE *mod);
50 
51 static int _compareList1AgainstList2(GWEN_IDLIST64 *idList1, GWEN_IDLIST64 *idList2);
52 
53 
54 
55 /* ------------------------------------------------------------------------------------------------
56  * implementations
57  * ------------------------------------------------------------------------------------------------
58  */
59 
60 
61 
63 {
64  GWEN_TEST_MODULE *newMod;
65 
66  newMod=GWEN_Test_Module_AddModule(mod, "GWEN_IdList64", NULL);
67 
68  GWEN_Test_Module_AddTest(newMod, "test1", test1, NULL);
69  GWEN_Test_Module_AddTest(newMod, "test2", test2, NULL);
70  GWEN_Test_Module_AddTest(newMod, "test3", test3, NULL);
71  GWEN_Test_Module_AddTest(newMod, "test4", test4, NULL);
72  GWEN_Test_Module_AddTest(newMod, "test5", test5, NULL);
73  GWEN_Test_Module_AddTest(newMod, "test6", test6, NULL);
74  GWEN_Test_Module_AddTest(newMod, "test7", test7, NULL);
75  GWEN_Test_Module_AddTest(newMod, "test8", test8, NULL);
76  GWEN_Test_Module_AddTest(newMod, "test9", test9, NULL);
77  GWEN_Test_Module_AddTest(newMod, "test10", test10, NULL);
78  GWEN_Test_Module_AddTest(newMod, "test11", test11, NULL);
79 
80  return 0;
81 }
82 
83 
84 
86 {
87  GWEN_IDLIST64 *idList1;
88  GWEN_IDLIST64_ITERATOR *iterator1;
89  int i;
90  uint64_t id;
91 
92  idList1=GWEN_IdList64_newWithSteps(64);
93  for (i=0; i<100; i++) {
94  int64_t rv;
95 
96  rv=GWEN_IdList64_AddId(idList1, i+1);
97  if (rv<0) {
98  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", (int) rv);
99  GWEN_IdList64_free(idList1);
100  return (int) rv;
101  }
102  if (rv!=(int64_t) i) {
103  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected position for id at index %u (is %lu, expected %u)",
104  i, (unsigned long) rv, i);
105  GWEN_IdList64_free(idList1);
106  return (int) rv;
107  }
108  }
109 
110  i=0;
111  iterator1=GWEN_IdList64_Iterator_new(idList1);
112  id=GWEN_IdList64_Iterator_GetFirstId(iterator1);
113  while (id) {
114  if (id!=i+1) {
115  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected id at index %lu (is %lu, expected %lu)",
116  (unsigned long) i, (unsigned long) id, (unsigned long) i+1);
117  GWEN_IdList64_Iterator_free(iterator1);
118  GWEN_IdList64_free(idList1);
119  return GWEN_ERROR_GENERIC;
120  }
121  i++;
122  id=GWEN_IdList64_Iterator_GetNextId(iterator1);
123  }
124  GWEN_IdList64_Iterator_free(iterator1);
125  GWEN_IdList64_free(idList1);
126  return 0;
127 }
128 
129 
130 
132 {
133  GWEN_IDLIST64 *idList1;
134  GWEN_IDLIST64_ITERATOR *iterator1;
135  int i;
136  uint64_t id;
137  int rv;
138 
139  idList1=GWEN_IdList64_newWithSteps(64);
140  for (i=0; i<100; i++) {
141  int64_t rv;
142 
143  rv=GWEN_IdList64_AddId(idList1, i+1);
144  if (rv<0) {
145  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", (int) rv);
146  GWEN_IdList64_free(idList1);
147  return (int) rv;
148  }
149  }
150 
151  rv=GWEN_IdList64_ReverseSort(idList1);
152  if (rv<0) {
153  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", (int) rv);
154  GWEN_IdList64_free(idList1);
155  return (int) rv;
156  }
157 
158 
159  i=0;
160  iterator1=GWEN_IdList64_Iterator_new(idList1);
161  id=GWEN_IdList64_Iterator_GetFirstId(iterator1);
162  while (id) {
163  if (id!=100-i) {
164  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected id at index %lu (is %lu, expected %lu)",
165  (unsigned long) i, (unsigned long) id, (unsigned long) i+1);
166  GWEN_IdList64_Iterator_free(iterator1);
167  GWEN_IdList64_free(idList1);
168  return GWEN_ERROR_GENERIC;
169  }
170  i++;
171  id=GWEN_IdList64_Iterator_GetNextId(iterator1);
172  }
173  if (i!=100) {
174  DBG_ERROR(GWEN_LOGDOMAIN, "More entries than expected (is %d, expected %d)", i, 100);
175  GWEN_IdList64_Iterator_free(iterator1);
176  GWEN_IdList64_free(idList1);
177  return GWEN_ERROR_GENERIC;
178  }
179  GWEN_IdList64_Iterator_free(iterator1);
180 
181 
182  rv=GWEN_IdList64_Sort(idList1);
183  if (rv<0) {
184  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", (int) rv);
185  GWEN_IdList64_free(idList1);
186  return (int) rv;
187  }
188 
189  i=0;
190  iterator1=GWEN_IdList64_Iterator_new(idList1);
191  id=GWEN_IdList64_Iterator_GetFirstId(iterator1);
192  while (id) {
193  if (id!=i+1) {
194  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected id at index %lu (is %lu, expected %lu)",
195  (unsigned long) i, (unsigned long) id, (unsigned long) i+1);
196  GWEN_IdList64_Iterator_free(iterator1);
197  GWEN_IdList64_free(idList1);
198  return GWEN_ERROR_GENERIC;
199  }
200  i++;
201  id=GWEN_IdList64_Iterator_GetNextId(iterator1);
202  }
203  if (i!=100) {
204  DBG_ERROR(GWEN_LOGDOMAIN, "More entries than expected (is %d, expected %d)", i, 100);
205  GWEN_IdList64_Iterator_free(iterator1);
206  GWEN_IdList64_free(idList1);
207  return GWEN_ERROR_GENERIC;
208  }
209  GWEN_IdList64_Iterator_free(iterator1);
210 
211 
212  GWEN_IdList64_free(idList1);
213  return 0;
214 }
215 
216 
217 
219 {
220  GWEN_IDLIST64 *ptrList1;
221  int i;
222 
223  ptrList1=GWEN_IdList64_newWithSteps(256);
224 
225  for (i=0; i<2048; i++) {
226  int64_t rv;
227 
228  rv=GWEN_IdList64_AddId(ptrList1, (uint64_t) i+1);
229  if (rv<0) {
231  "Error on GWEN_IdList64_AddEntry(%d): %s (%d)",
232  i, GWEN_Error_SimpleToString((int)rv), (int)rv);
233  return rv;
234  }
235  if (rv!=(int64_t)i) {
236  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected index returned for entry %d: is %ld, should be %d ", i, (unsigned long) rv, i);
237  return GWEN_ERROR_INTERNAL;
238  }
239  }
240 
241 
242  for (i=0; i<8; i++) {
243  GWEN_IDTABLE64 *table;
244  int refCounter;
245 
246  table=GWEN_IdList64_GetTableAt(ptrList1, i);
247  refCounter=table->refCount;
248  if (refCounter!=1) {
249  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table (list1) %d: is %d, should be 1 ", i, refCounter);
250  return GWEN_ERROR_INTERNAL;
251  }
252  }
253 
254  GWEN_IdList64_free(ptrList1);
255 
256  return 0;
257 }
258 
259 
260 
262 {
263  GWEN_IDLIST64 *ptrList1;
264  GWEN_IDLIST64 *ptrList2;
265  int i;
266 
267  ptrList1=GWEN_IdList64_newWithSteps(256);
268 
269  for (i=0; i<2048; i++) {
270  int64_t rv;
271 
272  rv=GWEN_IdList64_AddId(ptrList1, (uint64_t) i+1);
273  if (rv<0) {
275  "Error on GWEN_IdList64_AddId(%d): %s (%d)",
276  i, GWEN_Error_SimpleToString((int)rv), (int)rv);
277  return rv;
278  }
279  if (rv!=(int64_t)i) {
280  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected index returned for entry %d: is %ld, should be %d ", i, (unsigned long) rv, i);
281  return GWEN_ERROR_INTERNAL;
282  }
283  }
284 
285 
286  for (i=0; i<8; i++) {
287  GWEN_IDTABLE64 *table;
288  int refCounter;
289 
290  table=GWEN_IdList64_GetTableAt(ptrList1, i);
291  refCounter=table->refCount;
292  if (refCounter!=1) {
293  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table (list1) %d: is %d, should be 1 ", i, refCounter);
294  return GWEN_ERROR_INTERNAL;
295  }
296  }
297 
298  ptrList2=GWEN_IdList64_LazyCopy(ptrList1);
299 
300  GWEN_IdList64_free(ptrList1);
301  GWEN_IdList64_free(ptrList2);
302 
303  return 0;
304 }
305 
306 
307 
309 {
310  GWEN_IDLIST64 *ptrList1;
311  GWEN_IDLIST64 *ptrList2;
312  int i;
313 
314  ptrList1=GWEN_IdList64_newWithSteps(256);
315 
316  for (i=0; i<2048; i++) {
317  int64_t rv;
318 
319  rv=GWEN_IdList64_AddId(ptrList1, (uint64_t) i+1);
320  if (rv<0) {
322  "Error on GWEN_IdList64_AddId(%d): %s (%d)",
323  i, GWEN_Error_SimpleToString((int)rv), (int)rv);
324  return rv;
325  }
326  if (rv!=(int64_t)i) {
327  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected index returned for entry %d: is %ld, should be %d ", i, (unsigned long) rv, i);
328  return GWEN_ERROR_INTERNAL;
329  }
330  }
331 
332  ptrList2=GWEN_IdList64_LazyCopy(ptrList1);
333 
334  for (i=0; i<2048; i++) {
335  int64_t entry;
336 
337  entry=GWEN_IdList64_GetIdAt(ptrList1, i);
338  if (entry<0) {
340  "Error on GWEN_IdList64_GetIdAt(%d, list1): %s (%d)",
341  i, GWEN_Error_SimpleToString(entry), (int)entry);
342  return entry;
343  }
344  if (entry != (int64_t)(i+1)) {
345  DBG_ERROR(GWEN_LOGDOMAIN, "Non-matching entry at index %d: is %ld, should be %d ", i, (unsigned long) entry, i);
346  return GWEN_ERROR_INTERNAL;
347  }
348  }
349 
350  for (i=0; i<2048; i++) {
351  int64_t entry;
352 
353  entry=GWEN_IdList64_GetIdAt(ptrList2, i);
354  if (entry<0) {
356  "Error on GWEN_IdList64_GetIdAt(%d, list2): %s (%d)",
357  i, GWEN_Error_SimpleToString(entry), (int)entry);
358  return entry;
359  }
360  if (entry != (int64_t)(i+1)) {
361  DBG_ERROR(GWEN_LOGDOMAIN, "Non-matching entry at index %d: is %ld, should be %d ", i, (unsigned long) entry, i);
362  return GWEN_ERROR_INTERNAL;
363  }
364  }
365 
366 
367  for (i=0; i<8; i++) {
368  GWEN_IDTABLE64 *table;
369  int refCounter;
370 
371  table=GWEN_IdList64_GetTableAt(ptrList1, i);
372  refCounter=table->refCount;
373  if (refCounter!=1) {
374  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table (list1) %d: is %d, should be 1 ", i, refCounter);
375  return GWEN_ERROR_INTERNAL;
376  }
377  }
378 
379  for (i=0; i<8; i++) {
380  GWEN_IDTABLE64 *table;
381  int refCounter;
382 
383  table=GWEN_IdList64_GetTableAt(ptrList2, i);
384  refCounter=table->refCount;
385  if (refCounter!=1) {
386  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table (list2) %d: is %d, should be 1 ", i, refCounter);
387  return GWEN_ERROR_INTERNAL;
388  }
389  }
390 
391  GWEN_IdList64_free(ptrList2);
392  GWEN_IdList64_free(ptrList1);
393 
394  return 0;
395 }
396 
397 
398 
400 {
401  GWEN_IDLIST64 *ptrList1;
402  GWEN_IDLIST64 *ptrList2;
403  int i;
404 
405  ptrList1=GWEN_IdList64_newWithSteps(256);
406 
407  for (i=0; i<2048; i++) {
408  int64_t rv;
409 
410  rv=GWEN_IdList64_AddId(ptrList1, (uint64_t) i+1);
411  if (rv<0) {
413  "Error on GWEN_IdList64_AddId(%d): %s (%d)",
414  i, GWEN_Error_SimpleToString((int)rv), (int)rv);
415  return rv;
416  }
417  if (rv!=(int64_t)i) {
418  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected index returned for entry %d: is %ld, should be %d ", i, (unsigned long) rv, i);
419  return GWEN_ERROR_INTERNAL;
420  }
421  }
422 
423  ptrList2=GWEN_IdList64_LazyCopy(ptrList1);
424 
425  for (i=0; i<8; i++) {
426  GWEN_IDTABLE64 *table;
427  int refCounter;
428 
429  table=GWEN_IdList64_GetTableAt(ptrList1, i);
430  refCounter=table->refCount;
431  if (refCounter!=1) {
432  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 1", i, refCounter);
433  return GWEN_ERROR_INTERNAL;
434  }
435  }
436 
437  GWEN_IdList64_free(ptrList1);
438 
439  for (i=0; i<8; i++) {
440  GWEN_IDTABLE64 *table;
441  int refCounter;
442 
443  table=GWEN_IdList64_GetTableAt(ptrList2, i);
444  refCounter=table->refCount;
445  if (refCounter!=1) {
446  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table (list2) %d: is %d, should be 1 ", i, refCounter);
447  return GWEN_ERROR_INTERNAL;
448  }
449  }
450 
451  GWEN_IdList64_free(ptrList2);
452 
453  return 0;
454 }
455 
456 
457 
459 {
460  GWEN_IDLIST64 *ptrList1;
461  GWEN_IDLIST64 *ptrList2;
462  int i;
463  int64_t iEntry;
464 
465  ptrList1=GWEN_IdList64_newWithSteps(256);
466 
467  for (i=0; i<2048; i++) {
468  int64_t rv;
469 
470  rv=GWEN_IdList64_AddId(ptrList1, (uint64_t) i+1);
471  if (rv<0) {
473  "Error on GWEN_IdList64_AddId(%d): %s (%d)",
474  i, GWEN_Error_SimpleToString((int)rv), (int)rv);
475  return rv;
476  }
477  if (rv!=(int64_t)i) {
478  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected index returned for entry %d: is %ld, should be %d ", i, (unsigned long) rv, i);
479  return GWEN_ERROR_INTERNAL;
480  }
481  }
482 
483  for (i=0; i<8; i++) {
484  GWEN_IDTABLE64 *table;
485  int refCounter;
486 
487  table=GWEN_IdList64_GetTableAt(ptrList1, i);
488  refCounter=table->refCount;
489  if (refCounter!=1) {
490  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 1", i, refCounter);
491  return GWEN_ERROR_INTERNAL;
492  }
493  }
494 
495  ptrList2=GWEN_IdList64_LazyCopy(ptrList1);
496 
497  for (i=0; i<8; i++) {
498  GWEN_IDTABLE64 *table;
499  int refCounter;
500 
501  table=GWEN_IdList64_GetTableAt(ptrList2, i);
502  refCounter=table->refCount;
503  if (refCounter!=1) {
504  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 1 ", i, refCounter);
505  return GWEN_ERROR_INTERNAL;
506  }
507  }
508 
509  for (i=0; i<8; i++) {
510  GWEN_IDTABLE64 *table1;
511  GWEN_IDTABLE64 *table2;
512 
513  table1=GWEN_IdList64_GetTableAt(ptrList1, i);
514  table2=GWEN_IdList64_GetTableAt(ptrList2, i);
515  if (table1!=table2) {
516  DBG_ERROR(GWEN_LOGDOMAIN, "Table at position %d should be equal but isn't", i);
517  return GWEN_ERROR_INTERNAL;
518  }
519  }
520 
521 
522  iEntry=GWEN_IdList64_AddId(ptrList2, (uint64_t) 2048);
523  if (iEntry<0) {
525  "Error on GWEN_IdList64_AddId(%d): %s (%d)",
526  i, GWEN_Error_SimpleToString((int)iEntry), (int)iEntry);
527  return (int)iEntry;
528  }
529  if (iEntry!=(int64_t)2048) {
530  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected index returned for entry %d: is %ld, should be 2048", i, (unsigned long) iEntry);
531  return GWEN_ERROR_INTERNAL;
532  }
533 
534 
535  if (GWEN_IdList64_GetIdAt(ptrList1, 2048)>0) {
536  DBG_ERROR(GWEN_LOGDOMAIN, "Entry 2048 exists in list1 when it should not");
537  return GWEN_ERROR_INTERNAL;
538  }
539 
540  iEntry=GWEN_IdList64_GetIdAt(ptrList2, 2049);
541  if (iEntry>0) {
542  DBG_ERROR(GWEN_LOGDOMAIN, "Entry 2049 exists in list2 when it should not (%ld)", (long int) iEntry);
543  return GWEN_ERROR_INTERNAL;
544  }
545 
546 
547  for (i=0; i<8; i++) {
548  GWEN_IDTABLE64 *table;
549  int refCounter;
550 
551  table=GWEN_IdList64_GetTableAt(ptrList1, i);
552  refCounter=table->refCount;
553  if (refCounter!=2) {
554  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 2 ", i, refCounter);
555  return GWEN_ERROR_INTERNAL;
556  }
557  }
558 
559  for (i=0; i<8; i++) {
560  GWEN_IDTABLE64 *table;
561  int refCounter;
562 
563  table=GWEN_IdList64_GetTableAt(ptrList2, i);
564  refCounter=table->refCount;
565  if (refCounter!=2) {
566  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 2 ", i, refCounter);
567  return GWEN_ERROR_INTERNAL;
568  }
569  }
570 
571  for (i=8; i<9; i++) {
572  GWEN_IDTABLE64 *table;
573  int refCounter;
574 
575  table=GWEN_IdList64_GetTableAt(ptrList2, i);
576  refCounter=table->refCount;
577  if (refCounter!=1) {
578  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 1 ", i, refCounter);
579  return GWEN_ERROR_INTERNAL;
580  }
581  }
582 
583  return 0;
584 }
585 
586 
587 
589 {
590  GWEN_IDLIST64 *ptrList1;
591  GWEN_IDLIST64 *ptrList2;
592  int i;
593 
594  ptrList1=GWEN_IdList64_newWithSteps(256);
595 
596  for (i=0; i<2048; i++) {
597  int64_t rv;
598 
599  rv=GWEN_IdList64_AddId(ptrList1, (uint64_t) i+1);
600  if (rv<0) {
602  "Error on GWEN_IdList64_AddId(%d): %s (%d)",
603  i, GWEN_Error_SimpleToString((int)rv), (int)rv);
604  return rv;
605  }
606  if (rv!=(int64_t)i) {
607  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected index returned for entry %d: is %ld, should be %d ", i, (unsigned long) rv, i);
608  return GWEN_ERROR_INTERNAL;
609  }
610  }
611 
612  ptrList2=GWEN_IdList64_LazyCopy(ptrList1);
613 
614  for (i=2048; i<4096; i++) {
615  int64_t rv;
616 
617  rv=GWEN_IdList64_AddId(ptrList2, (uint64_t) i+1);
618  if (rv<0) {
620  "Error on GWEN_IdList64_AddId(%d): %s (%d)",
621  i, GWEN_Error_SimpleToString((int)rv), (int)rv);
622  return rv;
623  }
624  if (rv!=(int64_t)i) {
625  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected index returned for entry %d: is %ld, should be %d ", i, (unsigned long) rv, i);
626  return GWEN_ERROR_INTERNAL;
627  }
628  }
629 
630 
631  for (i=0; i<2048; i++) {
632  int64_t entry;
633 
634  entry=GWEN_IdList64_GetIdAt(ptrList1, i);
635  if (entry<0) {
637  "Error on GWEN_IdList64_GetIdAt(%d, list1): %s (%d)",
638  i, GWEN_Error_SimpleToString(entry), (int)entry);
639  return entry;
640  }
641  if (entry != (int64_t)(i+1)) {
642  DBG_ERROR(GWEN_LOGDOMAIN, "Non-matching entry at index %d: is %ld, should be %d ", i, (unsigned long) entry, i);
643  return GWEN_ERROR_INTERNAL;
644  }
645  }
646 
647  if (GWEN_IdList64_GetIdAt(ptrList1, 2048)>0) {
648  DBG_ERROR(GWEN_LOGDOMAIN, "Entry 2048 exists in list1 when it should not");
649  return GWEN_ERROR_INTERNAL;
650  }
651 
652  for (i=0; i<4096; i++) {
653  int64_t entry;
654 
655  entry=GWEN_IdList64_GetIdAt(ptrList2, i);
656  if (entry<0) {
658  "Error on GWEN_IdList64_GetIdAt(%d, list2): %s (%d)",
659  i, GWEN_Error_SimpleToString(entry), (int)entry);
660  return entry;
661  }
662  if (entry != (int64_t)(i+1)) {
663  DBG_ERROR(GWEN_LOGDOMAIN, "Non-matching entry at index %d: is %ld, should be %d ", i, (unsigned long) entry, i);
664  return GWEN_ERROR_INTERNAL;
665  }
666  }
667 
668  if (GWEN_IdList64_GetIdAt(ptrList1, 4096)>=0) {
669  DBG_ERROR(GWEN_LOGDOMAIN, "Entry 4096 exists in list2 when it should not");
670  return GWEN_ERROR_INTERNAL;
671  }
672 
673 
674  for (i=0; i<8; i++) {
675  GWEN_IDTABLE64 *table;
676  int refCounter;
677 
678  table=GWEN_IdList64_GetTableAt(ptrList1, i);
679  refCounter=table->refCount;
680  if (refCounter!=2) {
681  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 2 ", i, refCounter);
682  return GWEN_ERROR_INTERNAL;
683  }
684  }
685 
686  for (i=0; i<8; i++) {
687  GWEN_IDTABLE64 *table;
688  int refCounter;
689 
690  table=GWEN_IdList64_GetTableAt(ptrList2, i);
691  refCounter=table->refCount;
692  if (refCounter!=2) {
693  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 2 ", i, refCounter);
694  return GWEN_ERROR_INTERNAL;
695  }
696  }
697 
698  for (i=8; i<16; i++) {
699  GWEN_IDTABLE64 *table;
700  int refCounter;
701 
702  table=GWEN_IdList64_GetTableAt(ptrList2, i);
703  refCounter=table->refCount;
704  if (refCounter!=1) {
705  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 1 ", i, refCounter);
706  return GWEN_ERROR_INTERNAL;
707  }
708  }
709 
710 
711  GWEN_IdList64_free(ptrList1);
712 
713  for (i=0; i<(2048/256); i++) {
714  GWEN_IDTABLE64 *table;
715  int refCounter;
716 
717  table=GWEN_IdList64_GetTableAt(ptrList2, i);
718  refCounter=table->refCount;
719  if (refCounter!=1) {
720  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table (list2) %d: is %d, should be 1 ", i, refCounter);
721  return GWEN_ERROR_INTERNAL;
722  }
723  }
724 
725  return 0;
726 }
727 
728 
729 
731 {
732  GWEN_IDLIST64 *ptrList1;
733  GWEN_IDLIST64 *ptrList2;
734  int i;
735  int rv;
736 
737  ptrList1=GWEN_IdList64_newWithSteps(256);
738 
739  for (i=0; i<2047; i++) {
740  int64_t rv;
741 
742  rv=GWEN_IdList64_AddId(ptrList1, (uint64_t) i+1);
743  if (rv<0) {
745  "Error on GWEN_IdList64_AddId(%d): %s (%d)",
746  i, GWEN_Error_SimpleToString((int)rv), (int)rv);
747  return rv;
748  }
749  if (rv!=(int64_t)i) {
750  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected index returned for entry %d: is %ld, should be %d ", i, (unsigned long) rv, i);
751  return GWEN_ERROR_INTERNAL;
752  }
753  }
754 
755  for (i=0; i<8; i++) {
756  GWEN_IDTABLE64 *table;
757  int refCounter;
758 
759  table=GWEN_IdList64_GetTableAt(ptrList1, i);
760  refCounter=table->refCount;
761  if (refCounter!=1) {
762  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 1", i, refCounter);
763  return GWEN_ERROR_INTERNAL;
764  }
765  }
766 
767  ptrList2=GWEN_IdList64_LazyCopy(ptrList1);
768 
769  rv=GWEN_IdList64_AddId(ptrList2, (uint64_t) 2047);
770  if (rv<0) {
772  "Error on GWEN_IdList64_AddId(%d): %s (%d)",
773  i, GWEN_Error_SimpleToString((int)rv), (int)rv);
774  return rv;
775  }
776  if (rv!=(int64_t)2047) {
777  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected index returned for entry %d: is %ld, should be 2047", i, (unsigned long) rv);
778  return GWEN_ERROR_INTERNAL;
779  }
780 
781  if (GWEN_IdList64_GetTableAt(ptrList2, 8)) {
782  DBG_ERROR(GWEN_LOGDOMAIN, "Table 8 exists when it should not");
783  return GWEN_ERROR_INTERNAL;
784  }
785 
786 
787  if (GWEN_IdList64_GetIdAt(ptrList2, 2049)>0) {
788  DBG_ERROR(GWEN_LOGDOMAIN, "Entry 2049 exists in list2 when it should not");
789  return GWEN_ERROR_INTERNAL;
790  }
791 
792 
793  for (i=0; i<8; i++) {
794  GWEN_IDTABLE64 *table;
795  int refCounter;
796 
797  table=GWEN_IdList64_GetTableAt(ptrList1, i);
798  refCounter=table->refCount;
799  if (refCounter!=2) {
800  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 2 ", i, refCounter);
801  return GWEN_ERROR_INTERNAL;
802  }
803  }
804 
805  for (i=0; i<8; i++) {
806  GWEN_IDTABLE64 *table;
807  int refCounter;
808 
809  table=GWEN_IdList64_GetTableAt(ptrList2, i);
810  refCounter=table->refCount;
811  if (refCounter!=2) {
812  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 2 ", i, refCounter);
813  return GWEN_ERROR_INTERNAL;
814  }
815  }
816 
817  for (i=8; i<8; i++) {
818  GWEN_IDTABLE64 *table;
819  int refCounter;
820 
821  table=GWEN_IdList64_GetTableAt(ptrList2, i);
822  refCounter=table->refCount;
823  if (refCounter!=1) {
824  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table %d: is %d, should be 1 ", i, refCounter);
825  return GWEN_ERROR_INTERNAL;
826  }
827  }
828 
829  return 0;
830 }
831 
832 
833 
835 {
836  GWEN_IDLIST64 *ptrList1;
837  GWEN_IDLIST64 *ptrList2;
838  int i;
839 
840  ptrList1=GWEN_IdList64_newWithSteps(256);
841 
842  for (i=0; i<2048; i++) {
843  int64_t rv;
844 
845  rv=GWEN_IdList64_AddId(ptrList1, (uint64_t) i+1);
846  if (rv<0) {
848  "Error on GWEN_IdList64_AddId(%d): %s (%d)",
849  i, GWEN_Error_SimpleToString((int)rv), (int)rv);
850  return rv;
851  }
852  if (rv!=(int64_t)i) {
853  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected index returned for entry %d: is %ld, should be %d ", i, (unsigned long) rv, i);
854  return GWEN_ERROR_INTERNAL;
855  }
856  }
857 
858  ptrList2=GWEN_IdList64_dup(ptrList1);
859 
860  for (i=0; i<2048; i++) {
861  int64_t entry;
862 
863  entry=GWEN_IdList64_GetIdAt(ptrList1, i);
864  if (entry<0) {
866  "Error on GWEN_IdList64_GetIdAt(%d, list1): %s (%d)",
867  i, GWEN_Error_SimpleToString(entry), (int)entry);
868  return entry;
869  }
870  if (entry != (int64_t)(i+1)) {
871  DBG_ERROR(GWEN_LOGDOMAIN, "Non-matching entry at index %d: is %ld, should be %d ", i, (unsigned long) entry, i);
872  return GWEN_ERROR_INTERNAL;
873  }
874  }
875 
876  for (i=0; i<2048; i++) {
877  int64_t entry;
878 
879  entry=GWEN_IdList64_GetIdAt(ptrList2, i);
880  if (entry<0) {
882  "Error on GWEN_IdList64_GetIdAt(%d, list2): %s (%d)",
883  i, GWEN_Error_SimpleToString(entry), (int)entry);
884  return entry;
885  }
886  if (entry != (int64_t)(i+1)) {
887  DBG_ERROR(GWEN_LOGDOMAIN, "Non-matching entry at index %d: is %ld, should be %d ", i, (unsigned long) entry, i);
888  return GWEN_ERROR_INTERNAL;
889  }
890  }
891 
892 
893  for (i=0; i<8; i++) {
894  GWEN_IDTABLE64 *table;
895  int refCounter;
896 
897  table=GWEN_IdList64_GetTableAt(ptrList1, i);
898  refCounter=table->refCount;
899  if (refCounter!=1) {
900  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table (list1) %d: is %d, should be 1 ", i, refCounter);
901  return GWEN_ERROR_INTERNAL;
902  }
903  }
904 
905  for (i=0; i<8; i++) {
906  GWEN_IDTABLE64 *table;
907  int refCounter;
908 
909  table=GWEN_IdList64_GetTableAt(ptrList2, i);
910  refCounter=table->refCount;
911  if (refCounter!=1) {
912  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected reference counter in table (list2) %d: is %d, should be 1 ", i, refCounter);
913  return GWEN_ERROR_INTERNAL;
914  }
915  }
916 
917  GWEN_IdList64_free(ptrList2);
918  GWEN_IdList64_free(ptrList1);
919 
920  return 0;
921 }
922 
923 
924 
926 {
927  GWEN_IDLIST64 *ptrList1;
928  GWEN_IDLIST64 *ptrList2;
929  int i;
930  int rv;
931 
932  ptrList1=GWEN_IdList64_newWithSteps(256);
933 
934  for (i=0; i<2048; i++) {
935  int64_t rv;
936 
937  rv=GWEN_IdList64_AddId(ptrList1, (uint64_t) i+1);
938  if (rv<0) {
940  "Error on GWEN_IdList64_AddId(%d): %s (%d)",
941  i, GWEN_Error_SimpleToString((int)rv), (int)rv);
942  return rv;
943  }
944  if (rv!=(int64_t)i) {
945  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected index returned for entry %d: is %ld, should be %d ", i, (unsigned long) rv, i);
946  return GWEN_ERROR_INTERNAL;
947  }
948  }
949 
950  ptrList2=GWEN_IdList64_dup(ptrList1);
951 
952 
953  rv=_compareList1AgainstList2(ptrList1, ptrList2);
954  if (rv<0) {
955  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", (int) rv);
956  GWEN_IdList64_free(ptrList2);
957  GWEN_IdList64_free(ptrList1);
958  return (int) rv;
959  }
960 
961  GWEN_IdList64_free(ptrList2);
962  GWEN_IdList64_free(ptrList1);
963 
964  return 0;
965 }
966 
967 
968 
969 
970 
971 int _compareList1AgainstList2(GWEN_IDLIST64 *idList1, GWEN_IDLIST64 *idList2)
972 {
973  GWEN_IDLIST64_ITERATOR *iter1;
974  GWEN_IDLIST64_ITERATOR *iter2;
975  uint64_t id1;
976  uint64_t id2;
977  uint64_t index=0;
978 
979  iter1=GWEN_IdList64_Iterator_new(idList1);
980  iter2=GWEN_IdList64_Iterator_new(idList2);
983  while (id1>0 && id2>0) {
984  if (id1 != id2) {
985  fprintf(stderr, "Tables differ at position %lu (%lu != %lu)\n",
986  (unsigned long) index,
987  (unsigned long) id1,
988  (unsigned long) id2);
991  return GWEN_ERROR_GENERIC;
992  }
993  index++;
996  }
998  fprintf(stderr, "NUmber of elements in lists differs\n");
1001  return GWEN_ERROR_GENERIC;
1002  }
1005 
1006  return 0;
1007 }
1008 
1009 
1010 
1011 #else
1012 
1014 {
1015  DBG_ERROR(GWEN_LOGDOMAIN, "Gwenhywfar was compiled without test code enabled.");
1016  return GWEN_ERROR_GENERIC;
1017 }
1018 
1019 #endif
1020 
int test10(int argc, char **argv)
int test5(int argc, char **argv)
int test3(int argc, char **argv)
Definition: libtest.m:204
GWEN_IDLIST64_ITERATOR * GWEN_IdList64_Iterator_new(GWEN_IDLIST64 *idl)
Definition: idlist64.c:728
GWEN_IDLIST64 * GWEN_IdList64_dup(const GWEN_IDLIST64 *oldList)
Definition: idlist64.c:111
#define NULL
Definition: binreloc.c:300
int test6(int argc, char **argv)
#define GWEN_LOGDOMAIN
Definition: logger.h:35
int test9(int argc, char **argv)
int test2(int argc, char **argv)
int GWEN_IdList64_Sort(GWEN_IDLIST64 *idl)
Definition: idlist64.c:674
void GWEN_IdList64_free(GWEN_IDLIST64 *idl)
Definition: idlist64.c:153
static GWEN_IDTABLE64 * GWEN_IdList64_GetTableAt(const GWEN_IDLIST64 *tl, uint64_t idx)
Definition: idlist64.c:204
void GWEN_IdList64_Iterator_free(GWEN_IDLIST64_ITERATOR *it)
Definition: idlist64.c:743
GWEN_IDLIST64 * GWEN_IdList64_newWithSteps(uint64_t steps)
Definition: idlist64.c:95
GWEN_TEST_MODULE * GWEN_Test_Module_AddTest(GWEN_TEST_MODULE *st, const char *tName, GWEN_TEST_MODULE_TEST_FN fn, const char *tDescr)
Definition: testmodule.c:424
int test8(int argc, char **argv)
GWEN_SIMPLEPTRLIST GWEN_IDLIST64
Definition: idlist64.h:43
int64_t GWEN_IdList64_GetIdAt(const GWEN_IDLIST64 *idl, uint64_t idx)
Definition: idlist64.c:244
uint64_t GWEN_IdList64_Iterator_GetFirstId(GWEN_IDLIST64_ITERATOR *it)
Definition: idlist64.c:753
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
struct GWEN_TEST_MODULE GWEN_TEST_MODULE
Definition: testmodule.h:65
#define GWEN_ERROR_GENERIC
Definition: error.h:62
int test1()
Definition: libtest.m:63
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
int test7(int argc, char **argv)
int GWEN_IdList64_AddTests(GWEN_TEST_MODULE *mod)
Definition: idlist64-t.c:1013
GWEN_IDLIST64 * GWEN_IdList64_LazyCopy(GWEN_IDLIST64 *oldList)
Definition: idlist64.c:197
int test4(int argc, char **argv)
int test11(int argc, char **argv)
uint64_t GWEN_IdList64_Iterator_GetNextId(GWEN_IDLIST64_ITERATOR *it)
Definition: idlist64.c:760
#define GWEN_ERROR_INTERNAL
Definition: error.h:125
GWEN_TEST_MODULE * GWEN_Test_Module_AddModule(GWEN_TEST_MODULE *st, const char *tName, const char *tDescr)
Definition: testmodule.c:440
struct GWEN_IDLIST64_ITERATOR GWEN_IDLIST64_ITERATOR
Definition: idlist64.h:44
int64_t GWEN_IdList64_AddId(GWEN_IDLIST64 *idl, uint64_t entry)
Definition: idlist64.c:335
#define GWEN_UNUSED
int GWEN_IdList64_ReverseSort(GWEN_IDLIST64 *idl)
Definition: idlist64.c:681
const char * GWEN_Error_SimpleToString(int i)
Returns a (very) short string describing the given GWEN error code, or "Unknown error" for unknown co...
Definition: error.c:95