/* libmisc/tests/test_endian.c - Tests for <libmisc/endian.h> * * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> * SPDX-License-Identifier: AGPL-3.0-or-later */ #include <string.h> /* for memcmp() */ #include <libmisc/endian.h> #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; }