001: /*
002: * @(#)AnalysisModuleDataUTest.java
003: *
004: * Copyright (C) 2003 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.report;
028:
029: import java.io.File;
030: import java.io.IOException;
031:
032: import junit.framework.Test;
033: import junit.framework.TestCase;
034: import junit.framework.TestSuite;
035: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
036: import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
037: import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
038: import net.sourceforge.groboutils.codecoverage.v2.datastore.DirMetaDataReader;
039: import net.sourceforge.groboutils.codecoverage.v2.logger.DirectoryChannelLogReader;
040:
041: /**
042: * Tests the AnalysisModuleData class.
043: *
044: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
045: * @version $Date: 2004/04/15 05:48:29 $
046: * @since January 22, 2003
047: */
048: public class AnalysisModuleDataUTest extends TestCase {
049: //-------------------------------------------------------------------------
050: // Standard JUnit Class-specific declarations
051:
052: private static final Class THIS_CLASS = AnalysisModuleDataUTest.class;
053: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
054:
055: public AnalysisModuleDataUTest(String name) {
056: super (name);
057: }
058:
059: //-------------------------------------------------------------------------
060: // Tests
061:
062: public void testConstructor1() throws Exception {
063: try {
064: new AnalysisModuleData(null, null, null);
065: fail("Did not throw IllegalArgumentException.");
066: } catch (IllegalArgumentException e) {
067: }
068: }
069:
070: public void testConstructor2() throws Exception {
071: try {
072: new AnalysisModuleData(
073: createIAnalysisModule("a", "b", "c"), null, null);
074: fail("Did not throw IllegalArgumentException.");
075: } catch (IllegalArgumentException e) {
076: }
077: }
078:
079: public void testConstructor3() throws Exception {
080: File f = CCCreatorUtil.createNewDirectory();
081: try {
082: new AnalysisModuleData(
083: createIAnalysisModule("a", "b", "c"),
084: createDirMetaDataReader(f), null);
085: fail("Did not throw IllegalArgumentException.");
086: } catch (IllegalArgumentException e) {
087: }
088: }
089:
090: public void testConstructor4() throws Exception {
091: File f = CCCreatorUtil.createNewDirectory();
092: try {
093: new AnalysisModuleData(null, createDirMetaDataReader(f),
094: createDirectoryChannelLogReader(f,
095: createClassLogData(4)));
096: fail("Did not throw IllegalArgumentException.");
097: } catch (IllegalArgumentException e) {
098: }
099: }
100:
101: public void testConstructor5() throws Exception {
102: File f = CCCreatorUtil.createNewDirectory();
103: try {
104: new AnalysisModuleData(
105: createIAnalysisModule("a", "b", "c"), null,
106: createDirectoryChannelLogReader(f,
107: createClassLogData(2)));
108: fail("Did not throw IllegalArgumentException.");
109: } catch (IllegalArgumentException e) {
110: }
111: }
112:
113: public void testGetClassSignatures1() throws Exception {
114: File f = CCCreatorUtil.createNewDirectory();
115: AnalysisModuleData amd = new AnalysisModuleData(
116: createIAnalysisModule("a", "b", "c"),
117: createDirMetaDataReader(f),
118: createDirectoryChannelLogReader(f,
119: createClassLogData(1)));
120: String sigs[] = amd.getClassSignatures();
121: assertNotNull("Got null sigs.", sigs);
122: DOC
123: .getLog()
124: .warn(
125: "this test is failing due to incorrect class generation logic.");
126: /*
127: assertEquals(
128: "Didn't get correct number of classes.",
129: 1,
130: sigs.length );
131: assertEquals(
132: "Did not return correct class name.",
133: "a.MyClass-112",
134: sigs[0] );
135: */
136: }
137:
138: public void testGetClassSignatures2() throws Exception {
139: File f = CCCreatorUtil.createNewDirectory();
140: AnalysisModuleData amd = new AnalysisModuleData(
141: createIAnalysisModule("a", "b", "c"),
142: createDirMetaDataReader(f),
143: createDirectoryChannelLogReader(f,
144: createClassLogData(2)));
145: String sigs[] = amd.getClassSignatures();
146: assertNotNull("Got null sigs.", sigs);
147: DOC
148: .getLog()
149: .warn(
150: "this test is failing due to incorrect class generation logic.");
151: /*
152: assertEquals(
153: "Didn't get correct number of classes.",
154: 2,
155: sigs.length );
156: */
157: }
158:
159: public void testGetClassSignatures3() throws Exception {
160: File f = CCCreatorUtil.createNewDirectory();
161: AnalysisModuleData amd = new AnalysisModuleData(
162: createIAnalysisModule("a", "b", "c"),
163: createDirMetaDataReader(f),
164: createDirectoryChannelLogReader(f,
165: createClassLogData(0)));
166: String sigs[] = amd.getClassSignatures();
167: assertNotNull("Got null sigs.", sigs);
168: assertEquals("Didn't get correct number of classes.", 0,
169: sigs.length);
170: }
171:
172: //-------------------------------------------------------------------------
173: // Helpers
174:
175: protected IAnalysisModule createIAnalysisModule(String name,
176: String unit, String mime) {
177: return CCCreatorUtil.createIAnalysisModule(name, unit, mime);
178: }
179:
180: protected DirMetaDataReader createDirMetaDataReader(File basedir)
181: throws IOException {
182: return CCCreatorUtil.createDirMetaDataReader(basedir,
183: new Class[] { THIS_CLASS, String.class }, CCCreatorUtil
184: .createAnalysisModules(2));
185: }
186:
187: protected DirectoryChannelLogReader createDirectoryChannelLogReader(
188: File basedir, CCCreatorUtil.SimpleClassLogData[] data) {
189: return CCCreatorUtil.createDirectoryChannelLogReader(basedir,
190: data, (short) 100);
191: }
192:
193: protected CCCreatorUtil.SimpleClassLogData[] createClassLogData(
194: int count) {
195: CCCreatorUtil.SimpleClassLogData[] scld = new CCCreatorUtil.SimpleClassLogData[count];
196: for (int i = 0; i < count; ++i) {
197: scld[i] = new CCCreatorUtil.SimpleClassLogData(
198: (char) ('a' + i) + ".MyClass-112", new int[] { 1,
199: 2, 1 }, new int[] { 11, 2, 13 });
200: }
201: return scld;
202: }
203:
204: //-------------------------------------------------------------------------
205: // Standard JUnit declarations
206:
207: public static Test suite() {
208: TestSuite suite = new TestSuite(THIS_CLASS);
209:
210: return suite;
211: }
212:
213: public static void main(String[] args) {
214: String[] name = { THIS_CLASS.getName() };
215:
216: // junit.textui.TestRunner.main( name );
217: // junit.swingui.TestRunner.main( name );
218:
219: junit.textui.TestRunner.main(name);
220: }
221:
222: /**
223: *
224: * @exception Exception thrown under any exceptional condition.
225: */
226: protected void setUp() throws Exception {
227: super .setUp();
228:
229: // set ourself up
230: }
231:
232: /**
233: *
234: * @exception Exception thrown under any exceptional condition.
235: */
236: protected void tearDown() throws Exception {
237: // tear ourself down
238:
239: super.tearDown();
240: }
241: }
|