Made lib/base conversion functions const where possible

This commit is contained in:
2024-04-28 17:41:00 +05:30
parent cce3259b56
commit 06a883d538
3 changed files with 28 additions and 26 deletions

View File

@@ -18,17 +18,18 @@
void testing_lib_bytes_to_hword(void)
{
byte_t tests[][4] = {{0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF},
{1},
{0, 0, 0, 0b10000000},
{0x89, 0xab, 0xcd, 0xef}};
const byte_t tests[][4] = {{0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF},
{1},
{0, 0, 0, 0b10000000},
{0x89, 0xab, 0xcd, 0xef}};
hword_t expected[ARR_SIZE(tests)] = {0, HWORD_MAX, 1, 1 << 31, 0xefcdab89};
const hword_t expected[ARR_SIZE(tests)] = {0, HWORD_MAX, 1, 1 << 31,
0xefcdab89};
for (size_t i = 0; i < ARR_SIZE(tests); ++i)
{
hword_t got = convert_bytes_to_hword(tests[i]);
const hword_t got = convert_bytes_to_hword(tests[i]);
if (expected[i] != got)
{
FAIL(__func__, "[%lu] -> Expected 0x%x got 0x%x\n", i, expected[i], got);
@@ -40,18 +41,18 @@ void testing_lib_bytes_to_hword(void)
void testing_lib_bytes_to_word(void)
{
byte_t tests[][8] = {{0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0x01, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0b10000000},
{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}};
const byte_t tests[][8] = {{0, 0, 0, 0},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0x01, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0b10000000},
{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}};
word_t expected[ARR_SIZE(tests)] = {0, WORD_MAX, 1, 1LU << 63,
const word_t expected[ARR_SIZE(tests)] = {0, WORD_MAX, 1, 1LU << 63,
0xefcdab8967452301};
0xefcdab8967452301};
for (size_t i = 0; i < ARR_SIZE(tests); ++i)
{
word_t got = convert_bytes_to_word(tests[i]);
const word_t got = convert_bytes_to_word(tests[i]);
if (expected[i] != got)
{
FAIL(__func__, "[%lu] -> Expected 0x%lx got 0x%lx\n", i, expected[i],