001: /*
002: * @(#)DirectoryChannelLoggerUTest.java
003: *
004: * Copyright (C) 2003-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.logger;
028:
029: import java.io.File;
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: import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
036:
037: /**
038: * Tests the DirectoryChannelLogger class.
039: *
040: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
041: * @version $Date: 2004/07/07 09:39:13 $
042: * @since January 22, 2003
043: */
044: public class DirectoryChannelLoggerUTest extends TestCase {
045: //-------------------------------------------------------------------------
046: // Standard JUnit Class-specific declarations
047:
048: private static final Class THIS_CLASS = DirectoryChannelLoggerUTest.class;
049: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
050:
051: public DirectoryChannelLoggerUTest(String name) {
052: super (name);
053: }
054:
055: //-------------------------------------------------------------------------
056: // Tests
057:
058: public void testConstructor1() {
059: new DirectoryChannelLogger(null);
060: }
061:
062: public void testNullDir1() {
063: DirectoryChannelLogger dcl = new DirectoryChannelLogger(null);
064: short a = (short) 1;
065: dcl.cover("a", a, a);
066: dcl.cover("b", a, a);
067: dcl.cover("c", a, a);
068: }
069:
070: public void testCreateFile1() {
071: // test the base directory + one up not existing
072: File basedir = CCCreatorUtil.createNewDirectory();
073: File otherDir = new File(basedir, "1");
074: otherDir = new File(otherDir, "2");
075: DirectoryChannelLogger dcl = new DirectoryChannelLogger(
076: otherDir);
077: dcl.cover("a", (short) 1, (short) 1);
078: File outputFile = new File(otherDir, "a.class.log");
079: assertTrue("Incorrectly was able to create output file.",
080: !outputFile.exists());
081: }
082:
083: public void testCreateFile2() {
084: // test the base directory already existing
085: File basedir = CCCreatorUtil.createNewDirectory();
086: DirectoryChannelLogger dcl = new DirectoryChannelLogger(basedir);
087: dcl.cover("a", (short) 1, (short) 1);
088: File outputFile = new File(basedir, "a.class.log");
089: assertTrue("Did not create output file.", outputFile.exists());
090: }
091:
092: public void testCreateFile3() {
093: // test the base directory not existing, but the one up does
094: File basedir = CCCreatorUtil.createNewDirectory();
095: File otherDir = new File(basedir, "1");
096: DirectoryChannelLogger dcl = new DirectoryChannelLogger(
097: otherDir);
098: dcl.cover("a", (short) 1, (short) 1);
099: File outputFile = new File(otherDir, "a.class.log");
100: assertTrue("Did not create output file.", outputFile.exists());
101: }
102:
103: public void testCreateCoverString1() {
104: assertEquals("Didn't convert right", "0001 0004\n",
105: coverString(0x1, 0x4));
106: }
107:
108: public void testCreateCoverString2() {
109: assertEquals("Didn't convert right", "0030 FFDD\n",
110: coverString(0x30, 0xFFDD));
111: }
112:
113: public void testCreateCoverString3() {
114: assertEquals("Didn't convert right", "0000 0000\n",
115: coverString(0x0, 0x0));
116: }
117:
118: //-------------------------------------------------------------------------
119: // Helpers
120:
121: protected String coverString(int a, int b) {
122: char c[] = DirectoryChannelLogger.createCoverString((short) a,
123: (short) b);
124: return new String(c);
125: }
126:
127: //-------------------------------------------------------------------------
128: // Standard JUnit declarations
129:
130: public static Test suite() {
131: TestSuite suite = new TestSuite(THIS_CLASS);
132:
133: return suite;
134: }
135:
136: public static void main(String[] args) {
137: String[] name = { THIS_CLASS.getName() };
138:
139: // junit.textui.TestRunner.main( name );
140: // junit.swingui.TestRunner.main( name );
141:
142: junit.textui.TestRunner.main(name);
143: }
144:
145: /**
146: *
147: * @exception Exception thrown under any exceptional condition.
148: */
149: protected void setUp() throws Exception {
150: super .setUp();
151:
152: // set ourself up
153: }
154:
155: /**
156: *
157: * @exception Exception thrown under any exceptional condition.
158: */
159: protected void tearDown() throws Exception {
160: // tear ourself down
161:
162: super.tearDown();
163: }
164: }
|