]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
added more files to libntp/ and added some autogenerated tests to sandbox so other...
authorDamir Tomic <viperus@ntp.org>
Tue, 26 May 2015 09:13:23 +0000 (09:13 +0000)
committerDamir Tomic <viperus@ntp.org>
Tue, 26 May 2015 09:13:23 +0000 (09:13 +0000)
bk: 55643933gK4aa1QI_AUUngHxg6gHSA

tests/libntp/g_modetoa.cpp [moved from tests/libntp/modetoa.cpp with 100% similarity]
tests/libntp/g_uglydate.cpp [moved from tests/libntp/uglydate.cpp with 100% similarity]
tests/libntp/modetoa.c [new file with mode: 0644]
tests/libntp/test-libntp.c [new file with mode: 0644]
tests/libntp/test-libntp.h [new file with mode: 0644]
tests/libntp/testcalshims.c [new file with mode: 0644]
tests/libntp/testcalshims.h [new file with mode: 0644]
tests/libntp/uglydate.c [new file with mode: 0644]
tests/sandbox/run-first-test.c [new file with mode: 0644]
tests/sandbox/run-second-test.c [new file with mode: 0644]
tests/sandbox/run-ut-2803.c [new file with mode: 0644]

diff --git a/tests/libntp/modetoa.c b/tests/libntp/modetoa.c
new file mode 100644 (file)
index 0000000..811eef6
--- /dev/null
@@ -0,0 +1,20 @@
+//#include "config.h"
+//#include "libntptest.h"
+#include "unity.h"
+//#include "ntp_stdlib.h"
+
+
+
+void test_KnownMode(void) {
+       const int MODE = 3; // Should be "client"
+       TEST_ASSERT_EQUAL_STRING("client", modetoa(MODE));
+
+//     EXPECT_STREQ("client", modetoa(MODE));
+}
+
+void test_UnknownMode(void) {
+       const int MODE = 100;
+
+        TEST_ASSERT_EQUAL_STRING("mode#1001", modetoa(MODE));
+//     EXPECT_STREQ("mode#100", modetoa(MODE));
+}
diff --git a/tests/libntp/test-libntp.c b/tests/libntp/test-libntp.c
new file mode 100644 (file)
index 0000000..cce8076
--- /dev/null
@@ -0,0 +1,29 @@
+#include "test-libntp.h"
+#include <stdio.h>     /* HMS: for the printf's below */
+
+void
+setUp(void)
+{
+       printf("setUp from big test");
+}
+
+void
+tearDown(void)
+{
+}
+
+void
+test_modetoa(void)
+{
+printf("modetoa:test_KnownMode()\n");
+       test_KnownMode();
+printf("modetoa:test_UnknownMode()\n");
+       test_UnknownMode();
+}
+
+void
+test_uglydate(void)
+{
+printf("uglydate:test_ConstantDateTime()\n");
+       test_ConstantDateTime();
+}
diff --git a/tests/libntp/test-libntp.h b/tests/libntp/test-libntp.h
new file mode 100644 (file)
index 0000000..9d2bca6
--- /dev/null
@@ -0,0 +1,6 @@
+// From modetoa.c:
+extern void    test_KnownMode(void);
+extern void    test_UnknownMode(void);
+
+// From uglydate.c:
+extern void    test_ConstantDateTime(void);
diff --git a/tests/libntp/testcalshims.c b/tests/libntp/testcalshims.c
new file mode 100644 (file)
index 0000000..6a18b43
--- /dev/null
@@ -0,0 +1,27 @@
+#include "libntptest.h"
+
+/* This file contains various constants that libntp needs to be set
+ *  and that is normally defined in ntpd/ntpq/...
+ */
+
+u_long current_time = 4; // needed by authkeys. Used only in to calculate lifetime.
+const char *progname = "libntptest";
+
+time_t nowtime = 0;
+
+time_t timefunc(time_t *ptr)
+{
+    if (ptr)
+       *ptr = nowtime;
+    return nowtime;
+}
+
+void settime(int y, int m, int d, int H, int M, int S)
+{
+
+    time_t days(ntpcal_edate_to_eradays(y-1, m-1, d-1) + 1 - DAY_UNIX_STARTS);
+    time_t secs(ntpcal_etime_to_seconds(H, M, S));
+
+    nowtime = days * SECSPERDAY + secs;
+}
+
diff --git a/tests/libntp/testcalshims.h b/tests/libntp/testcalshims.h
new file mode 100644 (file)
index 0000000..5afb7b8
--- /dev/null
@@ -0,0 +1,9 @@
+//#include "tests_main.h"
+
+#include "ntp_stdlib.h"
+#include "ntp_calendar.h"
+
+       static time_t timefunc(time_t*);
+       static time_t nowtime;
+       static void   settime(int y, int m, int d, int H, int M, int S);
+
diff --git a/tests/libntp/uglydate.c b/tests/libntp/uglydate.c
new file mode 100644 (file)
index 0000000..a7879c1
--- /dev/null
@@ -0,0 +1,16 @@
+#include "config.h"
+#include "ntp_fp.h"
+#include "unity.h"
+
+//#include "ntp_stdlib.h"
+//#include "libntptest.h"
+
+void
+test_ConstantDateTime(void) {
+       const u_int32 HALF = 2147483648UL;
+
+       l_fp time = {3485080800UL, HALF}; // 2010-06-09 14:00:00.5
+
+       TEST_ASSERT_EQUAL_STRING("3485080800.500000 10:159:14:00:00.500",
+                                uglydate(&time));
+}
diff --git a/tests/sandbox/run-first-test.c b/tests/sandbox/run-first-test.c
new file mode 100644 (file)
index 0000000..dd909ad
--- /dev/null
@@ -0,0 +1,48 @@
+/* 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_ConstantDateTime(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+
+//=======MAIN=====
+int main(void)
+{
+  Unity.TestFile = "uglydate.c";
+  UnityBegin("");
+  RUN_TEST(test_ConstantDateTime, 9);
+
+  return (UnityEnd());
+}
diff --git a/tests/sandbox/run-second-test.c b/tests/sandbox/run-second-test.c
new file mode 100644 (file)
index 0000000..776dda4
--- /dev/null
@@ -0,0 +1,50 @@
+/* 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_KnownMode(void);
+extern void test_UnknownMode(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+
+//=======MAIN=====
+int main(void)
+{
+  Unity.TestFile = "modetoa.c";
+  UnityBegin("");
+  RUN_TEST(test_KnownMode, 8);
+  RUN_TEST(test_UnknownMode, 15);
+
+  return (UnityEnd());
+}
diff --git a/tests/sandbox/run-ut-2803.c b/tests/sandbox/run-ut-2803.c
new file mode 100644 (file)
index 0000000..d6ca2ee
--- /dev/null
@@ -0,0 +1,58 @@
+/* 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_main(void );
+extern void test_XPASS(void);
+extern void test_XFAIL(void);
+extern void test_XFAIL_WITH_MESSAGE(void);
+extern void test_main_incorrect(void);
+extern void test_ignored(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+
+//=======MAIN=====
+int main(void)
+{
+  Unity.TestFile = "ut-2803.c";
+  UnityBegin("");
+  RUN_TEST(test_main, 30);
+  RUN_TEST(test_XPASS, 37);
+  RUN_TEST(test_XFAIL, 49);
+  RUN_TEST(test_XFAIL_WITH_MESSAGE, 61);
+  RUN_TEST(test_main_incorrect, 73);
+  RUN_TEST(test_ignored, 77);
+
+  return (UnityEnd());
+}