Commit | Line | Data |
---|---|---|
6f19218c 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 | ||
a72f06b6 | 21 | #define BOOST_TEST_MAIN |
6f19218c | 22 | #define BOOST_TEST_DYN_LINK |
6f19218c GMF |
23 | |
24 | #include <streambuf> | |
25 | ||
26 | #include <boost/asio.hpp> | |
27 | #include <boost/test/unit_test.hpp> | |
28 | ||
72e54d1c | 29 | #include "mock_linkstatus.h" |
6f19218c | 30 | |
6c14bbee | 31 | #include "host/hoststatus.h" |
96c4e7a4 | 32 | #include "host/pingstatus.h" |
6f19218c | 33 | |
6c14bbee | 34 | BOOST_AUTO_TEST_SUITE( TestHostStatus ) |
6f19218c GMF |
35 | |
36 | BOOST_AUTO_TEST_CASE( fail_percentage_10 ) | |
37 | { | |
38 | int ping_fail_percentage_limit = 10; | |
39 | int resolved_ip_count = 10; | |
40 | ||
72e54d1c | 41 | LinkStatusItem link_status( new LinkStatus ); |
6c14bbee | 42 | HostStatus host_status( "localhost", ping_fail_percentage_limit, link_status ); |
6f19218c GMF |
43 | host_status.set_resolved_ip_count( resolved_ip_count ); |
44 | ||
96c4e7a4 | 45 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
46 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
47 | ||
96c4e7a4 | 48 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
49 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
50 | ||
96c4e7a4 | 51 | host_status.update_ping_statistics( PingStatus_FailureOther, 1); |
6f19218c GMF |
52 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
53 | ||
96c4e7a4 | 54 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
55 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
56 | ||
96c4e7a4 | 57 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
58 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
59 | ||
96c4e7a4 | 60 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
61 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
62 | ||
96c4e7a4 | 63 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
64 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
65 | ||
96c4e7a4 | 66 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
67 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
68 | ||
96c4e7a4 | 69 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
70 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
71 | ||
96c4e7a4 | 72 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
73 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
74 | } | |
75 | ||
76 | BOOST_AUTO_TEST_CASE( fail_percentage_50 ) | |
77 | { | |
78 | int ping_fail_percentage_limit = 50; | |
79 | int resolved_ip_count = 10; | |
80 | ||
72e54d1c | 81 | LinkStatusItem link_status( new LinkStatus ); |
6c14bbee | 82 | HostStatus host_status( "localhost", ping_fail_percentage_limit, link_status ); |
6f19218c GMF |
83 | host_status.set_resolved_ip_count( resolved_ip_count ); |
84 | ||
96c4e7a4 | 85 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
86 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
87 | ||
96c4e7a4 | 88 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
89 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
90 | ||
96c4e7a4 | 91 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
92 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
93 | ||
96c4e7a4 | 94 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
95 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
96 | ||
96c4e7a4 | 97 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
98 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
99 | ||
96c4e7a4 | 100 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
101 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
102 | ||
96c4e7a4 | 103 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
104 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
105 | ||
96c4e7a4 | 106 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
107 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
108 | ||
96c4e7a4 | 109 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
110 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
111 | ||
96c4e7a4 | 112 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
113 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
114 | } | |
115 | ||
116 | BOOST_AUTO_TEST_CASE( fail_percentage_80 ) | |
117 | { | |
118 | int ping_fail_percentage_limit = 80; | |
119 | int resolved_ip_count = 10; | |
120 | ||
72e54d1c | 121 | LinkStatusItem link_status( new LinkStatus ); |
6c14bbee | 122 | HostStatus host_status( "localhost", ping_fail_percentage_limit, link_status ); |
6f19218c GMF |
123 | host_status.set_resolved_ip_count( resolved_ip_count ); |
124 | ||
96c4e7a4 | 125 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
126 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
127 | ||
96c4e7a4 | 128 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
129 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
130 | ||
96c4e7a4 | 131 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
132 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
133 | ||
96c4e7a4 | 134 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
135 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
136 | ||
96c4e7a4 | 137 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
138 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
139 | ||
96c4e7a4 | 140 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
141 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
142 | ||
96c4e7a4 | 143 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
144 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
145 | ||
96c4e7a4 | 146 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
147 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
148 | ||
96c4e7a4 | 149 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
150 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
151 | ||
96c4e7a4 | 152 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
153 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
154 | } | |
155 | ||
156 | BOOST_AUTO_TEST_SUITE_END() |