pool.c 877 Bytes
Newer Older
1 2 3 4 5 6
#include "clar_libgit2.h"
#include "pool.h"
#include "git2/oid.h"

static char to_hex[] = "0123456789abcdef";

7
void test_core_pool__oid(void)
8 9
{
	git_pool p;
10
	char oid_hex[GIT_OID_SHA1_HEXSIZE];
11 12 13 14 15
	git_oid *oid;
	int i, j;

	memset(oid_hex, '0', sizeof(oid_hex));

16 17
	git_pool_init(&p, sizeof(git_oid));
	p.page_size = 4000;
18 19

	for (i = 1000; i < 10000; i++) {
20 21 22
		oid = git_pool_malloc(&p, 1);
		cl_assert(oid != NULL);

23 24
		for (j = 0; j < 8; j++)
			oid_hex[j] = to_hex[(i >> (4 * j)) & 0x0f];
25
		cl_git_pass(git_oid__fromstr(oid, oid_hex, GIT_OID_SHA1));
26 27
	}

28
#ifndef GIT_DEBUG_POOL
29
	/* with fixed page size, allocation must end up with these values */
30 31

# ifdef GIT_EXPERIMENTAL_SHA256
Edward Thomson committed
32
	cl_assert_equal_i(sizeof(void *) == 8 ? 90 : 82, git_pool__open_pages(&p));
33 34 35
# else
	cl_assert_equal_i(sizeof(void *) == 8 ? 55 : 45, git_pool__open_pages(&p));
# endif
36
#endif
37 38
	git_pool_clear(&p);
}