From d96bebaf45b6264216100cc7f498e214fcf7054a Mon Sep 17 00:00:00 2001 From: timerix Date: Fri, 12 Aug 2022 22:27:34 +0600 Subject: [PATCH] test_network --- tests/main.cpp | 1 + tests/test_network.c | 29 +++++++++++++++++++++++++++++ tests/tests.h | 1 + 3 files changed, 31 insertions(+) create mode 100644 tests/test_network.c diff --git a/tests/main.cpp b/tests/main.cpp index 10f54f3..b68a42d 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -8,6 +8,7 @@ void test_all(){ test_hash_functions(); test_hashtable(); test_dtsod(); + test_network(); printf("\e[96m--------------------------------------\e[0m\n"); } diff --git a/tests/test_network.c b/tests/test_network.c new file mode 100644 index 0000000..8ef2b33 --- /dev/null +++ b/tests/test_network.c @@ -0,0 +1,29 @@ +#include "tests.h" +#include "../src/Network/network.h" + +void __test_knIPV4Address_fromStr(char* addrStr, uint8 a, uint8 b, uint8 c, uint8 d){ + tryLast(knIPV4Address_fromStr(addrStr), maybeAddr){ + knIPV4Address addr; + addr.address=(uint32)maybeAddr.value.UInt64; + printf("\e[94mknIPV4Address_fromStr(\e[96m%s\e[94m) -> ", addrStr); + if(maybeAddr.value.UInt64!=knIPV4Address_fromBytes(a,b,c,d).address){ + printf("\e[91m%u.%u.%u.%u\n", + (uint8)addr.bytes[0], (uint8)addr.bytes[1], (uint8)addr.bytes[2], (uint8)addr.bytes[3]); + throw("knIPV4Address_fromStr returned wrong value"); + } + else printf("\e[92m%u.%u.%u.%u\n", + (uint8)addr.bytes[0], (uint8)addr.bytes[1], (uint8)addr.bytes[2], (uint8)addr.bytes[3]); + } +} +#define test_knIPV4Address_fromStr(a,b,c,d) __test_knIPV4Address_fromStr(#a"."#b"."#c"."#d, a,b,c,d) + +void test_network(){ + optime(__func__,1,({ + printf("\e[96m------------[test_network]------------\n"); + if(sizeof(knIPV4Endpoint)!=sizeof(knPort)+sizeof(knIPV4Address)) + throw(ERR_WRONGTYPE); + test_knIPV4Address_fromStr(127,0,0,1); + test_knIPV4Address_fromStr(34,255,45,0); + test_knIPV4Address_fromStr(3,3,3,128); + })); +} \ No newline at end of file diff --git a/tests/tests.h b/tests/tests.h index d19ea17..012a7e2 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -13,6 +13,7 @@ void test_autoarr(); void test_hash_functions(); void test_hashtable(); void test_dtsod(); +void test_network(); #if __cplusplus }