-
Notifications
You must be signed in to change notification settings - Fork 0
/
deallocator_test.c
53 lines (44 loc) · 1.42 KB
/
deallocator_test.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
#include "deallocator.h"
#include <stdio.h>
#include <criterion/criterion.h>
Test(deallocator_define, should_pass_some_example_tests)
{
DA_STRUCT(1000) da = {{1000, 0}, {0, }};
cr_assert(sizeof(da) >= sizeof(struct deallocator) + 1000 * sizeof(void *));
cr_assert_eq(da.head.capacity, 1000);
cr_assert_eq(da.head.size, 0);
}
Test(deallocator_init, should_pass_some_example_tests)
{
DA_STRUCT(1000) da;
deallocator_init(&da.head, 1000);
cr_assert_eq(da.head.capacity, 1000);
cr_assert_eq(da.head.size, 0);
}
Test(deallocator_cleanup, should_pass_some_example_tests)
{
DA_STRUCT(1000) da;
deallocator_init(&da.head, 1000);
da_c(&da, strdup("some string 1"));
da_c(&da, strdup("some string 2"));
da_c(&da, strdup("some string 3"));
da_c(&da, strdup("some string 4"));
da_c(&da, strdup("some string 5"));
da_c(&da, strdup("some string 6"));
da_c(&da, strdup("some string 7"));
da_c(&da, strdup("some string 8"));
da_c(&da, strdup("some string 9"));
deallocator_cleanup(&da.head);
cr_assert_eq(da.head.size, 0);
}
Test(deallocator_da_c, should_pass_some_example_tests)
{
DA_STRUCT(1000) da;
deallocator_init(&da.head, 1000);
char *string1 = strdup("some string");
cr_assert_eq(da_c(&da, string1), string1);
cr_assert_eq(da.head.size, 1);
cr_assert_eq(da.head.pointers[0], string1);
deallocator_cleanup(&da.head);
}
// vim: set sw=4 et: