]> git.ipfire.org Git - thirdparty/git.git/blob - t/unit-tests/t-mem-pool.c
Merge branch 'rs/use-xstrncmpz'
[thirdparty/git.git] / t / unit-tests / t-mem-pool.c
1 #include "test-lib.h"
2 #include "mem-pool.h"
3
4 static void setup_static(void (*f)(struct mem_pool *), size_t block_alloc)
5 {
6 struct mem_pool pool = { .block_alloc = block_alloc };
7 f(&pool);
8 mem_pool_discard(&pool, 0);
9 }
10
11 static void t_calloc_100(struct mem_pool *pool)
12 {
13 size_t size = 100;
14 char *buffer = mem_pool_calloc(pool, 1, size);
15 for (size_t i = 0; i < size; i++)
16 check_int(buffer[i], ==, 0);
17 if (!check(pool->mp_block != NULL))
18 return;
19 check(pool->mp_block->next_free != NULL);
20 check(pool->mp_block->end != NULL);
21 }
22
23 int cmd_main(int argc, const char **argv)
24 {
25 TEST(setup_static(t_calloc_100, 1024 * 1024),
26 "mem_pool_calloc returns 100 zeroed bytes with big block");
27 TEST(setup_static(t_calloc_100, 1),
28 "mem_pool_calloc returns 100 zeroed bytes with tiny block");
29
30 return test_done();
31 }