001: /*
002: * @(#)MarkedInstructionUTest.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.compiler;
028:
029: import junit.framework.Test;
030: import junit.framework.TestCase;
031: import junit.framework.TestSuite;
032: import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
033: import net.sourceforge.groboutils.codecoverage.v2.BCELCreatorUtil;
034:
035: import org.apache.bcel.generic.InstructionHandle;
036: import org.apache.bcel.generic.InstructionList;
037:
038: /**
039: * Tests the MarkedInstruction class.
040: *
041: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
042: * @version $Date: 2004/04/15 05:48:28 $
043: * @since January 13, 2003
044: */
045: public class MarkedInstructionUTest extends TestCase {
046: //-------------------------------------------------------------------------
047: // Standard JUnit Class-specific declarations
048:
049: private static final Class THIS_CLASS = MarkedInstructionUTest.class;
050: private static final AutoDoc DOC = new AutoDoc(THIS_CLASS);
051:
052: public MarkedInstructionUTest(String name) {
053: super (name);
054: }
055:
056: //-------------------------------------------------------------------------
057: // Tests
058:
059: private static final int MARK_INSTRUCTION_COUNT = 5;
060:
061: public void testConstructor1() {
062: try {
063: new MarkedInstruction((short) 0, 0, 0, null);
064: fail("Did not throw IllegalArgumentException.");
065: } catch (IllegalArgumentException e) {
066: // test failure?
067: }
068: }
069:
070: public void testGetInstruction1() {
071: InstructionHandle ih = createInstructionHandle();
072: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
073: ih);
074: assertEquals("Did not return expected instruction.", ih
075: .getInstruction(), mi.getHandle().getInstruction());
076: }
077:
078: public void testAddMark1() {
079: InstructionHandle ih = createInstructionHandle();
080: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
081: ih);
082: mi.addMark((short) 1, Short.MIN_VALUE);
083: }
084:
085: public void testAddMark2() {
086: InstructionHandle ih = createInstructionHandle();
087: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
088: ih);
089: mi.addMark(Short.MIN_VALUE, (short) 1);
090: }
091:
092: public void testAddMark3() {
093: InstructionHandle ih = createInstructionHandle();
094: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
095: ih);
096: mi.addMark((short) 1, Short.MAX_VALUE);
097: }
098:
099: public void testAddMark4() {
100: InstructionHandle ih = createInstructionHandle();
101: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
102: ih);
103: mi.addMark(Short.MAX_VALUE, (short) 1);
104: }
105:
106: public void testGetMarkedList1() {
107: InstructionHandle ih = createInstructionHandle();
108: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
109: ih);
110: InstructionList il = mi.getMarkedList();
111: assertNull("Did not return a null marked list.", il);
112: }
113:
114: public void testGetMarkedList2() {
115: InstructionHandle ih = createInstructionHandle();
116: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
117: ih);
118: mi.addMark((short) 1, (short) 1);
119: InstructionList il = mi.getMarkedList();
120: assertEquals(
121: "Did not return a marked list of the expected size.",
122: MARK_INSTRUCTION_COUNT, il.size());
123: }
124:
125: public void testGetMarkedList3() {
126: InstructionHandle ih = createInstructionHandle();
127: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
128: ih);
129: mi.addMark((short) 1, (short) 1);
130: mi.addMark((short) 1, (short) 1);
131: mi.addMark((short) 1, (short) 1);
132: InstructionList il = mi.getMarkedList();
133: assertEquals(
134: "Did not return a marked list of the expected size.",
135: MARK_INSTRUCTION_COUNT * 3, il.size());
136: }
137:
138: public void testGetMarkedList_state1() {
139: InstructionHandle ih = createInstructionHandle();
140: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
141: ih);
142: mi.getMarkedList();
143:
144: // repeat again without any mark changes
145: InstructionList il = mi.getMarkedList();
146: assertNull("Did not return a null marked list.", il);
147: }
148:
149: public void testGetMarkedList_state2() {
150: InstructionHandle ih = createInstructionHandle();
151: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
152: ih);
153: mi.addMark((short) 1, (short) 1);
154: mi.addMark((short) 1, (short) 1);
155: mi.getMarkedList();
156:
157: // repeat again without any mark changes
158: InstructionList il = mi.getMarkedList();
159: assertNull("Did not return a null marked list.", il);
160: }
161:
162: public void testGetMarkedList_state3() {
163: InstructionHandle ih = createInstructionHandle();
164: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
165: ih);
166: mi.getMarkedList();
167:
168: mi.addMark((short) 1, (short) 1);
169: mi.addMark((short) 1, (short) 1);
170: InstructionList il = mi.getMarkedList();
171: assertEquals(
172: "Did not return a marked list of the expected size.",
173: MARK_INSTRUCTION_COUNT * 2, il.size());
174: }
175:
176: public void testGetMarkedList_state4() {
177: InstructionHandle ih = createInstructionHandle();
178: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
179: ih);
180: mi.addMark((short) 0, (short) 0);
181: mi.addMark((short) 0, (short) 1);
182: mi.addMark((short) 0, (short) 2);
183: mi.getMarkedList();
184:
185: mi.addMark((short) 1, (short) 0);
186: mi.addMark((short) 1, (short) 1);
187: InstructionList il = mi.getMarkedList();
188: assertEquals(
189: "Did not return a marked list of the expected size.",
190: MARK_INSTRUCTION_COUNT * 2, il.size());
191: }
192:
193: public void testGetHandle1() {
194: InstructionHandle ih = createInstructionHandle();
195: MarkedInstruction mi = new MarkedInstruction((short) 0, 0, 0,
196: ih);
197: assertSame("Did not return same handle.", ih, mi.getHandle());
198: }
199:
200: //-------------------------------------------------------------------------
201: // Helpers
202:
203: protected InstructionHandle createInstructionHandle() {
204: return BCELCreatorUtil.createInstructionHandle();
205: }
206:
207: //-------------------------------------------------------------------------
208: // Standard JUnit declarations
209:
210: public static Test suite() {
211: TestSuite suite = new TestSuite(THIS_CLASS);
212:
213: return suite;
214: }
215:
216: public static void main(String[] args) {
217: String[] name = { THIS_CLASS.getName() };
218:
219: // junit.textui.TestRunner.main( name );
220: // junit.swingui.TestRunner.main( name );
221:
222: junit.textui.TestRunner.main(name);
223: }
224:
225: /**
226: *
227: * @exception Exception thrown under any exceptional condition.
228: */
229: protected void setUp() throws Exception {
230: super .setUp();
231:
232: // set ourself up
233: }
234:
235: /**
236: *
237: * @exception Exception thrown under any exceptional condition.
238: */
239: protected void tearDown() throws Exception {
240: // tear ourself down
241:
242: super.tearDown();
243: }
244: }
|