mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
some tests for encoding and decoding of names according to DNS protocol
This commit is contained in:
parent
6773d5d2ef
commit
7443edeaff
32
test/net/azib/ipscan/util/MDNSResolverTest.java
Normal file
32
test/net/azib/ipscan/util/MDNSResolverTest.java
Normal file
@ -0,0 +1,32 @@
|
||||
package net.azib.ipscan.util;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class MDNSResolverTest {
|
||||
MDNSResolver resolver;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
resolver = new MDNSResolver();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodeNameForDNS() throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(baos);
|
||||
resolver.writeName(out, "a.bb.ccc.dddd");
|
||||
assertEquals("\u0001a\u0002bb\u0003ccc\u0004dddd\u0000", new String(baos.toByteArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeNameFromDNS() throws Exception {
|
||||
byte[] data = "\u0000\u0000\u0001a\u0002bb\u0003ccc\u0004dddd\u0000".getBytes();
|
||||
assertEquals("a.bb.ccc.dddd", resolver.decodeName(data, 2, data.length - 2));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user