/* The software in this package is distributed under the GNU General Public License version 2 (with a special exception described below). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING.GPL. As a special exception, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other works to produce a work based on this file, this file does not by itself cause the resulting work to be covered by the GNU General Public License. However the source code for this file must still be made available in accordance with section (3) of the GNU General Public License. This exception does not invalidate any other reasons why a work based on this file might be covered by the GNU General Public License. */ #define BOOST_TEST_MAIN #define BOOST_TEST_DYN_LINK #include #include #include #include "config/configurationcommandline.h" BOOST_AUTO_TEST_SUITE( TestConfigurationCommandLine ) BOOST_AUTO_TEST_CASE( normal_options ) { const int argc = 25; const char *argv[argc] = { "./pingcheck", "--daemon", "--config-file=conf/config_file.conf", "--default-source-network-interface=eth0", "--nameserver=localhost", "--hosts-down-limit=2", "--ping-fail-limit=80", "--status-notifier-cmd=scripts/notifier_command.sh", "--link-up-interval=600", "--link-down-interval=600", // 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", // 3rd host "--host.name=www.kernel.org", "--host.port=80", "--host.source-network-interface=eth1", "--host.interval=1000", "--host.ping-protocol=ICMP,ICMPv6", }; boost::program_options::variables_map vm; Configuration config; ConfigurationCommandLine command_line( argc, argv ); bool command_line_processed = command_line.process( &vm ); bool command_line_parsed = command_line.parse( vm, &config ); BOOST_CHECK_EQUAL( command_line_processed, true ); BOOST_CHECK_EQUAL( command_line_parsed, true ); BOOST_CHECK_EQUAL( config.get_daemon(), true ); BOOST_CHECK_EQUAL( config.get_config_file_name(), "conf/config_file.conf" ); BOOST_CHECK_EQUAL( config.get_source_network_interface(), "eth0" ); BOOST_CHECK_EQUAL( config.get_nameserver(), "localhost" ); BOOST_CHECK_EQUAL( config.get_hosts_down_limit(), 2 ); BOOST_CHECK_EQUAL( config.get_ping_fail_limit(), 80 ); BOOST_CHECK_EQUAL( config.get_status_notifier_cmd(), "scripts/notifier_command.sh" ); BOOST_CHECK_EQUAL( config.get_link_up_interval_in_sec(), 600 ); BOOST_CHECK_EQUAL( config.get_link_down_interval_in_sec(), 600 ); BOOST_CHECK_EQUAL( config.get_hosts().size(), 3 ); 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_list().size(), 1 ); BOOST_CHECK_EQUAL( host1->get_ping_protocol_list().front(), 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_list().size(), 1 ); BOOST_CHECK_EQUAL( host2->get_ping_protocol_list().front(), PingProtocol_ICMP ); HostItem host3 = config.get_hosts().at(2); BOOST_CHECK_EQUAL( host3->get_address(), "www.kernel.org" ); BOOST_CHECK_EQUAL( host3->get_port(), 80 ); BOOST_CHECK_EQUAL( host3->get_source_network_interface(), "eth1" ); BOOST_CHECK_EQUAL( host3->get_interval_in_sec(), 1000 ); BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().size(), 2 ); BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().front(), PingProtocol_ICMP ); BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().back(), PingProtocol_ICMPv6 ); } BOOST_AUTO_TEST_CASE( version_option ) { const char *argv[2] = { "./pingcheck", "--version" }; const int argc = 2; boost::program_options::variables_map vm; Configuration config; ConfigurationCommandLine command_line( argc, argv ); bool command_line_processed = command_line.process( &vm ); bool command_line_parsed = command_line.parse( vm, &config ); BOOST_CHECK_EQUAL( command_line_processed, true ); BOOST_CHECK_EQUAL( command_line_parsed, false ); } BOOST_AUTO_TEST_CASE( help_option ) { const char *argv[2] = { "./pingcheck", "--help" }; const int argc = 2; boost::program_options::variables_map vm; Configuration config; ConfigurationCommandLine command_line( argc, argv ); bool command_line_processed = command_line.process( &vm ); bool command_line_parsed = command_line.parse( vm, &config ); BOOST_CHECK_EQUAL( command_line_processed, true ); BOOST_CHECK_EQUAL( command_line_parsed, false ); } BOOST_AUTO_TEST_SUITE_END()