001: /*
002: * @(#)AnalysisModuleIOUTest.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.datastore;
028:
029: import java.io.IOException;
030: import java.io.StringReader;
031: import java.io.StringWriter;
032:
033: import junit.framework.Test;
034: import junit.framework.TestCase;
035: import junit.framework.TestSuite;
036: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
037: import net.sourceforge.groboutils.codecoverage.v2.CCCreatorUtil;
038: import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule;
039:
040: /**
041: * Tests the AnalysisModuleIO class.
042: *
043: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
044: * @version $Date: 2004/04/15 05:48:28 $
045: * @since January 7, 2003
046: */
047: public class AnalysisModuleIOUTest extends TestCase {
048: //-------------------------------------------------------------------------
049: // Standard JUnit Class-specific declarations
050:
051: private static final Class THIS_CLASS = AnalysisModuleIOUTest.class;
052: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
053:
054: public AnalysisModuleIOUTest(String name) {
055: super (name);
056: }
057:
058: //-------------------------------------------------------------------------
059: // Tests
060:
061: public void testWriteAnalysisModule1() throws Exception {
062: AnalysisModuleIO amio = new AnalysisModuleIO();
063: StringWriter sw = new StringWriter();
064: IAnalysisModule am = createIAnalysisModule("n", "u", "m");
065:
066: amio.writeAnalysisModule(am, sw);
067:
068: String res = sw.toString();
069: DOC.getLog().info("Wrote module [" + res + "]");
070: assertEquals("Incorrect result format.", "1:n,1:u,1:m", res);
071: }
072:
073: public void testWriteAnalysisModule2() throws Exception {
074: AnalysisModuleIO amio = new AnalysisModuleIO();
075: StringWriter sw = new StringWriter();
076: IAnalysisModule am = createIAnalysisModule("", "", "");
077:
078: amio.writeAnalysisModule(am, sw);
079:
080: String res = sw.toString();
081: DOC.getLog().info("Wrote module [" + res + "]");
082: assertEquals("Incorrect result format.", "0:,0:,0:", res);
083: }
084:
085: public void testWriteAnalysisModule3() throws Exception {
086: AnalysisModuleIO amio = new AnalysisModuleIO();
087: StringWriter sw = new StringWriter();
088: IAnalysisModule am = createIAnalysisModule("aaaa", "bbbb",
089: "1234");
090:
091: amio.writeAnalysisModule(am, sw);
092:
093: String res = sw.toString();
094: DOC.getLog().info("Wrote module [" + res + "]");
095: assertEquals("Incorrect result format.",
096: "4:aaaa,4:bbbb,4:1234", res);
097: }
098:
099: public void testReadAnalysisModule1() throws Exception {
100: AnalysisModuleIO amio = new AnalysisModuleIO();
101: StringReader sr = new StringReader("1:n,1:u,1:m");
102: IAnalysisModule am = amio.readAnalysisModule(sr);
103: assertNotNull("Returned null data.", am);
104: assertEquals("name incorrect.", "n", am.getMeasureName());
105: assertEquals("unit incorrect.", "u", am.getMeasureUnit());
106: assertEquals("instruction weight incorrect.", "m", am
107: .getMimeEncoding());
108: }
109:
110: public void testReadAnalysisMetaData2() throws Exception {
111: AnalysisModuleIO amio = new AnalysisModuleIO();
112: StringReader sr = new StringReader("0: ,0:,0:asdf,");
113: IAnalysisModule am = amio.readAnalysisModule(sr);
114: assertNotNull("Returned null data.", am);
115: assertEquals("name incorrect.", "", am.getMeasureName());
116: assertEquals("unit incorrect.", "", am.getMeasureUnit());
117: assertEquals("instruction weight incorrect.", "", am
118: .getMimeEncoding());
119: }
120:
121: public void testReadAnalysisMetaData3() throws Exception {
122: AnalysisModuleIO amio = new AnalysisModuleIO();
123: StringReader sr = new StringReader("");
124: try {
125: amio.readAnalysisModule(sr);
126: fail("Did not throw IOException.");
127: } catch (IOException ioe) {
128: // verify ioe
129: }
130: }
131:
132: public void testReadAnalysisMetaData4() throws Exception {
133: AnalysisModuleIO amio = new AnalysisModuleIO();
134: StringReader sr = new StringReader("1");
135: try {
136: amio.readAnalysisModule(sr);
137: fail("Did not throw IOException.");
138: } catch (IOException ioe) {
139: // verify ioe
140: }
141: }
142:
143: public void testReadAnalysisMetaData5() throws Exception {
144: AnalysisModuleIO amio = new AnalysisModuleIO();
145: StringReader sr = new StringReader("a:a,1:1,1:1");
146: try {
147: amio.readAnalysisModule(sr);
148: fail("Did not throw IOException.");
149: } catch (IOException ioe) {
150: // verify ioe
151: }
152: }
153:
154: //-------------------------------------------------------------------------
155: // Helpers
156:
157: protected IAnalysisModule createIAnalysisModule(String name,
158: String unit, String mime) {
159: return CCCreatorUtil.createIAnalysisModule(name, unit, mime);
160: }
161:
162: //-------------------------------------------------------------------------
163: // Standard JUnit declarations
164:
165: public static Test suite() {
166: TestSuite suite = new TestSuite(THIS_CLASS);
167:
168: return suite;
169: }
170:
171: public static void main(String[] args) {
172: String[] name = { THIS_CLASS.getName() };
173:
174: // junit.textui.TestRunner.main( name );
175: // junit.swingui.TestRunner.main( name );
176:
177: junit.textui.TestRunner.main(name);
178: }
179:
180: /**
181: *
182: * @exception Exception thrown under any exceptional condition.
183: */
184: protected void setUp() throws Exception {
185: super .setUp();
186:
187: // set ourself up
188: }
189:
190: /**
191: *
192: * @exception Exception thrown under any exceptional condition.
193: */
194: protected void tearDown() throws Exception {
195: // tear ourself down
196:
197: super.tearDown();
198: }
199: }
|