⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aplrecordtest.java

📁 DNS Java 是java实现的DNS
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	{	    Tokenizer t = new Tokenizer("1:" + m_addr4_string + "/11\n");	    APLRecord ar = new APLRecord();	    ar.rdataFromString(t, null);	    	    ArrayList exp = new ArrayList();	    exp.add(new Element(false, m_addr4, 11));	    	    assertEquals(exp, ar.getElements());	    	    // make sure extra token is put back	    assertEquals(Tokenizer.EOL, t.get().type);	}		public void test_valid_multi() throws IOException	{	    Tokenizer t = new Tokenizer("1:" + m_addr4_string + "/11 !2:" + m_addr6_string + "/100");	    APLRecord ar = new APLRecord();	    ar.rdataFromString(t, null);	    	    ArrayList exp = new ArrayList();	    exp.add(new Element(false, m_addr4, 11));	    exp.add(new Element(true, m_addr6, 100));	    	    assertEquals(exp, ar.getElements());	}		public void test_validIPv6() throws IOException	{	    Tokenizer t = new Tokenizer("!2:" + m_addr6_string + "/36\n");	    APLRecord ar = new APLRecord();	    ar.rdataFromString(t, null);	    	    ArrayList exp = new ArrayList();	    exp.add(new Element(true, m_addr6, 36));	    	    assertEquals(exp, ar.getElements());	    	    // make sure extra token is put back	    assertEquals(Tokenizer.EOL, t.get().type);	}		public void test_no_colon() throws IOException	{	    Tokenizer t = new Tokenizer("!1192.68.0.1/20");	    APLRecord ar = new APLRecord();	    try {		ar.rdataFromString(t, null);		fail("TextParseException not thrown");	    }	    catch( TextParseException e ){}	}		public void test_colon_and_slash_swapped() throws IOException	{	    Tokenizer t = new Tokenizer("!1/192.68.0.1:20");	    APLRecord ar = new APLRecord();	    try {		ar.rdataFromString(t, null);		fail("TextParseException not thrown");	    }	    catch( TextParseException e ){}	}		public void test_no_slash() throws IOException	{	    Tokenizer t = new Tokenizer("!1:192.68.0.1|20");	    APLRecord ar = new APLRecord();	    try {		ar.rdataFromString(t, null);		fail("TextParseException not thrown");	    }	    catch( TextParseException e ){}	}		public void test_empty_family() throws IOException	{	    Tokenizer t = new Tokenizer("!:192.68.0.1/20");	    APLRecord ar = new APLRecord();	    try {		ar.rdataFromString(t, null);		fail("TextParseException not thrown");	    }	    catch( TextParseException e ){}	}		public void test_malformed_family() throws IOException	{	    Tokenizer t = new Tokenizer("family:192.68.0.1/20");	    APLRecord ar = new APLRecord();	    try {		ar.rdataFromString(t, null);		fail("TextParseException not thrown");	    }	    catch( TextParseException e ){}	}		public void test_invalid_family() throws IOException	{	    Tokenizer t = new Tokenizer("3:192.68.0.1/20");	    APLRecord ar = new APLRecord();	    try {		ar.rdataFromString(t, null);		fail("TextParseException not thrown");	    }	    catch( TextParseException e ){}	}		public void test_empty_prefix() throws IOException	{	    Tokenizer t = new Tokenizer("1:192.68.0.1/");	    APLRecord ar = new APLRecord();	    try {		ar.rdataFromString(t, null);		fail("TextParseException not thrown");	    }	    catch( TextParseException e ){}	}	public void test_malformed_prefix() throws IOException	{	    Tokenizer t = new Tokenizer("1:192.68.0.1/prefix");	    APLRecord ar = new APLRecord();	    try {		ar.rdataFromString(t, null);		fail("TextParseException not thrown");	    }	    catch( TextParseException e ){}	}		public void test_invalid_prefix() throws IOException	{	    Tokenizer t = new Tokenizer("1:192.68.0.1/33");	    APLRecord ar = new APLRecord();	    try {		ar.rdataFromString(t, null);		fail("TextParseException not thrown");	    }	    catch( TextParseException e ){}	}		public void test_empty_address() throws IOException	{	    Tokenizer t = new Tokenizer("1:/33");	    APLRecord ar = new APLRecord();	    try {		ar.rdataFromString(t, null);		fail("TextParseException not thrown");	    }	    catch( TextParseException e ){}	}		public void test_malformed_address() throws IOException	{	    Tokenizer t = new Tokenizer("1:A.B.C.D/33");	    APLRecord ar = new APLRecord();	    try {		ar.rdataFromString(t, null);		fail("TextParseException not thrown");	    }	    catch( TextParseException e ){}	}    }    public static class Test_rrToString extends TestCase    {	Name m_an, m_rn;	long m_ttl;	ArrayList m_elements;	InetAddress m_addr4;	String m_addr4_string;	byte[] m_addr4_bytes;	InetAddress m_addr6;	String m_addr6_string;	byte[] m_addr6_bytes;	protected void setUp() throws TextParseException,				      UnknownHostException	{	    m_an = Name.fromString("My.Absolute.Name.");	    m_rn = Name.fromString("My.Relative.Name");	    m_ttl = 0x13579;	    m_addr4_string = "193.160.232.5";	    m_addr4 = InetAddress.getByName(m_addr4_string);	    m_addr4_bytes = m_addr4.getAddress();	    	    m_addr6_string = "2001:db8:85a3:8d3:1319:8a2e:370:7334";	    m_addr6 = InetAddress.getByName(m_addr6_string);	    m_addr6_bytes = m_addr6.getAddress();	    	    m_elements = new ArrayList(2);	    Element e = new Element(true, m_addr4, 12);	    m_elements.add(e);	    	    e = new Element(false, m_addr6, 64);	    m_elements.add(e);	}		public void test()	{	    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl, m_elements);	    assertEquals("!1:" + m_addr4_string + "/12 2:" + m_addr6_string + "/64",			 ar.rrToString());	}    }    public static class Test_rrToWire extends TestCase    {	Name m_an, m_rn;	long m_ttl;	ArrayList m_elements;	InetAddress m_addr4;	String m_addr4_string;	byte[] m_addr4_bytes;	InetAddress m_addr6;	String m_addr6_string;	byte[] m_addr6_bytes;	protected void setUp() throws TextParseException,				      UnknownHostException	{	    m_an = Name.fromString("My.Absolute.Name.");	    m_rn = Name.fromString("My.Relative.Name");	    m_ttl = 0x13579;	    m_addr4_string = "193.160.232.5";	    m_addr4 = InetAddress.getByName(m_addr4_string);	    m_addr4_bytes = m_addr4.getAddress();	    	    m_addr6_string = "2001:db8:85a3:8d3:1319:8a2e:370:7334";	    m_addr6 = InetAddress.getByName(m_addr6_string);	    m_addr6_bytes = m_addr6.getAddress();	    	    m_elements = new ArrayList(2);	    Element e = new Element(true, m_addr4, 12);	    m_elements.add(e);	    	    e = new Element(false, m_addr6, 64);	    m_elements.add(e);	}		public void test_empty()	{	    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl, new ArrayList());	    DNSOutput dout = new DNSOutput();	    	    ar.rrToWire(dout, null, true);	    assertTrue(Arrays.equals(new byte[0], dout.toByteArray()));	}		public void test_basic()	{	    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl, m_elements);	    	    byte[] exp = new byte[] { 0, 1, 12, (byte)0x84, 				      m_addr4_bytes[0], m_addr4_bytes[1],				      m_addr4_bytes[2], m_addr4_bytes[3],				      0, 2, 64, 0x10,				      m_addr6_bytes[0], m_addr6_bytes[1],				      m_addr6_bytes[2], m_addr6_bytes[3],				      m_addr6_bytes[4], m_addr6_bytes[5],				      m_addr6_bytes[6], m_addr6_bytes[7],				      m_addr6_bytes[8], m_addr6_bytes[9],				      m_addr6_bytes[10], m_addr6_bytes[11],				      m_addr6_bytes[12], m_addr6_bytes[13],				      m_addr6_bytes[14], m_addr6_bytes[15] };	    	    DNSOutput dout = new DNSOutput();	    	    ar.rrToWire(dout, null, true);	    assertTrue(Arrays.equals(exp, dout.toByteArray()));	}		public void test_non_IP() throws IOException	{	    byte[] exp = new byte[] { 0, 3, (byte)130, (byte)0x85, 				      1, 2, 3, 4, 5 };	    	    DNSInput di = new DNSInput(exp);	    APLRecord ar = new APLRecord();	    ar.rrFromWire(di);	    	    DNSOutput dout = new DNSOutput();	    	    ar.rrToWire(dout, null, true);	    assertTrue(Arrays.equals(exp, dout.toByteArray()));	}		public void test_address_with_embedded_zero() throws UnknownHostException	{	    InetAddress a = InetAddress.getByName("232.0.11.1");	    ArrayList elements = new ArrayList();	    elements.add(new Element(true, a, 31));	    	    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl, elements);	    	    byte[] exp = new byte[] { 0, 1, 31, (byte)0x84, (byte)232, 0, 11, 1 };	    	    DNSOutput dout = new DNSOutput();	    	    ar.rrToWire(dout, null, true);	    assertTrue(Arrays.equals(exp, dout.toByteArray()));	}		public void test_short_address() throws UnknownHostException	{	    InetAddress a = InetAddress.getByName("232.0.11.0");	    ArrayList elements = new ArrayList();	    elements.add(new Element(true, a, 31));	    	    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl, elements);	    	    byte[] exp = new byte[] { 0, 1, 31, (byte)0x83, (byte)232, 0, 11  };	    	    DNSOutput dout = new DNSOutput();	    	    ar.rrToWire(dout, null, true);	    assertTrue(Arrays.equals(exp, dout.toByteArray()));	}		public void test_wildcard_address() throws UnknownHostException	{	    InetAddress a = InetAddress.getByName("0.0.0.0");	    ArrayList elements = new ArrayList();	    elements.add(new Element(true, a, 31));	    	    APLRecord ar = new APLRecord(m_an, DClass.IN, m_ttl, elements);	    	    byte[] exp = new byte[] { 0, 1, 31, (byte)0x80 };	    	    DNSOutput dout = new DNSOutput();	    	    ar.rrToWire(dout, null, true);	    assertTrue(Arrays.equals(exp, dout.toByteArray()));	}    }    public static Test suite()    {	TestSuite s = new TestSuite();	s.addTestSuite(Test_Element_init.class);	s.addTestSuite(Test_init.class);	s.addTestSuite(Test_rrFromWire.class);	s.addTestSuite(Test_rdataFromString.class);	s.addTestSuite(Test_rrToString.class);	s.addTestSuite(Test_rrToWire.class);	return s;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -