MCPcopy Create free account
hub / github.com/codr7/hacktical-c / malloc1_tests

Function malloc1_tests

malloc1/tests.c:4–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include "malloc1.h"
3
4void malloc1_tests() {
5 assert(hc_align(0, 4) == 0);
6 assert(hc_align(1, 4) == 4);
7 assert(hc_align(3, 4) == 4);
8 assert(hc_align(4, 4) == 4);
9 assert(hc_align(5, 4) == 8);
10
11 const int s = 1024;
12 struct hc_bump_alloc a;
13 hc_bump_alloc_init(&a, &hc_malloc_default, s);
14 hc_defer(hc_bump_alloc_deinit(&a));
15 assert(a.size == s);
16 assert(a.offset == 0);
17
18 int *ip = hc_acquire(&a.malloc, sizeof(int));
19 *ip = 42;
20
21 long *lp = hc_acquire(&a.malloc, sizeof(long));
22 *lp = 42L;
23
24 assert(a.offset >= sizeof(int) + sizeof(long));
25 bool caught = false;
26
27 void on_catch(struct hc_error *e) {
28 assert(hc_streq(e->message, HC_NO_MEMORY) == 0);
29 caught = true;
30 }
31
32 hc_catch(on_catch) {
33 hc_acquire(&a.malloc, s);
34 assert(false);
35 }
36
37 assert(caught);
38}

Callers 1

mainFunction · 0.85

Calls 2

hc_bump_alloc_initFunction · 0.85
hc_bump_alloc_deinitFunction · 0.85

Tested by

no test coverage detected