Commit | Line | Data |
---|---|---|
5dfcc527 GMF |
1 | /* |
2 | The software in this package is distributed under the GNU General | |
3 | Public License version 2 (with a special exception described below). | |
4 | ||
5 | A copy of GNU General Public License (GPL) is included in this distribution, | |
6 | in the file COPYING.GPL. | |
7 | ||
8 | As a special exception, if other files instantiate templates or use macros | |
9 | or inline functions from this file, or you compile this file and link it | |
10 | with other works to produce a work based on this file, this file | |
11 | does not by itself cause the resulting work to be covered | |
12 | by the GNU General Public License. | |
13 | ||
14 | However the source code for this file must still be made available | |
15 | in accordance with section (3) of the GNU General Public License. | |
16 | ||
17 | This exception does not invalidate any other reasons why a work based | |
18 | on this file might be covered by the GNU General Public License. | |
19 | */ | |
20 | ||
21 | #define BOOST_TEST_MAIN | |
22 | #define BOOST_TEST_DYN_LINK | |
23 | ||
24 | #include <streambuf> | |
25 | ||
26 | #include <boost/program_options.hpp> | |
27 | #include <boost/test/unit_test.hpp> | |
28 | ||
29 | #include "config/configurationcommandline.h" | |
30 | ||
31 | BOOST_AUTO_TEST_SUITE( TestConfigurationCommandLine ) | |
32 | ||
33 | BOOST_AUTO_TEST_CASE( normal_options ) | |
34 | { | |
7c85a848 | 35 | const int argc = 25; |
5c3c6449 | 36 | const char *argv[argc] = { |
5dfcc527 | 37 | "./pingcheck", |
8a8f3cea | 38 | "--daemon", |
5dfcc527 | 39 | "--config-file=conf/config_file.conf", |
504adbea | 40 | "--default-source-network-interface=eth0", |
5dfcc527 GMF |
41 | "--nameserver=localhost", |
42 | "--hosts-down-limit=2", | |
43 | "--ping-fail-limit=80", | |
44 | "--status-notifier-cmd=scripts/notifier_command.sh", | |
97837af8 CH |
45 | "--link-up-interval=600", |
46 | "--link-down-interval=600", | |
8a8f3cea | 47 | // 1st host |
5dfcc527 GMF |
48 | "--host.name=www.intra2net.com", |
49 | "--host.port=80", | |
504adbea | 50 | "--host.source-network-interface=eth0", |
5dfcc527 GMF |
51 | "--host.interval=4000", |
52 | "--host.ping-protocol=TCP", | |
8a8f3cea | 53 | // 2nd host |
5dfcc527 GMF |
54 | "--host.name=www.ufsc.br", |
55 | "--host.port=25", | |
504adbea | 56 | "--host.source-network-interface=lo", |
5dfcc527 GMF |
57 | "--host.interval=1000", |
58 | "--host.ping-protocol=ICMP", | |
47f51204 GMF |
59 | // 3rd host |
60 | "--host.name=www.kernel.org", | |
61 | "--host.port=80", | |
7c85a848 | 62 | "--host.source-network-interface=eth1", |
47f51204 | 63 | "--host.interval=1000", |
7724b119 | 64 | "--host.ping-protocol=ICMP,ICMPv6", |
5dfcc527 GMF |
65 | }; |
66 | boost::program_options::variables_map vm; | |
67 | Configuration config; | |
68 | ||
69 | ConfigurationCommandLine command_line( argc, argv ); | |
70 | bool command_line_processed = command_line.process( &vm ); | |
71 | bool command_line_parsed = command_line.parse( vm, &config ); | |
72 | ||
73 | BOOST_CHECK_EQUAL( command_line_processed, true ); | |
74 | BOOST_CHECK_EQUAL( command_line_parsed, true ); | |
75 | ||
8a8f3cea | 76 | BOOST_CHECK_EQUAL( config.get_daemon(), true ); |
5dfcc527 GMF |
77 | BOOST_CHECK_EQUAL( config.get_config_file_name(), "conf/config_file.conf" ); |
78 | BOOST_CHECK_EQUAL( config.get_source_network_interface(), "eth0" ); | |
79 | BOOST_CHECK_EQUAL( config.get_nameserver(), "localhost" ); | |
80 | BOOST_CHECK_EQUAL( config.get_hosts_down_limit(), 2 ); | |
81 | BOOST_CHECK_EQUAL( config.get_ping_fail_limit(), 80 ); | |
82 | BOOST_CHECK_EQUAL( config.get_status_notifier_cmd(), "scripts/notifier_command.sh" ); | |
97837af8 CH |
83 | BOOST_CHECK_EQUAL( config.get_link_up_interval_in_sec(), 600 ); |
84 | BOOST_CHECK_EQUAL( config.get_link_down_interval_in_sec(), 600 ); | |
5dfcc527 | 85 | |
47f51204 | 86 | BOOST_CHECK_EQUAL( config.get_hosts().size(), 3 ); |
5dfcc527 GMF |
87 | HostItem host1 = config.get_hosts().at(0); |
88 | BOOST_CHECK_EQUAL( host1->get_address(), "www.intra2net.com" ); | |
89 | BOOST_CHECK_EQUAL( host1->get_port(), 80 ); | |
504adbea | 90 | BOOST_CHECK_EQUAL( host1->get_source_network_interface(), "eth0" ); |
5dfcc527 | 91 | BOOST_CHECK_EQUAL( host1->get_interval_in_sec(), 4000 ); |
47f51204 GMF |
92 | BOOST_CHECK_EQUAL( host1->get_ping_protocol_list().size(), 1 ); |
93 | BOOST_CHECK_EQUAL( host1->get_ping_protocol_list().front(), PingProtocol_TCP ); | |
5dfcc527 GMF |
94 | HostItem host2 = config.get_hosts().at(1); |
95 | BOOST_CHECK_EQUAL( host2->get_address(), "www.ufsc.br" ); | |
96 | BOOST_CHECK_EQUAL( host2->get_port(), 25 ); | |
504adbea | 97 | BOOST_CHECK_EQUAL( host2->get_source_network_interface(), "lo" ); |
5dfcc527 | 98 | BOOST_CHECK_EQUAL( host2->get_interval_in_sec(), 1000 ); |
47f51204 GMF |
99 | BOOST_CHECK_EQUAL( host2->get_ping_protocol_list().size(), 1 ); |
100 | BOOST_CHECK_EQUAL( host2->get_ping_protocol_list().front(), PingProtocol_ICMP ); | |
101 | HostItem host3 = config.get_hosts().at(2); | |
102 | BOOST_CHECK_EQUAL( host3->get_address(), "www.kernel.org" ); | |
103 | BOOST_CHECK_EQUAL( host3->get_port(), 80 ); | |
7c85a848 | 104 | BOOST_CHECK_EQUAL( host3->get_source_network_interface(), "eth1" ); |
47f51204 GMF |
105 | BOOST_CHECK_EQUAL( host3->get_interval_in_sec(), 1000 ); |
106 | BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().size(), 2 ); | |
107 | BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().front(), PingProtocol_ICMP ); | |
108 | BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().back(), PingProtocol_ICMPv6 ); | |
5dfcc527 GMF |
109 | } |
110 | ||
111 | BOOST_AUTO_TEST_CASE( version_option ) | |
112 | { | |
5c3c6449 | 113 | const char *argv[2] = { "./pingcheck", "--version" }; |
5dfcc527 GMF |
114 | const int argc = 2; |
115 | boost::program_options::variables_map vm; | |
116 | Configuration config; | |
117 | ||
118 | ConfigurationCommandLine command_line( argc, argv ); | |
119 | bool command_line_processed = command_line.process( &vm ); | |
120 | ||
121 | bool command_line_parsed = command_line.parse( vm, &config ); | |
122 | ||
123 | BOOST_CHECK_EQUAL( command_line_processed, true ); | |
124 | BOOST_CHECK_EQUAL( command_line_parsed, false ); | |
125 | } | |
126 | ||
127 | BOOST_AUTO_TEST_CASE( help_option ) | |
128 | { | |
5c3c6449 | 129 | const char *argv[2] = { "./pingcheck", "--help" }; |
5dfcc527 GMF |
130 | const int argc = 2; |
131 | boost::program_options::variables_map vm; | |
132 | Configuration config; | |
133 | ||
134 | ConfigurationCommandLine command_line( argc, argv ); | |
135 | bool command_line_processed = command_line.process( &vm ); | |
136 | ||
137 | bool command_line_parsed = command_line.parse( vm, &config ); | |
138 | ||
139 | BOOST_CHECK_EQUAL( command_line_processed, true ); | |
140 | BOOST_CHECK_EQUAL( command_line_parsed, false ); | |
141 | } | |
142 | ||
143 | BOOST_AUTO_TEST_SUITE_END() |