[Git][NTPsec/ntpsec][master] 2 commits: Convert libntp/humandate.c

Amar Takhar gitlab at mg.gitlab.com
Fri Dec 4 19:03:31 UTC 2015


Amar Takhar pushed to branch master at NTPsec / ntpsec


Commits:
a26e3a0a by Amar Takhar at 2015-12-04T13:55:04Z
Convert libntp/humandate.c

- - - - -
d013bd51 by Amar Takhar at 2015-12-04T14:02:38Z
For loop initial declarations are in C99.

- - - - -


4 changed files:

- tests/common/tests_main.c
- tests/libntp/calendar.c
- tests/libntp/humandate.c
- tests/wscript


Changes:

=====================================
tests/common/tests_main.c
=====================================
--- a/tests/common/tests_main.c
+++ b/tests/common/tests_main.c
@@ -48,7 +48,7 @@ static void RunAllTests(void)
 	RUN_TEST_GROUP(clocktime);
 	RUN_TEST_GROUP(decodenetnum);
 	RUN_TEST_GROUP(hextolfp);
-//	RUN_TEST_GROUP(humandate);
+	RUN_TEST_GROUP(humandate);
 //	RUN_TEST_GROUP(lfp);
 //	RUN_TEST_GROUP(lfptostr);
 	RUN_TEST_GROUP(modetoa);


=====================================
tests/libntp/calendar.c
=====================================
--- a/tests/libntp/calendar.c
+++ b/tests/libntp/calendar.c
@@ -120,8 +120,11 @@ static const u_short real_month_days[2][14] = {
 // intermediate results would definitely overflow and the hi DWORD of
 // the 'vint64' is definitely needed.
 TEST(calendar, DaySplitMerge) {
-	for (int32_t day = -1000000; day <= 1000000; day += 100) {
-		for (int32_t sec = -100000; sec <= 186400; sec += 10000) {
+	int32_t day;
+	int32_t sec;
+
+	for (day = -1000000; day <= 1000000; day += 100) {
+		for (sec = -100000; sec <= 186400; sec += 10000) {
 			vint64	     merge = ntpcal_dayjoin(day, sec);
 			ntpcal_split split = ntpcal_daysplit(&merge);
 			int32_t	     eday  = day;
@@ -143,7 +146,9 @@ TEST(calendar, DaySplitMerge) {
 }
 
 TEST(calendar, SplitYearDays1) {
-	for (int32_t eyd = -1; eyd <= 365; eyd++) {
+	int32_t eyd;
+
+	for (eyd = -1; eyd <= 365; eyd++) {
 		ntpcal_split split = ntpcal_split_yeardays(eyd, 0);
 		if (split.lo >= 0 && split.hi >= 0) {
 			TEST_ASSERT_GREATER_THAN(12, split.hi);
@@ -156,7 +161,9 @@ TEST(calendar, SplitYearDays1) {
 }
 
 TEST(calendar, SplitYearDays2) {
-	for (int32_t eyd = -1; eyd <= 366; eyd++) {
+	int32_t eyd;
+
+	for (eyd = -1; eyd <= 366; eyd++) {
 		ntpcal_split split = ntpcal_split_yeardays(eyd, 1);
 		if (split.lo >= 0 && split.hi >= 0) {
 			TEST_ASSERT_GREATER_THAN(12, split.hi);


=====================================
tests/libntp/humandate.c
=====================================
--- a/tests/libntp/humandate.c
+++ b/tests/libntp/humandate.c
@@ -1,10 +1,9 @@
 #include "config.h"
 #include "ntp_stdlib.h"
 
-extern "C" {
 #include "unity.h"
 #include "unity_fixture.h"
-}
+
 
 TEST_GROUP(humandate);
 
@@ -13,46 +12,36 @@ TEST_SETUP(humandate) {}
 TEST_TEAR_DOWN(humandate) {}
 
 
-#include <sstream>
-#include <string>
-
-class humandateTest : public libntptest {
-};
-
 TEST(humandate, RegularTime) {
 	time_t sample = 1276601278;
-	std::ostringstream expected;
-	struct tm;
+	char expected[255];
+
+	struct tm tmbuf;
 
-	tm* time;
+	struct tm* time;
 	time = localtime_r(&sample, &tmbuf);
 	TEST_ASSERT_TRUE(time != NULL);
 
-	expected << std::setfill('0')
-			 << std::setw(2) << time->tm_hour << ":"
-			 << std::setw(2) << time->tm_min << ":"
-			 << std::setw(2) << time->tm_sec;
+	snprintf(expected, 255, "%02d:%02d:%02d", time->tm_hour, time->tm_min, time->tm_sec);
 
-	TEST_ASSERT_EQUAL_STRING(expected.str().c_str(), humantime(sample));
+	TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
 }
 
 TEST(humandate, CurrentTime) {
 	time_t sample;
-	std::ostringstream expected;
-	struct tm;
+	char expected[255];
+
+	struct tm tmbuf;
 
 	time(&sample);
 
-	tm* time;
+	struct tm* time;
 	time = localtime_r(&sample, &tmbuf);
 	TEST_ASSERT_TRUE(time != NULL);
 
-	expected << std::setfill('0')
-			 << std::setw(2) << time->tm_hour << ":"
-			 << std::setw(2) << time->tm_min << ":"
-			 << std::setw(2) << time->tm_sec;
+	snprintf(expected, 255, "%02d:%02d:%02d", time->tm_hour, time->tm_min, time->tm_sec);
 
-	TEST_ASSERT_EQUAL_STRING(expected.str().c_str(), humantime(sample));
+	TEST_ASSERT_EQUAL_STRING(expected, humantime(sample));
 }
 
 TEST_GROUP_RUNNER(humandate) {


=====================================
tests/wscript
=====================================
--- a/tests/wscript
+++ b/tests/wscript
@@ -63,7 +63,7 @@ def build(ctx):
 		"libntp/clocktime.c",
 		"libntp/decodenetnum.c",
 		"libntp/hextolfp.c",
-#		"libntp/humandate.c",
+		"libntp/humandate.c",
 #		"libntp/lfpfunc.c",
 #		"libntp/lfptostr.c",
 		"libntp/modetoa.c",



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/c0ef5549f227759a99ebae150e7f0e97a263301c...d013bd510cea7a5fbf6646e08e73e3daf51c17c9
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151204/e62ee6d7/attachment.html>


More information about the vc mailing list