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 base16Test extends TestCase {
040: public base16Test(String name) {
041: super (name);
042: }
043:
044: public void test_toString_emptyArray() {
045: String out = base16.toString(new byte[0]);
046: assertEquals("", out);
047: }
048:
049: public void test_toString_singleByte1() {
050: byte[] data = { (byte) 1 };
051: String out = base16.toString(data);
052: assertEquals("01", out);
053: }
054:
055: public void test_toString_singleByte2() {
056: byte[] data = { (byte) 16 };
057: String out = base16.toString(data);
058: assertEquals("10", out);
059: }
060:
061: public void test_toString_singleByte3() {
062: byte[] data = { (byte) 255 };
063: String out = base16.toString(data);
064: assertEquals("FF", out);
065: }
066:
067: public void test_toString_array1() {
068: byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
069: 15 };
070: String out = base16.toString(data);
071: assertEquals("0102030405060708090A0B0C0D0E0F", out);
072: }
073:
074: public void test_fromString_emptyString() {
075: String data = "";
076: byte[] out = base16.fromString(data);
077: assertEquals(0, out.length);
078: }
079:
080: public void test_fromString_invalidStringLength() {
081: String data = "1";
082: byte[] out = base16.fromString(data);
083: assertNull(out);
084: }
085:
086: public void test_fromString_nonHexChars() {
087: String data = "GG";
088: byte[] out = base16.fromString(data);
089: /*
090: * the output is basically encoded as (-1<<4) + -1, not sure
091: * we want an assertion for this.
092: */
093: }
094:
095: public void test_fromString_normal() {
096: String data = "0102030405060708090A0B0C0D0E0F";
097: byte[] out = base16.fromString(data);
098: byte[] exp = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
099: 15 };
100: assertEquals(exp.length, out.length);
101: for (int i = 0; i < exp.length; ++i) {
102: assertEquals(exp[i], out[i]);
103: }
104: }
105: }
|