summaryrefslogtreecommitdiffstats
path: root/tests/java5
diff options
context:
space:
mode:
authoravasseur <avasseur>2005-05-10 15:44:11 +0000
committeravasseur <avasseur>2005-05-10 15:44:11 +0000
commit83655ff47c1af1ca58c8043626799e0483d5acd4 (patch)
tree0cd02ea9863cbbb759ab0df465dd60a584855b8f /tests/java5
parent2c4f9d292a521703642169d8c066792d0e0802f5 (diff)
downloadaspectj-83655ff47c1af1ca58c8043626799e0483d5acd4.tar.gz
aspectj-83655ff47c1af1ca58c8043626799e0483d5acd4.zip
fix 75442 thru lateTypeMungers, currently @AJaspectOf and perObject are lateTypeMungers. new LTW tests, some fix in the LTW test error reporting
Diffstat (limited to 'tests/java5')
-rw-r--r--tests/java5/ataspectj/ajc-ant.xml26
-rw-r--r--tests/java5/ataspectj/ataspectj/AllLTWTests.java1
-rw-r--r--tests/java5/ataspectj/ataspectj/PerClauseTest.java122
-rw-r--r--tests/java5/ataspectj/ataspectj/PerClauseTestAspects.java85
-rw-r--r--tests/java5/ataspectj/ataspectj/TestHelper.java29
-rw-r--r--tests/java5/ataspectj/ataspectj/aop.xml9
6 files changed, 169 insertions, 103 deletions
diff --git a/tests/java5/ataspectj/ajc-ant.xml b/tests/java5/ataspectj/ajc-ant.xml
index 4aaf76d0d..ec223ea54 100644
--- a/tests/java5/ataspectj/ajc-ant.xml
+++ b/tests/java5/ataspectj/ajc-ant.xml
@@ -1,5 +1,9 @@
<!-- ajc-ant script, not to be used from Ant commant line - see AntSpec -->
-<project name="foo" default="all">
+<project name="foo" default="javac.ltw">
+
+ <property
+ name="jdwp"
+ value=""/>
<target name="compile:javac">
<!-- compile only javac compilable stuff -->
@@ -10,11 +14,29 @@
</javac>
</target>
- <target name="all" depends="compile:javac">
+ <target name="ltw">
<java fork="yes" classname="ataspectj.AllLTWTests" failonerror="yes">
<classpath refid="aj.path"/>
<jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>
<jvmarg value="-Daj5.def=ataspectj/aop.xml"/>
</java>
</target>
+
+ <target name="ltw.PerClauseTest">
+ <java fork="yes" classname="ataspectj.PerClauseTest" failonerror="yes">
+ <classpath refid="aj.path"/>
+ <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>
+ <jvmarg value="-Daj5.def=ataspectj/aop.xml"/>
+ </java>
+ </target>
+
+ <target name="ltw.AroundInlineMungerTest">
+ <java fork="yes" classname="ataspectj.AroundInlineMungerTest" failonerror="yes">
+ <classpath refid="aj.path"/>
+ <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>
+ <jvmarg value="-Daj5.def=ataspectj/aop.xml"/>
+ </java>
+ </target>
+
+ <target name="javac.ltw" depends="compile:javac, ltw"/>
</project> \ No newline at end of file
diff --git a/tests/java5/ataspectj/ataspectj/AllLTWTests.java b/tests/java5/ataspectj/ataspectj/AllLTWTests.java
index eddd0cde2..e015a0a8e 100644
--- a/tests/java5/ataspectj/ataspectj/AllLTWTests.java
+++ b/tests/java5/ataspectj/ataspectj/AllLTWTests.java
@@ -13,7 +13,6 @@ package ataspectj;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import test.loadtime5.AtAspectJTest;
/**
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
diff --git a/tests/java5/ataspectj/ataspectj/PerClauseTest.java b/tests/java5/ataspectj/ataspectj/PerClauseTest.java
index ff8a354d2..268873696 100644
--- a/tests/java5/ataspectj/ataspectj/PerClauseTest.java
+++ b/tests/java5/ataspectj/ataspectj/PerClauseTest.java
@@ -45,8 +45,8 @@ public class PerClauseTest extends TestCase {
// singleton is bound as soon as clinit
try {
- assertTrue(Aspects.hasAspect(TestAspectPerSingleton.class));
- Aspects.aspectOf(TestAspectPerSingleton.class);
+ assertTrue(Aspects.hasAspect(PerClauseTestAspects.TestAspectPerSingleton.class));
+ Aspects.aspectOf(PerClauseTestAspects.TestAspectPerSingleton.class);
} catch (NoAspectBoundException e) {
fail(e.toString());
}
@@ -55,24 +55,9 @@ public class PerClauseTest extends TestCase {
assertEquals("AOP.perSingleton perSingleton ", s_log.toString());
perSingleton();
- assertEquals(1, TestAspectPerSingleton.s_count);
+ assertEquals(1, PerClauseTestAspects.TestAspectPerSingleton.s_count);
}
- @Aspect()
- public static class TestAspectPerSingleton {
- static int s_count = 0;
- public TestAspectPerSingleton() {
- s_count++;
- }
-
- @Before("execution(* ataspectj.PerClauseTest.perSingleton()) && target(t)")
- public void before(JoinPoint jp, Object t) {
- log("AOP."+jp.getSignature().getName());
- assertTrue("perX match", this.equals(Aspects.aspectOf(getClass())));
- }
- }
-
-
public void perTarget() {
log("perTarget");
}
@@ -84,8 +69,8 @@ public class PerClauseTest extends TestCase {
// calling singleton API will fail
try {
- assertFalse(Aspects.hasAspect(TestAspectPerTarget.class));
- Aspects.aspectOf(TestAspectPerTarget.class);
+ assertFalse(Aspects.hasAspect(PerClauseTestAspects.TestAspectPerTarget.class));
+ Aspects.aspectOf(PerClauseTestAspects.TestAspectPerTarget.class);
fail("should fail with NOABE");
} catch (NoAspectBoundException e) {
;//ok
@@ -93,8 +78,8 @@ public class PerClauseTest extends TestCase {
// this per
try {
- assertTrue(Aspects.hasAspect(TestAspectPerTarget.class, this));
- TestAspectPerTarget aspect = (TestAspectPerTarget) Aspects.aspectOf(TestAspectPerTarget.class, this);
+ assertTrue(Aspects.hasAspect(PerClauseTestAspects.TestAspectPerTarget.class, this));
+ PerClauseTestAspects.TestAspectPerTarget aspect = (PerClauseTestAspects.TestAspectPerTarget) Aspects.aspectOf(PerClauseTestAspects.TestAspectPerTarget.class, this);
assertNotNull(aspect);
} catch (NoAspectBoundException e) {
fail(e.toString());
@@ -103,44 +88,29 @@ public class PerClauseTest extends TestCase {
// another per
PerClauseTest me = new PerClauseTest();
try {
- assertFalse(Aspects.hasAspect(TestAspectPerTarget.class, me));
- Aspects.aspectOf(TestAspectPerTarget.class, me);
+ assertFalse(Aspects.hasAspect(PerClauseTestAspects.TestAspectPerTarget.class, me));
+ Aspects.aspectOf(PerClauseTestAspects.TestAspectPerTarget.class, me);
fail("should fail");
} catch (NoAspectBoundException e) {
;//ok
}
me.perTarget();
try {
- assertTrue(Aspects.hasAspect(TestAspectPerTarget.class, me));
- TestAspectPerTarget aspect = (TestAspectPerTarget) Aspects.aspectOf(TestAspectPerTarget.class, me);
+ assertTrue(Aspects.hasAspect(PerClauseTestAspects.TestAspectPerTarget.class, me));
+ PerClauseTestAspects.TestAspectPerTarget aspect = (PerClauseTestAspects.TestAspectPerTarget) Aspects.aspectOf(PerClauseTestAspects.TestAspectPerTarget.class, me);
assertNotNull(aspect);
} catch (NoAspectBoundException e) {
fail(e.toString());
}
- assertEquals(2, TestAspectPerTarget.s_count);
- }
-
- @Aspect("pertarget(execution(* ataspectj.PerClauseTest.perTarget()))")
- public static class TestAspectPerTarget {
- static int s_count;
-
- public TestAspectPerTarget() {
- s_count++;
- }
-
- @Before("execution(* ataspectj.PerClauseTest.perTarget()) && target(t)")
- public void before(JoinPoint jp, Object t) {
- log("AOP."+jp.getSignature().getName());
- assertTrue("perX match", this.equals(Aspects.aspectOf(getClass(), t)));
- }
+ assertEquals(2, PerClauseTestAspects.TestAspectPerTarget.s_count);
}
public void perCflowEntry() {
// the aspect is bound to the executing thread
try {
- assertTrue(Aspects.hasAspect(TestAspectPerCflow.class));
- Aspects.aspectOf(TestAspectPerCflow.class);
+ assertTrue(Aspects.hasAspect(PerClauseTestAspects.TestAspectPerCflow.class));
+ Aspects.aspectOf(PerClauseTestAspects.TestAspectPerCflow.class);
} catch (NoAspectBoundException e) {
fail(e.toString());
}
@@ -156,8 +126,8 @@ public class PerClauseTest extends TestCase {
// no aspect bound yet
try {
- assertFalse(Aspects.hasAspect(TestAspectPerCflow.class));
- Aspects.aspectOf(TestAspectPerCflow.class);
+ assertFalse(Aspects.hasAspect(PerClauseTestAspects.TestAspectPerCflow.class));
+ Aspects.aspectOf(PerClauseTestAspects.TestAspectPerCflow.class);
fail("No perCflow should be bound yet");
} catch (NoAspectBoundException e) {
;//ok
@@ -167,8 +137,8 @@ public class PerClauseTest extends TestCase {
assertEquals("perCflow ", s_log.toString());
// still no aspect bound yet
try {
- assertFalse(Aspects.hasAspect(TestAspectPerCflow.class));
- Aspects.aspectOf(TestAspectPerCflow.class);
+ assertFalse(Aspects.hasAspect(PerClauseTestAspects.TestAspectPerCflow.class));
+ Aspects.aspectOf(PerClauseTestAspects.TestAspectPerCflow.class);
fail("No perCflow should be bound yet");
} catch (NoAspectBoundException e) {
;//ok
@@ -179,8 +149,8 @@ public class PerClauseTest extends TestCase {
assertEquals("AOP.perCflow perCflow ", s_log.toString());
// no aspect bound anymore since went OUT of the per clause
try {
- assertFalse(Aspects.hasAspect(TestAspectPerCflow.class));
- Aspects.aspectOf(TestAspectPerCflow.class);
+ assertFalse(Aspects.hasAspect(PerClauseTestAspects.TestAspectPerCflow.class));
+ Aspects.aspectOf(PerClauseTestAspects.TestAspectPerCflow.class);
fail("No perCflow should be bound anymore");
} catch (NoAspectBoundException e) {
;//ok
@@ -204,45 +174,30 @@ public class PerClauseTest extends TestCase {
trko.start();
trko.join();
- assertEquals(2, TestAspectPerCflow.s_count);
- }
-
- @Aspect("percflow(execution(* ataspectj.PerClauseTest.perCflowEntry()))")
- public static class TestAspectPerCflow {
- static int s_count;
-
- public TestAspectPerCflow() {
- s_count++;
- }
-
- @Before("execution(* ataspectj.PerClauseTest.perCflow())")
- public void before(JoinPoint jp) {
- log("AOP."+jp.getSignature().getName());
- assertTrue("perX match", this.equals(Aspects.aspectOf(getClass())));
- }
+ assertEquals(2, PerClauseTestAspects.TestAspectPerCflow.s_count);
}
public void testPerTypeWithin() {
- assertTrue(Aspects.hasAspect(TestAspectPTW.class, PTW1.class));
- assertTrue(Aspects.hasAspect(TestAspectPTW.class, PTW2.class));
- assertFalse(Aspects.hasAspect(TestAspectPTW.class, PTWNoMatch.class));
+ assertTrue(Aspects.hasAspect(PerClauseTestAspects.TestAspectPTW.class, PTW1.class));
+ assertTrue(Aspects.hasAspect(PerClauseTestAspects.TestAspectPTW.class, PTW2.class));
+ assertFalse(Aspects.hasAspect(PerClauseTestAspects.TestAspectPTW.class, PTWNoMatch.class));
PTW1.foo();
PTW2.foo();
PTWNoMatch.foo();
- assertEquals(2, TestAspectPTW.s_count);
+ assertEquals(2, PerClauseTestAspects.TestAspectPTW.s_count);
try {
- assertTrue(Aspects.hasAspect(TestAspectPTW.class, PTW1.class));
- assertTrue(Aspects.hasAspect(TestAspectPTW.class, PTW2.class));
- Aspects.aspectOf(TestAspectPTW.class, PTW1.class);
- Aspects.aspectOf(TestAspectPTW.class, PTW2.class);
+ assertTrue(Aspects.hasAspect(PerClauseTestAspects.TestAspectPTW.class, PTW1.class));
+ assertTrue(Aspects.hasAspect(PerClauseTestAspects.TestAspectPTW.class, PTW2.class));
+ Aspects.aspectOf(PerClauseTestAspects.TestAspectPTW.class, PTW1.class);
+ Aspects.aspectOf(PerClauseTestAspects.TestAspectPTW.class, PTW2.class);
} catch (NoAspectBoundException e) {
fail(e.toString());
}
try {
- assertFalse(Aspects.hasAspect(TestAspectPTW.class, PTWNoMatch.class));
- Aspects.aspectOf(TestAspectPTW.class, PTWNoMatch.class);
+ assertFalse(Aspects.hasAspect(PerClauseTestAspects.TestAspectPTW.class, PTWNoMatch.class));
+ Aspects.aspectOf(PerClauseTestAspects.TestAspectPTW.class, PTWNoMatch.class);
fail("should not have PTW aspect");
} catch (NoAspectBoundException e) {
;//ok
@@ -258,19 +213,4 @@ public class PerClauseTest extends TestCase {
static class PTWNoMatch {
static void foo() {};
}
-
- @Aspect("pertypewithin(ataspectj.PerClauseTest.PTW* && !ataspectj.PerClauseTest.PTWNoMatch)")
- public static class TestAspectPTW {
- static int s_count;
-
- public TestAspectPTW() {
- s_count++;
- }
-
- @Before("execution(* ataspectj.PerClauseTest.PTW*.foo())")
- public void before(JoinPoint jp) {
- ;
- }
-
- }
}
diff --git a/tests/java5/ataspectj/ataspectj/PerClauseTestAspects.java b/tests/java5/ataspectj/ataspectj/PerClauseTestAspects.java
new file mode 100644
index 000000000..175eb79ce
--- /dev/null
+++ b/tests/java5/ataspectj/ataspectj/PerClauseTestAspects.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Vasseur initial implementation
+ *******************************************************************************/
+package ataspectj;
+
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.Aspects;
+import junit.framework.Assert;
+
+/**
+ * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
+ */
+public class PerClauseTestAspects {
+
+ @Aspect()
+ public static class TestAspectPerSingleton {
+ static int s_count = 0;
+ public TestAspectPerSingleton() {
+ s_count++;
+ }
+
+ @Before("execution(* ataspectj.PerClauseTest.perSingleton()) && target(t)")
+ public void before(JoinPoint jp, Object t) {
+ PerClauseTest.log("AOP."+jp.getSignature().getName());
+ Assert.assertTrue("perX match", this.equals(Aspects.aspectOf(getClass())));
+ }
+ }
+
+ @Aspect("pertarget(execution(* ataspectj.PerClauseTest.perTarget()))")
+ public static class TestAspectPerTarget {
+ static int s_count;
+
+ public TestAspectPerTarget() {
+ s_count++;
+ }
+
+ @Before("execution(* ataspectj.PerClauseTest.perTarget()) && target(t)")
+ public void before(JoinPoint jp, Object t) {
+ PerClauseTest.log("AOP."+jp.getSignature().getName());
+ Assert.assertTrue("perX match", this.equals(Aspects.aspectOf(getClass(), t)));
+ }
+ }
+
+ @Aspect("percflow(execution(* ataspectj.PerClauseTest.perCflowEntry()))")
+ public static class TestAspectPerCflow {
+ static int s_count;
+
+ public TestAspectPerCflow() {
+ s_count++;
+ }
+
+ @Before("execution(* ataspectj.PerClauseTest.perCflow())")
+ public void before(JoinPoint jp) {
+ PerClauseTest.log("AOP."+jp.getSignature().getName());
+ Assert.assertTrue("perX match", this.equals(Aspects.aspectOf(getClass())));
+ }
+ }
+
+ @Aspect("pertypewithin(ataspectj.PerClauseTest.PTW* && !ataspectj.PerClauseTest.PTWNoMatch)")
+ public static class TestAspectPTW {
+ static int s_count;
+
+ public TestAspectPTW() {
+ s_count++;
+ }
+
+ @Before("execution(* ataspectj.PerClauseTest.PTW*.foo())")
+ public void before(JoinPoint jp) {
+ ;
+ }
+
+ }
+
+
+}
diff --git a/tests/java5/ataspectj/ataspectj/TestHelper.java b/tests/java5/ataspectj/ataspectj/TestHelper.java
index bf30408fc..ba8eab807 100644
--- a/tests/java5/ataspectj/ataspectj/TestHelper.java
+++ b/tests/java5/ataspectj/ataspectj/TestHelper.java
@@ -13,9 +13,16 @@ package ataspectj;
import junit.textui.TestRunner;
import junit.framework.TestResult;
+import junit.framework.Assert;
+import junit.framework.TestFailure;
import java.util.Enumeration;
+import org.aspectj.bridge.IMessageHandler;
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.AbortException;
+import org.aspectj.weaver.loadtime.DefaultMessageHandler;
+
/**
* Helper to run a test as a main class, but still throw exception and not just print on stderr
* upon test failure.
@@ -24,7 +31,7 @@ import java.util.Enumeration;
*
* @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
*/
-public class TestHelper {
+public class TestHelper extends DefaultMessageHandler {
public static void runAndThrowOnFailure(junit.framework.Test test) {
TestRunner r = new TestRunner();
@@ -33,18 +40,30 @@ public class TestHelper {
StringBuffer sb = new StringBuffer("\n");
Enumeration e = rr.failures();
while (e.hasMoreElements()) {
- sb.append("Failure: ");
- sb.append(e.nextElement());
+ sb.append("JUnit Failure: ");
+ sb.append(((TestFailure)e.nextElement()).thrownException().toString());
sb.append("\n");
}
e = rr.errors();
while (e.hasMoreElements()) {
- sb.append("Error: ");
- sb.append(e.nextElement());
+ sb.append("JUnit Error: ");
+ sb.append(((TestFailure)e.nextElement()).thrownException().toString());
sb.append("\n");
}
throw new RuntimeException(sb.toString());
}
}
+ public boolean handleMessage(IMessage message) throws AbortException {
+ boolean ret = super.handleMessage(message);
+ if (message.getKind().isSameOrLessThan(IMessage.INFO)) {
+ ;
+ } else {
+ // we do exit here since Assert.fail will only trigger a runtime exception that might
+ // be catched by the weaver anyway
+ System.exit(-1);
+ }
+ return ret;
+ }
+
}
diff --git a/tests/java5/ataspectj/ataspectj/aop.xml b/tests/java5/ataspectj/ataspectj/aop.xml
index d76592f04..efe556127 100644
--- a/tests/java5/ataspectj/ataspectj/aop.xml
+++ b/tests/java5/ataspectj/ataspectj/aop.xml
@@ -1,5 +1,6 @@
<?xml version="1.0"?>
<aspectj>
+ <weaver options="-XmessageHolderClass:ataspectj.TestHelper"/>
<aspects>
<!-- see here nested class with ".", "$" is accepted as well -->
<aspect name="ataspectj.SingletonAspectBindingsTest.TestAspect"/>
@@ -15,10 +16,10 @@
<aspect name="ataspectj.BindingTest.TestAspect_1"/>
- <aspect name="ataspectj.PerClauseTest.TestAspectPerSingleton"/>
- <aspect name="ataspectj.PerClauseTest.TestAspectPerTarget"/>
- <aspect name="ataspectj.PerClauseTest.TestAspectPerCflow"/>
- <aspect name="ataspectj.PerClauseTest.TestAspectPTW"/>
+ <aspect name="ataspectj.PerClauseTestAspects.TestAspectPerSingleton"/>
+ <aspect name="ataspectj.PerClauseTestAspects.TestAspectPerTarget"/>
+ <aspect name="ataspectj.PerClauseTestAspects.TestAspectPerCflow"/>
+ <aspect name="ataspectj.PerClauseTestAspects.TestAspectPTW"/>
<aspect name="ataspectj.AroundInlineMungerTest.Open"/>
</aspects>