]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Code review changes
authorLokesh Walase <lokeshw24@ntp.org>
Mon, 6 Jul 2015 14:25:50 +0000 (19:55 +0530)
committerLokesh Walase <lokeshw24@ntp.org>
Mon, 6 Jul 2015 14:25:50 +0000 (19:55 +0530)
bk: 559a8feez5Ssn88zVxmsuF53aNMGLw

tests/libntp/decodenetnum.c
tests/libntp/hextolfp.c
tests/libntp/lfptostr.c
tests/libntp/netof.c
tests/libntp/octtoint.c
tests/libntp/socktoa.c

index 681b7125a017a06a0762cc055b99347d08f0d207..3f0a066f0f19e42d55f055208fc3b5ad7133aba7 100644 (file)
@@ -1,12 +1,11 @@
 #include "config.h"
 #include "ntp_stdlib.h"
 #include "ntp_calendar.h"
-#include "unity.h"
-
 #include "sockaddrtest.h"
+#include "unity.h"
 
-
-void test_IPv4AddressOnly(void) {
+void 
+test_IPv4AddressOnly(void) {
        const char *str = "192.0.2.1";
        sockaddr_u actual;
 
@@ -19,7 +18,8 @@ void test_IPv4AddressOnly(void) {
        TEST_ASSERT_TRUE(IsEqual(expected, actual));
 }
 
-void test_IPv4AddressWithPort(void) {
+void 
+test_IPv4AddressWithPort(void) {
        const char *str = "192.0.2.2:2000";
        sockaddr_u actual;
 
@@ -32,7 +32,8 @@ void test_IPv4AddressWithPort(void) {
        TEST_ASSERT_TRUE(IsEqual(expected, actual));
 }
 
-void test_IPv6AddressOnly(void) {
+void 
+test_IPv6AddressOnly(void) {
        const struct in6_addr address = {
                0x20, 0x01, 0x0d, 0xb8,
         0x85, 0xa3, 0x08, 0xd3, 
@@ -52,7 +53,8 @@ void test_IPv6AddressOnly(void) {
        TEST_ASSERT_TRUE(IsEqual(expected, actual));
 }
 
-void test_IPv6AddressWithPort(void) {
+void 
+test_IPv6AddressWithPort(void) {
        const struct in6_addr address = {
                0x20, 0x01, 0x0d, 0xb8,
         0x85, 0xa3, 0x08, 0xd3, 
@@ -72,14 +74,16 @@ void test_IPv6AddressWithPort(void) {
        TEST_ASSERT_TRUE(IsEqual(expected, actual));
 }
 
-void test_IllegalAddress(void) {
+void 
+test_IllegalAddress(void) {
        const char *str = "192.0.2.270:2000";
        sockaddr_u actual;
 
        TEST_ASSERT_FALSE(decodenetnum(str, &actual));
 }
 
-void test_IllegalCharInPort(void) {
+void 
+test_IllegalCharInPort(void) {
        /* An illegal port does not make the decodenetnum fail, but instead
         * makes it use the standard port.
         */
index a2f548f5664483bc88e753fe8a7f8cba0f5b1e6f..75249b2a67c844982c1bf8b06977a90ed65be2fc 100644 (file)
@@ -60,4 +60,3 @@ void test_IllegalChar(void) {
 
        TEST_ASSERT_FALSE(hextolfp(str, &actual));
 }
-
index c76e07fb0ed87b34d589b864838286c8473258ee..b185853e69e7824220d4ba4b385439be98948899 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "config.h"
 #include "ntp_stdlib.h"
-#include "ntp_calendar.h"
+//#include "ntp_calendar.h"
 #include "ntp_fp.h"
 
 #include "unity.h"
@@ -20,63 +20,72 @@ static const int THREE_FOURTH = -1073741824;
 static const int HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005
 static const int HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005
 
-void test_PositiveInteger(void) {
+void 
+test_PositiveInteger(void) {
        l_fp test = {200, 0}; // exact 200.0000000000
 
        TEST_ASSERT_EQUAL_STRING("200.0000000000", mfptoa(test.l_ui, test.l_uf, LFP_MAX_PRECISION));
        TEST_ASSERT_EQUAL_STRING("200000.0000000", mfptoms(test.l_ui, test.l_uf, LFP_MAX_PRECISION_MS));
 }
 
-void test_NegativeInteger(void) {
+void 
+test_NegativeInteger(void) {
        l_fp test = {-100, 0}; // -100
 
        TEST_ASSERT_EQUAL_STRING("-100.0000000000", lfptoa(&test, LFP_MAX_PRECISION));
        TEST_ASSERT_EQUAL_STRING("-100000.0000000", lfptoms(&test, LFP_MAX_PRECISION_MS));
 }
 
-void test_PositiveIntegerWithFraction(void) {
+void 
+test_PositiveIntegerWithFraction(void) {
        l_fp test = {200, ONE_FOURTH}; // 200.25
 
        TEST_ASSERT_EQUAL_STRING("200.2500000000", lfptoa(&test, LFP_MAX_PRECISION));
        TEST_ASSERT_EQUAL_STRING("200250.0000000", lfptoms(&test, LFP_MAX_PRECISION_MS));
 }
 
-void test_NegativeIntegerWithFraction(void) {
+void 
+test_NegativeIntegerWithFraction(void) {
        l_fp test = {-100, ONE_FOURTH}; // -99.75
 
        TEST_ASSERT_EQUAL_STRING("-99.7500000000", lfptoa(&test, LFP_MAX_PRECISION));
        TEST_ASSERT_EQUAL_STRING("-99750.0000000", lfptoms(&test, LFP_MAX_PRECISION_MS));
 }
 
-void test_RoundingDownToInteger(void) {
+void 
+test_RoundingDownToInteger(void) {
        l_fp test = {10, ONE_FOURTH}; // 10.25
 
        TEST_ASSERT_EQUAL_STRING("10", lfptoa(&test, 0));
        TEST_ASSERT_EQUAL_STRING("10250", lfptoms(&test, 0));
 }
 
-void test_RoundingMiddleToInteger(void) {
+void 
+test_RoundingMiddleToInteger(void) {
        l_fp test = {10, HALF}; // 10.5
 
        TEST_ASSERT_EQUAL_STRING("11", lfptoa(&test, 0));
        TEST_ASSERT_EQUAL_STRING("10500", lfptoms(&test, 0));
 }
 
-void test_RoundingUpToInteger(void) {
+void 
+test_RoundingUpToInteger(void) {
        l_fp test = {5, THREE_FOURTH}; // 5.75
 
        TEST_ASSERT_EQUAL_STRING("6", lfptoa(&test, 0));
        TEST_ASSERT_EQUAL_STRING("5750", lfptoms(&test, 0));
 }
 
-void test_SingleDecimal(void) {
+void 
+test_SingleDecimal(void) {
        l_fp test = {8, ONE_FOURTH}; // 8.25
 
        TEST_ASSERT_EQUAL_STRING("8.3", lfptoa(&test, 1));
        TEST_ASSERT_EQUAL_STRING("8250.0", lfptoms(&test, 1));
 }
 
-void test_MillisecondsRoundingUp(void) {
+void 
+test_MillisecondsRoundingUp(void) {
        l_fp test = {1, HALF_PROMILLE_UP}; //slightly more than 1.0005
 
        TEST_ASSERT_EQUAL_STRING("1.0", lfptoa(&test, 1));
@@ -85,7 +94,8 @@ void test_MillisecondsRoundingUp(void) {
        TEST_ASSERT_EQUAL_STRING("1001", lfptoms(&test, 0));
 }
 
-void test_MillisecondsRoundingDown(void) {
+void 
+test_MillisecondsRoundingDown(void) {
        l_fp test = {1, HALF_PROMILLE_DOWN}; // slightly less than 1.0005
 
        TEST_ASSERT_EQUAL_STRING("1.0", lfptoa(&test, 1));
@@ -94,7 +104,8 @@ void test_MillisecondsRoundingDown(void) {
        TEST_ASSERT_EQUAL_STRING("1000", lfptoms(&test, 0));
 }
 
-void test_UnsignedInteger(void) {
+void 
+test_UnsignedInteger(void) {
        l_fp test = {3000000000UL, 0};
 
        TEST_ASSERT_EQUAL_STRING("3000000000.0", ulfptoa(&test, 1));
index 010b16429365d4657f8b8b5f7fe8743695d3d4f3..6a3aa42337116ea1e1855ac73cdc862432821597 100644 (file)
@@ -1,13 +1,14 @@
 #include "config.h"
 
 #include "ntp_stdlib.h"
-#include "ntp_calendar.h"
+//#include "ntp_calendar.h"
 
 #include "unity.h"
 
 #include "sockaddrtest.h"
 
-void test_ClassBAddress(void) {
+void 
+test_ClassBAddress(void) {
        sockaddr_u input = CreateSockaddr4("172.16.2.1", NTP_PORT);
        sockaddr_u expected = CreateSockaddr4("172.16.0.0", NTP_PORT);
 
@@ -17,7 +18,8 @@ void test_ClassBAddress(void) {
        TEST_ASSERT_TRUE(IsEqual(expected, *actual));
 }
 
-void test_ClassCAddress(void) {
+void 
+test_ClassCAddress(void) {
        sockaddr_u input = CreateSockaddr4("192.0.2.255", NTP_PORT);
        sockaddr_u expected = CreateSockaddr4("192.0.2.0", NTP_PORT);
 
@@ -27,7 +29,8 @@ void test_ClassCAddress(void) {
        TEST_ASSERT_TRUE(IsEqual(expected, *actual));
 }
 
-void  test_ClassAAddress(void) {
+void 
+test_ClassAAddress(void) {
        /* Class A addresses are assumed to be classless,
         * thus the same address should be returned.
         */
@@ -40,7 +43,8 @@ void  test_ClassAAddress(void) {
        TEST_ASSERT_TRUE(IsEqual(expected, *actual));
 }
 
-void  test_IPv6Address(void) {
+void 
+test_IPv6Address(void) {
        /* IPv6 addresses are assumed to have 64-bit host- and 64-bit network parts. */
        const struct in6_addr input_address = {
                0x20, 0x01, 0x0d, 0xb8,
@@ -71,4 +75,3 @@ void  test_IPv6Address(void) {
        TEST_ASSERT_TRUE(actual != NULL);
        TEST_ASSERT_TRUE(IsEqual(expected, *actual));
 }
-
index 4b0f94ceaa36a5b7637ada04684dabd37278682f..c069d68346925ea3bb369581a26f59337b3c16d0 100644 (file)
@@ -4,7 +4,8 @@
 
 #include "unity.h"
 
-void test_SingleDigit(void) {
+void 
+test_SingleDigit(void) {
        const char* str = "5";
        u_long actual;
 
@@ -12,7 +13,8 @@ void test_SingleDigit(void) {
        TEST_ASSERT_EQUAL(5, actual);
 }
 
-void test_MultipleDigits(void){
+void 
+test_MultipleDigits(void){
        const char* str = "271";
        u_long actual;
 
@@ -21,7 +23,8 @@ void test_MultipleDigits(void){
 
 }
 
-void test_Zero(void){
+void 
+test_Zero(void) {
        const char* str = "0";
        u_long actual;
 
@@ -30,7 +33,8 @@ void test_Zero(void){
 
 }
 
-void test_MaximumUnsigned32bit(void){
+void 
+test_MaximumUnsigned32bit(void) {
        const char* str = "37777777777";
        u_long actual;
 
@@ -39,7 +43,8 @@ void test_MaximumUnsigned32bit(void){
 
 }
 
-void test_Overflow(void){
+void 
+test_Overflow(void) {
        const char* str = "40000000000";
        u_long actual;
 
@@ -47,7 +52,8 @@ void test_Overflow(void){
 
 }
 
-void test_IllegalCharacter(void){
+void 
+test_IllegalCharacter(void) {
        const char* str = "5ac2";
        u_long actual;
 
@@ -55,7 +61,8 @@ void test_IllegalCharacter(void){
 
 }
 
-void test_IllegalDigit(void){
+void 
+test_IllegalDigit(void) {
        const char* str = "5283";
        u_long actual;
 
index 537df1e44407ddd8cad5d7f48d7ec2381563853b..bd584d347682e3d2e440a669f8a002ccf4cf9929 100644 (file)
@@ -4,18 +4,19 @@
 #include "ntp_calendar.h"
 
 #include "unity.h"
-
 #include "sockaddrtest.h"
 
 
-void test_IPv4AddressWithPort(void) {
+void 
+test_IPv4AddressWithPort(void) {
        sockaddr_u input = CreateSockaddr4("192.0.2.10", 123);
 
        TEST_ASSERT_EQUAL_STRING("192.0.2.10", socktoa(&input));
        TEST_ASSERT_EQUAL_STRING("192.0.2.10:123", sockporttoa(&input));
 }
 
-void test_IPv6AddressWithPort(void) {
+void 
+test_IPv6AddressWithPort(void) {
        const struct in6_addr address = {
                0x20, 0x01, 0x0d, 0xb8,
                0x85, 0xa3, 0x08, 0xd3, 
@@ -38,8 +39,9 @@ void test_IPv6AddressWithPort(void) {
        TEST_ASSERT_EQUAL_STRING(expected_port, sockporttoa(&input));
 }
 
+void 
+test_ScopedIPv6AddressWithPort(void) {
 #ifdef ISC_PLATFORM_HAVESCOPEID
-void test_ScopedIPv6AddressWithPort(void) {
        const struct in6_addr address = {
                0xfe, 0x80, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
@@ -61,10 +63,13 @@ void test_ScopedIPv6AddressWithPort(void) {
 
        TEST_ASSERT_EQUAL_STRING(expected, socktoa(&input));
        TEST_ASSERT_EQUAL_STRING(expected_port, sockporttoa(&input));
+#else
+       TEST_IGNORE_MESSAGE("Skipping because ISC_PLATFORM does not have Scope ID");
+#endif
 }
-#endif /* ISC_PLATFORM_HAVESCOPEID */
 
-void test_HashEqual(void) {
+void 
+test_HashEqual(void) {
        sockaddr_u input1 = CreateSockaddr4("192.00.2.2", 123);
        sockaddr_u input2 = CreateSockaddr4("192.0.2.2", 123);
 
@@ -72,20 +77,18 @@ void test_HashEqual(void) {
        TEST_ASSERT_EQUAL(sock_hash(&input1), sock_hash(&input2));
 }
 
-void test_HashNotEqual(void) {
+void 
+test_HashNotEqual(void) {
        /* These two addresses should not generate the same hash. */
        sockaddr_u input1 = CreateSockaddr4("192.0.2.1", 123);
        sockaddr_u input2 = CreateSockaddr4("192.0.2.2", 123);
 
        TEST_ASSERT_FALSE(IsEqual(input1, input2));
-       //TODO : EXPECT_NE(sock_hash(&input1), sock_hash(&input2));
-       //Damir's suggestion below:
        TEST_ASSERT_FALSE(sock_hash(&input1) == sock_hash(&input2)); 
-       //NOTE: sock_hash returns u_short, so you can compare it with ==
-       //for complex structures you have to write an additional function like bool compare(a,b) 
 }
 
-void test_IgnoreIPv6Fields(void) {
+void 
+test_IgnoreIPv6Fields(void) {
        const struct in6_addr address = {
                0x20, 0x01, 0x0d, 0xb8,
         0x85, 0xa3, 0x08, 0xd3,