added more tests to increase test coverage
tho [Thu, 12 Mar 2009 14:23:00 +0000 (14:23 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1151 270642c3-0616-0410-b53a-bc976706d245

20 files changed:
PPI/AnnotationRouter.hh
PPI/AnnotationRouter.test.cc
PPI/CloneSource.cc
PPI/CloneSource.test.cc
Packets/80221Bundle/TLVPacket.hh
Packets/DefaultBundle/IPv4Packet.test.cc
Packets/DefaultBundle/IPv6Packet.test.cc
Packets/DefaultBundle/Mldv2Packet.test.cc
Packets/DefaultBundle/UDPPacket.test.cc
Packets/MPEGDVBBundle/DTCPPacket.test.cc
Packets/Packet.hh
Packets/Packet.test.cc
Socket/Protocols/INet/INet4Address.test.cc
Socket/Protocols/INet/INet6Address.test.cc
Socket/Protocols/INet/INetAddressing.hh
Socket/Protocols/INet/INetAddressing.test.cc
Socket/Protocols/Raw/LLAddressing.test.cc
Socket/Protocols/Raw/MACAddress.test.cc
Socket/Protocols/UN/UNAddressing.cc
Socket/Protocols/UN/UNAddressing.test.cc

index 218f0a4..705eb8d 100644 (file)
@@ -28,6 +28,7 @@
 
 // Custom includes
 #include <boost/ptr_container/ptr_map.hpp>
+#include "../Utils/String.hh"
 #include "Module.hh"
 #include "Connectors.hh"
 
@@ -104,7 +105,7 @@ namespace module {
         struct DuplicateKeyException : public senf::Exception
         { DuplicateKeyException(AnnotationType const & key) 
               : senf::Exception("Duplicate senf::ppi::module::AnnotationRouter routing key ")
-                { append(boost::lexical_cast<std::string>(key)); } };
+                { append( senf::str(key)); } };
 
     private:
         connector::ActiveOutput<> & newOutput(AnnotationType const & key);
index 6b55d73..ca0c0ab 100644 (file)
@@ -62,6 +62,9 @@ BOOST_AUTO_UNIT_TEST(annotationRouter)
     senf::ppi::connect(source, router);
     senf::ppi::connect(router, sink1, 1);
     senf::ppi::connect(router, sink2, 2);
+    
+    BOOST_CHECK_THROW( senf::ppi::connect(router, sink2, 2), 
+            senf::ppi::module::AnnotationRouter<IntAnnotation>::DuplicateKeyException);
 
     senf::ppi::init();
 
index 60f8e86..cb0b67c 100644 (file)
@@ -43,6 +43,7 @@ void senf::ppi::module::CloneSource::request()
 {
     output(packet_.clone());
 }
+
 void senf::ppi::module::CloneSource::replacePacket(senf::Packet const & packet)
 {
     packet_ = packet;
index ee5ef08..105ad0d 100644 (file)
@@ -40,7 +40,7 @@
 
 BOOST_AUTO_UNIT_TEST(cloneSource)
 {
-    senf::PacketData::byte data[] = { 0xAB };
+    senf::PacketData::byte data[] = { 0xab };
     senf::Packet p (senf::DataPacket::create(data));
 
     senf::ppi::module::CloneSource source (p);
@@ -52,6 +52,11 @@ BOOST_AUTO_UNIT_TEST(cloneSource)
     BOOST_CHECK( sink.request() != p );
     BOOST_CHECK( sink.request().data()[0] == p.data()[0] );
     BOOST_CHECK( sink.request().data()[0] == p.data()[0] );
+    
+    data[0] = 0xcd;
+    senf::Packet p2 (senf::DataPacket::create(data));
+    source.replacePacket( p2);
+    BOOST_CHECK( sink.request().data()[0] == p2.data()[0] );
 }
 
 
index bf0ce2e..4c1a588 100644 (file)
 
 namespace senf {
 
-
     struct TLVLengthException : public senf::Exception
-    { TLVLengthException() 
-          : senf::Exception("TLVLengthException"){} };
+    { 
+        TLVLengthException() 
+          : senf::Exception("TLVLengthException") {} 
+    };
 
     
     class DynamicTLVLengthParser 
index 26d630c..7ddbe86 100644 (file)
 
 using namespace senf;
 
-BOOST_AUTO_UNIT_TEST(ipV4Packet_packet)
+BOOST_AUTO_UNIT_TEST(ipV4Packet_parse)
 {
-
-    unsigned char data[] = { 0x01, 0x02, 0x03, 0x04,
-                             0x05, 0x06, 0x07, 0x08,
-                             0x09, 0x0A, 0x0B, 0x0C,
-                             0x11, 0x12, 0x13, 0x14,
-                             0x15, 0x16, 0x17, 0x18
-                           };
+    unsigned char data[] = {
+            0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+            0x09, 0x0A, 0x0B, 0x0C, 0x11, 0x12, 0x13, 0x14,
+            0x15, 0x16, 0x17, 0x18
+    };
 
     senf::IPv4Packet p (senf::IPv4Packet::create(data));
 
index 87cdcc1..b3f2711 100644 (file)
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
 
-BOOST_AUTO_UNIT_TEST(ipV6Packet_packet)
+BOOST_AUTO_UNIT_TEST(ipV6Packet_parse)
 {
-    unsigned char data[] = { 0x60, 0x12, 0x20, 0x30,
-                             0x01, 0x02, 0x03, 0x04,
-                             0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
-                             0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
-                             0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
-                             0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
-                             0xff };
+    unsigned char data[] = { 
+            0x60, 0x12, 0x20, 0x30,
+            0x00, 0x01, 0x03, 0x04,
+            0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+            0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+            0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+            0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
+            0xff 
+    };
 
     senf::IPv6Packet p (senf::IPv6Packet::create(data));
 
     BOOST_CHECK_EQUAL( p->version(),       0x06u      );
     BOOST_CHECK_EQUAL( p->trafficClass(),  0x01u      );
     BOOST_CHECK_EQUAL( p->flowLabel(),     0x22030u   );
-    BOOST_CHECK_EQUAL( p->length(),        0x0102u    );
+    BOOST_CHECK_EQUAL( p->length(),        0x0001u    );
     BOOST_CHECK_EQUAL( p->nextHeader(),    0x03u      );
     BOOST_CHECK_EQUAL( p->hopLimit(),      0x04u      );
     BOOST_CHECK_EQUAL( p->source().value(),
@@ -68,6 +70,30 @@ BOOST_AUTO_UNIT_TEST(ipV6Packet_packet)
     SENF_CHECK_NO_THROW( p.dump( oss));
 }
 
+BOOST_AUTO_UNIT_TEST(ipV6Packet_create)
+{
+    senf::IPv6Packet ip (senf::IPv6Packet::create());
+
+    ip->trafficClass() = 0x01u;
+    ip->flowLabel() = 0x22030u;
+    ip->hopLimit() = 0x04u;
+    ip->source() = senf::INet6Address::from_string("1011:1213:1415:1617:1819:1a1b:1c1d:1e1f");
+    ip->destination() = senf::INet6Address::from_string("2021:2223:2425:2627:2829:2a2b:2c2d:2e2f");
+    
+    ip.finalizeAll();
+    
+    unsigned char data[] = { 
+            0x60, 0x12, 0x20, 0x30,
+            0x00, 0x00, 0x3b, 0x04,
+            0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+            0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+            0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+            0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
+    };
+    BOOST_CHECK_EQUAL_COLLECTIONS( 
+            data, data+sizeof(data), ip.data().begin(), ip.data().end() );
+}
+
 ///////////////////////////////cc.e////////////////////////////////////////
 #undef prefix_
 
index a6c072a..f42a48f 100644 (file)
 // Custom includes
 
 #include "ICMPv6Packet.hh"
+#include "ICMPv6TypePacket.hh"
 #include "../../Packets/DataPacket.hh"
+#include "../../Utils/String.hh"
+
 #include "../../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
-#include "ICMPv6TypePacket.hh"
+
 
 BOOST_AUTO_UNIT_TEST(ICMPv6_MLDv2_Packet_packet)
 {
@@ -44,5 +47,5 @@ BOOST_AUTO_UNIT_TEST(ICMPv6_MLDv2_Packet_packet)
     senf::MLDv2ListenerReport::Parser::mcastAddrRecords_t::container mcastAddrRecords (p->mcastAddrRecords());
     senf::MLDv2ListenerReport::Parser::mcastAddrRecords_t::container::iterator mcAddrIt (mcastAddrRecords.begin() );
     BOOST_CHECK_EQUAL(mcAddrIt->recordType(), 0x04);
-    BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(mcAddrIt->mcAddress() ), "ff15::16");
+    BOOST_CHECK_EQUAL(senf::str(mcAddrIt->mcAddress() ), "ff15::16");
 }
index d9b4eee..18722a3 100644 (file)
@@ -80,8 +80,8 @@ BOOST_AUTO_UNIT_TEST(udpPacket_in_ipv6_create)
     BOOST_CHECK( udp->validateChecksum() );
 
     ip.finalizeAll();
-    BOOST_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data),
-                                   ip.data().begin(), ip.data().end() );
+    BOOST_CHECK_EQUAL_COLLECTIONS( 
+            data, data+sizeof(data), ip.data().begin(), ip.data().end() );
     BOOST_CHECK( udp->validateChecksum() );
 }
 
index 9f71db8..7e03d14 100644 (file)
@@ -28,6 +28,7 @@
 
 // Custom includes
 #include "DTCPPacket.hh"
+#include "../../Utils/String.hh"
 
 #include "../../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
@@ -64,8 +65,8 @@ BOOST_AUTO_UNIT_TEST(dtcpPacket)
     BOOST_CHECK_EQUAL( hello->tunnelProtocol(), 23u );
     BOOST_CHECK_EQUAL( hello->fbipCount(), 2u );
     BOOST_CHECK( hello->has_v4fbipList() );
-    BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(hello->v4fbipList()[0]), "101.102.103.104" );
-    BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(hello->v4fbipList()[1]), "201.202.203.204" );
+    BOOST_CHECK_EQUAL( senf::str(hello->v4fbipList()[0]), "101.102.103.104" );
+    BOOST_CHECK_EQUAL( senf::str(hello->v4fbipList()[1]), "201.202.203.204" );
 
     std::stringstream ss;
     hello.dump(ss);
