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