| 271 CX_TEST_ASSERT(buf.size == 8); |
271 CX_TEST_ASSERT(buf.size == 8); |
| 272 CX_TEST_ASSERT(memcmp(buf.space, "Testing", 8) == 0); |
272 CX_TEST_ASSERT(memcmp(buf.space, "Testing", 8) == 0); |
| 273 CX_TEST_ASSERT(talloc.alloc_total == 0); |
273 CX_TEST_ASSERT(talloc.alloc_total == 0); |
| 274 cxBufferDestroy(&buf); |
274 cxBufferDestroy(&buf); |
| 275 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
275 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
| |
276 } |
| |
277 cx_testing_allocator_destroy(&talloc); |
| |
278 } |
| |
279 |
| |
280 CX_TEST(test_buffer_reserve) { |
| |
281 CxTestingAllocator talloc; |
| |
282 cx_testing_allocator_init(&talloc); |
| |
283 CxAllocator *alloc = &talloc.base; |
| |
284 CX_TEST_DO { |
| |
285 CxBuffer buf; |
| |
286 char space[16] = "Testing"; |
| |
287 cxBufferInit(&buf, space, 16, alloc, CX_BUFFER_COPY_ON_EXTEND); |
| |
288 buf.size = 8; |
| |
289 CX_TEST_ASSERT(buf.capacity == 16); |
| |
290 CX_TEST_ASSERT(talloc.alloc_total == 0); |
| |
291 // reserve to grow |
| |
292 cxBufferReserve(&buf, 32); |
| |
293 CX_TEST_ASSERT(buf.capacity == 32); |
| |
294 CX_TEST_ASSERT(buf.size == 8); |
| |
295 CX_TEST_ASSERT(memcmp(buf.space, "Testing", 8) == 0); |
| |
296 CX_TEST_ASSERT(talloc.alloc_total > 0); |
| |
297 CX_TEST_ASSERT((buf.flags & CX_BUFFER_COPY_ON_EXTEND) == 0); |
| |
298 // reserve to shrink |
| |
299 buf.size = 24; |
| |
300 cxBufferReserve(&buf, 16); |
| |
301 CX_TEST_ASSERT(buf.capacity == 16); |
| |
302 CX_TEST_ASSERT(buf.size == 16); |
| |
303 CX_TEST_ASSERT(memcmp(buf.space, "Testing", 8) == 0); |
| |
304 // reserve to free |
| |
305 cxBufferReserve(&buf, 0); |
| |
306 CX_TEST_ASSERT(buf.capacity == 0); |
| |
307 CX_TEST_ASSERT(buf.size == 0); |
| |
308 CX_TEST_ASSERT(buf.space == NULL); |
| |
309 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
| |
310 cxBufferDestroy(&buf); |
| 276 } |
311 } |
| 277 cx_testing_allocator_destroy(&talloc); |
312 cx_testing_allocator_destroy(&talloc); |
| 278 } |
313 } |
| 279 |
314 |
| 280 CX_TEST(test_buffer_clear) { |
315 CX_TEST(test_buffer_clear) { |
| 1767 cx_test_register(suite, test_buffer_minimum_capacity_sufficient); |
1802 cx_test_register(suite, test_buffer_minimum_capacity_sufficient); |
| 1768 cx_test_register(suite, test_buffer_minimum_capacity_extend); |
1803 cx_test_register(suite, test_buffer_minimum_capacity_extend); |
| 1769 cx_test_register(suite, test_buffer_shrink); |
1804 cx_test_register(suite, test_buffer_shrink); |
| 1770 cx_test_register(suite, test_buffer_shrink_copy_on_write); |
1805 cx_test_register(suite, test_buffer_shrink_copy_on_write); |
| 1771 cx_test_register(suite, test_buffer_shrink_copy_on_extend); |
1806 cx_test_register(suite, test_buffer_shrink_copy_on_extend); |
| |
1807 cx_test_register(suite, test_buffer_reserve); |
| 1772 cx_test_register(suite, test_buffer_clear); |
1808 cx_test_register(suite, test_buffer_clear); |
| 1773 cx_test_register(suite, test_buffer_clear_copy_on_write); |
1809 cx_test_register(suite, test_buffer_clear_copy_on_write); |
| 1774 cx_test_register(suite, test_buffer_reset); |
1810 cx_test_register(suite, test_buffer_reset); |
| 1775 cx_test_register(suite, test_buffer_seek_set_zero); |
1811 cx_test_register(suite, test_buffer_seek_set_zero); |
| 1776 cx_test_register(suite, test_buffer_seek_set_valid); |
1812 cx_test_register(suite, test_buffer_seek_set_valid); |