From: tho Date: Wed, 18 Feb 2009 17:23:25 +0000 (+0000) Subject: replaced all BOOST_CHECK_NO_THROW with SENF_CHECK_NO_THROW X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=d001b1fe2a8fb121145d2a111d737219abae20d7;p=senf.git replaced all BOOST_CHECK_NO_THROW with SENF_CHECK_NO_THROW added more tests to increase test coverage git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1126 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/Connectors.test.cc b/PPI/Connectors.test.cc index 2e599ba..a793d26 100644 --- a/PPI/Connectors.test.cc +++ b/PPI/Connectors.test.cc @@ -402,22 +402,22 @@ BOOST_AUTO_UNIT_TEST(connectorTest) { TypedPassiveInput<> input; TypedActiveOutput<> output; - BOOST_CHECK_NO_THROW( ppi::connect(output, input) ); + SENF_CHECK_NO_THROW( ppi::connect(output, input) ); } { TypedPassiveInput<> input; debug::ActiveSource output; - BOOST_CHECK_NO_THROW( ppi::connect(output, input) ); + SENF_CHECK_NO_THROW( ppi::connect(output, input) ); } { debug::ActiveSink input; TypedPassiveOutput<> output; - BOOST_CHECK_NO_THROW( ppi::connect(output, input) ); + SENF_CHECK_NO_THROW( ppi::connect(output, input) ); } { debug::ActiveSink input; debug::PassiveSource output; - BOOST_CHECK_NO_THROW( ppi::connect(output, input) ); + SENF_CHECK_NO_THROW( ppi::connect(output, input) ); } } diff --git a/Packets/80221Bundle/MIHPacket.test.cc b/Packets/80221Bundle/MIHPacket.test.cc index 675bc61..4fcbdbc 100644 --- a/Packets/80221Bundle/MIHPacket.test.cc +++ b/Packets/80221Bundle/MIHPacket.test.cc @@ -60,6 +60,9 @@ BOOST_AUTO_UNIT_TEST(MIHPacket_create_string) BOOST_CHECK_EQUAL( mihPacket->src_mihfId().asString(), "senf@berlios.de"); BOOST_CHECK_EQUAL( mihPacket->dst_mihfId().asString(), "test"); + // the maximum length of a MIHF_ID is 253 octets + BOOST_CHECK_THROW( mihPacket->dst_mihfId().setString( std::string(254, 'x')), std::length_error); + // now expand a MIHF_ID mihPacket->dst_mihfId().maxLengthValue(253); mihPacket->dst_mihfId().setString( std::string(200, 'x')); diff --git a/Packets/80221Bundle/TLVPacket.test.cc b/Packets/80221Bundle/TLVPacket.test.cc index b5c4949..2ba1864 100644 --- a/Packets/80221Bundle/TLVPacket.test.cc +++ b/Packets/80221Bundle/TLVPacket.test.cc @@ -44,6 +44,8 @@ void check_TLVPacket(GenericTLVPacket &tlvPacket, boost::uint8_t type, boost::ui BOOST_CHECK_EQUAL( tlvPacket->type(), type ); BOOST_CHECK_EQUAL( tlvPacket->length(), length ); BOOST_CHECK_EQUAL( tlvPacket->value().size(), int(length) ); + std::ostringstream oss (std::ostringstream::out); + SENF_CHECK_NO_THROW( tlvPacket.dump( oss)); senf::PacketData::iterator dataIterator (tlvPacket->value().begin()); for (unsigned i=0; imaxLengthValue( DynamicTLVLengthParser::max_value); tlvPacket->type() = 42u; tlvPacket->value( value); tlvPacket.finalizeThis(); diff --git a/Packets/MPEGDVBBundle/TransportPacket.test.cc b/Packets/MPEGDVBBundle/TransportPacket.test.cc index c3cc1a7..caa2b02 100644 --- a/Packets/MPEGDVBBundle/TransportPacket.test.cc +++ b/Packets/MPEGDVBBundle/TransportPacket.test.cc @@ -116,6 +116,8 @@ BOOST_AUTO_UNIT_TEST(transportPacket_create_with_pusi) 0x1d, 0xc4, 0xe8, 0xc1 }; senf::DataPacket payload (senf::DataPacket::createAfter( ts_packet, payload_data)); + + // TODO: add method for stuffing } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Packets/PacketInterpreter.test.cc b/Packets/PacketInterpreter.test.cc index c790d21..679940a 100644 --- a/Packets/PacketInterpreter.test.cc +++ b/Packets/PacketInterpreter.test.cc @@ -129,7 +129,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter) } { - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( senf::PacketInterpreter::create(4u,senf::noinit)); senf::PacketInterpreter::ptr p (senf::PacketInterpreter::create(senf::noinit)); @@ -178,7 +178,7 @@ BOOST_AUTO_UNIT_TEST(packetInterpreter) BOOST_CHECK_EQUAL( p2->data()[0], 0x01u ); BOOST_CHECK_THROW( senf::PacketInterpreter::createAfter(p, size_type(4u)), senf::TruncatedPacketException ); - BOOST_CHECK_NO_THROW( senf::PacketInterpreter::createAfter( + SENF_CHECK_NO_THROW( senf::PacketInterpreter::createAfter( p,4u,senf::noinit) ); } diff --git a/Packets/PacketParser.test.cc b/Packets/PacketParser.test.cc index 66d84f3..7adc52a 100644 --- a/Packets/PacketParser.test.cc +++ b/Packets/PacketParser.test.cc @@ -77,7 +77,7 @@ BOOST_AUTO_UNIT_TEST(packetParserBase) BOOST_CHECK( pi->data().begin() == p.i() ); BOOST_CHECK( p.check(6u) ); BOOST_CHECK( ! p.check(7u) ); - BOOST_CHECK_NO_THROW( p.validate(6u) ); + SENF_CHECK_NO_THROW( p.validate(6u) ); BOOST_CHECK_THROW( p.validate(7u), senf::TruncatedPacketException ); // ?? Why the heck do I need the +0? I get an 'undefined symbol FooParser::fixed_bytes' diff --git a/Scheduler/Scheduler.test.cc b/Scheduler/Scheduler.test.cc index b8c5b50..2254cdb 100644 --- a/Scheduler/Scheduler.test.cc +++ b/Scheduler/Scheduler.test.cc @@ -248,7 +248,7 @@ void schedulerTest() senf::scheduler::FdEvent fde1 ("testFdEvent", boost::bind(&callback, sock, _1), sock, senf::scheduler::FdEvent::EV_READ); event = senf::scheduler::FdEvent::EV_NONE; - BOOST_CHECK_NO_THROW( senf::scheduler::process() ); + SENF_CHECK_NO_THROW( senf::scheduler::process() ); BOOST_CHECK_EQUAL( event, senf::scheduler::FdEvent::EV_READ ); BOOST_REQUIRE_EQUAL( size, 4 ); buffer[size]=0; @@ -260,13 +260,13 @@ void schedulerTest() strcpy(buffer,"WRITE"); size=5; event = senf::scheduler::FdEvent::EV_NONE; - BOOST_CHECK_NO_THROW( senf::scheduler::process() ); + SENF_CHECK_NO_THROW( senf::scheduler::process() ); BOOST_CHECK_EQUAL( event, senf::scheduler::FdEvent::EV_WRITE ); SENF_CHECK_NO_THROW( fde2.disable() ); event = senf::scheduler::FdEvent::EV_NONE; sleep(1); - BOOST_CHECK_NO_THROW( senf::scheduler::process() ); + SENF_CHECK_NO_THROW( senf::scheduler::process() ); BOOST_CHECK_EQUAL( event, senf::scheduler::FdEvent::EV_READ|senf::scheduler::FdEvent::EV_HUP ); BOOST_REQUIRE_EQUAL( size, 2 ); buffer[size]=0; @@ -281,23 +281,23 @@ void schedulerTest() event = senf::scheduler::FdEvent::EV_NONE; senf::ClockService::clock_type t (senf::ClockService::now()); - BOOST_CHECK_NO_THROW( senf::scheduler::process() ); + SENF_CHECK_NO_THROW( senf::scheduler::process() ); BOOST_CHECK_PREDICATE( is_close, (senf::ClockService::now()-t) (senf::ClockService::milliseconds(200)) ); BOOST_CHECK( timeoutCalled ); BOOST_CHECK( ! timer1.enabled() ); BOOST_CHECK_EQUAL( event, senf::scheduler::FdEvent::EV_NONE ); BOOST_CHECK_PREDICATE( is_close, (senf::ClockService::now()) (senf::scheduler::eventTime()) ); timeoutCalled = false; - BOOST_CHECK_NO_THROW( senf::scheduler::process() ); + SENF_CHECK_NO_THROW( senf::scheduler::process() ); BOOST_CHECK_PREDICATE( is_close, (senf::ClockService::now()-t) (senf::ClockService::milliseconds(400)) ); BOOST_CHECK( timeoutCalled ); BOOST_CHECK_EQUAL( event, senf::scheduler::FdEvent::EV_NONE ); BOOST_CHECK( ! timer2.enabled() ); BOOST_WARN_MESSAGE( false, "A 'Scheduler task hanging' error is expected to be signaled here." ); - BOOST_CHECK_NO_THROW( timer1.action(&blockingHandler) ); - BOOST_CHECK_NO_THROW( timer1.timeout(senf::ClockService::now()) ); - BOOST_CHECK_NO_THROW( senf::scheduler::process() ); + SENF_CHECK_NO_THROW( timer1.action(&blockingHandler) ); + SENF_CHECK_NO_THROW( timer1.timeout(senf::ClockService::now()) ); + SENF_CHECK_NO_THROW( senf::scheduler::process() ); BOOST_CHECK_EQUAL( senf::scheduler::hangCount(), 1u ); } @@ -309,10 +309,10 @@ void schedulerTest() senf::ClockService::clock_type t = senf::ClockService::now(); ::kill(::getpid(), SIGUSR1); delay(200); - BOOST_CHECK_NO_THROW( senf::scheduler::process() ); + SENF_CHECK_NO_THROW( senf::scheduler::process() ); BOOST_CHECK_PREDICATE( is_close, (senf::ClockService::now()) (t+senf::ClockService::milliseconds(200)) ); BOOST_CHECK_PREDICATE( is_close, (sigtime) (t+senf::ClockService::milliseconds(200)) ); - BOOST_CHECK_NO_THROW( senf::scheduler::process() ); + SENF_CHECK_NO_THROW( senf::scheduler::process() ); } BOOST_CHECK( eventCount >= 8u ); @@ -365,14 +365,14 @@ BOOST_AUTO_UNIT_TEST(blockSignals) senf::scheduler::SignalEvent sig (SIGUSR1, &sigusr); senf::ClockService::clock_type t = senf::ClockService::now(); - BOOST_CHECK_NO_THROW( senf::scheduler::process() ); + SENF_CHECK_NO_THROW( senf::scheduler::process() ); BOOST_CHECK_PREDICATE( is_close, (senf::ClockService::now()) (t+senf::ClockService::milliseconds(200)) ); BOOST_CHECK_PREDICATE( is_close, (sigtime) (t+senf::ClockService::milliseconds(200)) ); - BOOST_CHECK_NO_THROW( senf::scheduler::process() ); + SENF_CHECK_NO_THROW( senf::scheduler::process() ); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Socket/ClientSocketHandle.test.cc b/Socket/ClientSocketHandle.test.cc index 9dda3e7..0d6e994 100644 --- a/Socket/ClientSocketHandle.test.cc +++ b/Socket/ClientSocketHandle.test.cc @@ -74,7 +74,7 @@ BOOST_AUTO_UNIT_TEST(clientSocketHandle) BOOST_CHECKPOINT("static_casting socket handle"); SomeSocketHandle ssh = senf::static_socket_cast(osh); - BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast(osh) ); + SENF_CHECK_NO_THROW( senf::dynamic_socket_cast(osh) ); typedef senf::ClientSocketHandle= prefix_len() && match(net.address()); @@ -160,7 +160,7 @@ prefix_ std::ostream & senf::operator<<(std::ostream & os, INet4Network const & ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ - + // Local Variables: // mode: c++ // fill-column: 100 diff --git a/Socket/Protocols/INet/INet4Address.hh b/Socket/Protocols/INet/INet4Address.hh index 4b5f3ec..fc21d0a 100644 --- a/Socket/Protocols/INet/INet4Address.hh +++ b/Socket/Protocols/INet/INet4Address.hh @@ -223,9 +223,9 @@ namespace senf { ///@{ INet4Network(); ///< Construct empty (0.0.0.0/0) network - INet4Network(INet4Address address, unsigned prefix_len); + INet4Network(INet4Address const & address, unsigned prefix_len); ///< Construct network from given address and prefix length - explicit INet4Network(std::string s); ///< Construct network from CIDR notation + explicit INet4Network(std::string const & s); ///< Construct network from CIDR notation ///@} /////////////////////////////////////////////////////////////////////////// @@ -237,8 +237,8 @@ namespace senf { bool operator==(INet4Network const & other) const; ///< Compare to networks for equality - bool match(INet4Address addr) const; ///< \c true, if the network includes \a addr - bool match(INet4Network net) const; ///< \c true, if the network includes \a net + bool match(INet4Address const & addr) const; ///< \c true, if the network includes \a addr + bool match(INet4Network const & net) const; ///< \c true, if the network includes \a net /**< The is true, if \a net is sub-network (or the same as) \c this. */ diff --git a/Socket/Protocols/INet/INet4Address.test.cc b/Socket/Protocols/INet/INet4Address.test.cc index 7ff1539..b026788 100644 --- a/Socket/Protocols/INet/INet4Address.test.cc +++ b/Socket/Protocols/INet/INet4Address.test.cc @@ -40,36 +40,46 @@ BOOST_AUTO_UNIT_TEST(inet4Address) { - senf::INet4Address addr (senf::INet4Address::from_string("127.0.0.1")); - BOOST_CHECK_EQUAL( addr, senf::INet4Address::Loopback ); - BOOST_CHECK( addr != senf::INet4Address::Broadcast ); + using senf::INet4Address; + using senf::AddressSyntaxException; + using senf::UnknownHostnameException; - addr = senf::INet4Address::from_string("localhost"); - BOOST_CHECK_EQUAL( addr, senf::INet4Address::Loopback ); + INet4Address addr (INet4Address::from_string("127.0.0.1")); + BOOST_CHECK_EQUAL( addr, INet4Address::Loopback ); + BOOST_CHECK( addr != INet4Address::Broadcast ); + + addr = INet4Address::from_string("localhost"); + BOOST_CHECK_EQUAL( addr, INet4Address::Loopback ); BOOST_CHECK( addr.loopback() ); char data[] = { 128, 129, 130, 131 }; - addr = senf::INet4Address::from_data(data); - BOOST_CHECK_EQUAL( addr, senf::INet4Address::from_string("128.129.130.131") ); + addr = INet4Address::from_data(data); + BOOST_CHECK_EQUAL( addr, INet4Address::from_string("128.129.130.131") ); BOOST_CHECK_EQUAL( addr.inaddr(), htonl(0x80818283u) ); BOOST_CHECK_EQUAL( addr.address(), 0x80818283u ); BOOST_CHECK( ! addr.loopback() ); BOOST_CHECK( ! addr.local() ); - BOOST_CHECK( senf::INet4Address::from_string("192.168.1.2").local() ); + BOOST_CHECK( INet4Address::from_string("192.168.1.2").local() ); BOOST_CHECK( ! addr.multicast() ); - BOOST_CHECK( senf::INet4Address::from_string("224.1.2.3").multicast() ); + BOOST_CHECK( INet4Address::from_string("224.1.2.3").multicast() ); BOOST_CHECK( ! addr.broadcast() ); - BOOST_CHECK( senf::INet4Address::from_string("255.255.255.255").broadcast() ); + BOOST_CHECK( INet4Address::from_string("255.255.255.255").broadcast() ); BOOST_CHECK( addr ); - BOOST_CHECK( ! senf::INet4Address() ); + BOOST_CHECK( ! INet4Address() ); + BOOST_CHECK_THROW( INet4Address::from_string(""), AddressSyntaxException ); + 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_EQUAL(addr, senf::INet4Address::from_string("128.129.130.131") ); + BOOST_CHECK( ! str.fail()); + BOOST_CHECK_EQUAL(addr, INet4Address::from_string("128.129.130.131") ); } BOOST_AUTO_UNIT_TEST(inet4Network) @@ -79,7 +89,7 @@ BOOST_AUTO_UNIT_TEST(inet4Network) BOOST_CHECK_EQUAL( net.prefix_len(), 8u ); BOOST_CHECK( net ); BOOST_CHECK( ! senf::INet4Network() ); - + senf::INet4Network net2 ("192.0.111.222/16"); BOOST_CHECK_EQUAL( net2.address(), senf::INet4Address::from_string("192.0.0.0") ); BOOST_CHECK_EQUAL( net2.prefix_len(), 16u ); @@ -95,12 +105,15 @@ BOOST_AUTO_UNIT_TEST(inet4Network) BOOST_CHECK_EQUAL( net2.host(-1), senf::INet4Address::from_string("192.0.255.255") ); BOOST_CHECK_EQUAL( boost::lexical_cast(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 ); } ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ - + // Local Variables: // mode: c++ // fill-column: 100 diff --git a/Socket/Protocols/INet/INet6Address.cc b/Socket/Protocols/INet/INet6Address.cc index 94afd47..9d16e19 100644 --- a/Socket/Protocols/INet/INet6Address.cc +++ b/Socket/Protocols/INet/INet6Address.cc @@ -124,7 +124,7 @@ senf::INet6Address const senf::INet6Address::AllRouters (0xFF02u,0u,0u,0u,0u,0u, /////////////////////////////////////////////////////////////////////////// // senf::INet6Network -prefix_ senf::INet6Network::INet6Network(std::string s) +prefix_ senf::INet6Network::INet6Network(std::string const & s) { using boost::lambda::_1; using boost::lambda::_2; diff --git a/Socket/Protocols/INet/INet6Address.cci b/Socket/Protocols/INet/INet6Address.cci index 61fa0c6..93ab3c0 100644 --- a/Socket/Protocols/INet/INet6Address.cci +++ b/Socket/Protocols/INet/INet6Address.cci @@ -63,7 +63,7 @@ prefix_ senf::INet6Address senf::INet6Address::from_in6addr(in6_addr const & in6 return senf::INet6Address::from_data(&in6addr.s6_addr[0]); } -prefix_ senf::INet6Address senf::INet6Address::from_inet4address(INet4Address addr4) +prefix_ senf::INet6Address senf::INet6Address::from_inet4address(INet4Address const & addr4) { INet6Address addr; addr[10] = 0xffu; @@ -75,7 +75,7 @@ prefix_ senf::INet6Address senf::INet6Address::from_inet4address(INet4Address ad prefix_ boost::uint64_t senf::INet6Address::network() const { - return + return ((boost::uint64_t((*this)[0]) & 0xff) << 56 ) | ((boost::uint64_t((*this)[1]) & 0xff) << 48 ) | ((boost::uint64_t((*this)[2]) & 0xff) << 40 ) | @@ -89,7 +89,7 @@ prefix_ boost::uint64_t senf::INet6Address::network() prefix_ boost::uint64_t senf::INet6Address::id() const { - return + return ((boost::uint64_t((*this)[ 8]) & 0xff) << 56 ) | ((boost::uint64_t((*this)[ 9]) & 0xff) << 48 ) | ((boost::uint64_t((*this)[10]) & 0xff) << 40 ) | @@ -138,9 +138,9 @@ prefix_ senf::INet6Address::ScopeId senf::INet6Address::scope() AdminScope, SiteScope, UnassignedScope, UnassignedScope, OrganizationScope, UnassignedScope, UnassignedScope, UnassignedScope, UnassignedScope, UnassignedScope, GlobalScope, ReservedScope }; - return multicast() ? scopeMap[(*this)[1] & 0x0Fu] : - (*this)[0] == 0xFEu ? (((*this)[1]&0xC0) == 0x80 ? LinkScope : - ((*this)[1]&0xC0) == 0xC0 ? SiteScope : GlobalScope ) + return multicast() ? scopeMap[(*this)[1] & 0x0Fu] : + (*this)[0] == 0xFEu ? (((*this)[1]&0xC0) == 0x80 ? LinkScope : + ((*this)[1]&0xC0) == 0xC0 ? SiteScope : GlobalScope ) : GlobalScope; } @@ -161,7 +161,7 @@ prefix_ bool senf::INet6Address::globalScope() { return scope() == GlobalScope; } - + prefix_ bool senf::INet6Address::linkScope() const { @@ -230,7 +230,7 @@ prefix_ senf::INet6Network::INet6Network() : prefix_len_(), address_() {} -prefix_ senf::INet6Network::INet6Network(INet6Address address, unsigned prefix_len) +prefix_ senf::INet6Network::INet6Network(INet6Address const & address, unsigned prefix_len) : prefix_len_(prefix_len), address_(address) { using boost::lambda::_1; @@ -262,7 +262,7 @@ prefix_ bool senf::INet6Network::operator==(INet6Network const & other) return prefix_len() == other.prefix_len() && address() == other.address(); } -prefix_ bool senf::INet6Network::match(INet6Address addr) +prefix_ bool senf::INet6Network::match(INet6Address const & addr) const { using boost::lambda::_1; @@ -272,7 +272,7 @@ prefix_ bool senf::INet6Network::match(INet6Address addr) _1 != (_2 & _3)) == address_.end(); } -prefix_ bool senf::INet6Network::match(INet6Network net) +prefix_ bool senf::INet6Network::match(INet6Network const & net) const { return net.prefix_len() >= prefix_len() && match(net.address()); @@ -316,7 +316,7 @@ prefix_ boost::uint8_t senf::detail::low_bits_mask(unsigned bits) ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ - + // Local Variables: // mode: c++ // fill-column: 100 diff --git a/Socket/Protocols/INet/INet6Address.hh b/Socket/Protocols/INet/INet6Address.hh index a959837..953bc49 100644 --- a/Socket/Protocols/INet/INet6Address.hh +++ b/Socket/Protocols/INet/INet6Address.hh @@ -193,7 +193,7 @@ namespace senf { data as accessed by the iterator. The data must be in network byte order. */ - static INet6Address from_inet4address(INet4Address addr); + static INet6Address from_inet4address(INet4Address const & addr); ///< Construct an INet6-mapped INet4 address /**< This will construct an address of the form ::FFFF::w.x.y.z where w.x.y.z is @@ -335,9 +335,9 @@ namespace senf { ///@{ INet6Network(); ///< Construct empty (::/0) network - INet6Network(INet6Address address, unsigned prefix_len); + INet6Network(INet6Address const & address, unsigned prefix_len); ///< Construct network from given address and prefix length - explicit INet6Network(std::string s); ///< Construct network from CIDR notation + explicit INet6Network(std::string const & s); ///< Construct network from CIDR notation ///@} /////////////////////////////////////////////////////////////////////////// @@ -349,8 +349,8 @@ namespace senf { bool operator==(INet6Network const & other) const; ///< Compare two networks for equality - bool match(INet6Address addr) const; ///< \c true, if the network includes \a addr - bool match(INet6Network net) const; ///< \c true, if the network includes \a net + bool match(INet6Address const & addr) const; ///< \c true, if the network includes \a addr + bool match(INet6Network const & net) const; ///< \c true, if the network includes \a net /**< The is true, if \a net is sub-network (or the same as) \c this. */ INet6Address host(boost::uint64_t id); ///< Return the host with the given id diff --git a/Socket/Protocols/INet/INet6Address.test.cc b/Socket/Protocols/INet/INet6Address.test.cc index 4932467..3bdce5a 100644 --- a/Socket/Protocols/INet/INet6Address.test.cc +++ b/Socket/Protocols/INet/INet6Address.test.cc @@ -122,19 +122,25 @@ BOOST_AUTO_UNIT_TEST(inet6Address) BOOST_CHECK( INet6Address(0u,0u,0u,0u,0u,0xFFFF,0x0102,0x0304).inet4Mapped() ); BOOST_CHECK( ! addr.inet4Compatible() ); BOOST_CHECK( ! addr.inet4Mapped() ); - + BOOST_CHECK( INet6Address::AllNodes.globalMulticastAddr() ); BOOST_CHECK( ! INet6Address::AllNodes.prefixMulticastAddr() ); BOOST_CHECK( ! INet6Address::AllNodes.embeddedRpAddr() ); BOOST_CHECK( INet6Address::Loopback ); BOOST_CHECK( ! INet6Address::None ); - + } + + { + INet6Address addr (INet6Address::from_string("2001:dead:beef::1002:3004")); std::stringstream str; + str >> addr; + BOOST_CHECK( str.fail()); + str.clear(); str << addr; BOOST_CHECK_EQUAL( str.str(), "2001:dead:beef::1002:3004"); - str >> addr; + BOOST_CHECK( ! str.fail()); BOOST_CHECK_EQUAL(addr, INet6Address::from_string("2001:dead:beef::1002:3004")); } @@ -149,34 +155,41 @@ BOOST_AUTO_UNIT_TEST(inet6Address) BOOST_AUTO_UNIT_TEST(inet6Network) { - senf::INet6Network net (senf::INet6Address(0xFF14u,0x1234u),32u); + using senf::INet6Address; + using senf::INet6Network; + using senf::AddressSyntaxException; + + INet6Network net (INet6Address(0xFF14u,0x1234u),32u); BOOST_CHECK_EQUAL( boost::lexical_cast(net.address()), "ff14:1234::"); BOOST_CHECK_EQUAL( net.prefix_len(), 32u ); BOOST_CHECK( net ); - BOOST_CHECK( ! senf::INet6Network() ); - - senf::INet6Network net2 ("2001:db8:1234::/44"); - BOOST_CHECK_EQUAL( net2.address(), senf::INet6Address::from_string("2001:db8:1230::") ); + BOOST_CHECK( ! INet6Network() ); + + INet6Network net2 ("2001:db8:1234::/44"); + BOOST_CHECK_EQUAL( net2.address(), INet6Address::from_string("2001:db8:1230::") ); BOOST_CHECK_EQUAL( net2.prefix_len(), 44u ); BOOST_CHECK( net != net2 ); - BOOST_CHECK( net.match(senf::INet6Address::from_string("ff14:1234::1")) ); - BOOST_CHECK( ! net2.match(senf::INet6Address::from_string("ff13:1234::1")) ); + 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(senf::INet6Network("2001:db8:1234::/48")) ); - BOOST_CHECK( ! net2.match(senf::INet6Network("2001:db8:1234::/32")) ); + BOOST_CHECK( net2.match(INet6Network("2001:db8:1234::/48")) ); + BOOST_CHECK( ! net2.match(INet6Network("2001:db8:1234::/32")) ); BOOST_CHECK_EQUAL( boost::lexical_cast(net2), "2001:db8:1230::/44" ); - BOOST_CHECK_EQUAL( net2.host(0x1234u), senf::INet6Address::from_string("2001:db8:1230::1234") ); - BOOST_CHECK_EQUAL( boost::lexical_cast(net2.subnet(2u,48u)), + BOOST_CHECK_EQUAL( net2.host(0x1234u), INet6Address::from_string("2001:db8:1230::1234") ); + BOOST_CHECK_EQUAL( boost::lexical_cast(net2.subnet(2u,48u)), "2001:db8:1232::/48" ); + + BOOST_CHECK_THROW( INet6Network(""), AddressSyntaxException ); + BOOST_CHECK_THROW( INet6Network("2001:db8:1234::/beef"), AddressSyntaxException ); } ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ - + // Local Variables: // mode: c++ // fill-column: 100 diff --git a/Socket/Protocols/INet/INetAddressing.test.cc b/Socket/Protocols/INet/INetAddressing.test.cc index 0c7a7b0..8049dac 100644 --- a/Socket/Protocols/INet/INetAddressing.test.cc +++ b/Socket/Protocols/INet/INetAddressing.test.cc @@ -42,7 +42,7 @@ BOOST_AUTO_UNIT_TEST(inet4SocketAddress) { INet4SocketAddress addr; - + BOOST_CHECK( ! addr ); addr = INet4SocketAddress("127.0.0.1:12345"); @@ -54,7 +54,7 @@ BOOST_AUTO_UNIT_TEST(inet4SocketAddress) INet4SocketAddress addr3(INet4Address::Loopback,12345); } - BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345"), + BOOST_CHECK_EQUAL( INet4SocketAddress("127.0.0.1:12345"), INet4SocketAddress(INet4Address::Loopback,12345) ); BOOST_CHECK_THROW( INet4SocketAddress("127.0.0.1"), AddressSyntaxException ); @@ -74,9 +74,17 @@ BOOST_AUTO_UNIT_TEST(inet4SocketAddress) BOOST_CHECK_EQUAL( reinterpret_cast< ::sockaddr_in * >(addr.sockaddr_p())->sin_addr.s_addr, htonl(INADDR_LOOPBACK) ); - std::stringstream s; - s << addr; - BOOST_CHECK_EQUAL( s.str(), "127.0.0.1:12345" ); + BOOST_CHECK_EQUAL( addr, INet4SocketAddress(addr) ); + + std::stringstream str; + str >> addr; + BOOST_CHECK( str.fail()); + str.clear(); + str << addr; + BOOST_CHECK_EQUAL( str.str(), "127.0.0.1:12345" ); + str >> addr; + BOOST_CHECK( ! str.fail()); + BOOST_CHECK_EQUAL(addr, INet4SocketAddress("127.0.0.1:12345")); } } @@ -92,29 +100,40 @@ BOOST_AUTO_UNIT_TEST(inet6SocketAddress) BOOST_CHECK_EQUAL( boost::lexical_cast(addr.address()), "::" ); BOOST_CHECK_EQUAL( addr.port(), 0u ); BOOST_CHECK_EQUAL( addr.iface(), "" ); - addr = senf::INet6SocketAddress("[12::21]:12345"); - BOOST_CHECK( addr == senf::INet6SocketAddress("[12::21]:12345") ); - BOOST_CHECK( addr != senf::INet6SocketAddress("[12::21%lo]:12345") ); + addr = INet6SocketAddress("[12::21]:12345"); + BOOST_CHECK( addr == INet6SocketAddress("[12::21]:12345") ); + BOOST_CHECK_EQUAL( addr, INet6SocketAddress(addr) ); + BOOST_CHECK( addr != INet6SocketAddress("[12::21%lo]:12345") ); BOOST_CHECK( addr ); BOOST_CHECK_EQUAL( addr.address(), INet6Address::from_string("12::21") ); BOOST_CHECK_EQUAL( addr.port(), 12345u ); BOOST_CHECK_EQUAL( addr.iface(), "" ); BOOST_CHECK_EQUAL( addr, INet6SocketAddress("[12::21]:12345") ); - BOOST_CHECK_NO_THROW( INet6SocketAddress("www.6bone.net:80") ); - addr = senf::INet6SocketAddress("1.2.3.4:12345", INet6Address::ResolveINet4); + SENF_CHECK_NO_THROW( INet6SocketAddress("www.6bone.net:80") ); + addr = INet6SocketAddress("1.2.3.4:12345", INet6Address::ResolveINet4); 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")); } { INet6SocketAddress addr (INet6Address::from_string("::1"), 1); - BOOST_CHECK_EQUAL( addr,senf::INet6SocketAddress("[::1]:1") ); + BOOST_CHECK_EQUAL( addr, INet6SocketAddress("[::1]:1") ); BOOST_CHECK_EQUAL( addr.iface(), "" ); } { INet6SocketAddress addr (INet6Address::Loopback, 1, "lo"); - BOOST_CHECK_EQUAL( addr, senf::INet6SocketAddress("[::1%lo]:1") ); + BOOST_CHECK_EQUAL( addr, INet6SocketAddress("[::1%lo]:1") ); BOOST_CHECK_EQUAL( addr.iface(), "lo" ); addr.iface(""); BOOST_CHECK_EQUAL( addr.iface(), "" ); @@ -122,12 +141,10 @@ BOOST_AUTO_UNIT_TEST(inet6SocketAddress) BOOST_CHECK_EQUAL( addr.port(), 100u ); addr.address(INet6Address::from_string("::2")); BOOST_CHECK_EQUAL( addr.address(), INet6Address::from_string("::2") ); - BOOST_CHECK_THROW( senf::INet6SocketAddress(""), AddressSyntaxException ); - BOOST_CHECK_THROW( senf::INet6SocketAddress("[::1]"), - AddressSyntaxException ); - BOOST_CHECK_THROW( senf::INet6SocketAddress("[::1]1234"), - AddressSyntaxException ); - addr = senf::INet6SocketAddress("[12::21%lo]:12345"); + BOOST_CHECK_THROW( INet6SocketAddress(""), AddressSyntaxException ); + 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(addr), "[12::21%lo]:12345" ); BOOST_CHECK_EQUAL( addr.address(), INet6Address::from_string("12::21") ); BOOST_CHECK_EQUAL( addr.port(), 12345u ); @@ -139,7 +156,7 @@ BOOST_AUTO_UNIT_TEST(inet6SocketAddress) ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ - + // Local Variables: // mode: c++ // fill-column: 100 diff --git a/Socket/Protocols/INet/RawINetSocketHandle.test.cc b/Socket/Protocols/INet/RawINetSocketHandle.test.cc index 696ec6d..d8949e3 100644 --- a/Socket/Protocols/INet/RawINetSocketHandle.test.cc +++ b/Socket/Protocols/INet/RawINetSocketHandle.test.cc @@ -148,15 +148,15 @@ BOOST_AUTO_UNIT_TEST(RawV4ClientSocketHandle) alarm(10); start(server_v4); senf::RawV4ClientSocketHandle sock(47); //IPPROTO_GRE - BOOST_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) ); + SENF_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) ); BOOST_CHECK_EQUAL( sock.protocol().rcvbuf(), 2048u ); - BOOST_CHECK_NO_THROW( sock.protocol().sndbuf(2048) ); + SENF_CHECK_NO_THROW( sock.protocol().sndbuf(2048) ); BOOST_CHECK_EQUAL( sock.protocol().sndbuf(), 2048u ); - BOOST_CHECK_NO_THROW( sock.writeto(senf::INet4SocketAddress("127.0.0.1:0"), test) ); + SENF_CHECK_NO_THROW( sock.writeto(senf::INet4SocketAddress("127.0.0.1:0"), test) ); senf::RawV4ClientSocketHandle sockrec(48); //IPPROTO_GRE+1 std::string in = sockrec.read(); BOOST_CHECK_EQUAL(in.substr(20), test); - BOOST_CHECK_NO_THROW( sock.writeto(senf::INet4SocketAddress("127.0.0.1:0"),"QUIT")); + SENF_CHECK_NO_THROW( sock.writeto(senf::INet4SocketAddress("127.0.0.1:0"),"QUIT")); //sock.close(); //sockrec.close(); alarm(0); @@ -178,15 +178,15 @@ BOOST_AUTO_UNIT_TEST(RawV6ClientSocketHandle) start(server_v6); sleep(1); senf::RawV6ClientSocketHandle sock(47); //IPPROTO_GRE - BOOST_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) ); + SENF_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) ); BOOST_CHECK_EQUAL( sock.protocol().rcvbuf(), 2048u ); - BOOST_CHECK_NO_THROW( sock.protocol().sndbuf(2048) ); + SENF_CHECK_NO_THROW( sock.protocol().sndbuf(2048) ); BOOST_CHECK_EQUAL( sock.protocol().sndbuf(), 2048u ); - BOOST_CHECK_NO_THROW( sock.writeto(senf::INet6SocketAddress("[::1]:0"), test) ); + SENF_CHECK_NO_THROW( sock.writeto(senf::INet6SocketAddress("[::1]:0"), test) ); senf::RawV6ClientSocketHandle sockrec(48); //IPPROTO_GRE+1 std::string in = sockrec.read(); BOOST_CHECK_EQUAL(in, test); - BOOST_CHECK_NO_THROW( sock.writeto(senf::INet6SocketAddress("[::1]:0"),"QUIT")); + SENF_CHECK_NO_THROW( sock.writeto(senf::INet6SocketAddress("[::1]:0"),"QUIT")); alarm(0); } catch (...) { alarm(0); diff --git a/Socket/Protocols/INet/TCPSocketHandle.test.cc b/Socket/Protocols/INet/TCPSocketHandle.test.cc index 70d599e..b4e8e61 100644 --- a/Socket/Protocols/INet/TCPSocketHandle.test.cc +++ b/Socket/Protocols/INet/TCPSocketHandle.test.cc @@ -167,16 +167,16 @@ BOOST_AUTO_UNIT_TEST(tcpv4ClientSocketHandle) alarm(10); start(server_v4); senf::TCPv4ClientSocketHandle sock; - BOOST_CHECK_NO_THROW( sock.bind(senf::INet4SocketAddress("127.0.0.1:23456")) ); - BOOST_CHECK_NO_THROW( sock.connect(senf::INet4SocketAddress("127.0.0.1:12345")) ); + SENF_CHECK_NO_THROW( sock.bind(senf::INet4SocketAddress("127.0.0.1:23456")) ); + SENF_CHECK_NO_THROW( sock.connect(senf::INet4SocketAddress("127.0.0.1:12345")) ); BOOST_CHECK( sock.peer() == senf::INet4SocketAddress("127.0.0.1:12345") ); BOOST_CHECK( sock.local() == senf::INet4SocketAddress("127.0.0.1:23456") ); BOOST_CHECK( sock.blocking() ); - BOOST_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) ); + SENF_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) ); BOOST_CHECK_EQUAL( sock.protocol().rcvbuf(), 2048u ); - BOOST_CHECK_NO_THROW( sock.protocol().sndbuf(2048) ); + SENF_CHECK_NO_THROW( sock.protocol().sndbuf(2048) ); BOOST_CHECK_EQUAL( sock.protocol().sndbuf(), 2048u ); - BOOST_CHECK_NO_THROW( sock.write(std::string("TEST-WRITE")) ); + SENF_CHECK_NO_THROW( sock.write(std::string("TEST-WRITE")) ); BOOST_CHECK_EQUAL( sock.read(), std::string("TEST-WRITE") ); BOOST_CHECK( !sock.eof() ); sock.write(std::string("QUIT")); @@ -202,25 +202,25 @@ BOOST_AUTO_UNIT_TEST(tcpv4ClientSocketHandle) // are at least not sensible ... // I'll have to move those to a UDPSocket test ... they should // realy only be in the UDP Protocol implementation -// BOOST_CHECK_NO_THROW( sock.protocol().mcTTL() ); +// SENF_CHECK_NO_THROW( sock.protocol().mcTTL() ); // BOOST_CHECK_THROW( sock.protocol().mcTTL(1), senf::SystemException ); -// BOOST_CHECK_NO_THROW( sock.protocol().mcLoop() ); -// BOOST_CHECK_NO_THROW( sock.protocol().mcLoop(false) ); -// BOOST_CHECK_NO_THROW( sock.protocol().mcAddMembership("224.0.0.1:0") ); -// BOOST_CHECK_NO_THROW( sock.protocol().mcAddMembership("224.0.0.1:0","127.0.0.1:0") ); -// BOOST_CHECK_NO_THROW( sock.protocol().mcDropMembership("224.0.0.1:0","127.0.0.1:0") ); -// BOOST_CHECK_NO_THROW( sock.protocol().mcDropMembership("224.0.0.1:0") ); +// SENF_CHECK_NO_THROW( sock.protocol().mcLoop() ); +// SENF_CHECK_NO_THROW( sock.protocol().mcLoop(false) ); +// SENF_CHECK_NO_THROW( sock.protocol().mcAddMembership("224.0.0.1:0") ); +// SENF_CHECK_NO_THROW( sock.protocol().mcAddMembership("224.0.0.1:0","127.0.0.1:0") ); +// SENF_CHECK_NO_THROW( sock.protocol().mcDropMembership("224.0.0.1:0","127.0.0.1:0") ); +// SENF_CHECK_NO_THROW( sock.protocol().mcDropMembership("224.0.0.1:0") ); // BOOST_CHECK_THROW( sock.protocol().mcIface("lo"), senf::SystemException ); // The following setsockopts are hard to REALLY test ... - BOOST_CHECK_NO_THROW( sock.protocol().nodelay(true) ); + SENF_CHECK_NO_THROW( sock.protocol().nodelay(true) ); BOOST_CHECK( sock.protocol().nodelay() ); BOOST_CHECK_EQUAL( sock.protocol().siocinq(), 0u ); BOOST_CHECK_EQUAL( sock.protocol().siocoutq(), 0u ); - BOOST_CHECK_NO_THROW( sock.protocol().reuseaddr(true) ); + SENF_CHECK_NO_THROW( sock.protocol().reuseaddr(true) ); BOOST_CHECK( sock.protocol().reuseaddr() ); - BOOST_CHECK_NO_THROW( sock.protocol().linger(true,0) ); + SENF_CHECK_NO_THROW( sock.protocol().linger(true,0) ); BOOST_CHECK( sock.protocol().linger() == std::make_pair(true, 0u) ); } } @@ -238,19 +238,19 @@ BOOST_AUTO_UNIT_TEST(tcpv6ClientSocketHandle) alarm(10); start(server_v6); senf::TCPv6ClientSocketHandle sock; - BOOST_CHECK_NO_THROW( sock.bind(senf::INet6SocketAddress("[::1]:23456")) ); - BOOST_CHECK_NO_THROW( sock.connect(senf::INet6SocketAddress("[::1]:12345")) ); + SENF_CHECK_NO_THROW( sock.bind(senf::INet6SocketAddress("[::1]:23456")) ); + SENF_CHECK_NO_THROW( sock.connect(senf::INet6SocketAddress("[::1]:12345")) ); BOOST_CHECK( sock.peer() == senf::INet6SocketAddress("[::1]:12345") ); BOOST_CHECK( sock.local() == senf::INet6SocketAddress("[::1]:23456") ); BOOST_CHECK( sock.blocking() ); - BOOST_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) ); + SENF_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) ); BOOST_CHECK_EQUAL( sock.protocol().rcvbuf(), 2048u ); - BOOST_CHECK_NO_THROW( sock.protocol().sndbuf(2048) ); + SENF_CHECK_NO_THROW( sock.protocol().sndbuf(2048) ); BOOST_CHECK_EQUAL( sock.protocol().sndbuf(), 2048u ); - BOOST_CHECK_NO_THROW( sock.write(std::string("TEST-WRITE")) ); + SENF_CHECK_NO_THROW( sock.write(std::string("TEST-WRITE")) ); BOOST_CHECK_EQUAL( sock.read(), std::string("TEST-WRITE") ); // this fails with ENOFILE ... why ???? - // BOOST_CHECK_NO_THROW( sock.protocol().timestamp() ); + // SENF_CHECK_NO_THROW( sock.protocol().timestamp() ); BOOST_CHECK( !sock.eof() ); sock.write(std::string("QUIT")); sleep(1); @@ -272,14 +272,14 @@ BOOST_AUTO_UNIT_TEST(tcpv6ClientSocketHandle) senf::TCPv6ClientSocketHandle sock; // The following setsockopts are hard to REALLY test ... - BOOST_CHECK_NO_THROW( sock.protocol().nodelay(true) ); + SENF_CHECK_NO_THROW( sock.protocol().nodelay(true) ); BOOST_CHECK( sock.protocol().nodelay() ); BOOST_CHECK_EQUAL( sock.protocol().siocinq(), 0u ); BOOST_CHECK_EQUAL( sock.protocol().siocoutq(), 0u ); - BOOST_CHECK_NO_THROW( sock.protocol().reuseaddr(true) ); + SENF_CHECK_NO_THROW( sock.protocol().reuseaddr(true) ); BOOST_CHECK( sock.protocol().reuseaddr() ); - BOOST_CHECK_NO_THROW( sock.protocol().linger(true,0) ); + SENF_CHECK_NO_THROW( sock.protocol().linger(true,0) ); BOOST_CHECK( sock.protocol().linger() == std::make_pair(true, 0u) ); } } @@ -349,7 +349,7 @@ BOOST_AUTO_UNIT_TEST(tcpv4ServerSocketHandle) BOOST_CHECKPOINT("Accepting connection"); senf::TCPv4ClientSocketHandle client = server.accept(); - BOOST_CHECK_NO_THROW(client.write(std::string("QUIT"))); + SENF_CHECK_NO_THROW(client.write(std::string("QUIT"))); BOOST_CHECKPOINT("Stopping client"); sleep(1); @@ -375,7 +375,7 @@ BOOST_AUTO_UNIT_TEST(tcpv6ServerSocketHandle) BOOST_CHECKPOINT("Accepting connection"); senf::TCPv6ClientSocketHandle client = server.accept(); - BOOST_CHECK_NO_THROW(client.write(std::string("QUIT"))); + SENF_CHECK_NO_THROW(client.write(std::string("QUIT"))); BOOST_CHECKPOINT("Stopping client"); sleep(1); diff --git a/Socket/Protocols/INet/UDPSocketHandle.test.cc b/Socket/Protocols/INet/UDPSocketHandle.test.cc index 44c51ec..ac4c7df 100644 --- a/Socket/Protocols/INet/UDPSocketHandle.test.cc +++ b/Socket/Protocols/INet/UDPSocketHandle.test.cc @@ -146,16 +146,16 @@ BOOST_AUTO_UNIT_TEST(udpv4ClientSocketHandle) alarm(10); start(server_v4); senf::UDPv4ClientSocketHandle sock; - BOOST_CHECK_NO_THROW( sock.bind(senf::INet4SocketAddress("127.0.0.1:23456")) ); + SENF_CHECK_NO_THROW( sock.bind(senf::INet4SocketAddress("127.0.0.1:23456")) ); BOOST_CHECK( sock.local() == senf::INet4SocketAddress("127.0.0.1:23456") ); - BOOST_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) ); + SENF_CHECK_NO_THROW( sock.protocol().rcvbuf(2048) ); BOOST_CHECK_EQUAL( sock.protocol().rcvbuf(), 2048u ); - BOOST_CHECK_NO_THROW( sock.protocol().sndbuf(2048) ); + SENF_CHECK_NO_THROW( sock.protocol().sndbuf(2048) ); BOOST_CHECK_EQUAL( sock.protocol().sndbuf(), 2048u ); - BOOST_CHECK_NO_THROW( sock.writeto(senf::INet4SocketAddress("127.0.0.1:12345"), + SENF_CHECK_NO_THROW( sock.writeto(senf::INet4SocketAddress("127.0.0.1:12345"), std::string("TEST-WRITE")) ); BOOST_CHECK_EQUAL( sock.read(), "TEST-WRITE" ); - BOOST_CHECK_NO_THROW( sock.protocol().timestamp() ); + SENF_CHECK_NO_THROW( sock.protocol().timestamp() ); sock.writeto(senf::INet4SocketAddress("127.0.0.1:12345"), std::string("QUIT")); sleep(1); stop(); diff --git a/Socket/Protocols/Raw/MACAddress.test.cc b/Socket/Protocols/Raw/MACAddress.test.cc index 0550c1a..b2c33b7 100644 --- a/Socket/Protocols/Raw/MACAddress.test.cc +++ b/Socket/Protocols/Raw/MACAddress.test.cc @@ -41,7 +41,7 @@ BOOST_AUTO_UNIT_TEST(macAddress) { using senf::MACAddress; using senf::AddressSyntaxException; - + std::string test ("A1-b2-C3:d4:E5:f6"); MACAddress mac (MACAddress::from_string(test)); @@ -53,12 +53,15 @@ BOOST_AUTO_UNIT_TEST(macAddress) 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()); BOOST_CHECK_EQUAL(mac, MACAddress::from_string(test)); - + BOOST_CHECK( ! mac.local() ); BOOST_CHECK( mac.multicast() ); BOOST_CHECK( ! mac.broadcast() ); @@ -86,14 +89,14 @@ BOOST_AUTO_UNIT_TEST(macAddress) BOOST_CHECK_EQUAL( mac, MACAddress::from_eui64(0xa1b2c3fffed4e5f6llu) ); BOOST_CHECK_THROW( MACAddress::from_eui64(0u), AddressSyntaxException ); - + BOOST_CHECK_EQUAL( MACAddress(0x1a2b3c4d5e6fULL).uint64(), 0x1a2b3c4d5e6fULL); } ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ - + // Local Variables: // mode: c++ // fill-column: 100 diff --git a/Socket/Protocols/Raw/PacketSocketHandle.test.cc b/Socket/Protocols/Raw/PacketSocketHandle.test.cc index 99941e6..e3ab322 100644 --- a/Socket/Protocols/Raw/PacketSocketHandle.test.cc +++ b/Socket/Protocols/Raw/PacketSocketHandle.test.cc @@ -48,19 +48,19 @@ BOOST_AUTO_UNIT_TEST(packetSocketHandle) { senf::PacketSocketHandle sock; - BOOST_CHECK_NO_THROW( sock.bind(senf::LLSocketAddress("eth0")) ); + SENF_CHECK_NO_THROW( sock.bind(senf::LLSocketAddress("eth0")) ); senf::LLSocketAddress a; - BOOST_CHECK_NO_THROW( sock.local(a) ); + SENF_CHECK_NO_THROW( sock.local(a) ); BOOST_CHECK_EQUAL( a.interface(), "eth0" ); // How am I supposed to test read and write .. grmpf .. - BOOST_CHECK_NO_THROW( sock.protocol().mcAdd( + SENF_CHECK_NO_THROW( sock.protocol().mcAdd( "eth0",senf::MACAddress::from_string("01-02-03-04-05-06")) ); - BOOST_CHECK_NO_THROW( sock.protocol().mcDrop( + SENF_CHECK_NO_THROW( sock.protocol().mcDrop( "eth0",senf::MACAddress::from_string("01-02-03-04-05-06")) ); - BOOST_CHECK_NO_THROW( sock.protocol().available() ); + SENF_CHECK_NO_THROW( sock.protocol().available() ); BOOST_CHECK( ! sock.eof() ); } } diff --git a/Socket/Protocols/Raw/TunTapSocketHandle.test.cc b/Socket/Protocols/Raw/TunTapSocketHandle.test.cc index 45d7154..4613922 100644 --- a/Socket/Protocols/Raw/TunTapSocketHandle.test.cc +++ b/Socket/Protocols/Raw/TunTapSocketHandle.test.cc @@ -51,7 +51,7 @@ BOOST_AUTO_UNIT_TEST(tapSocketHandle) BOOST_CHECK_EQUAL( WEXITSTATUS(ret), 0); senf::PacketSocketHandle sock; - BOOST_CHECK_NO_THROW( sock.bind(senf::LLSocketAddress("tap_unittest")) ); + SENF_CHECK_NO_THROW( sock.bind(senf::LLSocketAddress("tap_unittest")) ); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Socket/ServerSocketHandle.test.cc b/Socket/ServerSocketHandle.test.cc index 18f9967..3eb0a62 100644 --- a/Socket/ServerSocketHandle.test.cc +++ b/Socket/ServerSocketHandle.test.cc @@ -74,13 +74,13 @@ BOOST_AUTO_UNIT_TEST(serverSocketHandle) >::policy> SomeOtherSocketHandle; typedef senf::ClientSocketHandle OtherClientHandle; - BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast(osh) ); + SENF_CHECK_NO_THROW( senf::dynamic_socket_cast(osh) ); BOOST_CHECK_THROW( senf::dynamic_socket_cast(osh), std::bad_cast ); BOOST_CHECK_THROW( senf::dynamic_socket_cast(osh), std::bad_cast ); - BOOST_CHECK_NO_THROW( myh.bind(0) ); + SENF_CHECK_NO_THROW( myh.bind(0) ); BOOST_CHECK_EQUAL( myh.local(), 2u ); { diff --git a/Socket/SocketHandle.test.cc b/Socket/SocketHandle.test.cc index c8071f3..bb3835d 100644 --- a/Socket/SocketHandle.test.cc +++ b/Socket/SocketHandle.test.cc @@ -80,8 +80,8 @@ BOOST_AUTO_UNIT_TEST(socketHandle) typedef senf::SocketHandle SomeSocketHandle; SomeSocketHandle ssh = senf::static_socket_cast(osh); - BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast(osh) ); - BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast(osh) ); + SENF_CHECK_NO_THROW( senf::dynamic_socket_cast(osh) ); + SENF_CHECK_NO_THROW( senf::dynamic_socket_cast(osh) ); typedef senf::SocketHandle< senf::MakeSocketPolicy< OtherSocketPolicy, @@ -102,7 +102,7 @@ BOOST_AUTO_UNIT_TEST(socketHandle) "socket.protocol.policy: senf::SocketPolicy\n" "socket.server: false\n" ); - BOOST_CHECK_NO_THROW( myh.facet() ); + SENF_CHECK_NO_THROW( myh.facet() ); } // Ensure, the destructor is called and calls the correct close() implementation diff --git a/Socket/SocketPolicy.test.cc b/Socket/SocketPolicy.test.cc index 7063ccc..72ba433 100644 --- a/Socket/SocketPolicy.test.cc +++ b/Socket/SocketPolicy.test.cc @@ -132,7 +132,7 @@ BOOST_AUTO_UNIT_TEST(socketPolicy) Policy3 p3; BOOST_CHECK_THROW( Policy1::checkBaseOf(p3), std::bad_cast ); - BOOST_CHECK_NO_THROW( Policy3::checkBaseOf(p1) ); + SENF_CHECK_NO_THROW( Policy3::checkBaseOf(p1) ); } } diff --git a/Utils/Console/OverloadedCommand.test.cc b/Utils/Console/OverloadedCommand.test.cc index 67d22de..5372055 100644 --- a/Utils/Console/OverloadedCommand.test.cc +++ b/Utils/Console/OverloadedCommand.test.cc @@ -71,7 +71,7 @@ BOOST_AUTO_UNIT_TEST(overladedCommand) senf::console::SyntaxErrorException ); cmd.add(senf::console::SimpleCommandOverload::create(&fn3)).doc("fn3"); - BOOST_CHECK_NO_THROW( senf::console::root()("overload")(ss, info) ); + SENF_CHECK_NO_THROW( senf::console::root()("overload")(ss, info) ); BOOST_CHECK_EQUAL( ss.str(), "fn3\n" ); } diff --git a/Utils/Console/Parse.test.cc b/Utils/Console/Parse.test.cc index 7b9e7be..7f85ac7 100644 --- a/Utils/Console/Parse.test.cc +++ b/Utils/Console/Parse.test.cc @@ -200,7 +200,7 @@ BOOST_AUTO_UNIT_TEST(commandParser) " 0304\";" "ls /foo/bar; "; - BOOST_CHECK_NO_THROW( parser.parse(text, &setInfo) ); + SENF_CHECK_NO_THROW( parser.parse(text, &setInfo) ); BOOST_CHECK_EQUAL( commands.size(), 2u ); { @@ -274,14 +274,14 @@ BOOST_AUTO_UNIT_TEST(checkedArgumentIterator) { senf::console::CommandParser parser; - BOOST_CHECK_NO_THROW( parser.parse("foo a", &setInfo) ); + SENF_CHECK_NO_THROW( parser.parse("foo a", &setInfo) ); BOOST_CHECK_THROW( parseArgs(commands.back().arguments()), senf::console::SyntaxErrorException ); - BOOST_CHECK_NO_THROW( parser.parse("foo a b", &setInfo) ); - BOOST_CHECK_NO_THROW( parseArgs(commands.back().arguments()) ); + SENF_CHECK_NO_THROW( parser.parse("foo a b", &setInfo) ); + SENF_CHECK_NO_THROW( parseArgs(commands.back().arguments()) ); - BOOST_CHECK_NO_THROW( parser.parse("foo a b c", &setInfo) ); + SENF_CHECK_NO_THROW( parser.parse("foo a b c", &setInfo) ); BOOST_CHECK_THROW( parseArgs(commands.back().arguments()), senf::console::SyntaxErrorException ); diff --git a/Utils/Console/ParsedCommand.test.cc b/Utils/Console/ParsedCommand.test.cc index 42a5097..efce1ef 100644 --- a/Utils/Console/ParsedCommand.test.cc +++ b/Utils/Console/ParsedCommand.test.cc @@ -132,7 +132,7 @@ BOOST_AUTO_UNIT_TEST(parsedCommand) // Just for the fun of it, use a functor and not a function pointer as parser ... dir.add("cb6", &cb5) .arg( kw::parser = TestParser() ); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/cb6 false", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "Value: true\n" ); @@ -145,7 +145,7 @@ BOOST_AUTO_UNIT_TEST(parsedCommand) // compatible types also work dir.add("cb7", boost::function(&cb2)) .formatter( &testFormatter ); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/cb7", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "formatter\n" ); @@ -187,16 +187,16 @@ BOOST_AUTO_UNIT_TEST(parsedCommand) (void) cbNode; - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/cb 111 222.4", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/cb 222", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/cb foo", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/cb", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); diff --git a/Utils/Console/STLSupport.test.cc b/Utils/Console/STLSupport.test.cc index 8b3dcf0..a4e0cf3 100644 --- a/Utils/Console/STLSupport.test.cc +++ b/Utils/Console/STLSupport.test.cc @@ -72,13 +72,13 @@ BOOST_AUTO_UNIT_TEST(vectorSupport) .arg("data", "test data", senf::console::kw::default_value = defv); std::stringstream ss; - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/test; test/test (); test/test 5; test/test (13); test/test (4 5 8)", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "9\n" "0\n" "5\n" "13\n" "17\n" ); ss.str(""); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("help test/test", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( @@ -103,13 +103,13 @@ BOOST_AUTO_UNIT_TEST(listSupport) .arg("data", "test data", senf::console::kw::default_value = defv); std::stringstream ss; - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/test; test/test (); test/test 5; test/test (13); test/test (4 5 8)", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "9\n" "0\n" "5\n" "13\n" "17\n" ); ss.str(""); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("help test/test", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( diff --git a/Utils/Console/Traits.test.cc b/Utils/Console/Traits.test.cc index b8d366b..054f993 100644 --- a/Utils/Console/Traits.test.cc +++ b/Utils/Console/Traits.test.cc @@ -64,32 +64,32 @@ BOOST_AUTO_UNIT_TEST(boolTraits) dir.add("test", &boolTest); std::stringstream ss; - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/test true; test/test false", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "true\n" "false\n" ); ss.str(""); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/test enabled; test/test disabled", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "true\n" "false\n" ); ss.str(""); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/test yes; test/test no", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "true\n" "false\n" ); ss.str(""); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/test Y; test/test enA", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "true\n" "true\n" ); dir.add("test2", &boolTest).formatter( senf::console::formatEnabledDisabled ); ss.str(""); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/test2 0; test/test2 -1", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "disabled\n" "enabled\n" ); @@ -105,13 +105,13 @@ BOOST_AUTO_UNIT_TEST(enumSupport) dir.add("test",&test); std::stringstream ss; - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/test Foo", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "Foo\n" ); ss.str(""); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/test Bar", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "Bar\n" ); @@ -129,13 +129,13 @@ BOOST_AUTO_UNIT_TEST(enumSupport) dir.add("member", &TestClass::test); ss.str(""); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/member MemberFoo", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "MemberFoo\n" ); ss.str(""); - BOOST_CHECK_NO_THROW( + SENF_CHECK_NO_THROW( parser.parse("test/member MemberBar", boost::bind( boost::ref(executor), boost::ref(ss), _1 )) ); BOOST_CHECK_EQUAL( ss.str(), "MemberBar\n" ); diff --git a/Utils/Daemon/Daemon.test.cc b/Utils/Daemon/Daemon.test.cc index c814ffd..8031988 100644 --- a/Utils/Daemon/Daemon.test.cc +++ b/Utils/Daemon/Daemon.test.cc @@ -151,8 +151,8 @@ BOOST_AUTO_UNIT_TEST(testDaemon) std::stringstream data; data << log.rdbuf(); BOOST_CHECK_EQUAL( data.str(), "Running init()\n(stderr)\nRunning run()\n" ); - BOOST_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log") ); - BOOST_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log.1") ); + SENF_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log") ); + SENF_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log.1") ); } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Utils/Logger/FileTarget.test.cc b/Utils/Logger/FileTarget.test.cc new file mode 100644 index 0000000..8594699 --- /dev/null +++ b/Utils/Logger/FileTarget.test.cc @@ -0,0 +1,88 @@ +// $Id$ +// +// Copyright (C) 2009 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Thorsten Horstmann +// +// 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. +// +// 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. +// +// 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. + +/** \file + \brief FileTarget unit tests */ + +//#include "FileTarget.test.hh" +//#include "FileTarget.test.ih" + +// Custom includes +#include +#include +#include "FileTarget.hh" +#include "Logger.hh" + +#include "../Utils/auto_unit_test.hh" +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// + +BOOST_AUTO_UNIT_TEST(fileTarget) +{ + std::string filename ("/tmp/senf_fileTarget_test.log"); + senf::log::FileTarget target (filename); + + target.tag(""); + target.showTime(false); + target.showLevel(false); + target.route(); + + std::string message ("Test message"); + SENF_LOG((message)); + + BOOST_REQUIRE( boost::filesystem::exists(filename)); + std::ifstream inFile; + inFile.open(filename.c_str()); + BOOST_REQUIRE( inFile); + + char buffer[256]; + inFile.getline(buffer, 256); + inFile.close(); + BOOST_CHECK_EQUAL( std::string(buffer), message); + + SENF_CHECK_NO_THROW( boost::filesystem::remove(filename) ); + + target.reopen(); + BOOST_REQUIRE( boost::filesystem::exists(filename)); + SENF_CHECK_NO_THROW( boost::filesystem::remove(filename) ); + + filename = std::string("/tmp/senf_fileTarget_test2.log"); + target.reopen( filename); + BOOST_REQUIRE( boost::filesystem::exists(filename)); + SENF_CHECK_NO_THROW( boost::filesystem::remove(filename) ); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: