@brief Validates `sz_memory_allocator_t` and related construction utilities. */
| 207 | |
| 208 | /** @brief Validates `sz_memory_allocator_t` and related construction utilities. */ |
| 209 | void test_memory_allocator_struct() { |
| 210 | // Our behavior for `malloc(0)` is to return a NULL pointer, |
| 211 | // while the standard is implementation-defined. |
| 212 | { |
| 213 | sz_memory_allocator_t alloc; |
| 214 | sz_memory_allocator_init_default(&alloc); |
| 215 | assert(alloc.allocate(0, alloc.handle) == nullptr); |
| 216 | } |
| 217 | |
| 218 | // Non-NULL allocation |
| 219 | { |
| 220 | sz_memory_allocator_t alloc; |
| 221 | sz_memory_allocator_init_default(&alloc); |
| 222 | void *byte = alloc.allocate(1, alloc.handle); |
| 223 | assert(byte != nullptr); |
| 224 | alloc.free(byte, 1, alloc.handle); |
| 225 | } |
| 226 | |
| 227 | // Use a fixed buffer |
| 228 | { |
| 229 | char buffer[1024]; |
| 230 | sz_memory_allocator_t alloc; |
| 231 | sz_memory_allocator_init_fixed(&alloc, buffer, sizeof(buffer)); |
| 232 | void *byte = alloc.allocate(1, alloc.handle); |
| 233 | assert(byte != nullptr); |
| 234 | alloc.free(byte, 1, alloc.handle); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /** @brief Validates `sz_byteset_t` and related construction utilities. */ |
| 239 | void test_byteset_struct() { |
no test coverage detected
searching dependent graphs…