-
Notifications
You must be signed in to change notification settings - Fork 13
/
buffer.c
59 lines (46 loc) · 1.33 KB
/
buffer.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
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include <sys/time.h>
#include <setjmp.h>
#include <cmocka.h>
#include "../src/dynamic/buffer.h"
extern int debug_out_of_memory;
extern int debug_abort;
void core(__attribute__((unused)) void **state)
{
buffer b;
buffer_construct(&b);
assert_int_equal(buffer_size(&b), 0);
assert_int_equal(buffer_capacity(&b), 0);
buffer_resize(&b, 100);
assert_int_equal(buffer_size(&b), 100);
buffer_resize(&b, 0);
assert_int_equal(buffer_size(&b), 0);
buffer_reserve(&b, 0);
buffer_reserve(&b, 1024);
assert_int_equal(buffer_capacity(&b), 1024);
buffer_compact(&b);
buffer_compact(&b);
assert_int_equal(buffer_capacity(&b), 0);
buffer_insert(&b, 0, "last", 4);
buffer_insert(&b, 0, "first", 5);
buffer_insert(&b, buffer_size(&b), "", 1);
assert_string_equal(buffer_data(&b), "firstlast");
buffer_erase(&b, 5, 4);
assert_string_equal(buffer_data(&b), "first");
buffer_insert_fill(&b, 0, 5, "x", 1);
assert_string_equal(buffer_data(&b), "xxxxxfirst");
buffer_insert_fill(&b, buffer_size(&b), 5, "x", 1);
assert_string_equal(buffer_data(&b), "xxxxxfirst");
buffer_destruct(&b);
}
int main()
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(core)
};
return cmocka_run_group_tests(tests, NULL, NULL);
}