feat: initial commit, basic arena
This commit is contained in:
46
test/niarena_test_alloc_buffer.c
Normal file
46
test/niarena_test_alloc_buffer.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int call_count = 0;
|
||||
void *
|
||||
bad_malloc(size_t sz)
|
||||
{
|
||||
call_count++;
|
||||
if(call_count != 2) {
|
||||
return malloc(sz);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#define NIARENA_MALLOC(sz) bad_malloc(sz)
|
||||
|
||||
void
|
||||
mock_free(void *p)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
#define NIARENA_FREE(p) mock_free(p)
|
||||
|
||||
#define N_INTS_TEST 4
|
||||
#define NIARENA_ARENA_SIZE (N_INTS_TEST * sizeof(int))
|
||||
#define NIARENA_IMPLEMENTATION
|
||||
|
||||
#include "../niarena.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
niarena_test_malloc_fail_buffer()
|
||||
{
|
||||
NIArena *arena = niarena_new();
|
||||
assert(arena == NULL);
|
||||
const char *err = niarena_get_error();
|
||||
assert(strcmp(err, "niarena_new: out of memory allocating buffer") == 0);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
niarena_test_malloc_fail_buffer();
|
||||
printf("== TESTS SUCCESSFUL ==\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user