aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/org/aspectj
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/org/aspectj')
-rw-r--r--tests/src/org/aspectj/systemtest/AllTests.java2
-rw-r--r--tests/src/org/aspectj/systemtest/AllTests15.java2
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/ajc150.xml6
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java12
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java1
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/CreatingModelForInjarTests.java198
-rw-r--r--tests/src/org/aspectj/systemtest/ajc152/injar.xml20
-rw-r--r--tests/src/org/aspectj/systemtest/model/Model5Tests.java42
-rw-r--r--tests/src/org/aspectj/systemtest/model/ModelTestCase.java208
-rw-r--r--tests/src/org/aspectj/systemtest/model/ModelTests.java47
-rw-r--r--tests/src/org/aspectj/systemtest/model/model.xml31
11 files changed, 341 insertions, 228 deletions
diff --git a/tests/src/org/aspectj/systemtest/AllTests.java b/tests/src/org/aspectj/systemtest/AllTests.java
index 2a399b1dc..a4aec7d68 100644
--- a/tests/src/org/aspectj/systemtest/AllTests.java
+++ b/tests/src/org/aspectj/systemtest/AllTests.java
@@ -20,6 +20,7 @@ import org.aspectj.systemtest.incremental.IncrementalTests;
import org.aspectj.systemtest.incremental.model.IncrementalModelTests;
import org.aspectj.systemtest.incremental.tools.OutputLocationManagerTests;
import org.aspectj.systemtest.inpath.InPathTests;
+import org.aspectj.systemtest.model.ModelTests;
import org.aspectj.systemtest.options.OptionsTests;
import org.aspectj.systemtest.pre10x.AjcPre10xTests;
import org.aspectj.systemtest.serialVerUID.SUIDTests;
@@ -52,6 +53,7 @@ public class AllTests {
suite.addTest(SUIDTests.suite());
suite.addTest(XLintTests.suite());
suite.addTest(TracingTests.suite());
+ suite.addTest(ModelTests.suite());
//$JUnit-END$
return suite;
diff --git a/tests/src/org/aspectj/systemtest/AllTests15.java b/tests/src/org/aspectj/systemtest/AllTests15.java
index 09ed48206..e0a372662 100644
--- a/tests/src/org/aspectj/systemtest/AllTests15.java
+++ b/tests/src/org/aspectj/systemtest/AllTests15.java
@@ -11,6 +11,7 @@ import org.aspectj.systemtest.ajc150.ataspectj.AtAjAnnotationGenTests;
import org.aspectj.systemtest.ajc151.AllTestsAspectJ151;
import org.aspectj.systemtest.ajc152.AllTestsAspectJ152;
import org.aspectj.systemtest.ajc153.AllTestsAspectJ153;
+import org.aspectj.systemtest.model.Model5Tests;
import org.aspectj.systemtest.incremental.tools.MultiProjectIncrementalTests;
import org.aspectj.systemtest.xlint.XLint5Tests;
@@ -25,6 +26,7 @@ public class AllTests15 {
suite.addTest(AllTestsAspectJ152.suite());
suite.addTest(AllTestsAspectJ153.suite());
suite.addTest(AtAjAnnotationGenTests.suite());
+ suite.addTest(Model5Tests.suite());
/* FIXME maw Many of these tests do not depend on Java 5 but they
* cannot be executed in Eclipse with 1.3 because of XML issues and
* are excluded on the build machine so moving them here loses nothing
diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
index c8f86b2f5..3de18f230 100644
--- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
+++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
@@ -1880,9 +1880,9 @@
<weave classesFiles="AnnotatedType.java,SimpleAnnotation.java,SimpleAnnotation2.java"
aspectsFiles="AnnotationAspect02.aj"
options="-1.5,-showWeaveInfo">
- <message kind="weave" text="Type 'AnnotatedType' (AnnotatedType.java:3) advised by before advice from 'AnnotationAspect02' (AnnotationAspect02.aj:4)"/>
- <message kind="weave" text="Type 'AnnotatedType' (AnnotatedType.java:3) advised by before advice from 'AnnotationAspect02' (AnnotationAspect02.aj:2)"/>
- <message kind="weave" text="Type 'AnnotatedType' (AnnotatedType.java:4) advised by before advice from 'AnnotationAspect02' (AnnotationAspect02.aj:4)"/>
+ <message kind="weave" text="Type 'AnnotatedType' (AnnotatedType.java:3) advised by before advice from 'AnnotationAspect02' (aspects.jar!AnnotationAspect02.class:4(from AnnotationAspect02.aj))"/>
+ <message kind="weave" text="Type 'AnnotatedType' (AnnotatedType.java:3) advised by before advice from 'AnnotationAspect02' (aspects.jar!AnnotationAspect02.class:2(from AnnotationAspect02.aj))"/>
+ <message kind="weave" text="Type 'AnnotatedType' (AnnotatedType.java:4) advised by before advice from 'AnnotationAspect02' (aspects.jar!AnnotationAspect02.class:4(from AnnotationAspect02.aj))"/>
</weave>
</ajc-test>
diff --git a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
index bf7ae5bce..a47368db7 100644
--- a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
+++ b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
@@ -219,11 +219,11 @@ public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
// expecting:
// sourceOfRelationship main in MyFoo.java
// relationship advised by
- // target MyBar.aj
+ // target MyBar.class
//
// and
//
- // sourceOfRelationship MyBar.aj
+ // sourceOfRelationship MyBar.class
// relationship advises
// target main in MyFoo.java
@@ -236,8 +236,8 @@ public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
String sourceOfRelationship = (String) iter.next();
IProgramElement ipe = top.findElementForHandle(sourceOfRelationship);
List relationships = asmRelMap.get(ipe);
- if (ipe.getName().equals("MyBar.aj")) {
- assertEquals("expected MyBar.aj to have one relationships but found "
+ if (ipe.getName().equals("MyBar.class")) {
+ assertEquals("expected MyBar.class to have one relationships but found "
+ relationships.size(),1,relationships.size());
Relationship rel = (Relationship)relationships.get(0);
assertEquals("expected relationship to be 'advises' but was "
@@ -264,8 +264,8 @@ public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
List targets = rel.getTargets();
assertEquals("expected one target but found " + targets.size(),1,targets.size());
IProgramElement link = top.findElementForHandle((String)targets.get(0));
- assertEquals("expected target 'MyBar.aj' but target " + link.getName(),
- "MyBar.aj",link.getName());
+ assertEquals("expected target 'MyBar.class' but target " + link.getName(),
+ "MyBar.class",link.getName());
} else {
fail("unexpected element " + ipe.getName() + " in the relationship map");
diff --git a/tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java b/tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java
index 1cf8167f7..05c311f50 100644
--- a/tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java
+++ b/tests/src/org/aspectj/systemtest/ajc152/AllTestsAspectJ152.java
@@ -19,7 +19,6 @@ 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
deleted file mode 100644
index 845e7b29f..000000000
--- a/tests/src/org/aspectj/systemtest/ajc152/CreatingModelForInjarTests.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/********************************************************************
- * 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.asm.IRelationshipMap;
-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);
- }
-
- public void testAdviceInRelMap() {
- runTest("advice and deow");
- IHierarchy top = AsmManager.getDefault().getHierarchy();
- IProgramElement adviceNode = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.ADVICE,"before(): p..");
- IRelationshipMap relMap = AsmManager.getDefault().getRelationshipMap();
- List adviceRels = relMap.get(adviceNode);
- assertFalse("expected before advice to have relationships but did not",adviceRels.isEmpty());
- }
-
- public void testDeclareWarningInRelMap() {
- runTest("advice and deow");
- IHierarchy top = AsmManager.getDefault().getHierarchy();
- IProgramElement dwNode = top.findElementForLabel(top.getRoot(),
- IProgramElement.Kind.DECLARE_WARNING,
- "declare warning: \"There should be n..\"");
- IRelationshipMap relMap = AsmManager.getDefault().getRelationshipMap();
- List dwRels = relMap.get(dwNode);
- assertFalse("expected declare warning to have relationships but did not",dwRels.isEmpty());
- }
-
- public void testAdviceLabelsCorrect() {
- runTest("ensure advice label is correct");
- IHierarchy top = AsmManager.getDefault().getHierarchy();
-
- IProgramElement node = top.findElementForLabel(top.getRoot(),
- IProgramElement.Kind.ADVICE, "before(): execM1()..");
- assertNotNull("expected to find ipe with label 'before(): execM1()..'" +
- " but didn't", node);
-
- node = top.findElementForLabel(top.getRoot(),
- IProgramElement.Kind.ADVICE, "before(): execM2()..");
- assertNotNull("expected to find ipe with label 'before(): execM2()..'" +
- " but didn't", node);
-
- node = top.findElementForLabel(top.getRoot(),
- IProgramElement.Kind.ADVICE, "before(): <anonymous pointcut>");
- assertNotNull("expected to find ipe with label 'before(): <anonymous pointcut>'" +
- " but didn't", node);
- }
-
- // ensure that filled in hierarchy only has one entry for
- // aspect
- public void testOnlyOneAspectEntry() {
- runTest("ensure advice label is correct");
-
- IProgramElement pkgNode = getPkgNode();
- assertEquals("expected one child node but found " +
- pkgNode.getChildren().size(), 1, pkgNode.getChildren().size());
-
- }
-
- public void testOnlyOneAspectEntry_inDefaultPackage() {
- runTest("aspect in default package");
- // expect there to be two children - 'pack' and
- // 'AspectInDefaultPackage.aj (binary)'
- IProgramElement defaultPkg = AsmManager.getDefault().getHierarchy().getRoot();
- assertEquals("expected two child node but found " +
- defaultPkg.getChildren().size(), 2, defaultPkg.getChildren().size());
-
- }
-
- // --------------------- Helper methods ---------------------
-
- 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
deleted file mode 100644
index f53dbbaac..000000000
--- a/tests/src/org/aspectj/systemtest/ajc152/injar.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<!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>
-
- <ajc-test dir="bugs152/pr145963" title="ensure advice label is correct">
- <compile files="C.java" aspectpath="adviceLabels.jar" options="-emacssym"/>
- </ajc-test>
-
- <ajc-test dir="bugs152/pr145963" title="aspect in default package">
- <compile files="C.java" aspectpath="aspectInDefaultPackage.jar" options="-emacssym"/>
- </ajc-test>
-
-</suite>
diff --git a/tests/src/org/aspectj/systemtest/model/Model5Tests.java b/tests/src/org/aspectj/systemtest/model/Model5Tests.java
new file mode 100644
index 000000000..6678256e6
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/model/Model5Tests.java
@@ -0,0 +1,42 @@
+/********************************************************************
+ * 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.model;
+
+import java.io.File;
+
+import junit.framework.Test;
+
+import org.aspectj.testing.XMLBasedAjcTestCase;
+
+/**
+ * Tests the model when there is a requirement on Java5 features.
+ * @see org.aspectj.systemtest.model.ModelTestCase
+ */
+public class Model5Tests extends ModelTestCase {
+
+ static {
+ // Switch this to true for a single iteration if you want to reconstruct the
+ // 'expected model' files.
+ regenerate = false;
+ // Switch this to true if you want to debug the comparison
+ debugTest = false;
+ }
+
+ // ///////////////////////////////////////
+ public static Test suite() {
+ return XMLBasedAjcTestCase.loadSuite(Model5Tests.class);
+ }
+
+ protected File getSpecFile() {
+ return new File("../tests/src/org/aspectj/systemtest/model/model.xml");
+ }
+
+}
diff --git a/tests/src/org/aspectj/systemtest/model/ModelTestCase.java b/tests/src/org/aspectj/systemtest/model/ModelTestCase.java
new file mode 100644
index 000000000..37f873839
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/model/ModelTestCase.java
@@ -0,0 +1,208 @@
+/********************************************************************
+ * 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.model;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.aspectj.asm.AsmManager;
+import org.aspectj.asm.IElementHandleProvider;
+import org.aspectj.asm.IModelFilter;
+import org.aspectj.asm.internal.JDTLikeHandleProvider;
+import org.aspectj.testing.XMLBasedAjcTestCase;
+import org.aspectj.util.FileUtil;
+
+/**
+ * This class provides an extension to the XMLBasedAjcTestCase to manage
+ * testing the model. It assumes the testdata is in ../tests/model/<testid>
+ * and that the expected model against which to do the comparison is in
+ * the file ../tests/model/expected/<testid>.txt. One test ensures that both
+ * the model and the relationship map are as expected for the given testdata.
+ *
+ * To write a testcase, create a testdata directory containing the data
+ * for the test run and a file containing the expected model (this can be
+ * generated by setting the regenerate flag to true). Add the required
+ * configuration to model.xml. Finally, create a testcase in either ModelTests
+ * or Model5Tests (depending on whether the testcase has a requirement
+ * on Java5) and call runModelTest(<title of test>,<testid>).
+ */
+public abstract class ModelTestCase extends XMLBasedAjcTestCase {
+
+ protected static boolean regenerate = false;
+ protected static boolean debugTest = false;
+
+ private final String expectedOutDir = "../tests/model/expected" + File.separator;
+ private String testid;
+
+ private String modelFilename;
+
+ private IElementHandleProvider handleProvider;
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ // using the JDTLikeHandleProvider because this produces consistent handles
+ // over different compiles
+ handleProvider = AsmManager.getDefault().getHandleProvider();
+ AsmManager.getDefault().setHandleProvider(new JDTLikeHandleProvider());
+ // We are about to create a sandbox for the model output file, don't let the
+ // following compile wipe it.
+ ajc.setShouldEmptySandbox(false);
+ // report all information - model, relationships delta processing
+ modelFilename = ajc.getSandboxDirectory().getAbsolutePath() + File.separator + "model.txt";
+ AsmManager.setReporting(modelFilename,
+ true,true,true,false,new TestFilter(ajc.getSandboxDirectory().getAbsolutePath()));
+ }
+
+ static class TestFilter implements IModelFilter {
+ String sandboxDirectory ;
+ public TestFilter(String sandboxDirectory) {
+ this.sandboxDirectory = sandboxDirectory;
+ }
+
+ public String processFilelocation(String loc) {
+ if (loc.startsWith(sandboxDirectory)) return "TEST_SANDBOX"+loc.substring(sandboxDirectory.length());
+ return loc;
+ }
+
+ public boolean wantsHandleIds() {
+ return false;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ AsmManager.getDefault().setHandleProvider(handleProvider);
+ AsmManager.setDontReport();
+ ajc.setShouldEmptySandbox(true);
+ }
+
+ /**
+ * Firstly sets the testid which is both the name of the expected output
+ * file and the name of the testdata directory. It then
+ * invokes XMLBasedAjcTestCase.runTest(String) with the given
+ * title and finally verifies that the model file created from this test
+ * run is the same as the expected output (includes model information, the
+ * relationship map and various properties about the model) contained
+ * in ../tests/model/expected/<testid>.txt
+ */
+ protected void runModelTest(String title,String testid) {
+ this.testid = testid;
+ runTest(title);
+ verifyModel();
+ }
+
+ private void verifyModel() {
+ File expectedOutput = new File(expectedOutDir + testid + ".txt");
+ if (regenerate) {
+ // Create the file
+ saveModel(expectedOutput);
+ } else {
+ // Verify the file matches what we have
+ compareModel(expectedOutput);
+ }
+ }
+
+ private void compareModel(File expectedF) {
+ if (debugTest) System.out.println("comparing with model in file " + expectedF.getAbsolutePath());
+ List fileContents = new ArrayList();
+ try {
+ String sandboxDir = ajc.getSandboxDirectory().getAbsolutePath();
+ String modelOutput = modelFilename;
+ // Load the file with the expected output
+ BufferedReader expect = new BufferedReader(new FileReader(expectedF));
+// String tempDir = expect.readLine();
+ String expectedLine = null;
+ while((expectedLine=expect.readLine())!=null) {
+ fileContents.add(expectedLine);
+ }
+ List expectedFileContents = new ArrayList();
+ expectedFileContents.addAll(fileContents);
+
+ // Load the file with the output from this test run
+ BufferedReader found = new BufferedReader(new FileReader(new File(modelOutput)));
+ String foundLine = null;
+ List foundFileContents = new ArrayList();
+ while((foundLine=found.readLine())!=null) {
+// int i = foundLine.indexOf(sandboxDir);
+// if (i == -1) {
+// int j = foundLine.indexOf("(targets=");
+// if (j == -1) {
+ foundFileContents.add(foundLine);
+// } else {
+// foundFileContents.add(foundLine.substring(j));
+// }
+// } else {
+// String newLine = foundLine.substring(0,i) + tempDir
+// + foundLine.substring(i + sandboxDir.length());
+// foundFileContents.add(newLine);
+// }
+ }
+
+ // iterate over what we found
+ for (Iterator iter = foundFileContents.iterator(); iter.hasNext();) {
+ String line = (String) iter.next();
+ if (debugTest) System.err.println("looking at model entry: " + line);
+ if (!fileContents.contains(line)) {
+// if (!((String)fileContents.get(lineNumber)).equals(line)) {
+
+ if(debugTest) {
+ System.err.println("couldn't find: " + line);
+ for (Iterator iterator = fileContents.iterator(); iterator
+ .hasNext();) {
+ String element = (String) iterator.next();
+ System.err.println("compared with: " + element);
+ }
+ }
+
+// StringBuffer errorData = new StringBuffer();
+// errorData.append("Problem with comparison at line number: "+)
+ fail("couldn't find model entry '" + line + "' in expected output");
+ } else {
+ fileContents.remove(line);
+ }
+ }
+
+ if (debugTest && !fileContents.isEmpty()) {
+ for (Iterator iter = fileContents.iterator(); iter
+ .hasNext();) {
+ String element = (String) iter.next();
+ System.err.println("remaining: " + element);
+ }
+ }
+ assertTrue("should have found all expected model output: " + fileContents,fileContents.isEmpty());
+ } catch (Exception e) {
+ fail("Unexpected exception comparing model files:"+e);
+ }
+ }
+
+ private void saveModel(File f) {
+ if (debugTest) System.out.println("Saving model into "+f.getAbsolutePath());
+ File modelFile = new File(modelFilename);
+ try {
+ FileUtil.copyFile(modelFile, f);
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ fail("Couldn't copy file to "+f.toString());
+ }
+ }
+
+}
diff --git a/tests/src/org/aspectj/systemtest/model/ModelTests.java b/tests/src/org/aspectj/systemtest/model/ModelTests.java
new file mode 100644
index 000000000..304321698
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/model/ModelTests.java
@@ -0,0 +1,47 @@
+/********************************************************************
+ * 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.model;
+
+import java.io.File;
+
+import junit.framework.Test;
+
+import org.aspectj.testing.XMLBasedAjcTestCase;
+
+/**
+ * Tests the model when there is no requirement on Java5 features.
+ * @see org.aspectj.systemtest.model.ModelTestCase
+ */
+public class ModelTests extends ModelTestCase {
+
+ static {
+ // Switch this to true for a single iteration if you want to reconstruct the
+ // 'expected model' files.
+ regenerate = false;
+ // Switch this to true if you want to debug the comparison
+ debugTest = false;
+ }
+
+ public void testSourceLocationAndJarFile_pr145963() {runModelTest("sourcelocation and jar file","pr145963_1");}
+ public void testSourceLocationAndClassFile_pr145963() {runModelTest("sourcelocation and class file","pr145963_2");}
+ public void testAspectInDefaultPackage_pr145963() {runModelTest("aspect in default package", "pr145963_3");}
+ public void testAspectInJavaFile_pr145963() {runModelTest("aspect in java file", "pr145963_4");}
+
+ /////////////////////////////////////////
+ public static Test suite() {
+ return XMLBasedAjcTestCase.loadSuite(ModelTests.class);
+ }
+
+ protected File getSpecFile() {
+ return new File("../tests/src/org/aspectj/systemtest/model/model.xml");
+ }
+
+}
diff --git a/tests/src/org/aspectj/systemtest/model/model.xml b/tests/src/org/aspectj/systemtest/model/model.xml
new file mode 100644
index 000000000..5a1843e22
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/model/model.xml
@@ -0,0 +1,31 @@
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>
+
+<!-- Model and Hierarchy Tests -->
+<suite>
+
+ <ajc-test dir="model/pr145963_1" title="sourcelocation and jar file">
+ <compile files="C.java, SourceAspect.aj" aspectpath="simple.jar" options="-emacssym">
+ <message kind="warning" line="6" text="There should be no printlns"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="model/pr145963_2" title="sourcelocation and class file">
+ <compile files="C.java, SourceAspect.aj" aspectpath="pkg" options="-emacssym">
+ <message kind="warning" line="6" text="There should be no printlns"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="model/pr145963_3" title="aspect in default package">
+ <compile files="C.java" aspectpath="simple.jar" options="-emacssym">
+ <message kind="warning" line="6" text="There should be no printlns"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="model/pr145963_4" title="aspect in java file">
+ <compile files="C.java" aspectpath="simple.jar" options="-emacssym">
+ <message kind="warning" line="6" text="There should be no printlns"/>
+ </compile>
+ </ajc-test>
+
+
+</suite>