index 8cff108..d148598 100644 (file)
@@ -269,7 +269,10 @@ namespace senf {
              OtherPacket. The new packet is added to the chain after
              \c this.
              \returns new packet instance sharing the same data and
-                 placed after \c this packet in the chain. */
+                 placed after \c this packet in the chain. 
+             \throws InvalidPacketChainException if no next
+                 packet header is allowed (viz. nextPacketRange() of the the current
+                 PacketType returns no_range() ) */
         Packet      parseNextAs(factory_t factory) const;
         ///< Interpret payload of \c this as \a factory type packet
         /**< parseNextAs() will throw away the packet chain after
@@ -278,7 +281,10 @@ namespace senf {
              factory. The new packet is added to the chain after
              \c this.
              \returns new packet instance sharing the same data and
-                 placed after \c this packet in the chain. */
+                 placed after \c this packet in the chain.
+             \throws InvalidPacketChainException if no next
+                 packet header is allowed (viz. nextPacketRange() of the the current
+                 PacketType returns no_range() ) */
 
         template <class OtherPacket> bool        is() const;
         ///< Check, whether \c this packet is of the given type
index 35b3214..521dfcb 100644 (file)
@@ -136,7 +136,7 @@ namespace {
 
 BOOST_AUTO_UNIT_TEST(packet)
 {
-    senf::Packet packet (FooPacket::create());
+    senf::Packet packet (FooPacket::create());    
     BarPacket::createAfter(packet);
 
     BOOST_REQUIRE( packet );
@@ -197,7 +197,7 @@ BOOST_AUTO_UNIT_TEST(packet)
     senf::PacketData::byte data[] = { 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                       0x81, 0x82, 0x83 };
 
-    BarPacket::createAfter(packet,data);
+    BarPacket::createAfter(packet, data);
     BOOST_REQUIRE( packet.next() );
     BOOST_REQUIRE( packet.next().is<BarPacket>() );
     BOOST_CHECK( packet.last().is<FooPacket>() );
@@ -214,6 +214,10 @@ BOOST_AUTO_UNIT_TEST(packet)
     BOOST_CHECK( packet.last().rfind<FooPacket>() == packet.last() );
     BOOST_CHECK( packet.next<BarPacket>() == packet.next() );
     BOOST_CHECK( packet.last().prev().prev<FooPacket>() == packet );
+    
+    senf::DataPacket::createAfter(packet);
+    BOOST_CHECK_THROW( packet.next().next().next().parseNextAs<BarPacket>(),
+            senf::InvalidPacketChainException );
 }
 
 BOOST_AUTO_UNIT_TEST(concretePacket)
index b026788..c837018 100644 (file)
@@ -28,9 +28,9 @@
 
 // Custom includes
 #include <arpa/inet.h>
-#include <boost/lexical_cast.hpp>
 #include <sstream>
 #include "INet4Address.hh"
+#include "../../../Utils/String.hh"
 
 #include "../../../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
@@ -71,15 +71,24 @@ BOOST_AUTO_UNIT_TEST(inet4Address)
     BOOST_CHECK( INet4Address::from_string("www.6bone.net") != INet4Address::None );
     BOOST_CHECK_THROW( INet4Address::from_string("invalid.host.fhg.de"), UnknownHostnameException);
 
-    std::stringstream str;
-    str >> addr;
-    BOOST_CHECK( str.fail());
-    str.clear();
-    str << addr;
-    BOOST_CHECK_EQUAL( str.str(), "128.129.130.131" );
-    str >> addr;
-    BOOST_CHECK( ! str.fail());
-    BOOST_CHECK_EQUAL(addr, INet4Address::from_string("128.129.130.131") );
+    {
+        std::stringstream str;
+        str >> addr;
+        BOOST_CHECK( str.fail());
+    }
+    {
+        std::stringstream str ("invalid.host.fhg.de");
+        str >> addr;
+        BOOST_CHECK( str.fail());
+    }
+    {
+        std::stringstream str;
+        str << addr;
+        BOOST_CHECK_EQUAL( str.str(), "128.129.130.131" );
+        str >> addr;
+        BOOST_CHECK( ! str.fail());
+        BOOST_CHECK_EQUAL(addr, INet4Address::from_string("128.129.130.131") );
+    }
 }
 
 BOOST_AUTO_UNIT_TEST(inet4Network)
@@ -101,10 +110,10 @@ BOOST_AUTO_UNIT_TEST(inet4Network)
     BOOST_CHECK( net2.match(senf::INet4Network("192.0.111.0/24")) );
     BOOST_CHECK( ! net2.match(senf::INet4Network("192.0.0.0/15")) );
 
-    BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(net2), "192.0.0.0/16" );
+    BOOST_CHECK_EQUAL( senf::str(net2), "192.0.0.0/16" );
 
     BOOST_CHECK_EQUAL( net2.host(-1), senf::INet4Address::from_string("192.0.255.255") );
-    BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(net2.subnet(2u,24u)), "192.0.2.0/24" );
+    BOOST_CHECK_EQUAL( senf::str(net2.subnet(2u,24u)), "192.0.2.0/24" );
 
     BOOST_CHECK_THROW( senf::INet4Network(""), senf::AddressSyntaxException );
     BOOST_CHECK_THROW( senf::INet4Network("192.0.2.0/24/beef"), senf::AddressSyntaxException );
index 3bdce5a..50bf350 100644 (file)
@@ -27,8 +27,8 @@
 //#include "INet6Address.test.ih"
 
 // Custom includes
-#include <boost/lexical_cast.hpp>
 #include "INet6Address.hh"
+#include "../../../Utils/String.hh"
 
 #include "../../../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
@@ -63,7 +63,7 @@ BOOST_AUTO_UNIT_TEST(inet6Address)
         BOOST_CHECK_EQUAL( addr1[15], 0 );
         BOOST_CHECK( INet6Address::from_string("www.6bone.net") != INet6Address::None );
         INet6Address addr2;
-        BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(addr2), "::" );
+        BOOST_CHECK_EQUAL( senf::str(addr2), "::" );
         addr2 = INet6Address::from_string("::1");
         BOOST_CHECK( addr1 != addr2 );
         addr1 =INet6Address::from_string("::1");
