001: /*
002: * @(#)DirectoryClassChannelLogReaderUTest.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: import java.io.FileWriter;
031: import java.io.IOException;
032:
033: import junit.framework.Test;
034: import junit.framework.TestCase;
035: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
036: import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
037: import net.sourceforge.groboutils.codecoverage.v2.IChannelLogRecord;
038: import net.sourceforge.groboutils.codecoverage.v2.IClassChannelLogReaderUTestI;
039: import net.sourceforge.groboutils.junit.v1.iftc.CxFactory;
040: import net.sourceforge.groboutils.junit.v1.iftc.InterfaceTestSuite;
041:
042: /**
043: * Tests the DirectoryClassChannelLogReader class.
044: *
045: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
046: * @version $Date: 2004/07/07 09:39:13 $
047: * @since January 22, 2003
048: */
049: public class DirectoryClassChannelLogReaderUTest extends TestCase {
050: //-------------------------------------------------------------------------
051: // Standard JUnit Class-specific declarations
052:
053: private static final Class THIS_CLASS = DirectoryClassChannelLogReaderUTest.class;
054: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
055:
056: public DirectoryClassChannelLogReaderUTest(String name) {
057: super (name);
058: }
059:
060: //-------------------------------------------------------------------------
061: // Tests
062:
063: public void testNextRecord1() throws Exception {
064: String sig = "MySig-1";
065: File log = new File(CCCreatorUtil.createNewDirectory(),
066: "test.log");
067: FileWriter fw = new FileWriter(log);
068: fw.write("1 0\n2 2\n0002 0002\n3 1\n");
069: fw.close();
070: DirectoryClassChannelLogReader dcclr = new DirectoryClassChannelLogReader(
071: log, sig);
072: IChannelLogRecord clr;
073: assertChannelLogRecord(dcclr.nextRecord(), sig, 1, 0);
074: assertChannelLogRecord(dcclr.nextRecord(), sig, 2, 2);
075: assertChannelLogRecord(dcclr.nextRecord(), sig, 2, 2);
076: assertChannelLogRecord(dcclr.nextRecord(), sig, 3, 1);
077: assertNull("Didn't return null clr.", dcclr.nextRecord());
078: }
079:
080: //-------------------------------------------------------------------------
081: // Helpers
082:
083: protected void assertChannelLogRecord(IChannelLogRecord clr,
084: String sig, int methodIndex, int markIndex) {
085: assertNotNull("Returned null record.", clr);
086: assertEquals("Didn't return correct signature.", sig, clr
087: .getClassSignature());
088: assertEquals("Didn't return correct method index.",
089: methodIndex, clr.getMethodIndex());
090: assertEquals("Didn't return correct mark index.", markIndex,
091: clr.getMarkIndex());
092: }
093:
094: //-------------------------------------------------------------------------
095: // Standard JUnit declarations
096:
097: public static Test suite() {
098: InterfaceTestSuite suite = IClassChannelLogReaderUTestI.suite();
099: suite.addTestSuite(THIS_CLASS);
100: suite.addFactory(new CxFactory("A") {
101: public Object createImplObject() throws IOException {
102: File log = new File(CCCreatorUtil.createNewDirectory(),
103: "test.log");
104: FileWriter fw = new FileWriter(log);
105: fw.write("1 0\n2 2\n0002 0002\n3 1\n");
106: fw.close();
107: return new DirectoryClassChannelLogReader(log,
108: "MySig-1");
109: }
110: });
111:
112: return suite;
113: }
114:
115: public static void main(String[] args) {
116: String[] name = { THIS_CLASS.getName() };
117:
118: // junit.textui.TestRunner.main( name );
119: // junit.swingui.TestRunner.main( name );
120:
121: junit.textui.TestRunner.main(name);
122: }
123:
124: /**
125: *
126: * @exception Exception thrown under any exceptional condition.
127: */
128: protected void setUp() throws Exception {
129: super .setUp();
130:
131: // set ourself up
132: }
133:
134: /**
135: *
136: * @exception Exception thrown under any exceptional condition.
137: */
138: protected void tearDown() throws Exception {
139: // tear ourself down
140:
141: super.tearDown();
142: }
143: }
|