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 java.util.Arrays;
039: import junit.framework.TestCase;
040:
041: public class HINFORecordTest extends TestCase {
042: public void test_ctor_0arg() {
043: HINFORecord dr = new HINFORecord();
044: assertNull(dr.getName());
045: assertEquals(0, dr.getType());
046: assertEquals(0, dr.getDClass());
047: assertEquals(0, dr.getTTL());
048: }
049:
050: public void test_getObject() {
051: HINFORecord dr = new HINFORecord();
052: Record r = dr.getObject();
053: assertTrue(r instanceof HINFORecord);
054: }
055:
056: public void test_ctor_5arg() throws TextParseException {
057: Name n = Name.fromString("The.Name.");
058: long ttl = 0xABCDL;
059: String cpu = "i686 Intel(R) Pentium(R) M processor 1.70GHz GenuineIntel GNU/Linux";
060: String os = "Linux troy 2.6.10-gentoo-r6 #8 Wed Apr 6 21:25:04 MDT 2005";
061:
062: HINFORecord dr = new HINFORecord(n, DClass.IN, ttl, cpu, os);
063: assertEquals(n, dr.getName());
064: assertEquals(DClass.IN, dr.getDClass());
065: assertEquals(Type.HINFO, dr.getType());
066: assertEquals(ttl, dr.getTTL());
067: assertEquals(cpu, dr.getCPU());
068: assertEquals(os, dr.getOS());
069: }
070:
071: public void test_ctor_5arg_invalid_CPU() throws TextParseException {
072: Name n = Name.fromString("The.Name.");
073: long ttl = 0xABCDL;
074: String cpu = "i686 Intel(R) Pentium(R) M \\256 processor 1.70GHz GenuineIntel GNU/Linux";
075: String os = "Linux troy 2.6.10-gentoo-r6 #8 Wed Apr 6 21:25:04 MDT 2005";
076:
077: try {
078: new HINFORecord(n, DClass.IN, ttl, cpu, os);
079: fail("IllegalArgumentException not thrown");
080: } catch (IllegalArgumentException e) {
081: }
082: }
083:
084: public void test_ctor_5arg_invalid_OS() throws TextParseException {
085: Name n = Name.fromString("The.Name.");
086: long ttl = 0xABCDL;
087: String cpu = "i686 Intel(R) Pentium(R) M processor 1.70GHz GenuineIntel GNU/Linux";
088: String os = "Linux troy 2.6.10-gentoo-r6 \\1 #8 Wed Apr 6 21:25:04 MDT 2005";
089:
090: try {
091: new HINFORecord(n, DClass.IN, ttl, cpu, os);
092: fail("IllegalArgumentException not thrown");
093: } catch (IllegalArgumentException e) {
094: }
095: }
096:
097: public void test_rrFromWire() throws IOException {
098: String cpu = "Intel(R) Pentium(R) M processor 1.70GHz";
099: String os = "Linux troy 2.6.10-gentoo-r6";
100:
101: byte[] raw = new byte[] { 39, 'I', 'n', 't', 'e', 'l', '(',
102: 'R', ')', ' ', 'P', 'e', 'n', 't', 'i', 'u', 'm', '(',
103: 'R', ')', ' ', 'M', ' ', 'p', 'r', 'o', 'c', 'e', 's',
104: 's', 'o', 'r', ' ', '1', '.', '7', '0', 'G', 'H', 'z',
105: 27, 'L', 'i', 'n', 'u', 'x', ' ', 't', 'r', 'o', 'y',
106: ' ', '2', '.', '6', '.', '1', '0', '-', 'g', 'e', 'n',
107: 't', 'o', 'o', '-', 'r', '6' };
108:
109: DNSInput in = new DNSInput(raw);
110:
111: HINFORecord dr = new HINFORecord();
112: dr.rrFromWire(in);
113: assertEquals(cpu, dr.getCPU());
114: assertEquals(os, dr.getOS());
115: }
116:
117: public void test_rdataFromString() throws IOException {
118: String cpu = "Intel(R) Pentium(R) M processor 1.70GHz";
119: String os = "Linux troy 2.6.10-gentoo-r6";
120:
121: Tokenizer t = new Tokenizer("\"" + cpu + "\" \"" + os + "\"");
122:
123: HINFORecord dr = new HINFORecord();
124: dr.rdataFromString(t, null);
125: assertEquals(cpu, dr.getCPU());
126: assertEquals(os, dr.getOS());
127: }
128:
129: public void test_rdataFromString_invalid_CPU() throws IOException {
130: String cpu = "Intel(R) Pentium(R) \\388 M processor 1.70GHz";
131: String os = "Linux troy 2.6.10-gentoo-r6";
132:
133: Tokenizer t = new Tokenizer("\"" + cpu + "\" \"" + os + "\"");
134:
135: HINFORecord dr = new HINFORecord();
136: try {
137: dr.rdataFromString(t, null);
138: fail("TextParseException not thrown");
139: } catch (TextParseException e) {
140: }
141: }
142:
143: public void test_rdataFromString_invalid_OS() throws IOException {
144: String cpu = "Intel(R) Pentium(R) M processor 1.70GHz";
145:
146: Tokenizer t = new Tokenizer("\"" + cpu + "\"");
147:
148: HINFORecord dr = new HINFORecord();
149: try {
150: dr.rdataFromString(t, null);
151: fail("TextParseException not thrown");
152: } catch (TextParseException e) {
153: }
154: }
155:
156: public void test_rrToString() throws TextParseException {
157: String cpu = "Intel(R) Pentium(R) M processor 1.70GHz";
158: String os = "Linux troy 2.6.10-gentoo-r6";
159:
160: String exp = "\"" + cpu + "\" \"" + os + "\"";
161:
162: HINFORecord dr = new HINFORecord(Name.fromString("The.Name."),
163: DClass.IN, 0x123, cpu, os);
164: assertEquals(exp, dr.rrToString());
165: }
166:
167: public void test_rrToWire() throws TextParseException {
168: String cpu = "Intel(R) Pentium(R) M processor 1.70GHz";
169: String os = "Linux troy 2.6.10-gentoo-r6";
170: byte[] raw = new byte[] { 39, 'I', 'n', 't', 'e', 'l', '(',
171: 'R', ')', ' ', 'P', 'e', 'n', 't', 'i', 'u', 'm', '(',
172: 'R', ')', ' ', 'M', ' ', 'p', 'r', 'o', 'c', 'e', 's',
173: 's', 'o', 'r', ' ', '1', '.', '7', '0', 'G', 'H', 'z',
174: 27, 'L', 'i', 'n', 'u', 'x', ' ', 't', 'r', 'o', 'y',
175: ' ', '2', '.', '6', '.', '1', '0', '-', 'g', 'e', 'n',
176: 't', 'o', 'o', '-', 'r', '6' };
177:
178: HINFORecord dr = new HINFORecord(Name.fromString("The.Name."),
179: DClass.IN, 0x123, cpu, os);
180:
181: DNSOutput out = new DNSOutput();
182: dr.rrToWire(out, null, true);
183:
184: assertTrue(Arrays.equals(raw, out.toByteArray()));
185: }
186: }
|