From 69c6a41ffb878ef98c9378ed4b1634a404cfaa7f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 6 May 2024 02:53:35 +0200 Subject: Adding upstream version 2.7.6. Signed-off-by: Daniel Baumann --- tests/libknot/test_wire.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/libknot/test_wire.c (limited to 'tests/libknot/test_wire.c') diff --git a/tests/libknot/test_wire.c b/tests/libknot/test_wire.c new file mode 100644 index 0000000..70617f9 --- /dev/null +++ b/tests/libknot/test_wire.c @@ -0,0 +1,46 @@ +/* Copyright (C) 2018 CZ.NIC, z.s.p.o. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#include + +#include "libknot/wire.h" + +#define write_test(size, value, ...) { \ + const uint8_t expect[] = { __VA_ARGS__ }; \ + uint8_t wdata[sizeof(expect)] = { 0x00 }; \ + knot_wire_write_u ## size(wdata, value); \ + ok(memcmp(wdata, expect, sizeof(expect)) == 0, "%d-bit write", size); \ +} + +int main(int argc, char *argv[]) +{ + plan(8); + + const uint8_t rdata[] = { 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; + + is_hex( 0x8899, knot_wire_read_u16(rdata), "16-bit read"); + is_hex( 0x8899aabb, knot_wire_read_u32(rdata), "32-bit read"); + is_hex( 0x8899aabbccdd, knot_wire_read_u48(rdata), "48-bit read"); + is_hex(0x8899aabbccddeeff, knot_wire_read_u64(rdata), "64-bit read"); + + write_test(16, 0x1122, 0x11, 0x22); + write_test(32, 0x66778899, 0x66, 0x77, 0x88, 0x99); + write_test(48, 0xbbccdd778899, 0xbb, 0xcc, 0xdd, 0x77, 0x88, 0x99); + write_test(64, 0xbbccddee66778899, 0xbb, 0xcc, 0xdd, 0xee, + 0x66, 0x77, 0x88, 0x99); + + return 0; +} -- cgit v1.2.3