@@ -72,7 +72,7 @@ BOOST_AUTO_UNIT_TEST(inet6Address)
         addr2 = INet6Address::from_string("::");
         BOOST_CHECK_EQUAL( addr1, addr2 );
         BOOST_CHECK_THROW( INet6Address::from_string(""), AddressSyntaxException );
-        BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(addr1), "::" );
+        BOOST_CHECK_EQUAL( senf::str(addr1), "::" );
         unsigned char data[] = { 0x12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x21, 0 };
         INet6Address addr3 (INet6Address::from_data(data));
         BOOST_CHECK_EQUAL( addr3, INet6Address::from_string("1200::21") );
@@ -132,11 +132,20 @@ BOOST_AUTO_UNIT_TEST(inet6Address)
     }
 
     {
-        INet6Address addr (INet6Address::from_string("2001:dead:beef::1002:3004"));
         std::stringstream str;
+        INet6Address addr;
         str >> addr;
         BOOST_CHECK( str.fail());
-        str.clear();
+    }
+    {
+        std::stringstream str ("invalid.host.fhg.de");
+        INet6Address addr;
+        str >> addr;
+        BOOST_CHECK( str.fail());
+    }
+    {
+        std::stringstream str;
+        INet6Address addr (INet6Address::from_string("2001:dead:beef::1002:3004"));
         str << addr;
         BOOST_CHECK_EQUAL( str.str(), "2001:dead:beef::1002:3004");
         str >> addr;
@@ -160,7 +169,7 @@ BOOST_AUTO_UNIT_TEST(inet6Network)
     using senf::AddressSyntaxException;
 
     INet6Network net (INet6Address(0xFF14u,0x1234u),32u);
-    BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(net.address()), "ff14:1234::");
+    BOOST_CHECK_EQUAL( senf::str(net.address()), "ff14:1234::");
     BOOST_CHECK_EQUAL( net.prefix_len(), 32u );
     BOOST_CHECK( net );
     BOOST_CHECK( ! INet6Network() );
@@ -176,11 +185,10 @@ BOOST_AUTO_UNIT_TEST(inet6Network)
     BOOST_CHECK( net2.match(INet6Network("2001:db8:1234::/48")) );
     BOOST_CHECK( ! net2.match(INet6Network("2001:db8:1234::/32")) );
 
