1 7 package ch.ethz.prose.filter; 8 9 import junit.framework.*; 11 import ch.ethz.prose.DefaultAspect; 12 import ch.ethz.prose.ProseSystem; 13 import ch.ethz.prose.crosscut.*; 14 15 21 public 22 class CflowSTest extends TestCase { 23 24 String ffoo; 26 String fbar; 27 int fbaz; 28 29 int alternative(int a) 30 { 31 bar("a" + a, "b" + a); 32 return 1; 33 } 34 35 int foo (String x, String y, String z) 36 { 37 bar (x+y,z); 38 ffoo=z; 39 return 1; 40 41 } 42 43 int bar(String x, String y) 44 { 45 baz(1,x+y); 46 fbar=x; 47 return 1; 48 } 49 50 Object baz(int x, Object y) 51 { 52 try 53 { 54 throw new IllegalStateException (); 55 } 56 catch(IllegalStateException e) 57 { 58 fbaz=x; 59 } 60 return y; 61 } 62 63 64 public static MethodCut m1 = new MethodCut() 65 { 66 public void METHOD_ARGS(ANY x, REST y) 67 { } 68 69 protected PointCutter pointCutter() 70 { 71 return Within.method("foo"); 72 } 73 }; 74 75 public static MethodCut m2 = new MethodCut() 76 { 77 public void METHOD_ARGS(ANY x, REST y) 78 {} 79 80 protected PointCutter pointCutter() 81 { 82 return Within.method("nosuchMethod"); 83 } 84 85 }; 86 87 static boolean setBazCutViz = false; 88 89 public static class SetBazCut extends DefaultAspect 90 { 91 public Crosscut c1 = new SetCut() 92 { 93 public void SET_ARGS() 94 {setBazCutViz = true;} 95 96 protected PointCutter pointCutter() 97 { 98 return (Fields.named("fbaz")). AND 99 (Within.method("baz")).AND 100 (Cflow.below(m1)); 101 } 102 }; 103 104 }; 105 106 public static class SetBazCut1 extends DefaultAspect 107 { 108 public Crosscut c1 = new SetCut() 109 { 110 public void SET_ARGS() 111 { 112 System.err.println("visiting the mood"); 113 setBazCutViz = true; 115 } 116 117 protected PointCutter pointCutter() 118 { 119 return 120 (Fields.named("fbaz")). AND 121 (Within.method("baz")).AND 122 (Cflow.below(m2)); 123 } 124 }; 125 126 } 127 128 SetBazCut setBazCut; 129 SetBazCut1 setBazCut1; 130 131 135 public CflowSTest(String name) 136 { 137 super(name); 138 } 139 140 143 protected 144 void setUp() throws Exception 145 { 146 try 147 { 148 ProseSystem.startup(); 149 setBazCut = new SetBazCut(); 150 setBazCut1 = new SetBazCut1(); 151 setBazCutViz = false; 152 } 153 catch (Exception e) 154 { 155 e.printStackTrace(); 156 throw e; 157 } 158 } 159 160 protected void 161 tearDown() throws Exception 162 { 163 try 164 { 165 ProseSystem.teardown(); 166 } 167 catch (Exception e) 168 { 169 e.printStackTrace(); 170 throw e; 171 } 172 } 173 174 public void testBelowFoo() 175 { 176 177 178 ProseSystem.getAspectManager().insert(setBazCut); 179 foo("a","b","c"); ProseSystem.getAspectManager().withdraw(setBazCut); 181 assertTrue("SetBazCut was visited since baz below foo",setBazCutViz); 182 } 183 184 public void testBelowNothing() 185 { 186 try 187 { 188 ProseSystem.getAspectManager().insert(setBazCut1); 189 foo("a","b","c"); 190 ProseSystem.getAspectManager().withdraw(setBazCut1); 191 assertTrue("SetBazCut was not visited since baz below not below XXX",!setBazCutViz); 192 } 193 catch (RuntimeException e) 194 { 195 e.printStackTrace(); 196 throw e; 197 } 198 } 199 200 204 public static 205 Test suite() 206 { 207 return new TestSuite(CflowSTest.class); 208 } 209 210 } 211 212 213 | Popular Tags |