min test
This commit is contained in:
22
tests/05_allocation.c
Normal file
22
tests/05_allocation.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#define DEBUG
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "../include/arena.h"
|
||||
#include "../include/mem.h"
|
||||
#include <string.h>
|
||||
|
||||
int main(void){
|
||||
size_t nbytes = 10;
|
||||
Arena a = ARENA(0,nbytes);
|
||||
assert(a.beg != NULL);
|
||||
assert( mem_is_zero(a.beg, nbytes));
|
||||
|
||||
char *ptr = ARENA_ALLOC(0, &a, nbytes,nbytes,1);
|
||||
assert(ptr != NULL);
|
||||
memcpy(ptr,"abcdefghij",nbytes);
|
||||
assert(memcmp(ptr, "abcdefghij", nbytes) == 0);
|
||||
|
||||
|
||||
free(ptr);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
24
tests/06_backing.c
Normal file
24
tests/06_backing.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#define DEBUG
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "../include/arena.h"
|
||||
#include "../include/mem.h"
|
||||
#include <string.h>
|
||||
|
||||
int main(void){
|
||||
const size_t nbytes = 10;
|
||||
char *buf[nbytes];
|
||||
memset(buf,0,nbytes);
|
||||
Arena a;
|
||||
ARENA_BACK(&a,buf,nbytes);
|
||||
assert(a.beg != NULL);
|
||||
assert( mem_is_zero(a.beg, nbytes));
|
||||
|
||||
char *ptr = ARENA_ALLOC(0, &a, nbytes,nbytes,1);
|
||||
assert(ptr != NULL);
|
||||
memcpy(ptr,"abcdefghij",nbytes);
|
||||
assert(memcmp(ptr, "abcdefghij", nbytes) == 0);
|
||||
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user