run_unity = cd $(srcdir) && ruby ../../sntp/unity/auto/generate_test_runner.rb
#removed test-libntp
-check_PROGRAMS = test-modetoa test-uglydate
+check_PROGRAMS = test-modetoa test-uglydate test-ymd2yd test-statestr test-numtoa test-numtohost \
+test-hextoint test-atoint
+
if GTEST_AVAILABLE
check_PROGRAMS += tests
else
$(GTEST_LIBS) \
$(NULL)
+unity_tests_LDADD = \
+ $(LDADD) \
+ $(top_builddir)/sntp/unity/libunity.a \
+ $(NULL)
+
AM_CFLAGS = $(CFLAGS_NTP)
AM_CXXFLAGS = $(GTEST_CXXFLAGS)
tests_SOURCES = $(top_srcdir)/sntp/tests_main.cpp \
libntptest.cpp \
a_md5encrypt.cpp \
- atoint.cpp \
+ g_atoint.cpp \
atouint.cpp \
authkeys.cpp \
buftvtots.cpp \
calyearstart.cpp \
clocktime.cpp \
decodenetnum.cpp \
- hextoint.cpp \
+ g_hextoint.cpp \
hextolfp.cpp \
humandate.cpp \
lfpfunc.cpp \
g_modetoa.cpp \
msyslog.cpp \
netof.cpp \
- numtoa.cpp \
- numtohost.cpp \
+ g_numtoa.cpp \
+ g_numtohost.cpp \
octtoint.cpp \
prettydate.cpp \
recvbuff.cpp \
sfptostr.cpp \
socktoa.cpp \
ssl_init.cpp \
- statestr.cpp \
+ g_statestr.cpp \
strtolfp.cpp \
timespecops.cpp \
timestructs.cpp \
tvtots.cpp \
g_uglydate.cpp \
vi64ops.cpp \
- ymd2yd.cpp \
+ g_ymd2yd.cpp \
$(NULL)
noinst_HEADERS = \
-I$(top_srcdir)/sntp/unity \
$(NULL)
-
test_modetoa_LDADD = \
$(LDADD) \
$(top_builddir)/sntp/unity/libunity.a \
$(top_builddir)/sntp/unity/libunity.a \
$(NULL)
-#removed one combined test, because unity devs suggested we use one program per test
-test_libntp_SOURCES = \
- modetoa.c \
- uglydate.c \
- test-libntp.c \
- test-libntp.h \
- run-test-libntp.c \
+test_ymd2yd_CFLAGS = \
+ -I$(top_srcdir)/sntp/unity \
+ $(NULL)
+
+test_ymd2yd_LDADD = \
+ $(LDADD) \
+ $(top_builddir)/sntp/unity/libunity.a \
+ $(NULL)
+
+test_statestr_CFLAGS = \
+ -I$(top_srcdir)/sntp/unity \
+ $(NULL)
+
+test_statestr_LDADD = \
+ $(LDADD) \
+ $(top_builddir)/sntp/unity/libunity.a \
+ $(NULL)
+
+test_numtoa_CFLAGS = \
+ -I$(top_srcdir)/sntp/unity \
+ $(NULL)
+
+test_numtoa_LDADD = \
+ $(unity_tests_LDADD)
+
+test_numtohost_CFLAGS = \
+ -I$(top_srcdir)/sntp/unity \
+ $(NULL)
+
+test_numtohost_LDADD = \
+ $(unity_tests_LDADD) \
+ $(NULL)
+
+test_hextoint_CFLAGS = \
+ -I$(top_srcdir)/sntp/unity \
+ $(NULL)
+
+test_hextoint_LDADD = \
+ $(unity_tests_LDADD)
+ $(NULL)
+
+test_atoint_CFLAGS = \
+ -I$(top_srcdir)/sntp/unity \
+ $(NULL)
+
+test_atoint_LDADD = \
+ $(unity_tests_LDADD)
$(NULL)
+
+#removed one combined test, because unity devs suggested we use one program per test
+#test_libntp_SOURCES = \
+# modetoa.c \
+# uglydate.c \
+# test-libntp.c \
+# test-libntp.h \
+# run-test-libntp.c \
+# $(NULL)
+
test_modetoa_SOURCES = \
modetoa.c \
run-test-modetoa.c \
run-test-uglydate.c \
$(NULL)
+test_ymd2yd_SOURCES = \
+ ymd2yd.c \
+ run-test-ymd2yd.c \
+ $(NULL)
+
+test_statestr_SOURCES = \
+ statestr.c \
+ run-test-statestr.c \
+ $(NULL)
+
+test_numtoa_SOURCES = \
+ numtoa.c \
+ run-test-numtoa.c \
+ $(NULL)
+
+test_numtohost_SOURCES = \
+ numtohost.c \
+ run-test-numtohost.c \
+ $(NULL)
+
+test_hextoint_SOURCES = \
+ hextoint.c \
+ run-test-hextoint.c \
+ $(NULL)
+
+test_atoint_SOURCES = \
+ atoint.c \
+ run-test-atoint.c \
+ $(NULL)
+
+
$(srcdir)/run-test-modetoa.c: $(srcdir)/modetoa.c $(std_unity_list)
$(run_unity) modetoa.c run-test-modetoa.c
$(srcdir)/run-test-uglydate.c: $(srcdir)/uglydate.c $(std_unity_list)
$(run_unity) uglydate.c run-test-uglydate.c
+$(srcdir)/run-test-ymd2yd.c: $(srcdir)/ymd2yd.c $(std_unity_list)
+ $(run_unity) ymd2yd.c run-test-ymd2yd.c
+
+$(srcdir)/run-test-statestr.c: $(srcdir)/statestr.c $(std_unity_list)
+ $(run_unity) statestr.c run-test-statestr.c
+
+$(srcdir)/run-test-numtoa.c: $(srcdir)/numtoa.c $(std_unity_list)
+ $(run_unity) numtoa.c run-test-numtoa.c
+
+$(srcdir)/run-test-numtohost.c: $(srcdir)/numtohost.c $(std_unity_list)
+ $(run_unity) numtohost.c run-test-numtohost.c
+
+$(srcdir)/run-test-hextoint.c: $(srcdir)/hextoint.c $(std_unity_list)
+ $(run_unity) hextoint.c run-test-hextoint.c
+
+$(srcdir)/run-test-atoint.c: $(srcdir)/atoint.c $(std_unity_list)
+ $(run_unity) atoint.c run-test-atoint.c
TESTS =
--- /dev/null
+#include "unity.h"
+
+void test_RegularPositive(void) {
+ const char *str = "17";
+ long val;
+
+ TEST_ASSERT_TRUE(atoint(str, &val));
+ TEST_ASSERT_EQUAL(17, val);
+}
+
+void test_RegularNegative(void) {
+ const char *str = "-20";
+ long val;
+
+ TEST_ASSERT_TRUE(atoint(str, &val));
+ TEST_ASSERT_EQUAL(-20, val);
+}
+
+void test_PositiveOverflowBoundary(void) {
+ const char *str = "2147483648";
+ long val;
+
+ TEST_ASSERT_FALSE(atoint(str, &val));
+}
+
+void test_NegativeOverflowBoundary(void) {
+ const char *str = "-2147483649";
+ long val;
+
+ TEST_ASSERT_FALSE(atoint(str, &val));
+}
+
+void test_PositiveOverflowBig(void) {
+ const char *str = "2300000000";
+ long val;
+
+ TEST_ASSERT_FALSE(atoint(str, &val));
+}
+
+void test_IllegalCharacter(void) {
+ const char *str = "4500l";
+ long val;
+
+ TEST_ASSERT_FALSE(atoint(str, &val));
+}
+
+
TEST_F(statestrTest, ClockCodeUnknown) {
EXPECT_STREQ("clk_-1", ceventstr(-1));
}
+
--- /dev/null
+#include "config.h"
+#include "ntp_fp.h"
+#include "unity.h"
+//#include "libntptest.h"
+
+
+void test_SingleDigit(void) {
+ const char *str = "a"; // 10 decimal
+ u_long actual;
+
+ TEST_ASSERT_TRUE(hextoint(str, &actual));
+ TEST_ASSERT_EQUAL(10, actual);
+}
+
+void test_MultipleDigits(void) {
+ const char *str = "8F3"; // 2291 decimal
+ u_long actual;
+
+ TEST_ASSERT_TRUE(hextoint(str, &actual));
+ TEST_ASSERT_EQUAL(2291, actual);
+}
+
+void test_MaxUnsigned(void) {
+ const char *str = "ffffffff"; // 4294967295 decimal
+ u_long actual;
+
+ TEST_ASSERT_TRUE(hextoint(str, &actual));
+ TEST_ASSERT_EQUAL(4294967295UL, actual);
+}
+
+void test_Overflow(void) {
+ const char *str = "100000000"; // Overflow by 1
+ u_long actual;
+
+ TEST_ASSERT_FALSE(hextoint(str, &actual));
+}
+
+void test_IllegalChar(void) {
+ const char *str = "5gb"; // Illegal character g
+ u_long actual;
+
+ TEST_ASSERT_FALSE(hextoint(str, &actual));
+}
+
//#include "config.h"
-//#include "libntptest.h"
+//#include "libntptest.h" //used for google test framework, not needed
#include "unity.h"
//#include "ntp_stdlib.h"
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));
+ TEST_ASSERT_EQUAL_STRING("mode#100", modetoa(MODE));
// EXPECT_STREQ("mode#100", modetoa(MODE));
}
--- /dev/null
+#include "config.h"
+#include "ntp_fp.h"
+#include "unity.h"
+
+
+void setUp(void)
+{
+}
+
+void tearDown(void)
+{
+}
+
+void test_Address(void) {
+ u_int32 input = htonl(3221225472UL+512UL+1UL); // 192.0.2.1
+
+ TEST_ASSERT_EQUAL_STRING("192.0.2.1", numtoa(input));
+}
+
+void test_Netmask(void) {
+ // 255.255.255.0
+ u_int32 hostOrder = 255UL*256UL*256UL*256UL + 255UL*256UL*256UL + 255UL*256UL;
+ u_int32 input = htonl(hostOrder);
+
+ TEST_ASSERT_EQUAL_STRING("255.255.255.0", numtoa(input));
+}
+
--- /dev/null
+#include "config.h"
+#include "ntp_fp.h"
+
+#include "unity.h"
+
+void test_LoopbackNetNonResolve(void) {
+ /* A loopback address in 127.0.0.0/8 is chosen, and
+ * numtohost() should not try to resolve it unless
+ * it is 127.0.0.1
+ */
+
+ u_int32 input = 127*256*256*256 + 1*256 + 1; // 127.0.1.1
+
+ TEST_ASSERT_EQUAL_STRING("127.0.1.1", numtohost(htonl(input)));
+}
+
--- /dev/null
+/* 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_RegularPositive(void);
+extern void test_RegularNegative(void);
+extern void test_PositiveOverflowBoundary(void);
+extern void test_NegativeOverflowBoundary(void);
+extern void test_PositiveOverflowBig(void);
+extern void test_IllegalCharacter(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+ tearDown();
+ setUp();
+}
+
+
+//=======MAIN=====
+int main(void)
+{
+ Unity.TestFile = "atoint.c";
+ UnityBegin("atoint.c");
+ RUN_TEST(test_RegularPositive, 3);
+ RUN_TEST(test_RegularNegative, 11);
+ RUN_TEST(test_PositiveOverflowBoundary, 19);
+ RUN_TEST(test_NegativeOverflowBoundary, 26);
+ RUN_TEST(test_PositiveOverflowBig, 33);
+ RUN_TEST(test_IllegalCharacter, 40);
+
+ return (UnityEnd());
+}
--- /dev/null
+/* 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_SingleDigit(void);
+extern void test_MultipleDigits(void);
+extern void test_MaxUnsigned(void);
+extern void test_Overflow(void);
+extern void test_IllegalChar(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+ tearDown();
+ setUp();
+}
+
+
+//=======MAIN=====
+int main(void)
+{
+ Unity.TestFile = "hextoint.c";
+ UnityBegin("hextoint.c");
+ RUN_TEST(test_SingleDigit, 7);
+ RUN_TEST(test_MultipleDigits, 15);
+ RUN_TEST(test_MaxUnsigned, 23);
+ RUN_TEST(test_Overflow, 31);
+ RUN_TEST(test_IllegalChar, 38);
+
+ return (UnityEnd());
+}
Unity.TestFile = "modetoa.c";
UnityBegin("modetoa.c");
RUN_TEST(test_KnownMode, 8);
- RUN_TEST(test_UnknownMode, 15);
+ RUN_TEST(test_UnknownMode, 14);
return (UnityEnd());
}
--- /dev/null
+/* 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_Address(void);
+extern void test_Netmask(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+ tearDown();
+ setUp();
+}
+
+
+//=======MAIN=====
+int main(void)
+{
+ Unity.TestFile = "numtoa.c";
+ UnityBegin("numtoa.c");
+ RUN_TEST(test_Address, 14);
+ RUN_TEST(test_Netmask, 20);
+
+ return (UnityEnd());
+}
--- /dev/null
+/* 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_LoopbackNetNonResolve(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+ tearDown();
+ setUp();
+}
+
+
+//=======MAIN=====
+int main(void)
+{
+ Unity.TestFile = "numtohost.c";
+ UnityBegin("numtohost.c");
+ RUN_TEST(test_LoopbackNetNonResolve, 6);
+
+ return (UnityEnd());
+}
--- /dev/null
+/* 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_PeerRestart(void);
+extern void test_SysUnspecified(void);
+extern void test_ClockCodeExists(void);
+extern void test_ClockCodeUnknown(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+ tearDown();
+ setUp();
+}
+
+
+//=======MAIN=====
+int main(void)
+{
+ Unity.TestFile = "statestr.c";
+ UnityBegin("statestr.c");
+ RUN_TEST(test_PeerRestart, 18);
+ RUN_TEST(test_SysUnspecified, 22);
+ RUN_TEST(test_ClockCodeExists, 27);
+ RUN_TEST(test_ClockCodeUnknown, 31);
+
+ return (UnityEnd());
+}
--- /dev/null
+/* 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_NonLeapYearFebruary(void);
+extern void test_NonLeapYearJune(void);
+extern void test_LeapYearFebruary(void);
+extern void test_LeapYearDecember(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+ tearDown();
+ setUp();
+}
+
+
+//=======MAIN=====
+int main(void)
+{
+ Unity.TestFile = "ymd2yd.c";
+ UnityBegin("ymd2yd.c");
+ RUN_TEST(test_NonLeapYearFebruary, 12);
+ RUN_TEST(test_NonLeapYearJune, 16);
+ RUN_TEST(test_LeapYearFebruary, 21);
+ RUN_TEST(test_LeapYearDecember, 25);
+
+ return (UnityEnd());
+}
--- /dev/null
+#include "config.h"
+//#include "libntptest.h"
+
+#include "unity.h"
+#include "ntp.h" // Needed for MAX_MAC_LEN used in ntp_control.h
+#include "ntp_control.h"
+
+void setUp(void)
+{
+}
+
+void tearDown(void)
+{
+}
+
+
+// eventstr()
+void test_PeerRestart(void) {
+ TEST_ASSERT_EQUAL_STRING("restart", eventstr(PEVNT_RESTART));
+}
+
+void test_SysUnspecified(void) {
+ TEST_ASSERT_EQUAL_STRING("unspecified", eventstr(EVNT_UNSPEC));
+}
+
+// ceventstr()
+void test_ClockCodeExists(void) {
+ TEST_ASSERT_EQUAL_STRING("clk_unspec", ceventstr(CTL_CLK_OKAY));
+}
+
+void test_ClockCodeUnknown(void) {
+ TEST_ASSERT_EQUAL_STRING("clk_-1", ceventstr(-1));
+}
+
--- /dev/null
+#include "unity.h"
+
+void setUp(void)
+{
+}
+
+void tearDown(void)
+{
+}
+
+
+void test_NonLeapYearFebruary (void) {
+ TEST_ASSERT_EQUAL(31+20, ymd2yd(2010,2,20)); //2010-02-20
+}
+
+void test_NonLeapYearJune (void) {
+ int expected = 31+28+31+30+31+18; // 18 June non-leap year
+ TEST_ASSERT_EQUAL(expected, ymd2yd(2011,6,18));
+}
+
+void test_LeapYearFebruary (void) {
+ TEST_ASSERT_EQUAL(31+20, ymd2yd(2012,2,20)); //2012-02-20 (leap year)
+}
+
+void test_LeapYearDecember (void) {
+ // 2012-12-31
+ int expected = 31+29+31+30+31+30+31+31+30+31+30+31;
+ TEST_ASSERT_EQUAL(expected, ymd2yd(2012,12,31));
+}
+