aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src
diff options
context:
space:
mode:
authoraclement <aclement>2006-06-12 13:09:51 +0000
committeraclement <aclement>2006-06-12 13:09:51 +0000
commit4dcb8f3d88ed5e464bf31378d9c222fdf791ff4a (patch)
tree33e156385995a2fa2194b72a6ba29a7e73ba38f4 /tests/src
parent75afb31e38f75e61de5c15058d3332f3dac0df15 (diff)
downloadaspectj-4dcb8f3d88ed5e464bf31378d9c222fdf791ff4a.tar.gz
aspectj-4dcb8f3d88ed5e464bf31378d9c222fdf791ff4a.zip
test and fix for 145963: faulting in aspects coming in as binary inputs
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java1
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/CreatingModelForInjarTests.java134
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/injar.xml13
3 files changed, 148 insertions, 0 deletions
diff --git a/tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java b/tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java
index 05c311f50..1cf8167f7 100644
--- a/tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java
+++ b/tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java
@@ -19,6 +19,7 @@ public class AllTestsAspectJ152 {
TestSuite suite = new TestSuite("AspectJ 1.5.2 tests");
//$JUnit-BEGIN$
suite.addTest(Ajc152Tests.suite());
+ suite.addTest(CreatingModelForInjarTests.suite());
suite.addTest(SynchronizationTests.suite());
suite.addTest(SynchronizationTransformTests.suite());
//$JUnit-END$
diff --git a/tests/src/org/aspectj/systemtest/ajc152/CreatingModelForInjarTests.java b/tests/src/org/aspectj/systemtest/ajc152/CreatingModelForInjarTests.java
new file mode 100644
index 000000000..213dd2bdc
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/ajc152/CreatingModelForInjarTests.java
@@ -0,0 +1,134 @@
+/********************************************************************
+ * Copyright (c) 2006 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: IBM Corporation - initial API and implementation
+ * Helen Hawkins - initial version
+ *******************************************************************/
+package org.aspectj.systemtest.ajc152;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.aspectj.asm.AsmManager;
+import org.aspectj.asm.IHierarchy;
+import org.aspectj.asm.IProgramElement;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+import org.aspectj.weaver.World;
+
+public class CreatingModelForInjarTests extends org.aspectj.testing.XMLBasedAjcTestCase {
+
+ public void testAdviceAndNamedPCD() {
+ runTest("advice and deow");
+
+ // expect:
+ // - pkg {package}
+ // - A.aj (binary) {java source file}
+ // - import declarations {import reference}
+ // - A {aspect}
+ // - p {pointcut}
+ // - before {advice}
+
+ IProgramElement pkgNode = getPkgNode();
+ IProgramElement srcFile = checkChild(pkgNode,IProgramElement.Kind.FILE_JAVA,"A.aj (binary)",1);
+ checkChild(srcFile,IProgramElement.Kind.IMPORT_REFERENCE,"import declarations",-1);
+ IProgramElement aspectNode = checkChild(srcFile,IProgramElement.Kind.ASPECT,"A",-1);
+ checkChild(aspectNode,IProgramElement.Kind.POINTCUT,"p",5);
+ checkChild(aspectNode,IProgramElement.Kind.ADVICE,"before",7);
+ }
+
+ public void testDeclareWarning() {
+ runTest("advice and deow");
+
+ // expect:
+ // - pkg {package}
+ // - Deow.aj (binary) {java source file}
+ // - import declarations {import reference}
+ // - Deow {aspect}
+ // - declare warning {declare warning}
+
+ IHierarchy top = AsmManager.getDefault().getHierarchy();
+ IProgramElement dwNode = top.findElementForLabel(top.getRoot(),
+ IProgramElement.Kind.DECLARE_WARNING,
+ "declare warning: \"There should be n..\"");
+ assertNotNull("Couldn't find 'declare warning: \"There should be n..\"' " +
+ "element in the tree",dwNode);
+ assertEquals("expected 'declare warning: \"There should be n..\"'" +
+ " to be on line 5 but was on " + dwNode.getSourceLocation().getLine(),
+ 5, dwNode.getSourceLocation().getLine());
+ }
+
+ public void testNumberOfPackageNodes() {
+ runTest("advice and deow");
+ // check that the 'pkg' package node has not been added twice
+ IProgramElement root = AsmManager.getDefault().getHierarchy().getRoot();
+ List l = root.getChildren();
+ int numberOfPkgs = 0;
+ for (Iterator iter = l.iterator(); iter.hasNext();) {
+ IProgramElement element = (IProgramElement) iter.next();
+ if (element.getKind().equals(IProgramElement.Kind.PACKAGE)
+ && element.getName().equals("pkg")) {
+ numberOfPkgs++;
+ }
+ }
+ assertEquals("expected one package called 'pkg' but found " + numberOfPkgs,1,numberOfPkgs);
+ }
+
+ private IProgramElement getPkgNode() {
+ IHierarchy top = AsmManager.getDefault().getHierarchy();
+ IProgramElement pkgNode = top.findElementForLabel(top.getRoot(),
+ IProgramElement.Kind.PACKAGE,"pkg");
+ assertNotNull("Couldn't find 'pkg' element in the tree",pkgNode);
+ return pkgNode;
+ }
+
+ private IProgramElement checkChild(IProgramElement parent,
+ IProgramElement.Kind childKind,
+ String childName,
+ int childLineNumbr) {
+ List children = parent.getChildren();
+ boolean foundChild = false;
+ for (Iterator iter = children.iterator(); iter.hasNext();) {
+ IProgramElement element = (IProgramElement) iter.next();
+ if (element.getKind().equals(childKind)
+ && element.getName().equals(childName) ) {
+ foundChild = true;
+ if (childLineNumbr != -1) {
+ assertEquals("expected " + childKind.toString() + childName +
+ " to be on line " + childLineNumbr + " but was on " +
+ element.getSourceLocation().getLine(),
+ childLineNumbr, element.getSourceLocation().getLine());
+ }
+ return element;
+ }
+ }
+ assertTrue("expected " + parent.getName() + " to have child " + childName
+ + " but it did not", foundChild);
+ return null;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ World.createInjarHierarchy = true;
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ World.createInjarHierarchy = false;
+ }
+
+ // ///////////////////////////////////////
+ public static Test suite() {
+ return XMLBasedAjcTestCase.loadSuite(CreatingModelForInjarTests.class);
+ }
+
+ protected File getSpecFile() {
+ return new File("../tests/src/org/aspectj/systemtest/ajc152/injar.xml");
+ }
+}
diff --git a/tests/src/org/aspectj/systemtest/ajc152/injar.xml b/tests/src/org/aspectj/systemtest/ajc152/injar.xml
new file mode 100644
index 000000000..955069a3e
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/ajc152/injar.xml
@@ -0,0 +1,13 @@
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>
+
+<!-- AspectJ v1.5.2 Tests -->
+<suite>
+
+ <ajc-test dir="bugs152/pr145963" title="advice and deow">
+ <compile files="ClassForAspectPath.java" aspectpath="adviceAndDeow.jar" options="-emacssym">
+ <message kind="warning" line="9" text="There should be no printlns"/>
+ </compile>
+ </ajc-test>
+
+
+</suite>