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 junit.framework.TestCase;
038:
039: public class RcodeTest extends TestCase {
040: public void test_string() {
041: // a regular one
042: assertEquals("NXDOMAIN", Rcode.string(Rcode.NXDOMAIN));
043:
044: // one with an alias
045: assertEquals("NOTIMP", Rcode.string(Rcode.NOTIMP));
046:
047: // one that doesn't exist
048: assertTrue(Rcode.string(20).startsWith("RESERVED"));
049:
050: try {
051: Rcode.string(-1);
052: fail("IllegalArgumentException not thrown");
053: } catch (IllegalArgumentException e) {
054: }
055:
056: // (max is 0xFFF)
057: try {
058: Rcode.string(0x1000);
059: fail("IllegalArgumentException not thrown");
060: } catch (IllegalArgumentException e) {
061: }
062: }
063:
064: public void test_TSIGstring() {
065: // a regular one
066: assertEquals("BADSIG", Rcode.TSIGstring(Rcode.BADSIG));
067:
068: // one that doesn't exist
069: assertTrue(Rcode.TSIGstring(20).startsWith("RESERVED"));
070:
071: try {
072: Rcode.TSIGstring(-1);
073: fail("IllegalArgumentException not thrown");
074: } catch (IllegalArgumentException e) {
075: }
076:
077: // (max is 0xFFFF)
078: try {
079: Rcode.string(0x10000);
080: fail("IllegalArgumentException not thrown");
081: } catch (IllegalArgumentException e) {
082: }
083: }
084:
085: public void test_value() {
086: // regular one
087: assertEquals(Rcode.FORMERR, Rcode.value("FORMERR"));
088:
089: // one with alias
090: assertEquals(Rcode.NOTIMP, Rcode.value("NOTIMP"));
091: assertEquals(Rcode.NOTIMP, Rcode.value("NOTIMPL"));
092:
093: // one thats undefined but within range
094: assertEquals(35, Rcode.value("RESERVED35"));
095:
096: // one thats undefined but out of range
097: assertEquals(-1, Rcode.value("RESERVED" + 0x1000));
098:
099: // something that unknown
100: assertEquals(-1, Rcode.value("THIS IS DEFINITELY UNKNOWN"));
101:
102: // empty string
103: assertEquals(-1, Rcode.value(""));
104: }
105: }
|