| 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 | |
| 21 | #define BOOST_TEST_MAIN |
| 22 | #define BOOST_TEST_DYN_LINK |
| 23 | |
| 24 | #include <streambuf> |
| 25 | |
| 26 | #include <boost/asio.hpp> |
| 27 | #include <boost/test/unit_test.hpp> |
| 28 | #include <boost/thread.hpp> |
| 29 | |
| 30 | #include "mock_statusnotifiercommand.h" |
| 31 | |
| 32 | #include "link/linkstatus.h" |
| 33 | |
| 34 | BOOST_AUTO_TEST_SUITE( TestLinkStatus ) |
| 35 | |
| 36 | BOOST_AUTO_TEST_CASE( is_link_up_enough_time ) |
| 37 | { |
| 38 | int hosts_down_limit = 2; |
| 39 | int link_up_interval_in_min = 0; |
| 40 | int link_down_interval_in_min = 1; |
| 41 | |
| 42 | std::string status_notifier_cmd = "none"; |
| 43 | |
| 44 | LinkStatus link_status( |
| 45 | hosts_down_limit, |
| 46 | link_up_interval_in_min, |
| 47 | link_down_interval_in_min, |
| 48 | status_notifier_cmd |
| 49 | ); |
| 50 | |
| 51 | link_status.notify_host_up( "www.intra2net.com" ); |
| 52 | BOOST_CHECK_EQUAL( link_status.is_link_up_enough_time(), true ); |
| 53 | } |
| 54 | |
| 55 | BOOST_AUTO_TEST_CASE( is_link_down_enough_time ) |
| 56 | { |
| 57 | int hosts_down_limit = 2; |
| 58 | int link_up_interval_in_min = 1; |
| 59 | int link_down_interval_in_min = 0; |
| 60 | |
| 61 | std::string status_notifier_cmd = "none"; |
| 62 | |
| 63 | LinkStatus link_status( |
| 64 | hosts_down_limit, |
| 65 | link_up_interval_in_min, |
| 66 | link_down_interval_in_min, |
| 67 | status_notifier_cmd |
| 68 | ); |
| 69 | |
| 70 | link_status.notify_host_down( "www.intra2net.com" ); |
| 71 | BOOST_CHECK_EQUAL( link_status.is_link_down_enough_time(), true ); |
| 72 | } |
| 73 | |
| 74 | BOOST_AUTO_TEST_CASE( exceeded_host_down_limit ) |
| 75 | { |
| 76 | int hosts_down_limit = 2; |
| 77 | int link_up_interval_in_min = 1; |
| 78 | int link_down_interval_in_min = 1; |
| 79 | |
| 80 | std::string status_notifier_cmd = "none"; |
| 81 | |
| 82 | LinkStatus link_status( |
| 83 | hosts_down_limit, |
| 84 | link_up_interval_in_min, |
| 85 | link_down_interval_in_min, |
| 86 | status_notifier_cmd |
| 87 | ); |
| 88 | |
| 89 | link_status.notify_host_down( "www.intra2net.com" ); |
| 90 | BOOST_CHECK_EQUAL( link_status.exceeded_host_down_limit(), false ); |
| 91 | |
| 92 | link_status.notify_host_down( "www.ufsc.br" ); |
| 93 | BOOST_CHECK_EQUAL( link_status.exceeded_host_down_limit(), false ); |
| 94 | |
| 95 | link_status.notify_host_down( "www.google.com" ); |
| 96 | BOOST_CHECK_EQUAL( link_status.exceeded_host_down_limit(), true ); |
| 97 | |
| 98 | link_status.notify_host_down( "www.fazenda.gov.br" ); |
| 99 | BOOST_CHECK_EQUAL( link_status.exceeded_host_down_limit(), true ); |
| 100 | } |
| 101 | |
| 102 | BOOST_AUTO_TEST_SUITE_END() |