Permalink
Browse files

Improve Interface equality checking, test the new Interface string me…

…thods
  • Loading branch information...
peternewman committed Aug 17, 2018
1 parent 3d9e433 commit 75da6b06c55e9986cd99d1fdc13f0c6c90167373
Showing with 26 additions and 7 deletions.
  1. +9 −6 common/network/Interface.cpp
  2. +17 −1 common/network/InterfaceTest.cpp
@@ -120,7 +120,9 @@ Interface& Interface::operator=(const Interface &other) {
bool Interface::operator==(const Interface &other) const {
return (name == other.name &&
ip_address == other.ip_address &&
bcast_address == other.bcast_address &&
subnet_mask == other.subnet_mask &&
hw_address == other.hw_address &&
loopback == other.loopback &&
index == other.index &&
type == other.type);
@@ -130,12 +132,13 @@ bool Interface::operator==(const Interface &other) const {
string Interface::ToString(const string &separator) const {
std::ostringstream str;
str << name << separator
<< "index: " << index << separator
<< "ip: " << ip_address << separator
<< "bcast: " << bcast_address << separator
<< "subnet: " << subnet_mask << separator
<< "type: " << type << separator
<< "hw_addr: " << hw_address;
<< "Index: " << index << separator
<< "IP: " << ip_address << separator
<< "Broadcast: " << bcast_address << separator
<< "Subnet: " << subnet_mask << separator
<< "Type: " << type << separator
<< "MAC: " << hw_address << separator
<< "Loopback: " << loopback;
return str.str();
}

@@ -112,7 +112,7 @@ void InterfaceTest::testBuilder() {
// now build from IPV4Address and MACAddress objects
IPV4Address ip_address, netmask, broadcast_address;
IPV4Address::FromString("10.0.0.1", &ip_address);
IPV4Address::FromString("10.0.255.255", &netmask);
IPV4Address::FromString("255.255.0.0", &netmask);
IPV4Address::FromString("10.0.255.255", &broadcast_address);
MACAddress mac_address;
MACAddress::FromString("ba:98:76:54:32:10", &mac_address);
@@ -129,4 +129,20 @@ void InterfaceTest::testBuilder() {
OLA_ASSERT_EQ(broadcast_address, interface.bcast_address);
OLA_ASSERT_EQ(netmask, interface.subnet_mask);
OLA_ASSERT_EQ(mac_address, interface.hw_address);

// test stringification
OLA_ASSERT_EQ(string("eth1, Index: -1, IP: 10.0.0.1, Broadcast: "
"10.0.255.255, Subnet: 255.255.0.0, Type: 65535, MAC: "
"ba:98:76:54:32:10, Loopback: 0"),
interface.ToString());
OLA_ASSERT_EQ(string("eth1|Index: -1|IP: 10.0.0.1|Broadcast: 10.0.255.255|"
"Subnet: 255.255.0.0|Type: 65535|MAC: "
"ba:98:76:54:32:10|Loopback: 0"),
interface.ToString("|"));
std::ostringstream str;
str << interface;
OLA_ASSERT_EQ(string("eth1, Index: -1, IP: 10.0.0.1, Broadcast: "
"10.0.255.255, Subnet: 255.255.0.0, Type: 65535, MAC: "
"ba:98:76:54:32:10, Loopback: 0"),
str.str());
}

0 comments on commit 75da6b0

Please sign in to comment.