GCC Code Coverage Report


Directory: src/gate/
File: src/gate/encode/tests/gateencode_test/test_hashes.c
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 31 31 100.0%
Functions: 5 5 100.0%
Branches: 4 8 50.0%

Line Branch Exec Source
1 #include "gate/tests.h"
2 #include "test_hashes.h"
3 #include "gate/encode/md5hash.h"
4 #include "gate/encode/sha1hash.h"
5 #include "gate/encode/sha256hash.h"
6 #include "gate/encode/crchash.h"
7 #include "gate/streams.h"
8
9 1 GATE_TEST_FUNCTION(test_md5)
10 {
11 gate_md5_t md5;
12 gate_md5_result_t md5result;
13 static char const md5_empty[] = { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e };
14
15 1 GATE_TEST_UNIT_BEGIN(test_md5);
16
17 1 gate_md5_init(&md5);
18 1 gate_md5_finish(&md5, &md5result);
19 1 GATE_TEST_CHECK_EQUAL(sizeof(md5result.hash), sizeof(md5_empty));
20
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_mem_compare(&md5result.hash[0], &md5_empty[0], sizeof(md5_empty)), 0);
21
22 1 GATE_TEST_UNIT_END;
23 }
24
25 1 GATE_TEST_FUNCTION(test_sha1)
26 {
27 gate_sha1_t sha1;
28 gate_sha1_result_t sha1result;
29 static char const sha1_empty[] = { 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09 };
30
31 1 GATE_TEST_UNIT_BEGIN(test_sha1);
32
33 1 gate_sha1_init(&sha1);
34 1 gate_sha1_finish(&sha1, &sha1result);
35 1 GATE_TEST_CHECK_EQUAL(sizeof(sha1result.hash), sizeof(sha1_empty));
36
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_mem_compare(&sha1result.hash[0], &sha1_empty[0], sizeof(sha1_empty)), 0);
37
38 1 GATE_TEST_UNIT_END;
39 }
40
41 1 GATE_TEST_FUNCTION(test_sha256)
42 {
43 gate_sha256_t sha256;
44 gate_sha256_result_t sha256result;
45 static char const sha256_empty[] = { 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55 };
46
47 1 GATE_TEST_UNIT_BEGIN(test_sha256);
48
49 1 gate_sha256_init(&sha256);
50 1 gate_sha256_finish(&sha256, &sha256result);
51 1 GATE_TEST_CHECK_EQUAL(sizeof(sha256result.hash), sizeof(sha256_empty));
52
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_mem_compare(&sha256result.hash[0], &sha256_empty[0], sizeof(sha256_empty)), 0);
53
54 1 GATE_TEST_UNIT_END;
55 }
56
57 1 GATE_TEST_FUNCTION(test_crc16)
58 {
59 1 GATE_TEST_UNIT_BEGIN(test_crc16);
60
61
62 1 GATE_TEST_UNIT_END;
63 }
64
65 1 GATE_TEST_FUNCTION(test_crc32)
66 {
67 gate_crc32_t crc32;
68 gate_crc32_result_t crc32result;
69 static char const crc32_empty[] = { 0x00, 0x00, 0x00, 0x00 };
70 1 GATE_TEST_UNIT_BEGIN(test_crc32);
71
72 1 gate_crc32_init(&crc32);
73 1 gate_crc32_finish(&crc32, &crc32result);
74 1 GATE_TEST_CHECK_EQUAL(sizeof(crc32result.hash), sizeof(crc32_empty));
75
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 GATE_TEST_CHECK_EQUAL(gate_mem_compare(&crc32result.hash[0], &crc32_empty[0], sizeof(crc32_empty)), 0);
76
77 1 GATE_TEST_UNIT_END;
78 }
79