]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
c_sockaddrtest.h:
authorDamir Tomic <viperus@ntp.org>
Mon, 15 Jun 2015 22:54:42 +0000 (00:54 +0200)
committerDamir Tomic <viperus@ntp.org>
Mon, 15 Jun 2015 22:54:42 +0000 (00:54 +0200)
  removed stuff like 1==1 with TRUE. Also added cin cout stuff, should be replaced b
Many files:
  new file
Makefile.am:
  fixes to Lokesh-Damir merge, added new .h to noinst_SOURCES
c_lfptest.h:
  put the static vars back in here, removed them from hextolfp.c, because more files will need them.
hextolfp.c:
  removed static consts, placed them in c_lpftest.h
octtoint.c:
  removed outdates testcalshims.h, replaced with required includes

bk: 557f57b2AUMb_7zs3jaMY7oj3giHSg

tests/libntp/Makefile.am
tests/libntp/c_lfptest.h
tests/libntp/c_sockaddrtest.h
tests/libntp/hextolfp.c
tests/libntp/octtoint.c
tests/libntp/run-test-decodenetnum.c [new file with mode: 0644]
tests/libntp/run-test-hextolfp.c [new file with mode: 0644]
tests/libntp/run-test-netof.c [new file with mode: 0644]
tests/libntp/run-test-octtoint.c
tests/libntp/run-test-socktoa.c [new file with mode: 0644]

index 0daef1778a7fe44719bf84189040417e88d8654b..bfa346c4781d389c527dc4481bb01f52eed547f5 100644 (file)
@@ -28,8 +28,8 @@ check_PROGRAMS =              \
        test-hextolfp           \
        test-netof              \
        test-socktoa            \
+       test-decodenetnum       \
        $(NULL)
-#test-decodenetnum
 
 if GTEST_AVAILABLE
 check_PROGRAMS += tests
@@ -111,8 +111,10 @@ tests_SOURCES =                                    \
 
 noinst_HEADERS =       \
        lfptest.h       \
+       c_lfptest.h     \
        libntptest.h    \
        sockaddrtest.h  \
+       c_sockaddrtest.h        \
        timestructs.h   \
        test-libntp.h   \
        $(NULL)
@@ -197,42 +199,48 @@ test_atoint_LDADD =                               \
        $(unity_tests_LDADD)
        $(NULL)
 
-test_octtoint_CFLAGS =                  \
-       -I$(top_srcdir)/sntp/unity      \
+test_octtoint_CFLAGS =                 \
+       -I$(top_srcdir)/sntp/unity      \
        $(NULL)
 
-test_octtoint_LDADD =                   \
-       $(unity_tests_LDADD)
+test_octtoint_LDADD =                  \
+       $(unity_tests_LDADD)            \
        $(NULL)
 
-test_hextolfp_CFLAGS =                  \
-       -I$(top_srcdir)/sntp/unity      \
+test_hextolfp_CFLAGS =                 \
+       -I$(top_srcdir)/sntp/unity      \
        $(NULL)
 
-test_hextolfp_LDADD =                   \
-       $(unity_tests_LDADD)
+test_hextolfp_LDADD =                  \
+       $(unity_tests_LDADD)            \
        $(NULL)
 
-test_netof_CFLAGS =                  \
-       -I$(top_srcdir)/sntp/unity      \
+test_netof_CFLAGS =                    \
+       -I$(top_srcdir)/sntp/unity      \
        $(NULL)
 
-test_netof_LDADD =                   \
-       $(unity_tests_LDADD)
+test_netof_LDADD =                     \
+       $(unity_tests_LDADD)            \
        $(NULL)
 
-#test_decodenetnum_CFLAGS =                  \
-#      -I$(top_srcdir)/sntp/unity      \
-#      $(NULL)
-#
-#test_decodenetnum_LDADD =                   \
-#      $(unity_tests_LDADD)
-#      $(NULL)
+test_decodenetnum_CFLAGS =             \
+       -I$(top_srcdir)/sntp/unity      \
+       $(NULL)
+
+test_decodenetnum_LDADD =              \
+       $(unity_tests_LDADD)            \
+       $(NULL)
+
+test_socktoa_CFLAGS =                  \
+       -I$(top_srcdir)/sntp/unity      \
+       $(NULL)
 
