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.utils;
036:
037: import junit.framework.TestCase;
038:
039: public class hexdumpTest extends TestCase {
040: public hexdumpTest(String name) {
041: super (name);
042: }
043:
044: /*
045: * this seems to be basically a debugging routine, so its most
046: * important to check that the values are all rendered correctly,
047: * not the formatting.
048: */
049:
050: public void test_shortform() {
051: byte[] data = new byte[] { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
052: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
053: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, };
054: String desc = "This Is My Description";
055:
056: // compare against output from the long form
057: String long_out = hexdump.dump(desc, data, 0, data.length);
058: String short_out = hexdump.dump(desc, data);
059:
060: assertEquals(long_out, short_out);
061: }
062:
063: public void test_0() {
064: byte[] data = new byte[] { 1, 0, 2 };
065: String out = hexdump.dump(null, data, 1, 1);
066: assertEquals("1b:\t00 \n", out);
067: }
068:
069: public void test_1() {
070: byte[] data = new byte[] { 2, 1, 3 };
071: String out = hexdump.dump(null, data, 1, 1);
072: assertEquals("1b:\t01 \n", out);
073: }
074:
075: public void test_2() {
076: byte[] data = new byte[] { 1, 2, 3 };
077: String out = hexdump.dump(null, data, 1, 1);
078: assertEquals("1b:\t02 \n", out);
079: }
080:
081: public void test_3() {
082: byte[] data = new byte[] { 1, 3, 2 };
083: String out = hexdump.dump(null, data, 1, 1);
084: assertEquals("1b:\t03 \n", out);
085: }
086:
087: public void test_4() {
088: byte[] data = new byte[] { 1, 4, 2 };
089: String out = hexdump.dump(null, data, 1, 1);
090: assertEquals("1b:\t04 \n", out);
091: }
092:
093: public void test_5() {
094: byte[] data = new byte[] { 1, 5, 2 };
095: String out = hexdump.dump(null, data, 1, 1);
096: assertEquals("1b:\t05 \n", out);
097: }
098:
099: public void test_6() {
100: byte[] data = new byte[] { 1, 6, 2 };
101: String out = hexdump.dump(null, data, 1, 1);
102: assertEquals("1b:\t06 \n", out);
103: }
104:
105: public void test_7() {
106: byte[] data = new byte[] { 1, 7, 2 };
107: String out = hexdump.dump(null, data, 1, 1);
108: assertEquals("1b:\t07 \n", out);
109: }
110:
111: public void test_8() {
112: byte[] data = new byte[] { 1, 8, 2 };
113: String out = hexdump.dump(null, data, 1, 1);
114: assertEquals("1b:\t08 \n", out);
115: }
116:
117: public void test_9() {
118: byte[] data = new byte[] { 1, 9, 2 };
119: String out = hexdump.dump(null, data, 1, 1);
120: assertEquals("1b:\t09 \n", out);
121: }
122:
123: public void test_10() {
124: byte[] data = new byte[] { 1, 10, 2 };
125: String out = hexdump.dump(null, data, 1, 1);
126: assertEquals("1b:\t0A \n", out);
127: }
128:
129: public void test_11() {
130: byte[] data = new byte[] { 1, 11, 2 };
131: String out = hexdump.dump(null, data, 1, 1);
132: assertEquals("1b:\t0B \n", out);
133: }
134:
135: public void test_12() {
136: byte[] data = new byte[] { 1, 12, 2 };
137: String out = hexdump.dump(null, data, 1, 1);
138: assertEquals("1b:\t0C \n", out);
139: }
140:
141: public void test_13() {
142: byte[] data = new byte[] { 1, 13, 2 };
143: String out = hexdump.dump(null, data, 1, 1);
144: assertEquals("1b:\t0D \n", out);
145: }
146:
147: public void test_14() {
148: byte[] data = new byte[] { 1, 14, 2 };
149: String out = hexdump.dump(null, data, 1, 1);
150: assertEquals("1b:\t0E \n", out);
151: }
152:
153: public void test_15() {
154: byte[] data = new byte[] { 1, 15, 2 };
155: String out = hexdump.dump(null, data, 1, 1);
156: assertEquals("1b:\t0F \n", out);
157: }
158:
159: // strictly for stupid code coverage...a useless test
160: public void test_default_constructor() {
161: new hexdump();
162: }
163: }
|