Added other tests
This commit is contained in:
12
tests/05_arena_new.c
Normal file
12
tests/05_arena_new.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#define DEBUG
|
||||
#include <stdlib.h>
|
||||
#include "../include/mem.h"
|
||||
|
||||
int main(void){
|
||||
size_t nbytes = 20;
|
||||
Arena a = ARENA(0,nbytes);
|
||||
ASSERTED(a.beg != NULL);
|
||||
ASSERTED( mem_is_zero(a.beg, nbytes));
|
||||
FREE(a.beg);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
12
tests/06_arena_nozero.c
Normal file
12
tests/06_arena_nozero.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#define DEBUG
|
||||
#include <stdlib.h>
|
||||
#include "../include/mem.h"
|
||||
|
||||
int main(void){
|
||||
size_t nbytes = 20;
|
||||
Arena a = ARENA(NOZERO,nbytes);
|
||||
ASSERTED(a.beg != NULL);
|
||||
ASSERTED( !mem_is_zero(a.beg, nbytes));
|
||||
FREE(a.beg);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
11
tests/07_arena_softfail.c
Normal file
11
tests/07_arena_softfail.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#define DEBUG
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "../include/mem.h"
|
||||
|
||||
int main(void){
|
||||
size_t nbytes = MEM_GB(1024);
|
||||
Arena a = ARENA(SOFT_FAIL, nbytes);
|
||||
ASSERTED(a.beg == NULL);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
28
tests/08_arena_exception.c
Normal file
28
tests/08_arena_exception.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#define DEBUG
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "../include/mem.h"
|
||||
|
||||
int main(void){
|
||||
size_t nbytes = MEM_GB(1024);
|
||||
Arena a;
|
||||
TRY {
|
||||
a = ARENA(0,nbytes); /* try 1GB */
|
||||
if (!a.beg)
|
||||
RAISE(OOM);
|
||||
free(a.beg);
|
||||
}
|
||||
EXCEPT(OOM) {
|
||||
/* handle memory failure gracefully */
|
||||
fprintf(stderr, "Caught: %s\n", OOM.reason);
|
||||
return EXIT_SUCCESS; /* requested behavior */
|
||||
}
|
||||
FINALLY {
|
||||
/* cleanup if needed, runs always */
|
||||
if (a.beg) free(a.beg);
|
||||
}
|
||||
END_TRY;
|
||||
|
||||
return EXIT_FAILURE; /* shouldn't reach here for this example */
|
||||
}
|
||||
Reference in New Issue
Block a user