From 18ad73b60a4e7ae554a653243404e299c592bcd0 Mon Sep 17 00:00:00 2001 From: Lokesh Walase Date: Mon, 6 Jul 2015 19:55:50 +0530 Subject: [PATCH] Code review changes bk: 559a8feez5Ssn88zVxmsuF53aNMGLw --- tests/libntp/decodenetnum.c | 22 +++++++++++++--------- tests/libntp/hextolfp.c | 1 - tests/libntp/lfptostr.c | 35 +++++++++++++++++++++++------------ tests/libntp/netof.c | 15 +++++++++------ tests/libntp/octtoint.c | 21 ++++++++++++++------- tests/libntp/socktoa.c | 27 +++++++++++++++------------ 6 files changed, 74 insertions(+), 47 deletions(-) diff --git a/tests/libntp/decodenetnum.c b/tests/libntp/decodenetnum.c index 681b7125a..3f0a066f0 100644 --- a/tests/libntp/decodenetnum.c +++ b/tests/libntp/decodenetnum.c @@ -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. */ diff --git a/tests/libntp/hextolfp.c b/tests/libntp/hextolfp.c index a2f548f56..75249b2a6 100644 --- a/tests/libntp/hextolfp.c +++ b/tests/libntp/hextolfp.c @@ -60,4 +60,3 @@ void test_IllegalChar(void) { TEST_ASSERT_FALSE(hextolfp(str, &actual)); } - diff --git a/tests/libntp/lfptostr.c b/tests/libntp/lfptostr.c index c76e07fb0..b185853e6 100644 --- a/tests/libntp/lfptostr.c +++ b/tests/libntp/lfptostr.c @@ -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)); diff --git a/tests/libntp/netof.c b/tests/libntp/netof.c index 010b16429..6a3aa4233 100644 --- a/tests/libntp/netof.c +++ b/tests/libntp/netof.c @@ -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)); } - diff --git a/tests/libntp/octtoint.c b/tests/libntp/octtoint.c index 4b0f94cea..c069d6834 100644 --- a/tests/libntp/octtoint.c +++ b/tests/libntp/octtoint.c @@ -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; diff --git a/tests/libntp/socktoa.c b/tests/libntp/socktoa.c index 537df1e44..bd584d347 100644 --- a/tests/libntp/socktoa.c +++ b/tests/libntp/socktoa.c @@ -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, -- 2.47.3