-    BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(net2), "2001:db8:1230::/44" );
+    BOOST_CHECK_EQUAL( senf::str(net2), "2001:db8:1230::/44" );
 
     BOOST_CHECK_EQUAL( net2.host(0x1234u), INet6Address::from_string("2001:db8:1230::1234") );
-    BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(net2.subnet(2u,48u)),
-                       "2001:db8:1232::/48" );
+    BOOST_CHECK_EQUAL( senf::str(net2.subnet(2u,48u)), "2001:db8:1232::/48" );
 
     BOOST_CHECK_THROW( INet6Network(""), AddressSyntaxException );
     BOOST_CHECK_THROW( INet6Network("2001:db8:1234::/beef"), AddressSyntaxException );
index a54b95e..362e55c 100644 (file)
@@ -168,6 +168,8 @@ namespace senf {
                                         ///< Initialize from address and port
         INet6SocketAddress(INet6Address const & addr, unsigned port, std::string const & iface);
                                         ///< Initialize explicitly from given parameters
+                                        /**< \throws AddressSyntaxException if the
+                                                given iface cannot be resolved. */
         explicit INet6SocketAddress(unsigned port);
                                         ///< Initialize from port and set to 'unspecified' addr
                                         /**< The address is set to [::]
@@ -183,10 +185,12 @@ namespace senf {
         void address(INet6Address const & addr); ///< Change address
 
         unsigned port() const;          ///< Get port number
-        void port(unsigned poirt);      ///< Change port number
+        void port(unsigned port);       ///< Change port number
 
         std::string iface() const;      ///< Get interface name
         void iface(std::string const & iface); ///< Change interface
+                                               /**< \throws AddressSyntaxException if the
+                                                        given iface cannot be resolved. */
 
         using BSDSocketAddress::sockaddr_p;
         using BSDSocketAddress::socklen_p;
index 8049dac..a6f2dbd 100644 (file)
@@ -27,6 +27,7 @@
 
 // Custom includes
 #include "INetAddressing.hh"
+#include "../../../Utils/String.hh"
 
 #include "../../../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
@@ -42,13 +43,10 @@ BOOST_AUTO_UNIT_TEST(inet4SocketAddress)
 
     {
         INet4SocketAddress addr;
-
         BOOST_CHECK( ! addr );
-
         addr = INet4SocketAddress("127.0.0.1:12345");
         BOOST_CHECK ( addr != INet4SocketAddress("127.0.0.2:12345") );
     }
-
     {
         INet4SocketAddress addr1("127.0.0.1:12345");
         INet4SocketAddress addr3(INet4Address::Loopback,12345);
@@ -62,24 +60,31 @@ BOOST_AUTO_UNIT_TEST(inet4SocketAddress)
     BOOST_CHECK_THROW( INet4SocketAddress(":12345"), AddressSyntaxException );
     BOOST_CHECK_THROW( INet4SocketAddress("127.0.0.1:1234a"), AddressSyntaxException );
 
+    BOOST_CHECK_EQUAL( INet4SocketAddress(12345).port(), 12345 );
+    BOOST_CHECK_EQUAL( INet4SocketAddress(12345).address(), INet4Address::None );
     BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345").address(), INet4Address::Loopback );
     BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345").port(), 12345u );
-    BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(INet4SocketAddress("127.0.0.1:12345")),
-                       "127.0.0.1:12345" );
-
-    {
-        INet4SocketAddress addr("127.0.0.1:12345");
-        BOOST_CHECK_EQUAL( reinterpret_cast< ::sockaddr_in * >(addr.sockaddr_p())->sin_port,
-                           htons(12345) );
-        BOOST_CHECK_EQUAL( reinterpret_cast< ::sockaddr_in * >(addr.sockaddr_p())->sin_addr.s_addr,
-                           htonl(INADDR_LOOPBACK) );
+    BOOST_CHECK_EQUAL( senf::str(INet4SocketAddress("127.0.0.1:12345")), "127.0.0.1:12345" );
 
-        BOOST_CHECK_EQUAL( addr, INet4SocketAddress(addr) );
+    INet4SocketAddress addr("127.0.0.1:12345");
+    BOOST_CHECK_EQUAL( reinterpret_cast< ::sockaddr_in * >(addr.sockaddr_p())->sin_port,
+            htons(12345) );
+    BOOST_CHECK_EQUAL( reinterpret_cast< ::sockaddr_in * >(addr.sockaddr_p())->sin_addr.s_addr,
+            htonl(INADDR_LOOPBACK) );
+    BOOST_CHECK_EQUAL( addr, INet4SocketAddress(addr) );
 
+    {
         std::stringstream str;
         str >> addr;
         BOOST_CHECK( str.fail());
-        str.clear();
+    }
+    {
+        std::stringstream str ("foo:bar");
+        str >> addr;
+        BOOST_CHECK( str.fail());
+    }
+    {
+        std::stringstream str;
         str << addr;
         BOOST_CHECK_EQUAL( str.str(), "127.0.0.1:12345" );
         str >> addr;
@@ -97,7 +102,7 @@ BOOST_AUTO_UNIT_TEST(inet6SocketAddress)
     {
         INet6SocketAddress addr;
         BOOST_CHECK( ! addr );
-        BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(addr.address()), "::" );
+        BOOST_CHECK_EQUAL( senf::str(addr.address()), "::" );
         BOOST_CHECK_EQUAL( addr.port(), 0u );
         BOOST_CHECK_EQUAL( addr.iface(), "" );
         addr = INet6SocketAddress("[12::21]:12345");
@@ -114,15 +119,24 @@ BOOST_AUTO_UNIT_TEST(inet6SocketAddress)
         BOOST_CHECK_EQUAL( addr.address(), INet6Address::from_string("::ffff:1.2.3.4") );
         BOOST_CHECK_EQUAL( addr.port(), 12345u );
 
-        std::stringstream str;
-        str >> addr;
-        BOOST_CHECK( str.fail());
-        str.clear();
-        str << addr;
-        BOOST_CHECK_EQUAL( str.str(), "[::ffff:1.2.3.4]:12345");
-        str >> addr;
-        BOOST_CHECK( ! str.fail());
-        BOOST_CHECK_EQUAL(addr, INet6SocketAddress("[::ffff:1.2.3.4]:12345"));
+        {
+            std::stringstream str;
+            str >> addr;
+            BOOST_CHECK( str.fail());
+        }
+        {
+            std::stringstream str ("[::1]");
+            str >> addr;
+            BOOST_CHECK( str.fail());
+        }
+        {
+            std::stringstream str;
+            str << addr;
+            BOOST_CHECK_EQUAL( str.str(), "[::ffff:1.2.3.4]:12345");
+            str >> addr;
+            BOOST_CHECK( ! str.fail());
+            BOOST_CHECK_EQUAL(addr, INet6SocketAddress("[::ffff:1.2.3.4]:12345"));
+        }
     }
 
     {
@@ -132,6 +146,8 @@ BOOST_AUTO_UNIT_TEST(inet6SocketAddress)
     }
 
     {
+        BOOST_CHECK_THROW( INet6SocketAddress(INet6Address::Loopback, 1, "invalid_iface"), 
+                AddressSyntaxException );
         INet6SocketAddress addr (INet6Address::Loopback, 1, "lo");
         BOOST_CHECK_EQUAL( addr, INet6SocketAddress("[::1%lo]:1") );
         BOOST_CHECK_EQUAL( addr.iface(), "lo" );
@@ -145,11 +161,13 @@ BOOST_AUTO_UNIT_TEST(inet6SocketAddress)
         BOOST_CHECK_THROW( INet6SocketAddress("[::1]"), AddressSyntaxException );
         BOOST_CHECK_THROW( INet6SocketAddress("[::1]1234"), AddressSyntaxException );
         addr = INet6SocketAddress("[12::21%lo]:12345");
-        BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(addr), "[12::21%lo]:12345" );
+        BOOST_CHECK_EQUAL( senf::str(addr), "[12::21%lo]:12345" );
         BOOST_CHECK_EQUAL( addr.address(), INet6Address::from_string("12::21") );
         BOOST_CHECK_EQUAL( addr.port(), 12345u );
         BOOST_CHECK_EQUAL( addr.iface(), "lo" );
-        BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(addr), "[12::21%lo]:12345" );
+        BOOST_CHECK_EQUAL( senf::str(addr), "[12::21%lo]:12345" );
+        BOOST_CHECK_EQUAL( INet6SocketAddress(12345).port(), 12345 );
+        BOOST_CHECK_EQUAL( INet6SocketAddress(12345).address(), INet6Address::None );
     }
 }
 
index 1a2f25e..19446c1 100644 (file)
@@ -26,7 +26,7 @@
 //#include "LLAddressing.test.ih"
 
 // Custom includes
-#include <boost/lexical_cast.hpp>
+#include "../../../Utils/String.hh"
 #include "LLAddressing.hh"
 
 #include "../../../Utils/auto_unit_test.hh"
 
 BOOST_AUTO_UNIT_TEST(llAddress)
 {
+    using senf::LLSocketAddress;
+    
     {
-        senf::LLSocketAddress a;
+        LLSocketAddress addr;
 
-        BOOST_CHECK_EQUAL( a.protocol(), 0u );
-        BOOST_CHECK_EQUAL( a.interface(), "" );
-        BOOST_CHECK_EQUAL( a.arptype(), 0u );
-        BOOST_CHECK_EQUAL( a.pkttype(), senf::LLSocketAddress::Undefined );
-        BOOST_CHECK( ! a.address() );
+        BOOST_CHECK( ! addr );
+        BOOST_CHECK_EQUAL( addr.protocol(), 0u );
+        BOOST_CHECK_EQUAL( addr.interface(), "" );
+        BOOST_CHECK_EQUAL( addr.arptype(), 0u );
+        BOOST_CHECK_EQUAL( addr.pkttype(), LLSocketAddress::Undefined );
+        BOOST_CHECK( ! addr.address() );
 
-        a.address(senf::MACAddress::from_string("05-10-1A-2f-25-30"));
-        BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(a.address()), "05:10:1a:2f:25:30" );
-        a.interface("lo");
-        BOOST_CHECK_EQUAL( a.interface(), "lo" );
-        a.protocol(123);
-        BOOST_CHECK_EQUAL( a.protocol(), 123u );
+        senf::MACAddress mac (senf::MACAddress::from_string("05-10-1A-2f-25-30"));
+        addr.address( mac);
+        BOOST_CHECK( addr );
+        BOOST_CHECK_EQUAL( addr, LLSocketAddress(mac));
+        BOOST_CHECK_EQUAL( addr, LLSocketAddress(addr));
+        BOOST_CHECK_EQUAL( addr.address(), mac );
+        addr.interface("lo");
+        BOOST_CHECK_EQUAL( addr.interface(), "lo" );
+        addr.protocol(123);
+        BOOST_CHECK_EQUAL( addr.protocol(), 123u );
     }
 
     {
-        senf::LLSocketAddress a (
+        LLSocketAddress addr (
             senf::MACAddress::from_string("11-12-13-14-15-16"), "lo");
 
-        BOOST_CHECK_EQUAL( a.protocol(), 0u );
-        BOOST_CHECK_EQUAL( a.interface(), "lo" );
-        BOOST_CHECK_EQUAL( a.arptype(), 0u );
-        BOOST_CHECK_EQUAL( a.pkttype(), senf::LLSocketAddress::Undefined );
-        BOOST_CHECK_EQUAL( boost::lexical_cast<std::string>(a.address()), "11:12:13:14:15:16" );
+        BOOST_CHECK_EQUAL( addr.protocol(), 0u );
+        BOOST_CHECK_EQUAL( addr.interface(), "lo" );
+        BOOST_CHECK_EQUAL( addr.arptype(), 0u );
+        BOOST_CHECK_EQUAL( addr.pkttype(), LLSocketAddress::Undefined );
+        BOOST_CHECK_EQUAL( senf::str(addr.address()), "11:12:13:14:15:16" );
     }
 
     {
-        senf::LLSocketAddress a (123, "lo");
+        LLSocketAddress addr (123, "lo");
 
-        BOOST_CHECK_EQUAL( a.protocol(), 123u );
-        BOOST_CHECK_EQUAL( a.interface(), "lo" );
-        BOOST_CHECK_EQUAL( a.arptype(), 0u );
-        BOOST_CHECK_EQUAL( a.pkttype(), senf::LLSocketAddress::Undefined );
-        BOOST_CHECK( ! a.address() );
+        BOOST_CHECK_EQUAL( addr.protocol(), 123u );
+        BOOST_CHECK_EQUAL( addr.interface(), "lo" );
+        BOOST_CHECK_EQUAL( addr.arptype(), 0u );
+        BOOST_CHECK_EQUAL( addr.pkttype(), LLSocketAddress::Undefined );
+        BOOST_CHECK( ! addr.address() );
+    }
+    
+    {
+        BOOST_CHECK_THROW( LLSocketAddress addr("SENF_TEST_INVALID_INTERFACENAME"),
+                senf::AddressSyntaxException );
+        
+        LLSocketAddress addr ("lo");
+        
+        BOOST_CHECK_EQUAL( addr.protocol(), 0u );
+        BOOST_CHECK_EQUAL( addr.interface(), "lo" );
+        BOOST_CHECK_EQUAL( addr.arptype(), 0u );
+        BOOST_CHECK_EQUAL( addr.pkttype(), LLSocketAddress::Undefined );
+        BOOST_CHECK( ! addr.address() );
+        
+        BOOST_CHECK_EQUAL( LLSocketAddress("").interface(), "" );
     }
 }
 
index b2c33b7..c4e36af 100644 (file)
@@ -52,16 +52,25 @@ BOOST_AUTO_UNIT_TEST(macAddress)
     BOOST_CHECK_EQUAL( mac[4], 0xE5u );
     BOOST_CHECK_EQUAL( mac[5], 0xF6u );
 
-    std::stringstream str;
-    str >> mac;
-    BOOST_CHECK( str.fail());
-    str.clear();
-    str << mac;
-    BOOST_CHECK_EQUAL( str.str(), "a1:b2:c3:d4:e5:f6" );
-    str >> mac;
-    BOOST_CHECK( ! str.fail());
+    {
+        std::stringstream str;
+        str >> mac;
+        BOOST_CHECK( str.fail());
+    }
+    {
+        std::stringstream str ( "invalid_mac_address");
+        str >> mac;
+        BOOST_CHECK( str.fail());
+    }
+    {
+        std::stringstream str;
+        str << mac;
+        BOOST_CHECK_EQUAL( str.str(), "a1:b2:c3:d4:e5:f6" );
+        str >> mac;
+        BOOST_CHECK( ! str.fail());
+    }
+    
     BOOST_CHECK_EQUAL(mac, MACAddress::from_string(test));
-
     BOOST_CHECK( ! mac.local() );
     BOOST_CHECK( mac.multicast() );
     BOOST_CHECK( ! mac.broadcast() );