-test_socktoa_CFLAGS =                  \
-       -I$(top_srcdir)/sntp/unity      \
+test_socktoa_LDADD =                   \
+       $(unity_tests_LDADD)            \
        $(NULL)
 
+test_a_md5encrypt_CFLAGS =                     \
+       -I$(top_srcdir)/sntp/unity              \
        $(NULL)
 
 test_a_md5encrypt_LDADD =                      \
@@ -319,7 +327,6 @@ test_calendar_LDADD =                               \
        $(NULL)
 
 
-
 test_modetoa_SOURCES =                 \
        modetoa.c                       \
        run-test-modetoa.c              \
@@ -360,29 +367,34 @@ test_atoint_SOURCES =                     \
        run-test-atoint.c               \
        $(NULL)
 
-test_octtoint_SOURCES =                \
-       octtoint.c                      \
-       run-test-octtoint.c                     \
+test_a_md5encrypt_SOURCES =            \
+       a_md5encrypt.c                  \
+       run-test-a_md5encrypt.c         \
        $(NULL)
 
-test_hextolfp_SOURCES =                \
-       hextolfp.c                      \
-       run-test-hextolfp.c                     \
+test_octtoint_SOURCES =                        \
+       octtoint.c                      \
+       run-test-octtoint.c             \
        $(NULL)
 
-test_netof_SOURCES =                   \
-       netof.c                 \
-       run-test-netof.c                \
+test_hextolfp_SOURCES =                        \
+       hextolfp.c                      \
+       run-test-hextolfp.c             \
        $(NULL)
 
-#test_decodenetnum_SOURCES =                   \
-#      decodenetnum.c                  \
-#      run-test-decodenetnum.c                 \
-#      $(NULL)
+test_netof_SOURCES =                   \
+       netof.c                         \
+       run-test-netof.c                \
+       $(NULL)
 
-test_socktoa_SOURCES =                 \
-       socktoa.c                       \
-       run-test-socktoa.c                      \
+test_decodenetnum_SOURCES =            \
+       decodenetnum.c                  \
+       run-test-decodenetnum.c         \
+       $(NULL)
+
+test_socktoa_SOURCES =                 \
+       socktoa.c                       \
+       run-test-socktoa.c              \
        $(NULL)
 
 test_atouint_SOURCES =                 \
@@ -428,10 +440,10 @@ test_caljulian_SOURCES =          \
        test-libntp.c                   \
        $(NULL)
 
-test_calendar_SOURCES =                                \
-       calendar.c                              \
-       run-test-calendar.c                     \
-       test-libntp.c                           \
+test_calendar_SOURCES =                        \
+       calendar.c                      \
+       run-test-calendar.c             \
+       test-libntp.c                   \
        $(NULL)
 
 
@@ -443,12 +455,17 @@ BUILT_SOURCES +=                          \
        $(srcdir)/run-test-caljulian.c          \
        $(srcdir)/run-test-calyearstart.c       \
        $(srcdir)/run-test-clocktime.c          \
+       $(srcdir)/run-test-decodenetnum.c       \
        $(srcdir)/run-test-hextoint.c           \
+       $(srcdir)/run-test-hextolfp.c           \
        $(srcdir)/run-test-lfpfunc.c            \
        $(srcdir)/run-test-modetoa.c            \
+       $(srcdir)/run-test-netof.c              \
        $(srcdir)/run-test-numtoa.c             \
        $(srcdir)/run-test-numtohost.c          \
+       $(srcdir)/run-test-octtoint.c           \
        $(srcdir)/run-test-refnumtoa.c          \
+       $(srcdir)/run-test-socktoa.c            \
        $(srcdir)/run-test-statestr.c           \
        $(srcdir)/run-test-uglydate.c           \
        $(srcdir)/run-test-vi64ops.c            \
@@ -489,8 +506,8 @@ $(srcdir)/run-test-hextolfp.c: $(srcdir)/hextolfp.c $(std_unity_list)
 $(srcdir)/run-test-netof.c: $(srcdir)/netof.c $(std_unity_list)
        $(run_unity) netof.c run-test-netof.c
 
-#$(srcdir)/run-test-decodenetnum.c: $(srcdir)/decodenetnum.c $(std_unity_list)
-#      $(run_unity) decodenetnum.c run-test-decodenetnum.c
+$(srcdir)/run-test-decodenetnum.c: $(srcdir)/decodenetnum.c $(std_unity_list)
+       $(run_unity) decodenetnum.c run-test-decodenetnum.c
 
 $(srcdir)/run-test-socktoa.c: $(srcdir)/socktoa.c $(std_unity_list)
        $(run_unity) socktoa.c run-test-socktoa.c
index a6e3627e9745fdf7ad1d3a3449778264e507617f..7949821a2063c4b9716265cfc8627ca115ee1ab2 100644 (file)
@@ -5,13 +5,26 @@
 
 int IsEqual(const l_fp expected, const l_fp actual) {
        if (L_ISEQU(&expected, &actual)) {
-               return 1==1;
+               return TRUE;
        } else {
-               return 1==2;
+               //printf(" expected: ...");
+               /*
+               << " expected: " << lfptoa(&expected, FRACTION_PREC)
+                               << " (" << expected.l_ui << "." << expected.l_uf << ")"
+                               << " but was: " << lfptoa(&actual, FRACTION_PREC)
+                               << " (" << actual.l_ui << "." << actual.l_uf << ")";
+               */
+               return FALSE;
        }
 
 }
 
+static const int32 HALF = -2147483647L - 1L;
+static const int32 HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005
+static const int32 HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005
+static const int32 QUARTER = 1073741824L;
+static const int32 QUARTER_PROMILLE_APPRX = 1073742L;
+
 #endif
 
 
index f5cd6b39872dafd1fd56e8687f7b7b408fe42eeb..f9a9fde41ee8f94a8f095d288c8fa5252035163e 100644 (file)
@@ -18,27 +18,35 @@ int IsEqual(const sockaddr_u expected, const sockaddr_u actual) {
        struct in6_addr in6;
 
        if (expected.sa.sa_family != actual.sa.sa_family) {
-               return 1==2;
+               //<< "Expected sa_family: " << expected.sa.sa_family
+               //<< " but got: " << actual.sa.sa_family;
+               return FALSE;
        }
 
        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;
+                       return TRUE;
                } else {
-                       return 1==2;
+                       //<< "IPv4 comparision failed, expected: "
+                       //<< expected.sa4.sin_addr.s_addr
+                       //<< "(" << socktoa(&expected) << ") but was: "
+                       //<< actual.sa4.sin_addr.s_addr "(" << socktoa(&actual) << ")";
+                       return FALSE;
                }
        } 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;
+                       return TRUE;
                } else {
-                       return 1==2;
+                       printf("IPv6 comparision failed");
+                       return FALSE;
                }
        } else { // Unknown family
-               return 1==2;
+               printf("Unknown sa_family: ");// << actual.sa.sa_family;
+               return FALSE;
        }
 }
 
index f17642ef3f0afaff563fe1c88284e8fcafc153b3..0a4a6f9cf2dea54455410009ca13831dc25b6baa 100644 (file)
@@ -4,13 +4,6 @@
 #include "unity.h"
 #include "c_lfptest.h"
 
-static const int32 HALF = -2147483647L - 1L;
-static const int32 HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005
-static const int32 HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005
-static const int32 QUARTER = 1073741824L;
-static const int32 QUARTER_PROMILLE_APPRX = 1073742L;
-
-
 
 void test_PositiveInteger(void) {
        const char *str = "00001000.00000000";
index b2ceeed09cc040deea3f621a58d5863cb2e1be27..3541b2106dc80399c9de05e304c763bf767ccde6 100644 (file)
@@ -1,4 +1,7 @@
-#include "testcalshims.h"
+#include "config.h"
+
+#include "ntp_stdlib.h"
+//#include "ntp_calendar.h"
 //#include "ntp_fp.h"
 #include "unity.h"
 
diff --git a/tests/libntp/run-test-decodenetnum.c b/tests/libntp/run-test-decodenetnum.c
new file mode 100644 (file)
index 0000000..5c82a39
--- /dev/null
@@ -0,0 +1,61 @@
+/* AUTOGENERATED FILE. DO NOT EDIT. */
+
+//=======Test Runner Used To Run Each Test Below=====
+#define RUN_TEST(TestFunc, TestLineNum) \
+{ \
+  Unity.CurrentTestName = #TestFunc; \
+  Unity.CurrentTestLineNumber = TestLineNum; \
+  Unity.NumberOfTests++; \
+  if (TEST_PROTECT()) \
+  { \
+      setUp(); \
+      TestFunc(); \
+  } \
+  if (TEST_PROTECT() && !TEST_IS_IGNORED) \
+  { \
+    tearDown(); \
+  } \
+  UnityConcludeTest(); \
+}
+
+//=======Automagically Detected Files To Include=====
+#include "unity.h"
+#include <setjmp.h>
+#include <stdio.h>
+
+//=======External Functions This Runner Calls=====
+extern void setUp(void);
+extern void tearDown(void);
+extern void test_IPv4AddressOnly(void);
+extern void test_IPv4AddressWithPort(void);
+extern void test_IPv6AddressOnly(void);
+extern void test_IPv6AddressWithPort(void);
+extern void test_IllegalAddress(void);
+extern void test_IllegalCharInPort(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "decodenetnum.c";
+  UnityBegin("decodenetnum.c");
+  RUN_TEST(test_IPv4AddressOnly, 9);
+  RUN_TEST(test_IPv4AddressWithPort, 22);
+  RUN_TEST(test_IPv6AddressOnly, 35);
+  RUN_TEST(test_IPv6AddressWithPort, 55);
+  RUN_TEST(test_IllegalAddress, 75);
+  RUN_TEST(test_IllegalCharInPort, 82);
+
+  return (UnityEnd());
+}
diff --git a/tests/libntp/run-test-hextolfp.c b/tests/libntp/run-test-hextolfp.c
new file mode 100644 (file)
index 0000000..9cc331e
--- /dev/null
@@ -0,0 +1,61 @@
+/* AUTOGENERATED FILE. DO NOT EDIT. */
+
+//=======Test Runner Used To Run Each Test Below=====
+#define RUN_TEST(TestFunc, TestLineNum) \
+{ \
+  Unity.CurrentTestName = #TestFunc; \
+  Unity.CurrentTestLineNumber = TestLineNum; \
+  Unity.NumberOfTests++; \
+  if (TEST_PROTECT()) \
+  { \
+      setUp(); \
+      TestFunc(); \
+  } \
+  if (TEST_PROTECT() && !TEST_IS_IGNORED) \
+  { \
+    tearDown(); \
+  } \
+  UnityConcludeTest(); \
+}
+
+//=======Automagically Detected Files To Include=====
+#include "unity.h"
+#include <setjmp.h>
+#include <stdio.h>
+
+//=======External Functions This Runner Calls=====
+extern void setUp(void);
+extern void tearDown(void);
+extern void test_PositiveInteger(void);
+extern void test_NegativeInteger(void);
+extern void test_PositiveFraction(void);
+extern void test_NegativeFraction(void);
+extern void test_IllegalNumberOfInteger(void);
+extern void test_IllegalChar(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "hextolfp.c";
+  UnityBegin("hextolfp.c");
+  RUN_TEST(test_PositiveInteger, 8);
+  RUN_TEST(test_NegativeInteger, 18);
+  RUN_TEST(test_PositiveFraction, 28);
+  RUN_TEST(test_NegativeFraction, 38);
+  RUN_TEST(test_IllegalNumberOfInteger, 48);
+  RUN_TEST(test_IllegalChar, 55);
+
+  return (UnityEnd());
+}
diff --git a/tests/libntp/run-test-netof.c b/tests/libntp/run-test-netof.c
new file mode 100644 (file)
index 0000000..b39c9ee
--- /dev/null
@@ -0,0 +1,57 @@
+/* AUTOGENERATED FILE. DO NOT EDIT. */
+
+//=======Test Runner Used To Run Each Test Below=====
+#define RUN_TEST(TestFunc, TestLineNum) \
+{ \
+  Unity.CurrentTestName = #TestFunc; \
+  Unity.CurrentTestLineNumber = TestLineNum; \
+  Unity.NumberOfTests++; \
+  if (TEST_PROTECT()) \
+  { \
+      setUp(); \
+      TestFunc(); \
+  } \
+  if (TEST_PROTECT() && !TEST_IS_IGNORED) \
+  { \
+    tearDown(); \
+  } \
+  UnityConcludeTest(); \
+}
+
+//=======Automagically Detected Files To Include=====
+#include "unity.h"
+#include <setjmp.h>
+#include <stdio.h>
+
+//=======External Functions This Runner Calls=====
+extern void setUp(void);
+extern void tearDown(void);
+extern void test_ClassBAddress(void);
+extern void test_ClassCAddress(void);
+extern void test_ClassAAddress(void);
+extern void test_IPv6Address(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "netof.c";
+  UnityBegin("netof.c");
+  RUN_TEST(test_ClassBAddress, 10);
+  RUN_TEST(test_ClassCAddress, 20);
+  RUN_TEST(test_ClassAAddress, 30);
+  RUN_TEST(test_IPv6Address, 43);
+
+  return (UnityEnd());
+}
index be9d09b11750933ffe7806c74a53dd2823bbcff7..4dd84a0b7177425fb17041bacf1098947623c50e 100644 (file)
@@ -42,19 +42,22 @@ void resetTest()
   setUp();
 }
 
