Skip to content

Commit 6e9da24

Browse files
committed
Wrong handling of unsupported protocol, added a test for it.
1 parent 89362bc commit 6e9da24

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/main/java/zmq/SocketBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private NetProtocol checkProtocol(String protocol)
213213
NetProtocol proto = NetProtocol.getProtocol(protocol);
214214
if (!proto.isValid()) {
215215
errno.set(ZError.EPROTONOSUPPORT);
216-
return proto;
216+
return null;
217217
}
218218

219219
// Check whether socket type and transport protocol match.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package zmq;
2+
3+
import java.util.List;
4+
import java.util.function.Predicate;
5+
6+
import org.junit.After;
7+
import org.junit.Test;
8+
9+
import static org.hamcrest.CoreMatchers.is;
10+
import static org.hamcrest.MatcherAssert.assertThat;
11+
12+
public class TestUnsupported
13+
{
14+
Ctx ctx = ZMQ.init(1);
15+
16+
@After
17+
public void close()
18+
{
19+
ctx.terminate();
20+
}
21+
22+
private void doOperation(Predicate<SocketBase> networkOperation)
23+
{
24+
SocketBase socket = ZMQ.socket(ctx, ZMQ.ZMQ_SERVER);
25+
try {
26+
boolean rc = networkOperation.test(socket);
27+
assertThat(rc, is(false));
28+
assertThat(socket.errno.get(), is(ZError.EPROTONOSUPPORT));
29+
}
30+
finally {
31+
socket.close();
32+
}
33+
}
34+
35+
@Test(timeout = 100)
36+
public void doTests()
37+
{
38+
for (String proto : List.of("pgm", "epgm", "norm", "ws", "wss", "tipc", "vmci")) {
39+
doOperation(s -> s.connect(proto + "://localhost:*"));
40+
doOperation(s -> s.bind(proto + "://localhost:*"));
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)