GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tests/gatecore_test/test_arrays.c
Date: 2026-12-03 19:36:00
Exec Total Coverage
Lines: 88 88 100.0%
Functions: 5 5 100.0%
Branches: 36 72 50.0%

Line Branch Exec Source
1 #include "gate/tests.h"
2 #include "test_arrays.h"
3 #include "gate/arrays.h"
4 #include "gate/comparers.h"
5
6 1 GATE_TEST_FUNCTION(test_arraylists)
7 {
8 static int const i1 = 1;
9 static int const i2 = 2;
10 static int const i3 = 3;
11 1 gate_arraylist_t al = GATE_INIT_EMPTY;
12 1 gate_arraylist_t al2 = GATE_INIT_EMPTY;
13 gate_result_t result;
14 1 void* ptr_item = NULL;
15 int dummy;
16
17
18 1 GATE_TEST_UNIT_BEGIN(test_arraylists);
19
20 1 al = gate_arraylist_create(sizeof(int), NULL, 0, NULL, NULL);
21
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_REQUIRE(gate_arraylist_is_null(al) == false);
22
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_arraylist_length(al), 0);
23
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_arraylist_itemsize(al), sizeof(int));
24
25
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_arraylist_create_item(al, &dummy, sizeof(dummy)), sizeof(dummy));
26 1 gate_arraylist_destroy_item(al, &dummy);
27
28 1 ptr_item = gate_arraylist_add(al, &i1);
29
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_item != NULL);
30
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i1);
31
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_arraylist_length(al), 1);
32
33 1 ptr_item = gate_arraylist_add(al, &i2);
34
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_item != NULL);
35
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i2);
36
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_arraylist_length(al), 2);
37
38 1 ptr_item = gate_arraylist_add(al, &i3);
39
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_item != NULL);
40
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i3);
41
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_arraylist_length(al), 3);
42
43 1 ptr_item = gate_arraylist_get(al, 0);
44
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_item != NULL);
45
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i1);
46
47 1 ptr_item = gate_arraylist_get(al, 1);
48
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_item != NULL);
49
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i2);
50
51 1 ptr_item = gate_arraylist_get(al, 2);
52
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_item != NULL);
53
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i3);
54
55
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_OK(gate_arraylist_remove(al, 1, 1));
56
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_arraylist_length(al), 2);
57
58 1 ptr_item = gate_arraylist_get(al, 0);
59
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_item != NULL);
60
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i1);
61
62 1 ptr_item = gate_arraylist_get(al, 1);
63
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_item != NULL);
64
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(*((int const*)ptr_item), i3);
65
66 1 result = gate_arraylist_copy_constructor(&al2, &al);
67
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_OK(result);
68
1/2
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_arraylist_length(al), gate_arraylist_length(al2));
69 1 gate_arraylist_destructor(&al2);
70
71 1 gate_arraylist_release(&al);
72
73 1 GATE_TEST_UNIT_END;
74 }
75
76
77 8 static gate_bool_t find_odd(void const* item, void* param)
78 {
79 8 gate_int16_t const* ptr = (gate_int16_t const*)item;
80 GATE_UNUSED_ARG(param);
81
82 8 return (*ptr % 2) == 1;
83 }
84
85 1 GATE_TEST_FUNCTION(test_arrayutils)
86 {
87 1 gate_int16_t iarr[] = { 8, 7, 6, 5, 4, 3, 2, 1 };
88 1 gate_size_t const iarr_sz = sizeof(iarr) / sizeof(iarr[0]);
89 1 gate_array_t arr = GATE_INIT_EMPTY;
90 1 gate_array_t* ptr_arr = NULL;
91 1 gate_array_t arrcopy = GATE_INIT_EMPTY;
92 gate_result_t result;
93 gate_size_t new_size;
94
95 1 GATE_TEST_UNIT_BEGIN(test_arrayutils);
96
97 1 ptr_arr = gate_array_create_static(&arr, iarr, sizeof(iarr[0]), iarr_sz);
98
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE(ptr_arr != NULL);
99
100 1 result = gate_array_copy_constructor(&arrcopy, ptr_arr);
101
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_REQUIRE_OK(result);
102
103
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_array_find(&arrcopy, gate_compare_int16, &iarr[1], 0), 1);
104
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_array_find(&arrcopy, gate_compare_int16, &iarr[1], 2), GATE_ARRAY_NPOS);
105
106 1 gate_array_sort(iarr, sizeof(iarr[0]), iarr_sz, &gate_compare_int16, NULL, NULL);
107 1 gate_array_sort_descending(iarr, sizeof(iarr[0]), iarr_sz, &gate_compare_int16, NULL, NULL);
108
109 1 gate_array_destructor(&arrcopy);
110
111 1 gate_array_release(&arr);
112
113 1 new_size = gate_array_remove_if(iarr, sizeof(iarr[0]), iarr_sz, &find_odd, NULL, NULL, NULL);
114
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(new_size, iarr_sz / 2);
115
116 1 GATE_TEST_UNIT_END;
117 }
118
119 1 GATE_TEST_FUNCTION(test_arrays)
120 {
121 1 gate_bool_t result = true;
122
123 1 result |= test_arraylists();
124 1 result |= test_arrayutils();
125
126 1 return result;
127 }
128
129 1 GATE_TEST_FUNCTION(test_slotlists)
130 {
131 1 gate_slotlist_t sl = GATE_INIT_EMPTY;
132 int value;
133 gate_slotlist_iterator_t iter;
134 1 int* ptr_value = NULL;
135
136 1 GATE_TEST_UNIT_BEGIN(test_slotlists);
137
138
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_slotlist_create(&sl, sizeof(int), NULL, NULL) != NULL);
139 1 value = 12;
140
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(gate_slotlist_add(&sl, &value) != NULL);
141
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_slotlist_length(&sl), 1);
142
143 1 gate_slotlist_first(&sl, &iter);
144 1 ptr_value = (int*)gate_slotlist_export(&sl, &iter);
145
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(ptr_value != NULL);
146 1 gate_mem_dealloc(ptr_value);
147
148 1 gate_slotlist_destroy(&sl);
149
150 1 GATE_TEST_UNIT_END;
151 }
152