test_network

This commit is contained in:
timerix 2022-08-12 22:27:34 +06:00
parent 4ec2984b5a
commit d96bebaf45
3 changed files with 31 additions and 0 deletions

View File

@ -8,6 +8,7 @@ void test_all(){
test_hash_functions();
test_hashtable();
test_dtsod();
test_network();
printf("\e[96m--------------------------------------\e[0m\n");
}

29
tests/test_network.c Normal file
View File

@ -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);
}));
}

View File

@ -13,6 +13,7 @@ void test_autoarr();
void test_hash_functions();
void test_hashtable();
void test_dtsod();
void test_network();
#if __cplusplus
}