@@ -85,7 +94,11 @@ BOOST_AUTO_UNIT_TEST(macAddress)
 
     BOOST_CHECK_THROW( MACAddress::from_string("1:2:3:4:5:6"), AddressSyntaxException );
     BOOST_CHECK_THROW( MACAddress::from_string("01:02:03:04:05"), AddressSyntaxException );
+    // test all invalid ascii ranges
     BOOST_CHECK_THROW( MACAddress::from_string("01:02:03:04:05:z6"), AddressSyntaxException );
+    BOOST_CHECK_THROW( MACAddress::from_string("01:02:03:04:05:/6"), AddressSyntaxException );
+    BOOST_CHECK_THROW( MACAddress::from_string("01:02:03:04:05:@6"), AddressSyntaxException );
+    BOOST_CHECK_THROW( MACAddress::from_string("01:02:03:04:05:[6"), AddressSyntaxException );
 
     BOOST_CHECK_EQUAL( mac, MACAddress::from_eui64(0xa1b2c3fffed4e5f6llu) );
     BOOST_CHECK_THROW( MACAddress::from_eui64(0u), AddressSyntaxException );
index 59c5cfa..bcf1641 100644 (file)
@@ -35,7 +35,7 @@
 prefix_ void senf::UNSocketAddress::path(std::string const & path)
 {
     if (path.size() > sizeof(sockaddr_un)-sizeof(short)-1)
-        throw AddressSyntaxException();
+        throw AddressSyntaxException() << "UNSocketAddress path too long: " << path;
     socklen(path.size()+sizeof(short));
     memcpy(addr_.sun_path, path.c_str(), socklen()-sizeof(short));
     addr_.sun_path[socklen()-sizeof(short)+1] = 0;
index 5863d4b..d3a7fc6 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 //
-// Copyright (C) 2007
+// Copyright (C) 2009
 // Fraunhofer Institute for Open Communication Systems (FOKUS)
 // Competence Center NETwork research (NET), St. Augustin, GERMANY
-//     David Wagner <dw6@berlios.de>
+//     Thorsten Horstmann <tho@berlios.de>
 //
 // 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
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 /** \file
-    \brief UNAddressing.test unit tests */
+    \brief UNAddressing unit tests */
 
 //#include "UNAddressing.test.hh"
 //#include "UNAddressing.test.ih"
 
 // Custom includes
 #include "UNAddressing.hh"
+#include "../AddressExceptions.hh"
+#include <sstream>
 
 #include "../../../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
 
-#include <sys/socket.h>
-#include <sys/un.h>
-
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
 
-BOOST_AUTO_UNIT_TEST(unSocketAddress)
+BOOST_AUTO_UNIT_TEST(UNSocketAddress)
 {
-//  TODO: muss wieder rein.     
-//    std::string testS = "/tmp/senfTestSocket";
-//    senf::UNSocketAddress addr (testS) ; 
-//    int mySock = socket(AF_UNIX, SOCK_DGRAM, 0); 
-//    if (bind(mySock, addr.sockaddr_p(), addr.socklen())) { 
-//        std::cout << "Error while binding name to unix socket" << std::endl;
-//    }
-
+    senf::UNSocketAddress addr;
+    BOOST_CHECK( ! addr);
+        
+    std::string path ("/tmp/SENF_TEST");
+    addr.path( path);
+    
+    BOOST_CHECK( addr);
+    BOOST_CHECK_EQUAL( addr.path(), path);
+    BOOST_CHECK_EQUAL( addr, senf::UNSocketAddress(path));
+    BOOST_CHECK_EQUAL( addr, senf::UNSocketAddress(addr));
+    
+    std::stringstream str;
+    str << addr;
+    BOOST_CHECK_EQUAL( str.str(), path );
+    
+    // UNSocketAddress path too long
+    BOOST_CHECK_THROW( senf::UNSocketAddress(std::string(1024, 'x')), senf::AddressSyntaxException );
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////