From: Damir Tomic Date: Tue, 26 May 2015 09:13:23 +0000 (+0000) Subject: added more files to libntp/ and added some autogenerated tests to sandbox so other... X-Git-Tag: NTP_4_3_40~6^2~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b1a711704efdb0c3c4f537f74df3505bade2698;p=thirdparty%2Fntp.git added more files to libntp/ and added some autogenerated tests to sandbox so other people can see how do they lok like. bk: 55643933gK4aa1QI_AUUngHxg6gHSA --- diff --git a/tests/libntp/modetoa.cpp b/tests/libntp/g_modetoa.cpp similarity index 100% rename from tests/libntp/modetoa.cpp rename to tests/libntp/g_modetoa.cpp diff --git a/tests/libntp/uglydate.cpp b/tests/libntp/g_uglydate.cpp similarity index 100% rename from tests/libntp/uglydate.cpp rename to tests/libntp/g_uglydate.cpp diff --git a/tests/libntp/modetoa.c b/tests/libntp/modetoa.c new file mode 100644 index 000000000..811eef626 --- /dev/null +++ b/tests/libntp/modetoa.c @@ -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 index 000000000..cce807623 --- /dev/null +++ b/tests/libntp/test-libntp.c @@ -0,0 +1,29 @@ +#include "test-libntp.h" +#include /* 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 index 000000000..9d2bca61f --- /dev/null +++ b/tests/libntp/test-libntp.h @@ -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 index 000000000..6a18b4345 --- /dev/null +++ b/tests/libntp/testcalshims.c @@ -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 index 000000000..5afb7b879 --- /dev/null +++ b/tests/libntp/testcalshims.h @@ -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 index 000000000..a7879c117 --- /dev/null +++ b/tests/libntp/uglydate.c @@ -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 index 000000000..dd909adb0 --- /dev/null +++ b/tests/sandbox/run-first-test.c @@ -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 +#include + +//=======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 index 000000000..776dda485 --- /dev/null +++ b/tests/sandbox/run-second-test.c @@ -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 +#include + +//=======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 index 000000000..d6ca2ee7d --- /dev/null +++ b/tests/sandbox/run-ut-2803.c @@ -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 +#include + +//=======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()); +}