From 1381903ac81cdab2b79b6525096671aa5d62eaeb Mon Sep 17 00:00:00 2001 From: acolyer Date: Fri, 11 Feb 2005 12:47:56 +0000 Subject: [PATCH] move all java 5 tests out of code and back into .xml files now that we can compile them properly --- tests/bugs/java5/arrayCloning/C.java | 2 +- .../thisOrtarget/ThisOrTargetTests.aj | 49 +- tests/java5/enums/Enum.java | 3 - tests/java5/enums/EnumAspect03.aj | 5 +- tests/java5/enums/EnumAspect04.aj | 3 +- tests/java5/generics/GenericMethods.java | 51 + .../generics/GenericParameterMatching.aj | 65 ++ .../generics/ParameterizedMethodMatching.aj | 21 + tests/java5/generics/ParameterizedType.java | 19 + tests/java5/generics/ReturningLists.aj | 27 + tests/java5/generics/issues.txt | 21 + .../org/aspectj/systemtest/AllTests15.java | 4 +- .../systemtest/ajc121/Ajc121Tests.java | 18 - .../systemtest/ajc121/ajc121-tests.xml | 6 - .../systemtest/ajc150/AccBridgeMethods.java | 16 +- .../systemtest/ajc150/Ajc150Tests.java | 89 ++ .../ajc150/Ajc150TestsNoHarness.java | 96 -- .../ajc150/Ajc150TestsRequireJava15.java | 44 - .../systemtest/ajc150/AllTestsAspectJ150.java | 14 +- .../ajc150/AllTestsAspectJ150_NeedJava15.java | 32 - .../systemtest/ajc150/AnnotationBinding.java | 186 +--- .../ajc150/AnnotationPointcutsTests.java | 58 +- .../ajc150/AnnotationRuntimeTests.java | 54 +- .../systemtest/ajc150/Annotations.java | 60 +- .../ajc150/AnnotationsBinaryWeaving.java | 57 +- .../aspectj/systemtest/ajc150/Autoboxing.java | 153 +-- .../systemtest/ajc150/CovarianceTests.java | 178 +--- .../org/aspectj/systemtest/ajc150/Enums.java | 76 +- .../systemtest/ajc150/MigrationTests.java | 33 +- .../systemtest/ajc150/PerTypeWithinTests.java | 137 +-- .../aspectj/systemtest/ajc150/TestUtils.java | 135 --- .../systemtest/ajc150/VarargsTests.java | 68 +- .../systemtest/ajc150/ajc150-tests.xml | 31 - .../org/aspectj/systemtest/ajc150/ajc150.xml | 893 +++++++++++++++++- 34 files changed, 1555 insertions(+), 1149 deletions(-) delete mode 100644 tests/java5/enums/Enum.java create mode 100644 tests/java5/generics/GenericMethods.java create mode 100644 tests/java5/generics/GenericParameterMatching.aj create mode 100644 tests/java5/generics/ParameterizedMethodMatching.aj create mode 100644 tests/java5/generics/ParameterizedType.java create mode 100644 tests/java5/generics/ReturningLists.aj create mode 100644 tests/java5/generics/issues.txt delete mode 100644 tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java delete mode 100644 tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsRequireJava15.java delete mode 100644 tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150_NeedJava15.java delete mode 100644 tests/src/org/aspectj/systemtest/ajc150/TestUtils.java delete mode 100644 tests/src/org/aspectj/systemtest/ajc150/ajc150-tests.xml diff --git a/tests/bugs/java5/arrayCloning/C.java b/tests/bugs/java5/arrayCloning/C.java index 8886906f5..616fdcf15 100644 --- a/tests/bugs/java5/arrayCloning/C.java +++ b/tests/bugs/java5/arrayCloning/C.java @@ -1,6 +1,6 @@ import java.lang.reflect.*; -class C { +public class C { public static B.D[] arr = new B.D[5]; diff --git a/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj b/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj index cc5ab5cd0..2936b2ec5 100644 --- a/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj +++ b/tests/java5/annotations/thisOrtarget/ThisOrTargetTests.aj @@ -1,7 +1,18 @@ import java.util.List; +import java.util.ArrayList; +import java.util.Iterator; +import org.aspectj.lang.JoinPoint.StaticPart; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.Signature; public aspect ThisOrTargetTests { + List before1Matches = new ArrayList(); + List before2Matches = new ArrayList(); + List after1Matches = new ArrayList(); + List after2Matches = new ArrayList(); + + pointcut doSomethingExecution() : execution(* doSomething()); pointcut doSomethingCall() : call(* doSomething()); @@ -9,7 +20,7 @@ public aspect ThisOrTargetTests { // should match: // b.doSomething(), reallyB.doSomething() [with test], // c.doSomething() - System.out.println("@this(@MyAnnotation): " + thisJoinPointStaticPart); + add(before1Matches,thisJoinPointStaticPart); } before() : doSomethingExecution() && @this(@MyInheritableAnnotation) { @@ -17,14 +28,14 @@ public aspect ThisOrTargetTests { // c.doSomething() // d.doSomething() // reallyD.doSomething() - System.out.println("@this(@MyInheritableAnnotation): " + thisJoinPointStaticPart); + add(before2Matches,thisJoinPointStaticPart); } after() returning : doSomethingCall() && @target(@MyAnnotation) { // should match: // b.doSomething(), reallyB.doSomething() [with test], // c.doSomething() - System.out.println("@target(@MyAnnotation): " + thisJoinPointStaticPart); + add(after1Matches,thisJoinPointStaticPart); } after() returning : doSomethingCall() && @target(@MyInheritableAnnotation) { @@ -32,7 +43,37 @@ public aspect ThisOrTargetTests { // c.doSomething() // d.doSomething() // reallyD.doSomething() - System.out.println("@target(@MyInheritableAnnotation): " + thisJoinPointStaticPart); + add(after2Matches,thisJoinPointStaticPart); } + private void add(List toList, JoinPoint.StaticPart jpsp) { + Signature sig = jpsp.getSignature(); + String toAdd = sig.getDeclaringTypeName() + "." + sig.getName(); + toList.add(toAdd); + } + + after() returning : execution(* main(String[])) { + assertMatches("before1",before1Matches, + new String[] {"B.doSomething","C.doSomething","B.doSomething"} ); + assertMatches("before2",before2Matches, + new String[] {"C.doSomething","D.doSomething","D.doSomething"} ); + assertMatches("after1",after1Matches, + new String[] {"B.doSomething","C.doSomething","A.doSomething"} ); + assertMatches("after2",after2Matches, + new String[] {"C.doSomething","D.doSomething","C.doSomething"} ); + } + + private void assertMatches(String name, List matches,String[] spec) { + if (matches.size() != spec.length) { + for (Iterator iter = matches.iterator(); iter.hasNext();) { + String match = iter.next(); + System.out.println(match); + } + + throw new RuntimeException(name + ": Expected " + spec.length + " matches, got " + matches.size()); + } + for (int i = 0; i < spec.length; i++) { + if (!matches.get(i).equals(spec[i])) throw new RuntimeException(name + ":Excepted " + spec[i] + " got " + matches.get(i)); + } + } } \ No newline at end of file diff --git a/tests/java5/enums/Enum.java b/tests/java5/enums/Enum.java deleted file mode 100644 index b04789320..000000000 --- a/tests/java5/enums/Enum.java +++ /dev/null @@ -1,3 +0,0 @@ -package java.lang; // Fake class to keep 1.4 JVM (that will be running the tests) happy -public class Enum { -} diff --git a/tests/java5/enums/EnumAspect03.aj b/tests/java5/enums/EnumAspect03.aj index ecaa2e20e..2ebcdeeea 100644 --- a/tests/java5/enums/EnumAspect03.aj +++ b/tests/java5/enums/EnumAspect03.aj @@ -1,9 +1,10 @@ import java.lang.Enum; public aspect EnumAspect03 { - declare parents: SimpleEnum implements java.io.Serializable; + interface I {} + declare parents: SimpleEnum implements I; - class C extends Enum { } + enum C {A,B,C}; declare parents: SimpleEnum extends C; class D {} diff --git a/tests/java5/enums/EnumAspect04.aj b/tests/java5/enums/EnumAspect04.aj index 834d48807..439c9d4ef 100644 --- a/tests/java5/enums/EnumAspect04.aj +++ b/tests/java5/enums/EnumAspect04.aj @@ -1,6 +1,7 @@ import java.lang.Enum; public aspect EnumAspect04 { - declare parents: SimpleE* implements java.io.Serializable; + interface I {}; + declare parents: SimpleE* implements I; } diff --git a/tests/java5/generics/GenericMethods.java b/tests/java5/generics/GenericMethods.java new file mode 100644 index 000000000..78ef49212 --- /dev/null +++ b/tests/java5/generics/GenericMethods.java @@ -0,0 +1,51 @@ +import java.util.*; +/* + * test case fodder for basic generic signature matching + */ +public class GenericMethods { + + public List returningListOfInteger() { + return new LinkedList(); + } + + public List returningListOfObject() { + return new LinkedList(); + } + + public List returningRawList() { return new ArrayList(); } + + public LinkedList returningSubtypeOfListOfInteger() { + return new LinkedList(); + } + + public void takesAMap(Map aMap) {} + + public void takesAHashmap(HashMap aMap) {} + + public static void staticTakesAMap(Map aMap) {} + + public void collectionOfAnything(Collection aCollection) {} + + public void collectionOfAnyNumber(Collection aNumberCollection) {} + + public void collectionOfAnythingTakingADouble(Collection aDoubleHandlingCollection) {} + + // now some fun with statics + static T findMax(List ts) { return ts.get(0); } + + static > T betterMax(Collection collection) { + return null; + } + + static > T evenBetterMax(Collection coll) { + return null; + } + + static > T jdkMax(Collection coll) { + return null; + } + + static void copy(List dest, List src) {} + + static copyv2(List dest, List src) {} +} \ No newline at end of file diff --git a/tests/java5/generics/GenericParameterMatching.aj b/tests/java5/generics/GenericParameterMatching.aj new file mode 100644 index 000000000..e044e3c93 --- /dev/null +++ b/tests/java5/generics/GenericParameterMatching.aj @@ -0,0 +1,65 @@ +import java.util.*; + +public aspect GenericParameterMatching { + + pointcut takesAMap() : execution(* *(Map)); + // matches takesAMap, staticTakesAMap + + pointcut takesAnyMapType() : execution(* *(Map+)); + // matches collectionOfAnything + + pointcut collectionOfAnyNumber() : execution(* *(Collection)); + // matches collectionOfAnythingTakingADouble + + pointcut anyCollection() : execution(* *(Collection<*>)); + // matches all 3 collection methods + + pointcut anyObjectOrSubtypeCollection() : execution(* *(Collection)); + // matches collection of any number + + pointcut superTypePattern(): execution(* *(Collection)); + // matches collection of anything taking a double + + // RTT matching... + + pointcut mapargs() : args(Map); + // matches takesAMap, staticTakesAMap, takesAHashmap + + pointcut hashmapargs() : args(HashMap); + // matches takesAHashmap, RT test for takesAMap, staticTakesAmap + + pointcut nomapargs(): args(Map); + // no matches + + pointcut wildargs() : args(Map); + // matches takesAMap, staticTakesAMap, takesAHashmap + + pointcut nowildargs() : args(Map); + // no matches + + pointcut wildsuperargs() : args(Map); + // matches takesAmap, staticTakesAmap, takesAHashmap + + // RTT matching with signature wildcards + + pointcut collAnythingArgs() : args(Collection); + // matches all collection methods + + pointcut collNumberArgs() : args(Collection); + // does NOT match collectionOfAnyNumber (can't insert safely) + // does NOT match collectionOfAnythingTakingADouble (can't remove safely) + + pointcut collNumberArgsWild() : args(Collection); + // matches collection of any number + + pointcut superDoubleArgs(): args(Collection); + // matches coll taking a double + + // add max and copy tests here... +} \ No newline at end of file diff --git a/tests/java5/generics/ParameterizedMethodMatching.aj b/tests/java5/generics/ParameterizedMethodMatching.aj new file mode 100644 index 000000000..d33d48ecd --- /dev/null +++ b/tests/java5/generics/ParameterizedMethodMatching.aj @@ -0,0 +1,21 @@ +import java.util.*; + +public aspect ParameterizedMethodMatching { + + pointcut findMax() : execution(static T *(List)); + // matches findMax + // does not match e.g. Object foo(List foos) {...} + + pointcut findMax2() : execution(static X * List)); + // matches findMax + + pointcut findMax3() : execution(static T+ *(List)); + // CE + + pointcut listargs(): args(List); + // always matches findMax + + pointcut listNumberargs() : args(List); + // may match findMax (RTT) + +} \ No newline at end of file diff --git a/tests/java5/generics/ParameterizedType.java b/tests/java5/generics/ParameterizedType.java new file mode 100644 index 000000000..24a501b3d --- /dev/null +++ b/tests/java5/generics/ParameterizedType.java @@ -0,0 +1,19 @@ +import java.util.*; + +/* + * test case fodder for basic member matching with parameterized types + */ + public class ParameterizedType { + + T aTField; + S anSField; + + T giveMeAT() { return null; } + S giveMeAnS() { return null; } + + S sComesBeforeT(T t) { return null; } + + void theMadMapper(Map aMap) {} + + static T convert(S s) { return null; } + } \ No newline at end of file diff --git a/tests/java5/generics/ReturningLists.aj b/tests/java5/generics/ReturningLists.aj new file mode 100644 index 000000000..ae260ce2a --- /dev/null +++ b/tests/java5/generics/ReturningLists.aj @@ -0,0 +1,27 @@ +import java.util.*; + +public aspect ReturningLists { + + pointcut listOfInteger() : execution(List *(..)); + // matches returningListOfInteger + + pointcut listOfObject() : execution(List *(..)); + // matches returningListOfObject + + pointcut listOfObjects() : execution(List *(..)); + // matches returningListOfInteger and returningListofObject + + pointcut listOfAnything() : execution(List<*> *(..)); + // matches returningListOfInteger and returningListofObject + + pointcut rawList() : execution(List *(..)); + // matches returningRawList + + pointcut wildcardList() : execution(List *(..)); + // matches nothing + + pointcut anyListType() : execution(List+<*> *(..)); + // matches returning list of integer, returning list of object, + // returning subtype of list of integer + +} \ No newline at end of file diff --git a/tests/java5/generics/issues.txt b/tests/java5/generics/issues.txt new file mode 100644 index 000000000..2b78e9ef5 --- /dev/null +++ b/tests/java5/generics/issues.txt @@ -0,0 +1,21 @@ +pointcut matching for constructor calls: + +call(List.new()) ? + +call(List.new(Integer i)) ?? + +call( List.new()) + +call( List.new(T)) + +execution likewise ? + +for methods and fields in parameterized types: + +call( foo(T)) etc. ? + +There is only ONE class remember. + +get( T foo*) + +does get(Object obj) match new Foo() with Foo { T obj } ??? \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/AllTests15.java b/tests/src/org/aspectj/systemtest/AllTests15.java index 647bd722a..badf030b5 100644 --- a/tests/src/org/aspectj/systemtest/AllTests15.java +++ b/tests/src/org/aspectj/systemtest/AllTests15.java @@ -6,7 +6,7 @@ package org.aspectj.systemtest; import junit.framework.Test; import junit.framework.TestSuite; -import org.aspectj.systemtest.ajc150.AllTestsAspectJ150_NeedJava15; +import org.aspectj.systemtest.ajc150.AllTestsAspectJ150; public class AllTests15 { @@ -14,7 +14,7 @@ public class AllTests15 { TestSuite suite = new TestSuite("AspectJ System Test Suite - JDK 1.5"); //$JUnit-BEGIN$ suite.addTest(AllTests14.suite()); - suite.addTestSuite(AllTestsAspectJ150_NeedJava15.class); + suite.addTest(AllTestsAspectJ150.suite()); //$JUnit-END$ return suite; } diff --git a/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java b/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java index 1926ea38e..70a0eb59c 100644 --- a/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java @@ -10,12 +10,9 @@ package org.aspectj.systemtest.ajc121; import java.io.File; -import java.util.Iterator; -import java.util.List; import junit.framework.Test; -import org.aspectj.bridge.WeaveMessage; import org.aspectj.testing.XMLBasedAjcTestCase; public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { @@ -273,21 +270,6 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public void test050_typePatternMatchingWithArrays() { runTest("declare warning warns at wrong points"); } - - public void test051_arrayCloningInJava5() { - runTest("AJC possible bug with static nested classes"); - List l = ajc.getLastCompilationResult().getInfoMessages(); - assertTrue("Should at least have had one weaving message",l!=null && l.size()>0); - boolean gotWeaveMessage = false; - for (Iterator msg = l.iterator(); msg.hasNext();) { - Object element = (Object) msg.next(); - if (element instanceof WeaveMessage) { - WeaveMessage wm = (WeaveMessage)element; - if (wm.getMessage().indexOf("advised by around advice from")!=-1) gotWeaveMessage = true; - } - } - assertTrue("Expected a weaving message but only found "+l,gotWeaveMessage); - } public void test052_bogusMessage1() { runTest("Bogus error message: The abstract method ajc$pointcut$$tracingScope$a2 in type Tracing can only be defined by an abstract class (1)"); diff --git a/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml b/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml index 64e966c94..be0f58644 100644 --- a/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml +++ b/tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml @@ -406,12 +406,6 @@ - - - - - diff --git a/tests/src/org/aspectj/systemtest/ajc150/AccBridgeMethods.java b/tests/src/org/aspectj/systemtest/ajc150/AccBridgeMethods.java index f364528d9..c22cfd947 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/AccBridgeMethods.java +++ b/tests/src/org/aspectj/systemtest/ajc150/AccBridgeMethods.java @@ -66,21 +66,7 @@ public class AccBridgeMethods extends org.aspectj.testing.XMLBasedAjcTestCase { */ public void test001_bridgeMethodIgnored() { runTest("Ignore bridge methods"); - List weaveMessages = getWeaveMessages(ajc.getLastCompilationResult(),false); - assertTrue("Should only be two weave messages",weaveMessages.size()==2); } - private List getWeaveMessages(CompilationResult cr,boolean printThem) { - List weaveMessages = new ArrayList(); - List infoMessages = cr.getInfoMessages(); - for (Iterator iter = infoMessages.iterator(); iter.hasNext();) { - IMessage element = (IMessage) iter.next(); - if (element.getKind()==IMessage.WEAVEINFO) { - weaveMessages.add(element); - if (printThem) System.err.println(element); - } - } - return weaveMessages; - } - + } \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index a84821aab..4d9aaba79 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -10,10 +10,18 @@ *******************************************************************************/ package org.aspectj.systemtest.ajc150; +import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; import junit.framework.Test; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.util.ClassPath; +import org.aspectj.apache.bcel.util.SyntheticRepository; +import org.aspectj.asm.AsmManager; import org.aspectj.testing.XMLBasedAjcTestCase; /** @@ -44,4 +52,85 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public void test_ambiguousArgsDetection() { runTest("ambiguous args"); } + + public void testIncorrectExceptionTableWhenBreakInMethod_pr78021() { + runTest("Injecting exception into while loop with break statement causes catch block to be ignored"); + } + + + public void testIncorrectExceptionTableWhenReturnInMethod_pr79554() { + runTest("Return in try-block disables catch-block if final-block is present"); + } + + public void testMissingDebugInfoForGeneratedMethods_pr82570() throws ClassNotFoundException { + runTest("Weaved code does not include debug lines"); + boolean f = false; + JavaClass jc = getClassFrom(ajc.getSandboxDirectory(),"PR82570_1"); + Method[] meths = jc.getMethods(); + for (int i = 0; i < meths.length; i++) { + Method method = meths[i]; + if (f) System.err.println("Line number table for "+method.getName()+method.getSignature()+" = "+method.getLineNumberTable()); + assertTrue("Didn't find a line number table for method "+method.getName()+method.getSignature(), + method.getLineNumberTable()!=null); + } + + // This test would determine the info isn't there if you pass -g:none ... +// cR = ajc(baseDir,new String[]{"PR82570_1.java","-g:none"}); +// assertTrue("Expected no compile problem:"+cR,!cR.hasErrorMessages()); +// System.err.println(cR.getStandardError()); +// jc = getClassFrom(ajc.getSandboxDirectory(),"PR82570_1"); +// meths = jc.getMethods(); +// for (int i = 0; i < meths.length; i++) { +// Method method = meths[i]; +// assertTrue("Found a line number table for method "+method.getName(), +// method.getLineNumberTable()==null); +// } + } + + + public void testCanOverrideProtectedMethodsViaITDandDecp_pr83303() { + runTest("compiler error when mixing inheritance, overriding and polymorphism"); + } + + public void testPerTypeWithinMissesNamedInnerTypes() { + runTest("pertypewithin() handing of inner classes (1)"); + } + + public void testPerTypeWithinMissesAnonymousInnerTypes() { + runTest("pertypewithin() handing of inner classes (2)"); + } + + public void testPerTypeWithinIncorrectlyMatchingInterfaces() { + runTest("pertypewithin({interface}) illegal field modifier"); + } + + public void test051_arrayCloningInJava5() { + runTest("AJC possible bug with static nested classes"); + } + + public void testBadASMforEnums() throws IOException { + runTest("bad asm for enums"); + + if (System.getProperty("java.vm.version").startsWith("1.5")) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintWriter pw = new PrintWriter(baos); + AsmManager.dumptree(pw,AsmManager.getDefault().getHierarchy().getRoot(),0); + pw.flush(); + String tree = baos.toString(); + assertTrue("Expected 'Red [enumvalue]' somewhere in here:"+tree,tree.indexOf("Red [enumvalue]")!=-1); + } + } + + // helper methods..... + + public SyntheticRepository createRepos(File cpentry) { + ClassPath cp = new ClassPath(cpentry+File.pathSeparator+System.getProperty("java.class.path")); + return SyntheticRepository.getInstance(cp); + } + + protected JavaClass getClassFrom(File where,String clazzname) throws ClassNotFoundException { + SyntheticRepository repos = createRepos(where); + return repos.loadClass(clazzname); + } + } \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java deleted file mode 100644 index b3835b786..000000000 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsNoHarness.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * 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 org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.tools.ajc.CompilationResult; - - -/** - * These are tests that run on Java 1.4 and use the new ajctestcase format. - * If you have a test that *needs* to run on Java 1.5 then look in Ajc150TestsRequireJava15.java - */ -public class Ajc150TestsNoHarness extends TestUtils { - - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/bugs150"); - } - - public void testIncorrectExceptionTableWhenBreakInMethod_pr78021() { - CompilationResult cR=ajc(baseDir,new String[]{"PR78021.java"}); - if (verbose) { System.err.println(cR); System.err.println(cR.getStandardError());} - RunResult rR = run("PR78021"); - if (verbose) {System.err.println(rR.getStdErr());} - } - - - public void testIncorrectExceptionTableWhenReturnInMethod_pr79554() { - CompilationResult cR=ajc(baseDir,new String[]{"PR79554.java"}); - if (verbose) { System.err.println(cR); System.err.println(cR.getStandardError());} - RunResult rR = run("PR79554"); - if (verbose) {System.err.println(rR.getStdErr());} - } - - - public void testMissingDebugInfoForGeneratedMethods_pr82570() throws ClassNotFoundException { - boolean f = false; - CompilationResult cR = ajc(baseDir,new String[]{"PR82570_1.java"}); - System.err.println(cR.getStandardError()); - assertTrue("Expected no compile problem:"+cR,!cR.hasErrorMessages()); - JavaClass jc = getClassFrom(ajc.getSandboxDirectory(),"PR82570_1"); - Method[] meths = jc.getMethods(); - for (int i = 0; i < meths.length; i++) { - Method method = meths[i]; - if (f) System.err.println("Line number table for "+method.getName()+method.getSignature()+" = "+method.getLineNumberTable()); - assertTrue("Didn't find a line number table for method "+method.getName()+method.getSignature(), - method.getLineNumberTable()!=null); - } - - // This test would determine the info isn't there if you pass -g:none ... -// cR = ajc(baseDir,new String[]{"PR82570_1.java","-g:none"}); -// assertTrue("Expected no compile problem:"+cR,!cR.hasErrorMessages()); -// System.err.println(cR.getStandardError()); -// jc = getClassFrom(ajc.getSandboxDirectory(),"PR82570_1"); -// meths = jc.getMethods(); -// for (int i = 0; i < meths.length; i++) { -// Method method = meths[i]; -// assertTrue("Found a line number table for method "+method.getName(), -// method.getLineNumberTable()==null); -// } - } - - public void testCanOverrideProtectedMethodsViaITDandDecp_pr83303() { - CompilationResult cR = ajc(baseDir,new String[]{"PR83303.java"}); - assertTrue("Should be no errors:"+cR,!cR.hasErrorMessages()); - } - - public void testPerTypeWithinMissesNamedInnerTypes() { - CompilationResult cR = ajc(baseDir,new String[]{"PR83563_1.java"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("PR83563_1"); - } - - public void testPerTypeWithinMissesAnonymousInnerTypes() { - CompilationResult cR = ajc(baseDir,new String[]{"PR83563_2.java"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("PR83563_2"); - } - - public void testPerTypeWithinIncorrectlyMatchingInterfaces() { - CompilationResult cR = ajc(baseDir,new String[]{"PR83645.java"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("PR83645"); - } -} \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsRequireJava15.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsRequireJava15.java deleted file mode 100644 index 7e744828b..000000000 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150TestsRequireJava15.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * 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.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; - -import org.aspectj.asm.AsmManager; -import org.aspectj.tools.ajc.CompilationResult; - - -/** - * These tests only execute in a 1.5 environment. - */ -public class Ajc150TestsRequireJava15 extends TestUtils { - - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/bugs150"); - } - - public void testBadASMforEnums() throws IOException { - CompilationResult cR = ajc(baseDir,new String[]{"Rainbow.java","-emacssym","-1.5"}); - // System.err.println(cR); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintWriter pw = new PrintWriter(baos); - AsmManager.dumptree(pw,AsmManager.getDefault().getHierarchy().getRoot(),0); - pw.flush(); - String tree = baos.toString(); - assertTrue("Expected 'Red [enumvalue]' somewhere in here:"+tree,tree.indexOf("Red [enumvalue]")!=-1); - } - -} \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java b/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java index 286832e3d..098224728 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java +++ b/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java @@ -19,24 +19,24 @@ import junit.framework.TestSuite; public class AllTestsAspectJ150 { public static Test suite() { - TestSuite suite = new TestSuite("Java5 - binary weaving"); + TestSuite suite = new TestSuite("Java5/AspectJ5 tests"); //$JUnit-BEGIN$ suite.addTestSuite(MigrationTests.class); suite.addTest(Ajc150Tests.suite()); - suite.addTestSuite(Ajc150TestsNoHarness.class); suite.addTestSuite(SCCSFixTests.class); - // These are binary weaving tests suite.addTest(AccBridgeMethods.suite()); suite.addTestSuite(CovarianceTests.class); suite.addTestSuite(Enums.class); - suite.addTestSuite(AnnotationsBinaryWeaving.class); - suite.addTestSuite(AnnotationPointcutsTests.class); + suite.addTest(AnnotationsBinaryWeaving.suite()); + suite.addTest(AnnotationPointcutsTests.suite()); suite.addTestSuite(VarargsTests.class); - suite.addTestSuite(AnnotationRuntimeTests.class); + suite.addTest(AnnotationRuntimeTests.suite()); suite.addTestSuite(PerTypeWithinTests.class); - + suite.addTest(Autoboxing.suite()); + suite.addTest(Annotations.suite()); + suite.addTest(AnnotationBinding.suite()); //$JUnit-END$ return suite; } diff --git a/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150_NeedJava15.java b/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150_NeedJava15.java deleted file mode 100644 index 0a7881b8c..000000000 --- a/tests/src/org/aspectj/systemtest/ajc150/AllTestsAspectJ150_NeedJava15.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * 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 junit.framework.Test; -import junit.framework.TestSuite; - -/** - * This is a superset of AllTestsAspectJ150 that includes tests that must be run on Java 1.5 - */ -public class AllTestsAspectJ150_NeedJava15 { - - public static Test suite() { - TestSuite suite = new TestSuite("Java5"); - //$JUnit-BEGIN$ - suite.addTestSuite(Ajc150TestsRequireJava15.class); - suite.addTestSuite(Autoboxing.class); - suite.addTestSuite(Annotations.class); - suite.addTestSuite(AnnotationBinding.class); - - //$JUnit-END$ - return suite; - } -} diff --git a/tests/src/org/aspectj/systemtest/ajc150/AnnotationBinding.java b/tests/src/org/aspectj/systemtest/ajc150/AnnotationBinding.java index cf2987a70..8c906f63b 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/AnnotationBinding.java +++ b/tests/src/org/aspectj/systemtest/ajc150/AnnotationBinding.java @@ -11,110 +11,84 @@ package org.aspectj.systemtest.ajc150; import java.io.File; -import java.util.ArrayList; -import java.util.List; -import org.aspectj.tools.ajc.CompilationResult; +import junit.framework.Test; -public class AnnotationBinding extends TestUtils { - - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/java5/annotations/binding"); +import org.aspectj.testing.XMLBasedAjcTestCase; + +public class AnnotationBinding extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AnnotationBinding.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); } ///////////////////////////////////// @ANNOTATION and CALL // Very simple annotation binding for 'call() && @annotation()' public void testCallAnnotationBinding1() { - CompilationResult cR = ajc(baseDir,new String[]{"CallAnnBinding.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("CallAnnBinding"); + runTest("call annotation binding 1"); } // 'call() && @annotation()' when the called method has multiple arguments public void testCallAnnotationBinding2() { - CompilationResult cR = ajc(baseDir,new String[]{"CallAnnBinding2.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("CallAnnBinding2"); + runTest("call annotation binding 2"); } // 'call() && @annotation()' when the called method takes primitive arguments (YUCK!) public void testCallAnnotationBinding3() { - CompilationResult cR = ajc(baseDir,new String[]{"CallAnnBinding3.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("CallAnnBinding3"); + runTest("call annotation binding 3"); } // 'call() && @annotation()' when runtime type will exhibit different annotation (due to interface implementing) public void testCallAnnotationBinding4() { - CompilationResult cR = ajc(baseDir,new String[]{"CallAnnBinding4.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("CallAnnBinding4"); + runTest("call annotation binding 4"); } // 'call() && @annotation()' when target doesnt have an annotation ! public void testCallAnnotationBinding5() { - CompilationResult cR = ajc(baseDir,new String[]{"CallAnnBinding5.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("CallAnnBinding5"); + runTest("call annotation binding 5"); } // 'call() && @annotation()' when runtime type will exhibit different annotation (due to subclassing) public void testCallAnnotationBinding6() { - CompilationResult cR = ajc(baseDir,new String[]{"CallAnnBinding6.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("CallAnnBinding6"); + runTest("call annotation binding 6"); } - // 'call() && @annotation()' using named pointcut public void testCallAnnotationBinding7() { - CompilationResult cR = ajc(baseDir,new String[]{"CallAnnBinding7.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("CallAnnBinding7"); + runTest("call annotation binding 7"); } - - - ///////////////////////////////////// @TARGET // 'call() && @target()' public void testAtTargetAnnotationBinding1() { - CompilationResult cR = ajc(baseDir,new String[]{"AtTarget1.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtTarget1"); + runTest("@target annotation binding 1"); } // 'call() && @target() && @target' public void testAtTargetAnnotationBinding2() { - CompilationResult cR = ajc(baseDir,new String[]{"AtTarget2.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtTarget2"); + runTest("@target annotation binding 2"); } // 'call() && @target()' - using a type hierarchy where some levels are missing annotations public void testAtTargetAnnotationBinding3() { - CompilationResult cR = ajc(baseDir,new String[]{"AtTarget3.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtTarget3"); + runTest("@target annotation binding 3"); } // 'call() && @target()' - using a type hierarchy where some levels are missing annotations // but the annotation is inherited public void testAtTargetAnnotationBinding4() { - CompilationResult cR = ajc(baseDir,new String[]{"AtTarget4.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtTarget4"); + runTest("@target annotation binding 4"); } // @target() with an annotation in a package public void testAtTargetAnnotationBinding5() { - CompilationResult cR = ajc(new File(baseDir,"usingPackageNames"), - new String[]{"MyAspect.aj","MyAnnotation.java","MyClass.java","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("test.MyClass"); + runTest("@target annotation binding 5"); } @@ -122,75 +96,55 @@ public class AnnotationBinding extends TestUtils { // 'call() && @this()' public void testAtThisAnnotationBinding1() { - CompilationResult cR = ajc(baseDir,new String[]{"AtThis1.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtThis1"); + runTest("@this annotation binding 1"); } // 'call() && @this() && @this' public void testAtThisAnnotationBinding2() { - CompilationResult cR = ajc(baseDir,new String[]{"AtThis2.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtThis2"); + runTest("@this annotation binding 2"); } // 'call() && @this()' - using a type hierarchy where some levels are missing annotations public void testAtThisAnnotationBinding3() { - CompilationResult cR = ajc(baseDir,new String[]{"AtThis3.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtThis3"); + runTest("@this annotation binding 3"); } // 'call() && @this()' - using a type hierarchy where some levels are missing annotations // but the annotation is inherited public void testAtThisAnnotationBinding4() { - CompilationResult cR = ajc(baseDir,new String[]{"AtThis4.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtThis4"); + runTest("@this annotation binding 4"); } // '@this() and @target()' used together public void testAtThisAtTargetAnnotationBinding() { - CompilationResult cR = ajc(baseDir,new String[]{"AtThis5.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtThis5"); + runTest("@this annotation binding 5"); } ///////////////////////////////////// @ARGS // complex case when there are 3 parameters public void testAtArgs1() { - CompilationResult cR = ajc(baseDir,new String[]{"AtArgs1.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtArgs1"); + runTest("@args annotation binding 1"); } // simple case when there is only one parameter public void testAtArgs2() { - CompilationResult cR = ajc(baseDir,new String[]{"AtArgs2.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtArgs2"); + runTest("@args annotation binding 2"); } // simple case when there is only one parameter and no binding public void testAtArgs3() { - CompilationResult cR = ajc(baseDir,new String[]{"AtArgs3.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtArgs3"); + runTest("@args annotation binding 3"); } // complex case binding different annotation kinds public void testAtArgs4() { - CompilationResult cR = ajc(baseDir,new String[]{"AtArgs4.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtArgs4"); + runTest("@args annotation binding 4"); } // check @args and execution() public void testAtArgs5() { - CompilationResult cR = ajc(baseDir,new String[]{"AtArgs5.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AtArgs5"); + runTest("@args annotation binding 5"); } @@ -198,96 +152,73 @@ public class AnnotationBinding extends TestUtils { // 'execution() && @annotation()' public void testExecutionAnnotationBinding1() { - CompilationResult cR = ajc(baseDir,new String[]{"ExecutionAnnBinding1.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("ExecutionAnnBinding1"); + runTest("execution and @annotation"); } ///////////////////////////////////// @ANNOTATION and SET // 'set() && @annotation()' public void testFieldAnnotationBinding1() { - CompilationResult cR = ajc(baseDir,new String[]{"FieldAnnBinding1.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("FieldAnnBinding1"); + runTest("set and @annotation"); } // 'get() && @annotation()' public void testFieldAnnotationBinding2() { - CompilationResult cR = ajc(baseDir,new String[]{"FieldAnnBinding2.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("FieldAnnBinding2"); + runTest("get and @annotation"); } // 'get() && @annotation()' when using array fields public void testFieldAnnotationBinding3() { - CompilationResult cR = ajc(baseDir,new String[]{"FieldAnnBinding3.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("FieldAnnBinding3"); + runTest("get and @annotation with arrays"); } ///////////////////////////////////// @ANNOTATION and CTOR-CALL // 'ctor-call(new) && @annotation()' public void testCtorCallAnnotationBinding1() { - CompilationResult cR = ajc(baseDir,new String[]{"CtorAnnBinding1.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("CtorAnnBinding1"); + runTest("cons call and @annotation"); } ///////////////////////////////////// @ANNOTATION and CTOR-CALL // 'ctor-execution() && @annotation()' public void testCtorExecAnnotationBinding1() { - CompilationResult cR = ajc(baseDir,new String[]{"CtorAnnBinding2.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("CtorAnnBinding2"); + runTest("cons exe and @annotation"); } - - + ///////////////////////////////////// @ANNOTATION and STATICINITIALIZATION // 'staticinitialization() && @annotation()' public void testStaticInitAnnotationBinding1() { - CompilationResult cR = ajc(baseDir,new String[]{"StaticInitBinding.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("StaticInitBinding"); + runTest("staticinit and @annotation"); } ///////////////////////////////////// @ANNOTATION and PREINITIALIZATION // 'preinitialization() && @annotation()' public void testPreInitAnnotationBinding1() { - CompilationResult cR = ajc(baseDir,new String[]{"PreInitBinding.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("PreInitBinding"); + runTest("preinit and @annotation"); } ///////////////////////////////////// @ANNOTATION and INITIALIZATION // 'initialization() && @annotation()' public void testInitAnnotationBinding1() { - CompilationResult cR = ajc(baseDir,new String[]{"InitBinding.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("InitBinding"); + runTest("init and @annotation"); } ///////////////////////////////////// @ANNOTATION and ADVICEEXECUTION // 'adviceexecution() && @annotation()' public void testAdviceExecAnnotationBinding1() { - CompilationResult cR = ajc(baseDir,new String[]{"AdviceExecBinding.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("AdviceExecBinding"); + runTest("adviceexecution and @annotation"); } ///////////////////////////////////// @ANNOTATION and HANDLER // 'handler() && @annotation()' public void testHandlerAnnotationBinding1() { - CompilationResult cR = ajc(baseDir,new String[]{"HandlerBinding.aj","-1.5"}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("HandlerBinding"); + runTest("handler and @annotation"); } @@ -295,43 +226,26 @@ public class AnnotationBinding extends TestUtils { // Using package names for the types (including the annotation) - NO BINDING public void testPackageNamedTypesNoBinding() { - CompilationResult cR = ajc(new File(baseDir,"complexExample"), - new String[]{"A.java","B.java","Color.java","X.java","-1.5","-d","."}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("a.b.c.A"); + runTest("packages and no binding"); } // Using package names for the types (including the annotation) - INCLUDES BINDING public void testPackageNamedTypesWithBinding() { - CompilationResult cR = ajc(new File(baseDir,"complexExample"), - new String[]{"A.java","B.java","Color.java","X2.java","-1.5","-d","."}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("a.b.c.A"); + runTest("packages and binding"); } // declare parents: @Color * implements Serializable public void testDeclareParentsWithAnnotatedAnyPattern() { - CompilationResult cR = ajc(new File(baseDir,"complexExample"), - new String[]{"A.java","B.java","C.java","Color.java","X3.java","-1.5","-d","."}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("g.h.i.C"); // C should now be serializable - rR = run("a.b.c.A"); // A should not be serializable + runTest("annotated any pattern"); } // Should error (in a nice way!) on usage of an annotation that isnt imported public void testAnnotationUsedButNotImported() { - CompilationResult cR = ajc(new File(baseDir,"complexExample"), - new String[]{"A.java","B.java","Color.java","X4.java","-1.5","-d","."}); - List warnings = new ArrayList(); - warnings.add(new Message(6)); - assertMessages(cR,new MessageSpec(warnings,null)); - RunResult rR = run("a.b.c.A"); + runTest("annotation not imported"); } // Binding with calls/executions of static methods public void testCallsAndExecutionsOfStaticMethods() { - CompilationResult cR = ajc(baseDir,new String[]{"StaticMethods.java","-1.5","-d","."}); - assertMessages(cR,new EmptyMessageSpec()); - RunResult rR = run("StaticMethods"); + runTest("binding with static methods"); } } \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java b/tests/src/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java index cc75ea350..2d7e30909 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java @@ -11,63 +11,41 @@ package org.aspectj.systemtest.ajc150; import java.io.File; -import java.util.ArrayList; -import java.util.List; -import org.aspectj.tools.ajc.CompilationResult; +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; /** * Tests the use of Annotations in pointcuts */ -public class AnnotationPointcutsTests extends TestUtils { - - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/java5/annotations"); - } - +public class AnnotationPointcutsTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AnnotationPointcutsTests.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); + } + // before(): call(@SimpleAnnotation * *(..)) { } public void test001_usingAnnotationsInPointcuts() { - CompilationResult cR = binaryWeave("testcode.jar","AnnotationAspect02.aj",0,0); - System.err.println(cR.getStandardError()); - System.err.println(cR.getErrorMessages()); - System.err.println(cR.getInfoMessages()); - verifyWeavingMessagesOutput(cR,new String[]{ - "weaveinfo Type 'AnnotatedType' (AnnotatedType.java:3) advised by before advice from 'AnnotationAspect02' (AnnotationAspect02.aj:4)", - "weaveinfo Type 'AnnotatedType' (AnnotatedType.java:3) advised by before advice from 'AnnotationAspect02' (AnnotationAspect02.aj:2)", - "weaveinfo Type 'AnnotatedType' (AnnotatedType.java:4) advised by before advice from 'AnnotationAspect02' (AnnotationAspect02.aj:4)"}); + runTest("annotation matching on call"); } public void test002_AtAnnotationMatching() { - CompilationResult cR = binaryWeave("testcode.jar","AnnotationAspect03.aj",0,1); - List expectedWarnings = new ArrayList(); - expectedWarnings.add(new Message("@annotation matched here")); // L 8 - assertMessages(cR, new MessageSpec(expectedWarnings, new ArrayList())); + runTest("at annotation matching"); } public void test003_Within_Code() { - baseDir = new File("../tests/java5/annotations/within_code"); - CompilationResult cR = binaryWeave("TestingAnnotations.jar","WithinAndWithinCodeTests.java",0,5); - List warnings = new ArrayList(); - warnings.add(new Message(32,"@within match on non-inherited annotation")); - warnings.add(new Message(39,"@within match on non-inherited annotation")); - warnings.add(new Message(39,"@within match on inheritable annotation")); - warnings.add(new Message(43,"@within match on inheritable annotation")); - warnings.add(new Message(32,"@withincode match")); - MessageSpec mSpec = new MessageSpec(warnings,new ArrayList()); - assertMessages(cR,mSpec); + runTest("annotations and within(code)"); } public void test004_Within() { - baseDir = new File("../tests/java5/annotations/within"); - CompilationResult cR = binaryWeave("PlainWithin.jar","PlainWithinTests.java",0,2); - List warnings = new ArrayList(); - warnings.add(new Message(21,"positive within match on annotation")); - warnings.add(new Message(25,"negative within match on annotation")); - MessageSpec mSpec = new MessageSpec(warnings,new ArrayList()); - assertMessages(cR,mSpec); - } + runTest("annotations and within"); + } // TODO extra tests // 3) @annotation on the different join point kinds, matches with inherited annotation diff --git a/tests/src/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java b/tests/src/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java index f427e0e9e..768eb936e 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java @@ -11,20 +11,23 @@ package org.aspectj.systemtest.ajc150; import java.io.File; -import java.util.ArrayList; -import java.util.List; -import org.aspectj.tools.ajc.CompilationResult; +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; /** * Tests for @this, @target, @args */ -public class AnnotationRuntimeTests extends TestUtils { +public class AnnotationRuntimeTests extends XMLBasedAjcTestCase { - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/java5/annotations/thisOrtarget"); - } + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AnnotationRuntimeTests.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); + } // No longer a limitation ASC 31Jan05 // public void test001_BindingWithAtTargetAllowed() { @@ -35,46 +38,23 @@ public class AnnotationRuntimeTests extends TestUtils { // } public void test002_MustHaveRuntimeRetention() { - CompilationResult cR = binaryWeave("TestingAnnotations.jar","NotRuntimeRetention.aj",2,0); - List errors = new ArrayList(); - errors.add(new Message(7,"Annotation type MyClassRetentionAnnotation does not have runtime retention")); - errors.add(new Message(13,"Annotation type MyClassRetentionAnnotation does not have runtime retention")); - - MessageSpec messageSpec = new MessageSpec(new ArrayList(), errors); - assertMessages(cR, messageSpec); + runTest("must have runtime retention"); } public void test003_InheritableOrNot() { - CompilationResult cR = binaryWeave("TestingAnnotations.jar","ThisOrTargetTests.aj",0,0); + runTest("inheritable or not"); } public void test004_CantUseinDecEoW() { - CompilationResult cR = binaryWeave("TestingAnnotations.jar","DeclareEoW.java",4,0); - List errors = new ArrayList(); - errors.add(new Message(3,"this() pointcut designator cannot be used in declare statement")); - errors.add(new Message(5,"target() pointcut designator cannot be used in declare statement")); - MessageSpec messageSpec = new MessageSpec(new ArrayList(), errors); - assertMessages(cR, messageSpec); + runTest("use of @this/target in deow"); } - - // TODO extra tests - // run the result of test003 and validate matches (needs 1.5 runtime) - // test inheritable annotation not present on type [should generate runtime test] - + public void test005_ArgsSuite() { - baseDir = new File("../tests/java5/annotations/args"); - CompilationResult cR = binaryWeave("TestingArgsAnnotations.jar","AtArgsAspect.java",0,0); - // TODO need to RUN the result of these tests... - System.out.println(cR); + runTest("@args tests"); } public void test006_CantUseinDecEoW() { - baseDir = new File("../tests/java5/annotations/args"); - CompilationResult cR = binaryWeave("TestingArgsAnnotations.jar","DeclareEoW.java",2,0); - List errors = new ArrayList(); - errors.add(new Message(3,"args() pointcut designator cannot be used in declare statement")); - MessageSpec messageSpec = new MessageSpec(new ArrayList(), errors); - assertMessages(cR, messageSpec); + runTest("use of @args in deow"); } } diff --git a/tests/src/org/aspectj/systemtest/ajc150/Annotations.java b/tests/src/org/aspectj/systemtest/ajc150/Annotations.java index 328471251..1ac7ef36e 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Annotations.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Annotations.java @@ -11,40 +11,35 @@ package org.aspectj.systemtest.ajc150; import java.io.File; -import java.util.ArrayList; -import java.util.List; + +import junit.framework.Test; import org.aspectj.apache.bcel.classfile.JavaClass; import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.tools.ajc.CompilationResult; +import org.aspectj.apache.bcel.util.ClassPath; +import org.aspectj.apache.bcel.util.SyntheticRepository; +import org.aspectj.testing.XMLBasedAjcTestCase; -public class Annotations extends TestUtils { - - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/java5/annotations"); - } - +public class Annotations extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Annotations.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); + } + public void testCompilingAnnotation() { - CompilationResult cR = ajc(baseDir,new String[]{"SimpleAnnotation.java","-1.5"}); - MessageSpec ms = new MessageSpec(null,null); - assertMessages(cR,ms); + runTest("compiling an annotation"); } public void testCompilingAnnotatedFile() { - CompilationResult cR = ajc(baseDir,new String[]{"AnnotatedType.java","SimpleAnnotation.java","-1.5"}); - MessageSpec ms = new MessageSpec(null,null); - assertMessages(cR,ms); + runTest("compiling annotated file"); } public void testCompilingUsingWithinAndAnnotationTypePattern() { - CompilationResult cR = ajc(new File(baseDir+File.separator+"within"), - new String[]{"PlainWithin.java","PlainWithinTests.java","-1.5"}); - List expectedInfoMessages = new ArrayList(); - expectedInfoMessages.add(new Message(21,"positive within match on annotation")); - expectedInfoMessages.add(new Message(25,"negative within match on annotation")); - MessageSpec ms = new MessageSpec(expectedInfoMessages,null); - assertMessages(cR,ms); + runTest("annotations and within (src)"); } /** @@ -53,12 +48,7 @@ public class Annotations extends TestUtils { * a simple program then checks the annotations were copied across. */ public void testBugWithAnnotationsLostOnWovenMethods() throws ClassNotFoundException { - CompilationResult cR = ajc(new File(baseDir+File.separator+"attarget"), - new String[]{"Program.java","AtTargetAspect.java","-1.5"}); - //System.err.println(cR.getStandardError()); - List expectedInfoMessages = new ArrayList(); - MessageSpec ms = new MessageSpec(null,null); - assertMessages(cR,ms); + runTest("losing annotations..."); JavaClass jc = getClassFrom(ajc.getSandboxDirectory(),"Program"); Method[] meths = jc.getMethods(); @@ -69,4 +59,16 @@ public class Annotations extends TestUtils { } } } + + // helper methods..... + + public SyntheticRepository createRepos(File cpentry) { + ClassPath cp = new ClassPath(cpentry+File.pathSeparator+System.getProperty("java.class.path")); + return SyntheticRepository.getInstance(cp); + } + + protected JavaClass getClassFrom(File where,String clazzname) throws ClassNotFoundException { + SyntheticRepository repos = createRepos(where); + return repos.loadClass(clazzname); + } } \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/AnnotationsBinaryWeaving.java b/tests/src/org/aspectj/systemtest/ajc150/AnnotationsBinaryWeaving.java index c7510e15e..39ac09d54 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/AnnotationsBinaryWeaving.java +++ b/tests/src/org/aspectj/systemtest/ajc150/AnnotationsBinaryWeaving.java @@ -12,8 +12,9 @@ package org.aspectj.systemtest.ajc150; import java.io.File; -import org.aspectj.bridge.IMessage; -import org.aspectj.tools.ajc.CompilationResult; +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; /** @@ -27,55 +28,29 @@ import org.aspectj.tools.ajc.CompilationResult; * 6. Compilation error if you explicitly identify an Annotation type. * 7. Lint warning if a non-explicit type pattern would match an annotation type. */ -public class AnnotationsBinaryWeaving extends TestUtils { - - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/java5/annotations"); - } +public class AnnotationsBinaryWeaving extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AnnotationsBinaryWeaving.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); + } // Cannot make ITD (c/m/f) on an annotation public void test001_itdsOnAnnotationsNotAllowed() { - CompilationResult cR = binaryWeave("testcode.jar","AnnotationAspect01.aj",3,0); - assertTrue("Expected three message about ITDs not allowed on Annotations but got: #"+ - cR.getErrorMessages().size()+": \n"+cR.getErrorMessages(), - cR.getErrorMessages().size()==3); - IMessage msg1_ctor = (IMessage)cR.getErrorMessages().get(0); - IMessage msg2_method = (IMessage)cR.getErrorMessages().get(1); - IMessage msg3_field = (IMessage)cR.getErrorMessages().get(2); - assertTrue("Expected message about ITDCs on annotations not allowed, but got: \n"+msg1_ctor, - msg1_ctor.toString().indexOf("can't make inter-type constructor declarations")!=-1); - assertTrue("Expected message about ITDMs on annotations not allowed, but got: \n"+msg2_method, - msg2_method.toString().indexOf("can't make inter-type method declarations")!=-1); - assertTrue("Expected message about ITDFs on annotations not allowed, but got: \n"+msg3_field, - msg3_field.toString().indexOf("can't make inter-type field declarations")!=-1); - verifyWeavingMessagesOutput(cR,new String[]{}); + runTest("no itds on annotation types"); } // Deals with the cases where an explicit type is specified and it is an annotation type public void test002_decpOnAnnotationNotAllowed_errors() { - CompilationResult cR = binaryWeave("testcode.jar","AnnotationAspect04.aj",3,0,true,new String[]{"-source","1.5"}); - IMessage msg = (IMessage)cR.getErrorMessages().get(1); - assertTrue("Expected a message about can't use decp to alter supertype of an annotation: "+msg, - msg.toString().indexOf("to alter supertype of annotation type")!=-1); - msg = (IMessage)cR.getErrorMessages().get(2); - assertTrue("Expected a message about can't use decp to make annotation implement interface: "+msg, - msg.toString().indexOf("implement an interface")!=-1); - msg = (IMessage)cR.getErrorMessages().get(0); - assertTrue("Expected a message about can't use decp to make Annotation parent of another type: "+msg, - msg.toString().indexOf("the parent of type")!=-1); - verifyWeavingMessagesOutput(cR,new String[]{}); + runTest("no declare parents on annotation types"); } //Deals with the cases where an wild type pattern is specified and it hits an annotation type public void test004_decpOnAnnotationNotAllowed_xlints() { - CompilationResult cR = binaryWeave("testcode.jar","AnnotationAspect05.aj",0,2,false); - IMessage msg = (IMessage)cR.getWarningMessages().get(0); - assertTrue("Expected a message about an annotation type matching a declare parents but being ignored: "+msg, - msg.toString().indexOf("matches a declare parents type pattern")!=-1); - msg = (IMessage)cR.getWarningMessages().get(1); - assertTrue("Expected a message about an annotation type matching a declare parents but being ignored: "+msg, - msg.toString().indexOf("matches a declare parents type pattern")!=-1); - verifyWeavingMessagesOutput(cR,new String[]{}); + runTest("declare parents wildcards matching annotation types"); } + } \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/Autoboxing.java b/tests/src/org/aspectj/systemtest/ajc150/Autoboxing.java index 9d5f57160..7221cd1cf 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Autoboxing.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Autoboxing.java @@ -12,144 +12,83 @@ package org.aspectj.systemtest.ajc150; import java.io.File; -import org.aspectj.tools.ajc.CompilationResult; +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; /** This test must be run under a Java5 VM - so it is *not* currently in the test suite !!! */ -public class Autoboxing extends TestUtils { +public class Autoboxing extends XMLBasedAjcTestCase { - private boolean runningUnderJava5 = false; - - - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/java5/autoboxing"); - } - + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Autoboxing.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); + } public void testSimpleBoxing() { - CompilationResult cR = binaryWeave("testcode.jar","SimpleAutoboxingAspect.aj",0,0,"-1.5"); - assertTrue("Expected two weaving messages (both on line 7) but got:"+getWeavingMessages(cR.getInfoMessages()).size(), - getWeavingMessages(cR.getInfoMessages()).size()==2); - RunResult rR = run("SimpleAutoboxing"); - verify(rR.getStdErr(),"Matching by Integer:20000"); - verify(rR.getStdErr(),"Matching by int:20000"); - verify(rR.getStdErr(),"method_takes_Integer=20000"); + runTest("simple boxing test"); } public void testIntegerBoxing() { - CompilationResult cR = binaryWeave("testcode.jar","AspectInteger.aj",0,0,"-1.5"); - System.err.println(cR.getStandardError()); - assertTrue("Expected eight weaving messages but got: "+getWeavingMessages(cR.getInfoMessages()).size(), - getWeavingMessages(cR.getInfoMessages()).size()==8); - RunResult rR = run("AutoboxingI"); - verify(rR.getStdErr(),"Matching by Integer:10000"); - verify(rR.getStdErr(),"Matching by int:10000"); - verify(rR.getStdErr(),"method_takes_Integer=10000"); - verify(rR.getStdErr(),"Matching by Integer:20000"); - verify(rR.getStdErr(),"Matching by int:20000"); - verify(rR.getStdErr(),"method_takes_Integer=20000"); - verify(rR.getStdErr(),"Matching by Integer:30000"); - verify(rR.getStdErr(),"Matching by int:30000"); - verify(rR.getStdErr(),"method_takes_int=30000"); - verify(rR.getStdErr(),"Matching by Integer:40000"); - verify(rR.getStdErr(),"Matching by int:40000"); - verify(rR.getStdErr(),"method_takes_int=40000"); + runTest("integer boxing"); } - + public void testCharacterBoxing() { - CompilationResult cR = binaryWeave("testcode.jar","AspectChar.aj",0,0,"-1.5"); - System.err.println(cR.getStandardError()); - assertTrue("Expected eight weaving messages but got: "+getWeavingMessages(cR.getInfoMessages()).size(), - getWeavingMessages(cR.getInfoMessages()).size()==8); - RunResult rR = run("AutoboxingC"); - int lines = countLines(rR.getStdErr()); - assertTrue("Expected 12 lines of output but got: #"+lines+":\n"+rR.getStdErr(),lines==12); + runTest("char boxing"); } - + public void testDoubleBoxing() { - CompilationResult cR = binaryWeave("testcode.jar","AspectDouble.aj",0,0,"-1.5"); - System.err.println(cR.getStandardError()); - assertTrue("Expected eight weaving messages but got: "+getWeavingMessages(cR.getInfoMessages()).size(), - getWeavingMessages(cR.getInfoMessages()).size()==8); - RunResult rR = run("AutoboxingD"); - int lines = countLines(rR.getStdErr()); - assertTrue("Expected 12 lines of output but got: #"+lines+":\n"+rR.getStdErr(),lines==12); + runTest("double boxing"); } - + public void testFloatBoxing() { - CompilationResult cR = binaryWeave("testcode.jar","AspectFloat.aj",0,0,"-1.5"); - System.err.println(cR.getStandardError()); - assertTrue("Expected eight weaving messages but got: "+getWeavingMessages(cR.getInfoMessages()).size(), - getWeavingMessages(cR.getInfoMessages()).size()==8); - RunResult rR = run("AutoboxingF"); - int lines = countLines(rR.getStdErr()); - assertTrue("Expected 12 lines of output but got: #"+lines+":\n"+rR.getStdErr(),lines==12); + runTest("float boxing"); } public void testShortBoxing() { - CompilationResult cR = binaryWeave("testcode.jar","AspectShort.aj",0,0,"-1.5"); - System.err.println(cR.getStandardError()); - assertTrue("Expected eight weaving messages but got: "+getWeavingMessages(cR.getInfoMessages()).size(), - getWeavingMessages(cR.getInfoMessages()).size()==8); - RunResult rR = run("AutoboxingS"); - int lines = countLines(rR.getStdErr()); - assertTrue("Expected 12 lines of output but got: #"+lines+":\n"+rR.getStdErr(),lines==12); + runTest("short boxing"); } public void testLongBoxing() { - CompilationResult cR = binaryWeave("testcode.jar","AspectLong.aj",0,0,"-1.5"); - System.err.println(cR.getStandardError()); - assertTrue("Expected eight weaving messages but got: "+getWeavingMessages(cR.getInfoMessages()).size(), - getWeavingMessages(cR.getInfoMessages()).size()==8); - RunResult rR = run("AutoboxingJ"); - int lines = countLines(rR.getStdErr()); - assertTrue("Expected 12 lines of output but got: #"+lines+":\n"+rR.getStdErr(),lines==12); + runTest("long boxing"); } public void testBooleanBoxing() { - CompilationResult cR = binaryWeave("testcode.jar","AspectBoolean.aj",0,0,"-1.5"); - System.err.println(cR.getStandardError()); - assertTrue("Expected eight weaving messages but got: "+getWeavingMessages(cR.getInfoMessages()).size(), - getWeavingMessages(cR.getInfoMessages()).size()==8); - RunResult rR = run("AutoboxingZ"); - int lines = countLines(rR.getStdErr()); - assertTrue("Expected 12 lines of output but got: #"+lines+":\n"+rR.getStdErr(),lines==12); + runTest("boolean boxing"); } public void testByteBoxing() { - CompilationResult cR = binaryWeave("testcode.jar","AspectByte.aj",0,0,"-1.5"); - System.err.println(cR.getStandardError()); - assertTrue("Expected eight weaving messages but got: "+getWeavingMessages(cR.getInfoMessages()).size(), - getWeavingMessages(cR.getInfoMessages()).size()==8); - RunResult rR = run("AutoboxingB"); - int lines = countLines(rR.getStdErr()); - assertTrue("Expected 12 lines of output but got: #"+lines+":\n"+rR.getStdErr(),lines==12); + runTest("byte boxing"); } public void testBoxingAfterReturning() { - CompilationResult cR = binaryWeave("testcode.jar","AspectAfterReturning.aj",0,0,"-1.5"); - //System.err.println(cR.getStandardError()); - assertTrue("Expected six weaving messages but got: "+getWeavingMessages(cR.getInfoMessages()).size(), - getWeavingMessages(cR.getInfoMessages()).size()==6); - RunResult rR = run("AspectAfterReturning"); - int lines = countLines(rR.getStdErr()); - assertTrue("Expected 6 lines of output but got: #"+lines+":\n"+rR.getStdErr(),lines==6); + runTest("boxing in after returning"); } - - public int countLines(String s) { - int count = 0; - while (s.indexOf("\n")!=-1) { - count++; - s = s.substring(s.indexOf("\n")+1); - } - return count; - } - - protected void verify(String output,String lookingFor) { - assertTrue("Didn't find expected string '"+lookingFor+"' in:\n"+output,output.indexOf(lookingFor)!=-1); - } - +// CompilationResult cR = binaryWeave("testcode.jar","AspectAfterReturning.aj",0,0,"-1.5"); +// //System.err.println(cR.getStandardError()); +// assertTrue("Expected six weaving messages but got: "+getWeavingMessages(cR.getInfoMessages()).size(), +// getWeavingMessages(cR.getInfoMessages()).size()==6); +// RunResult rR = run("AspectAfterReturning"); +// int lines = countLines(rR.getStdErr()); +// assertTrue("Expected 6 lines of output but got: #"+lines+":\n"+rR.getStdErr(),lines==6); +// } +// +// public int countLines(String s) { +// int count = 0; +// while (s.indexOf("\n")!=-1) { +// count++; +// s = s.substring(s.indexOf("\n")+1); +// } +// return count; +// } +// +// protected void verify(String output,String lookingFor) { +// assertTrue("Didn't find expected string '"+lookingFor+"' in:\n"+output,output.indexOf(lookingFor)!=-1); +// } +// } diff --git a/tests/src/org/aspectj/systemtest/ajc150/CovarianceTests.java b/tests/src/org/aspectj/systemtest/ajc150/CovarianceTests.java index 393bdf050..07050501e 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/CovarianceTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/CovarianceTests.java @@ -11,17 +11,10 @@ package org.aspectj.systemtest.ajc150; import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import org.aspectj.bridge.IMessage; -import org.aspectj.tools.ajc.AjcTestCase; -import org.aspectj.tools.ajc.CompilationResult; +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; /* @@ -63,8 +56,15 @@ public class CovBaseProgram01 { /** * Covariance is simply where a type overrides some inherited implementation and narrows the return type. */ -public class CovarianceTests extends AjcTestCase { +public class CovarianceTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(CovarianceTests.class); + } + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); + } private boolean verbose = false; @@ -72,11 +72,7 @@ public class CovarianceTests extends AjcTestCase { * call(* getCar()) should match both */ public void testCOV001() { - CompilationResult cR = binaryWeave("CovBaseProgram01.jar","CovAspect01.aj",0,0); - verifyOutput(cR,new String[]{ - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:26) advised by before advice from 'CovAspect01' (CovAspect01.aj:5)", - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:27) advised by before advice from 'CovAspect01' (CovAspect01.aj:5)" - }); + runTest("covariance 1"); } @@ -99,11 +95,7 @@ public class CovarianceTests extends AjcTestCase { * a possibility. All the tests pass so I'll leave it like this for now. */ public void testCOV002() { - CompilationResult cR = binaryWeave("CovBaseProgram01.jar","CovAspect02.aj",0,0); - verifyOutput(cR,new String[]{ - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:26) advised by before advice from 'CovAspect02' (CovAspect02.aj:5)", - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:27) advised by before advice from 'CovAspect02' (CovAspect02.aj:5)" - }); + runTest("covariance 2"); } /** @@ -112,12 +104,7 @@ public class CovarianceTests extends AjcTestCase { * Had to implement proper covariance support here... */ public void testCOV003() { - CompilationResult cR = binaryWeave("CovBaseProgram01.jar","CovAspect03.aj",0,0); - - verifyOutput(cR,new String[]{ - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:26) advised by before advice from 'CovAspect03' (CovAspect03.aj:5)", - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:27) advised by before advice from 'CovAspect03' (CovAspect03.aj:5)" - }); + runTest("covariance 3"); } /** @@ -125,10 +112,7 @@ public class CovarianceTests extends AjcTestCase { * call(Car Super.getCar()) should only match first call to getCar() */ public void testCOV004() { - CompilationResult cR = binaryWeave("CovBaseProgram02.jar","CovAspect04.aj",0,0); - verifyOutput(cR,new String[]{ - "weaveinfo Type 'CovBaseProgram02' (CovBaseProgram02.java:30) advised by before advice from 'CovAspect04' (CovAspect04.aj:5)" - }); + runTest("covariance 4"); } /** @@ -136,34 +120,21 @@ public class CovarianceTests extends AjcTestCase { * call(Car Super.getCar()) should match both */ public void testCOV005() { - CompilationResult cR = binaryWeave("CovBaseProgram01.jar","CovAspect05.aj",0,0); - verifyOutput(cR,new String[]{ - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:26) advised by before advice from 'CovAspect05' (CovAspect05.aj:5)", - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:27) advised by before advice from 'CovAspect05' (CovAspect05.aj:5)" - }); + runTest("covariance 5"); } /** * call(Car Sub.getCar()) should not match anything */ public void testCOV006() { - CompilationResult cR = binaryWeave("CovBaseProgram01.jar","CovAspect06.aj",0,1); - verifyOutput(cR,new String[]{/* no expected output! */}); - assertTrue("Expected one xlint warning message for line 26, but got: "+cR.getWarningMessages(), - cR.getWarningMessages().size()==1 && ((IMessage)cR.getWarningMessages().get(0)).toString().indexOf("26")!=-1); - + runTest("covariance 6"); } /** * call(Car+ Sub.getCar()) should match 2nd call with xlint for the 1st call */ public void testCOV007() { - CompilationResult cR = binaryWeave("CovBaseProgram01.jar","CovAspect07.aj",0,1); - verifyOutput(cR,new String[]{ - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:27) advised by before advice from 'CovAspect07' (CovAspect07.aj:5)" - }); - assertTrue("Expected one xlint warning message for line 26, but got: "+cR.getWarningMessages(), - cR.getWarningMessages().size()==1 && ((IMessage)cR.getWarningMessages().get(0)).toString().indexOf("26")!=-1); + runTest("covariance 7"); } /** @@ -172,128 +143,21 @@ public class CovarianceTests extends AjcTestCase { * call(FastCar Sub.getCar()) matches on 2nd call */ public void testCOV008() { - CompilationResult cR = binaryWeave("CovBaseProgram01.jar","CovAspect08.aj",0,0); - verifyOutput(cR,new String[]{ - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:27) advised by before advice from 'CovAspect08' (CovAspect08.aj:11)", - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:27) advised by before advice from 'CovAspect08' (CovAspect08.aj:5)" - }); + runTest("covariance 8"); } /** * call(FastCar Super.getCar()) matches nothing */ public void testCOV009() { - CompilationResult cR = binaryWeave("CovBaseProgram01.jar","CovAspect09.aj",0,0); - verifyOutput(cR,new String[]{/* No matches */}); - assertTrue("Expected no warnings but got: "+cR.getWarningMessages(),cR.getWarningMessages().size()==0); + runTest("covariance 9"); } /** * call(Car+ getCar()) matches both */ public void testCOV010() { - CompilationResult cR = binaryWeave("CovBaseProgram01.jar","CovAspect10.aj",0,0); - verifyOutput(cR,new String[]{ - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:26) advised by before advice from 'CovAspect10' (CovAspect10.aj:5)", - "weaveinfo Type 'CovBaseProgram01' (CovBaseProgram01.java:27) advised by before advice from 'CovAspect10' (CovAspect10.aj:5)" - }); + runTest("covariance 10"); } - //-------------------------------------------------------------------------------- - //-------------------------------------------------------------------------------- - //-------------------------------------------------------------------------------- - - private File baseDir; - - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/java5/covariance"); - } - - private CompilationResult binaryWeave(String inpath, String insource,int expErrors,int expWarnings) { - String[] args = new String[] {"-inpath",inpath,insource,"-showWeaveInfo"}; - CompilationResult result = ajc(baseDir,args); - if (verbose || result.hasErrorMessages()) System.out.println(result); - assertTrue("Expected "+expErrors+" errors but got "+result.getErrorMessages().size()+":\n"+ - formatCollection(result.getErrorMessages()),result.getErrorMessages().size()==expErrors); - assertTrue("Expected "+expWarnings+" warnings but got "+result.getWarningMessages().size()+":\n"+ - formatCollection(result.getWarningMessages()),result.getWarningMessages().size()==expWarnings); - return result; - } - - private List getWeavingMessages(List msgs) { - List result = new ArrayList(); - for (Iterator iter = msgs.iterator(); iter.hasNext();) { - IMessage element = (IMessage) iter.next(); - if (element.getKind()==IMessage.WEAVEINFO) { - result.add(element.toString()); - } - } - return result; - } - - private void verifyOutput(CompilationResult cR,String[] expected) { - List weavingmessages = getWeavingMessages(cR.getInfoMessages()); - dump(weavingmessages); - for (int i = 0; i < expected.length; i++) { - boolean found = weavingmessages.contains(expected[i]); - if (found) { - weavingmessages.remove(expected[i]); - } else { - System.err.println(dump(getWeavingMessages(cR.getInfoMessages()))); - fail("Expected message not found.\nExpected:\n"+expected[i]+"\nObtained:\n"+dump(getWeavingMessages(cR.getInfoMessages()))); - } - } - if (weavingmessages.size()!=0) { - fail("Unexpected messages obtained from program:\n"+dump(weavingmessages)); - } - } - - private String formatCollection(Collection s) { - StringBuffer sb = new StringBuffer(); - for (Iterator iter = s.iterator(); iter.hasNext();) { - Object element = (Object) iter.next(); - sb.append(element).append("\n"); - } - return sb.toString(); - } - - private static Set split(String input) { - Set l = new HashSet(); - int idx = 0; - while (input.indexOf("]",idx)!=-1) { - int nextbreak = input.indexOf("]",idx); - String s = input.substring(idx,nextbreak+1); - - l.add(s); - idx = input.indexOf("[",nextbreak+1); - if (idx==-1) break; - } - return l; - } - - private void copyFile(String fromName) { - copyFile(fromName,fromName); - } - - private void copyFile(String from,String to) { - try { - org.aspectj.util.FileUtil.copyFile(new File(baseDir + File.separator + from), - new File(ajc.getSandboxDirectory(),to)); - } catch (IOException ioe) { - ioe.printStackTrace(); - } - } - - - private String dump(List l) { - StringBuffer sb = new StringBuffer(); - int i =0; - sb.append("--- Weaving Messages ---\n"); - for (Iterator iter = l.iterator(); iter.hasNext();) { - sb.append(i+") "+iter.next()+"\n"); - } - sb.append("------------------------\n"); - return sb.toString(); - } } diff --git a/tests/src/org/aspectj/systemtest/ajc150/Enums.java b/tests/src/org/aspectj/systemtest/ajc150/Enums.java index 20bd6ef77..a24f153f7 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Enums.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Enums.java @@ -12,8 +12,9 @@ package org.aspectj.systemtest.ajc150; import java.io.File; -import org.aspectj.bridge.IMessage; -import org.aspectj.tools.ajc.CompilationResult; +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; /** @@ -29,64 +30,43 @@ import org.aspectj.tools.ajc.CompilationResult; * 8. Lint warning if a non-explicit type pattern would match an enum type. * */ -public class Enums extends TestUtils { - - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/java5/enums"); - } - +public class Enums extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Enums.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); + } + // Cannot make ITDC on an enum public void test001_itdcsOnEnumNotAllowed() { - CompilationResult cR = binaryWeave("testcode.jar","EnumAspect01.aj",1,0); - IMessage msg = (IMessage)cR.getErrorMessages().get(0); - assertTrue("Expected a message about ITDCs not allowed on enums but got: "+msg, - msg.toString().indexOf("can't make inter-type constructor declarations")!=-1); - verifyWeavingMessagesOutput(cR,new String[]{}); + runTest("cant itd constructor on enum"); } - + // Cannot make ITDM or ITDF on an enum public void test002_itdFieldOrMethodOnEnumNotAllowed() { - CompilationResult cR = binaryWeave("testcode.jar","EnumAspect02.aj",2,0); - IMessage msg1 = (IMessage)cR.getErrorMessages().get(0); - IMessage msg2 = (IMessage)cR.getErrorMessages().get(1); - assertTrue("Expected a message about ITD methods not allowed on enums but got: "+msg1, - msg1.toString().indexOf("can't make inter-type method declarations")!=-1); - assertTrue("Expected a message about ITD fields not allowed on enums but got: "+msg2, - msg2.toString().indexOf("can't make inter-type field declarations")!=-1); - verifyWeavingMessagesOutput(cR,new String[]{}); + runTest("cant itd field or method on enum"); } - + // Deals with the cases where an explicit type is specified and it is an enum type public void test003_decpOnEnumNotAllowed_errors() { - CompilationResult cR = binaryWeave("testcode.jar","EnumAspect03.aj",4,0,true); - // THE ORDERING CAN BE SENSITIVE HERE... OUGHT TO FIX IT PROPERLY AND ALLOW FOR THEM - // IN ANY POSITION - IMessage msg = (IMessage)cR.getErrorMessages().get(1); - assertTrue("Expected a message about can't use decp to alter supertype of an enum: "+msg, - msg.toString().indexOf("to alter supertype of enum type")!=-1); - msg = (IMessage)cR.getErrorMessages().get(2); - assertTrue("Expected a message about can't use decp to make enum implement interface: "+msg, - msg.toString().indexOf("implement an interface")!=-1); - msg = (IMessage)cR.getErrorMessages().get(0); - assertTrue("Expected a message about can't use decp to make Enum parent of another type: "+msg, - msg.toString().indexOf("the parent of type")!=-1); - msg = (IMessage)cR.getErrorMessages().get(3); - assertTrue("Excpected message about not subclassing Enum: "+msg, - msg.toString().indexOf("The type C may not subclass Enum explicitly")!=-1); - verifyWeavingMessagesOutput(cR,new String[]{}); + runTest("declare parents and enums"); } //Deals with the cases where an wild type pattern is specified and it hits an enum type public void test004_decpOnEnumNotAllowed_xlints() { - CompilationResult cR = binaryWeave("testcode.jar","EnumAspect04.aj",0,2,false); - IMessage msg = (IMessage)cR.getWarningMessages().get(0); - assertTrue("Expected a message about an enum type matching a declare parents but being ignored: "+msg, - msg.toString().indexOf("matches a declare parents type pattern")!=-1); - msg = (IMessage)cR.getWarningMessages().get(1); - assertTrue("Expected a message about an enum type matching a declare parents but being ignored: "+msg, - msg.toString().indexOf("matches a declare parents type pattern")!=-1); - verifyWeavingMessagesOutput(cR,new String[]{}); + runTest("wildcard enum match in itd"); } +// CompilationResult cR = binaryWeave("testcode.jar","EnumAspect04.aj",0,2,false); +// IMessage msg = (IMessage)cR.getWarningMessages().get(0); +// assertTrue("Expected a message about an enum type matching a declare parents but being ignored: "+msg, +// msg.toString().indexOf("matches a declare parents type pattern")!=-1); +// msg = (IMessage)cR.getWarningMessages().get(1); +// assertTrue("Expected a message about an enum type matching a declare parents but being ignored: "+msg, +// msg.toString().indexOf("matches a declare parents type pattern")!=-1); +// verifyWeavingMessagesOutput(cR,new String[]{}); +// } } \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/MigrationTests.java b/tests/src/org/aspectj/systemtest/ajc150/MigrationTests.java index 869b71b78..671f19602 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/MigrationTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/MigrationTests.java @@ -12,19 +12,23 @@ package org.aspectj.systemtest.ajc150; import java.io.File; -import org.aspectj.tools.ajc.CompilationResult; +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; /** * Checks if we are obeying migration rules. */ -public class MigrationTests extends TestUtils { - - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/migration"); - } +public class MigrationTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(MigrationTests.class); + } + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); + } /** * Compile a simple java class with an aspect library built with aspectj 1.2.1 - this * checks that we can load in attributes (especially pointcuts) that were written out @@ -32,13 +36,14 @@ public class MigrationTests extends TestUtils { * */ public void testMigrationFrom121_pointcutsAndAdvice() { - CompilationResult cR = ajc(baseDir,new String[]{"-aspectpath","aspects121.jar","Program.java"}); - System.err.println(cR.getStandardError()); - assertTrue("Should not coredump: "+cR.getStandardError(),cR.getStandardError().indexOf("Dumping to ajcore")==-1); - assertTrue("Should be no error messages: \n"+cR.getErrorMessages(),cR.getErrorMessages().size()==0); - File f = new File(ajc.getSandboxDirectory()+File.separator+"Program.class"); - assertTrue("Missing class file",f.exists()); - run("Program"); + runTest("load aspectj 1.2.1 aspects in aspectj 5"); +// CompilationResult cR = ajc(baseDir,new String[]{"-aspectpath","aspects121.jar","Program.java"}); +// System.err.println(cR.getStandardError()); +// assertTrue("Should not coredump: "+cR.getStandardError(),cR.getStandardError().indexOf("Dumping to ajcore")==-1); +// assertTrue("Should be no error messages: \n"+cR.getErrorMessages(),cR.getErrorMessages().size()==0); +// File f = new File(ajc.getSandboxDirectory()+File.separator+"Program.class"); +// assertTrue("Missing class file",f.exists()); +// run("Program"); } // /** diff --git a/tests/src/org/aspectj/systemtest/ajc150/PerTypeWithinTests.java b/tests/src/org/aspectj/systemtest/ajc150/PerTypeWithinTests.java index 6c61fcad1..c8e81c317 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/PerTypeWithinTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/PerTypeWithinTests.java @@ -11,20 +11,23 @@ package org.aspectj.systemtest.ajc150; import java.io.File; -import java.util.Iterator; -import java.util.List; -import org.aspectj.bridge.IMessage; +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; import org.aspectj.tools.ajc.CompilationResult; -public class PerTypeWithinTests extends TestUtils { +public class PerTypeWithinTests extends XMLBasedAjcTestCase { - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/java5/pertypewithin"); - } + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(PerTypeWithinTests.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); + } /** * First few tests: @@ -41,111 +44,57 @@ public class PerTypeWithinTests extends TestUtils { * 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); + runTest("basic ptw test"); } 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); + runTest("ptw hasAspect"); } - + 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());} - - } - + runTest("ptw aspectOf"); + } /** * 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); + runTest("ptw multi-aspects"); } - + /** * 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); + CompilationResult cR = ajc(new File("../tests/java5/pertypewithin"),new String[]{"U.java","-showWeaveInfo"}); + int weavingMessagesFromNormalDeploymentModel = cR.getWeaveMessages().size(); + + cR = ajc(new File("../tests/java5/pertypewithin"),new String[]{"V.java","-showWeaveInfo"}); + int weavingMessagesFromPerTypeWithin = cR.getWeaveMessages().size(); - 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); - + assertEquals("Expected same number of messages regardless of perclause", + weavingMessagesFromNormalDeploymentModel,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); + public void testBinaryWeaving_ClassesAreBinary() { + runTest("ptw binary"); } - - // binary weaving case ... + + public void testBinaryWeaving_AspectsAreBinary() { + runTest("ptw binary aspect"); + } +// // Compile the aspect H.java into classes3 +// CompilationResult cR = ajc(new File("../tests/java5/pertypewithin"),new String[]{"H.java","-outjar","aspects.jar"}); +// setShouldEmptySandbox(false); +// // Compile the class with H.class as aspectpath, should be binary woven correctly +// cR = ajc(new File("../tests/java5/pertypewithin"),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 diff --git a/tests/src/org/aspectj/systemtest/ajc150/TestUtils.java b/tests/src/org/aspectj/systemtest/ajc150/TestUtils.java deleted file mode 100644 index 69b3b9f4e..000000000 --- a/tests/src/org/aspectj/systemtest/ajc150/TestUtils.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * 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 implementation - *******************************************************************************/ -package org.aspectj.systemtest.ajc150; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.util.ClassPath; -import org.aspectj.apache.bcel.util.SyntheticRepository; -import org.aspectj.bridge.IMessage; -import org.aspectj.tools.ajc.AjcTestCase; -import org.aspectj.tools.ajc.CompilationResult; - -public abstract class TestUtils extends AjcTestCase { - protected static final boolean verbose = false; - protected File baseDir; - - protected CompilationResult binaryWeave(String inpath,String insource,int expErrors,int expWarnings) { - return binaryWeave(inpath,insource,expErrors,expWarnings,false); - } - - protected CompilationResult binaryWeave(String inpath, String insource,int expErrors,int expWarnings,boolean xlinterror) { - return binaryWeave(inpath,insource,expErrors,expWarnings,xlinterror,(String[])null); - } - - protected CompilationResult binaryWeave(String inpath, String insource,int expErrors,int expWarnings,String extraOption) { - return binaryWeave(inpath,insource,expErrors,expWarnings,false,extraOption); - } - - protected CompilationResult binaryWeave(String inpath, String insource,int expErrors,int expWarnings,boolean xlinterror,String extraOption) { - return binaryWeave(inpath, insource, expErrors, expWarnings,xlinterror,new String[] {extraOption}); - } - - protected CompilationResult binaryWeave(String inpath, String insource,int expErrors,int expWarnings,boolean xlinterror,String[] extraOptions) { - String[] args = null; - if (xlinterror) { - if (extraOptions!=null && extraOptions.length > 0) { - String[] firstargs = new String[] {"-inpath",inpath,insource,"-showWeaveInfo","-proceedOnError","-Xlint:warning"}; - args = new String[firstargs.length + extraOptions.length]; - System.arraycopy(firstargs,0,args,0,firstargs.length); - System.arraycopy(extraOptions,0,args,firstargs.length,extraOptions.length); - } - else - args = new String[] {"-inpath",inpath,insource,"-showWeaveInfo","-proceedOnError","-Xlint:warning"}; - } else { - if (extraOptions!=null && extraOptions.length>0) { - String[] firstargs = new String[] {"-inpath",inpath,insource,"-showWeaveInfo","-proceedOnError"}; - args = new String[firstargs.length + extraOptions.length]; - System.arraycopy(firstargs,0,args,0,firstargs.length); - System.arraycopy(extraOptions,0,args,firstargs.length,extraOptions.length); - } - else - args = new String[] {"-inpath",inpath,insource,"-showWeaveInfo","-proceedOnError"}; - } - CompilationResult result = ajc(baseDir,args); - if (verbose || result.hasErrorMessages()) System.out.println(result); - assertTrue("Expected "+expErrors+" errors but got "+result.getErrorMessages().size()+":\n"+ - formatCollection(result.getErrorMessages()),result.getErrorMessages().size()==expErrors); - assertTrue("Expected "+expWarnings+" warnings but got "+result.getWarningMessages().size()+":\n"+ - formatCollection(result.getWarningMessages()),result.getWarningMessages().size()==expWarnings); - return result; - } - - - private String formatCollection(Collection s) { - StringBuffer sb = new StringBuffer(); - for (Iterator iter = s.iterator(); iter.hasNext();) { - Object element = (Object) iter.next(); - sb.append(element).append("\n"); - } - return sb.toString(); - } - - protected List getWeavingMessages(List msgs) { - List result = new ArrayList(); - for (Iterator iter = msgs.iterator(); iter.hasNext();) { - IMessage element = (IMessage) iter.next(); - if (element.getKind()==IMessage.WEAVEINFO) { - result.add(element.toString()); - } - } - return result; - } - - protected void verifyWeavingMessagesOutput(CompilationResult cR,String[] expected) { - List weavingmessages = getWeavingMessages(cR.getInfoMessages()); - dump(weavingmessages); - for (int i = 0; i < expected.length; i++) { - boolean found = weavingmessages.contains(expected[i]); - if (found) { - weavingmessages.remove(expected[i]); - } else { - System.err.println(dump(getWeavingMessages(cR.getInfoMessages()))); - fail("Expected message not found.\nExpected:\n"+expected[i]+"\nObtained:\n"+dump(getWeavingMessages(cR.getInfoMessages()))); - } - } - if (weavingmessages.size()!=0) { - fail("Unexpected messages obtained from program:\n"+dump(weavingmessages)); - } - } - - - private String dump(List l) { - StringBuffer sb = new StringBuffer(); - int i =0; - sb.append("--- Weaving Messages ---\n"); - for (Iterator iter = l.iterator(); iter.hasNext();) { - sb.append(i+") "+iter.next()+"\n"); - } - sb.append("------------------------\n"); - return sb.toString(); - } - - public SyntheticRepository createRepos(File cpentry) { - ClassPath cp = new ClassPath(cpentry+File.pathSeparator+System.getProperty("java.class.path")); - return SyntheticRepository.getInstance(cp); - } - - protected JavaClass getClassFrom(File where,String clazzname) throws ClassNotFoundException { - SyntheticRepository repos = createRepos(where); - return repos.loadClass(clazzname); - } -} diff --git a/tests/src/org/aspectj/systemtest/ajc150/VarargsTests.java b/tests/src/org/aspectj/systemtest/ajc150/VarargsTests.java index 14f4532c7..e4175fee7 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/VarargsTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/VarargsTests.java @@ -12,8 +12,9 @@ package org.aspectj.systemtest.ajc150; import java.io.File; -import org.aspectj.bridge.IMessage; -import org.aspectj.tools.ajc.CompilationResult; +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; /** @@ -22,73 +23,46 @@ import org.aspectj.tools.ajc.CompilationResult; * 1. cannot match on a varargs method by using 'Object[]' in your signature, * this affects call/execution/initialization/withincode */ -public class VarargsTests extends TestUtils { - - protected void setUp() throws Exception { - super.setUp(); - baseDir = new File("../tests/java5/varargs"); - } +public class VarargsTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(VarargsTests.class); + } + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); + } + // check when signature is from a call PCD // should get message: // "an array type as the last parameter in a signature does not match on the varargs declared method: " public void test001_cantMatchVarargsWithObjectArray_callPCD() { - CompilationResult cR = binaryWeave("testcode.jar","VarargsAspect01.aj",0,3,true); - assertTrue("Did not get expected message about a varargs mismatch, instead got: "+cR.getWarningMessages(), - ((IMessage)cR.getWarningMessages().get(0)).toString().indexOf("varargs declared method")!=-1); - verifyWeavingMessagesOutput(cR,new String[]{}); + runTest("varargs not matched by Object[] (call)"); } // check when signature is from an execution PCD public void test002_cantMatchVarargsWithObjectArray_execPCD() { - CompilationResult cR = binaryWeave("testcode.jar","VarargsAspect02.aj",0,1,true); - assertTrue("Did not get expected message about a varargs mismatch, instead got: "+cR.getWarningMessages(), - ((IMessage)cR.getWarningMessages().get(0)).toString().indexOf("varargs declared method")!=-1); - verifyWeavingMessagesOutput(cR,new String[]{}); + runTest("varargs not matched by Object[] (exe)"); } // check when signature is from an initialization PCD public void test003_cantMatchVarargsWithObjectArray_initPCD() { - CompilationResult cR = binaryWeave("testcode.jar","VarargsAspect03.aj",0,1,true); - assertTrue("Did not get expected message about a varags mismatch, instead got: "+cR.getWarningMessages(), - ((IMessage)cR.getWarningMessages().get(0)).toString().indexOf("varargs declared method")!=-1); - verifyWeavingMessagesOutput(cR,new String[]{}); + runTest("varargs not matched by Object[] (init)"); } // check when signature is from an withincode PCD public void test003_cantMatchVarargsWithObjectArray_withincodePCD() { - CompilationResult cR = binaryWeave("testcode.jar","VarargsAspect04.aj",0,1,true); - - assertTrue("Did not get expected message about a varargs mismatch, instead got: "+cR.getWarningMessages(), - ((IMessage)cR.getWarningMessages().get(0)).toString().indexOf("varargs declared method")!=-1); - - verifyWeavingMessagesOutput(cR,new String[]{}); + runTest("varargs not matched by Object[] (withincode)"); } - // before(): call(* *(Integer...)) { } public void test_usingVarargsInPointcuts1() { - CompilationResult cR = binaryWeave("testcode.jar","VarargsAspect05.aj",0,0,true); - System.err.println(cR.getStandardError()); - System.err.println(cR.getErrorMessages()); - System.err.println(cR.getInfoMessages()); - verifyWeavingMessagesOutput(cR,new String[]{ - "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:20) advised by before advice from 'VarargsAspect05' (VarargsAspect05.aj:3)", - "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:21) advised by before advice from 'VarargsAspect05' (VarargsAspect05.aj:3)", - "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:22) advised by before advice from 'VarargsAspect05' (VarargsAspect05.aj:3)"}); + runTest("call with varargs signature"); } - + // before(): call(* *(int,Integer...)) { } - slightly more complex pcut public void test_usingVarargsInPointcuts2() { - CompilationResult cR = binaryWeave("testcode.jar","VarargsAspect06.aj",0,0,true); - System.err.println(cR.getStandardError()); - System.err.println(cR.getErrorMessages()); - System.err.println(cR.getInfoMessages()); - - verifyWeavingMessagesOutput(cR,new String[]{ - "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:25) advised by before advice from 'VarargsAspect06' (VarargsAspect06.aj:3)", - "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:26) advised by before advice from 'VarargsAspect06' (VarargsAspect06.aj:3)", - "weaveinfo Type 'SimpleVarargs' (SimpleVarargs.java:27) advised by before advice from 'VarargsAspect06' (VarargsAspect06.aj:3)"}); - } - + runTest("call with varargs multi-signature"); + } + } \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150-tests.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150-tests.xml deleted file mode 100644 index c0fbc6bd2..000000000 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150-tests.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index b85b36f54..8e100ce36 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -1,12 +1,901 @@ ]> -&tests; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5