KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > codecoverage > v2 > compiler > MarkedInstructionUTest


1 /*
2  * @(#)MarkedInstructionUTest.java
3  *
4  * Copyright (C) 2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.codecoverage.v2.compiler;
28
29 import junit.framework.Test;
30 import junit.framework.TestCase;
31 import junit.framework.TestSuite;
32 import net.sourceforge.groboutils.autodoc.v1.AutoDoc;
33 import net.sourceforge.groboutils.codecoverage.v2.BCELCreatorUtil;
34
35 import org.apache.bcel.generic.InstructionHandle;
36 import org.apache.bcel.generic.InstructionList;
37
38
39 /**
40  * Tests the MarkedInstruction class.
41  *
42  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
43  * @version $Date: 2004/04/15 05:48:28 $
44  * @since January 13, 2003
45  */

46 public class MarkedInstructionUTest extends TestCase
47 {
48     //-------------------------------------------------------------------------
49
// Standard JUnit Class-specific declarations
50

51     private static final Class JavaDoc THIS_CLASS = MarkedInstructionUTest.class;
52     private static final AutoDoc DOC = new AutoDoc( THIS_CLASS );
53     
54     public MarkedInstructionUTest( String JavaDoc name )
55     {
56         super( name );
57     }
58
59
60     //-------------------------------------------------------------------------
61
// Tests
62

63     private static final int MARK_INSTRUCTION_COUNT = 5;
64     
65     
66     public void testConstructor1()
67     {
68         try
69         {
70             new MarkedInstruction( (short)0, 0, 0, null );
71             fail( "Did not throw IllegalArgumentException." );
72         }
73         catch (IllegalArgumentException JavaDoc e)
74         {
75             // test failure?
76
}
77     }
78     
79     
80     public void testGetInstruction1()
81     {
82         InstructionHandle ih = createInstructionHandle();
83         MarkedInstruction mi = new MarkedInstruction(
84             (short)0, 0, 0, ih );
85         assertEquals(
86             "Did not return expected instruction.",
87             ih.getInstruction(),
88             mi.getHandle().getInstruction() );
89     }
90     
91     
92     public void testAddMark1()
93     {
94         InstructionHandle ih = createInstructionHandle();
95         MarkedInstruction mi = new MarkedInstruction(
96             (short)0, 0, 0, ih );
97         mi.addMark( (short)1, Short.MIN_VALUE );
98     }
99     
100     
101     public void testAddMark2()
102     {
103         InstructionHandle ih = createInstructionHandle();
104         MarkedInstruction mi = new MarkedInstruction(
105             (short)0, 0, 0, ih );
106         mi.addMark( Short.MIN_VALUE, (short)1 );
107     }
108     
109     
110     public void testAddMark3()
111     {
112         InstructionHandle ih = createInstructionHandle();
113         MarkedInstruction mi = new MarkedInstruction(
114             (short)0, 0, 0, ih );
115         mi.addMark( (short)1, Short.MAX_VALUE );
116     }
117     
118     
119     public void testAddMark4()
120     {
121         InstructionHandle ih = createInstructionHandle();
122         MarkedInstruction mi = new MarkedInstruction(
123             (short)0, 0, 0, ih );
124         mi.addMark( Short.MAX_VALUE, (short)1 );
125     }
126     
127     
128     public void testGetMarkedList1()
129     {
130         InstructionHandle ih = createInstructionHandle();
131         MarkedInstruction mi = new MarkedInstruction(
132             (short)0, 0, 0, ih );
133         InstructionList il = mi.getMarkedList();
134         assertNull(
135             "Did not return a null marked list.",
136             il );
137     }
138     
139     
140     public void testGetMarkedList2()
141     {
142         InstructionHandle ih = createInstructionHandle();
143         MarkedInstruction mi = new MarkedInstruction(
144             (short)0, 0, 0, ih );
145         mi.addMark( (short)1, (short)1 );
146         InstructionList il = mi.getMarkedList();
147         assertEquals(
148             "Did not return a marked list of the expected size.",
149             MARK_INSTRUCTION_COUNT,
150             il.size() );
151     }
152     
153     
154     public void testGetMarkedList3()
155     {
156         InstructionHandle ih = createInstructionHandle();
157         MarkedInstruction mi = new MarkedInstruction(
158             (short)0, 0, 0, ih );
159         mi.addMark( (short)1, (short)1 );
160         mi.addMark( (short)1, (short)1 );
161         mi.addMark( (short)1, (short)1 );
162         InstructionList il = mi.getMarkedList();
163         assertEquals(
164             "Did not return a marked list of the expected size.",
165             MARK_INSTRUCTION_COUNT*3,
166             il.size() );
167     }
168     
169     
170     public void testGetMarkedList_state1()
171     {
172         InstructionHandle ih = createInstructionHandle();
173         MarkedInstruction mi = new MarkedInstruction(
174             (short)0, 0, 0, ih );
175         mi.getMarkedList();
176         
177         // repeat again without any mark changes
178
InstructionList il = mi.getMarkedList();
179         assertNull(
180             "Did not return a null marked list.",
181             il );
182     }
183     
184     
185     public void testGetMarkedList_state2()
186     {
187         InstructionHandle ih = createInstructionHandle();
188         MarkedInstruction mi = new MarkedInstruction(
189             (short)0, 0, 0, ih );
190         mi.addMark( (short)1, (short)1 );
191         mi.addMark( (short)1, (short)1 );
192         mi.getMarkedList();
193         
194         // repeat again without any mark changes
195
InstructionList il = mi.getMarkedList();
196         assertNull(
197             "Did not return a null marked list.",
198             il );
199     }
200     
201     
202     public void testGetMarkedList_state3()
203     {
204         InstructionHandle ih = createInstructionHandle();
205         MarkedInstruction mi = new MarkedInstruction(
206             (short)0, 0, 0, ih );
207         mi.getMarkedList();
208         
209         mi.addMark( (short)1, (short)1 );
210         mi.addMark( (short)1, (short)1 );
211         InstructionList il = mi.getMarkedList();
212         assertEquals(
213             "Did not return a marked list of the expected size.",
214             MARK_INSTRUCTION_COUNT*2,
215             il.size() );
216     }
217     
218     
219     public void testGetMarkedList_state4()
220     {
221         InstructionHandle ih = createInstructionHandle();
222         MarkedInstruction mi = new MarkedInstruction(
223             (short)0, 0, 0, ih );
224         mi.addMark( (short)0, (short)0 );
225         mi.addMark( (short)0, (short)1 );
226         mi.addMark( (short)0, (short)2 );
227         mi.getMarkedList();
228         
229         mi.addMark( (short)1, (short)0 );
230         mi.addMark( (short)1, (short)1 );
231         InstructionList il = mi.getMarkedList();
232         assertEquals(
233             "Did not return a marked list of the expected size.",
234             MARK_INSTRUCTION_COUNT*2,
235             il.size() );
236     }
237     
238     
239     public void testGetHandle1()
240     {
241         InstructionHandle ih = createInstructionHandle();
242         MarkedInstruction mi = new MarkedInstruction(
243             (short)0, 0, 0, ih );
244         assertSame(
245             "Did not return same handle.",
246             ih,
247             mi.getHandle() );
248     }
249     
250     
251     //-------------------------------------------------------------------------
252
// Helpers
253

254     
255     protected InstructionHandle createInstructionHandle()
256     {
257         return BCELCreatorUtil.createInstructionHandle();
258     }
259     
260     
261     
262     //-------------------------------------------------------------------------
263
// Standard JUnit declarations
264

265     
266     public static Test suite()
267     {
268         TestSuite suite = new TestSuite( THIS_CLASS );
269         
270         return suite;
271     }
272     
273     public static void main( String JavaDoc[] args )
274     {
275         String JavaDoc[] name = { THIS_CLASS.getName() };
276         
277         // junit.textui.TestRunner.main( name );
278
// junit.swingui.TestRunner.main( name );
279

280         junit.textui.TestRunner.main( name );
281     }
282     
283     
284     /**
285      *
286      * @exception Exception thrown under any exceptional condition.
287      */

288     protected void setUp() throws Exception JavaDoc
289     {
290         super.setUp();
291         
292         // set ourself up
293
}
294     
295     
296     /**
297      *
298      * @exception Exception thrown under any exceptional condition.
299      */

300     protected void tearDown() throws Exception JavaDoc
301     {
302         // tear ourself down
303

304         
305         super.tearDown();
306     }
307 }
308
309
Popular Tags