From: Lokesh Walase Date: Mon, 15 Jun 2015 05:35:04 +0000 (+0530) Subject: Changes for tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d9ba6c4775b6e22c46c29a119dcb80322229c59;p=thirdparty%2Fntp.git Changes for tests bk: 557e6408CQ2CNpUdCoQnmo4ZTu-m7g --- diff --git a/tests/libntp/c_sockaddrtest.h b/tests/libntp/c_sockaddrtest.h new file mode 100644 index 000000000..f5cd6b398 --- /dev/null +++ b/tests/libntp/c_sockaddrtest.h @@ -0,0 +1,49 @@ +#ifndef TESTS_SOCKADDRTEST_H +#define TESTS_SOCKADDRTEST_H + +#include "ntp.h" +#include "ntp_stdlib.h" + +sockaddr_u CreateSockaddr4(const char* address, unsigned int port) { + sockaddr_u s; + s.sa4.sin_family = AF_INET; + s.sa4.sin_addr.s_addr = inet_addr(address); + SET_PORT(&s, port); + + return s; +} + +int IsEqual(const sockaddr_u expected, const sockaddr_u actual) { + struct in_addr in; + struct in6_addr in6; + + if (expected.sa.sa_family != actual.sa.sa_family) { + return 1==2; + } + + if (actual.sa.sa_family == AF_INET) { // IPv4 + if (expected.sa4.sin_port == actual.sa4.sin_port && + memcmp(&expected.sa4.sin_addr, &actual.sa4.sin_addr, + sizeof( in )) == 0) { + return 1==1; + } else { + return 1==2; + } + } else if (actual.sa.sa_family == AF_INET6) { //IPv6 + if (expected.sa6.sin6_port == actual.sa6.sin6_port && + memcmp(&expected.sa6.sin6_addr, &actual.sa6.sin6_addr, + sizeof(in6)) == 0) { + return 1==1; + } else { + return 1==2; + } + } else { // Unknown family + return 1==2; + } +} + + +#endif // TESTS_SOCKADDRTEST_H + + + diff --git a/tests/libntp/netof.c b/tests/libntp/netof.c index 0774d2ccf..c6434448d 100644 --- a/tests/libntp/netof.c +++ b/tests/libntp/netof.c @@ -5,7 +5,7 @@ //#include "ntp.h" //#include "ntp_net.h" -#include "sockaddrtest.h" +#include "c_sockaddrtest.h" void test_ClassBAddress(void) { sockaddr_u input = CreateSockaddr4("172.16.2.1", NTP_PORT); diff --git a/tests/libntp/sockaddrtest.h b/tests/libntp/sockaddrtest.h index 97581f495..fd3e4af82 100644 --- a/tests/libntp/sockaddrtest.h +++ b/tests/libntp/sockaddrtest.h @@ -1,57 +1,6 @@ #ifndef TESTS_SOCKADDRTEST_H #define TESTS_SOCKADDRTEST_H -#include "ntp.h" -#include "ntp_stdlib.h" - -sockaddr_u CreateSockaddr4(const char* address, unsigned int port) { - sockaddr_u s; - s.sa4.sin_family = AF_INET; - s.sa4.sin_addr.s_addr = inet_addr(address); - SET_PORT(&s, port); - - return s; -} - -int IsEqual(const sockaddr_u expected, const sockaddr_u actual) { - struct in_addr in; - struct in6_addr in6; - - if (expected.sa.sa_family != actual.sa.sa_family) { - return 1==2; - } - - if (actual.sa.sa_family == AF_INET) { // IPv4 - if (expected.sa4.sin_port == actual.sa4.sin_port && - memcmp(&expected.sa4.sin_addr, &actual.sa4.sin_addr, - sizeof( in )) == 0) { - return 1==1; - } else { - return 1==2; - } - } else if (actual.sa.sa_family == AF_INET6) { //IPv6 - if (expected.sa6.sin6_port == actual.sa6.sin6_port && - memcmp(&expected.sa6.sin6_addr, &actual.sa6.sin6_addr, - sizeof(in6)) == 0) { - return 1==1; - } else { - return 1==2; - } - } else { // Unknown family - return 1==2; - } -} - - -#endif // TESTS_SOCKADDRTEST_H - - - - -/* -#ifndef TESTS_SOCKADDRTEST_H -#define TESTS_SOCKADDRTEST_H - #include "libntptest.h" extern "C" { @@ -108,4 +57,3 @@ protected: #endif // TESTS_SOCKADDRTEST_H -*/