Blob


1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <arraylist.h>
6 void test_basic(void)
7 {
8 int *p;
9 ARRAYLIST(int) list;
10 ARRAYLIST_INIT(list, 2);
12 #define dump() do {\
13 printf("(%d items)\n", list.len); \
14 ARRAYLIST_FOREACH(p, list) \
15 printf("[%d] %d\n", ARRAYLIST_IDX(p, list), *p); \
16 printf("\n"); \
17 } while(0)
19 dump();
21 ARRAYLIST_ADD(p, list);
22 *p = 100;
23 dump();
25 ARRAYLIST_ADD(p, list);
26 *p = 101;
27 dump();
29 ARRAYLIST_ADD(p, list);
30 *p = 102;
31 dump();
33 #define insert_test(AT) do {\
34 printf("insert at [" #AT "]:\n"); \
35 ARRAYLIST_INSERT(p, list, AT); \
36 *p = AT; \
37 dump(); \
38 } while(0)
40 insert_test(list.len - 1);
41 insert_test(1);
42 insert_test(0);
43 insert_test(6);
44 insert_test(123);
45 insert_test(-42);
47 printf("clear:\n");
48 ARRAYLIST_CLEAR(list);
49 dump();
51 ARRAYLIST_FREE(list);
52 }
54 int main(void)
55 {
56 test_basic();
57 }