X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FSocket%2FProtocols%2FINet%2FINet6Address.test.cc;h=ec03f8da0e3a0eb88cdc4c057f0d44e46c6231e2;hb=72cc548dfc3fa72d14d4d8c1a178f162165e933a;hp=391c8ec1947356202da40dcaa0f836b175ba5cef;hpb=601d1f509f5bb24df167a4dd5a20da67a0af9af8;p=senf.git diff --git a/senf/Socket/Protocols/INet/INet6Address.test.cc b/senf/Socket/Protocols/INet/INet6Address.test.cc index 391c8ec..ec03f8d 100644 --- a/senf/Socket/Protocols/INet/INet6Address.test.cc +++ b/senf/Socket/Protocols/INet/INet6Address.test.cc @@ -2,23 +2,28 @@ // // Copyright (C) 2007 // Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY -// Stefan Bund // -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. +// The contents of this file are subject to the Fraunhofer FOKUS Public License +// Version 1.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// http://senf.berlios.de/license.html // -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// The Fraunhofer FOKUS Public License Version 1.0 is based on, +// but modifies the Mozilla Public License Version 1.1. +// See the full license text for the amendments. // -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// Software distributed under the License is distributed on an "AS IS" basis, +// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +// for the specific language governing rights and limitations under the License. +// +// The Original Code is Fraunhofer FOKUS code. +// +// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. +// (registered association), Hansastraße 27 c, 80686 Munich, Germany. +// All Rights Reserved. +// +// Contributor(s): +// Stefan Bund /** \file \brief INet6Address unit tests */ @@ -28,15 +33,18 @@ // Custom includes #include "INet6Address.hh" -#include "../../../Utils/String.hh" +#include +#include +#include +#include -#include "../../../Utils/auto_unit_test.hh" +#include #include #define prefix_ -///////////////////////////////cc.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_UNIT_TEST(inet6Address) +SENF_AUTO_UNIT_TEST(inet6Address) { using senf::INet6Address; using senf::INet4Address; @@ -61,12 +69,12 @@ BOOST_AUTO_UNIT_TEST(inet6Address) BOOST_CHECK_EQUAL( addr1[13], 14 ); BOOST_CHECK_EQUAL( addr1[14], 15 ); BOOST_CHECK_EQUAL( addr1[15], 0 ); - BOOST_CHECK( INet6Address::from_string("www.go6.net") != INet6Address::None ); + SENF_CHECK_NOT_EQUAL( INet6Address::from_string("www.go6.net"), INet6Address::None ); INet6Address addr2; BOOST_CHECK_EQUAL( senf::str(addr2), "::" ); addr2 = INet6Address::from_string("::1"); - BOOST_CHECK( addr1 != addr2 ); - addr1 =INet6Address::from_string("::1"); + SENF_CHECK_NOT_EQUAL( addr1, addr2 ); + addr1 = INet6Address::from_string("::1"); BOOST_CHECK_EQUAL( addr1, addr2 ); addr1 = INet6Address::None; addr2 = INet6Address::from_string("::"); @@ -78,12 +86,12 @@ BOOST_AUTO_UNIT_TEST(inet6Address) BOOST_CHECK_EQUAL( addr3, INet6Address::from_string("1200::21") ); BOOST_CHECK_EQUAL( INet6Address::from_inet4address(INet4Address(0x01020304)), INet6Address::from_string("::ffff:1.2.3.4") ); + BOOST_CHECK( INet6Address::from_inet4address(INet4Address(0x01020304)).inet4Mapped()); BOOST_CHECK_THROW( INet6Address::from_string("1.2.3.4"), UnknownHostnameException ); BOOST_CHECK_EQUAL( INet6Address::from_string("1.2.3.4", INet6Address::ResolveINet4), INet6Address::from_string("::ffff:1.2.3.4") ); } - { INet6Address addr (INet6Address::from_string("2001:dead:beef::1002:3004")); BOOST_CHECK_EQUAL( addr.network(), senf::INet6Network( @@ -131,7 +139,6 @@ BOOST_AUTO_UNIT_TEST(inet6Address) BOOST_CHECK( INet6Address::Loopback ); BOOST_CHECK( ! INet6Address::None ); } - { std::stringstream str; INet6Address addr; @@ -153,7 +160,6 @@ BOOST_AUTO_UNIT_TEST(inet6Address) BOOST_CHECK( ! str.fail()); BOOST_CHECK_EQUAL(addr, INet6Address::from_string("2001:dead:beef::1002:3004")); } - { INet6Address addr; addr.network(0x2000010203040506ull); @@ -161,9 +167,18 @@ BOOST_AUTO_UNIT_TEST(inet6Address) addr.id(1u); BOOST_CHECK_EQUAL( addr, INet6Address(0x2000u,0x0102u,0x0304u,0x0506u,0u,0u,0u,1u) ); } + { + using senf::MACAddress; + BOOST_CHECK_EQUAL( + INet6Address::from_mac( MACAddress::from_string("00-0C-29-C2-52-FF")), + INet6Address::from_string("fe80::20c:29ff:fec2:52ff") ); + BOOST_CHECK_EQUAL( + INet6Address::from_eui64( senf::EUI64::from_mac( MACAddress::from_string("a4:ba:db:fd:b8:76"))), + INet6Address::from_string("fe80::a6ba:dbff:fefd:b876") ); + } } -BOOST_AUTO_UNIT_TEST(inet6Network) +SENF_AUTO_UNIT_TEST(inet6Network) { using senf::INet6Address; using senf::INet6Network; @@ -179,13 +194,15 @@ BOOST_AUTO_UNIT_TEST(inet6Network) BOOST_CHECK_EQUAL( net2.address(), INet6Address::from_string("2001:db8:1230::") ); BOOST_CHECK_EQUAL( net2.prefix_len(), 44u ); - BOOST_CHECK( net != net2 ); + SENF_CHECK_NOT_EQUAL( net, net2 ); BOOST_CHECK( net.match(INet6Address::from_string("ff14:1234::1")) ); BOOST_CHECK( ! net2.match(INet6Address::from_string("ff13:1234::1")) ); BOOST_CHECK( ! net.match(net2) ); BOOST_CHECK( net2.match(INet6Network("2001:db8:1234::/48")) ); BOOST_CHECK( ! net2.match(INet6Network("2001:db8:1234::/32")) ); + BOOST_CHECK( ! INet6Network("ff14:1234::1/128").match(INet6Network("ff14:1234::2/128")) ); + BOOST_CHECK_EQUAL( senf::str(net2), "2001:db8:1230::/44" ); BOOST_CHECK_EQUAL( net2.host(0x1234u), INet6Address::from_string("2001:db8:1230::1234") ); @@ -193,9 +210,25 @@ BOOST_AUTO_UNIT_TEST(inet6Network) BOOST_CHECK_THROW( INet6Network(""), AddressSyntaxException ); BOOST_CHECK_THROW( INet6Network("2001:db8:1234::/beef"), AddressSyntaxException ); + + { + std::stringstream str; + INet6Network net; + str >> net; + BOOST_CHECK( str.fail()); + } + { + std::stringstream str; + INet6Network net ("2001:db8:1230::/44"); + str << net; + BOOST_CHECK_EQUAL( str.str(), "2001:db8:1230::/44"); + str >> net; + BOOST_CHECK( ! str.fail()); + BOOST_CHECK_EQUAL(net, INet6Network("2001:db8:1230::/44")); + } } -///////////////////////////////cc.e//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_