From: Guilherme Maciel Ferreira Date: Fri, 20 Jan 2012 10:21:06 +0000 (-0200) Subject: Test: bring aboard HostStatusAnalyzer test case. X-Git-Tag: v1.3~11^2~38 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=6f19218c8e6e74c6da00faf61fd65d0118419fc7;p=pingcheck Test: bring aboard HostStatusAnalyzer test case. --- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 39a13a3..c1a392a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -23,15 +23,22 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) # compiler: source code from test cases set(TESTS_SOURCES test_messagepayload.cpp + test_hoststatusanalyzer.cpp test_ipv4header.cpp test_ipv6header.cpp test_icmpv4header.cpp test_icmpv6header.cpp ) +# compiler: source code from mock objects +set(MOCK_SOURCES + mock_linkstatusanalyzer.cpp +) + # compiler: source code to be tested set(SOURCES ${CMAKE_SOURCE_DIR}/src/host/messagepayload.cpp + ${CMAKE_SOURCE_DIR}/src/host/hoststatusanalyzer.cpp ${CMAKE_SOURCE_DIR}/src/ip/ipv4header.cpp ${CMAKE_SOURCE_DIR}/src/ip/ipv6header.cpp ${CMAKE_SOURCE_DIR}/src/icmp/icmpv4header.cpp @@ -44,7 +51,7 @@ set(SOURCES ) # compiler: creates the binary -add_executable(test_${TARGET} ${SOURCES} ${TESTS_SOURCES}) +add_executable(test_${TARGET} ${SOURCES} ${MOCK_SOURCES} ${TESTS_SOURCES}) # cmake: add a custom "make check" target which automatically builds the binary add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS test_${TARGET}) diff --git a/test/test_hoststatusanalyzer.cpp b/test/test_hoststatusanalyzer.cpp new file mode 100644 index 0000000..d795998 --- /dev/null +++ b/test/test_hoststatusanalyzer.cpp @@ -0,0 +1,157 @@ +/* +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 + +#include +#include + +#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() + +