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 FlagsTest extends TestCase {
040: public void test_string() {
041: // a regular one
042: assertEquals("aa", Flags.string(Flags.AA));
043:
044: // one that doesn't exist
045: assertTrue(Flags.string(12).startsWith("flag"));
046:
047: try {
048: Flags.string(-1);
049: fail("IllegalArgumentException not thrown");
050: } catch (IllegalArgumentException e) {
051: }
052:
053: // (max is 0xF)
054: try {
055: Flags.string(0x10);
056: fail("IllegalArgumentException not thrown");
057: } catch (IllegalArgumentException e) {
058: }
059: }
060:
061: public void test_value() {
062: // regular one
063: assertEquals(Flags.CD, Flags.value("cd"));
064:
065: // one thats undefined but within range
066: assertEquals(13, Flags.value("FLAG13"));
067:
068: // one thats undefined but out of range
069: assertEquals(-1, Flags.value("FLAG" + 0x10));
070:
071: // something that unknown
072: assertEquals(-1, Flags.value("THIS IS DEFINITELY UNKNOWN"));
073:
074: // empty string
075: assertEquals(-1, Flags.value(""));
076: }
077:
078: public void test_isFlag() {
079: try {
080: Flags.isFlag(-1);
081: fail("IllegalArgumentException not thrown");
082: } catch (IllegalArgumentException e) {
083: }
084: assertTrue(Flags.isFlag(0));
085: assertFalse(Flags.isFlag(1)); // opcode
086: assertFalse(Flags.isFlag(2));
087: assertFalse(Flags.isFlag(3));
088: assertFalse(Flags.isFlag(4));
089: assertTrue(Flags.isFlag(5));
090: assertTrue(Flags.isFlag(6));
091: assertTrue(Flags.isFlag(7));
092: assertTrue(Flags.isFlag(8));
093: assertTrue(Flags.isFlag(9));
094: assertTrue(Flags.isFlag(10));
095: assertTrue(Flags.isFlag(11));
096: assertFalse(Flags.isFlag(12));
097: assertFalse(Flags.isFlag(13));
098: assertFalse(Flags.isFlag(14));
099: assertFalse(Flags.isFlag(14));
100: try {
101: Flags.isFlag(16);
102: fail("IllegalArgumentException not thrown");
103: } catch (IllegalArgumentException e) {
104: }
105: }
106: }
|