-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-region.c
105 lines (85 loc) · 2.02 KB
/
check-region.c
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <stdlib.h>
#include <stdio.h>
#include "region.h"
#include "cut.h"
#define BUFFER_SIZE 1024
#define REG_HEADER_SIZE (sizeof(struct region_storage))
#define BLOB_HEADER_SIZE (sizeof(struct blob))
#define CAP (BUFFER_SIZE - REG_HEADER_SIZE)
#define MAX_BLOB (CAP - BLOB_HEADER_SIZE)
static char reg_storage[BUFFER_SIZE] = {};
static struct region reg = {};
void
__CUT_BRINGUP__void_region()
{
}
void
__CUT__void_region_constructor()
{
#define ID 7
region_init(®, ID, (region_storage) reg_storage, sizeof(reg_storage));
ASSERT(reg.id == ID, "");
ASSERT(reg.storage == (region_storage) reg_storage, "");
ASSERT(reg.free == reg.storage->blobs, "");
ASSERT(reg.top == reg_storage + sizeof(reg_storage), "");
ASSERT(reg.next == 0, "");
}
void
__CUT_TAKEDOWN__void_region()
{
}
void
__CUT_BRINGUP__empty_region()
{
region_init(®, 0, (region_storage) reg_storage, sizeof(reg_storage));
}
void
__CUT__empty_region_header_size()
{
ASSERT(REG_HEADER_SIZE == reg.storage->blobs - (char *) reg.storage, "");
}
void
__CUT__empty_region_should_have_space()
{
ASSERT(region_has_space_for_blob(®, MAX_BLOB), "should have space");
}
void
__CUT__empty_region_should_not_have_space()
{
ASSERT(!region_has_space_for_blob(®, MAX_BLOB + 1),
"should not have space");
}
void
__CUT__empty_region_allocate_max_blob()
{
ASSERT(region_allocate_blob(®, MAX_BLOB), "should have space");
}
void
__CUT__empty_region_allocate_max_blob_plus_one()
{
ASSERT(!region_allocate_blob(®, MAX_BLOB + 1), "should not have space");
}
void
__CUT_TAKEDOWN__empty_region()
{
}
void
__CUT_BRINGUP__full_region()
{
region_init(®, 0, (region_storage) reg_storage, sizeof(reg_storage));
region_allocate_blob(®, MAX_BLOB);
}
void
__CUT__full_region_should_have_no_space()
{
ASSERT(!region_has_space_for_blob(®, 0), "should not have space");
}
void
__CUT__full_region_allocate_blob()
{
ASSERT(!region_allocate_blob(®, 0), "should not have space");
}
void
__CUT_TAKEDOWN__full_region()
{
}