started parallel pings, not quite done yet since need to delay them
[pingcheck] / test / test_hoststatus.cpp
CommitLineData
6f19218c
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
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 34BOOST_AUTO_TEST_SUITE( TestHostStatus )
6f19218c
GMF
35
36BOOST_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 );
91aa83f9
CH
42 HostStatus host_status( "localhost", ping_fail_percentage_limit, 1,
43 link_status );
6f19218c
GMF
44 host_status.set_resolved_ip_count( resolved_ip_count );
45
96c4e7a4 46 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
47 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
48
96c4e7a4 49 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
50 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
51
96c4e7a4 52 host_status.update_ping_statistics( PingStatus_FailureOther, 1);
6f19218c
GMF
53 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
54
96c4e7a4 55 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
56 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
57
96c4e7a4 58 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
59 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
60
96c4e7a4 61 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
62 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
63
96c4e7a4 64 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
65 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
66
96c4e7a4 67 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
68 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
69
96c4e7a4 70 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
71 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
72
96c4e7a4 73 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
74 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
75}
76
77BOOST_AUTO_TEST_CASE( fail_percentage_50 )
78{
79 int ping_fail_percentage_limit = 50;
80 int resolved_ip_count = 10;
81
72e54d1c 82 LinkStatusItem link_status( new LinkStatus );
91aa83f9
CH
83 HostStatus host_status( "localhost", ping_fail_percentage_limit, 1,
84 link_status );
6f19218c
GMF
85 host_status.set_resolved_ip_count( resolved_ip_count );
86
96c4e7a4 87 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
88 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
89
96c4e7a4 90 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
91 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
92
96c4e7a4 93 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
94 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
95
96c4e7a4 96 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
97 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
98
96c4e7a4 99 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
100 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
101
96c4e7a4 102 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
103 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
104
96c4e7a4 105 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
106 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
107
96c4e7a4 108 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
109 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
110
96c4e7a4 111 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
112 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
113
96c4e7a4 114 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
115 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
116}
117
118BOOST_AUTO_TEST_CASE( fail_percentage_80 )
119{
120 int ping_fail_percentage_limit = 80;
121 int resolved_ip_count = 10;
122
72e54d1c 123 LinkStatusItem link_status( new LinkStatus );
91aa83f9
CH
124 HostStatus host_status( "localhost", ping_fail_percentage_limit, 1,
125 link_status );
6f19218c
GMF
126 host_status.set_resolved_ip_count( resolved_ip_count );
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(), false );
151
96c4e7a4 152 host_status.update_ping_statistics( PingStatus_FailureOther, 1 );
6f19218c
GMF
153 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
154
96c4e7a4 155 host_status.update_ping_statistics( PingStatus_SuccessReply, 1 );
6f19218c
GMF
156 BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
157}
158
159BOOST_AUTO_TEST_SUITE_END()