KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)ModifiedInstructionListUTest.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.InstructionList;
36
37
38 /**
39  * Tests the ModifiedInstructionList class.
40  *
41  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
42  * @version $Date: 2004/04/15 05:48:28 $
43  * @since January 13, 2003
44  */

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

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

62     public void testConstructor1()
63     {
64         try
65         {
66             new ModifiedInstructionList( (short)0, 0, 0, null, null );
67             fail( "Did not throw IllegalArgumentException." );
68         }
69         catch (IllegalArgumentException JavaDoc e)
70         {
71             // test exception
72
}
73     }
74     
75     
76     public void testConstructor2()
77     {
78         new ModifiedInstructionList( (short)0, 0,
79             0, createInstructionList(), createModifiedTargeters() );
80     }
81     
82     
83     public void testClose1()
84     {
85         ModifiedInstructionList mil = new ModifiedInstructionList(
86             (short)0, 0, 0, createInstructionList(),
87             createModifiedTargeters() );
88         mil.close();
89     }
90     
91     
92     public void testClose2()
93     {
94         ModifiedInstructionList mil = new ModifiedInstructionList(
95             (short)0, 0, 0, createInstructionList(),
96             createModifiedTargeters() );
97         mil.close();
98         try
99         {
100             mil.close();
101             fail( "Did not throw IllegalStateException." );
102         }
103         catch (IllegalStateException JavaDoc e)
104         {
105             // test exception
106
}
107     }
108     
109     
110     public void testClose3()
111     {
112         ModifiedInstructionList mil = new ModifiedInstructionList(
113             (short)0, 0, 0, createInstructionList(),
114             createModifiedTargeters() );
115         mil.close();
116         try
117         {
118             mil.getInstructionAt(0);
119             fail( "Did not throw IllegalStateException." );
120         }
121         catch (IllegalStateException JavaDoc e)
122         {
123             // test exception
124
}
125     }
126     
127     
128     public void testClose4()
129     {
130         ModifiedInstructionList mil = new ModifiedInstructionList(
131             (short)0, 0, 0, createInstructionList(),
132             createModifiedTargeters() );
133         mil.close();
134         try
135         {
136             mil.getInstructionCount();
137             fail( "Did not throw IllegalStateException." );
138         }
139         catch (IllegalStateException JavaDoc e)
140         {
141             // test exception
142
}
143     }
144     
145     
146     public void testClose5()
147     {
148         ModifiedInstructionList mil = new ModifiedInstructionList(
149             (short)0, 0, 0, createInstructionList(),
150             createModifiedTargeters() );
151         mil.close();
152         try
153         {
154             mil.updateInstructionList();
155             fail( "Did not throw IllegalStateException." );
156         }
157         catch (IllegalStateException JavaDoc e)
158         {
159             // test exception
160
}
161     }
162     
163     
164     public void testUpdateInstructionList1()
165     {
166         ModifiedInstructionList mil = new ModifiedInstructionList(
167             (short)0, 0, 0, createInstructionList(),
168             createModifiedTargeters() );
169         int origCount = mil.getInstructionCount();
170         mil.updateInstructionList();
171         assertEquals( "Changed instruction count!", origCount,
172             mil.getInstructionCount() );
173         mil.updateInstructionList();
174         assertEquals( "Changed instruction count!", origCount,
175             mil.getInstructionCount() );
176         mil.updateInstructionList();
177         assertEquals( "Changed instruction count!", origCount,
178             mil.getInstructionCount() );
179     }
180     
181     
182     public void testUpdateInstructionList2()
183     {
184         ModifiedInstructionList mil = new ModifiedInstructionList(
185             (short)0, 0, 0, createInstructionList(),
186             createModifiedTargeters() );
187         int origCount = mil.getInstructionCount();
188         mil.getInstructionAt( origCount - 1 ).
189             addMark( (short)1, Short.MAX_VALUE );
190         mil.updateInstructionList();
191         mil.getInstructionAt( origCount - 1 ).
192             addMark( (short)1, Short.MAX_VALUE );
193         mil.updateInstructionList();
194         int count = mil.getInstructionCount();
195         mil.updateInstructionList();
196         assertEquals( "Changed instruction count!", count,
197             mil.getInstructionCount() );
198     }
199     
200     
201     public void testGetInstructionAt1()
202     {
203         // requirement: we need to be able to put a mark at the end of the
204
// list.
205
ModifiedInstructionList mil = new ModifiedInstructionList(
206             (short)0, 0, 0, new InstructionList(),
207             createModifiedTargeters() );
208         MarkedInstruction mi = mil.getInstructionAt( 0 );
209         assertNotNull(
210             "Returned null end instruction.",
211             mi );
212         assertTrue(
213             "End instruction is not the NullInstruction.",
214             mi.getInstruction() instanceof NullInstruction );
215     }
216     
217     
218     
219     //-------------------------------------------------------------------------
220
// Helpers
221

222     
223     protected InstructionList createInstructionList()
224     {
225         InstructionList il = BCELCreatorUtil.createInstructionList();
226         BCELCreatorUtil.addInstructionHandle( il );
227         return il;
228     }
229     
230     
231     protected ModifiedTargeters createModifiedTargeters()
232     {
233         org.apache.bcel.classfile.JavaClass jc = null;
234         try
235         {
236             jc = BCELCreatorUtil.createJavaClass( THIS_CLASS );
237         }
238         catch (java.io.IOException JavaDoc ex)
239         {
240             ex.printStackTrace();
241             fail( ex.getMessage() );
242         }
243         return new ModifiedTargeters(
244             BCELCreatorUtil.createMethodGen( jc, 0 ) );
245     }
246     
247     
248     //-------------------------------------------------------------------------
249
// Standard JUnit declarations
250

251     
252     public static Test suite()
253     {
254         TestSuite suite = new TestSuite( THIS_CLASS );
255         
256         return suite;
257     }
258     
259     public static void main( String JavaDoc[] args )
260     {
261         String JavaDoc[] name = { THIS_CLASS.getName() };
262         
263         // junit.textui.TestRunner.main( name );
264
// junit.swingui.TestRunner.main( name );
265

266         junit.textui.TestRunner.main( name );
267     }
268     
269     
270     /**
271      *
272      * @exception Exception thrown under any exceptional condition.
273      */

274     protected void setUp() throws Exception JavaDoc
275     {
276         super.setUp();
277         
278         // set ourself up
279
}
280     
281     
282     /**
283      *
284      * @exception Exception thrown under any exceptional condition.
285      */

286     protected void tearDown() throws Exception JavaDoc
287     {
288         // tear ourself down
289

290         
291         super.tearDown();
292     }
293 }
294
295
Popular Tags