+char *progname;
+
 
 //=======MAIN=====
-int main(void)
+int main(int argc, char *argv[])
 {
+  progname = argv[0];
   Unity.TestFile = "octtoint.c";
   UnityBegin("octtoint.c");
-  RUN_TEST(test_SingleDigit, 5);
-  RUN_TEST(test_MultipleDigits, 14);
-  RUN_TEST(test_Zero, 23);
-  RUN_TEST(test_MaximumUnsigned32bit, 32);
-  RUN_TEST(test_Overflow, 41);
-  RUN_TEST(test_IllegalCharacter, 49);
-  RUN_TEST(test_IllegalDigit, 57);
+  RUN_TEST(test_SingleDigit, 8);
+  RUN_TEST(test_MultipleDigits, 17);
+  RUN_TEST(test_Zero, 26);
+  RUN_TEST(test_MaximumUnsigned32bit, 35);
+  RUN_TEST(test_Overflow, 44);
+  RUN_TEST(test_IllegalCharacter, 52);
+  RUN_TEST(test_IllegalDigit, 60);
 
   return (UnityEnd());
 }
diff --git a/tests/libntp/run-test-socktoa.c b/tests/libntp/run-test-socktoa.c
new file mode 100644 (file)
index 0000000..894404a
--- /dev/null
@@ -0,0 +1,61 @@
+/* AUTOGENERATED FILE. DO NOT EDIT. */
+
+//=======Test Runner Used To Run Each Test Below=====
+#define RUN_TEST(TestFunc, TestLineNum) \
+{ \
+  Unity.CurrentTestName = #TestFunc; \
+  Unity.CurrentTestLineNumber = TestLineNum; \
+  Unity.NumberOfTests++; \
+  if (TEST_PROTECT()) \
+  { \
+      setUp(); \
+      TestFunc(); \
+  } \
+  if (TEST_PROTECT() && !TEST_IS_IGNORED) \
+  { \
+    tearDown(); \
+  } \
+  UnityConcludeTest(); \
+}
+
+//=======Automagically Detected Files To Include=====
+#include "unity.h"
+#include <setjmp.h>
+#include <stdio.h>
+
+//=======External Functions This Runner Calls=====
+extern void setUp(void);
+extern void tearDown(void);
+extern void test_IPv4AddressWithPort(void);
+extern void test_IPv6AddressWithPort(void);
+extern void test_ScopedIPv6AddressWithPort(void);
+extern void test_HashEqual(void);
+extern void test_HashNotEqual(void);
+extern void test_IgnoreIPv6Fields(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "socktoa.c";
+  UnityBegin("socktoa.c");
+  RUN_TEST(test_IPv4AddressWithPort, 9);
+  RUN_TEST(test_IPv6AddressWithPort, 16);
+  RUN_TEST(test_ScopedIPv6AddressWithPort, 40);
+  RUN_TEST(test_HashEqual, 65);
+  RUN_TEST(test_HashNotEqual, 73);
+  RUN_TEST(test_IgnoreIPv6Fields, 82);
+
+  return (UnityEnd());
+}