[Git][NTPsec/ntpsec][master] 2 commits: Convert vi64ops.c
Amar Takhar
gitlab at mg.gitlab.com
Tue Nov 24 18:24:45 UTC 2015
Amar Takhar pushed to branch master at NTPsec / ntpsec
Commits:
605fde79 by Amar Takhar at 2015-11-24T13:24:27Z
Convert vi64ops.c
- - - - -
bce7a4b7 by Amar Takhar at 2015-11-24T13:24:27Z
Convert calyearstart.c and do some header cleanup.
* Move time functions to caltime.(c|h)
* Rename TEST_LIBNTP_SSL to TEST_LIBNTP
- - - - -
8 changed files:
- + tests/common/caltime.c
- + tests/common/caltime.h
- tests/common/tests_main.c
- − tests/libntp/cal.h
- tests/libntp/calyearstart.c
- tests/libntp/libntptest.h
- tests/libntp/vi64ops.c
- tests/wscript
Changes:
=====================================
tests/common/caltime.c
=====================================
--- /dev/null
+++ b/tests/common/caltime.c
@@ -0,0 +1,25 @@
+#include "config.h"
+#include <time.h>
+
+#include "caltime.h"
+#include "ntp_stdlib.h"
+#include "ntp_calendar.h"
+
+u_long current_time = 4;
+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;
+}
+
=====================================
tests/common/caltime.h
=====================================
--- /dev/null
+++ b/tests/common/caltime.h
@@ -0,0 +1,3 @@
+time_t timefunc(time_t*);
+void settime(int y, int m, int d, int H, int M, int S);
+
=====================================
tests/common/tests_main.c
=====================================
--- a/tests/common/tests_main.c
+++ b/tests/common/tests_main.c
@@ -1,6 +1,7 @@
-#include "tests_main.h"
-const char *progname = "ntpdigtest";
+
+#include "tests_main.h"
+const char *progname = "ntpsectest";
static const char** args_argv;
static int args_argc;
@@ -35,13 +36,13 @@ static void RunAllTests(void)
RUN_TEST_GROUP(packetHandling);
#endif
-#ifdef TEST_LIBNTP_SSL
+#ifdef TEST_LIBNTP
// RUN_TEST_GROUP(a_md5encrypt);
// RUN_TEST_GROUP(authkeys);
// RUN_TEST_GROUP(calendar);
// RUN_TEST_GROUP(caljulian);
// RUN_TEST_GROUP(caltontp);
-// RUN_TEST_GROUP(calyearstart);
+ RUN_TEST_GROUP(calyearstart);
// RUN_TEST_GROUP(clocktime);
// RUN_TEST_GROUP(decodenetnum);
// RUN_TEST_GROUP(hextolfp);
@@ -66,12 +67,13 @@ static void RunAllTests(void)
// RUN_TEST_GROUP(timevalops);
RUN_TEST_GROUP(tstotv);
RUN_TEST_GROUP(tvtots);
-// RUN_TEST_GROUP(vi64);
+ RUN_TEST_GROUP(vi64ops);
// RUN_TEST_GROUP(ymd2yd);
#endif
}
+
int main(int argc, const char * argv[]) {
init_lib();
=====================================
tests/libntp/cal.h deleted
=====================================
--- a/tests/libntp/cal.h
+++ /dev/null
@@ -1,3 +0,0 @@
-static time_t timefunc(time_t*);
-static void settime(int y, int m, int d, int H, int M, int S);
-
=====================================
tests/libntp/calyearstart.c
=====================================
--- a/tests/libntp/calyearstart.c
+++ b/tests/libntp/calyearstart.c
@@ -1,54 +1,45 @@
-extern "C" {
+#include "config.h"
+
#include "unity.h"
#include "unity_fixture.h"
-}
-
-TEST_GROUP(calyearstart);
-
-TEST_SETUP(calyearstart) {}
-TEST_TEAR_DOWN(calyearstart) {}
+#include "ntp_stdlib.h"
+#include "ntp_calendar.h"
+#include "caltime.h"
-#include "libntptest.h"
-#include "cal.h"
+static time_t nowtime;
-class calyearstartTest : public libntptest {
-protected:
- virtual void SetUp();
- virtual void TearDown();
-};
+TEST_GROUP(calyearstart);
-void calyearstartTest::SetUp()
-{
+TEST_SETUP(calyearstart) {
ntpcal_set_timefunc(timefunc);
settime(1970, 1, 1, 0, 0, 0);
}
-void calyearstartTest::TearDown()
-{
+TEST_TEAR_DOWN(calyearstart) {
ntpcal_set_timefunc(NULL);
}
TEST(calyearstart, NoWrapInDateRange) {
- const u_int32 input = 3486372600UL; // 2010-06-24 12:50:00.
- const u_int32 expected = 3471292800UL; // 2010-01-01 00:00:00
+ const u_int32_t input = 3486372600UL; // 2010-06-24 12:50:00.
+ const u_int32_t expected = 3471292800UL; // 2010-01-01 00:00:00
TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime));
TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL));
}
TEST(calyearstart, NoWrapInDateRangeLeapYear) {
- const u_int32 input = 3549528000UL; // 2012-06-24 12:00:00
- const u_int32 expected = 3534364800UL; // 2012-01-01 00:00:00
+ const u_int32_t input = 3549528000UL; // 2012-06-24 12:00:00
+ const u_int32_t expected = 3534364800UL; // 2012-01-01 00:00:00
TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime));
TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL));
}
TEST(calyearstart, WrapInDateRange) {
- const u_int32 input = 19904UL; // 2036-02-07 12:00:00
- const u_int32 expected = 4291747200UL; // 2036-01-01 00:00:00
+ const u_int32_t input = 19904UL; // 2036-02-07 12:00:00
+ const u_int32_t expected = 4291747200UL; // 2036-01-01 00:00:00
TEST_ASSERT_EQUAL(expected, calyearstart(input, &nowtime));
TEST_ASSERT_EQUAL(expected, calyearstart(input, NULL));
=====================================
tests/libntp/libntptest.h
=====================================
--- a/tests/libntp/libntptest.h
+++ b/tests/libntp/libntptest.h
@@ -1,6 +1,4 @@
#include "tests_main.h"
#include "ntp_stdlib.h"
-#include "ntp_calendar.h"
-static time_t nowtime;
=====================================
tests/libntp/vi64ops.c
=====================================
--- a/tests/libntp/vi64ops.c
+++ b/tests/libntp/vi64ops.c
@@ -1,7 +1,5 @@
-extern "C" {
#include "unity.h"
#include "unity_fixture.h"
-}
TEST_GROUP(vi64ops);
@@ -11,30 +9,26 @@ TEST_TEAR_DOWN(vi64ops) {}
#include "libntptest.h"
-extern "C" {
#include "vint64ops.h"
-}
-class vi64Test : public libntptest {
-public:
- bool IsEqual(const vint64 &expected, const vint64 &actual) {
- if (0 == memcmp(&expected, &actual, sizeof(vint64))) {
- return true;
- } else {
- return false
- << "expected: "
- << std::hex << expected.D_s.hi << '.'
- << std::hex << expected.D_s.lo
- << " but was "
- << std::hex << actual.D_s.hi << '.'
- << std::hex << actual.D_s.lo;
- }
+bool IsEqual(const vint64 *expected, const vint64 *actual) {
+ if (0 == memcmp(expected, actual, sizeof(vint64))) {
+ return true;
+ } else {
+ printf("Expected: %04x.%04x but was: %04x.%04x\n", expected->D_s.hi, expected->D_s.lo, actual->D_s.hi, actual->D_s.lo);
+ return false;
+// << "expected: "
+// << std::hex << expected.D_s.hi << '.'
+// << std::hex << expected.D_s.lo
+// << " but was "
+// << std::hex << actual.D_s.hi << '.'
+// << std::hex << actual.D_s.lo;
}
-};
+}
// ----------------------------------------------------------------------
// test number parser
-TEST(vi64, ParseVUI64_pos) {
+TEST(vi64ops, ParseVUI64_pos) {
vint64 act, exp;
const char *sp;
char *ep;
@@ -43,11 +37,11 @@ TEST(vi64, ParseVUI64_pos) {
exp.D_s.hi = 0;
exp.D_s.lo = 1234;
act = strtouv64(sp, &ep, 0);
- TEST_ASSERT_TRUE(IsEqual(exp, act));
+ TEST_ASSERT_TRUE(IsEqual(&exp, &act));
TEST_ASSERT_EQUAL(*ep, 'x');
}
-TEST(vi64, ParseVUI64_neg) {
+TEST(vi64ops, ParseVUI64_neg) {
vint64 act, exp;
const char *sp;
char *ep;
@@ -56,11 +50,11 @@ TEST(vi64, ParseVUI64_neg) {
exp.D_s.hi = ~0;
exp.D_s.lo = -1234;
act = strtouv64(sp, &ep, 0);
- TEST_ASSERT_TRUE(IsEqual(exp, act));
+ TEST_ASSERT_TRUE(IsEqual(&exp, &act));
TEST_ASSERT_EQUAL(*ep, 'x');
}
-TEST(vi64, ParseVUI64_case) {
+TEST(vi64ops, ParseVUI64_case) {
vint64 act, exp;
const char *sp;
char *ep;
@@ -69,13 +63,13 @@ TEST(vi64, ParseVUI64_case) {
exp.D_s.hi = 0x01234567;
exp.D_s.lo = 0x89ABCDEF;
act = strtouv64(sp, &ep, 16);
- TEST_ASSERT_TRUE(IsEqual(exp, act));
+ TEST_ASSERT_TRUE(IsEqual(&exp, &act));
TEST_ASSERT_EQUAL(*ep, '\0');
}
-TEST_GROUP_RUNNER(vi64) {
- RUN_TEST_CASE(vi64, ParseVUI64_pos);
- RUN_TEST_CASE(vi64, ParseVUI64_neg);
- RUN_TEST_CASE(vi64, ParseVUI64_case);
+TEST_GROUP_RUNNER(vi64ops) {
+ RUN_TEST_CASE(vi64ops, ParseVUI64_pos);
+ RUN_TEST_CASE(vi64ops, ParseVUI64_neg);
+ RUN_TEST_CASE(vi64ops, ParseVUI64_case);
}
=====================================
tests/wscript
=====================================
--- a/tests/wscript
+++ b/tests/wscript
@@ -55,7 +55,7 @@ def build(ctx):
# "libntp/calendar.c",
# "libntp/caljulian.c",
# "libntp/caltontp.c",
-# "libntp/calyearstart.c",
+ "libntp/calyearstart.c",
# "libntp/clocktime.c",
# "libntp/decodenetnum.c",
# "libntp/hextolfp.c",
@@ -80,14 +80,14 @@ def build(ctx):
# "libntp/timevalops.c",
"libntp/tstotv.c",
"libntp/tvtots.c",
-# "libntp/vi64ops.c",
+ "libntp/vi64ops.c",
# "libntp/ymd2yd.c"
- ] + common_source
+ ] + common_source + ["common/caltime.c"]
ctx.ntp_test(
features = "c cprogram bld_include src_include libisc_include test",
target = "test_libntp",
- defines = ["TEST_LIBNTP_SSL"],
+ defines = ["TEST_LIBNTP=1"],
includes = [
"%s/tests/unity/" % srcnode,
"%s/tests/libntp/" % srcnode,
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/92ecea22056735e1b962793368966e2286249f3b...bce7a4b7ddbd1998c367be12f19a5d73d27cb90e
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151124/bed72114/attachment.html>
More information about the vc
mailing list