#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;
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;
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,
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,
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.
*/
TEST_ASSERT_FALSE(hextolfp(str, &actual));
}
-
#include "config.h"
#include "ntp_stdlib.h"
-#include "ntp_calendar.h"
+//#include "ntp_calendar.h"
#include "ntp_fp.h"
#include "unity.h"
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));
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));
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));
#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);
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);
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.
*/
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,
TEST_ASSERT_TRUE(actual != NULL);
TEST_ASSERT_TRUE(IsEqual(expected, *actual));
}
-
#include "unity.h"
-void test_SingleDigit(void) {
+void
+test_SingleDigit(void) {
const char* str = "5";
u_long actual;
TEST_ASSERT_EQUAL(5, actual);
}
-void test_MultipleDigits(void){
+void
+test_MultipleDigits(void){
const char* str = "271";
u_long actual;
}
-void test_Zero(void){
+void
+test_Zero(void) {
const char* str = "0";
u_long actual;
}
-void test_MaximumUnsigned32bit(void){
+void
+test_MaximumUnsigned32bit(void) {
const char* str = "37777777777";
u_long actual;
}
-void test_Overflow(void){
+void
+test_Overflow(void) {
const char* str = "40000000000";
u_long actual;
}
-void test_IllegalCharacter(void){
+void
+test_IllegalCharacter(void) {
const char* str = "5ac2";
u_long actual;
}
-void test_IllegalDigit(void){
+void
+test_IllegalDigit(void) {
const char* str = "5283";
u_long actual;
#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,
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,
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);
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,