Skip to content
Snippets Groups Projects
Commit 693303f4 authored by tho's avatar tho
Browse files

added some tests

parent a053b599
No related branches found
No related tags found
No related merge requests found
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
// Custom includes // Custom includes
#include "NetdeviceController.hh" #include "NetdeviceController.hh"
#include "Protocols/Raw/MACAddress.hh" #include "Protocols/Raw/MACAddress.hh"
#include <net/if.h>
#include "../Utils/auto_unit_test.hh" #include "../Utils/auto_unit_test.hh"
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>
...@@ -38,11 +39,13 @@ ...@@ -38,11 +39,13 @@
BOOST_AUTO_UNIT_TEST(NetdeviceController) { BOOST_AUTO_UNIT_TEST(NetdeviceController) {
senf::NetdeviceController ctrl ("lo"); std::string ifname ("lo");
BOOST_CHECK_EQUAL( ctrl.interfaceName(), "lo"); senf::NetdeviceController ctrl (ifname);
BOOST_CHECK_EQUAL( ctrl.interfaceName(), ifname);
int index = ctrl.interfaceIndex(); int index = ctrl.interfaceIndex();
BOOST_CHECK_EQUAL( index, senf::NetdeviceController(index).interfaceIndex() ); BOOST_CHECK_EQUAL( index, senf::NetdeviceController(index).interfaceIndex() );
BOOST_CHECK_EQUAL( index, if_nametoindex( ifname.c_str()) );
BOOST_CHECK_THROW( senf::NetdeviceController("invalid_interfacename"), senf::SystemException ); BOOST_CHECK_THROW( senf::NetdeviceController("invalid_interfacename"), senf::SystemException );
...@@ -51,6 +54,8 @@ BOOST_AUTO_UNIT_TEST(NetdeviceController) { ...@@ -51,6 +54,8 @@ BOOST_AUTO_UNIT_TEST(NetdeviceController) {
bool promisc; bool promisc;
SENF_CHECK_NO_THROW( promisc = ctrl.promisc()); SENF_CHECK_NO_THROW( promisc = ctrl.promisc());
BOOST_CHECK( ctrl.isUp());
if (getuid() != 0) { if (getuid() != 0) {
BOOST_WARN_MESSAGE(false, "Cannot run some tests of senf::NetdeviceController as non-root user"); BOOST_WARN_MESSAGE(false, "Cannot run some tests of senf::NetdeviceController as non-root user");
...@@ -71,7 +76,7 @@ BOOST_AUTO_UNIT_TEST(NetdeviceController) { ...@@ -71,7 +76,7 @@ BOOST_AUTO_UNIT_TEST(NetdeviceController) {
///////////////////////////////cc.e//////////////////////////////////////// ///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_ #undef prefix_
// Local Variables: // Local Variables:
// mode: c++ // mode: c++
// fill-column: 100 // fill-column: 100
......
...@@ -69,10 +69,15 @@ namespace { ...@@ -69,10 +69,15 @@ namespace {
BOOST_AUTO_UNIT_TEST(configBundle) BOOST_AUTO_UNIT_TEST(configBundle)
{ {
senf::console::ScopedDirectory<> root; senf::console::ScopedDirectory<> root;
senf::console::root().add("root",root); senf::console::root().add("root", root);
root.mkdir("dir1").add("fun1",&fun1); senf::console::ScopedDirectory<> chroot;
root.add("fun2",&fun2); senf::console::root().add("chroot", chroot);
root.mkdir("dir1").add("fun1", &fun1);
root.add("fun2", &fun2);
chroot.mkdir("dir1").add("fun1", &fun1);
chroot.add("fun2", &fun2);
TempFile cfg ("test.cfg"); TempFile cfg ("test.cfg");
cfg << "dir1/fun1 foo; fun2;" << TempFile::close; cfg << "dir1/fun1 foo; fun2;" << TempFile::close;
...@@ -86,6 +91,11 @@ BOOST_AUTO_UNIT_TEST(configBundle) ...@@ -86,6 +91,11 @@ BOOST_AUTO_UNIT_TEST(configBundle)
SENF_CHECK_NO_THROW( bundle.parse() ); SENF_CHECK_NO_THROW( bundle.parse() );
BOOST_CHECK_EQUAL( val1, "bar" ); BOOST_CHECK_EQUAL( val1, "bar" );
BOOST_CHECK_EQUAL( val2, true ); BOOST_CHECK_EQUAL( val2, true );
bundle.chroot( chroot);
SENF_CHECK_NO_THROW( bundle.parse() );
BOOST_CHECK_EQUAL( val1, "bar" );
BOOST_CHECK_EQUAL( val2, true );
} }
///////////////////////////////cc.e//////////////////////////////////////// ///////////////////////////////cc.e////////////////////////////////////////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment