summaryrefslogtreecommitdiffstats
path: root/test/test_vlan_interface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_vlan_interface.cpp')
-rw-r--r--test/test_vlan_interface.cpp157
1 files changed, 74 insertions, 83 deletions
diff --git a/test/test_vlan_interface.cpp b/test/test_vlan_interface.cpp
index 00384f1..1bcd87a 100644
--- a/test/test_vlan_interface.cpp
+++ b/test/test_vlan_interface.cpp
@@ -1,17 +1,18 @@
-#include "network_manager.hpp"
-#include "mock_syscall.hpp"
#include "config_parser.hpp"
-#include "vlan_interface.hpp"
#include "ipaddress.hpp"
+#include "mock_syscall.hpp"
+#include "network_manager.hpp"
+#include "vlan_interface.hpp"
-#include <gtest/gtest.h>
-#include <sdbusplus/bus.hpp>
-
+#include <arpa/inet.h>
#include <net/if.h>
#include <netinet/in.h>
-#include <arpa/inet.h>
+
#include <exception>
#include <experimental/filesystem>
+#include <sdbusplus/bus.hpp>
+
+#include <gtest/gtest.h>
namespace phosphor
{
@@ -22,98 +23,89 @@ namespace fs = std::experimental::filesystem;
class TestVlanInterface : public testing::Test
{
- public:
+ public:
+ sdbusplus::bus::bus bus;
+ Manager manager;
+ EthernetInterface interface;
+ std::string confDir;
+ TestVlanInterface() :
+ bus(sdbusplus::bus::new_default()),
+ manager(bus, "/xyz/openbmc_test/network", "/tmp"),
+ interface(bus, "/xyz/openbmc_test/network/test0", false, manager)
- sdbusplus::bus::bus bus;
- Manager manager;
- EthernetInterface interface;
- std::string confDir;
- TestVlanInterface()
- : bus(sdbusplus::bus::new_default()),
- manager(bus, "/xyz/openbmc_test/network", "/tmp"),
- interface(bus, "/xyz/openbmc_test/network/test0", false, manager)
-
- {
- setConfDir();
- }
+ {
+ setConfDir();
+ }
- ~TestVlanInterface()
+ ~TestVlanInterface()
+ {
+ if (confDir != "")
{
- if(confDir != "")
- {
- fs::remove_all(confDir);
- }
+ fs::remove_all(confDir);
}
+ }
- void setConfDir()
- {
- char tmp[] = "/tmp/VlanInterface.XXXXXX";
- confDir = mkdtemp(tmp);
- manager.setConfDir(confDir);
- }
+ void setConfDir()
+ {
+ char tmp[] = "/tmp/VlanInterface.XXXXXX";
+ confDir = mkdtemp(tmp);
+ manager.setConfDir(confDir);
+ }
- void createVlan(VlanId id)
- {
- interface.createVLAN(id);
- }
+ void createVlan(VlanId id)
+ {
+ interface.createVLAN(id);
+ }
- void deleteVlan(const std::string& interfaceName)
- {
- interface.deleteVLANObject(interfaceName);
- }
+ void deleteVlan(const std::string& interfaceName)
+ {
+ interface.deleteVLANObject(interfaceName);
+ }
- int countIPObjects()
- {
- return interface.getAddresses().size();
- }
+ int countIPObjects()
+ {
+ return interface.getAddresses().size();
+ }
- bool isIPObjectExist(const std::string& ipaddress)
+ bool isIPObjectExist(const std::string& ipaddress)
+ {
+ auto address = interface.getAddresses().find(ipaddress);
+ if (address == interface.getAddresses().end())
{
- auto address = interface.getAddresses().find(ipaddress);
- if (address == interface.getAddresses().end())
- {
- return false;
- }
- return true;
-
+ return false;
}
+ return true;
+ }
- bool deleteIPObject(const std::string& ipaddress)
+ bool deleteIPObject(const std::string& ipaddress)
+ {
+ auto address = interface.getAddresses().find(ipaddress);
+ if (address == interface.getAddresses().end())
{
- auto address = interface.getAddresses().find(ipaddress);
- if (address == interface.getAddresses().end())
- {
- return false;
- }
- address->second->delete_();
- return true;
+ return false;
}
+ address->second->delete_();
+ return true;
+ }
- void createIPObject(IP::Protocol addressType,
- const std::string& ipaddress,
- uint8_t subnetMask,
- const std::string& gateway)
- {
- interface.iP(addressType,
- ipaddress,
- subnetMask,
- gateway
- );
-
- }
+ void createIPObject(IP::Protocol addressType, const std::string& ipaddress,
+ uint8_t subnetMask, const std::string& gateway)
+ {
+ interface.iP(addressType, ipaddress, subnetMask, gateway);
+ }
- bool isValueFound(const std::vector<std::string>& values,
- const std::string& expectedValue)
+ bool isValueFound(const std::vector<std::string>& values,
+ const std::string& expectedValue)
+ {
+ for (const auto& value : values)
{
- for (const auto& value : values)
+ if (expectedValue == value)
{
- if (expectedValue == value)
- {
- return true;
- }
+ return true;
}
- return false;
}
+ return false;
+ }
};
TEST_F(TestVlanInterface, createVLAN)
@@ -140,7 +132,6 @@ TEST_F(TestVlanInterface, createVLAN)
expectedValue = "50";
found = isValueFound(values, expectedValue);
EXPECT_EQ(found, true);
-
}
TEST_F(TestVlanInterface, deleteVLAN)
@@ -153,7 +144,7 @@ TEST_F(TestVlanInterface, deleteVLAN)
filePath /= "test0.50.netdev";
if (fs::is_regular_file(filePath.string()))
{
- fileFound = true;
+ fileFound = true;
}
EXPECT_EQ(fileFound, false);
}
@@ -201,5 +192,5 @@ TEST_F(TestVlanInterface, createMultipleVLAN)
deleteVlan("test0.60");
}
-}// namespce network
-}// namespace phosphor
+} // namespace network
+} // namespace phosphor
OpenPOWER on IntegriCloud