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, link_status );
43 host_status.set_resolved_ip_count( resolved_ip_count );
45 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
46 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
48 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
49 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
51 host_status.update_ping_statistics( PingStatus_FailureOther, 1);
52 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
54 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
55 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
57 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
58 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
60 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
61 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
63 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
64 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
66 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
67 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
69 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
70 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
72 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
73 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
76 BOOST_AUTO_TEST_CASE( fail_percentage_50 )
78 int ping_fail_percentage_limit = 50;
79 int resolved_ip_count = 10;
81 LinkStatusItem link_status( new LinkStatus );
82 HostStatus host_status( "localhost", ping_fail_percentage_limit, link_status );
83 host_status.set_resolved_ip_count( resolved_ip_count );
85 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
86 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
88 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
89 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
91 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
92 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
94 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
95 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
97 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
98 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
100 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
101 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
103 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
104 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
106 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
107 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
109 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
110 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
112 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
113 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
116 BOOST_AUTO_TEST_CASE( fail_percentage_80 )
118 int ping_fail_percentage_limit = 80;
119 int resolved_ip_count = 10;
121 LinkStatusItem link_status( new LinkStatus );
122 HostStatus host_status( "localhost", ping_fail_percentage_limit, link_status );
123 host_status.set_resolved_ip_count( resolved_ip_count );
125 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
126 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
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(), true );
152 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
153 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
156 BOOST_AUTO_TEST_SUITE_END()