diff --git a/tests/src/icmpv6.cpp b/tests/src/icmpv6.cpp index 369d24c..a193633 100644 --- a/tests/src/icmpv6.cpp +++ b/tests/src/icmpv6.cpp @@ -218,9 +218,8 @@ TEST_F(ICMPv6Test, PrefixInformation) { TEST_F(ICMPv6Test, RedirectHeader) { ICMPv6 icmp; - IP ip = IP("127.0.0.1") / TCP(22); - PDU::serialization_type buffer = ip.serialize(); - buffer.insert(buffer.begin(), 6, 0); + EthernetII eth = EthernetII() / IP("8.8.8.8", "192.168.0.100") / TCP(22, 26); + PDU::serialization_type buffer = eth.serialize(); icmp.redirect_header(buffer); EXPECT_EQ(buffer, icmp.redirect_header()); } diff --git a/tests/src/network_interface.cpp b/tests/src/network_interface.cpp index ba41788..ef48820 100644 --- a/tests/src/network_interface.cpp +++ b/tests/src/network_interface.cpp @@ -1,10 +1,12 @@ #include #include +#include #include "network_interface.h" #include "utils.h" #include "macros.h" using namespace Tins; +using namespace std; class NetworkInterfaceTest : public ::testing::Test { public: @@ -12,17 +14,14 @@ public: }; #ifdef BSD -const std::string NetworkInterfaceTest::iface_name("lo0"), - NetworkInterfaceTest::iface_addr(""); -#elif defined(WIN32) -// modify me on every windows environment :D -const std::string NetworkInterfaceTest::iface_name("{INSERT-SOME-INTERFACE-NAME}"), +const string NetworkInterfaceTest::iface_name("lo0"), NetworkInterfaceTest::iface_addr(""); #else -const std::string NetworkInterfaceTest::iface_name("lo"), +const string NetworkInterfaceTest::iface_name("lo"), NetworkInterfaceTest::iface_addr(""); #endif +#ifndef WIN32 TEST_F(NetworkInterfaceTest, ConstructorFromString) { // just test this doesn't throw NetworkInterface iface(iface_name); @@ -63,5 +62,31 @@ TEST_F(NetworkInterfaceTest, DistinctOperator) { NetworkInterface iface1(iface_name), iface2; EXPECT_NE(iface1, iface2); } +#endif // WIN32 +// This is a more generic test that can be run on all platforms. +// The above ones won't run on windows since there's no name for the loopback interface. +// So this does more or less the same as all of the above, but iterating over the +// actual interfaces available in the system. +TEST_F(NetworkInterfaceTest, IterateOverInterfaces) { + vector interfaces = NetworkInterface::all(); + set names; + set ids; + for (size_t i = 0; i < interfaces.size(); ++i) { + // Expect unique names an all interfaces + EXPECT_TRUE(names.insert(interfaces[i].name()).second); + // Expect unique ids an all interfaces + EXPECT_TRUE(ids.insert(interfaces[i].id()).second); + // Expect this interface to be equal to itself + EXPECT_EQ(interfaces[i], interfaces[i]); + // We expect to be able to construct the interface from a name + // and they should still be equal + NetworkInterface iface(interfaces[i].name()); + EXPECT_EQ(interfaces[i], iface); + // We expect this interface to be different from the others + for (size_t u = i + 1; u < interfaces.size(); ++u) { + EXPECT_NE(interfaces[i], interfaces[u]); + } + } +} diff --git a/tests/src/udp.cpp b/tests/src/udp.cpp index f831b0b..ca867ff 100644 --- a/tests/src/udp.cpp +++ b/tests/src/udp.cpp @@ -3,7 +3,7 @@ #include #include "udp.h" #include "ip.h" - +#include "ethernetII.h" using namespace std; using namespace Tins; @@ -21,9 +21,11 @@ const uint8_t UDPTest::expected_packet[] = { }; const uint8_t UDPTest::checksum_packet[] = { - 69, 0, 0, 48, 35, 109, 64, 0, 64, 17, 25, 78, 0, 0, 0, 0, 127, 0, 0, - 1, 5, 57, 155, 11, 0, 28, 84, 167, 97, 115, 100, 97, 115, 100, 115, - 97, 115, 100, 97, 115, 100, 115, 97, 100, 97, 115, 100, 10 + 10, 128, 57, 251, 101, 187, 76, 128, 147, 141, 144, 65, 8, 0, 69, 0, 0, + 70, 14, 223, 64, 0, 64, 17, 138, 252, 10, 0, 0, 54, 75, 75, 75, 75, 215, + 173, 0, 53, 0, 50, 206, 155, 118, 39, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 11, + 48, 45, 101, 100, 103, 101, 45, 99, 104, 97, 116, 8, 102, 97, 99, 101, + 98, 111, 111, 107, 3, 99, 111, 109, 0, 0, 1, 0, 1 }; @@ -44,12 +46,12 @@ TEST_F(UDPTest, DefaultConstructor) { } TEST_F(UDPTest, ChecksumCheck) { - IP pkt1(checksum_packet, sizeof(checksum_packet)); + EthernetII pkt1(checksum_packet, sizeof(checksum_packet)); const UDP &udp1 = pkt1.rfind_pdu(); uint16_t checksum = udp1.checksum(); - IP::serialization_type buffer = pkt1.serialize(); - IP pkt2(&buffer[0], buffer.size()); + PDU::serialization_type buffer = pkt1.serialize(); + EthernetII pkt2(&buffer[0], buffer.size()); const UDP &udp2 = pkt2.rfind_pdu(); EXPECT_EQ(checksum, udp2.checksum()); EXPECT_EQ(udp1.checksum(), udp2.checksum()); diff --git a/tests/src/utils.cpp b/tests/src/utils.cpp index c7cec16..ac0381f 100644 --- a/tests/src/utils.cpp +++ b/tests/src/utils.cpp @@ -67,36 +67,7 @@ const uint32_t UtilsTest::data_len = 500; TEST_F(UtilsTest, Crc32) { - uint32_t crc = Utils::crc32(data, data_len); EXPECT_EQ(crc, 0x78840f54U); - -} - -TEST_F(UtilsTest, ResolveDomain) { - IPv4Address localhost_ip("127.0.0.1"); - - EXPECT_EQ(Utils::resolve_domain("localhost"), localhost_ip); -} - -/* -TEST_F(UtilsTest, ResolveDomain6) { - IPv6Address localhost_ip("2606:2800:220:6d:26bf:1447:1097:aa7"); - - EXPECT_EQ(Utils::resolve_domain6("example.com"), localhost_ip); -} -*/ - -// FIXME -TEST_F(UtilsTest, Checksum) { - - /*uint16_t checksum = Utils::do_checksum(data, data + data_len); - - //EXPECT_EQ(checksum, 0x231a); - - uint8_t my_data[] = {0, 0, 0, 0}; - checksum = Utils::do_checksum(my_data, my_data + 4); - //EXPECT_EQ(checksum, 0xFFFF); -*/ }