From: Guilherme Maciel Ferreira Date: Sun, 8 Jan 2012 15:57:51 +0000 (-0200) Subject: Test: bring aboard Ipv6Header test case. X-Git-Tag: v1.3~11^2~43 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=674077bee0a28947da82faa573a359309c22702f;p=pingcheck Test: bring aboard Ipv6Header test case. --- diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5d9d9a5..79a5935 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -24,12 +24,14 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) set(TESTS_SOURCES test_messagepayload.cpp test_ipv4header.cpp + test_ipv6header.cpp ) # compiler: source code to be tested set(SOURCES ${CMAKE_SOURCE_DIR}/src/host/messagepayload.cpp ${CMAKE_SOURCE_DIR}/src/ip/ipv4header.cpp + ${CMAKE_SOURCE_DIR}/src/ip/ipv6header.cpp ) # compiler: creates the binary diff --git a/test/test_ipv6header.cpp b/test/test_ipv6header.cpp new file mode 100644 index 0000000..5e8a030 --- /dev/null +++ b/test/test_ipv6header.cpp @@ -0,0 +1,83 @@ +/* +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 + +#include + +#include + +#include "ip/ipv6header.h" + +BOOST_AUTO_TEST_SUITE( TestIpv6Header ) + +BOOST_AUTO_TEST_CASE( icmpv6_packet ) +{ + uint8_t raw_packet_stream[] = { + 0x60, 0x00, 0x00, 0x00, 0x00, 0x14, 0x3a, 0x40, 0x20, 0x01, 0x12, 0x91, + 0x02, 0x00, 0x02, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x26, 0x07, 0xf8, 0xb0, 0x40, 0x08, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x10, 0x11 + }; + + std::basic_stringbuf sb; + sb.pubsetbuf( raw_packet_stream, sizeof(raw_packet_stream) ); + std::basic_istream is( &sb ); + + Ipv6Header ip_header; + reinterpret_cast(is) >> ip_header; + + BOOST_CHECK_EQUAL( ip_header.get_version(), 6 ); + BOOST_CHECK_EQUAL( ip_header.get_differentiated_services(), 0 ); + BOOST_CHECK_EQUAL( ip_header.get_flow_label(), 0 ); + BOOST_CHECK_EQUAL( ip_header.get_payload_length(), 20 ); + BOOST_CHECK_EQUAL( ip_header.get_next_header(), 0x3A ); // ICMPv6 + BOOST_CHECK_EQUAL( ip_header.get_hop_limit(), 64 ); + BOOST_CHECK_EQUAL( ip_header.get_source_address(), boost::asio::ip::address_v6::from_string("2001:1291:200:25a::2") ); + BOOST_CHECK_EQUAL( ip_header.get_destination_address(), boost::asio::ip::address_v6::from_string("2607:f8b0:4008:804::1011") ); +} + +BOOST_AUTO_TEST_CASE( tcp_packet ) +{ + uint8_t raw_packet_stream[] = { + 0x60, 0x00, 0x00, 0x00, 0x00, 0x28, 0x06, 0x40, 0x20, 0x01, 0x12, 0x91, + 0x02, 0x00, 0x02, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x26, 0x20, 0x00, 0x00, 0x06, 0xb0, 0x00, 0x0a, 0x02, 0x50, 0x56, 0xff, + 0xfe, 0x99, 0x78, 0xf7 + }; + + std::basic_stringbuf sb; + sb.pubsetbuf( raw_packet_stream, sizeof(raw_packet_stream) ); + std::basic_istream is( &sb ); + + Ipv6Header ip_header; + reinterpret_cast(is) >> ip_header; + + BOOST_CHECK_EQUAL( ip_header.get_version(), 6 ); + BOOST_CHECK_EQUAL( ip_header.get_differentiated_services(), 0 ); + BOOST_CHECK_EQUAL( ip_header.get_flow_label(), 0 ); + BOOST_CHECK_EQUAL( ip_header.get_payload_length(), 40 ); + BOOST_CHECK_EQUAL( ip_header.get_next_header(), 0x06 ); // TCP + BOOST_CHECK_EQUAL( ip_header.get_hop_limit(), 64 ); + BOOST_CHECK_EQUAL( ip_header.get_source_address(), boost::asio::ip::address_v6::from_string("2001:1291:200:25a::2") ); + BOOST_CHECK_EQUAL( ip_header.get_destination_address(), boost::asio::ip::address_v6::from_string("2620:0:6b0:a:250:56ff:fe99:78f7") ); +} + +BOOST_AUTO_TEST_SUITE_END()