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; | |
a7b15639 CH |
39 | int ping_congestion_percentage_limit = 75; |
40 | int ping_congestion_duration_thresh = 5; | |
41 | int n_parallel_pings = 1; | |
6f19218c GMF |
42 | int resolved_ip_count = 10; |
43 | ||
72e54d1c | 44 | LinkStatusItem link_status( new LinkStatus ); |
a7b15639 CH |
45 | HostStatus host_status( "localhost", |
46 | ping_fail_percentage_limit, | |
47 | ping_congestion_percentage_limit, | |
48 | ping_congestion_duration_thresh, | |
49 | n_parallel_pings, | |
91aa83f9 | 50 | link_status ); |
6f19218c GMF |
51 | host_status.set_resolved_ip_count( resolved_ip_count ); |
52 | ||
96c4e7a4 | 53 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
54 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
55 | ||
96c4e7a4 | 56 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
57 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
58 | ||
96c4e7a4 | 59 | host_status.update_ping_statistics( PingStatus_FailureOther, 1); |
6f19218c GMF |
60 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
61 | ||
96c4e7a4 | 62 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
63 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
64 | ||
96c4e7a4 | 65 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
66 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
67 | ||
96c4e7a4 | 68 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
69 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
70 | ||
96c4e7a4 | 71 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
72 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
73 | ||
96c4e7a4 | 74 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
75 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
76 | ||
96c4e7a4 | 77 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
78 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
79 | ||
96c4e7a4 | 80 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
81 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
82 | } | |
83 | ||
84 | BOOST_AUTO_TEST_CASE( fail_percentage_50 ) | |
85 | { | |
86 | int ping_fail_percentage_limit = 50; | |
a7b15639 CH |
87 | int ping_congestion_percentage_limit = 75; |
88 | int ping_congestion_duration_thresh = 5; | |
89 | int n_parallel_pings = 1; | |
6f19218c GMF |
90 | int resolved_ip_count = 10; |
91 | ||
72e54d1c | 92 | LinkStatusItem link_status( new LinkStatus ); |
a7b15639 CH |
93 | HostStatus host_status( "localhost", |
94 | ping_fail_percentage_limit, | |
95 | ping_congestion_percentage_limit, | |
96 | ping_congestion_duration_thresh, | |
97 | n_parallel_pings, | |
91aa83f9 | 98 | link_status ); |
6f19218c GMF |
99 | host_status.set_resolved_ip_count( resolved_ip_count ); |
100 | ||
96c4e7a4 | 101 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
102 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
103 | ||
96c4e7a4 | 104 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
105 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
106 | ||
96c4e7a4 | 107 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
108 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
109 | ||
96c4e7a4 | 110 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
111 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
112 | ||
96c4e7a4 | 113 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
114 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
115 | ||
96c4e7a4 | 116 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
117 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
118 | ||
96c4e7a4 | 119 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
120 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
121 | ||
96c4e7a4 | 122 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
123 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
124 | ||
96c4e7a4 | 125 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
126 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
127 | ||
96c4e7a4 | 128 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
129 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
130 | } | |
131 | ||
132 | BOOST_AUTO_TEST_CASE( fail_percentage_80 ) | |
133 | { | |
134 | int ping_fail_percentage_limit = 80; | |
a7b15639 CH |
135 | int ping_congestion_percentage_limit = 75; |
136 | int ping_congestion_duration_thresh = 5; | |
137 | int n_parallel_pings = 1; | |
6f19218c GMF |
138 | int resolved_ip_count = 10; |
139 | ||
72e54d1c | 140 | LinkStatusItem link_status( new LinkStatus ); |
a7b15639 CH |
141 | HostStatus host_status( "localhost", |
142 | ping_fail_percentage_limit, | |
143 | ping_congestion_percentage_limit, | |
144 | ping_congestion_duration_thresh, | |
145 | n_parallel_pings, | |
91aa83f9 | 146 | link_status ); |
6f19218c GMF |
147 | host_status.set_resolved_ip_count( resolved_ip_count ); |
148 | ||
96c4e7a4 | 149 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
150 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
151 | ||
96c4e7a4 | 152 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
153 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
154 | ||
96c4e7a4 | 155 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
156 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
157 | ||
96c4e7a4 | 158 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
159 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
160 | ||
96c4e7a4 | 161 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
162 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
163 | ||
96c4e7a4 | 164 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
165 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
166 | ||
96c4e7a4 | 167 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
168 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
169 | ||
96c4e7a4 | 170 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
171 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false ); |
172 | ||
96c4e7a4 | 173 | host_status.update_ping_statistics( PingStatus_FailureOther, 1 ); |
6f19218c GMF |
174 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
175 | ||
96c4e7a4 | 176 | host_status.update_ping_statistics( PingStatus_SuccessReply, 1 ); |
6f19218c GMF |
177 | BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true ); |
178 | } | |
179 | ||
180 | BOOST_AUTO_TEST_SUITE_END() |