Skip to content

Commit

Permalink
Fix ipv4 tests for non-Arch Linux
Browse files Browse the repository at this point in the history
See #4
  • Loading branch information
headius committed Sep 10, 2020
1 parent 57465f7 commit 615c4b8
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 24 deletions.
31 changes: 23 additions & 8 deletions src/test/java/jnr/netdb/FileProtocolDBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,32 @@ public void tearDown() {

@Test public void canLookupIpProtocolByName() {
ProtocolsDB db = FileProtocolsDB.getInstance();
Protocol p = db.getProtocolByName("ipv4");
assertNotNull("could not lookup ipv4 protocol", p);
assertEquals("incorrect proto number", 4, p.getProto());
assertEquals("incorrect name", "ipv4", p.getName());
// we try ip first and then ipv4 due to jnr/jnr-netdb#4
Protocol p = Protocol.getProtocolByName("ip");
if (p != null) {
assertEquals("incorrect proto number", 0, p.getProto());
assertEquals("incorrect name", "ip", p.getName());
} else {
p = Protocol.getProtocolByName("ipv4");
assertNotNull("could not lookup ipv4 protocol", p);
assertEquals("incorrect proto number", 4, p.getProto());
assertEquals("incorrect name", "ipv4", p.getName());
}
}

@Test public void canLookupIpProtocolByNumber() {
ProtocolsDB db = FileProtocolsDB.getInstance();
Protocol p = db.getProtocolByNumber(4);
assertNotNull("could not lookup ipv4 protocol", p);
assertEquals("incorrect proto number", 4, p.getProto());
assertEquals("incorrect name", "ipv4", p.getName());
// we try ip first and then ipv4 due to jnr/jnr-netdb#4
Protocol p = Protocol.getProtocolByName("ip");
if (p != null) {
p = Protocol.getProtocolByNumber(0);
assertEquals("incorrect proto number", 0, p.getProto());
assertEquals("incorrect name", "ip", p.getName());
} else {
p = Protocol.getProtocolByNumber(4);
assertNotNull("could not lookup ip protocol", p);
assertEquals("incorrect proto number", 4, p.getProto());
assertEquals("incorrect name", "ipv4", p.getName());
}
}
}
31 changes: 23 additions & 8 deletions src/test/java/jnr/netdb/NativeProtocolsDBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,33 @@ public void tearDown() {

@Test public void canLookupIpProtocolByName() {
ProtocolsDB db = NativeProtocolsDB.getInstance();
Protocol p = db.getProtocolByName("ipv4");
assertNotNull("could not lookup ipv4 protocol", p);
assertEquals("incorrect proto number", 4, p.getProto());
assertEquals("incorrect name", "ipv4", p.getName());
// we try ip first and then ipv4 due to jnr/jnr-netdb#4
Protocol p = Protocol.getProtocolByName("ip");
if (p != null) {
assertEquals("incorrect proto number", 0, p.getProto());
assertEquals("incorrect name", "ip", p.getName());
} else {
p = Protocol.getProtocolByName("ipv4");
assertNotNull("could not lookup ipv4 protocol", p);
assertEquals("incorrect proto number", 4, p.getProto());
assertEquals("incorrect name", "ipv4", p.getName());
}
}

@Test public void canLookupIpProtocolByNumber() {
ProtocolsDB db = NativeProtocolsDB.getInstance();
Protocol p = db.getProtocolByNumber(4);
assertNotNull("could not lookup ipv4 protocol", p);
assertEquals("incorrect proto number", 4, p.getProto());
assertEquals("incorrect name", "ipv4", p.getName());
// we try ip first and then ipv4 due to jnr/jnr-netdb#4
Protocol p = Protocol.getProtocolByName("ip");
if (p != null) {
p = Protocol.getProtocolByNumber(0);
assertEquals("incorrect proto number", 0, p.getProto());
assertEquals("incorrect name", "ip", p.getName());
} else {
p = Protocol.getProtocolByNumber(4);
assertNotNull("could not lookup ip protocol", p);
assertEquals("incorrect proto number", 4, p.getProto());
assertEquals("incorrect name", "ipv4", p.getName());
}
}

@Test public void canLookupTcpProtocolByName() {
Expand Down
31 changes: 23 additions & 8 deletions src/test/java/jnr/netdb/ProtocolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@ public void tearDown() {
}

@Test public void canLookupIpProtocolByName() {
Protocol p = Protocol.getProtocolByName("ipv4");
assertNotNull("could not lookup ipv4 protocol", p);
assertEquals("incorrect proto number", 4, p.getProto());
assertEquals("incorrect name", "ipv4", p.getName());
// we try ip first and then ipv4 due to jnr/jnr-netdb#4
Protocol p = Protocol.getProtocolByName("ip");
if (p != null) {
assertEquals("incorrect proto number", 0, p.getProto());
assertEquals("incorrect name", "ip", p.getName());
} else {
p = Protocol.getProtocolByName("ipv4");
assertNotNull("could not lookup ipv4 protocol", p);
assertEquals("incorrect proto number", 4, p.getProto());
assertEquals("incorrect name", "ipv4", p.getName());
}
}

@Test public void returnsNullOnUnknownProtocol() {
Expand All @@ -45,10 +52,18 @@ public void tearDown() {
}

@Test public void canLookupIpProtocolByNumber() {
Protocol p = Protocol.getProtocolByNumber(4);
assertNotNull("could not lookup ip protocol", p);
assertEquals("incorrect proto number", 4, p.getProto());
assertEquals("incorrect name", "ipv4", p.getName());
// we try ip first and then ipv4 due to jnr/jnr-netdb#4
Protocol p = Protocol.getProtocolByName("ip");
if (p != null) {
p = Protocol.getProtocolByNumber(0);
assertEquals("incorrect proto number", 0, p.getProto());
assertEquals("incorrect name", "ip", p.getName());
} else {
p = Protocol.getProtocolByNumber(4);
assertNotNull("could not lookup ip protocol", p);
assertEquals("incorrect proto number", 4, p.getProto());
assertEquals("incorrect name", "ipv4", p.getName());
}
}

@Test public void returnsNullOnInvalidNumber() {
Expand Down

0 comments on commit 615c4b8

Please sign in to comment.