001: // -*- Java -*-
002: //
003: // Copyright (c) 2005, Matthew J. Rutherford <rutherfo@cs.colorado.edu>
004: // Copyright (c) 2005, University of Colorado at Boulder
005: // All rights reserved.
006: //
007: // Redistribution and use in source and binary forms, with or without
008: // modification, are permitted provided that the following conditions are
009: // met:
010: //
011: // * Redistributions of source code must retain the above copyright
012: // notice, this list of conditions and the following disclaimer.
013: //
014: // * Redistributions in binary form must reproduce the above copyright
015: // notice, this list of conditions and the following disclaimer in the
016: // documentation and/or other materials provided with the distribution.
017: //
018: // * Neither the name of the University of Colorado at Boulder nor the
019: // names of its contributors may be used to endorse or promote
020: // products derived from this software without specific prior written
021: // permission.
022: //
023: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
024: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
025: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
026: // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
027: // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
028: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
029: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
030: // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
031: // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
032: // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
033: // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
034: //
035: package org.xbill.DNS;
036:
037: import java.io.IOException;
038: import junit.framework.TestCase;
039:
040: public class SingleCompressedNameBaseTest extends TestCase {
041: private void assertEquals(byte[] exp, byte[] act) {
042: assertTrue(java.util.Arrays.equals(exp, act));
043: }
044:
045: private static class TestClass extends SingleCompressedNameBase {
046: public TestClass() {
047: }
048:
049: public TestClass(Name name, int type, int dclass, long ttl,
050: Name singleName, String desc) {
051: super (name, type, dclass, ttl, singleName, desc);
052: }
053:
054: public Name getSingleName() {
055: return super .getSingleName();
056: }
057:
058: public Record getObject() {
059: return null;
060: }
061: }
062:
063: public void test_ctor() throws TextParseException {
064: TestClass tc = new TestClass();
065: assertNull(tc.getSingleName());
066:
067: Name n = Name.fromString("my.name.");
068: Name sn = Name.fromString("my.single.name.");
069:
070: tc = new TestClass(n, Type.A, DClass.IN, 100L, sn,
071: "The Description");
072:
073: assertSame(n, tc.getName());
074: assertEquals(Type.A, tc.getType());
075: assertEquals(DClass.IN, tc.getDClass());
076: assertEquals(100L, tc.getTTL());
077: assertSame(sn, tc.getSingleName());
078: }
079:
080: public void test_rrToWire() throws IOException, TextParseException {
081: Name n = Name.fromString("my.name.");
082: Name sn = Name.fromString("My.Single.Name.");
083:
084: // non-canonical (case sensitive)
085: TestClass tc = new TestClass(n, Type.A, DClass.IN, 100L, sn,
086: "The Description");
087: byte[] exp = new byte[] { 2, 'M', 'y', 6, 'S', 'i', 'n', 'g',
088: 'l', 'e', 4, 'N', 'a', 'm', 'e', 0 };
089:
090: DNSOutput dout = new DNSOutput();
091: tc.rrToWire(dout, null, false);
092:
093: byte[] out = dout.toByteArray();
094: assertEquals(exp, out);
095:
096: // canonical (lowercase)
097: tc = new TestClass(n, Type.A, DClass.IN, 100L, sn,
098: "The Description");
099: exp = new byte[] { 2, 'm', 'y', 6, 's', 'i', 'n', 'g', 'l',
100: 'e', 4, 'n', 'a', 'm', 'e', 0 };
101:
102: dout = new DNSOutput();
103: tc.rrToWire(dout, null, true);
104:
105: out = dout.toByteArray();
106: assertEquals(exp, out);
107: }
108: }
|