X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FSocket%2FProtocols%2FINet%2FINet6Address.test.cc;h=ec03f8da0e3a0eb88cdc4c057f0d44e46c6231e2;hb=72cc548dfc3fa72d14d4d8c1a178f162165e933a;hp=11dd1973f8c8956d26c0a593065baad304892725;hpb=5e230d44a5ea8916dc41f4a5b9958a26fbf8e1a0;p=senf.git diff --git a/senf/Socket/Protocols/INet/INet6Address.test.cc b/senf/Socket/Protocols/INet/INet6Address.test.cc index 11dd197..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 */ @@ -29,54 +34,17 @@ // Custom includes #include "INet6Address.hh" #include +#include +#include +#include #include #include #define prefix_ -///////////////////////////////cc.p//////////////////////////////////////// - -namespace { - - template - prefix_ ForwardIterator1 find_if_mask(unsigned bits, ForwardIterator1 b1, - ForwardIterator1 e1, ForwardIterator2 b2, - Function fn) - { - std::cerr << ">>> " << bits << ' ' << e1-b1 << '\n'; - for(; bits>8 && b1 != e1; bits -= 8, ++b1, ++b2) - if (fn(*b1, *b2, boost::lambda::make_const(0xFFu))) - return b1; - std::cerr << ">>> " << bits << ' ' << e1-b1 << '\n'; - if (bits > 0 && b1 != e1) - if (fn( *(b1++), *(b2++), boost::lambda::make_const(~ senf::detail::low_bits_mask(8-bits)))) - return b1; - std::cerr << ">>> " << bits << ' ' << e1-b1 << '\n'; - for(; b1 != e1; ++b1, ++b2) - if (fn(*b1, *b2, boost::lambda::make_const(0u))) - return b1; - return e1; - } +//-///////////////////////////////////////////////////////////////////////////////////////////////// - bool match(senf::INet6Network const & n, senf::INet6Address a) - { - using boost::lambda::_1; - using boost::lambda::_2; - using boost::lambda::_3; - using boost::lambda::ret; - using boost::lambda::constant; - senf::INet6Address na (n.address()); - return find_if_mask( - n.prefix_len(), na.begin(), na.end(), a.begin(), - ( - std::cerr << constant(">> ") << _1 << ' ' << _2 << ' ' << ret(_3) << '\n', - _1 != (_2 & _3) - )) == na.end(); - } - -} - -BOOST_AUTO_UNIT_TEST(inet6Address) +SENF_AUTO_UNIT_TEST(inet6Address) { using senf::INet6Address; using senf::INet4Address; @@ -101,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("::"); @@ -118,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( @@ -171,7 +139,6 @@ BOOST_AUTO_UNIT_TEST(inet6Address) BOOST_CHECK( INet6Address::Loopback ); BOOST_CHECK( ! INet6Address::None ); } - { std::stringstream str; INet6Address addr; @@ -193,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); @@ -201,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; @@ -219,13 +194,13 @@ 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" ); @@ -235,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_