TEST(socktoa, HashEqual) { sockaddr_u input1 = CreateSockaddr4("192.00.2.2", 123); sockaddr_u input2 = CreateSockaddr4("192.0.2.2", 123); TEST_ASSERT_TRUE(IsEqualS(&input1, &input2)); TEST_ASSERT_EQUAL(sock_hash(&input1), sock_hash(&input2)); }
void test_HashEqual(void) { sockaddr_u input1 = CreateSockaddr4("192.00.2.2", 123); sockaddr_u input2 = CreateSockaddr4("192.0.2.2", 123); TEST_ASSERT_TRUE(IsEqual(input1, input2)); TEST_ASSERT_EQUAL(sock_hash(&input1), sock_hash(&input2)); }
TEST_F(socktoaTest, HashEqual) { sockaddr_u input1 = CreateSockaddr4("192.00.2.2", 123); sockaddr_u input2 = CreateSockaddr4("192.0.2.2", 123); ASSERT_TRUE(IsEqual(input1, input2)); EXPECT_EQ(sock_hash(&input1), sock_hash(&input2)); }
TEST(socktoa, HashNotEqual) { /* 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_TRUE(IsDiffS(&input1, &input2)); TEST_ASSERT_NOT_EQUAL(sock_hash(&input1), sock_hash(&input2)); }
TEST_F(socktoaTest, HashNotEqual) { /* 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); ASSERT_FALSE(IsEqual(input1, input2)); EXPECT_NE(sock_hash(&input1), sock_hash(&input2)); }
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)); TEST_ASSERT_FALSE(sock_hash(&input1) == sock_hash(&input2)); }
void test_ClassCAddress(void) { sockaddr_u input = CreateSockaddr4("192.0.2.255", NTP_PORT); sockaddr_u expected = CreateSockaddr4("192.0.2.0", NTP_PORT); sockaddr_u* actual = netof(&input); TEST_ASSERT_TRUE(actual != NULL); TEST_ASSERT_TRUE(IsEqual(expected, *actual)); }
TEST_F(netofTest, ClassBAddress) { sockaddr_u input = CreateSockaddr4("172.16.2.1", NTP_PORT); sockaddr_u expected = CreateSockaddr4("172.16.0.0", NTP_PORT); sockaddr_u* actual = netof(&input); ASSERT_TRUE(actual != NULL); EXPECT_TRUE(IsEqual(expected, *actual)); }
void test_ClassAAddress(void) { /* Class A addresses are assumed to be classless, * thus the same address should be returned. */ sockaddr_u input = CreateSockaddr4("10.20.30.40", NTP_PORT); sockaddr_u expected = CreateSockaddr4("10.20.30.40", NTP_PORT); sockaddr_u* actual = netof(&input); TEST_ASSERT_TRUE(actual != NULL); TEST_ASSERT_TRUE(IsEqual(expected, *actual)); }
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_ClassBAddress(void) { sockaddr_u input = CreateSockaddr4("172.16.2.1", NTP_PORT); sockaddr_u expected = CreateSockaddr4("172.16.0.0", NTP_PORT); sockaddr_u* actual = netof(&input); TEST_ASSERT_TRUE(actual != NULL); TEST_ASSERT_TRUE(IsEqual(expected, *actual)); return; }
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_IPv4Address() { const char* ADDR = "192.0.2.10"; sockaddr_u input = CreateSockaddr4(ADDR); struct addrinfo inputA = CreateAddrinfo(&input); TEST_ASSERT_EQUAL_STRING(ADDR, ss_to_str(&input)); TEST_ASSERT_EQUAL_STRING(ADDR, addrinfo_to_str(&inputA)); }
TEST(utilities, IPv4Address) { const char* ADDR = "192.0.2.10"; sockaddr_u input = CreateSockaddr4(ADDR, 123); struct addrinfo inputA = CreateAddrinfo(&input); /* coverity[leaked_storage] */ TEST_ASSERT_EQUAL_STRING(ADDR, ss_to_str(&input)); /* coverity[leaked_storage] */ TEST_ASSERT_EQUAL_STRING(ADDR, addrinfo_to_str(&inputA)); /* coverity[leaked_storage] */ }
TEST_F(socktoaTest, IPv4AddressWithPort) { sockaddr_u input = CreateSockaddr4("192.0.2.10", 123); EXPECT_STREQ("192.0.2.10", socktoa(&input)); EXPECT_STREQ("192.0.2.10:123", sockporttoa(&input)); }