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