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.net.InetAddress;
038: import java.net.UnknownHostException;
039: import java.util.Arrays;
040: import junit.framework.Test;
041: import junit.framework.TestCase;
042: import junit.framework.TestSuite;
043:
044: public class MessageTest {
045: public static class Test_init extends TestCase {
046: public void test_0arg() {
047: Message m = new Message();
048: assertTrue(Arrays.equals(new Record[0], m
049: .getSectionArray(0)));
050: assertTrue(Arrays.equals(new Record[0], m
051: .getSectionArray(1)));
052: assertTrue(Arrays.equals(new Record[0], m
053: .getSectionArray(2)));
054: assertTrue(Arrays.equals(new Record[0], m
055: .getSectionArray(3)));
056: try {
057: m.getSectionArray(4);
058: fail("IndexOutOfBoundsException not thrown");
059: } catch (IndexOutOfBoundsException e) {
060: }
061: Header h = m.getHeader();
062: assertEquals(0, h.getCount(0));
063: assertEquals(0, h.getCount(1));
064: assertEquals(0, h.getCount(2));
065: assertEquals(0, h.getCount(3));
066: }
067:
068: public void test_1arg() {
069: Message m = new Message(10);
070: assertEquals(new Header(10).toString(), m.getHeader()
071: .toString());
072: assertTrue(Arrays.equals(new Record[0], m
073: .getSectionArray(0)));
074: assertTrue(Arrays.equals(new Record[0], m
075: .getSectionArray(1)));
076: assertTrue(Arrays.equals(new Record[0], m
077: .getSectionArray(2)));
078: assertTrue(Arrays.equals(new Record[0], m
079: .getSectionArray(3)));
080: try {
081: m.getSectionArray(4);
082: fail("IndexOutOfBoundsException not thrown");
083: } catch (IndexOutOfBoundsException e) {
084: }
085: Header h = m.getHeader();
086: assertEquals(0, h.getCount(0));
087: assertEquals(0, h.getCount(1));
088: assertEquals(0, h.getCount(2));
089: assertEquals(0, h.getCount(3));
090: }
091:
092: public void test_newQuery() throws TextParseException,
093: UnknownHostException {
094: Name n = Name.fromString("The.Name.");
095: ARecord ar = new ARecord(n, DClass.IN, 1, InetAddress
096: .getByName("192.168.101.110"));
097:
098: Message m = Message.newQuery(ar);
099: assertTrue(Arrays.equals(new Record[] { ar }, m
100: .getSectionArray(0)));
101: assertTrue(Arrays.equals(new Record[0], m
102: .getSectionArray(1)));
103: assertTrue(Arrays.equals(new Record[0], m
104: .getSectionArray(2)));
105: assertTrue(Arrays.equals(new Record[0], m
106: .getSectionArray(3)));
107:
108: Header h = m.getHeader();
109: assertEquals(1, h.getCount(0));
110: assertEquals(0, h.getCount(1));
111: assertEquals(0, h.getCount(2));
112: assertEquals(0, h.getCount(3));
113: assertEquals(Opcode.QUERY, h.getOpcode());
114: assertEquals(true, h.getFlag(Flags.RD));
115: }
116:
117: }
118:
119: public static Test suite() {
120: TestSuite s = new TestSuite();
121: s.addTestSuite(Test_init.class);
122: return s;
123: }
124: }
|