mirror of
https://github.com/mfontanini/libtins
synced 2026-01-28 12:44:25 +01:00
Add missing operators to address classes (#275)
* * add or-operator and a simlple unit test for hw_address, ip_address, ipv6_address * add not-operator and a simlple unit test for hw_address, ip_address, ipv6_address * add greater-then-operator and a simlple unit test for ipv6_address * add new constructor and a simlple unit test for network_interface, which use a ipv6_address to find the nic * add override the function gateway_from_ip for ipv6_address parameter (untested) * change the ipv6_address in NotMaskAdress_Test, so that the expceted addresses are valid for the winsock api * Delete CMakeLists.txt.user * * add <=, >, >= operator for HWAddress with tests * add <=, >, >= operator for IPv4Address with tests * add <=,>= operator for IPv6Address with tests * refactoring the & , |, ~ operator of ipv6_address to "regular" operator
This commit is contained in:
committed by
Matias Fontanini
parent
7848e28b62
commit
342e2c77a7
@@ -52,6 +52,7 @@ TEST_F(HWAddressTest, LessThanOperator) {
|
||||
HWAddress<6> bcast = "ff:ff:ff:ff:ff:ff";
|
||||
EXPECT_LT(addr2, addr1);
|
||||
EXPECT_LT(addr2, bcast);
|
||||
EXPECT_LE(addr1, addr1);
|
||||
std::map<HWAddress<6>, int> dict;
|
||||
dict[addr1] = 12;
|
||||
dict[addr2] = 15;
|
||||
@@ -59,6 +60,20 @@ TEST_F(HWAddressTest, LessThanOperator) {
|
||||
EXPECT_EQ(dict[addr2], 15);
|
||||
}
|
||||
|
||||
TEST_F(HWAddressTest, GreaterThanOperator) {
|
||||
HWAddress<6> addr1(byte_address), addr2(empty_addr);
|
||||
HWAddress<6> bcast = "ff:ff:ff:ff:ff:ff";
|
||||
EXPECT_GT(addr1, addr2);
|
||||
EXPECT_GT(bcast, addr2);
|
||||
EXPECT_GE(addr1, addr1);
|
||||
std::map<HWAddress<6>, int> dict;
|
||||
dict[addr1] = 12;
|
||||
dict[addr2] = 15;
|
||||
EXPECT_EQ(dict[addr1], 12);
|
||||
EXPECT_EQ(dict[addr2], 15);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_F(HWAddressTest, CopyConstructor) {
|
||||
HWAddress<6> addr1(byte_address), addr2(addr1);
|
||||
@@ -115,3 +130,18 @@ TEST_F(HWAddressTest, Mask) {
|
||||
address_type("de:ad:be:ef:00:00") & address_type("ff:ff:ff:f0:00:00")
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(HWAddressTest, OrMask) {
|
||||
typedef HWAddress<6> address_type;
|
||||
EXPECT_EQ(
|
||||
address_type("ff:ff:ff:ff:fe:be"),
|
||||
address_type("de:ad:be:ef:fe:be") | address_type("ff:ff:ff:f0:00:00")
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(HWAddressTest, NotMask) {
|
||||
typedef HWAddress<6> address_type;
|
||||
EXPECT_EQ(
|
||||
address_type("00:00:00:0f:ff:ff"), ~address_type("ff:ff:ff:f0:00:00")
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user