Test: updating the test cases with the new network interface options.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Wed, 14 Mar 2012 00:03:03 +0000 (21:03 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Wed, 14 Mar 2012 00:03:50 +0000 (21:03 -0300)
test/CMakeLists.test_configurationcommandline.txt
test/CMakeLists.test_configurationfile.txt
test/CMakeLists.test_configurationoptions.txt
test/test_configurationcommandline.cpp
test/test_configurationfile.cpp
test/test_configurationoptions.cpp

index 8b8e80c..2ff5f79 100644 (file)
@@ -14,6 +14,7 @@ add_executable(test_configurationcommandline
     ${CMAKE_SOURCE_DIR}/src/config/option/hostpingprotocoloption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/hostportoption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/hostnameoption.cpp
+    ${CMAKE_SOURCE_DIR}/src/config/option/hostsourcenetworkinterfaceoption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/hostsdownlimitoption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/linkdownintervaloption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/linkupintervaloption.cpp
index c83ffa7..721bc93 100644 (file)
@@ -14,6 +14,7 @@ add_executable(test_configurationfile
     ${CMAKE_SOURCE_DIR}/src/config/option/hostpingprotocoloption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/hostportoption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/hostnameoption.cpp
+    ${CMAKE_SOURCE_DIR}/src/config/option/hostsourcenetworkinterfaceoption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/hostsdownlimitoption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/linkdownintervaloption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/linkupintervaloption.cpp
index 0bd9de1..3d4b66b 100644 (file)
@@ -12,6 +12,7 @@ add_executable(test_configurationoptions
     ${CMAKE_SOURCE_DIR}/src/config/option/hostpingprotocoloption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/hostportoption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/hostnameoption.cpp
+    ${CMAKE_SOURCE_DIR}/src/config/option/hostsourcenetworkinterfaceoption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/hostsdownlimitoption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/linkdownintervaloption.cpp
     ${CMAKE_SOURCE_DIR}/src/config/option/linkupintervaloption.cpp
index 127e781..cefcef9 100644 (file)
@@ -32,12 +32,12 @@ BOOST_AUTO_TEST_SUITE( TestConfigurationCommandLine )
 
 BOOST_AUTO_TEST_CASE( normal_options )
 {
-    const int argc = 18;
+    const int argc = 20;
     const char *argv[argc] = {
         "./pingcheck",
         "--daemon",
         "--config-file=conf/config_file.conf",
-        "--source-network-interface=eth0",
+        "--default-source-network-interface=eth0",
         "--nameserver=localhost",
         "--hosts-down-limit=2",
         "--ping-fail-limit=80",
@@ -47,11 +47,13 @@ BOOST_AUTO_TEST_CASE( normal_options )
         // 1st host
         "--host.name=www.intra2net.com",
         "--host.port=80",
+        "--host.source-network-interface=eth0",
         "--host.interval=4000",
         "--host.ping-protocol=TCP",
         // 2nd host
         "--host.name=www.ufsc.br",
         "--host.port=25",
+        "--host.source-network-interface=lo",
         "--host.interval=1000",
         "--host.ping-protocol=ICMP",
     };
@@ -79,11 +81,13 @@ BOOST_AUTO_TEST_CASE( normal_options )
     HostItem host1 = config.get_hosts().at(0);
     BOOST_CHECK_EQUAL( host1->get_address(), "www.intra2net.com" );
     BOOST_CHECK_EQUAL( host1->get_port(), 80 );
+    BOOST_CHECK_EQUAL( host1->get_source_network_interface(), "eth0" );
     BOOST_CHECK_EQUAL( host1->get_interval_in_sec(), 4000 );
     BOOST_CHECK_EQUAL( host1->get_ping_protocol(), PingProtocol_TCP );
     HostItem host2 = config.get_hosts().at(1);
     BOOST_CHECK_EQUAL( host2->get_address(), "www.ufsc.br" );
     BOOST_CHECK_EQUAL( host2->get_port(), 25 );
+    BOOST_CHECK_EQUAL( host2->get_source_network_interface(), "lo" );
     BOOST_CHECK_EQUAL( host2->get_interval_in_sec(), 1000 );
     BOOST_CHECK_EQUAL( host2->get_ping_protocol(), PingProtocol_ICMP );
 }
index 6367f40..0a3fadf 100644 (file)
@@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE( normal_options )
 
     std::ofstream file;
     file.open( file_name.c_str() );
-    file << "source-network-interface=eth0\n";
+    file << "default-source-network-interface=eth0\n";
     file << "nameserver=localhost\n";
     file << "hosts-down-limit=2\n";
     file << "ping-fail-limit=80\n";
@@ -53,12 +53,14 @@ BOOST_AUTO_TEST_CASE( normal_options )
     file << "[host]\n";
     file << "name=www.intra2net.com\n";
     file << "port=80\n";
+    file << "source-network-interface=wlan1\n";
     file << "interval=4000\n";
     file << "ping-protocol=TCP\n";
     // 2nd host
     file << "[host]\n";
     file << "name=www.ufsc.br\n";
     file << "port=25\n";
+    file << "source-network-interface=eth3\n";
     file << "interval=1000\n";
     file << "ping-protocol=ICMP\n";
     file.close();
@@ -82,11 +84,13 @@ BOOST_AUTO_TEST_CASE( normal_options )
     HostItem host1 = config.get_hosts().at(0);
     BOOST_CHECK_EQUAL( host1->get_address(), "www.intra2net.com" );
     BOOST_CHECK_EQUAL( host1->get_port(), 80 );
+    BOOST_CHECK_EQUAL( host1->get_source_network_interface(), "wlan1" );
     BOOST_CHECK_EQUAL( host1->get_interval_in_sec(), 4000 );
     BOOST_CHECK_EQUAL( host1->get_ping_protocol(), PingProtocol_TCP );
     HostItem host2 = config.get_hosts().at(1);
     BOOST_CHECK_EQUAL( host2->get_address(), "www.ufsc.br" );
     BOOST_CHECK_EQUAL( host2->get_port(), 25 );
+    BOOST_CHECK_EQUAL( host2->get_source_network_interface(), "eth3" );
     BOOST_CHECK_EQUAL( host2->get_interval_in_sec(), 1000 );
     BOOST_CHECK_EQUAL( host2->get_ping_protocol(), PingProtocol_ICMP );
 }
index 4ed317c..a503299 100644 (file)
@@ -119,17 +119,18 @@ BOOST_AUTO_TEST_CASE( get_configuration_options )
 
     // if this assert fails, you must add or remove one of the options in the
     // test bellow
-    BOOST_CHECK_EQUAL( options.size(), 11 );
+    BOOST_CHECK_EQUAL( options.size(), 12 );
 
     BOOST_CHECK_EQUAL( option_present( options, "hosts-down-limit" ), true );
     BOOST_CHECK_EQUAL( option_present( options, "link-down-interval" ), true );
     BOOST_CHECK_EQUAL( option_present( options, "link-up-interval" ), true );
     BOOST_CHECK_EQUAL( option_present( options, "nameserver" ), true );
     BOOST_CHECK_EQUAL( option_present( options, "ping-fail-limit" ), true );
-    BOOST_CHECK_EQUAL( option_present( options, "source-network-interface" ), true );
+    BOOST_CHECK_EQUAL( option_present( options, "default-source-network-interface" ), true );
     BOOST_CHECK_EQUAL( option_present( options, "status-notifier-cmd" ), true );
     BOOST_CHECK_EQUAL( option_present( options, "host.name" ), true );
     BOOST_CHECK_EQUAL( option_present( options, "host.port" ), true );
+    BOOST_CHECK_EQUAL( option_present( options, "host.source-network-interface" ), true );
     BOOST_CHECK_EQUAL( option_present( options, "host.ping-protocol" ), true );
     BOOST_CHECK_EQUAL( option_present( options, "host.interval" ), true );
 }
@@ -160,7 +161,7 @@ BOOST_AUTO_TEST_CASE( parse_configuration_options )
     option_insert( "link-up-interval", boost::any( 40 ), vm );
     option_insert( "nameserver", boost::any( std::string("localhost") ), vm );
     option_insert( "ping-fail-limit", boost::any( 50 ), vm );
-    option_insert( "source-network-interface", boost::any( std::string("wlan1") ), vm );
+    option_insert( "default-source-network-interface", boost::any( std::string("wlan1") ), vm );
     option_insert( "status-notifier-cmd", boost::any( std::string("/tmp/command.sh") ), vm );
 
     ConfigurationOptions config_options;
@@ -180,26 +181,31 @@ BOOST_AUTO_TEST_CASE( parse_hosts_options )
 {
     std::vector<std::string> hosts_names;
     std::vector<int> hosts_ports;
+    std::vector<std::string> hosts_source_interfaces;
     std::vector<std::string> hosts_ping_protocols;
     std::vector<int> hosts_intervals;
     // host 1
     hosts_names.push_back( "www.fazenda.gov.br" );
     hosts_ports.push_back( 61 );
+    hosts_source_interfaces.push_back( "eth1" );
     hosts_ping_protocols.push_back( "TCP" );
     hosts_intervals.push_back( 71 );
     // host 2
     hosts_names.push_back( "www.intra2net.de" );
     hosts_ports.push_back( 62 );
+    hosts_source_interfaces.push_back( "eth2" );
     hosts_ping_protocols.push_back( "ICMP" );
     hosts_intervals.push_back( 72 );
     // host 3
     hosts_names.push_back( "www.ufsc.br" );
     hosts_ports.push_back( 63 );
+    hosts_source_interfaces.push_back( "eth3" );
     hosts_ping_protocols.push_back( "ICMPv6" );
     hosts_intervals.push_back( 73 );
     // host 4
     hosts_names.push_back( "www.google.com" );
     hosts_ports.push_back( 64 );
+    hosts_source_interfaces.push_back( "eth4" );
     hosts_ping_protocols.push_back( "TCP_IPv6" );
     hosts_intervals.push_back( 74 );
 
@@ -209,6 +215,7 @@ BOOST_AUTO_TEST_CASE( parse_hosts_options )
     option_insert( "host.name", boost::any( hosts_names ), vm );
     option_insert( "host.port", boost::any( hosts_ports ), vm );
     option_insert( "host.ping-protocol", boost::any( hosts_ping_protocols ), vm );
+    option_insert( "host.source-network-interface", boost::any( hosts_source_interfaces ), vm );
     option_insert( "host.interval", boost::any( hosts_intervals ), vm );
 
     config_options.parse_configuration_options( vm, &configuration );
@@ -217,24 +224,28 @@ BOOST_AUTO_TEST_CASE( parse_hosts_options )
      HostItem host1 = configuration.get_hosts().at(0);
     BOOST_CHECK_EQUAL( host1->get_address(), "www.fazenda.gov.br" );
     BOOST_CHECK_EQUAL( host1->get_port(), 61 );
+    BOOST_CHECK_EQUAL( host1->get_source_network_interface(), "eth1" );
     BOOST_CHECK_EQUAL( host1->get_ping_protocol(), PingProtocol_TCP );
     BOOST_CHECK_EQUAL( host1->get_interval_in_sec(), 71 );
     // host 2
      HostItem host2 = configuration.get_hosts().at(1);
     BOOST_CHECK_EQUAL( host2->get_address(), "www.intra2net.de" );
     BOOST_CHECK_EQUAL( host2->get_port(), 62 );
+    BOOST_CHECK_EQUAL( host2->get_source_network_interface(), "eth2" );
     BOOST_CHECK_EQUAL( host2->get_ping_protocol(), PingProtocol_ICMP );
     BOOST_CHECK_EQUAL( host2->get_interval_in_sec(), 72 );
     // host 3
      HostItem host3 = configuration.get_hosts().at(2);
     BOOST_CHECK_EQUAL( host3->get_address(), "www.ufsc.br" );
     BOOST_CHECK_EQUAL( host3->get_port(), 63 );
+    BOOST_CHECK_EQUAL( host3->get_source_network_interface(), "eth3" );
     BOOST_CHECK_EQUAL( host3->get_ping_protocol(), PingProtocol_ICMPv6 );
     BOOST_CHECK_EQUAL( host3->get_interval_in_sec(), 73 );
     // host 4
      HostItem host4 = configuration.get_hosts().at(3);
     BOOST_CHECK_EQUAL( host4->get_address(), "www.google.com" );
     BOOST_CHECK_EQUAL( host4->get_port(), 64 );
+    BOOST_CHECK_EQUAL( host4->get_source_network_interface(), "eth4" );
     BOOST_CHECK_EQUAL( host4->get_ping_protocol(), PingProtocol_TCP_IPv6 );
     BOOST_CHECK_EQUAL( host4->get_interval_in_sec(), 74 );
 }
@@ -275,7 +286,7 @@ BOOST_AUTO_TEST_CASE( halt_on_generic_options )
     option_clear_and_insert( "ping-fail-limit", value, vm );
     BOOST_CHECK_EQUAL( config_options.halt_on_generic_options( vm ), false );
 
-    option_clear_and_insert( "source-network-interface", value, vm );
+    option_clear_and_insert( "default-source-network-interface", value, vm );
     BOOST_CHECK_EQUAL( config_options.halt_on_generic_options( vm ), false );
 
     option_clear_and_insert( "status-notifier-cmd", value, vm );
@@ -287,6 +298,9 @@ BOOST_AUTO_TEST_CASE( halt_on_generic_options )
     option_clear_and_insert( "host.port", value, vm );
     BOOST_CHECK_EQUAL( config_options.halt_on_generic_options( vm ), false );
 
+    option_clear_and_insert( "host.source-network-interface", value, vm );
+    BOOST_CHECK_EQUAL( config_options.halt_on_generic_options( vm ), false );
+
     option_clear_and_insert( "host.ping-protocol", value, vm );
     BOOST_CHECK_EQUAL( config_options.halt_on_generic_options( vm ), false );