Merge branch 'rj/cygwin-has-dev-tty'
[git/gitster.git] / t / unit-tests / t-mem-pool.c
blobfe500c704b3c8a75c6eab8713c84cd27f60e84a9
1 #include "test-lib.h"
2 #include "mem-pool.h"
4 static void setup_static(void (*f)(struct mem_pool *), size_t block_alloc)
6 struct mem_pool pool = { .block_alloc = block_alloc };
7 f(&pool);
8 mem_pool_discard(&pool, 0);
11 static void t_calloc_100(struct mem_pool *pool)
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);
23 int cmd_main(int argc UNUSED, const char **argv UNUSED)
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");
30 return test_done();