]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
buftvtots.c:
authorTomek Mrugalski <tomasz@isc.org>
Sat, 4 Jul 2015 11:39:28 +0000 (13:39 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Sat, 4 Jul 2015 11:39:28 +0000 (13:39 +0200)
  fix formatting, declarations before code (C90)
authkeys.c:
  fixed formatting, removed unnecessary comment
calendar.c:
  further cleanup: deleted unnecessary comments, made first declaration, then code
clocktime.c:
  removed comments, fixed formatting
a_md5encrypt.c:
  fix formatting, add (void) as argument to a function etc
caltontp.c:
  fixed the order of #includes
run-buftvtots.c, run-a_md5encrypt.c:
  adding autogenerated file
calendar.c:
  deleted comments, fixed formatting, used snprintf instead of sprintf, change variable names to be meaningful,
caljulian.c:
  changed sprintf to snprintf, fixed formatting etc
a_md5encrypt.c:
  changed to first declaration, then code (C90 compatibility)
Many files:
  autogenerated
authkeys.c:
  further changes of formatting

bk: 5597c5f0dHomXzdFvCD5asldJNf-rQ

14 files changed:
tests/libntp/a_md5encrypt.c
tests/libntp/authkeys.c
tests/libntp/buftvtots.c
tests/libntp/calendar.c
tests/libntp/caljulian.c
tests/libntp/caltontp.c
tests/libntp/clocktime.c
tests/libntp/run-a_md5encrypt.c
tests/libntp/run-authkeys.c
tests/libntp/run-buftvtots.c
tests/libntp/run-calendar.c
tests/libntp/run-caljulian.c
tests/libntp/run-caltontp.c
tests/libntp/run-clocktime.c

index 0b748dcdeaac144b0c37f9a7850119e6971065da..70a872174be4cd66728119e641d8eabab5348110 100644 (file)
 u_long current_time = 4;
 
 
-void setUp(void)
-{
-}
-
-void tearDown(void)
-{
-}
-
 /*
  * Example packet with MD5 hash calculated manually.
  */
@@ -27,38 +19,43 @@ const int keytype = KEY_TYPE_MD5;
 const char *key = "abcdefgh";
 const u_short keyLength = 8;
 const char *packet = "ijklmnopqrstuvwx";
-#define packetLength 16                //const int packetLength = 16;
-#define keyIdLength  4         //const int keyIdLength = 4;
-#define digestLength 16                //const int digestLength = 16;
+#define packetLength 16
+#define keyIdLength  4
+#define digestLength 16
 const int totalLength = packetLength + keyIdLength + digestLength;
 const char *expectedPacket = "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\xa8\x68\x8e\x52\x38\xdb\xbc\x1c\x39\x53";
 
-void test_Encrypt() {
-       char *packetPtr = malloc(totalLength*sizeof(*packetPtr)); //new char[totalLength];
+void
+test_Encrypt(void) {
+       char *packetPtr;
+       int length;
+
+       packetPtr = malloc(totalLength * sizeof(*packetPtr));
 
-       memset(packetPtr+packetLength, 0, keyIdLength);
+       memset(packetPtr + packetLength, 0, keyIdLength);
        memcpy(packetPtr, packet, packetLength);
 
        cache_secretsize = keyLength;
 
-       int length = MD5authencrypt(keytype, (u_char*)key, (u_int32*)packetPtr, packetLength);
+       length = MD5authencrypt(keytype, (u_char*)key, (u_int32*)packetPtr, packetLength);
 
        TEST_ASSERT_TRUE(MD5authdecrypt(keytype, (u_char*)key, (u_int32*)packetPtr, packetLength, length));
 
        TEST_ASSERT_EQUAL(20, length);
-       //TEST_ASSERT_TRUE(memcmp(expectedPacket, packetPtr, totalLength) == 0);
        TEST_ASSERT_EQUAL_MEMORY(expectedPacket, packetPtr, totalLength);
 
-       free(packetPtr); //delete[] packetPtr;
+       free(packetPtr);
 }
 
-void test_DecryptValid() {
+void
+test_DecryptValid(void) {
        cache_secretsize = keyLength;
 
        TEST_ASSERT_TRUE(MD5authdecrypt(keytype, (u_char*)key, (u_int32*)expectedPacket, packetLength, 20));
 }
 
-void test_DecryptInvalid() {
+void
+test_DecryptInvalid(void) {
        cache_secretsize = keyLength;
 
        const char *invalidPacket = "ijklmnopqrstuvwx\0\0\0\0\x0c\x0e\x84\xcf\x0b\xb7\xa8\x68\x8e\x52\x38\xdb\xbc\x1c\x39\x54";
@@ -66,18 +63,22 @@ void test_DecryptInvalid() {
        TEST_ASSERT_FALSE(MD5authdecrypt(keytype, (u_char*)key, (u_int32*)invalidPacket, packetLength, 20));
 }
 
-void test_IPv4AddressToRefId() {
+void
+test_IPv4AddressToRefId(void) {
        sockaddr_u addr;
        addr.sa4.sin_family = AF_INET;
+       u_int32 address;
+
        addr.sa4.sin_port = htons(80);
 
-       u_int32 address = inet_addr("192.0.2.1");
+       address = inet_addr("192.0.2.1");
        addr.sa4.sin_addr.s_addr = address;
 
        TEST_ASSERT_EQUAL(address, addr2refid(&addr));
 }
 
-void test_IPv6AddressToRefId() {
+void
+test_IPv6AddressToRefId(void) {
        const struct in6_addr address = {
                0x20, 0x01, 0x0d, 0xb8,
                0x85, 0xa3, 0x08, 0xd3,
index b949628da3bd054a6f559614dad4020af943cb89..40fb0c576e2ffa2922edb79bb587c8849f04b3f1 100644 (file)
@@ -18,15 +18,14 @@ u_long current_time = 4;
 int counter = 0;
 
 
-// old code from google test framework, moved to SetUp() for unity
-void setUp(void)
+void
+setUp(void)
 { 
-//     init_lib();
-       if(counter ==0){
-       counter++;
-       init_auth(); //causes segfault if called more than once
+       if (counter == 0) {
+               counter++;
+               init_auth(); // causes segfault if called more than once
        }
-/*
+       /*
         * init_auth() is called by tests_main.cpp earlier.  It
         * does not initialize global variables like
         * authnumkeys, so let's reset them to zero here.
@@ -41,20 +40,18 @@ void setUp(void)
        cache_flags = 0;
        cache_secret = NULL;
        cache_secretsize = 0;
-
 }
 
-void tearDown(void)
+void
+tearDown(void)
 {
-}
 
+}
 
 static const int KEYTYPE = KEY_TYPE_MD5;
 
-
-
-
-void AddTrustedKey(keyid_t keyno) {
+void
+AddTrustedKey(keyid_t keyno) {
        /*
         * We need to add a MD5-key in addition to setting the
         * trust, because authhavekey() requires type != 0.
@@ -64,11 +61,13 @@ void AddTrustedKey(keyid_t keyno) {
        authtrust(keyno, TRUE);
 }
 
-void AddUntrustedKey(keyid_t keyno) {
+void
+AddUntrustedKey(keyid_t keyno) {
        authtrust(keyno, FALSE);
 }
 
-void test_AddTrustedKeys() {
+void
+test_AddTrustedKeys() {
        const keyid_t KEYNO1 = 5;
        const keyid_t KEYNO2 = 8;
 
@@ -79,7 +78,8 @@ void test_AddTrustedKeys() {
        TEST_ASSERT_TRUE(authistrusted(KEYNO2));
 }
 
-void test_AddUntrustedKey() {
+void
+test_AddUntrustedKey() {
        const keyid_t KEYNO = 3;
    
        AddUntrustedKey(KEYNO);
@@ -87,7 +87,8 @@ void test_AddUntrustedKey() {
        TEST_ASSERT_FALSE(authistrusted(KEYNO));
 }
 
-void test_HaveKeyCorrect() {
+void
+test_HaveKeyCorrect() {
        const keyid_t KEYNO = 3;
 
        AddTrustedKey(KEYNO);
@@ -96,21 +97,24 @@ void test_HaveKeyCorrect() {
        TEST_ASSERT_TRUE(authhavekey(KEYNO));
 }
 
-void test_HaveKeyIncorrect() {
+void
+test_HaveKeyIncorrect() {
        const keyid_t KEYNO = 2;
 
        TEST_ASSERT_FALSE(auth_havekey(KEYNO));
        TEST_ASSERT_FALSE(authhavekey(KEYNO));
 }
 
-void test_AddWithAuthUseKey() {
+void
+test_AddWithAuthUseKey() {
        const keyid_t KEYNO = 5;
        const char* KEY = "52a";
 
        TEST_ASSERT_TRUE(authusekey(KEYNO, KEYTYPE, (u_char*)KEY));     
 }
 
-void test_EmptyKey() {
+void
+test_EmptyKey() {
        const keyid_t KEYNO = 3;
        const char* KEY = "";
 
index edeedf63ad2b289e2647c5816e34f677ba378043..875766e63dbf4189365b6d456b9115889bd9adaf 100644 (file)
@@ -13,7 +13,8 @@
 
 
 
-void test_ZeroBuffer() {
+void
+test_ZeroBuffer(void) {
 #ifndef SYS_WINNT
        const struct timeval input = {0, 0};
        const l_fp expected = {0 + JAN_1970, 0};
@@ -27,11 +28,12 @@ void test_ZeroBuffer() {
 #endif
 }
 
-void test_IntegerAndFractionalBuffer() {
+void
+test_IntegerAndFractionalBuffer(void) {
 #ifndef SYS_WINNT
        const struct timeval input = {5, 500000}; // 5.5
        const l_fp expected = {5 + JAN_1970, HALF};
-
+       double expectedDouble, actualDouble;
        l_fp actual;
 
        TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual));
@@ -39,18 +41,18 @@ void test_IntegerAndFractionalBuffer() {
        // Compare the fractional part with an absolute error given.
        TEST_ASSERT_EQUAL(expected.l_ui, actual.l_ui);
 
-       double expectedDouble, actualDouble;
        M_LFPTOD(0, expected.l_uf, expectedDouble);
        M_LFPTOD(0, actual.l_uf, actualDouble);
 
        // The error should be less than 0.5 us
-       TEST_ASSERT_DOUBLE_WITHIN(0.0000005,expectedDouble,actualDouble);  //delta,epected,actual //_EXPECT_NEAR(expectedDouble, actualDouble, 0.0000005);
+       TEST_ASSERT_DOUBLE_WITHIN(0.0000005, expectedDouble, actualDouble);
 #else
        TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
 #endif
 }
 
-void test_IllegalMicroseconds() {
+void
+test_IllegalMicroseconds(void) {
 #ifndef SYS_WINNT
        const struct timeval input = {0, 1100000}; // > 999 999 microseconds.
        
@@ -63,7 +65,8 @@ void test_IllegalMicroseconds() {
 }
 
 
-void test_AlwaysFalseOnWindows() {
+void
+test_AlwaysFalseOnWindows(void) {
 #ifdef SYS_WINNT
        /*
         * Under Windows, buftvtots will just return
index 4ac1df469c7050e28800e991ab73bb00bbbd8749..016e384e2d6249c378590021340098018dcd066a 100644 (file)
@@ -4,25 +4,21 @@
 #include "ntp_calendar.h"
 #include "unity.h"
 
-//#include "test-libntp.h"
-
-
 #include <string.h>
-//#include <sstream>
 
 static int leapdays(int year);
 
 char * CalendarFromCalToString(const struct calendar cal); //&
 char * CalendarFromIsoToString(const struct isodate iso); //&
 
-//tehnically, booleans
+// technically, booleans
 int IsEqualCal(const struct calendar expected, const struct calendar actual);  //&&
 int IsEqualIso(const struct isodate expected, const struct isodate actual); //&&
 
 char * DateFromCalToStringCal(const struct calendar cal); //&
 char * DateFromIsoToStringIso(const struct isodate iso); //&
 
-//tehnically, booleans
+// technically, booleans
 int sEqualDateCal(const struct calendar expected, const struct calendar actual); //&&
 int IsEqualDateIso(const struct isodate expected, const struct isodate actual); //&&
 
@@ -32,19 +28,17 @@ int IsEqualDateIso(const struct isodate expected, const struct isodate actual);
 // test support stuff
 // ---------------------------------------------------------------------
 
-//function which, in combination with TEST_ASSERT_TRUE replaces google test framework's EXPECT_GT(a,b); -> GT means Greather Than
-//boolean
-int isGT(int first,int second){
-       if(first > second){
-       
-       return TRUE;
+int
+isGT(int first, int second){
+       if(first > second) {    
+               return TRUE;
+       } else {
+               return FALSE;
        }
-
-       else return FALSE;
 }
 
-
-int leapdays(int year)
+int
+leapdays(int year)
 {
        if (year % 400 == 0)
                return 1;
@@ -55,62 +49,63 @@ int leapdays(int year)
        return 0;
 }
 
-char * CalendarFromCalToString(const struct calendar cal) { //&
-       char * ss = malloc (sizeof (char) * 100);
+char *
+CalendarFromCalToString(const struct calendar cal) { //&
+       char * str = malloc (sizeof (char) * 100);
        
        char buffer[100] ="";
-       sprintf(buffer, "%u", cal.year);
-       strcat(ss,buffer);
-       strcat(ss,"-");
-       sprintf(buffer, "%u", (u_int)cal.month);
-       strcat(ss,buffer);
-       strcat(ss,"-");
-       sprintf(buffer, "%u", (u_int)cal.monthday);
-       strcat(ss,buffer);
-       strcat(ss," (");
-       sprintf(buffer, "%u", cal.yearday);
-       strcat(ss,buffer);
-       strcat(ss,") ");
-       sprintf(buffer, "%u", (u_int)cal.hour);
-       strcat(ss,buffer);
-       strcat(ss,":");
-       sprintf(buffer, "%u", (u_int)cal.minute);
-       strcat(ss,buffer);
-       strcat(ss,":");
-       sprintf(buffer, "%u", (u_int)cal.second);
-       strcat(ss,buffer);
-       //ss << cal.year << "-" << (u_int)cal.month << "-" << (u_int)cal.monthday << " (" << cal.yearday << ") " << (u_int)cal.hour << ":" << (u_int)cal.minute << ":" << (u_int)cal.second;
-       return ss;      
-
+       snprintf(buffer, 100, "%u", cal.year);
+       strcat(str, buffer);
+       strcat(str, "-");
+       snprintf(buffer, 100, "%u", (u_int)cal.month);
+       strcat(str, buffer);
+       strcat(str, "-");
+       snprintf(buffer, 100, "%u", (u_int)cal.monthday);
+       strcat(str, buffer);
+       strcat(str, " (");
+       snprintf(buffer, 100, "%u", cal.yearday);
+       strcat(str, buffer);
+       strcat(str, ") ");
+       snprintf(buffer, 100, "%u", (u_int)cal.hour);
+       strcat(str, buffer);
+       strcat(str, ":");
+       snprintf(buffer, 100, "%u", (u_int)cal.minute);
+       strcat(str, buffer);
+       strcat(str, ":");
+       snprintf(buffer, 100, "%u", (u_int)cal.second);
+       strcat(str, buffer);
+
+       return str;
 }
 
-char * CalendarFromIsoToString(const struct isodate iso) { //&
+char *
+CalendarFromIsoToString(const struct isodate iso) { //&
 
-       char * ss = malloc (sizeof (char) * 100);
+       char * str = malloc (sizeof (char) * 100);
        
        char buffer[100] ="";
-       sprintf(buffer, "%u", iso.year);
-       strcat(ss,buffer);
-       strcat(ss,"-");
-       sprintf(buffer, "%u", (u_int)iso.week);
-       strcat(ss,buffer);
-       strcat(ss,"-");
-       sprintf(buffer, "%u", (u_int)iso.weekday);
-       strcat(ss,buffer);
-       sprintf(buffer, "%u", (u_int)iso.hour);
-       strcat(ss,buffer);
-       strcat(ss,":");
-       sprintf(buffer, "%u", (u_int)iso.minute);
-       strcat(ss,buffer);
-       strcat(ss,":");
-       sprintf(buffer, "%u", (u_int)iso.second);
-       strcat(ss,buffer);
-       //ss << iso.year << "-" << (u_int)iso.week << "-" << (u_int)iso.weekday << (u_int)iso.hour << ":" << (u_int)iso.minute << ":" << (u_int)iso.second;     
-       return ss;      
-
+       snprintf(buffer, 100, "%u", iso.year);
+       strcat(str, buffer);
+       strcat(str, "-");
+       snprintf(buffer, 100, "%u", (u_int)iso.week);
+       strcat(str, buffer);
+       strcat(str, "-");
+       snprintf(buffer, 100, "%u", (u_int)iso.weekday);
+       strcat(str, buffer);
+       snprintf(buffer, 100, "%u", (u_int)iso.hour);
+       strcat(str, buffer);
+       strcat(str, ":");
+       snprintf(buffer, 100, "%u", (u_int)iso.minute);
+       strcat(str, buffer);
+       strcat(str, ":");
+       snprintf(buffer, 100, "%u", (u_int)iso.second);
+       strcat(str, buffer);
+
+       return str;
 }
 
-int IsEqualCal(const struct calendar expected, const struct calendar actual) { //&&
+int
+IsEqualCal(const struct calendar expected, const struct calendar actual) { //&&
        if (expected.year == actual.year &&
            (!expected.yearday || expected.yearday == actual.yearday) &&
            expected.month == actual.month &&
@@ -125,7 +120,8 @@ int IsEqualCal(const struct calendar expected, const struct calendar actual) { /
        }
 }
 
-int IsEqualIso(const struct isodate expected, const struct isodate actual) { //&&
+int
+IsEqualIso(const struct isodate expected, const struct isodate actual) { //&&
        if (expected.year == actual.year &&
            expected.week == actual.week &&
            expected.weekday == actual.weekday &&
@@ -139,49 +135,49 @@ int IsEqualIso(const struct isodate expected, const struct isodate actual) { //&
        }
 }
 
-char * DateFromCalToString(const struct calendar cal) { //&
+char *
+DateFromCalToString(const struct calendar cal) { //&
 
-       char * ss = malloc (sizeof (char) * 100);
+       char * str = malloc (sizeof (char) * 100);
        
        char buffer[100] ="";
-       sprintf(buffer, "%u", cal.year);
-       strcat(ss,buffer);
-       strcat(ss,"-");
-       sprintf(buffer, "%u", (u_int)cal.month);
-       strcat(ss,buffer);
-       strcat(ss,"-");
-       sprintf(buffer, "%u", (u_int)cal.monthday);
-       strcat(ss,buffer);
-       strcat(ss," (");
-       sprintf(buffer, "%u", cal.yearday);
-       strcat(ss,buffer);
-       strcat(ss,")");
+       snprintf(buffer, 100, "%u", cal.year);
+       strcat(str, buffer);
+       strcat(str, "-");
+       snprintf(buffer, 100, "%u", (u_int)cal.month);
+       strcat(str, buffer);
+       strcat(str, "-");
+       snprintf(buffer, 100, "%u", (u_int)cal.monthday);
+       strcat(str, buffer);
+       strcat(str, " (");
+       snprintf(buffer, 100, "%u", cal.yearday);
+       strcat(str, buffer);
+       strcat(str, ")");
        
-       return ss;
-       //ss << cal.year << "-" << (u_int)cal.month << "-" << (u_int)cal.monthday << " (" << cal.yearday << ")";
+       return str;
 }
 
-char * DateFromIsoToString(const struct isodate iso) { //&
+char *
+DateFromIsoToString(const struct isodate iso) { //&
 
-       char * ss = malloc (sizeof (char) * 100);
+       char * str = malloc (sizeof (char) * 100);
        
        char buffer[100] ="";
-       sprintf(buffer, "%u", iso.year);
-       strcat(ss,buffer);
-       strcat(ss,"-");
-       sprintf(buffer, "%u", (u_int)iso.week);
-       strcat(ss,buffer);
-       strcat(ss,"-");
-       sprintf(buffer, "%u", (u_int)iso.weekday);
-       strcat(ss,buffer);
-
-       return ss;
-       //ss << iso.year << "-" << (u_int)iso.week << "-" << (u_int)iso.weekday;
-       
+       snprintf(buffer, 100, "%u", iso.year);
+       strcat(str, buffer);
+       strcat(str, "-");
+       snprintf(buffer, 100, "%u", (u_int)iso.week);
+       strcat(str, buffer);
+       strcat(str, "-");
+       snprintf(buffer, 100, "%u", (u_int)iso.weekday);
+       strcat(str, buffer);
+
+       return str;
 }
 
-//boolean 
-int IsEqualDateCal(const struct calendar expected, const struct calendar actual) { //&&
+// boolean 
+int
+IsEqualDateCal(const struct calendar expected, const struct calendar actual) { //&&
        if (expected.year == actual.year &&
            (!expected.yearday || expected.yearday == actual.yearday) &&
            expected.month == actual.month &&
@@ -193,8 +189,9 @@ int IsEqualDateCal(const struct calendar expected, const struct calendar actual)
        }
 }
 
-//boolean
-int IsEqualDateIso(const struct isodate expected, const struct isodate actual) { //&&
+// boolean
+int
+IsEqualDateIso(const struct isodate expected, const struct isodate actual) { //&&
        if (expected.year == actual.year &&
            expected.week == actual.week &&
            expected.weekday == actual.weekday) {
@@ -227,14 +224,20 @@ static const u_short real_month_days[2][14] = {
 // test the day/sec join & split ops, making sure that 32bit
 // intermediate results would definitely overflow and the hi DWORD of
 // the 'vint64' is definitely needed.
-void test_DaySplitMerge() {
+void
+test_DaySplitMerge(void) {
        int32 day,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        eday  = day;
-                       int32        esec  = sec;
+                       vint64           merge;
+                       ntpcal_split split;
+                       int32            eday;
+                       int32            esec;
+
+                       merge = ntpcal_dayjoin(day, sec);
+                       split = ntpcal_daysplit(&merge);
+                       eday  = day;
+                       esec  = sec;
 
                        while (esec >= 86400) {
                                eday += 1;
@@ -251,13 +254,14 @@ void test_DaySplitMerge() {
        }
 }
 
-void test_SplitYearDays1() {
+void
+test_SplitYearDays1(void) {
        int32 eyd;
        for (eyd = -1; eyd <= 365; eyd++) {
                ntpcal_split split = ntpcal_split_yeardays(eyd, 0);
                if (split.lo >= 0 && split.hi >= 0) {
-                       TEST_ASSERT_TRUE(isGT(12,split.hi));//EXPECT_GT(12, split.hi);
-                       TEST_ASSERT_TRUE(isGT(real_month_days[0][split.hi+1], split.lo));//EXPECT_GT(real_month_days[0][split.hi+1], split.lo);
+                       TEST_ASSERT_TRUE(isGT(12,split.hi));
+                       TEST_ASSERT_TRUE(isGT(real_month_days[0][split.hi+1], split.lo));
                        int32 tyd = real_month_table[0][split.hi] + split.lo;
                        TEST_ASSERT_EQUAL(eyd, tyd);
                } else
@@ -265,7 +269,8 @@ void test_SplitYearDays1() {
        }
 }
                
-void test_SplitYearDays2() {
+void
+test_SplitYearDays2(void) {
        int32 eyd;
        for (eyd = -1; eyd <= 366; eyd++) {
                ntpcal_split split = ntpcal_split_yeardays(eyd, 1);
@@ -280,7 +285,8 @@ void test_SplitYearDays2() {
                }
 }
                
-void test_RataDie1() {
+void
+test_RataDie1(void) {
        int32    testDate = 1; // 0001-01-01 (proleptic date)
        struct calendar expected = { 1, 1, 1, 1 };
        struct calendar actual;
@@ -290,7 +296,8 @@ void test_RataDie1() {
 }
 
 // check last day of february for first 10000 years
-void test_LeapYears1() {
+void
+test_LeapYears1(void) {
        struct calendar dateIn, dateOut;
 
        for (dateIn.year = 1; dateIn.year < 10000; ++dateIn.year) {
@@ -305,7 +312,8 @@ void test_LeapYears1() {
 }
 
 // check first day of march for first 10000 years
-void test_LeapYears2() {
+void
+test_LeapYears2(void) {
        struct calendar dateIn, dateOut;
 
        for (dateIn.year = 1; dateIn.year < 10000; ++dateIn.year) {
@@ -323,10 +331,11 @@ void test_LeapYears2() {
 // (since the input is all nominal days of the calendar in that range
 // and the result of the inverse calculation must match the input no
 // invalid output can occur.)
-void test_RoundTripDate() {
+void
+test_RoundTripDate(void) {
        struct calendar truDate, expDate = { 1600, 0, 12, 31 };;
-       int32    truRdn, expRdn = ntpcal_date_to_rd(&expDate);
        int      leaps;
+       int32    truRdn, expRdn = ntpcal_date_to_rd(&expDate);
 
        while (expDate.year < 2400) {
                expDate.year++;
@@ -352,7 +361,8 @@ void test_RoundTripDate() {
 }
 
 // Roundtrip testing on calyearstart
-void test_RoundTripYearStart() {
+void
+test_RoundTripYearStart(void) {
        static const time_t pivot = 0;
        u_int32 ntp, expys, truys;
        struct calendar date;
@@ -368,7 +378,8 @@ void test_RoundTripYearStart() {
 }      
 
 // Roundtrip testing on calymonthstart
-void test_RoundTripMonthStart() {
+void
+test_RoundTripMonthStart(void) {
        static const time_t pivot = 0;
        u_int32 ntp, expms, trums;
        struct calendar date;
@@ -384,7 +395,8 @@ void test_RoundTripMonthStart() {
 }      
 
 // Roundtrip testing on calweekstart
-void test_RoundTripWeekStart() {
+void
+test_RoundTripWeekStart(void) {
        static const time_t pivot = 0;
        u_int32 ntp, expws, truws;
        struct isodate date;
@@ -400,7 +412,8 @@ void test_RoundTripWeekStart() {
 }      
 
 // Roundtrip testing on caldaystart
-void test_RoundTripDayStart() {
+void
+test_RoundTripDayStart(void) {
        static const time_t pivot = 0;
        u_int32 ntp, expds, truds;
        struct calendar date;
@@ -413,4 +426,3 @@ void test_RoundTripDayStart() {
                TEST_ASSERT_EQUAL(expds, truds);
        }
 }      
-
index 907f25d86edc7f5722e9589ff0e2de21aa18bc37..c2f7b175521864b48821265f82bc1aef7f047213 100644 (file)
@@ -2,46 +2,43 @@
 
 #include "ntp_calendar.h"
 #include "ntp_stdlib.h"
-#include "unity.h"
 
+#include "unity.h"
 #include "test-libntp.h"
 
-
 #include <string.h>
-//#include <stdlib.h>
 
-//added struct to calendar!
 
-char * CalendarToString(const struct calendar cal) {
-       char * ss = malloc (sizeof (char) * 100);
+char *
+CalendarToString(const struct calendar cal) {
+       char * str = malloc (sizeof (char) * 100);
        
        char buffer[100] ="";
-       sprintf(buffer, "%u", cal.year);
-       strcat(ss,buffer);
-       strcat(ss,"-");
-       sprintf(buffer, "%u", (u_int)cal.month);
-       strcat(ss,buffer);
-       strcat(ss,"-");
-       sprintf(buffer, "%u", (u_int)cal.monthday);
-       strcat(ss,buffer);
-       strcat(ss," (");
-       sprintf(buffer, "%u", (u_int) cal.yearday);
-       strcat(ss,buffer);
-       strcat(ss,") ");
-       sprintf(buffer, "%u", (u_int)cal.hour);
-       strcat(ss,buffer);
-       strcat(ss,":");
-       sprintf(buffer, "%u", (u_int)cal.minute);
-       strcat(ss,buffer);
-       strcat(ss,":");
-       sprintf(buffer, "%u", (u_int)cal.second);
-       strcat(ss,buffer);
-       //ss << cal.year << "-" << (u_int)cal.month << "-" << (u_int)cal.monthday << " (" << cal.yearday << ") " << (u_int)cal.hour << ":" << (u_int)cal.minute << ":" << (u_int)cal.second;
-       return ss;
+       snprintf(buffer, 100, "%u", cal.year);
+       strcat(str, buffer);
+       strcat(str, "-");
+       snprintf(buffer, 100, "%u", (u_int)cal.month);
+       strcat(str, buffer);
+       strcat(str, "-");
+       snprintf(buffer, 100, "%u", (u_int)cal.monthday);
+       strcat(str, buffer);
+       strcat(str, " (");
+       snprintf(buffer, 100, "%u", (u_int) cal.yearday);
+       strcat(str, buffer);
+       strcat(str, ") ");
+       snprintf(buffer, 100, "%u", (u_int)cal.hour);
+       strcat(str, buffer);
+       strcat(str, ":");
+       snprintf(buffer, 100, "%u", (u_int)cal.minute);
+       strcat(str, buffer);
+       strcat(str, ":");
+       snprintf(buffer, 100, "%u", (u_int)cal.second);
+       strcat(str, buffer);
+       return str;
 }
 
-//tehnically boolean
-int IsEqual(const struct calendar expected, const struct calendar actual) {
+int // technically boolean
+IsEqual(const struct calendar expected, const struct calendar actual) {
        if (expected.year == actual.year &&
                (expected.yearday == actual.yearday ||
                 (expected.month == actual.month &&
@@ -58,20 +55,22 @@ int IsEqual(const struct calendar expected, const struct calendar actual) {
 }
 
 
-void setUp()
+void
+setUp()
 {
-
     ntpcal_set_timefunc(timefunc);
     settime(1970, 1, 1, 0, 0, 0);
 }
 
-void tearDown()
+void
+tearDown()
 {
     ntpcal_set_timefunc(NULL);
 }
 
 
-void test_RegularTime() {
+void
+test_RegularTime(void) {
        u_long testDate = 3485080800UL; // 2010-06-09 14:00:00
        struct calendar expected = {2010,160,6,9,14,0,0};
 
@@ -82,7 +81,8 @@ void test_RegularTime() {
        TEST_ASSERT_TRUE(IsEqual(expected, actual));
 }
 
-void test_LeapYear() {
+void
+test_LeapYear(void) {
        u_long input = 3549902400UL; // 2012-06-28 20:00:00Z
        struct calendar expected = {2012, 179, 6, 28, 20, 0, 0};
 
@@ -93,7 +93,8 @@ void test_LeapYear() {
        TEST_ASSERT_TRUE(IsEqual(expected, actual));
 }
 
-void test_uLongBoundary() {
+void
+test_uLongBoundary(void) {
        u_long time = 4294967295UL; // 2036-02-07 6:28:15
        struct calendar expected = {2036,0,2,7,6,28,15};
 
@@ -104,7 +105,8 @@ void test_uLongBoundary() {
        TEST_ASSERT_TRUE(IsEqual(expected, actual));
 }
 
-void test_uLongWrapped() {
+void
+test_uLongWrapped(void) {
        u_long time = 0;
        struct calendar expected = {2036,0,2,7,6,28,16};
 
index 9ce4854405029616105994c5aea36faf815e2ac3..bdbfbfc7a36c9cf57a9d45968b6cd49289c62cd5 100644 (file)
@@ -1,6 +1,6 @@
 #include "config.h"
-#include "unity.h"
 #include "ntp_calendar.h"
+#include "unity.h"
 
 void
 test_DateGivenMonthDay(void) {
index a9c0fec82648a8b8d58e1f260da37510f4805696..f1d0726671591e4d34c1f886a1a22fdafdaf684a 100644 (file)
 // dependent on the actual system time.
 
 
-void setUp()
+void
+setUp()
 {
     ntpcal_set_timefunc(timefunc);
     settime(2000, 1, 1, 0, 0, 0);
 }
 
-void tearDown()
+void
+tearDown()
 {
     ntpcal_set_timefunc(NULL);
 }
@@ -29,7 +31,8 @@ void tearDown()
 // ---------------------------------------------------------------------
 // test cases
 
-void test_CurrentYear() {
+void
+test_CurrentYear(void) {
        // Timestamp: 2010-06-24 12:50:00Z
        const u_int32 timestamp = 3486372600UL;
        const u_int32 expected  = timestamp; // exactly the same.
@@ -44,7 +47,8 @@ void test_CurrentYear() {
        TEST_ASSERT_EQUAL(expected, actual);
 }
 
-void test_CurrentYearFuzz() {
+void
+test_CurrentYearFuzz(void) {
        /* 
         * Timestamp (rec_ui) is: 2010-06-24 12:50:00
         * Time sent into function is 12:00:00.
@@ -66,7 +70,8 @@ void test_CurrentYearFuzz() {
        TEST_ASSERT_EQUAL(expected, actual);
 }
 
-void test_TimeZoneOffset() {
+void
+test_TimeZoneOffset(void) {
        /*
         * Timestamp (rec_ui) is: 2010-06-24 12:00:00 +0800
         * (which is 2010-06-24 04:00:00Z)
@@ -86,7 +91,8 @@ void test_TimeZoneOffset() {
        TEST_ASSERT_EQUAL(expected, actual);
 }
 
-void test_WrongYearStart() {
+void
+test_WrongYearStart(void) {
        /* 
         * Timestamp (rec_ui) is: 2010-01-02 11:00:00Z
         * Time sent into function is 11:00:00.
@@ -105,7 +111,8 @@ void test_WrongYearStart() {
        TEST_ASSERT_EQUAL(expected, actual);
 }
 
-void test_PreviousYear() {
+void
+test_PreviousYear(void) {
        /*
         * Timestamp is: 2010-01-01 01:00:00Z
         * Time sent into function is 23:00:00
@@ -124,7 +131,8 @@ void test_PreviousYear() {
        TEST_ASSERT_EQUAL(expected, actual);
 }
 
-void test_NextYear() {
+void
+test_NextYear(void) {
        /*
         * Timestamp is: 2009-12-31 23:00:00Z
         * Time sent into function is 01:00:00
@@ -142,7 +150,8 @@ void test_NextYear() {
        TEST_ASSERT_EQUAL(expected, actual);
 }
 
-void test_NoReasonableConversion() {
+void
+test_NoReasonableConversion(void) {
        /* Timestamp is: 2010-01-02 11:00:00Z */
        const u_int32 timestamp = 3471418800UL;
        
@@ -154,9 +163,9 @@ void test_NoReasonableConversion() {
                                                   &yearstart, &actual));
 }
 
-// *** FUNCTION isLE, to simulate gtest's ASSERT_LE using Unity's TEST_ASSERT_TRUE
-//tehnically boolean
-int isLE(u_int32 diff,u_int32 actual){
+
+int // technically boolean
+isLE(u_int32 diff,u_int32 actual){
        if(diff <= actual){
                return TRUE;
        }
@@ -164,7 +173,8 @@ int isLE(u_int32 diff,u_int32 actual){
 }
 
 
-void test_AlwaysInLimit() {
+void
+test_AlwaysInLimit(void) {
        /* Timestamp is: 2010-01-02 11:00:00Z */
        const u_int32 timestamp = 3471418800UL;
        const u_short prime_incs[] = { 127, 151, 163, 179 };
@@ -192,8 +202,7 @@ void test_AlwaysInLimit() {
                                        diff = actual - timestamp;
                                        if (diff >= 0x80000000UL)
                                                diff = ~diff + 1;
-                                       TEST_ASSERT_TRUE(isLE(diff, (183u * SECSPERDAY))); // adding new function to return TRUE if first number is less or equal the second
-                                       //TEST_ASSERT_LE(diff, (183u * SECSPERDAY));
+                                       TEST_ASSERT_TRUE(isLE(diff, (183u * SECSPERDAY)));
                                }
                        }
                }
index a480c4a67602d85783e1678a0f4b05403bd47c19..95678d4063c3ceb3ac2396285ddb46a345cd3b49 100644 (file)
 extern void setUp(void);
 extern void tearDown(void);
 void resetTest(void);
-extern void test_Encrypt();
-extern void test_DecryptValid();
-extern void test_DecryptInvalid();
-extern void test_IPv4AddressToRefId();
-extern void test_IPv6AddressToRefId();
+extern void test_Encrypt(void);
+extern void test_DecryptValid(void);
+extern void test_DecryptInvalid(void);
+extern void test_IPv4AddressToRefId(void);
+extern void test_IPv6AddressToRefId(void);
 
 
 //=======Test Reset Option=====
@@ -50,11 +50,11 @@ int main(int argc, char *argv[])
   progname = argv[0];
   Unity.TestFile = "a_md5encrypt.c";
   UnityBegin("a_md5encrypt.c");
-  RUN_TEST(test_Encrypt, 36);
-  RUN_TEST(test_DecryptValid, 55);
-  RUN_TEST(test_DecryptInvalid, 61);
-  RUN_TEST(test_IPv4AddressToRefId, 69);
-  RUN_TEST(test_IPv6AddressToRefId, 80);
+  RUN_TEST(test_Encrypt, 29);
+  RUN_TEST(test_DecryptValid, 51);
+  RUN_TEST(test_DecryptInvalid, 58);
+  RUN_TEST(test_IPv4AddressToRefId, 67);
+  RUN_TEST(test_IPv6AddressToRefId, 81);
 
   return (UnityEnd());
 }
index 5e65cc9dc517e6fbf872f0461dd2a0de3a07c0f1..b70bd627a294cbaa8d92ced302c008cb4000c9ad 100644 (file)
@@ -26,6 +26,7 @@
 //=======External Functions This Runner Calls=====
 extern void setUp(void);
 extern void tearDown(void);
+void resetTest(void);
 extern void test_AddTrustedKeys();
 extern void test_AddUntrustedKey();
 extern void test_HaveKeyCorrect();
@@ -50,12 +51,12 @@ int main(int argc, char *argv[])
   progname = argv[0];
   Unity.TestFile = "authkeys.c";
   UnityBegin("authkeys.c");
-  RUN_TEST(test_AddTrustedKeys, 71);
+  RUN_TEST(test_AddTrustedKeys, 70);
   RUN_TEST(test_AddUntrustedKey, 82);
-  RUN_TEST(test_HaveKeyCorrect, 90);
-  RUN_TEST(test_HaveKeyIncorrect, 99);
-  RUN_TEST(test_AddWithAuthUseKey, 106);
-  RUN_TEST(test_EmptyKey, 113);
+  RUN_TEST(test_HaveKeyCorrect, 91);
+  RUN_TEST(test_HaveKeyIncorrect, 101);
+  RUN_TEST(test_AddWithAuthUseKey, 109);
+  RUN_TEST(test_EmptyKey, 117);
 
   return (UnityEnd());
 }
index c54c33912ab7bf17fe8a0a814c50fd3ef0d4794e..c23a3a56ed986f12a6bef2586850161af0028ac9 100644 (file)
 //=======External Functions This Runner Calls=====
 extern void setUp(void);
 extern void tearDown(void);
-extern void test_ZeroBuffer();
-extern void test_IntegerAndFractionalBuffer();
-extern void test_IllegalMicroseconds();
-extern void test_AlwaysFalseOnWindows();
+void resetTest(void);
+extern void test_ZeroBuffer(void);
+extern void test_IntegerAndFractionalBuffer(void);
+extern void test_IllegalMicroseconds(void);
+extern void test_AlwaysFalseOnWindows(void);
 
 
 //=======Test Reset Option=====
@@ -48,10 +49,10 @@ int main(int argc, char *argv[])
   progname = argv[0];
   Unity.TestFile = "buftvtots.c";
   UnityBegin("buftvtots.c");
-  RUN_TEST(test_ZeroBuffer, 16);
-  RUN_TEST(test_IntegerAndFractionalBuffer, 30);
-  RUN_TEST(test_IllegalMicroseconds, 53);
-  RUN_TEST(test_AlwaysFalseOnWindows, 66);
+  RUN_TEST(test_ZeroBuffer, 17);
+  RUN_TEST(test_IntegerAndFractionalBuffer, 32);
+  RUN_TEST(test_IllegalMicroseconds, 55);
+  RUN_TEST(test_AlwaysFalseOnWindows, 69);
 
   return (UnityEnd());
 }
index 07a5092f3faef59f896f9c6582675ab41a992ac1..3edb84b95b1ca6e6cf65ad54939e4c31209d7b7c 100644 (file)
 //=======External Functions This Runner Calls=====
 extern void setUp(void);
 extern void tearDown(void);
-extern void test_DaySplitMerge();
-extern void test_SplitYearDays1();
-extern void test_SplitYearDays2();
-extern void test_RataDie1();
-extern void test_LeapYears1();
-extern void test_LeapYears2();
-extern void test_RoundTripDate();
-extern void test_RoundTripYearStart();
-extern void test_RoundTripMonthStart();
-extern void test_RoundTripWeekStart();
-extern void test_RoundTripDayStart();
+void resetTest(void);
+extern void test_DaySplitMerge(void);
+extern void test_SplitYearDays1(void);
+extern void test_SplitYearDays2(void);
+extern void test_RataDie1(void);
+extern void test_LeapYears1(void);
+extern void test_LeapYears2(void);
+extern void test_RoundTripDate(void);
+extern void test_RoundTripYearStart(void);
+extern void test_RoundTripMonthStart(void);
+extern void test_RoundTripWeekStart(void);
+extern void test_RoundTripDayStart(void);
 
 
 //=======Test Reset Option=====
@@ -55,17 +56,17 @@ int main(int argc, char *argv[])
   progname = argv[0];
   Unity.TestFile = "calendar.c";
   UnityBegin("calendar.c");
-  RUN_TEST(test_DaySplitMerge, 230);
-  RUN_TEST(test_SplitYearDays1, 254);
-  RUN_TEST(test_SplitYearDays2, 268);
-  RUN_TEST(test_RataDie1, 283);
-  RUN_TEST(test_LeapYears1, 293);
-  RUN_TEST(test_LeapYears2, 308);
-  RUN_TEST(test_RoundTripDate, 326);
-  RUN_TEST(test_RoundTripYearStart, 355);
-  RUN_TEST(test_RoundTripMonthStart, 371);
-  RUN_TEST(test_RoundTripWeekStart, 387);
-  RUN_TEST(test_RoundTripDayStart, 403);
+  RUN_TEST(test_DaySplitMerge, 228);
+  RUN_TEST(test_SplitYearDays1, 258);
+  RUN_TEST(test_SplitYearDays2, 273);
+  RUN_TEST(test_RataDie1, 289);
+  RUN_TEST(test_LeapYears1, 300);
+  RUN_TEST(test_LeapYears2, 316);
+  RUN_TEST(test_RoundTripDate, 335);
+  RUN_TEST(test_RoundTripYearStart, 365);
+  RUN_TEST(test_RoundTripMonthStart, 382);
+  RUN_TEST(test_RoundTripWeekStart, 399);
+  RUN_TEST(test_RoundTripDayStart, 416);
 
   return (UnityEnd());
 }
index b4e3f480ec7ca073a8b8de4a78f38259daf90d7c..8049d1b9a898c3b1af7e24f479ff8e8b31fc708a 100644 (file)
 extern void setUp(void);
 extern void tearDown(void);
 void resetTest(void);
-extern void test_RegularTime();
-extern void test_LeapYear();
-extern void test_uLongBoundary();
-extern void test_uLongWrapped();
+extern void test_RegularTime(void);
+extern void test_LeapYear(void);
+extern void test_uLongBoundary(void);
+extern void test_uLongWrapped(void);
 
 
 //=======Test Reset Option=====
@@ -49,10 +49,10 @@ int main(int argc, char *argv[])
   progname = argv[0];
   Unity.TestFile = "caljulian.c";
   UnityBegin("caljulian.c");
-  RUN_TEST(test_RegularTime, 74);
+  RUN_TEST(test_RegularTime, 73);
   RUN_TEST(test_LeapYear, 85);
-  RUN_TEST(test_uLongBoundary, 96);
-  RUN_TEST(test_uLongWrapped, 107);
+  RUN_TEST(test_uLongBoundary, 97);
+  RUN_TEST(test_uLongWrapped, 109);
 
   return (UnityEnd());
 }
index b7b6626bfd05cf24a43258e5908a59a5caa75eca..b5c9863eba625357de05c4cf53df5fe7891ea34c 100644 (file)
@@ -26,6 +26,7 @@
 //=======External Functions This Runner Calls=====
 extern void setUp(void);
 extern void tearDown(void);
+void resetTest(void);
 extern void test_DateGivenMonthDay(void);
 extern void test_DateGivenYearDay(void);
 extern void test_DateLeapYear(void);
index f21de83eac00a016caaffe4556b98ade29da02a6..58e1725b9b10a0a7daf0c5a4dd272cb184c50f98 100644 (file)
 //=======External Functions This Runner Calls=====
 extern void setUp(void);
 extern void tearDown(void);
-extern void test_CurrentYear();
-extern void test_CurrentYearFuzz();
-extern void test_TimeZoneOffset();
-extern void test_WrongYearStart();
-extern void test_PreviousYear();
-extern void test_NextYear();
-extern void test_NoReasonableConversion();
-extern void test_AlwaysInLimit();
+void resetTest(void);
+extern void test_CurrentYear(void);
+extern void test_CurrentYearFuzz(void);
+extern void test_TimeZoneOffset(void);
+extern void test_WrongYearStart(void);
+extern void test_PreviousYear(void);
+extern void test_NextYear(void);
+extern void test_NoReasonableConversion(void);
+extern void test_AlwaysInLimit(void);
 
 
 //=======Test Reset Option=====
@@ -52,14 +53,14 @@ int main(int argc, char *argv[])
   progname = argv[0];
   Unity.TestFile = "clocktime.c";
   UnityBegin("clocktime.c");
-  RUN_TEST(test_CurrentYear, 32);
-  RUN_TEST(test_CurrentYearFuzz, 47);
-  RUN_TEST(test_TimeZoneOffset, 69);
-  RUN_TEST(test_WrongYearStart, 89);
-  RUN_TEST(test_PreviousYear, 108);
-  RUN_TEST(test_NextYear, 127);
-  RUN_TEST(test_NoReasonableConversion, 145);
-  RUN_TEST(test_AlwaysInLimit, 167);
+  RUN_TEST(test_CurrentYear, 35);
+  RUN_TEST(test_CurrentYearFuzz, 51);
+  RUN_TEST(test_TimeZoneOffset, 74);
+  RUN_TEST(test_WrongYearStart, 95);
+  RUN_TEST(test_PreviousYear, 115);
+  RUN_TEST(test_NextYear, 135);
+  RUN_TEST(test_NoReasonableConversion, 154);
+  RUN_TEST(test_AlwaysInLimit, 177);
 
   return (UnityEnd());
 }