// Custom includes
#include <boost/ptr_container/ptr_map.hpp>
+#include "../Utils/String.hh"
#include "Module.hh"
#include "Connectors.hh"
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);
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();
{
output(packet_.clone());
}
+
void senf::ppi::module::CloneSource::replacePacket(senf::Packet const & packet)
{
packet_ = packet;
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);
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] );
}
namespace senf {
-
struct TLVLengthException : public senf::Exception
- { TLVLengthException()
- : senf::Exception("TLVLengthException"){} };
+ {
+ TLVLengthException()
+ : senf::Exception("TLVLengthException") {}
+ };
class DynamicTLVLengthParser
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));
#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(),
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_
// 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)
{
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");
}
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() );
}
// Custom includes
#include "DTCPPacket.hh"
+#include "../../Utils/String.hh"
#include "../../Utils/auto_unit_test.hh"
#include <boost/test/test_tools.hpp>
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);
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
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
BOOST_AUTO_UNIT_TEST(packet)
{
- senf::Packet packet (FooPacket::create());
+ senf::Packet packet (FooPacket::create());
BarPacket::createAfter(packet);
BOOST_REQUIRE( 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>() );
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)
// 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>
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)
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 );
//#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>
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");
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") );
}
{
- 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;
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() );
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 );
///< 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 [::]
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;
// Custom includes
#include "INetAddressing.hh"
+#include "../../../Utils/String.hh"
#include "../../../Utils/auto_unit_test.hh"
#include <boost/test/test_tools.hpp>
{
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);
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;
{
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");
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"));
+ }
}
{
}
{
+ 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" );
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 );
}
}
//#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(), "" );
}
}
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() );
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 );
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;
// $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////////////////////////////////////////