changed value of link_up/down_interval from minutes to seconds
[pingcheck] / test / test_configurationfile.cpp
CommitLineData
288e39de
GMF
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on 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 <iostream>
25#include <fstream>
26#include <streambuf>
27#include <string>
28
29#include <boost/program_options.hpp>
30#include <boost/test/unit_test.hpp>
31
32#include "config/configurationfile.h"
33
34BOOST_AUTO_TEST_SUITE( TestConfigurationFile )
35
36BOOST_AUTO_TEST_CASE( normal_options )
37{
38 boost::program_options::variables_map vm;
39 Configuration config;
40
41 std::string file_name = "pingcheck.conf";
42
43 std::ofstream file;
44 file.open( file_name.c_str() );
504adbea 45 file << "default-source-network-interface=eth0\n";
288e39de
GMF
46 file << "nameserver=localhost\n";
47 file << "hosts-down-limit=2\n";
48 file << "ping-fail-limit=80\n";
49 file << "status-notifier-cmd=scripts/notifier_command.sh\n";
97837af8
CH
50 file << "link-up-interval=600\n";
51 file << "link-down-interval=600\n";
288e39de
GMF
52 // 1st host
53 file << "[host]\n";
54 file << "name=www.intra2net.com\n";
55 file << "port=80\n";
504adbea 56 file << "source-network-interface=wlan1\n";
288e39de
GMF
57 file << "interval=4000\n";
58 file << "ping-protocol=TCP\n";
59 // 2nd host
60 file << "[host]\n";
61 file << "name=www.ufsc.br\n";
62 file << "port=25\n";
7c85a848 63 file << "source-network-interface=eth2\n";
288e39de
GMF
64 file << "interval=1000\n";
65 file << "ping-protocol=ICMP\n";
47f51204
GMF
66 // 3rd host
67 file << "[host]\n";
68 file << "name=www.kernel.org\n";
69 file << "port=80\n";
7c85a848 70 file << "source-network-interface=eth3\n";
47f51204 71 file << "interval=1000\n";
7724b119 72 file << "ping-protocol=TCP,TCP_IPv6\n";
288e39de
GMF
73 file.close();
74
75 ConfigurationFile configuration_file( file_name );
76 bool file_processed = configuration_file.process( &vm );
77 bool file_parsed = configuration_file.parse( vm, &config );
78
79 BOOST_CHECK_EQUAL( file_processed, true );
80 BOOST_CHECK_EQUAL( file_parsed, true );
81
82 BOOST_CHECK_EQUAL( config.get_source_network_interface(), "eth0" );
83 BOOST_CHECK_EQUAL( config.get_nameserver(), "localhost" );
84 BOOST_CHECK_EQUAL( config.get_hosts_down_limit(), 2 );
85 BOOST_CHECK_EQUAL( config.get_ping_fail_limit(), 80 );
86 BOOST_CHECK_EQUAL( config.get_status_notifier_cmd(), "scripts/notifier_command.sh" );
97837af8
CH
87 BOOST_CHECK_EQUAL( config.get_link_up_interval_in_sec(), 600 );
88 BOOST_CHECK_EQUAL( config.get_link_down_interval_in_sec(), 600 );
288e39de 89
47f51204 90 BOOST_CHECK_EQUAL( config.get_hosts().size(), 3 );
288e39de
GMF
91 HostItem host1 = config.get_hosts().at(0);
92 BOOST_CHECK_EQUAL( host1->get_address(), "www.intra2net.com" );
93 BOOST_CHECK_EQUAL( host1->get_port(), 80 );
504adbea 94 BOOST_CHECK_EQUAL( host1->get_source_network_interface(), "wlan1" );
288e39de 95 BOOST_CHECK_EQUAL( host1->get_interval_in_sec(), 4000 );
47f51204
GMF
96 BOOST_CHECK_EQUAL( host1->get_ping_protocol_list().size(), 1 );
97 BOOST_CHECK_EQUAL( host1->get_ping_protocol_list().front(), PingProtocol_TCP );
288e39de
GMF
98 HostItem host2 = config.get_hosts().at(1);
99 BOOST_CHECK_EQUAL( host2->get_address(), "www.ufsc.br" );
100 BOOST_CHECK_EQUAL( host2->get_port(), 25 );
7c85a848 101 BOOST_CHECK_EQUAL( host2->get_source_network_interface(), "eth2" );
288e39de 102 BOOST_CHECK_EQUAL( host2->get_interval_in_sec(), 1000 );
47f51204
GMF
103 BOOST_CHECK_EQUAL( host2->get_ping_protocol_list().size(), 1 );
104 BOOST_CHECK_EQUAL( host2->get_ping_protocol_list().front(), PingProtocol_ICMP );
105 HostItem host3 = config.get_hosts().at(2);
106 BOOST_CHECK_EQUAL( host3->get_address(), "www.kernel.org" );
107 BOOST_CHECK_EQUAL( host3->get_port(), 80 );
7c85a848 108 BOOST_CHECK_EQUAL( host3->get_source_network_interface(), "eth3" );
47f51204
GMF
109 BOOST_CHECK_EQUAL( host3->get_interval_in_sec(), 1000 );
110 BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().size(), 2 );
111 BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().front(), PingProtocol_TCP );
112 BOOST_CHECK_EQUAL( host3->get_ping_protocol_list().back(), PingProtocol_TCP_IPv6 );
288e39de
GMF
113}
114
115BOOST_AUTO_TEST_SUITE_END()