summaryrefslogtreecommitdiff
path: root/test/allocator.c
blob: 96ef6dfc4cb269e0151ea7277996d0f900af2195 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "dged/allocator.h"

#include "assert.h"
#include "test.h"

void test_frame_allocator(void) {
  struct frame_allocator fa = frame_allocator_create(128);

  ASSERT(fa.capacity == 128,
         "Expected frame allocator to be created with specified capacity");

  void *bytes = frame_allocator_alloc(&fa, 128);
  ASSERT(
      bytes != NULL,
      "Expected to be able to allocate <capacity> bytes from frame allocator");

  void *bytes_again = frame_allocator_alloc(&fa, 128);
  ASSERT(bytes_again == NULL,
         "Expected to not be able to allocate <capacity> bytes "
         "from frame allocator a second time");

  frame_allocator_clear(&fa);
  void *bytes_after_clear = frame_allocator_alloc(&fa, 128);
  ASSERT(bytes_after_clear != NULL,
         "Expected to be able to allocate <capacity> bytes from frame "
         "allocator again after clearing it");

  frame_allocator_destroy(&fa);
}

void run_allocator_tests(void) { run_test(test_frame_allocator); }