]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
converted humandate from gtest to unity
authorTomek Mrugalski <tomasz@isc.org>
Fri, 19 Jun 2015 22:33:19 +0000 (00:33 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 19 Jun 2015 22:33:19 +0000 (00:33 +0200)
bk: 558498afslQYKtH_e8iZsWQ7ggijFg

tests/libntp/Makefile.am
tests/libntp/g_humandate.cpp [moved from tests/libntp/humandate.cpp with 100% similarity]
tests/libntp/humandate.c [new file with mode: 0644]
tests/libntp/run-humandate.c [new file with mode: 0644]
tests/libntp/run-sfptostr.c [new file with mode: 0644]

index 61e08e932442cdff5028056050284fa1ae3feeb6..edd02c3f38feac3c2aebb7ee9cbd41041af1786d 100644 (file)
@@ -17,6 +17,7 @@ check_PROGRAMS =              \
        test-decodenetnum       \
        test-hextoint           \
        test-hextolfp           \
+       test-humandate          \
        test-lfpfunc            \
        test-modetoa            \
        test-netof              \
@@ -87,7 +88,7 @@ tests_SOURCES =                                       \
        g_decodenetnum.cpp      \
        g_hextoint.cpp          \
        g_hextolfp.cpp          \
-       humandate.cpp           \
+       g_humandate.cpp         \
        g_lfpfunc.cpp           \
        lfptostr.cpp            \
        g_modetoa.cpp           \
@@ -125,6 +126,7 @@ BUILT_SOURCES +=                    \
        $(srcdir)/run-decodenetnum.c    \
        $(srcdir)/run-hextoint.c        \
        $(srcdir)/run-hextolfp.c        \
+       $(srcdir)/run-humandate.c       \
        $(srcdir)/run-lfpfunc.c         \
        $(srcdir)/run-modetoa.c         \
        $(srcdir)/run-netof.c           \
@@ -410,6 +412,15 @@ test_sfptostr_LDADD =                              \
        $(top_builddir)/sntp/unity/libunity.a   \
        $(NULL)
 
+test_humandate_CFLAGS =                                \
+       -I$(top_srcdir)/sntp/unity              \
+       $(NULL)
+
+test_humandate_LDADD =                         \
+       $(LDADD)                                \
+       $(top_builddir)/sntp/unity/libunity.a   \
+       $(NULL)
+
 
 test_modetoa_SOURCES =                 \
        modetoa.c                       \
@@ -555,6 +566,11 @@ test_sfptostr_SOURCES =                    \
        run-sfptostr.c                  \
        $(NULL)
 
+test_humandate_SOURCES =                       \
+       humandate.c                     \
+       run-humandate.c                 \
+       $(NULL)
+
 $(srcdir)/run-modetoa.c: $(srcdir)/modetoa.c $(std_unity_list)
        $(run_unity) modetoa.c run-modetoa.c
 
@@ -639,6 +655,9 @@ $(srcdir)/run-tvtots.c: $(srcdir)/tvtots.c $(std_unity_list)
 $(srcdir)/run-sfptostr.c: $(srcdir)/sfptostr.c $(std_unity_list)
        $(run_unity) sfptostr.c run-sfptostr.c
 
+$(srcdir)/run-humandate.c: $(srcdir)/humandate.c $(std_unity_list)
+       $(run_unity) humandate.c run-humandate.c
+
 
 TESTS =
 
diff --git a/tests/libntp/humandate.c b/tests/libntp/humandate.c
new file mode 100644 (file)
index 0000000..36cbe2b
--- /dev/null
@@ -0,0 +1,35 @@
+#include "config.h"
+#include "unity.h"
+#include "ntp_calendar.h"
+#include "ntp_stdlib.h"
+#include <stdio.h>
+
+void test_RegularTime(void)
+{
+       time_t sample = 1276601278;
+       char expected[15];
+
+       struct tm* time;
+       time = localtime(&sample);
+       TEST_ASSERT_TRUE(time != NULL);
+
+       snprintf(expected, 15, "%02d:%02d:%02d", time->tm_hour, time->tm_min, time->tm_sec);
+
+       TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
+}
+
+void test_CurrentTime(void)
+{
+       time_t sample;
+       char expected[15];
+
+       time(&sample);
+
+       struct tm* time;
+       time = localtime(&sample);
+       TEST_ASSERT_TRUE(time != NULL);
+
+       snprintf(expected, 15, "%02d:%02d:%02d", time->tm_hour, time->tm_min, time->tm_sec);
+
+       TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
+}
diff --git a/tests/libntp/run-humandate.c b/tests/libntp/run-humandate.c
new file mode 100644 (file)
index 0000000..be3930d
--- /dev/null
@@ -0,0 +1,53 @@
+/* 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_RegularTime(void);
+extern void test_CurrentTime(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "humandate.c";
+  UnityBegin("humandate.c");
+  RUN_TEST(test_RegularTime, 7);
+  RUN_TEST(test_CurrentTime, 21);
+
+  return (UnityEnd());
+}
diff --git a/tests/libntp/run-sfptostr.c b/tests/libntp/run-sfptostr.c
new file mode 100644 (file)
index 0000000..41bf078
--- /dev/null
@@ -0,0 +1,65 @@
+/* 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_PositiveIntegerPositiveFraction(void);
+extern void test_NegativeIntegerNegativeFraction(void);
+extern void test_PositiveIntegerNegativeFraction(void);
+extern void test_NegativeIntegerPositiveFraction(void);
+extern void test_SingleDecimalInteger(void);
+extern void test_SingleDecimalRounding(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "sfptostr.c";
+  UnityBegin("sfptostr.c");
+  RUN_TEST(test_PositiveInteger, 11);
+  RUN_TEST(test_NegativeInteger, 19);
+  RUN_TEST(test_PositiveIntegerPositiveFraction, 27);
+  RUN_TEST(test_NegativeIntegerNegativeFraction, 35);
+  RUN_TEST(test_PositiveIntegerNegativeFraction, 43);
+  RUN_TEST(test_NegativeIntegerPositiveFraction, 51);
+  RUN_TEST(test_SingleDecimalInteger, 59);
+  RUN_TEST(test_SingleDecimalRounding, 67);
+
+  return (UnityEnd());
+}