GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tests/gatecore_test/test_blobs.c
Date: 2026-03-20 22:56:14
Exec Total Coverage
Lines: 55 55 100.0%
Functions: 1 1 100.0%
Branches: 40 80 50.0%

Line Branch Exec Source
1 #include "gate/tests.h"
2 #include "test_blobs.h"
3 #include "gate/blobs.h"
4
5 static char static_bytes[] = "Hello World";
6
7 1 GATE_TEST_FUNCTION(test_blobs)
8 {
9 gate_blob_t blob;
10 gate_blob_t blob_copy;
11 gate_blob_t blob_clone;
12 gate_blob_t blob_dup;
13
14 1 GATE_TEST_UNIT_BEGIN(test_blobs);
15
16 /* test empty: */
17
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_create_empty(&blob), &blob);
18
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(blob.buffer, NULL);
19
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_data(&blob), NULL);
20
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob), 0U);
21 1 gate_blob_release(&blob);
22
23 /* test static: */
24
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_create_static(&blob, static_bytes, sizeof(static_bytes)), &blob);
25
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(blob.buffer, NULL);
26
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_data(&blob), &static_bytes[0]);
27
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob), sizeof(static_bytes));
28
1/2
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_mem_compare(gate_blob_data(&blob), &static_bytes[0], gate_blob_length(&blob)), 0);
29 1 gate_blob_release(&blob);
30
31 /* test duplicate: */
32
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_create_static(&blob, static_bytes, sizeof(static_bytes)), &blob);
33
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_create_duplicate(&blob_dup, &blob), &blob_dup);
34
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_EQUAL(blob_dup.buffer, NULL);
35
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_data(&blob_dup), &static_bytes[0]);
36
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob_dup), sizeof(static_bytes));
37 1 gate_blob_release(&blob_dup);
38 1 gate_blob_release(&blob);
39
40 /* test dynamic: */
41
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_create(&blob, static_bytes, sizeof(static_bytes)), &blob);
42
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 GATE_TEST_CHECK_NOT_EQUAL(blob.buffer, NULL);
43
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_NOT_EQUAL(gate_blob_data(&blob), &static_bytes[0]);
44
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob), sizeof(static_bytes));
45
1/2
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_mem_compare(gate_blob_data(&blob), &static_bytes[0], gate_blob_length(&blob)), 0);
46 1 gate_blob_release(&blob);
47
48 /* test copy: */
49
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_create(&blob, static_bytes, sizeof(static_bytes)), &blob);
50
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_create_copy(&blob_copy, &blob), &blob_copy);
51
1/2
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob), gate_blob_length(&blob_copy));
52
1/2
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_mem_compare(gate_blob_data(&blob), gate_blob_data(&blob_copy), gate_blob_length(&blob)), 0);
53 1 gate_blob_release(&blob_copy);
54 1 gate_blob_release(&blob);
55
56 /* test ref-clone: */
57
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_create(&blob, static_bytes, sizeof(static_bytes)), &blob);
58
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_create_clone(&blob_clone, &blob), &blob_clone);
59
1/2
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob), gate_blob_length(&blob_clone));
60
1/2
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_data(&blob), gate_blob_data(&blob_clone));
61 1 gate_blob_release(&blob_clone);
62 1 gate_blob_release(&blob);
63
64 /* test subset: */
65
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_create_static(&blob, static_bytes, sizeof(static_bytes)), &blob);
66
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_create_subset(&blob_dup, &blob, 0, sizeof(static_bytes) / 2), &blob_dup);
67
1/2
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_data(&blob), gate_blob_data(&blob_dup));
68
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_length(&blob_dup), sizeof(static_bytes) / 2);
69 1 gate_blob_release(&blob_dup);
70 1 gate_blob_release(&blob);
71
72 /* test set/get */
73
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_create(&blob, static_bytes, sizeof(static_bytes)), &blob);
74
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_OK(gate_blob_set_byte(&blob, 0, 'A'));
75
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_OK(gate_blob_set_byte(&blob, 1, 'B'));
76
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_OK(gate_blob_set_byte(&blob, 2, 'C'));
77
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_get_byte(&blob, 0), 'A');
78
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_get_byte(&blob, 1), 'B');
79
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_blob_get_byte(&blob, 2), 'C');
80
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_RESULT(gate_blob_set_byte(&blob, sizeof(static_bytes), 'X'), GATE_RESULT_OUTOFBOUNDS);
81
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_RESULT(gate_blob_get_byte(&blob, sizeof(static_bytes)), 0);
82 1 gate_blob_release(&blob);
83
84 1 GATE_TEST_UNIT_END;
85 }
86