GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tests/gatecore_test/test_map.c
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 37 38 97.4%
Functions: 2 2 100.0%
Branches: 18 24 75.0%

Line Branch Exec Source
1 #include "test_math.h"
2
3 #include "gate/tests.h"
4 #include "gate/maps.h"
5 #include "gate/randomgen.h"
6
7
8 1001 static gate_bool_t map_is_consistent(gate_map_t* m)
9 {
10 1001 gate_map_iterator_t iter = gate_map_first(m);
11 1001 gate_size_t counter = 0;
12 gate_int16_t max_val;
13 gate_int16_t cur_val;
14
15
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1000 times.
1001 if (!gate_map_iterator_valid(iter))
16 {
17 /* map is empty */
18 1 return (gate_map_count(m) == 0);
19 }
20
21
22 1000 max_val = *(gate_int16_t const*)gate_map_iterator_key(iter);
23 1000 ++counter;
24
2/2
✓ Branch 3 taken 314515 times.
✓ Branch 4 taken 1000 times.
315515 for (iter = gate_map_iterator_next(iter); gate_map_iterator_valid(iter); iter = gate_map_iterator_next(iter))
25 {
26 314515 cur_val = *(gate_int16_t const*)gate_map_iterator_key(iter);
27
1/2
✓ Branch 0 taken 314515 times.
✗ Branch 1 not taken.
314515 if (cur_val > max_val)
28 {
29 /* correct: */
30 314515 max_val = cur_val;
31 314515 ++counter;
32 }
33 else
34 {
35 /* wrong */
36 return false;
37 }
38 }
39 1000 return (gate_map_count(m) == counter);
40 }
41
42
43 1 GATE_TEST_FUNCTION(test_maps)
44 {
45 gate_size_t ndx;
46 gate_map_t m;
47 gate_randomsession_t rnd;
48 gate_uint64_t num;
49 gate_uint16_t value;
50 gate_bool_t map_creation_succeeded;
51 gate_bool_t map_ok;
52 static gate_uint16_t const max_num = 500;
53
54 1 GATE_TEST_UNIT_BEGIN(test_maps);
55
56
57 do
58 {
59
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_OK(gate_randomgenerator_create(&rnd));
60
61
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_REQUIRE((NULL != gate_map_create(&m, &gate_compare_uint16, sizeof(gate_uint16_t),
62 NULL, NULL, sizeof(gate_uint16_t), NULL, NULL)));
63
64 1 map_creation_succeeded = true;
65
2/2
✓ Branch 0 taken 250000 times.
✓ Branch 1 taken 1 times.
250001 for (ndx = 0; ndx != 250000; ++ndx)
66 {
67 250000 map_creation_succeeded &= GATE_SUCCEEDED(gate_randomgenerator_get_num(&rnd, &num));
68
69 250000 value = (gate_uint16_t)(num % (gate_uint64_t)max_num);
70
71
2/2
✓ Branch 0 taken 125000 times.
✓ Branch 1 taken 125000 times.
250000 if (ndx % 2)
72 {
73 125000 map_creation_succeeded &= (NULL != gate_map_add(&m, &value, &value));
74 }
75 else
76 {
77 125000 gate_map_remove(&m, &value);
78 }
79 }
80
81
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(map_creation_succeeded);
82
83
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK(map_is_consistent(&m));
84
85 1 map_ok = true;
86
2/2
✓ Branch 0 taken 500 times.
✓ Branch 1 taken 1 times.
501 for (value = 0; value != max_num; ++value)
87 {
88 500 gate_map_add(&m, &value, &value);
89 500 map_ok &= map_is_consistent(&m);
90 }
91
2/2
✓ Branch 0 taken 500 times.
✓ Branch 1 taken 1 times.
501 for (value = 0; value != max_num; ++value)
92 {
93 500 gate_map_remove(&m, &value);
94 500 map_ok &= map_is_consistent(&m);
95 }
96
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK(map_ok);
97
98 1 gate_map_destroy(&m);
99 1 gate_randomgenerator_destroy(&rnd);
100
101 } while (0);
102 1 GATE_TEST_UNIT_END;
103 }
104
105