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