--- /dev/null
+/*
+The software in this package is distributed under the GNU General
+Public License version 2 (with a special exception described below).
+
+A copy of GNU General Public License (GPL) is included in this distribution,
+in the file COPYING.GPL.
+
+As a special exception, if other files instantiate templates or use macros
+or inline functions from this file, or you compile this file and link it
+with other works to produce a work based on this file, this file
+does not by itself cause the resulting work to be covered
+by the GNU General Public License.
+
+However the source code for this file must still be made available
+in accordance with section (3) of the GNU General Public License.
+
+This exception does not invalidate any other reasons why a work based
+on this file might be covered by the GNU General Public License.
+*/
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MESSAGE usage
+
+#include <streambuf>
+
+#include <boost/asio.hpp>
+#include <boost/test/unit_test.hpp>
+
+#include "mock_linkstatusanalyzer.h"
+
+#include "host/hoststatusanalyzer.h"
+
+BOOST_AUTO_TEST_SUITE( TestHostStatusAnalyzer )
+
+BOOST_AUTO_TEST_CASE( fail_percentage_10 )
+{
+ int ping_fail_percentage_limit = 10;
+ int resolved_ip_count = 10;
+
+ LinkStatusAnalyzerItem link_status( new LinkStatusAnalyzer );
+ HostStatusAnalyzer host_status( "localhost", ping_fail_percentage_limit, link_status );
+ host_status.set_resolved_ip_count( resolved_ip_count );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
+}
+
+BOOST_AUTO_TEST_CASE( fail_percentage_50 )
+{
+ int ping_fail_percentage_limit = 50;
+ int resolved_ip_count = 10;
+
+ LinkStatusAnalyzerItem link_status( new LinkStatusAnalyzer );
+ HostStatusAnalyzer host_status( "localhost", ping_fail_percentage_limit, link_status );
+ host_status.set_resolved_ip_count( resolved_ip_count );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
+}
+
+BOOST_AUTO_TEST_CASE( fail_percentage_80 )
+{
+ int ping_fail_percentage_limit = 80;
+ int resolved_ip_count = 10;
+
+ LinkStatusAnalyzerItem link_status( new LinkStatusAnalyzer );
+ HostStatusAnalyzer host_status( "localhost", ping_fail_percentage_limit, link_status );
+ host_status.set_resolved_ip_count( resolved_ip_count );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), false );
+
+ host_status.update_ping_statistics( false );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
+
+ host_status.update_ping_statistics( true );
+ BOOST_CHECK_EQUAL( host_status.exceeded_ping_failed_limit(), true );
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+