diff --git a/test/testsock.cpp b/test/testsock.cpp index 3f9b0ec..2b67015 100644 --- a/test/testsock.cpp +++ b/test/testsock.cpp @@ -34,6 +34,64 @@ using namespace pvxs; # endif #endif +void testEndPoint() +{ + testDiag("Enter %s", __func__); + + { + SockEndpoint ep("127.0.0.1"); + testEq(ep.addr.tostring(), "127.0.0.1"); + testEq(ep.iface, ""); + testEq(ep.ttl, -1); + } + { + SockEndpoint ep("127.0.0.1:12"); + testEq(ep.addr.tostring(), "127.0.0.1:12"); + testEq(ep.iface, ""); + testEq(ep.ttl, -1); + } + { + SockEndpoint ep("127.0.0.1,1"); + testEq(ep.addr.tostring(), "127.0.0.1"); + testEq(ep.iface, ""); + testEq(ep.ttl, 1); + } + { + SockEndpoint ep("127.0.0.1@ifname"); + testEq(ep.addr.tostring(), "127.0.0.1"); + testEq(ep.iface, "ifname"); + testEq(ep.ttl, -1); + } + { + SockEndpoint ep("127.0.0.1,1@ifname"); + testEq(ep.addr.tostring(), "127.0.0.1"); + testEq(ep.iface, "ifname"); + testEq(ep.ttl, 1); + } + { + SockEndpoint ep("127.0.0.1:12,1@ifname"); + testEq(ep.addr.tostring(), "127.0.0.1:12"); + testEq(ep.iface, "ifname"); + testEq(ep.ttl, 1); + } + + std::vector bad({ + "127.0.0.", + "127.0.0.1:foo", + "127.0.0.1:", + "127.0.0.1:12,foo", + //"127.0.0.1:12@", // should fail... + "127.0.0.1:12,@", + "127.0,0.1,1@ifname", + }); + for(const auto& inp : bad) { + testThrows([&inp](){ + SockEndpoint x(inp); + (void)x; + })<<" "<