2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
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.
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.
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.
21 #define BOOST_TEST_MAIN
22 #define BOOST_TEST_DYN_LINK
26 #include <boost/asio.hpp>
27 #include <boost/test/unit_test.hpp>
29 #include "mock_linkstatus.h"
31 #include "host/hoststatus.h"
32 #include "host/pingstatus.h"
34 BOOST_AUTO_TEST_SUITE( TestHostStatus )
36 BOOST_AUTO_TEST_CASE( fail_percentage_10 )
38 int ping_fail_percentage_limit = 10;
39 int resolved_ip_count = 10;
41 LinkStatusItem link_status( new LinkStatus );
42 HostStatus host_status( "localhost", ping_fail_percentage_limit, 1,
44 host_status.set_resolved_ip_count( resolved_ip_count );
46 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
47 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
49 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
50 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
52 host_status.update_ping_statistics( PingStatus_FailureOther, 1);
53 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
55 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
56 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
58 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
59 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
61 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
62 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
64 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
65 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
67 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
68 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
70 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
71 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
73 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
74 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
77 BOOST_AUTO_TEST_CASE( fail_percentage_50 )
79 int ping_fail_percentage_limit = 50;
80 int resolved_ip_count = 10;
82 LinkStatusItem link_status( new LinkStatus );
83 HostStatus host_status( "localhost", ping_fail_percentage_limit, 1,
85 host_status.set_resolved_ip_count( resolved_ip_count );
87 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
88 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
90 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
91 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
93 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
94 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
96 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
97 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
99 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
100 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
102 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
103 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
105 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
106 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
108 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
109 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
111 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
112 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
114 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
115 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
118 BOOST_AUTO_TEST_CASE( fail_percentage_80 )
120 int ping_fail_percentage_limit = 80;
121 int resolved_ip_count = 10;
123 LinkStatusItem link_status( new LinkStatus );
124 HostStatus host_status( "localhost", ping_fail_percentage_limit, 1,
126 host_status.set_resolved_ip_count( resolved_ip_count );
128 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
129 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
131 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
132 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
134 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
135 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
137 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
138 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
140 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
141 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
143 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
144 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
146 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
147 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
149 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
150 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
152 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
153 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
155 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
156 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
159 BOOST_AUTO_TEST_SUITE_END()