001: // $Id: ExceptionCutUserDefinedTest.java,v 1.3 2004/05/12 17:26:51 anicoara Exp $
002: // =====================================================================
003: //
004: // (history at end)
005: //
006:
007: package ch.ethz.prose.crosscut;
008:
009: //used packages
010: import java.io.IOException;
011:
012: import junit.framework.*;
013: import ch.ethz.prose.DefaultAspect;
014: import ch.ethz.prose.ProseSystem;
015: import ch.ethz.prose.filter.PointCutter;
016:
017: /**
018: * JUnit testcase for class XXX.
019: *
020: * @version $Revision: 1.3 $
021: * @author Andrei Popovici
022: */
023: public class ExceptionCutUserDefinedTest extends TestCase {
024:
025: public static class MyRuntimeException extends RuntimeException {
026: };
027:
028: public static class MyException extends IOException {
029: };
030:
031: public static class MyError extends Error {
032: };
033:
034: // Jikes RVM doesn't allow to watch exceptions which are in the boot image.
035: // And the most common ones are...
036: public static class MySubRuntimeException extends
037: MyRuntimeException {
038: };
039:
040: public static class MySubException extends MyException {
041: };
042:
043: public static class MySubError extends MyError {
044: };
045:
046: public static class MyNullPointerException extends
047: NullPointerException {
048: };
049:
050: public static class TestExtension extends DefaultAspect {
051: int c1cnt = 0;
052: int c2cnt = 0;
053: int c3cnt = 0;
054: int c4cnt = 0;
055:
056: public Crosscut c1 = new ThrowCut() {
057: public void THROW_ARGS(ANY x) {
058: c1cnt++;
059: }
060:
061: protected PointCutter pointCutter() {
062: return null;
063: }
064: };
065:
066: public Crosscut c2 = new ThrowCut() {
067: public void THROW_ARGS(RuntimeException e) {
068: c2cnt++;
069: }
070:
071: protected PointCutter pointCutter() {
072: return null;
073: }
074:
075: };
076:
077: public Crosscut c3 = new ThrowCut() {
078: public void THROW_ARGS(IOException e) {
079: c3cnt++;
080: }
081:
082: protected PointCutter pointCutter() {
083: return null;
084: }
085:
086: };
087:
088: public Crosscut c4 = new ThrowCut() {
089: public void THROW_ARGS(Throwable e) {
090: c4cnt++;
091: }
092:
093: protected PointCutter pointCutter() {
094: return null;
095: }
096:
097: };
098: }
099:
100: /**
101: * Construct test with given name.
102: * @param name test name
103: */
104: public ExceptionCutUserDefinedTest(String name) {
105: super (name);
106: }
107:
108: /**
109: * Set up fixture.
110: */
111: protected void setUp() throws Exception {
112: ProseSystem.startup();
113: }
114:
115: protected void tearDown() throws Exception {
116: ProseSystem.teardown();
117: }
118:
119: public void testCustomExtensionCut() throws Exception {
120: // FIXME: w/o the follwing line problems: classes loaded dynamically are not returned by
121: Class c = MyRuntimeException.class;
122: c = MyException.class;
123: c = MyError.class;
124: c = MySubRuntimeException.class;
125: c = MySubException.class;
126: c = MySubError.class;
127: c = MyNullPointerException.class;
128: TestExtension x = new TestExtension();
129: ProseSystem.getAspectManager().insert(x);
130:
131: try {
132: throw new MySubRuntimeException();
133: } catch (MySubRuntimeException e) {
134: } // cnt1,4,2
135: try {
136: throw new MyRuntimeException();
137: } catch (MyRuntimeException e) {
138: } // cnt1,4,2
139: try {
140: throw new MyNullPointerException();
141: } catch (MyNullPointerException e) {
142: } // cnt1,4,2
143: try {
144: throw new MyException();
145: } catch (MyException e) {
146: } // cnt1,4,3
147: try {
148: throw new MySubException();
149: } catch (MySubException e) {
150: } // cnt1,4,3
151: try {
152: throw new MyError();
153: } catch (MyError e) {
154: } // cnt1,4
155: try {
156: throw new MySubError();
157: } catch (MySubError e) {
158: } // cnt1,4
159:
160: ProseSystem.getAspectManager().withdraw(x);
161:
162: assertEquals("exception captured by ANY:", 7, x.c1cnt);
163: assertEquals("exception captured by Runtime:", 3, x.c2cnt);
164: assertEquals("exception captured by IO:", 2, x.c3cnt);
165: assertEquals("exception captured by Throwable:", 7, x.c4cnt);
166: }
167:
168: /**
169: * Test suite.
170: * @return test instance
171: */
172: public static Test suite() {
173: return new TestSuite(ExceptionCutUserDefinedTest.class);
174: }
175: }
176:
177: //======================================================================
178: //
179: // $Log: ExceptionCutUserDefinedTest.java,v $
180: // Revision 1.3 2004/05/12 17:26:51 anicoara
181: // Adapt Junit tests to 3.8.1 version and the new package structure
182: //
183: // Revision 1.1.1.1 2003/07/02 15:30:43 apopovic
184: // Imported from ETH Zurich
185: //
186: // Revision 1.1 2003/05/05 14:03:29 popovici
187: // renaming from runes to prose
188: //
189: // Revision 1.4 2003/04/27 13:08:55 popovici
190: // Specializers renamed to PointCutter
191: //
192: // Revision 1.3 2003/04/17 15:15:17 popovici
193: // Extension->Aspect renaming
194: //
195: // Revision 1.2 2003/04/17 12:49:43 popovici
196: // Refactoring of the crosscut package
197: // ExceptionCut renamed to ThrowCut
198: // McutSignature is now SignaturePattern
199: //
200: // Revision 1.1 2003/04/17 08:46:47 popovici
201: // Important functionality additions
202: // - Cflow specializers
203: // - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
204: // - Transactional capabilities
205: // - Total refactoring of Specializer evaluation, which permits fine-grained distinction
206: // between static and dynamic specializers.
207: // - Functionality pulled up in abstract classes
208: // - Uniformization of advice methods patterns and names
209: //
|