From 470a25323ca89ffa3b0b697aeddcf184d12a1382 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Mon, 23 Jan 2023 18:32:49 -0800 Subject: Update listpool's interface to be on par with mempool's. --- listpool/test/listpool_test.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'listpool/test/listpool_test.c') diff --git a/listpool/test/listpool_test.c b/listpool/test/listpool_test.c index cb54d00..7a7b0cf 100644 --- a/listpool/test/listpool_test.c +++ b/listpool/test/listpool_test.c @@ -137,6 +137,23 @@ TEST_CASE(listpool_traverse_full) { TEST_EQUAL(sum(&pool), (NUM_BLOCKS) * (NUM_BLOCKS + 1) / 2); } +// Get the ith (allocated) block. +TEST_CASE(listpool_get_block) { + test_pool pool; + listpool_make(&pool); + + for (int i = 0; i < NUM_BLOCKS; ++i) { + int* block = listpool_alloc(&pool); + TEST_TRUE(block != 0); + *block = i; + TEST_EQUAL(listpool_get_block_index(&pool, block), (size_t)i); + } + + for (int i = 0; i < NUM_BLOCKS; ++i) { + TEST_EQUAL(*listpool_get_block(&pool, i), i); + } +} + // Remove a value from the list. TEST_CASE(listpool_remove_value) { test_pool pool; -- cgit v1.2.3