1 static int testarray_from_lit(void);
2 static int testarray_append_lit(void);
3 static int testarray_prepend_lit(void);
5 static void testLits(void) {
6 testing(array_from_lit);
7 ok1(testarray_from_lit());
9 testing(testarray_append_lit);
10 ok1(testarray_append_lit());
12 testing(testarray_prepend_lit);
13 ok1(testarray_prepend_lit());
16 static int testarray_from_lit(void) {
17 #ifndef ARRAY_USE_TALLOC
18 array_char a = array_new();
20 array_char a = array_new(NULL);
22 size_t testsPassed = 0;
27 array_from_lit(a, @str);
29 if (len != sizeof(@str)-1)
35 if (strcmp(a.item, @str))
38 #ifndef ARRAY_USE_TALLOC
48 return testsPassed == @amount;
56 static int testarray_append_lit(void) {
57 #ifndef ARRAY_USE_TALLOC
58 array_char a = array_new();
59 array(testLits_string) strings = array_new();
61 array_char a = array_new(NULL);
62 array(testLits_string) strings = array_new(NULL);
64 size_t testsPassed = 0;
66 testLits_string append;
71 append.size = sizeof(@str)-1;
73 array_append_lit(a, @str);
74 if (a.size != oldSize+append.size)
80 if (memcmp(a.item+oldSize, @str, a.size-oldSize))
82 append.item = strdup(@str);
83 array_append(strings, append);
87 if (strings.size != @amount)
90 if (a.size-offs < i->size)
92 if (memcmp(a.item+offs, i->item, i->size))
104 array_for(i, strings, free(i->item));
106 return testsPassed == @amount+1;
109 static int testarray_prepend_lit(void) {
110 #ifndef ARRAY_USE_TALLOC
111 array_char a = array_new();
112 array(testLits_string) strings = array_new();
114 array_char a = array_new(NULL);
115 array(testLits_string) strings = array_new(NULL);
117 size_t testsPassed = 0;
119 testLits_string append;
124 append.size = sizeof(@str)-1;
126 array_prepend_lit(a, @str);
127 if (a.size != oldSize+append.size)
129 if (a.size > a.alloc)
133 if (memcmp(a.item, @str, a.size-oldSize))
135 append.item = strdup(@str);
136 array_append(strings, append);
143 if (strings.size != @amount)
145 array_for(i, strings,
149 if (memcmp(a.item+offs, i->item, i->size))
158 array_for(i, strings, free(i->item));
160 return testsPassed == @amount+1;