?? nametest.java
字號:
public void test_ctor_max_labels() throws TextParseException { StringBuffer sb = new StringBuffer(); for(int i=0; i<127; ++i){ sb.append("a."); } Name n = new Name(sb.toString()); assertTrue(n.isAbsolute()); assertFalse(n.isWild()); assertEquals(128, n.labels()); assertEquals(255, n.length()); for(int i=0; i<127; ++i){ assertTrue(Arrays.equals(new byte[] { 1, 'a' }, n.getLabel(i))); assertEquals("a", n.getLabelString(i)); } assertTrue(Arrays.equals(new byte[] { 0 }, n.getLabel(127))); assertEquals("", n.getLabelString(127)); } public void test_ctor_toobig_label_escaped_end() throws TextParseException { try { // name with a 64 char label containing an escape at the end new Name("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\090.b."); fail("TextParseException not thrown"); } catch(TextParseException e){} } public void test_ctor_toobig_label_escaped() throws TextParseException { try { // name with a 64 char label containing an escape at the end new Name("aaaaaaaaaaaaaaaaaaaaaaaaaaaa\\001aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.b."); fail("TextParseException not thrown"); } catch(TextParseException e){} } public void test_fromString() throws TextParseException { Name n = new Name(m_rel, m_abs_origin); Name n2 = Name.fromString(m_rel, m_abs_origin); assertEquals(n, n2); } public void test_fromString_at() throws TextParseException { Name n = Name.fromString("@", m_rel_origin); assertSame(m_rel_origin, n); } public void test_fromString_dot() throws TextParseException { Name n = Name.fromString("."); assertSame(Name.root, n); } public void test_fromConstantString() throws TextParseException { Name n = new Name(m_abs); Name n2 = Name.fromConstantString(m_abs); assertEquals(n, n2); } public void test_fromConstantString_invalid() { try { Name.fromConstantString("junk..junk"); fail("IllegalArgumentException not thrown"); } catch(IllegalArgumentException e){} } } public static class Test_DNSInput_init extends TestCase { public void test_basic() throws IOException, TextParseException, WireParseException { final byte[] raw = new byte[] { 3, 'W', 'w', 'w', 7, 'D', 'n', 's', 'J', 'a', 'v', 'a', 3, 'o', 'r', 'g', 0 }; Name e = Name.fromString("Www.DnsJava.org."); Name n = new Name(raw); assertEquals(e, n); } public void test_incomplete() throws IOException { try { new Name(new byte[] { 3, 'W', 'w', 'w' }); fail("WireParseException not thrown"); } catch(WireParseException e ){} } public void test_root() throws WireParseException { final byte[] raw = new byte[] { 0 }; Name n = new Name(new DNSInput(raw)); assertEquals(Name.root, n); } public void test_invalid_length() throws IOException { try { new Name(new byte[] { 4, 'W', 'w', 'w' }); fail("WireParseException not thrown"); } catch(WireParseException e ){} } public void test_max_label_length() throws TextParseException, WireParseException { byte[] raw = new byte[] { 63, 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 0 }; Name e = Name.fromString("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb."); Name n = new Name(new DNSInput(raw)); assertEquals(e, n); } public void test_max_name() throws TextParseException, WireParseException { // absolute name with three 63-char labels and a 61-char label Name e = new Name("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd."); byte[] raw = new byte[] { 63, 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 63, 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 63, 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 61, 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 0 }; Name n = new Name(new DNSInput(raw)); assertEquals(e, n); } public void test_toolong_name() throws TextParseException, WireParseException { // absolute name with three 63-char labels and a 62-char label byte[] raw = new byte[] { 63, 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 63, 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 63, 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 62, 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 0 }; try { new Name(new DNSInput(raw)); fail("WireParseException not thrown"); } catch(WireParseException e ){} } public void test_max_labels() throws TextParseException, WireParseException { byte[] raw = new byte[] { 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 0 }; Name e = Name.fromString("a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a."); Name n = new Name(new DNSInput(raw)); assertEquals(128, n.labels()); assertEquals(e, n); } public void test_toomany_labels() throws TextParseException, WireParseException { byte[] raw = new byte[] { 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 0 }; try { new Name(new DNSInput(raw)); fail("WireParseException not thrown"); } catch(WireParseException e ){} } public void test_basic_compression() throws TextParseException, WireParseException { byte[] raw = new byte[] { 10, 3, 'a', 'b', 'c', 0, (byte)0xC0, 1 }; Name e = Name.fromString("abc."); DNSInput in = new DNSInput(raw); in.jump(6); Options.set("verbosecompression"); Name n = new Name(in); Options.unset("verbosecompression"); assertEquals(e, n); } public void test_two_pointer_compression() throws TextParseException, WireParseException { byte[] raw = new byte[] { 10, 3, 'a', 'b', 'c', 0, (byte)0xC0, 1, (byte)0xC0, 6 }; Name e = Name.fromString("abc."); DNSInput in = new DNSInput(raw); in.jump(8); Name n = new Name(in); assertEquals(e, n); } public void test_two_part_compression() throws TextParseException, WireParseException { byte[] raw = new byte[] { 10, 3, 'a', 'b', 'c', 0, 1, 'B', (byte)0xC0, 1 }; Name e = Name.fromString("B.abc."); DNSInput in = new DNSInput(raw); in.jump(6); Name n = new Name(in); assertEquals(e, n); } public void test_long_jump_compression() throws TextParseException, WireParseException { // pointer to name beginning at index 256 byte[] raw = new byte[] { 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 3, 'a', 'b', 'c', 0, (byte)0xC1, 0 }; Name e = Name.fromString("abc."); DNSInput in = new DNSInput(raw); in.jump(261); Name n = new Name(in); assertEquals(e, n); } public void test_bad_compression() throws TextParseException, WireParseException { byte[] raw = new byte[] { (byte)0xC0, 2, 0 }; try { new Name(new DNSInput(raw)); fail("WireParseException not thrown"); } catch(WireParseException e ){} } public void test_basic_compression_state_restore() throws TextParseException, WireParseException { byte[] raw = new byte[] { 10, 3, 'a', 'b', 'c', 0, (byte)0xC0, 1, 3, 'd', 'e', 'f', 0 }; Name e = Name.fromString("abc."); Name e2 = Name.fromString("def."); DNSInput in = new DNSInput(raw); in.jump(6); Name n = new Name(in); assertEquals(e, n); n = new Name(in); assertEquals(e2, n); } public void test_two_part_compression_state_restore() throws TextParseException, WireParseException { byte[] raw = new byte[] { 10, 3, 'a', 'b', 'c', 0, 1, 'B', (byte)0xC0, 1, 3, 'd', 'e', 'f', 0 }; Name e = Name.fromString("B.abc."); Name e2 = Name.fromString("def."); DNSInput in = new DNSInput(raw); in.jump(6); Name n = new Name(in); assertEquals(e, n); n = new Name(in); assertEquals(e2, n); } } public void test_init_from_name() throws TextParseException { Name n = new Name("A.B.c.d."); Name e = new Name("B.c.d."); Name o = new Name(n, 1); assertEquals(e, o); } public void test_init_from_name_root() throws TextParseException { Name n = new Name("A.B.c.d."); Name o = new Name(n, 4); assertEquals(Name.root, o); } public void test_init_from_name_empty() throws TextParseException { Name n = new Name("A.B.c.d."); Name n2 = new Name(n, 5); assertFalse(n2.isAbsolute()); assertFalse(n2.isWild()); assertEquals(0, n2.labels()); assertEquals(0, n2.length()); } public void test_concatenate_basic() throws NameTooLongException, TextParseException { Name p = Name.fromString("A.B"); Name s = Name.fromString("c.d."); Name e = Name.fromString("A.B.c.d."); Name n = Name.concatenate(p, s); assertEquals(e, n); } public void test_concatenate_abs_prefix() throws NameTooLongException, TextParseException { Name p = Name.fromString("A.B."); Name s = Name.fromString("c.d."); Name e = Name.fromString("A.B."); Name n = Name.concatenate(p, s); assertEquals(e, n); } public void test_concatenate_too_long() throws TextParseException { Name p = Name.fromString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"); Name s = Name.fromString("ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd."); try { Name.concatenate(p, s); fail("NameTooLongException not thrown"); } catch(NameTooLongException e ){} } public void test_relativize() throws TextParseException { Name sub = Name.fromString("a.b.c."); Name dom = Name.fromString("c."); Name exp = Name.fromString("a.b"); Name n = sub.relativize(dom); assertEquals(exp, n); } public void test_relativize_null_origin() throws TextParseException { Name sub = Name.fromString("a.b.c."); Name dom = null; Name n = sub.relativize(dom); assertEquals(sub, n); } public void test_relativize_disjoint() throws TextParseException { Name sub = Name.fromString("a.b.c."); Name dom = Name.fromString("e.f."); Name n = sub.relativize(dom); assertEquals(sub, n); } public void test_relativize_root() throws TextParseException { Name sub = Name.fromString("a.b.c."); Name dom = Name.fromString("."); Name exp = Name.fromString("a.b.c"); Name n = sub.relativize(dom); assertEquals(exp, n); } public void test_wild() throws TextParseException { Name sub = Name.fromString("a.b.c."); Name exp = Name.fromString("*.b.c."); Name n = sub.wild(1); assertEquals(exp, n); } public void test_wild_abs() throws TextParseException { Name sub = Name.fromString("a.b.c."); Name exp = Name.fromString("*."); Name n = sub.wild(3); assertEquals(exp, n); } public void test_wild_toobig() throws TextParseException { Name sub = Name.fromString("a.b.c."); try { sub.wild(4); fail("IllegalArgumentException not thrown"); } catch(IllegalArgumentException e){} } public void test_wild_toosmall() throws TextParseException { Name sub = Name.fromString("a.b.c."); try { sub.wild(0); fail("IllegalArgumentException not thrown"); } catch(IllegalArgumentException e){} } public void test_fromDNAME() throws NameTooLongException, TextParseException { Name own = new Name("the.owner."); Name alias = new Name("the.alias."); DNAMERecord dnr = new DNAMERecord(own, DClass.IN, 0xABCD, alias); Name sub = new Name("sub.the.owner."); Name exp = new Name("sub.the.alias."); Name n = sub.fromDNAME(dnr);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -