X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPPI%2FSocketSource.test.cc;h=459a9a58d171c1a320c912f2d68225ee054a76e4;hb=73c33f663ff0f65e4656ea5a5f6f07a43a2e1722;hp=4bf23ef9a2a6c592804c64e45ce41ddc64aea852;hpb=26610f603ebdd465307b9621f532c1fe19fd5571;p=senf.git diff --git a/senf/PPI/SocketSource.test.cc b/senf/PPI/SocketSource.test.cc index 4bf23ef..459a9a5 100644 --- a/senf/PPI/SocketSource.test.cc +++ b/senf/PPI/SocketSource.test.cc @@ -47,12 +47,31 @@ namespace { void timeout() { senf::scheduler::terminate(); } + + int base_pid = 0; + + unsigned port(unsigned i) + { + if (! base_pid) + base_pid = ::getpid(); + return 23456u + (((base_pid^(base_pid>>8)^(base_pid>>16)^(base_pid>>24))&0xff)<<2) + i; + } + + std::string localhost4str(unsigned i) + { + return (boost::format("localhost:%d") % port(i)).str(); + } + + std::string localhost6str(unsigned i) + { + return (boost::format("[::1]:%d") % port(i)).str(); + } } -BOOST_AUTO_UNIT_TEST(socketSource) +SENF_AUTO_UNIT_TEST(socketSource) { senf::UDPv4ClientSocketHandle inputSocket; - inputSocket.bind(senf::INet4SocketAddress("localhost:44344")); + inputSocket.bind(senf::INet4SocketAddress(localhost4str(0))); inputSocket.blocking(false); module::ActiveSocketSource<> udpSource(inputSocket); debug::PassiveSink sink; @@ -61,7 +80,7 @@ BOOST_AUTO_UNIT_TEST(socketSource) std::string data ("TEST"); senf::UDPv4ClientSocketHandle outputSocket; - outputSocket.writeto(senf::INet4SocketAddress("localhost:44344"),data); + outputSocket.writeto(senf::INet4SocketAddress(localhost4str(0)),data); senf::scheduler::TimerEvent timer ( "socketSource test timer", &timeout, senf::ClockService::now() + senf::ClockService::milliseconds(100)); @@ -69,7 +88,7 @@ BOOST_AUTO_UNIT_TEST(socketSource) BOOST_REQUIRE( ! sink.empty() ); BOOST_CHECK_EQUAL( sink.front().data().size(), data.size() ); - BOOST_CHECK( std::equal( sink.front().data().begin(), sink.front().data().end(), + BOOST_CHECK( std::equal( sink.front().data().begin(), sink.front().data().end(), data.begin()) ); }