1 18 19 package alt.jiapi; 20 21 import junit.framework.TestCase; 22 23 import alt.jiapi.instrumentor.CombInstrumentor; 24 import alt.jiapi.reflect.instruction.InstructionList; 25 import alt.jiapi.reflect.JiapiClass; 26 import alt.jiapi.reflect.JiapiMethod; 27 import alt.jiapi.reflect.Loader; 28 29 38 public class InstrumentorTest extends TestCase { 39 JiapiMethod[] methods; 40 41 public InstrumentorTest(String name) { 42 super(name); 43 } 44 45 protected void setUp() { 46 try { 47 Loader loader = new Loader(); 48 JiapiClass clazz = loader.loadClass("alt.jiapi.InstrumentorTest"); 49 methods = clazz.getDeclaredMethods(); 50 } catch (Exception e) { 51 e.printStackTrace(); 52 } 53 54 } 55 56 public void testInstrumentors() { 57 combTest0(); combTest1(); } 60 61 62 private void combTest0() { 63 TestCombInstrumentor combInstrumentor = 64 new TestCombInstrumentor(0x1); 66 for(int i = 0; i < methods.length; i++) { 67 combInstrumentor.instrument(methods[i].getInstructionList()); 68 assertTrue(!combInstrumentor.isBlocked()); } 70 } 71 private void combTest1() { 72 TestCombInstrumentor combInstrumentor = 73 new TestCombInstrumentor(0x2); 75 for(int i = 0; i < methods.length; i++) { 76 combInstrumentor.instrument(methods[i].getInstructionList()); 77 assertTrue(combInstrumentor.isBlocked()); 79 if (i < methods.length - 1) { 80 combInstrumentor.instrument(methods[i+1].getInstructionList()); 81 assertTrue(!combInstrumentor.isBlocked()); } 83 } 84 } 85 86 87 private void someMethod() { 89 foo(); 90 bar(); 91 } 92 93 private void foo() {} 95 private void bar() {} 96 private void baz() {} 97 private void foobar() {} 98 private void foobaz() {} 99 100 101 class TestCombInstrumentor extends CombInstrumentor { 105 public TestCombInstrumentor(int i) { 106 super(i); 107 } 108 109 private boolean forwardCalled = false; 110 111 public void forward(InstructionList il) { 112 forwardCalled = true; 113 } 114 115 public boolean isBlocked() { 116 boolean retVal = true; 117 118 if (forwardCalled) { 119 retVal = false; 120 } 121 122 forwardCalled = false; 123 124 return retVal; 125 } 126 } 127 128 } 129 130 | Popular Tags |