001: /*
002: * @(#)HexUtilUTest.java
003: *
004: * Copyright (C) 2004 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.codecoverage.v2.util;
028:
029: import java.util.zip.CRC32;
030:
031: import junit.framework.Test;
032: import junit.framework.TestCase;
033: import junit.framework.TestSuite;
034: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
035:
036: /**
037: * Tests the ChecksumUtil class.
038: *
039: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
040: * @version $Date: 2004/07/07 09:39:14 $
041: * @since July 7, 2004
042: */
043: public class HexUtilUTest extends TestCase {
044: //-------------------------------------------------------------------------
045: // Standard JUnit Class-specific declarations
046:
047: private static final Class THIS_CLASS = HexUtilUTest.class;
048: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
049:
050: public HexUtilUTest(String name) {
051: super (name);
052: }
053:
054: //-------------------------------------------------------------------------
055: // Tests
056:
057: public void testGetInstance() {
058: assertNotNull("getInstance must never return null.", HexUtil
059: .getInstance());
060: }
061:
062: public void testParseTwoHex1() {
063: assertFalse("Null TS", HexUtil.getInstance().parseTwoHex("a a",
064: null, ' ', 0));
065: }
066:
067: public void testParseTwoHex2() {
068: HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
069: assertFalse("Null string", HexUtil.getInstance().parseTwoHex(
070: null, ts, ' ', 0));
071: }
072:
073: public void testParseTwoHex3() {
074: HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
075: assertFalse("Negative start", HexUtil.getInstance()
076: .parseTwoHex("a a", ts, ' ', -1));
077: }
078:
079: public void testParseTwoHex4() {
080: HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
081: assertFalse("No separator", HexUtil.getInstance().parseTwoHex(
082: "a", ts, ' ', 0));
083: }
084:
085: public void testParseTwoHex5() {
086: HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
087: assertFalse("No separator after start", HexUtil.getInstance()
088: .parseTwoHex("a a", ts, ' ', 2));
089: }
090:
091: public void testParseTwoHex6() {
092: HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
093: assertFalse("Start is after string length", HexUtil
094: .getInstance().parseTwoHex("x x", ts, ' ', 12));
095: }
096:
097: public void testParseTwoHex7() {
098: HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
099: assertTrue("Should have parsed correctly", HexUtil
100: .getInstance().parseTwoHex("0AAA F", ts, ' ', 0));
101: assertEquals("Bad first string translate", 0x0AAA, ts.a);
102: assertEquals("Bad second string translate", 0xF, ts.b);
103: }
104:
105: public void testParseTwoHex8() {
106: HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
107: assertTrue("Should have parsed correctly", HexUtil
108: .getInstance().parseTwoHex(" 0BB 12", ts, ' ', 1));
109: assertEquals("Bad first string translate", 0x0BB, ts.a);
110: assertEquals("Bad second string translate", 0x12, ts.b);
111: }
112:
113: public void testParseTwoHex9() {
114: HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
115: assertTrue("Should have parsed correctly", HexUtil
116: .getInstance().parseTwoHex("1 2 ", ts, ' ', 0));
117: assertEquals("Bad first string translate", 0x1, ts.a);
118: assertEquals("Bad second string translate", 0x2, ts.b);
119: }
120:
121: public void testParseTwoHex10() {
122: HexUtil.TwoShorts ts = new HexUtil.TwoShorts();
123: ts.a = ts.b = -1;
124: assertTrue("Should have parsed correctly", HexUtil
125: .getInstance().parseTwoHex("0 0", ts, ' ', 0));
126: assertEquals("Bad first string translate", 0x0, ts.a);
127: assertEquals("Bad second string translate", 0x0, ts.b);
128: }
129:
130: //-------------------------------------------------------------------------
131: // Standard JUnit declarations
132:
133: public static Test suite() {
134: TestSuite suite = new TestSuite(THIS_CLASS);
135:
136: return suite;
137: }
138:
139: public static void main(String[] args) {
140: String[] name = { THIS_CLASS.getName() };
141:
142: // junit.textui.TestRunner.main( name );
143: // junit.swingui.TestRunner.main( name );
144:
145: junit.textui.TestRunner.main(name);
146: }
147:
148: /**
149: *
150: * @exception Exception thrown under any exceptional condition.
151: */
152: protected void setUp() throws Exception {
153: super .setUp();
154:
155: // set ourself up
156: }
157:
158: /**
159: *
160: * @exception Exception thrown under any exceptional condition.
161: */
162: protected void tearDown() throws Exception {
163: // tear ourself down
164:
165: super.tearDown();
166: }
167: }
|