1 18 19 package alt.jiapi.reflect; 20 21 import java.util.Iterator ; 22 import junit.framework.TestCase; 23 24 import alt.jiapi.reflect.instruction.*; 25 26 43 public class InstructionTest extends TestCase { 44 private JiapiClass clazz1; 45 46 public String getName() { 47 return "InstructionTest: " + super.getName(); 48 } 49 50 public InstructionTest(String name) { 51 super(name); 52 } 53 54 protected void setUp() { 55 try { 56 Loader loader = new Loader(); 57 clazz1 = loader.loadClass("alt.jiapi.reflect.InstructionTest"); 58 } 59 catch (Exception e) { 60 e.printStackTrace(); 61 } 62 } 63 64 public void testStackUsage() { 65 JiapiMethod jm = null; 66 67 try { 68 jm = clazz1.getDeclaredMethod("t1", new String [0]); 69 } 70 catch(Exception e) { 71 fail("Could not get JiapiMethod for testing"); 72 } 73 74 InstructionList il = jm.getInstructionList(); 75 76 int idx = il.indexOf(Opcodes.INVOKESTATIC); 77 assertTrue(idx != -1); 78 79 Invocation ins = (Invocation)il.get(idx); 80 assertTrue(ins.stackUsage() == 0); 81 82 84 idx = il.indexOf(Opcodes.INVOKEVIRTUAL); 85 assertTrue(idx != -1); 86 87 ins = (Invocation)il.get(idx); 88 assertTrue(ins.stackUsage() == -1); 89 } 90 91 92 public void t1() { 93 InstructionTest.bar1(); 94 foo1(); 95 } 96 97 public static void bar1() { 98 } 99 100 public void foo1() { 101 } 102 103 public int foo2() { 104 return 1; 105 } 106 } 107 108 | Popular Tags |