Source Code Cross Referenced for NameTest.java in  » Net » dnsjava » org » xbill » DNS » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » dnsjava » org.xbill.DNS 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        // -*- Java -*-
0002:        //
0003:        // Copyright (c) 2005, Matthew J. Rutherford <rutherfo@cs.colorado.edu>
0004:        // Copyright (c) 2005, University of Colorado at Boulder
0005:        // All rights reserved.
0006:        // 
0007:        // Redistribution and use in source and binary forms, with or without
0008:        // modification, are permitted provided that the following conditions are
0009:        // met:
0010:        // 
0011:        // * Redistributions of source code must retain the above copyright
0012:        //   notice, this list of conditions and the following disclaimer.
0013:        // 
0014:        // * Redistributions in binary form must reproduce the above copyright
0015:        //   notice, this list of conditions and the following disclaimer in the
0016:        //   documentation and/or other materials provided with the distribution.
0017:        // 
0018:        // * Neither the name of the University of Colorado at Boulder nor the
0019:        //   names of its contributors may be used to endorse or promote
0020:        //   products derived from this software without specific prior written
0021:        //   permission.
0022:        // 
0023:        // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0024:        // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0025:        // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0026:        // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0027:        // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0028:        // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0029:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0030:        // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0031:        // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0032:        // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0033:        // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0034:        //
0035:        package org.xbill.DNS;
0036:
0037:        import java.io.IOException;
0038:        import java.util.Arrays;
0039:        import junit.framework.Test;
0040:        import junit.framework.TestCase;
0041:        import junit.framework.TestSuite;
0042:        import org.xbill.DNS.Name;
0043:        import org.xbill.DNS.TextParseException;
0044:
0045:        public class NameTest extends TestCase {
0046:            public static class Test_String_init extends TestCase {
0047:                private final String m_abs = "WWW.DnsJava.org.";
0048:                private Name m_abs_origin;
0049:                private final String m_rel = "WWW.DnsJava";
0050:                private Name m_rel_origin;
0051:
0052:                protected void setUp() throws TextParseException {
0053:                    m_abs_origin = Name.fromString("Orig.");
0054:                    m_rel_origin = Name.fromString("Orig");
0055:                }
0056:
0057:                public void test_ctor_empty() {
0058:                    try {
0059:                        new Name("");
0060:                        fail("TextParseException not thrown");
0061:                    } catch (TextParseException e) {
0062:                    }
0063:                }
0064:
0065:                public void test_ctor_at_null_origin()
0066:                        throws TextParseException {
0067:                    Name n = new Name("@");
0068:                    assertFalse(n.isAbsolute());
0069:                    assertFalse(n.isWild());
0070:                    assertEquals(0, n.labels());
0071:                    assertEquals(0, n.length());
0072:                }
0073:
0074:                public void test_ctor_at_abs_origin() throws TextParseException {
0075:                    Name n = new Name("@", m_abs_origin);
0076:                    assertEquals(m_abs_origin, n);
0077:                }
0078:
0079:                public void test_ctor_at_rel_origin() throws TextParseException {
0080:                    Name n = new Name("@", m_rel_origin);
0081:                    assertEquals(m_rel_origin, n);
0082:                }
0083:
0084:                public void test_ctor_dot() throws TextParseException {
0085:                    Name n = new Name(".");
0086:                    assertEquals(Name.root, n);
0087:                    assertNotSame(Name.root, n);
0088:                    assertEquals(1, n.labels());
0089:                    assertEquals(1, n.length());
0090:                }
0091:
0092:                public void test_ctor_wildcard() throws TextParseException {
0093:                    Name n = new Name("*");
0094:                    assertFalse(n.isAbsolute());
0095:                    assertTrue(n.isWild());
0096:                    assertEquals(1, n.labels());
0097:                    assertEquals(2, n.length());
0098:                    assertTrue(Arrays.equals(new byte[] { 1, '*' }, n
0099:                            .getLabel(0)));
0100:                    assertEquals("*", n.getLabelString(0));
0101:                }
0102:
0103:                public void test_ctor_abs() throws TextParseException {
0104:                    Name n = new Name(m_abs);
0105:                    assertTrue(n.isAbsolute());
0106:                    assertFalse(n.isWild());
0107:                    assertEquals(4, n.labels());
0108:                    assertEquals(17, n.length());
0109:                    assertTrue(Arrays.equals(new byte[] { 3, 'W', 'W', 'W' }, n
0110:                            .getLabel(0)));
0111:                    assertEquals("WWW", n.getLabelString(0));
0112:                    assertTrue(Arrays.equals(new byte[] { 7, 'D', 'n', 's',
0113:                            'J', 'a', 'v', 'a' }, n.getLabel(1)));
0114:                    assertEquals("DnsJava", n.getLabelString(1));
0115:                    assertTrue(Arrays.equals(new byte[] { 3, 'o', 'r', 'g' }, n
0116:                            .getLabel(2)));
0117:                    assertEquals("org", n.getLabelString(2));
0118:                    assertTrue(Arrays.equals(new byte[] { 0 }, n.getLabel(3)));
0119:                    assertEquals("", n.getLabelString(3));
0120:                }
0121:
0122:                public void test_ctor_rel() throws TextParseException {
0123:                    Name n = new Name(m_rel);
0124:                    assertFalse(n.isAbsolute());
0125:                    assertFalse(n.isWild());
0126:                    assertEquals(2, n.labels());
0127:                    assertEquals(12, n.length());
0128:                    assertTrue(Arrays.equals(new byte[] { 3, 'W', 'W', 'W' }, n
0129:                            .getLabel(0)));
0130:                    assertEquals("WWW", n.getLabelString(0));
0131:                    assertTrue(Arrays.equals(new byte[] { 7, 'D', 'n', 's',
0132:                            'J', 'a', 'v', 'a' }, n.getLabel(1)));
0133:                    assertEquals("DnsJava", n.getLabelString(1));
0134:                }
0135:
0136:                public void test_ctor_7label() throws TextParseException {
0137:                    // 7 is the number of label positions that are cached
0138:                    Name n = new Name("a.b.c.d.e.f.");
0139:                    assertTrue(n.isAbsolute());
0140:                    assertFalse(n.isWild());
0141:                    assertEquals(7, n.labels());
0142:                    assertEquals(13, n.length());
0143:                    assertTrue(Arrays.equals(new byte[] { 1, 'a' }, n
0144:                            .getLabel(0)));
0145:                    assertEquals("a", n.getLabelString(0));
0146:                    assertTrue(Arrays.equals(new byte[] { 1, 'b' }, n
0147:                            .getLabel(1)));
0148:                    assertEquals("b", n.getLabelString(1));
0149:                    assertTrue(Arrays.equals(new byte[] { 1, 'c' }, n
0150:                            .getLabel(2)));
0151:                    assertEquals("c", n.getLabelString(2));
0152:                    assertTrue(Arrays.equals(new byte[] { 1, 'd' }, n
0153:                            .getLabel(3)));
0154:                    assertEquals("d", n.getLabelString(3));
0155:                    assertTrue(Arrays.equals(new byte[] { 1, 'e' }, n
0156:                            .getLabel(4)));
0157:                    assertEquals("e", n.getLabelString(4));
0158:                    assertTrue(Arrays.equals(new byte[] { 1, 'f' }, n
0159:                            .getLabel(5)));
0160:                    assertEquals("f", n.getLabelString(5));
0161:                    assertTrue(Arrays.equals(new byte[] { 0 }, n.getLabel(6)));
0162:                    assertEquals("", n.getLabelString(6));
0163:                }
0164:
0165:                public void test_ctor_8label() throws TextParseException {
0166:                    // 7 is the number of label positions that are cached
0167:                    Name n = new Name("a.b.c.d.e.f.g.");
0168:                    assertTrue(n.isAbsolute());
0169:                    assertFalse(n.isWild());
0170:                    assertEquals(8, n.labels());
0171:                    assertEquals(15, n.length());
0172:                    assertTrue(Arrays.equals(new byte[] { 1, 'a' }, n
0173:                            .getLabel(0)));
0174:                    assertEquals("a", n.getLabelString(0));
0175:                    assertTrue(Arrays.equals(new byte[] { 1, 'b' }, n
0176:                            .getLabel(1)));
0177:                    assertEquals("b", n.getLabelString(1));
0178:                    assertTrue(Arrays.equals(new byte[] { 1, 'c' }, n
0179:                            .getLabel(2)));
0180:                    assertEquals("c", n.getLabelString(2));
0181:                    assertTrue(Arrays.equals(new byte[] { 1, 'd' }, n
0182:                            .getLabel(3)));
0183:                    assertEquals("d", n.getLabelString(3));
0184:                    assertTrue(Arrays.equals(new byte[] { 1, 'e' }, n
0185:                            .getLabel(4)));
0186:                    assertEquals("e", n.getLabelString(4));
0187:                    assertTrue(Arrays.equals(new byte[] { 1, 'f' }, n
0188:                            .getLabel(5)));
0189:                    assertEquals("f", n.getLabelString(5));
0190:                    assertTrue(Arrays.equals(new byte[] { 1, 'g' }, n
0191:                            .getLabel(6)));
0192:                    assertEquals("g", n.getLabelString(6));
0193:                    assertTrue(Arrays.equals(new byte[] { 0 }, n.getLabel(7)));
0194:                    assertEquals("", n.getLabelString(7));
0195:                }
0196:
0197:                public void test_ctor_abs_abs_origin()
0198:                        throws TextParseException {
0199:                    Name n = new Name(m_abs, m_abs_origin);
0200:                    assertTrue(n.isAbsolute());
0201:                    assertFalse(n.isWild());
0202:                    assertEquals(4, n.labels());
0203:                    assertEquals(17, n.length());
0204:                    assertTrue(Arrays.equals(new byte[] { 3, 'W', 'W', 'W' }, n
0205:                            .getLabel(0)));
0206:                    assertEquals("WWW", n.getLabelString(0));
0207:                    assertTrue(Arrays.equals(new byte[] { 7, 'D', 'n', 's',
0208:                            'J', 'a', 'v', 'a' }, n.getLabel(1)));
0209:                    assertEquals("DnsJava", n.getLabelString(1));
0210:                    assertTrue(Arrays.equals(new byte[] { 3, 'o', 'r', 'g' }, n
0211:                            .getLabel(2)));
0212:                    assertEquals("org", n.getLabelString(2));
0213:                    assertTrue(Arrays.equals(new byte[] { 0 }, n.getLabel(3)));
0214:                    assertEquals("", n.getLabelString(3));
0215:                }
0216:
0217:                public void test_ctor_abs_rel_origin()
0218:                        throws TextParseException {
0219:                    Name n = new Name(m_abs, m_rel_origin);
0220:                    assertTrue(n.isAbsolute());
0221:                    assertFalse(n.isWild());
0222:                    assertEquals(4, n.labels());
0223:                    assertEquals(17, n.length());
0224:                    assertTrue(Arrays.equals(new byte[] { 3, 'W', 'W', 'W' }, n
0225:                            .getLabel(0)));
0226:                    assertEquals("WWW", n.getLabelString(0));
0227:                    assertTrue(Arrays.equals(new byte[] { 7, 'D', 'n', 's',
0228:                            'J', 'a', 'v', 'a' }, n.getLabel(1)));
0229:                    assertEquals("DnsJava", n.getLabelString(1));
0230:                    assertTrue(Arrays.equals(new byte[] { 3, 'o', 'r', 'g' }, n
0231:                            .getLabel(2)));
0232:                    assertEquals("org", n.getLabelString(2));
0233:                    assertTrue(Arrays.equals(new byte[] { 0 }, n.getLabel(3)));
0234:                    assertEquals("", n.getLabelString(3));
0235:                }
0236:
0237:                public void test_ctor_rel_abs_origin()
0238:                        throws TextParseException {
0239:                    Name n = new Name(m_rel, m_abs_origin);
0240:                    assertTrue(n.isAbsolute());
0241:                    assertFalse(n.isWild());
0242:                    assertEquals(4, n.labels());
0243:                    assertEquals(18, n.length());
0244:                    assertTrue(Arrays.equals(new byte[] { 3, 'W', 'W', 'W' }, n
0245:                            .getLabel(0)));
0246:                    assertEquals("WWW", n.getLabelString(0));
0247:                    assertTrue(Arrays.equals(new byte[] { 7, 'D', 'n', 's',
0248:                            'J', 'a', 'v', 'a' }, n.getLabel(1)));
0249:                    assertEquals("DnsJava", n.getLabelString(1));
0250:                    assertTrue(Arrays
0251:                            .equals(new byte[] { 4, 'O', 'r', 'i', 'g' }, n
0252:                                    .getLabel(2)));
0253:                    assertEquals("Orig", n.getLabelString(2));
0254:                    assertTrue(Arrays.equals(new byte[] { 0 }, n.getLabel(3)));
0255:                    assertEquals("", n.getLabelString(3));
0256:                }
0257:
0258:                public void test_ctor_invalid_label() {
0259:                    try {
0260:                        new Name("junk..junk.");
0261:                        fail("TextParseException not thrown");
0262:                    } catch (TextParseException e) {
0263:                    }
0264:                }
0265:
0266:                public void test_ctor_max_label() throws TextParseException {
0267:                    // name with a 63 char label
0268:                    Name n = new Name(
0269:                            "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.b.");
0270:                    assertTrue(n.isAbsolute());
0271:                    assertFalse(n.isWild());
0272:                    assertEquals(3, n.labels());
0273:                    assertEquals(67, n.length());
0274:                    assertTrue(Arrays.equals(new byte[] { 63, 'a', 'a', 'a',
0275:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0276:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0277:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0278:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0279:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0280:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a' },
0281:                            n.getLabel(0)));
0282:                    assertEquals(
0283:                            "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
0284:                            n.getLabelString(0));
0285:                    assertTrue(Arrays.equals(new byte[] { 1, 'b' }, n
0286:                            .getLabel(1)));
0287:                    assertEquals("b", n.getLabelString(1));
0288:                    assertTrue(Arrays.equals(new byte[] { 0 }, n.getLabel(2)));
0289:                    assertEquals("", n.getLabelString(2));
0290:                }
0291:
0292:                public void test_ctor_toobig_label() {
0293:                    // name with a 64 char label
0294:                    try {
0295:                        new Name(
0296:                                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.b.");
0297:                        fail("TextParseException not thrown");
0298:                    } catch (TextParseException e) {
0299:                    }
0300:                }
0301:
0302:                public void test_ctor_max_length_rel()
0303:                        throws TextParseException {
0304:                    // relative name with three 63-char labels and a 62-char label
0305:                    Name n = new Name(
0306:                            "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd");
0307:                    assertFalse(n.isAbsolute());
0308:                    assertFalse(n.isWild());
0309:                    assertEquals(4, n.labels());
0310:                    assertEquals(255, n.length());
0311:                }
0312:
0313:                public void test_ctor_max_length_abs()
0314:                        throws TextParseException {
0315:                    // absolute name with three 63-char labels and a 61-char label
0316:                    Name n = new Name(
0317:                            "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.");
0318:                    assertTrue(n.isAbsolute());
0319:                    assertFalse(n.isWild());
0320:                    assertEquals(5, n.labels());
0321:                    assertEquals(255, n.length());
0322:                }
0323:
0324:                public void test_ctor_escaped() throws TextParseException {
0325:                    Name n = new Name("ab\\123cd");
0326:                    assertFalse(n.isAbsolute());
0327:                    assertFalse(n.isWild());
0328:                    assertEquals(1, n.labels());
0329:                    assertEquals(6, n.length());
0330:                    assertTrue(Arrays.equals(new byte[] { 5, 'a', 'b',
0331:                            (byte) 123, 'c', 'd' }, n.getLabel(0)));
0332:                }
0333:
0334:                public void test_ctor_escaped_end() throws TextParseException {
0335:                    Name n = new Name("abcd\\123");
0336:                    assertFalse(n.isAbsolute());
0337:                    assertFalse(n.isWild());
0338:                    assertEquals(1, n.labels());
0339:                    assertEquals(6, n.length());
0340:                    assertTrue(Arrays.equals(new byte[] { 5, 'a', 'b', 'c',
0341:                            'd', (byte) 123 }, n.getLabel(0)));
0342:                }
0343:
0344:                public void test_ctor_short_escaped() throws TextParseException {
0345:                    try {
0346:                        new Name("ab\\12cd");
0347:                        fail("TextParseException not throw");
0348:                    } catch (TextParseException e) {
0349:                    }
0350:                }
0351:
0352:                public void test_ctor_short_escaped_end()
0353:                        throws TextParseException {
0354:                    try {
0355:                        new Name("ab\\12");
0356:                        fail("TextParseException not throw");
0357:                    } catch (TextParseException e) {
0358:                    }
0359:                }
0360:
0361:                public void test_ctor_empty_escaped_end()
0362:                        throws TextParseException {
0363:                    try {
0364:                        new Name("ab\\");
0365:                        fail("TextParseException not throw");
0366:                    } catch (TextParseException e) {
0367:                    }
0368:                }
0369:
0370:                public void test_ctor_toobig_escaped()
0371:                        throws TextParseException {
0372:                    try {
0373:                        new Name("ab\\256cd");
0374:                        fail("TextParseException not throw");
0375:                    } catch (TextParseException e) {
0376:                    }
0377:                }
0378:
0379:                public void test_ctor_toobig_escaped_end()
0380:                        throws TextParseException {
0381:                    try {
0382:                        new Name("ab\\256");
0383:                        fail("TextParseException not throw");
0384:                    } catch (TextParseException e) {
0385:                    }
0386:                }
0387:
0388:                public void test_ctor_max_label_escaped()
0389:                        throws TextParseException {
0390:                    // name with a 63 char label containing an escape
0391:                    Name n = new Name(
0392:                            "aaaa\\100aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.b.");
0393:                    assertTrue(n.isAbsolute());
0394:                    assertFalse(n.isWild());
0395:                    assertEquals(3, n.labels());
0396:                    assertEquals(67, n.length());
0397:                    assertTrue(Arrays.equals(new byte[] { 63, 'a', 'a', 'a',
0398:                            'a', (byte) 100, 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0399:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0400:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0401:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0402:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0403:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0404:                            'a' }, n.getLabel(0)));
0405:                    assertTrue(Arrays.equals(new byte[] { 1, 'b' }, n
0406:                            .getLabel(1)));
0407:                    assertEquals("b", n.getLabelString(1));
0408:                    assertTrue(Arrays.equals(new byte[] { 0 }, n.getLabel(2)));
0409:                    assertEquals("", n.getLabelString(2));
0410:                }
0411:
0412:                public void test_ctor_max_labels() throws TextParseException {
0413:                    StringBuffer sb = new StringBuffer();
0414:                    for (int i = 0; i < 127; ++i) {
0415:                        sb.append("a.");
0416:                    }
0417:                    Name n = new Name(sb.toString());
0418:                    assertTrue(n.isAbsolute());
0419:                    assertFalse(n.isWild());
0420:                    assertEquals(128, n.labels());
0421:                    assertEquals(255, n.length());
0422:                    for (int i = 0; i < 127; ++i) {
0423:                        assertTrue(Arrays.equals(new byte[] { 1, 'a' }, n
0424:                                .getLabel(i)));
0425:                        assertEquals("a", n.getLabelString(i));
0426:                    }
0427:                    assertTrue(Arrays.equals(new byte[] { 0 }, n.getLabel(127)));
0428:                    assertEquals("", n.getLabelString(127));
0429:                }
0430:
0431:                public void test_ctor_toobig_label_escaped_end()
0432:                        throws TextParseException {
0433:                    try {
0434:                        // name with a 64 char label containing an escape at the end
0435:                        new Name(
0436:                                "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\090.b.");
0437:                        fail("TextParseException not thrown");
0438:                    } catch (TextParseException e) {
0439:                    }
0440:                }
0441:
0442:                public void test_ctor_toobig_label_escaped()
0443:                        throws TextParseException {
0444:                    try {
0445:                        // name with a 64 char label containing an escape at the end
0446:                        new Name(
0447:                                "aaaaaaaaaaaaaaaaaaaaaaaaaaaa\\001aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.b.");
0448:                        fail("TextParseException not thrown");
0449:                    } catch (TextParseException e) {
0450:                    }
0451:                }
0452:
0453:                public void test_fromString() throws TextParseException {
0454:                    Name n = new Name(m_rel, m_abs_origin);
0455:                    Name n2 = Name.fromString(m_rel, m_abs_origin);
0456:                    assertEquals(n, n2);
0457:                }
0458:
0459:                public void test_fromString_at() throws TextParseException {
0460:                    Name n = Name.fromString("@", m_rel_origin);
0461:                    assertSame(m_rel_origin, n);
0462:                }
0463:
0464:                public void test_fromString_dot() throws TextParseException {
0465:                    Name n = Name.fromString(".");
0466:                    assertSame(Name.root, n);
0467:                }
0468:
0469:                public void test_fromConstantString() throws TextParseException {
0470:                    Name n = new Name(m_abs);
0471:                    Name n2 = Name.fromConstantString(m_abs);
0472:                    assertEquals(n, n2);
0473:                }
0474:
0475:                public void test_fromConstantString_invalid() {
0476:                    try {
0477:                        Name.fromConstantString("junk..junk");
0478:                        fail("IllegalArgumentException not thrown");
0479:                    } catch (IllegalArgumentException e) {
0480:                    }
0481:                }
0482:            }
0483:
0484:            public static class Test_DNSInput_init extends TestCase {
0485:                public void test_basic() throws IOException,
0486:                        TextParseException, WireParseException {
0487:
0488:                    final byte[] raw = new byte[] { 3, 'W', 'w', 'w', 7, 'D',
0489:                            'n', 's', 'J', 'a', 'v', 'a', 3, 'o', 'r', 'g', 0 };
0490:                    Name e = Name.fromString("Www.DnsJava.org.");
0491:
0492:                    Name n = new Name(raw);
0493:                    assertEquals(e, n);
0494:                }
0495:
0496:                public void test_incomplete() throws IOException {
0497:                    try {
0498:                        new Name(new byte[] { 3, 'W', 'w', 'w' });
0499:                        fail("WireParseException not thrown");
0500:                    } catch (WireParseException e) {
0501:                    }
0502:                }
0503:
0504:                public void test_root() throws WireParseException {
0505:                    final byte[] raw = new byte[] { 0 };
0506:                    Name n = new Name(new DNSInput(raw));
0507:                    assertEquals(Name.root, n);
0508:                }
0509:
0510:                public void test_invalid_length() throws IOException {
0511:                    try {
0512:                        new Name(new byte[] { 4, 'W', 'w', 'w' });
0513:                        fail("WireParseException not thrown");
0514:                    } catch (WireParseException e) {
0515:                    }
0516:                }
0517:
0518:                public void test_max_label_length() throws TextParseException,
0519:                        WireParseException {
0520:                    byte[] raw = new byte[] { 63, 'b', 'b', 'b', 'b', 'b', 'b',
0521:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0522:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0523:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0524:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0525:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0526:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 0 };
0527:                    Name e = Name
0528:                            .fromString("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.");
0529:
0530:                    Name n = new Name(new DNSInput(raw));
0531:                    assertEquals(e, n);
0532:                }
0533:
0534:                public void test_max_name() throws TextParseException,
0535:                        WireParseException {
0536:                    // absolute name with three 63-char labels and a 61-char label
0537:                    Name e = new Name(
0538:                            "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.");
0539:                    byte[] raw = new byte[] { 63, 'a', 'a', 'a', 'a', 'a', 'a',
0540:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0541:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0542:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0543:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0544:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0545:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 63, 'b', 'b',
0546:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0547:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0548:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0549:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0550:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0551:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0552:                            'b', 63, 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',
0553:                            'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',
0554:                            'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',
0555:                            'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',
0556:                            'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',
0557:                            'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',
0558:                            'c', 'c', 'c', 'c', 'c', 61, 'd', 'd', 'd', 'd',
0559:                            'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd',
0560:                            'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd',
0561:                            'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd',
0562:                            'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd',
0563:                            'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd',
0564:                            'd', 'd', 'd', 'd', 'd', 'd', 'd', 0 };
0565:
0566:                    Name n = new Name(new DNSInput(raw));
0567:                    assertEquals(e, n);
0568:                }
0569:
0570:                public void test_toolong_name() throws TextParseException,
0571:                        WireParseException {
0572:                    // absolute name with three 63-char labels and a 62-char label
0573:                    byte[] raw = new byte[] { 63, 'a', 'a', 'a', 'a', 'a', 'a',
0574:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0575:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0576:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0577:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0578:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
0579:                            'a', 'a', 'a', 'a', 'a', 'a', 'a', 63, 'b', 'b',
0580:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0581:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0582:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0583:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0584:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0585:                            'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b',
0586:                            'b', 63, 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',
0587:                            'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',
0588:                            'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',
0589:                            'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',
0590:                            'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',
0591:                            'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c',
0592:                            'c', 'c', 'c', 'c', 'c', 62, 'd', 'd', 'd', 'd',
0593:                            'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd',
0594:                            'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd',
0595:                            'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd',
0596:                            'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd',
0597:                            'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd',
0598:                            'd', 'd', 'd', 'd', 'd', 'd', 'd', 'd', 0 };
0599:
0600:                    try {
0601:                        new Name(new DNSInput(raw));
0602:                        fail("WireParseException not thrown");
0603:                    } catch (WireParseException e) {
0604:                    }
0605:                }
0606:
0607:                public void test_max_labels() throws TextParseException,
0608:                        WireParseException {
0609:                    byte[] raw = new byte[] { 1, 'a', 1, 'a', 1, 'a', 1, 'a',
0610:                            1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0611:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0612:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0613:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0614:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0615:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0616:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0617:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0618:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0619:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0620:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0621:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0622:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0623:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0624:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0625:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0626:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0627:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0628:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0629:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0630:                            'a', 1, 'a', 1, 'a', 0 };
0631:                    Name e = Name
0632:                            .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.");
0633:                    Name n = new Name(new DNSInput(raw));
0634:                    assertEquals(128, n.labels());
0635:                    assertEquals(e, n);
0636:                }
0637:
0638:                public void test_toomany_labels() throws TextParseException,
0639:                        WireParseException {
0640:                    byte[] raw = new byte[] { 1, 'a', 1, 'a', 1, 'a', 1, 'a',
0641:                            1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0642:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0643:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0644:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0645:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0646:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0647:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0648:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0649:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0650:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0651:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0652:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0653:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0654:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0655:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0656:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0657:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0658:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0659:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0660:                            'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1, 'a', 1,
0661:                            'a', 1, 'a', 1, 'a', 1, 'a', 0 };
0662:                    try {
0663:                        new Name(new DNSInput(raw));
0664:                        fail("WireParseException not thrown");
0665:                    } catch (WireParseException e) {
0666:                    }
0667:                }
0668:
0669:                public void test_basic_compression() throws TextParseException,
0670:                        WireParseException {
0671:                    byte[] raw = new byte[] { 10, 3, 'a', 'b', 'c', 0,
0672:                            (byte) 0xC0, 1 };
0673:                    Name e = Name.fromString("abc.");
0674:
0675:                    DNSInput in = new DNSInput(raw);
0676:                    in.jump(6);
0677:
0678:                    Options.set("verbosecompression");
0679:                    Name n = new Name(in);
0680:                    Options.unset("verbosecompression");
0681:                    assertEquals(e, n);
0682:                }
0683:
0684:                public void test_two_pointer_compression()
0685:                        throws TextParseException, WireParseException {
0686:                    byte[] raw = new byte[] { 10, 3, 'a', 'b', 'c', 0,
0687:                            (byte) 0xC0, 1, (byte) 0xC0, 6 };
0688:                    Name e = Name.fromString("abc.");
0689:
0690:                    DNSInput in = new DNSInput(raw);
0691:                    in.jump(8);
0692:
0693:                    Name n = new Name(in);
0694:                    assertEquals(e, n);
0695:                }
0696:
0697:                public void test_two_part_compression()
0698:                        throws TextParseException, WireParseException {
0699:                    byte[] raw = new byte[] { 10, 3, 'a', 'b', 'c', 0, 1, 'B',
0700:                            (byte) 0xC0, 1 };
0701:                    Name e = Name.fromString("B.abc.");
0702:
0703:                    DNSInput in = new DNSInput(raw);
0704:                    in.jump(6);
0705:
0706:                    Name n = new Name(in);
0707:                    assertEquals(e, n);
0708:                }
0709:
0710:                public void test_long_jump_compression()
0711:                        throws TextParseException, WireParseException {
0712:                    // pointer to name beginning at index 256
0713:                    byte[] raw = new byte[] { 12, 12, 12, 12, 12, 12, 12, 12,
0714:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0715:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0716:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0717:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0718:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0719:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0720:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0721:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0722:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0723:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0724:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0725:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0726:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0727:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0728:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0729:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0730:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0731:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0732:                            12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
0733:                            12, 3, 'a', 'b', 'c', 0, (byte) 0xC1, 0 };
0734:                    Name e = Name.fromString("abc.");
0735:
0736:                    DNSInput in = new DNSInput(raw);
0737:                    in.jump(261);
0738:                    Name n = new Name(in);
0739:                    assertEquals(e, n);
0740:                }
0741:
0742:                public void test_bad_compression() throws TextParseException,
0743:                        WireParseException {
0744:                    byte[] raw = new byte[] { (byte) 0xC0, 2, 0 };
0745:                    try {
0746:                        new Name(new DNSInput(raw));
0747:                        fail("WireParseException not thrown");
0748:                    } catch (WireParseException e) {
0749:                    }
0750:                }
0751:
0752:                public void test_basic_compression_state_restore()
0753:                        throws TextParseException, WireParseException {
0754:                    byte[] raw = new byte[] { 10, 3, 'a', 'b', 'c', 0,
0755:                            (byte) 0xC0, 1, 3, 'd', 'e', 'f', 0 };
0756:                    Name e = Name.fromString("abc.");
0757:                    Name e2 = Name.fromString("def.");
0758:
0759:                    DNSInput in = new DNSInput(raw);
0760:                    in.jump(6);
0761:
0762:                    Name n = new Name(in);
0763:                    assertEquals(e, n);
0764:
0765:                    n = new Name(in);
0766:                    assertEquals(e2, n);
0767:                }
0768:
0769:                public void test_two_part_compression_state_restore()
0770:                        throws TextParseException, WireParseException {
0771:                    byte[] raw = new byte[] { 10, 3, 'a', 'b', 'c', 0, 1, 'B',
0772:                            (byte) 0xC0, 1, 3, 'd', 'e', 'f', 0 };
0773:                    Name e = Name.fromString("B.abc.");
0774:                    Name e2 = Name.fromString("def.");
0775:
0776:                    DNSInput in = new DNSInput(raw);
0777:                    in.jump(6);
0778:
0779:                    Name n = new Name(in);
0780:                    assertEquals(e, n);
0781:
0782:                    n = new Name(in);
0783:                    assertEquals(e2, n);
0784:                }
0785:            }
0786:
0787:            public void test_init_from_name() throws TextParseException {
0788:                Name n = new Name("A.B.c.d.");
0789:                Name e = new Name("B.c.d.");
0790:                Name o = new Name(n, 1);
0791:                assertEquals(e, o);
0792:            }
0793:
0794:            public void test_init_from_name_root() throws TextParseException {
0795:                Name n = new Name("A.B.c.d.");
0796:                Name o = new Name(n, 4);
0797:                assertEquals(Name.root, o);
0798:            }
0799:
0800:            public void test_init_from_name_empty() throws TextParseException {
0801:                Name n = new Name("A.B.c.d.");
0802:                Name n2 = new Name(n, 5);
0803:
0804:                assertFalse(n2.isAbsolute());
0805:                assertFalse(n2.isWild());
0806:                assertEquals(0, n2.labels());
0807:                assertEquals(0, n2.length());
0808:            }
0809:
0810:            public void test_concatenate_basic() throws NameTooLongException,
0811:                    TextParseException {
0812:                Name p = Name.fromString("A.B");
0813:                Name s = Name.fromString("c.d.");
0814:                Name e = Name.fromString("A.B.c.d.");
0815:
0816:                Name n = Name.concatenate(p, s);
0817:                assertEquals(e, n);
0818:            }
0819:
0820:            public void test_concatenate_abs_prefix()
0821:                    throws NameTooLongException, TextParseException {
0822:                Name p = Name.fromString("A.B.");
0823:                Name s = Name.fromString("c.d.");
0824:                Name e = Name.fromString("A.B.");
0825:
0826:                Name n = Name.concatenate(p, s);
0827:                assertEquals(e, n);
0828:            }
0829:
0830:            public void test_concatenate_too_long() throws TextParseException {
0831:                Name p = Name
0832:                        .fromString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
0833:                Name s = Name
0834:                        .fromString("ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.");
0835:
0836:                try {
0837:                    Name.concatenate(p, s);
0838:                    fail("NameTooLongException not thrown");
0839:                } catch (NameTooLongException e) {
0840:                }
0841:            }
0842:
0843:            public void test_relativize() throws TextParseException {
0844:                Name sub = Name.fromString("a.b.c.");
0845:                Name dom = Name.fromString("c.");
0846:                Name exp = Name.fromString("a.b");
0847:
0848:                Name n = sub.relativize(dom);
0849:                assertEquals(exp, n);
0850:            }
0851:
0852:            public void test_relativize_null_origin() throws TextParseException {
0853:                Name sub = Name.fromString("a.b.c.");
0854:                Name dom = null;
0855:
0856:                Name n = sub.relativize(dom);
0857:                assertEquals(sub, n);
0858:            }
0859:
0860:            public void test_relativize_disjoint() throws TextParseException {
0861:                Name sub = Name.fromString("a.b.c.");
0862:                Name dom = Name.fromString("e.f.");
0863:
0864:                Name n = sub.relativize(dom);
0865:                assertEquals(sub, n);
0866:            }
0867:
0868:            public void test_relativize_root() throws TextParseException {
0869:                Name sub = Name.fromString("a.b.c.");
0870:                Name dom = Name.fromString(".");
0871:                Name exp = Name.fromString("a.b.c");
0872:
0873:                Name n = sub.relativize(dom);
0874:                assertEquals(exp, n);
0875:            }
0876:
0877:            public void test_wild() throws TextParseException {
0878:                Name sub = Name.fromString("a.b.c.");
0879:                Name exp = Name.fromString("*.b.c.");
0880:
0881:                Name n = sub.wild(1);
0882:                assertEquals(exp, n);
0883:            }
0884:
0885:            public void test_wild_abs() throws TextParseException {
0886:                Name sub = Name.fromString("a.b.c.");
0887:                Name exp = Name.fromString("*.");
0888:
0889:                Name n = sub.wild(3);
0890:                assertEquals(exp, n);
0891:            }
0892:
0893:            public void test_wild_toobig() throws TextParseException {
0894:                Name sub = Name.fromString("a.b.c.");
0895:                try {
0896:                    sub.wild(4);
0897:                    fail("IllegalArgumentException not thrown");
0898:                } catch (IllegalArgumentException e) {
0899:                }
0900:            }
0901:
0902:            public void test_wild_toosmall() throws TextParseException {
0903:                Name sub = Name.fromString("a.b.c.");
0904:                try {
0905:                    sub.wild(0);
0906:                    fail("IllegalArgumentException not thrown");
0907:                } catch (IllegalArgumentException e) {
0908:                }
0909:            }
0910:
0911:            public void test_fromDNAME() throws NameTooLongException,
0912:                    TextParseException {
0913:                Name own = new Name("the.owner.");
0914:                Name alias = new Name("the.alias.");
0915:                DNAMERecord dnr = new DNAMERecord(own, DClass.IN, 0xABCD, alias);
0916:                Name sub = new Name("sub.the.owner.");
0917:                Name exp = new Name("sub.the.alias.");
0918:
0919:                Name n = sub.fromDNAME(dnr);
0920:                assertEquals(exp, n);
0921:            }
0922:
0923:            public void test_fromDNAME_toobig() throws NameTooLongException,
0924:                    TextParseException {
0925:                Name own = new Name("the.owner.");
0926:                Name alias = new Name(
0927:                        "the.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.");
0928:                DNAMERecord dnr = new DNAMERecord(own, DClass.IN, 0xABCD, alias);
0929:                Name sub = new Name(
0930:                        "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd.the.owner.");
0931:
0932:                try {
0933:                    sub.fromDNAME(dnr);
0934:                    fail("NameTooLongException not thrown");
0935:                } catch (NameTooLongException e) {
0936:                }
0937:            }
0938:
0939:            public void test_fromDNAME_disjoint() throws NameTooLongException,
0940:                    TextParseException {
0941:                Name own = new Name("the.owner.");
0942:                Name alias = new Name("the.alias.");
0943:                DNAMERecord dnr = new DNAMERecord(own, DClass.IN, 0xABCD, alias);
0944:
0945:                Name sub = new Name("sub.the.other");
0946:
0947:                assertNull(sub.fromDNAME(dnr));
0948:            }
0949:
0950:            public void test_subdomain_abs() throws TextParseException {
0951:                Name dom = new Name("the.domain.");
0952:                Name sub = new Name("sub.of.the.domain.");
0953:                assertTrue(sub.subdomain(dom));
0954:                assertFalse(dom.subdomain(sub));
0955:            }
0956:
0957:            public void test_subdomain_rel() throws TextParseException {
0958:                Name dom = new Name("the.domain");
0959:                Name sub = new Name("sub.of.the.domain");
0960:                assertTrue(sub.subdomain(dom));
0961:                assertFalse(dom.subdomain(sub));
0962:            }
0963:
0964:            public void test_subdomain_equal() throws TextParseException {
0965:                Name dom = new Name("the.domain");
0966:                Name sub = new Name("the.domain");
0967:                assertTrue(sub.subdomain(dom));
0968:                assertTrue(dom.subdomain(sub));
0969:            }
0970:
0971:            public void test_toString_abs() throws TextParseException {
0972:                String in = "This.Is.My.Absolute.Name.";
0973:                Name n = new Name(in);
0974:
0975:                assertEquals(in, n.toString());
0976:            }
0977:
0978:            public void test_toString_rel() throws TextParseException {
0979:                String in = "This.Is.My.Relative.Name";
0980:                Name n = new Name(in);
0981:
0982:                assertEquals(in, n.toString());
0983:            }
0984:
0985:            public void test_toString_at() throws TextParseException {
0986:                Name n = new Name("@", null);
0987:                assertEquals("@", n.toString());
0988:            }
0989:
0990:            public void test_toString_root() throws TextParseException {
0991:                assertEquals(".", Name.root.toString());
0992:            }
0993:
0994:            public void test_toString_wild() throws TextParseException {
0995:                String in = "*.A.b.c.e";
0996:                Name n = new Name(in);
0997:                assertEquals(in, n.toString());
0998:            }
0999:
1000:            public void test_toString_escaped() throws TextParseException {
1001:                String in = "my.escaped.junk\\128.label.";
1002:                Name n = new Name(in);
1003:                assertEquals(in, n.toString());
1004:            }
1005:
1006:            public void test_toString_special_char() throws TextParseException,
1007:                    WireParseException {
1008:                byte[] raw = new byte[] { 1, '"', 1, '(', 1, ')', 1, '.', 1,
1009:                        ';', 1, '\\', 1, '@', 1, '$', 0 };
1010:                String exp = "\\\".\\(.\\).\\..\\;.\\\\.\\@.\\$.";
1011:                Name n = new Name(new DNSInput(raw));
1012:                assertEquals(exp, n.toString());
1013:            }
1014:
1015:            public static class Test_toWire extends TestCase {
1016:                public void test_rel() throws TextParseException {
1017:                    Name n = new Name("A.Relative.Name");
1018:                    try {
1019:                        n.toWire(new DNSOutput(), null);
1020:                        fail("IllegalArgumentException not thrown");
1021:                    } catch (IllegalArgumentException e) {
1022:                    }
1023:                }
1024:
1025:                public void test_null_Compression() throws TextParseException {
1026:                    byte[] raw = new byte[] { 1, 'A', 5, 'B', 'a', 's', 'i',
1027:                            'c', 4, 'N', 'a', 'm', 'e', 0 };
1028:                    Name n = new Name("A.Basic.Name.");
1029:
1030:                    DNSOutput o = new DNSOutput();
1031:                    n.toWire(o, null);
1032:
1033:                    assertTrue(Arrays.equals(raw, o.toByteArray()));
1034:                }
1035:
1036:                public void test_empty_Compression() throws TextParseException {
1037:                    byte[] raw = new byte[] { 1, 'A', 5, 'B', 'a', 's', 'i',
1038:                            'c', 4, 'N', 'a', 'm', 'e', 0 };
1039:                    Name n = new Name("A.Basic.Name.");
1040:
1041:                    Compression c = new Compression();
1042:                    DNSOutput o = new DNSOutput();
1043:                    n.toWire(o, c);
1044:
1045:                    assertTrue(Arrays.equals(raw, o.toByteArray()));
1046:                    assertEquals(0, c.get(n));
1047:                }
1048:
1049:                public void test_with_exact_Compression()
1050:                        throws TextParseException {
1051:                    Name n = new Name("A.Basic.Name.");
1052:
1053:                    Compression c = new Compression();
1054:                    c.add(256, n);
1055:                    byte[] exp = new byte[] { (byte) 0xC1, 0x0 };
1056:
1057:                    DNSOutput o = new DNSOutput();
1058:                    n.toWire(o, c);
1059:                    assertTrue(Arrays.equals(exp, o.toByteArray()));
1060:                    assertEquals(256, c.get(n));
1061:                }
1062:
1063:                public void test_with_partial_Compression()
1064:                        throws TextParseException {
1065:                    Name d = new Name("Basic.Name.");
1066:                    Name n = new Name("A.Basic.Name.");
1067:
1068:                    Compression c = new Compression();
1069:                    c.add(257, d);
1070:                    byte[] exp = new byte[] { 1, 'A', (byte) 0xC1, 0x1 };
1071:
1072:                    DNSOutput o = new DNSOutput();
1073:                    n.toWire(o, c);
1074:                    assertTrue(Arrays.equals(exp, o.toByteArray()));
1075:                    assertEquals(257, c.get(d));
1076:                    assertEquals(0, c.get(n));
1077:                }
1078:
1079:                public void test_0arg_rel() throws TextParseException {
1080:                    Name n = new Name("A.Relative.Name");
1081:                    try {
1082:                        n.toWire();
1083:                        fail("IllegalArgumentException not thrown");
1084:                    } catch (IllegalArgumentException e) {
1085:                    }
1086:                }
1087:
1088:                public void test_0arg() throws TextParseException {
1089:                    byte[] raw = new byte[] { 1, 'A', 5, 'B', 'a', 's', 'i',
1090:                            'c', 4, 'N', 'a', 'm', 'e', 0 };
1091:                    Name n = new Name("A.Basic.Name.");
1092:
1093:                    byte[] out = n.toWire();
1094:
1095:                    assertTrue(Arrays.equals(raw, out));
1096:                }
1097:
1098:                public void test_root() {
1099:                    byte[] out = Name.root.toWire();
1100:                    assertTrue(Arrays.equals(new byte[] { 0 }, out));
1101:                }
1102:
1103:                public void test_3arg() throws TextParseException {
1104:                    Name d = new Name("Basic.Name.");
1105:                    Name n = new Name("A.Basic.Name.");
1106:
1107:                    Compression c = new Compression();
1108:                    c.add(257, d);
1109:                    byte[] exp = new byte[] { 1, 'A', (byte) 0xC1, 0x1 };
1110:
1111:                    DNSOutput o = new DNSOutput();
1112:                    n.toWire(o, c, false);
1113:                    assertTrue(Arrays.equals(exp, o.toByteArray()));
1114:                    assertEquals(257, c.get(d));
1115:                    assertEquals(0, c.get(n));
1116:                }
1117:            }
1118:
1119:            public static class Test_toWireCanonical extends TestCase {
1120:                public void test_basic() throws TextParseException {
1121:                    byte[] raw = new byte[] { 1, 'a', 5, 'b', 'a', 's', 'i',
1122:                            'c', 4, 'n', 'a', 'm', 'e', 0 };
1123:                    Name n = new Name("A.Basic.Name.");
1124:
1125:                    DNSOutput o = new DNSOutput();
1126:                    n.toWireCanonical(o);
1127:
1128:                    assertTrue(Arrays.equals(raw, o.toByteArray()));
1129:                }
1130:
1131:                public void test_0arg() throws TextParseException {
1132:                    byte[] raw = new byte[] { 1, 'a', 5, 'b', 'a', 's', 'i',
1133:                            'c', 4, 'n', 'a', 'm', 'e', 0 };
1134:                    Name n = new Name("A.Basic.Name.");
1135:
1136:                    byte[] out = n.toWireCanonical();
1137:
1138:                    assertTrue(Arrays.equals(raw, out));
1139:                }
1140:
1141:                public void test_root() {
1142:                    byte[] out = Name.root.toWireCanonical();
1143:                    assertTrue(Arrays.equals(new byte[] { 0 }, out));
1144:                }
1145:
1146:                public void test_empty() throws TextParseException {
1147:                    Name n = new Name("@", null);
1148:                    byte[] out = n.toWireCanonical();
1149:                    assertTrue(Arrays.equals(new byte[0], out));
1150:                }
1151:
1152:                public void test_3arg() throws TextParseException {
1153:                    Name d = new Name("Basic.Name.");
1154:                    Name n = new Name("A.Basic.Name.");
1155:
1156:                    Compression c = new Compression();
1157:                    c.add(257, d);
1158:                    byte[] exp = new byte[] { 1, 'a', 5, 'b', 'a', 's', 'i',
1159:                            'c', 4, 'n', 'a', 'm', 'e', 0 };
1160:
1161:                    DNSOutput o = new DNSOutput();
1162:                    n.toWire(o, c, true);
1163:                    assertTrue(Arrays.equals(exp, o.toByteArray()));
1164:                    assertEquals(257, c.get(d));
1165:                    assertEquals(-1, c.get(n));
1166:                }
1167:            }
1168:
1169:            public static class Test_equals extends TestCase {
1170:                public void test_same() throws TextParseException {
1171:                    Name n = new Name("A.Name.");
1172:                    assertTrue(n.equals(n));
1173:                }
1174:
1175:                public void test_null() throws TextParseException {
1176:                    Name n = new Name("A.Name.");
1177:                    assertFalse(n.equals(null));
1178:                }
1179:
1180:                public void test_notName() throws TextParseException {
1181:                    Name n = new Name("A.Name.");
1182:                    assertFalse(n.equals(new Object()));
1183:                }
1184:
1185:                public void test_abs() throws TextParseException {
1186:                    Name n = new Name("A.Name.");
1187:                    Name n2 = new Name("a.name.");
1188:
1189:                    assertTrue(n.equals(n2));
1190:                    assertTrue(n2.equals(n));
1191:                }
1192:
1193:                public void test_rel() throws TextParseException {
1194:                    Name n1 = new Name("A.Relative.Name");
1195:                    Name n2 = new Name("a.relative.name");
1196:
1197:                    assertTrue(n1.equals(n2));
1198:                    assertTrue(n2.equals(n1));
1199:                }
1200:
1201:                public void test_mixed() throws TextParseException {
1202:                    Name n1 = new Name("A.Name");
1203:                    Name n2 = new Name("a.name.");
1204:
1205:                    assertFalse(n1.equals(n2));
1206:                    assertFalse(n2.equals(n1));
1207:                }
1208:
1209:                public void test_weird() throws TextParseException {
1210:                    Name n1 = new Name("ab.c");
1211:                    Name n2 = new Name("abc.");
1212:
1213:                    assertFalse(n1.equals(n2));
1214:                    assertFalse(n2.equals(n1));
1215:                }
1216:            }
1217:
1218:            public static class Test_compareTo extends TestCase {
1219:                public void test_notName() throws TextParseException {
1220:                    Name n = new Name("A.Name");
1221:                    try {
1222:                        n.compareTo(new Object());
1223:                        fail("ClassCastException not thrown");
1224:                    } catch (ClassCastException e) {
1225:                    }
1226:                }
1227:
1228:                public void test_same() throws TextParseException {
1229:                    Name n = new Name("A.Name");
1230:                    assertEquals(0, n.compareTo(n));
1231:                }
1232:
1233:                public void test_equal() throws TextParseException {
1234:                    Name n1 = new Name("A.Name.");
1235:                    Name n2 = new Name("a.name.");
1236:
1237:                    assertEquals(0, n1.compareTo(n2));
1238:                    assertEquals(0, n2.compareTo(n1));
1239:                }
1240:
1241:                public void test_close() throws TextParseException {
1242:                    Name n1 = new Name("a.name");
1243:                    Name n2 = new Name("a.name.");
1244:
1245:                    assertTrue(n1.compareTo(n2) > 0);
1246:                    assertTrue(n2.compareTo(n1) < 0);
1247:                }
1248:
1249:                public void test_disjoint() throws TextParseException {
1250:                    Name n1 = new Name("b");
1251:                    Name n2 = new Name("c");
1252:
1253:                    assertTrue(n1.compareTo(n2) < 0);
1254:                    assertTrue(n2.compareTo(n1) > 0);
1255:                }
1256:
1257:                public void test_label_prefix() throws TextParseException {
1258:                    Name n1 = new Name("thisIs.a.");
1259:                    Name n2 = new Name("thisIsGreater.a.");
1260:
1261:                    assertTrue(n1.compareTo(n2) < 0);
1262:                    assertTrue(n2.compareTo(n1) > 0);
1263:                }
1264:
1265:                public void test_more_labels() throws TextParseException {
1266:                    Name n1 = new Name("c.b.a.");
1267:                    Name n2 = new Name("d.c.b.a.");
1268:
1269:                    assertTrue(n1.compareTo(n2) < 0);
1270:                    assertTrue(n2.compareTo(n1) > 0);
1271:                }
1272:            }
1273:
1274:            public static Test suite() {
1275:                TestSuite s = new TestSuite();
1276:                s.addTestSuite(Test_String_init.class);
1277:                s.addTestSuite(Test_DNSInput_init.class);
1278:                s.addTestSuite(NameTest.class);
1279:                s.addTestSuite(Test_toWire.class);
1280:                s.addTestSuite(Test_toWireCanonical.class);
1281:                s.addTestSuite(Test_equals.class);
1282:                s.addTestSuite(Test_compareTo.class);
1283:                return s;
1284:            }
1285:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.