Skip to content

Commit

Permalink
test SockEndpoint parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavidsaver committed Aug 3, 2023
1 parent a2edecd commit a2d2721
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion test/testsock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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<std::runtime_error>([&inp](){
SockEndpoint x(inp);
(void)x;
})<<" "<<inp;
}
}

bool waitReadable(const evsocket& sock, double timeout=5.0)
{
pollfd pfd{};
Expand Down Expand Up @@ -436,8 +494,9 @@ MAIN(testsock)
{
SockAttach attach;
logger_config_env();
testPlan(68);
testPlan(92);
testSetup();
testEndPoint();
// check for behavior when binding ipv4 and ipv6 to the same socket
// as a function of socket type and order.
if(evsocket::canIPv6) {
Expand Down

0 comments on commit a2d2721

Please sign in to comment.