]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Files related to <netof> test
authorLokesh Walase <lokeshw24@ntp.org>
Sun, 14 Jun 2015 14:58:01 +0000 (20:28 +0530)
committerLokesh Walase <lokeshw24@ntp.org>
Sun, 14 Jun 2015 14:58:01 +0000 (20:28 +0530)
bk: 557d9679p4Soi7TFwgu5dhoET1wtzQ

tests/libntp/Makefile.am
tests/libntp/sockaddrtest.h

index e3af5f30eac6e318470aae1d3bc2fcc3ef9d0449..c7ffbf2d73b3e3602e6f47aad50f4dd4c953c685 100644 (file)
@@ -7,7 +7,7 @@ run_unity =     cd $(srcdir) && ruby ../../sntp/unity/auto/generate_test_runner.rb
 #removed test-libntp
 check_PROGRAMS = test-modetoa test-uglydate test-ymd2yd test-statestr test-numtoa test-numtohost \
 test-hextoint test-atoint test-atouint test-authkeys test-a_md5encrypt test-lfpfunc test-octtoint \
-test-hextolfp
+test-hextolfp test-netof
 
 if GTEST_AVAILABLE
 check_PROGRAMS += tests
@@ -64,7 +64,7 @@ tests_SOURCES = $(top_srcdir)/sntp/tests_main.cpp     \
                lfptostr.cpp            \
                g_modetoa.cpp           \
                msyslog.cpp             \
-               netof.cpp               \
+               g_netof.cpp             \
                g_numtoa.cpp            \
                g_numtohost.cpp         \
                g_octtoint.cpp          \
@@ -188,6 +188,14 @@ test_hextolfp_LDADD =                   \
        $(unity_tests_LDADD)
        $(NULL)
 
+test_netof_CFLAGS =                  \
+       -I$(top_srcdir)/sntp/unity      \
+       $(NULL)
+
+test_netof_LDADD =                   \
+       $(unity_tests_LDADD)
+       $(NULL)
+
 
 test_a_md5encrypt_CFLAGS =                  \
        -I$(top_srcdir)/sntp/unity      \
@@ -284,6 +292,12 @@ test_hextolfp_SOURCES =                    \
        run-test-hextolfp.c                     \
        $(NULL)
 
+test_netof_SOURCES =                   \
+       netof.c                 \
+       run-test-netof.c                \
+       $(NULL)
+
+
 
 test_a_md5encrypt_SOURCES =                    \
        a_md5encrypt.c                          \
@@ -337,6 +351,9 @@ $(srcdir)/run-test-octtoint.c: $(srcdir)/octtoint.c $(std_unity_list)
 $(srcdir)/run-test-hextolfp.c: $(srcdir)/hextolfp.c $(std_unity_list)
        $(run_unity) hextolfp.c run-test-hextolfp.c
 
+$(srcdir)/run-test-netof.c: $(srcdir)/netof.c $(std_unity_list)
+       $(run_unity) netof.c run-test-netof.c
+
 $(srcdir)/run-test-a_md5encrypt.c: $(srcdir)/a_md5encrypt.c $(std_unity_list)
        $(run_unity) a_md5encrypt.c run-test-a_md5encrypt.c
 
index 4baac4dd73ee547c2b4f31bafed3db8daf667462..97581f49562fc33504cc89ea53d9585cc30244f9 100644 (file)
@@ -1,6 +1,57 @@
 #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" {
@@ -56,3 +107,5 @@ protected:
 };
 
 #endif // TESTS_SOCKADDRTEST_H
+
+*/