|
1 | 1 | #include "include/test.h" |
2 | 2 | #include "../../src/include/util/hb_narray.h" |
| 3 | +#include <alloca.h> |
3 | 4 |
|
4 | 5 | TEST(test_hb_narray_init) |
5 | 6 | hb_narray_T array; |
| 7 | + hb_allocator_T allocator; |
| 8 | + hb_allocator_init(&allocator, HB_ALLOCATOR_MALLOC); |
6 | 9 |
|
7 | | - ck_assert(hb_narray_init(&array, sizeof(uint64_t), 1024)); |
| 10 | + ck_assert(hb_narray_init(&array, sizeof(uint64_t), 1024, &allocator)); |
8 | 11 |
|
9 | 12 | ck_assert_int_eq(array.item_size, sizeof(uint64_t)); |
10 | 13 | ck_assert_int_eq(array.capacity, 1024); |
|
17 | 20 | TEST(test_hb_narray_pointer_init) |
18 | 21 | hb_narray_T array; |
19 | 22 |
|
20 | | - ck_assert(hb_narray_pointer_init(&array, 1024)); |
| 23 | + hb_allocator_T allocator; |
| 24 | + hb_allocator_init(&allocator, HB_ALLOCATOR_MALLOC); |
| 25 | + |
| 26 | + ck_assert(hb_narray_pointer_init(&array, 1024, &allocator)); |
21 | 27 |
|
22 | 28 | ck_assert_int_eq(array.item_size, sizeof(void *)); |
23 | 29 | ck_assert_int_eq(array.capacity, 1024); |
|
30 | 36 | TEST(test_hb_narray_append) |
31 | 37 | hb_narray_T array; |
32 | 38 |
|
33 | | - ck_assert(hb_narray_init(&array, sizeof(uint64_t), 2)); |
| 39 | + hb_allocator_T allocator; |
| 40 | + hb_allocator_init(&allocator, HB_ALLOCATOR_MALLOC); |
| 41 | + |
| 42 | + ck_assert(hb_narray_init(&array, sizeof(uint64_t), 2, &allocator)); |
34 | 43 |
|
35 | 44 | uint64_t number = 1; |
36 | 45 | ck_assert(hb_narray_append(&array, &number)); |
|
55 | 64 |
|
56 | 65 | TEST(test_hb_narray_first_last) |
57 | 66 | hb_narray_T array; |
| 67 | + hb_allocator_T allocator; |
| 68 | + hb_allocator_init(&allocator, HB_ALLOCATOR_MALLOC); |
58 | 69 |
|
59 | | - hb_narray_init(&array, sizeof(uint64_t), 2); |
| 70 | + hb_narray_init(&array, sizeof(uint64_t), 2, &allocator); |
60 | 71 |
|
61 | 72 | ck_assert_ptr_null(hb_narray_first(&array)); |
62 | 73 | ck_assert_ptr_null(hb_narray_last(&array)); |
|
78 | 89 |
|
79 | 90 | TEST(test_hb_narray_stack_behavior) |
80 | 91 | hb_narray_T array; |
| 92 | + hb_allocator_T allocator; |
| 93 | + hb_allocator_init(&allocator, HB_ALLOCATOR_MALLOC); |
81 | 94 |
|
82 | | - hb_narray_init(&array, sizeof(uint64_t), 2); |
| 95 | + hb_narray_init(&array, sizeof(uint64_t), 2, &allocator); |
83 | 96 |
|
84 | 97 | for(uint64_t i = 0; i < 4; i++) { |
85 | 98 | hb_narray_push(&array, &i); |
|
110 | 123 |
|
111 | 124 | TEST(test_hb_narray_remove) |
112 | 125 | hb_narray_T array; |
| 126 | + hb_allocator_T allocator; |
| 127 | + hb_allocator_init(&allocator, HB_ALLOCATOR_MALLOC); |
113 | 128 |
|
114 | | - hb_narray_init(&array, sizeof(uint64_t), 2); |
| 129 | + hb_narray_init(&array, sizeof(uint64_t), 2, &allocator); |
115 | 130 |
|
116 | 131 | for(uint64_t i = 0; i < 4; i++) { |
117 | 132 | hb_narray_push(&array, &i); |
|
141 | 156 | // Test hb_narray_size with NULL safety |
142 | 157 | TEST(test_hb_narray_size) |
143 | 158 | ck_assert_int_eq(hb_narray_size(NULL), 0); |
| 159 | + hb_allocator_T allocator; |
| 160 | + hb_allocator_init(&allocator, HB_ALLOCATOR_MALLOC); |
144 | 161 |
|
145 | 162 | hb_narray_T array; |
146 | | - hb_narray_init(&array, sizeof(uint64_t), 5); |
| 163 | + hb_narray_init(&array, sizeof(uint64_t), 5, &allocator); |
147 | 164 | ck_assert_int_eq(hb_narray_size(&array), 0); |
148 | 165 |
|
149 | 166 | uint64_t item1 = 42, item2 = 99; |
|
158 | 175 |
|
159 | 176 | TEST(test_hb_narray_init_returns_bool) |
160 | 177 | hb_narray_T array; |
| 178 | + hb_allocator_T allocator; |
| 179 | + hb_allocator_init(&allocator, HB_ALLOCATOR_MALLOC); |
161 | 180 |
|
162 | | - ck_assert(hb_narray_init(&array, sizeof(uint64_t), 4)); |
| 181 | + ck_assert(hb_narray_init(&array, sizeof(uint64_t), 4, &allocator)); |
163 | 182 | ck_assert_ptr_nonnull(array.items); |
164 | 183 | ck_assert_int_eq(array.size, 0); |
165 | 184 | ck_assert_int_eq(array.capacity, 4); |
|
169 | 188 |
|
170 | 189 | TEST(test_hb_narray_append_returns_bool) |
171 | 190 | hb_narray_T array; |
| 191 | + hb_allocator_T allocator; |
| 192 | + hb_allocator_init(&allocator, HB_ALLOCATOR_MALLOC); |
172 | 193 |
|
173 | | - ck_assert(hb_narray_init(&array, sizeof(uint64_t), 2)); |
| 194 | + ck_assert(hb_narray_init(&array, sizeof(uint64_t), 2, &allocator)); |
174 | 195 |
|
175 | 196 | uint64_t number = 42; |
176 | 197 | ck_assert(hb_narray_append(&array, &number)); |
|
0 commit comments