Skip to content

Commit

Permalink
Merge pull request #95 from fgont/add-unit-tests
Browse files Browse the repository at this point in the history
Add addiotional unit tests
  • Loading branch information
fgont authored Oct 16, 2024
2 parents 5cc75c1 + 5046769 commit d35c1de
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/tests_libipv6.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include "../tools/libipv6.h"

void test_ether_ntop(void);
void test_ether_pton(void);
void test_is_service_port(void);

int main(void){
test_ether_ntop();
test_ether_pton();
test_is_service_port();
exit(EXIT_SUCCESS);
}

void test_ether_ntop(void){
struct ether_addr ether;
unsigned int i;
char plinkaddr[ETHER_ADDR_PLEN];

for (i=0; i < 6; i++) {
ether.a[i]= i+1;
}

assert(ether_ntop(&ether, plinkaddr, 5) != TRUE);
assert(ether_ntop(&ether, plinkaddr, sizeof(plinkaddr)) == TRUE);
assert(Strnlen(plinkaddr, 18) == 17);
assert(strncmp(plinkaddr, "01:02:03:04:05:06", 18) == 0);
return;
}

void test_ether_pton(void){
struct ether_addr ether;
char *linkaddr= "01:02:03:04:05:06";
unsigned int i;

assert(ether_pton(linkaddr, &ether, 5) != TRUE);
assert(ether_pton(linkaddr, &ether, sizeof(ether)));

for (i=0; i < 6; i++) {
assert(ether.a[i] == (i+1));
}

return;
}

void test_is_service_port(void){
assert(is_service_port(443));
assert(is_service_port(1000) == FALSE);
Expand Down

0 comments on commit d35c1de

Please sign in to comment.