1 7 package ch.ethz.prose; 8 9 import java.lang.reflect.Field ; 11 12 import junit.framework.*; 13 import ch.ethz.jvmai.FieldAccessJoinPoint; 14 import ch.ethz.jvmai.FieldModificationJoinPoint; 15 import ch.ethz.prose.crosscut.*; 16 import ch.ethz.prose.filter.PointCutter; 17 18 19 28 public class FieldNotificationTestWithOutput extends TestCase { 29 30 32 static class TestClass { 33 int initial = 1; 34 int inConstr; 35 int undefined; 36 37 int[] array; 38 39 Object o = null; 40 41 public TestClass() { 42 inConstr = 2; 43 } 44 45 } 46 47 public static class TestExtension extends DefaultAspect { 48 49 public Crosscut c1 = new GetCut() 50 { 51 public void GET_ARGS() 52 { 53 FieldAccessJoinPoint theEv = (FieldAccessJoinPoint)thisJoinPoint(); 54 Field f = theEv.getField(); 55 56 Object owner = theEv.getTarget(); 57 58 try 59 { 60 System.out.println("READ ACCESS"); 61 System.out.println("class: " + owner.getClass().getName()); 62 System.out.println("owner: " + owner); 63 System.out.println("fieldname: " + f.getName()); 64 System.out.println("value: " + f.get(owner)); 65 System.out.println(); 66 } 67 catch ( Exception e ) 68 { 69 e.printStackTrace(); 70 } 71 } 72 73 protected PointCutter pointCutter() 74 { return null;} 75 76 }; 77 78 public Crosscut c = new SetCut() 79 { 80 public void SET_ARGS() 81 { 82 try 83 { 84 FieldModificationJoinPoint fme = (FieldModificationJoinPoint)thisJoinPoint(); 85 86 System.out.println("MODIFICATION ACCESS"); 87 System.out.println("class: " + fme.getTarget().getClass().getName()); 88 System.out.println("owner: " + fme.getTarget()); 89 System.out.println("fieldname: " + fme.getField().getName()); 90 System.out.println("old value: " + fme.getField().get(fme.getTarget())); 91 System.out.println("new value: " + fme.getNewValue()); 92 System.out.println(); 93 } 94 catch ( Exception e ) 95 { 96 e.printStackTrace(); 97 } 98 } 99 100 protected PointCutter pointCutter() 101 { return null;} 102 103 104 protected Class [] potentialCrosscutClasses() { 106 Class [] result = {TestClass.class}; 107 return result; 108 } 109 }; 110 }; 111 112 113 TestClass test; 114 115 116 120 public FieldNotificationTestWithOutput(String name) { 121 super(name); 122 } 123 124 125 128 protected void setUp() { 129 try { 130 ProseSystem.startup(); 131 } 132 catch ( Exception e ) { 133 Assert.fail("ProseSystem.startup() failed."); 134 } 135 } 136 137 140 protected void tearDown() throws SystemTeardownException { 141 try { 142 ProseSystem.teardown(); 143 } 144 catch ( Exception e ) { 145 Assert.fail("ProseSystem.teardown() failed."); 146 } 147 } 148 149 150 153 public void testInstantiation() throws Exception { 154 155 int[] arr = {1,2,3,4,5}; 156 157 System.out.println("\n\ncreate new instance...\n"); 158 ProseSystem.getAspectManager().insert(new TestExtension()); 159 test = new TestClass(); 160 161 System.out.println("\naccess the fields...\n"); 162 test.undefined = -5; 163 test.o = new Object (); 164 test.array = arr; 165 arr[0] = 0; 166 test.array = arr; 167 test.array[1] = 9; 168 test.array[3] = 1; 169 test.array[4] = 10; 170 } 171 172 173 174 178 public static 179 Test suite() { 180 return new TestSuite(FieldNotificationTestWithOutput.class); 181 } 182 183 } 184 185 186
| Popular Tags
|