From: Tomek Mrugalski Date: Fri, 19 Jun 2015 22:33:19 +0000 (+0200) Subject: converted humandate from gtest to unity X-Git-Tag: NTP_4_3_43~2^2~21^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cab147b74c7942174ab4604e6420c290337b1f68;p=thirdparty%2Fntp.git converted humandate from gtest to unity bk: 558498afslQYKtH_e8iZsWQ7ggijFg --- diff --git a/tests/libntp/Makefile.am b/tests/libntp/Makefile.am index 61e08e932..edd02c3f3 100644 --- a/tests/libntp/Makefile.am +++ b/tests/libntp/Makefile.am @@ -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.cpp b/tests/libntp/g_humandate.cpp similarity index 100% rename from tests/libntp/humandate.cpp rename to tests/libntp/g_humandate.cpp diff --git a/tests/libntp/humandate.c b/tests/libntp/humandate.c new file mode 100644 index 000000000..36cbe2b9c --- /dev/null +++ b/tests/libntp/humandate.c @@ -0,0 +1,35 @@ +#include "config.h" +#include "unity.h" +#include "ntp_calendar.h" +#include "ntp_stdlib.h" +#include + +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 index 000000000..be3930d60 --- /dev/null +++ b/tests/libntp/run-humandate.c @@ -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 +#include + +//=======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 index 000000000..41bf07876 --- /dev/null +++ b/tests/libntp/run-sfptostr.c @@ -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 +#include + +//=======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()); +}