summaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authoraclement <aclement>2005-01-18 11:39:16 +0000
committeraclement <aclement>2005-01-18 11:39:16 +0000
commitfe310a4e10cf69486f54d5cf4edd4893b0a0835c (patch)
treee5b015ba92184dce33b61a686b9d7dd420403570 /tests/src
parent0e14ef28ab34628b3399cccb0118362fc22114a7 (diff)
downloadaspectj-fe310a4e10cf69486f54d5cf4edd4893b0a0835c.tar.gz
aspectj-fe310a4e10cf69486f54d5cf4edd4893b0a0835c.zip
PerTypeWithin support.
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java7
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/PerTypeWithinTests.java151
2 files changed, 152 insertions, 6 deletions
diff --git a/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java b/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java
index d138eb64b..fa0cff9c5 100644
--- a/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java
+++ b/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java
@@ -13,12 +13,6 @@ package org.aspectj.systemtest.ajc150;
import junit.framework.Test;
import junit.framework.TestSuite;
-/**
- * @author colyer
- *
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
- */
public class AllTestsAspectJ150 {
public static Test suite() {
@@ -36,6 +30,7 @@ public class AllTestsAspectJ150 {
suite.addTestSuite(AnnotationPointcutsTests.class);
suite.addTestSuite(VarargsTests.class);
suite.addTestSuite(AnnotationRuntimeTests.class);
+ suite.addTestSuite(PerTypeWithinTests.class);
//$JUnit-END$
diff --git a/tests/src/org/aspectj/systemtest/ajc150/PerTypeWithinTests.java b/tests/src/org/aspectj/systemtest/ajc150/PerTypeWithinTests.java
new file mode 100644
index 000000000..6c61fcad1
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/ajc150/PerTypeWithinTests.java
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * Copyright (c) 2005 IBM
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Andy Clement - initial API and implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc150;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.List;
+
+import org.aspectj.bridge.IMessage;
+import org.aspectj.tools.ajc.CompilationResult;
+
+
+
+public class PerTypeWithinTests extends TestUtils {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ baseDir = new File("../tests/java5/pertypewithin");
+ }
+
+ /**
+ * First few tests:
+ *
+ * Five types p.A, p.B, p.C, q.D, q.E and an aspect a.X.
+ *
+ * The aspect is pertypewithin(p..*) - this should match A,B,C but not D,E.
+ *
+ * Aspect instances should be accessible for A,B,C but not D,E.
+ * The aspect instances for A,B,C should be different.
+ *
+ * hasAspect(), aspectOf() should work.
+ *
+ * We test these assumptions in A,B,C,D,E.
+ */
+ public void testDoesItWorkAtAll() {
+ CompilationResult cR=ajc(baseDir,new String[]{"A.java","B.java","C.java","D.java","Main.java","X.java"});
+ assertTrue("Expected no errors:"+cR,!cR.hasErrorMessages());
+ // if (verbose) { System.err.println(cR); System.err.println(cR.getStandardError());}
+ RunResult rR = run("p.A");
+ // if (verbose) {System.err.println(rR.getStdErr());}
+ assertTrue("Expected a report from the aspect about 2 calls to sayhi():"+rR.getStdErr(),
+ rR.getStdErr().indexOf("callcount = 2")!=-1);
+ }
+
+ public void testCheckHasAspectWorks() {
+ CompilationResult cR=ajc(baseDir,new String[]{"A.java","B.java","C.java","D.java","Main.java","X.java"});
+ assertTrue("Expected no errors:"+cR,!cR.hasErrorMessages());
+ // if (verbose) { System.err.println(cR); System.err.println(cR.getStandardError());}
+ RunResult rR = run("p.A");
+ rR = run("p.B");
+ // if (verbose) {System.err.println(rR.getStdErr());}
+ assertTrue("Expected a report from the aspect about 3 calls to sayhi():"+rR.getStdErr(),
+ rR.getStdErr().indexOf("callcount = 3")!=-1);
+ }
+
+ public void testCheckAspectOfWorks() {
+ CompilationResult cR=ajc(baseDir,new String[]{"A.java","B.java","C.java","D.java","Main.java","X.java"});
+ assertTrue("Expected no errors:"+cR,!cR.hasErrorMessages());
+ // if (verbose) { System.err.println(cR); System.err.println(cR.getStandardError());}
+ RunResult rR = run("p.A");
+ rR = run("p.C");
+ // if (verbose) {System.err.println(rR.getStdErr());}
+
+ }
+
+ /**
+ * Aspects Q and R match P with a pertypewithin() - they shouldn't clash in any way
+ *
+ */
+ public void testTwoAspectsHittingOneType() {
+ CompilationResult cR=ajc(baseDir,new String[]{"P.java","Q.java","R.java"});
+ assertTrue("Expected no errors:"+cR,!cR.hasErrorMessages());
+ // if (verbose) { System.err.println(cR); System.err.println(cR.getStandardError());}
+ RunResult rR = run("P");
+ // if (verbose) {System.err.println(rR.getStdErr());}
+ assertTrue("Expected message about Q reporting 2: "+rR.getStdErr(),
+ rR.getStdErr().indexOf("Q reporting 2")!=-1);
+ assertTrue("Expected message about R reporting 3: "+rR.getStdErr(),
+ rR.getStdErr().indexOf("R reporting 3")!=-1);
+ }
+
+ /**
+ * Checks the use of pertypewithin() doesn't result in extra join points (i.e. the
+ * infrastructure is properly hidden in ajc$ or synthetic members)
+ */
+ public void testPervasivenessOfWeaving() {
+ CompilationResult cR = ajc(baseDir,new String[]{"U.java","-showWeaveInfo"});
+ List l = cR.getInfoMessages();
+ int cnt = 0;
+ for (Iterator iter = l.iterator(); iter.hasNext();) {
+ IMessage element = (IMessage) iter.next();
+ if (element.getKind()==IMessage.WEAVEINFO) {
+ //System.err.println(element);
+ cnt++;
+ }
+ }
+ int weavingMessagesFromNormalDeploymentModel = cnt;
+ //System.err.println(cnt);
+
+ cR = ajc(baseDir,new String[]{"V.java","-showWeaveInfo"});
+ l = cR.getInfoMessages();
+ cnt = 0;
+ for (Iterator iter = l.iterator(); iter.hasNext();) {
+ IMessage element = (IMessage) iter.next();
+ if (element.getKind()==IMessage.WEAVEINFO) {
+ //System.err.println(element);
+ cnt++;
+ }
+ }
+ int weavingMessagesFromPerTypeWithin = cnt;
+ //System.err.println(cnt);
+ if (weavingMessagesFromNormalDeploymentModel!=weavingMessagesFromPerTypeWithin)
+ fail("Expected same number of messages regardless of perclause but got "+
+ weavingMessagesFromNormalDeploymentModel+" and "+weavingMessagesFromPerTypeWithin);
+
+ }
+
+ public void testBinaryWeaving_ClassesAreBinary() {
+ // Compile the 'ordinary' class G.java into classes
+ CompilationResult cR = ajc(baseDir,new String[]{"G.java","-d","classes2"});
+ setShouldEmptySandbox(false);
+ // Compile the aspect with G.class as input, should be binary woven correctly
+ cR = ajc(baseDir,new String[]{"H.java","-inpath","classes2"});
+ RunResult rR = run("G");
+ assertTrue("Expected aspect related message 'advice running' in output from G",
+ rR.getStdErr().indexOf("advice running")!=-1);
+ setShouldEmptySandbox(true);
+ }
+
+ public void testBinaryWeaving_AspectsAreBinary() {
+ // Compile the aspect H.java into classes3
+ CompilationResult cR = ajc(baseDir,new String[]{"H.java","-outjar","aspects.jar"});
+ setShouldEmptySandbox(false);
+ // Compile the class with H.class as aspectpath, should be binary woven correctly
+ cR = ajc(baseDir,new String[]{"G.java","-aspectpath","aspects.jar"});
+ RunResult rR = run("G");
+ assertTrue("Expected aspect related message 'advice running' in output from G",
+ rR.getStdErr().indexOf("advice running")!=-1);
+ setShouldEmptySandbox(true);
+ }
+
+ // binary weaving case ...
+} \ No newline at end of file