1 /* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
2
3 This program is free software: you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation, either version 3 of the License, or
6 (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <https://www.gnu.org/licenses/>.
15 */
16
17 #include <tap/basic.h>
18
19 #include "libknot/wire.h"
20
21 #define write_test(size, value, ...) { \
22 const uint8_t expect[] = { __VA_ARGS__ }; \
23 uint8_t wdata[sizeof(expect)] = { 0x00 }; \
24 knot_wire_write_u ## size(wdata, value); \
25 ok(memcmp(wdata, expect, sizeof(expect)) == 0, "%d-bit write", size); \
26 }
27
main(int argc,char * argv[])28 int main(int argc, char *argv[])
29 {
30 plan(8);
31
32 const uint8_t rdata[] = { 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
33
34 is_hex( 0x8899, knot_wire_read_u16(rdata), "16-bit read");
35 is_hex( 0x8899aabb, knot_wire_read_u32(rdata), "32-bit read");
36 is_hex( 0x8899aabbccdd, knot_wire_read_u48(rdata), "48-bit read");
37 is_hex(0x8899aabbccddeeff, knot_wire_read_u64(rdata), "64-bit read");
38
39 write_test(16, 0x1122, 0x11, 0x22);
40 write_test(32, 0x66778899, 0x66, 0x77, 0x88, 0x99);
41 write_test(48, 0xbbccdd778899, 0xbb, 0xcc, 0xdd, 0x77, 0x88, 0x99);
42 write_test(64, 0xbbccddee66778899, 0xbb, 0xcc, 0xdd, 0xee,
43 0x66, 0x77, 0x88, 0x99);
44
45 return 0;
46 }
47