Test: bring aboard PingProtocol test case.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Mon, 6 Feb 2012 23:23:54 +0000 (21:23 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Mon, 6 Feb 2012 23:23:54 +0000 (21:23 -0200)
test/CMakeLists.test_pingprotocol.txt [new file with mode: 0644]
test/CMakeLists.txt
test/test_pingprotocol.cpp [new file with mode: 0644]

diff --git a/test/CMakeLists.test_pingprotocol.txt b/test/CMakeLists.test_pingprotocol.txt
new file mode 100644 (file)
index 0000000..bc95fd1
--- /dev/null
@@ -0,0 +1,15 @@
+# compiler: creates the binaries
+add_executable(test_pingprotocol
+    test_pingprotocol.cpp
+    ${CMAKE_SOURCE_DIR}/src/host/pingprotocol.cpp
+)
+
+# linker: link the program against the libraries
+target_link_libraries(
+    test_pingprotocol
+    ${I2NCOMMON_LIBRARIES}
+    ${Boost_LIBRARIES}
+)
+
+# cmake: invocation via "make test"
+add_test(test_pingprotocol test_pingprotocol)
index d832c8b..aaba1f6 100644 (file)
@@ -28,6 +28,7 @@ include(CMakeLists.test_configurationcommandline.txt)
 include(CMakeLists.test_configurationfile.txt)
 include(CMakeLists.test_configurationoptions.txt)
 include(CMakeLists.test_messagepayload.txt)
+include(CMakeLists.test_pingprotocol.txt)
 include(CMakeLists.test_hoststatus.txt)
 include(CMakeLists.test_ipv4header.txt)
 include(CMakeLists.test_ipv6header.txt)
@@ -40,6 +41,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS
     test_configurationfile
     test_configurationoptions
     test_messagepayload
+    test_pingprotocol
     test_hoststatus
     test_ipv4header
     test_ipv6header
diff --git a/test/test_pingprotocol.cpp b/test/test_pingprotocol.cpp
new file mode 100644 (file)
index 0000000..76ab599
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+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_MAIN
+#define BOOST_TEST_DYN_LINK
+
+#include <boost/test/unit_test.hpp>
+
+#include "host/pingprotocol.h"
+
+BOOST_AUTO_TEST_SUITE( TestDnsResolver )
+
+BOOST_AUTO_TEST_CASE( lowercase )
+{
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "icmp" ), PingProtocol_ICMP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "tcp" ), PingProtocol_TCP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "icmpv6" ), PingProtocol_ICMPv6 );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "tcp_ipv6" ), PingProtocol_TCP_IPv6 );
+}
+
+BOOST_AUTO_TEST_CASE( uppercase )
+{
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "ICMP" ), PingProtocol_ICMP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "TCP" ), PingProtocol_TCP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "ICMPV6" ), PingProtocol_ICMPv6 );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "TCP_IPV6" ), PingProtocol_TCP_IPv6 );
+}
+
+BOOST_AUTO_TEST_CASE( mixed_case )
+{
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "IcMp" ), PingProtocol_ICMP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "TcP" ), PingProtocol_TCP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "IcmpV6" ), PingProtocol_ICMPv6 );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "Tcp_Ipv6" ), PingProtocol_TCP_IPv6 );
+}
+
+BOOST_AUTO_TEST_CASE( misspelled )
+{
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "when" ), PingProtocol_ICMP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "the" ), PingProtocol_ICMP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "word" ), PingProtocol_ICMP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "is" ), PingProtocol_ICMP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "wrong" ), PingProtocol_ICMP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "stick" ), PingProtocol_ICMP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "to" ), PingProtocol_ICMP );
+    BOOST_CHECK_EQUAL( get_ping_protocol_from_string( "ICMP" ), PingProtocol_ICMP );
+}
+
+BOOST_AUTO_TEST_SUITE_END()