From 5704de985cff1d40359ecd15211cece0fbe79067 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Fri, 15 Nov 2024 15:12:08 -0700 Subject: Add tests to libmisc --- libmisc/tests/test_endian.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 libmisc/tests/test_endian.c (limited to 'libmisc/tests/test_endian.c') diff --git a/libmisc/tests/test_endian.c b/libmisc/tests/test_endian.c new file mode 100644 index 0000000..d0b547c --- /dev/null +++ b/libmisc/tests/test_endian.c @@ -0,0 +1,32 @@ +/* libmisc/tests/test_endian.c - Tests for + * + * Copyright (C) 2024 Luke T. Shumaker + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include /* for memcmp() */ + +#include + +#include "test.h" + +int main() { + uint8_t act[12] = {0}; + uint16be_encode(&act[0], UINT16_C(0x1234)); + uint32be_encode(&act[2], UINT32_C(0x56789ABC)); + uint16le_encode(&act[6], UINT16_C(0x1234)); + uint32le_encode(&act[8], UINT32_C(0x56789ABC)); + + uint8_t exp[12] = { 0x12, 0x34, + 0x56, 0x78, 0x9A, 0xBC, + 0x34, 0x12, + 0xBC, 0x9A, 0x78, 0x56 }; + test_assert(memcmp(act, exp, 12) == 0); + + test_assert(uint16be_decode(&act[0]) == UINT16_C(0x1234)); + test_assert(uint32be_decode(&act[2]) == UINT32_C(0x56789ABC)); + test_assert(uint16le_decode(&act[6]) == UINT16_C(0x1234)); + test_assert(uint32le_decode(&act[8]) == UINT32_C(0x56789ABC)); + + return 0; +} -- cgit v1.2.3-2-g168b