From 2b24e7377da7c849fe7f9f4fa06a701664f9d27d Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Wed, 30 Jan 2019 16:55:38 -0800 Subject: mavenizing tests - wip --- .../systemtest/ajc150/AccBridgeMethods.java | 67 + .../org/aspectj/systemtest/ajc150/Ajc150Tests.java | 1035 ++++ .../systemtest/ajc150/AllTestsAspectJ150.java | 63 + .../systemtest/ajc150/AnnotationBinding.java | 402 ++ .../ajc150/AnnotationPointcutsTests.java | 53 + .../systemtest/ajc150/AnnotationRuntimeTests.java | 60 + .../org/aspectj/systemtest/ajc150/Annotations.java | 171 + .../ajc150/AnnotationsBinaryWeaving.java | 56 + .../org/aspectj/systemtest/ajc150/Autoboxing.java | 94 + .../aspectj/systemtest/ajc150/CovarianceTests.java | 166 + .../systemtest/ajc150/DeclareAnnotationTests.java | 331 + .../java/org/aspectj/systemtest/ajc150/Enums.java | 72 + .../systemtest/ajc150/GenericITDsDesign.java | 254 + .../aspectj/systemtest/ajc150/GenericsTests.java | 996 ++++ .../org/aspectj/systemtest/ajc150/HasMember.java | 58 + .../aspectj/systemtest/ajc150/MigrationTests.java | 64 + .../systemtest/ajc150/PerTypeWithinTests.java | 104 + .../systemtest/ajc150/RuntimeAnnotations.java | 138 + .../aspectj/systemtest/ajc150/SCCSFixTests.java | 73 + .../aspectj/systemtest/ajc150/StaticImports.java | 33 + .../systemtest/ajc150/SuppressedWarnings.java | 53 + .../aspectj/systemtest/ajc150/VarargsTests.java | 80 + .../java/org/aspectj/systemtest/ajc150/ajc150.xml | 6308 ++++++++++++++++++++ .../ajc150/ataspectj/AtAjAnnotationGenTests.java | 160 + .../systemtest/ajc150/ataspectj/AtAjLTWTests.java | 237 + .../ajc150/ataspectj/AtAjMisuseTests.java | 68 + .../ajc150/ataspectj/AtAjSyntaxTests.java | 145 + .../systemtest/ajc150/ataspectj/annotationgen.xml | 187 + .../ajc150/ataspectj/coverage/CoverageTests.java | 43 + .../ajc150/ataspectj/coverage/coverage.xml | 320 + .../aspectj/systemtest/ajc150/ataspectj/ltw.xml | 349 ++ .../aspectj/systemtest/ajc150/ataspectj/misuse.xml | 146 + .../aspectj/systemtest/ajc150/ataspectj/syntax.xml | 202 + .../systemtest/ajc150/ltw/LTWServerTests.java | 27 + .../aspectj/systemtest/ajc150/ltw/LTWTests.java | 213 + .../aspectj/systemtest/ajc150/ltw/ltw-tests.xml | 670 +++ .../java/org/aspectj/systemtest/ajc150/ltw/ltw.xml | 11 + .../org/aspectj/systemtest/ajc150/tests/.cvsignore | 1 + 38 files changed, 13510 insertions(+) create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/AccBridgeMethods.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/Ajc150Tests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationBinding.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/Annotations.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationsBinaryWeaving.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/Autoboxing.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/CovarianceTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/DeclareAnnotationTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/Enums.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/GenericITDsDesign.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/GenericsTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/HasMember.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/MigrationTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/PerTypeWithinTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/RuntimeAnnotations.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/SCCSFixTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/StaticImports.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/SuppressedWarnings.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/VarargsTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ajc150.xml create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjAnnotationGenTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjLTWTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjMisuseTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/annotationgen.xml create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/coverage/CoverageTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/coverage/coverage.xml create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/misuse.xml create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/LTWServerTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/LTWTests.java create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/ltw.xml create mode 100644 tests/src/test/java/org/aspectj/systemtest/ajc150/tests/.cvsignore (limited to 'tests/src/test/java/org/aspectj/systemtest/ajc150') diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/AccBridgeMethods.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/AccBridgeMethods.java new file mode 100644 index 000000000..e9348f49c --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/AccBridgeMethods.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + + +/** + * These tests check binary weaving of code compiled with the 1.5 compiler. If you need to rebuild + * the class files then you will have to run tests/java5/bridgeMethods/build.xml. + * + *

Bridge methods are generated when a type extends or implements a parameterized class or interface and + * type erasure changes the signature of any inherited method. + * + *

They impact AspectJ in two ways: + *

    + *
  1. They exist as a method execution join point, and their 'body' exists as a set of new join points + * (although their body is normally coded simply to delegate to the method they are bridging too). + *
  2. They create a potential call join point where a call can be made to the bridge method. + *
+ * + *

The principal things we have to do are avoid weaving their body and ignore their existence + * as a method execution join point. Their existence as a potential target for a call join point are + * more complicated. Although they exist in the code, a 1.5 compiler will prevent a call to them with + * an error like this: + * + * M.java:3: compareTo(Number) in Number cannot be applied to (java.lang.String) + * new Number(5).compareTo("abc"); + * + * Our problem is that a Java 1.4 or earlier compiler will allow you to write calls to this bridge method + * and it will let them through. + */ +public class AccBridgeMethods extends org.aspectj.testing.XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AccBridgeMethods.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + + /** + * AspectX attempts to weave call and execution of the method for which a 'bridge method' is also created. + * If the test works then only two weaving messages come out. If it fails then usually 4 messages come out + * and we have incorrectly woven the bridge method (the 3rd message is execution of the bridge method and + * the 4th message is the call within the bridge method to the real method). + */ + public void test001_bridgeMethodIgnored() { + runTest("Ignore bridge methods"); + } + + +} \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/Ajc150Tests.java new file mode 100644 index 000000000..c9998d6c9 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -0,0 +1,1035 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-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 junit.framework.Test; + +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.classfile.Signature; +import org.aspectj.asm.AsmManager; +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.util.LangUtil; + +public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Ajc150Tests.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + public void testMixingCodeStyles_pr121385() { + runTest("mixing aspect styles"); + } + + public void testTypeVars_pr121575() { + runTest("different numbers of type vars"); + } + + public void testTypeVars_pr121575_2() { + runTest("different numbers of type vars - 2"); + } + + public void testTypeVars_pr121575_3() { + runTest("different numbers of type vars - 3"); + } + + public void testTypeVars_pr121575_4() { + runTest("different numbers of type vars - 4"); + } + + public void testDecps1() { + runTest("decps - 1"); + } + + public void testDecps1b() { + runTest("decps - 1b"); + } + + public void testDecps2() { + runTest("decps - 2"); + } + + public void testDecps2b() { + runTest("decps - 2b"); + } + + public void testDecps3() { + runTest("decps - 3"); + } + + public void testDecps3b() { + runTest("decps - 3b"); + } + + public void testDecps3c() { + runTest("decps - 3c"); + } + + public void testVarargsNPE_pr120826() { + runTest("varargs NPE"); + } + + public void testNamedPointcutPertarget_pr120521() { + runTest("named pointcut not resolved in pertarget pointcut"); + } + + public void testDollarClasses_pr120474() { + runTest("Dollar classes"); + } + + public void testGenericPTW_pr119539_1() { + runTest("generic pertypewithin aspect - 1"); + } + + public void testGenericPTW_pr119539_2() { + runTest("generic pertypewithin aspect - 2"); + } + + public void testGenericPTW_pr119539_3() { + runTest("generic pertypewithin aspect - 3"); + } + + /* + * public void testBrokenDispatchByITD_pr72834() { runTest("broken dispatch");} public void testMissingAccessor_pr73856() { + * runTest("missing accessor");} public void testCunningDeclareParents_pr92311() { runTest("cunning declare parents");} public + * void testGenericITDsAndAbstractMethodError_pr102357() { runTest("generic itds and abstract method error");} + */ + public void testIncorrectSignatureMatchingWithExceptions_pr119749() { + runTest("incorrect exception signature matching"); + } + + public void testGeneratingCodeForAnOldRuntime_pr116679_1() { + runTest("generating code for a 1.2.1 runtime - 1"); + } + + public void testGeneratingCodeForAnOldRuntime_pr116679_2() { + runTest("generating code for a 1.2.1 runtime - 2"); + } + + public void testAmbiguousMethod_pr118599_1() { + runTest("ambiguous method when binary weaving - 1"); + } + + public void testAmbiguousMethod_pr118599_2() { + runTest("ambiguous method when binary weaving - 2"); + } + + public void testAroundAdviceArrayAdviceSigs_pr118781() { + runTest("verify error with around advice array sigs"); + } + + public void testAtDeclareParents_pr117681() { + runTest("at declare parents"); + } + + public void testPrivilegeProblem_pr87525() { + runTest("privilege problem with switch"); + } + + public void testRangeProblem_pr109614() { + runTest("Range problem"); + } + + public void testGenericAspects_pr115237() { + runTest("aspectOf and generic aspects"); + } + + public void testClassFormatError_pr114436() { + runTest("ClassFormatError binary weaving perthis"); + } + + public void testParserException_pr115788() { + runTest("parser exception"); + } + + public void testPossibleStaticImports_pr113066_1() { + runTest("possible static imports bug - 1"); + } + + public void testPossibleStaticImports_pr113066_2() { + runTest("possible static imports bug - 2"); + } + + public void testPossibleStaticImports_pr113066_3() { + runTest("possible static imports bug - 3"); + } + + public void testITDCtor_pr112783() { + runTest("Problem with constructor ITDs"); + } + + public void testAnnotatedITDFs_pr114005_1() { + runTest("Annotated ITDFs - 1"); + } + + public void testAnnotatedITDFs_pr114005_2() { + runTest("Annotated ITDFs - 2"); + } + + public void testCantCallSuperMethods_pr90143() { + runTest("cant call super methods"); + } + + public void testBrokenDecp_pr112476() { + runTest("binary weaving decp broken"); + } + + public void testUnboundFormal_pr112027() { + runTest("unexpected error unboundFormalInPC"); + } + + public void testNPEScopeSetup_pr115038() { + runTest("NPE in ensureScopeSetup"); + } + + public void testCCEGenerics_pr113445() { + runTest("Generics ClassCastException"); + } + + public void testMatthewsAspect_pr113947_1() { + runTest("maws generic aspect - 1"); + } + + public void testMatthewsAspect_pr113947_2() { + runTest("maws generic aspect - 2"); + } + + public void testFieldGet_pr114343() { + runTest("field-get, generics and around advice"); + } + + public void testFieldGet_pr114343_2() { + runTest("field-get, generics and around advice - 2"); + } + + public void testFieldGet_pr114343_3() { + runTest("field-get, generics and around advice - 3"); + } + + public void testCaptureBinding_pr114744() { + runTest("capturebinding wildcard problem"); + } + + public void testAutoboxingAroundAdvice_pr119210_1() { + runTest("autoboxing around advice - 1"); + } + + public void testAutoboxingAroundAdvice_pr119210_2() { + runTest("autoboxing around advice - 2"); + } + + public void testAutoboxingAroundAdvice_pr119210_3() { + runTest("autoboxing around advice - 3"); + } + + public void testBadDecp_pr110788_1() { + runTest("bad generic decp - 1"); + } + + public void testBadDecp_pr110788_2() { + runTest("bad generic decp - 2"); + } + + public void testBadDecp_pr110788_3() { + runTest("bad generic decp - 3"); + } + + public void testBadDecp_pr110788_4() { + runTest("bad generic decp - 4"); + } + + // public void testSimplifiedGenericAspectITDTest() { runTest("spurious override method warning - 3");} + // public void testSpuriousOverrideMethodWarning_pr119570_1() { runTest("spurious override method warning");} + // public void testSpuriousOverrideMethodWarning_pr119570_2() { runTest("spurious override method warning - 2");} + + public void testBrokenSwitch_pr117854() { + runTest("broken switch transform"); + } + + public void testVarargsITD_pr110906() { + runTest("ITD varargs problem"); + } + + public void testBadRenderer_pr86903() { + runTest("bcelrenderer bad"); + } + + // public void testIllegalInitialization_pr118326_1() { runTest("illegal initialization - 1");} + // public void testIllegalInitialization_pr118326_2() { runTest("illegal initialization - 2");} + public void testLintForAdviceSorting_pr111667() { + runTest("lint for advice sorting"); + } + + public void testIncompatibleClassChangeError_pr113630_1() { + runTest("IncompatibleClassChangeError - errorscenario"); + } + + public void testIncompatibleClassChangeError_pr113630_2() { + runTest("IncompatibleClassChangeError - workingscenario"); + } + + public void testFieldGetProblemWithGenericField_pr113861() { + runTest("field-get problems with generic field"); + } + + public void testAccesstoPrivateITDInNested_pr118698() { + runTest("access to private ITD from nested type"); + } + + public void testDeclareAnnotationOnNonExistentType_pr99191_1() { + runTest("declare annotation on non existent type - 1"); + } + + public void testDeclareAnnotationOnNonExistentType_pr99191_2() { + runTest("declare annotation on non existent type - 2"); + } + + public void testDeclareAnnotationOnNonExistentType_pr99191_3() { + runTest("declare annotation on non existent type - 3"); + } + + public void testDeclareAnnotationOnNonExistentType_pr99191_4() { + runTest("declare annotation on non existent type - 4"); + } + + public void testDeclareAnnotationOnNonExistentType_pr99191_5() { + runTest("declare annotation on non existent type - 5"); + } + + public void testBadGenericSigAttribute_pr110927() { + runTest("cant create signature attribute"); + Signature sig = GenericsTests.getClassSignature(ajc, "I"); + if (sig == null) + fail("Couldn't find signature attribute for type I"); + String sigString = sig.getSignature(); + if (!(sigString.equals("Ljava/lang/Object;LIE2;LIE1;") || sigString + .equals("Ljava/lang/Object;LIE1;LIE2;"))) { + fail("Signature was " + sigString + + " when should have been something like Ljava/lang/Object;LIE1;LIE2;"); + } + } + + public void test_typeProcessingOrderWhenDeclareParents() { + runTest("Order of types passed to compiler determines weaving behavior"); + } + + public void test_aroundMethod() { + runTest("method called around in class"); + } + + public void test_aroundMethodAspect() { + runTest("method called around in aspect"); + } + + public void test_ambiguousBindingsDetection() { + runTest("Various kinds of ambiguous bindings"); + } + + 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 testPerTypeWithin_pr106554() { + runTest("Problem in staticinitialization with pertypewithin aspect"); + } + + 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 (LangUtil.is15VMOrGreater()) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintWriter pw = new PrintWriter(baos); + AsmManager.dumptree(pw, AsmManager.lastActiveStructureModel.getHierarchy().getRoot(), 0); + pw.flush(); + String tree = baos.toString(); + assertTrue("Expected 'Red [enumvalue]' somewhere in here:" + tree, tree.indexOf("Red [enumvalue]") != -1); + } + } + + public void npeOnTypeNotFound() { + runTest("structure model npe on type not found"); + } + + public void testNoRuntimeExceptionSoftening() { + runTest("declare soft of runtime exception"); + } + + public void testRuntimeNoSoftenWithHandler() { + runTest("declare soft w. catch block"); + } + + public void testSyntaxError() { + runTest("invalid cons syntax"); + } + + public void testVarargsInConsBug() { + runTest("varargs in constructor sig"); + } + + public void testAspectpathdirs() { + runTest("dirs on aspectpath"); + } + + public void testIntroSample() { + runTest("introduction sample"); + } + + public void testPTWInterface() { + runTest("pertypewithin({interface}) illegal field modifier"); + } + + public void testEnumCalledEnumEtc() { + runTest("enum called Enum, annotation called Annotation, etc"); + } + + public void testInternalCompilerError_pr86832() { + runTest("Internal compiler error"); + } + + public void testCloneMethod_pr83311() { + runTest("overriding/polymorphism error on interface method introduction"); + } + + // IfPointcut.findResidueInternal() was modified to make this test complete in a short amount + // of time - if you see it hanging, someone has messed with the optimization. + public void testIfEvaluationExplosion_pr94086() { + runTest("Exploding compile time with if() statements in pointcut"); + } + + public void testReflectNPE_pr94167() { + runTest("NPE in reflect implementation"); + } + + public void testStaticImports_pr84260() { + runTest("static import failures"); + } + + public void testGenerics_pr99089() { + runTest("ArrayIndexOutOfBoundsException - Generics in privileged aspects"); + } + + public void testGenerics_pr95993() { + runTest("NPE at ClassScope.java:660 when compiling generic class"); + } + + public void testItdGenerics_pr99228() { + runTest("ITD of a field into a generic class"); + } + + public void testItdGenerics_pr98320() { + runTest("intertype with nested generic type"); + } + + public void testItdGenerics_pr100227() { + runTest("inner class with generic enclosing class"); + } + + public void testItdGenerics_pr100260() { + runTest("methods inherited from a generic parent"); + } + + public void testSyntaxErrorNPE_pr103266() { + runTest("NPE on syntax error"); + } + + public void testFinalAbstractClass_pr109486() { + runTest("Internal compiler error (ClassParser.java:242)"); + } + + public void testComplexBinding_pr102210() { + runTest("NullPointerException trying to compile"); + } + + public void testIllegalStateExceptionOnNestedParameterizedType_pr106634() { + runTest("IllegalStateException unpacking signature of nested parameterized type"); + } + + public void testParseErrorOnAnnotationStarPlusPattern() { + runTest("(@Foo *)+ type pattern parse error"); + } + + public void test_pr106130_tooManyLocals() { + runTest("test weaving with > 256 locals"); + } + + public void testMissingNamePattern_pr106461() { + runTest("missing name pattern"); + } + + public void testMissingNamePattern_pr107059() { + runTest("parser crashes on call(void (@a *)(..)"); + } + + public void testIntermediateAnnotationMatching() { + runTest("intermediate annotation matching"); + } + + public void testBadRuntimeTestGeneration() { + runTest("target(@Foo *)"); + } + + // ONE_EIGHT remove for now, needs some grammar changes to ensure empty type annotations are put in place for later consumption +// public void testErrorMessageOnITDWithTypePatterns() { +// runTest("clear error message on itd with type pattern"); +// } + + public void testAjKeywordsAsIdentifiers() { + runTest("before and after are valid identifiers in classes"); + } + + public void testAjKeywordsAsIdentifiers2() { + runTest("before and after are valid identifiers in classes, part 2"); + } + + public void testNoBeforeReturningAdvice() { + runTest("before returning advice not allowed!"); + } + + public void testDetectVoidFieldType() { + runTest("void field type in pointcut expression"); + } + + public void testPointcutOverriding() { + runTest("overriding final pointcut from super-aspect"); + } + + public void testAtSuppressWarnings() { + runTest("@SuppressWarnings should suppress"); + } + + public void testDEOWWithBindingPointcut() { + runTest("declare warning : foo(str) : ...;"); + } + + public void testAroundAdviceAndInterfaceInitializer() { + runTest("around advice on interface initializer"); + } + + public void testGoodErrorMessageOnUnmatchedMemberSyntax() { + runTest("good error message for unmatched member syntax"); + } + + public void testITDWithNoExceptionAndIntermediary() { + runTest("itd override with no exception clause"); + } + + public void testAnonymousInnerClasses() { + runTest("anonymous inner classes"); + } + + public void testMultipleAnonymousInnerClasses() { + runTest("multiple anonymous inner classes"); + } + + public void testPrivilegedMethodAccessorsGetRightExceptions_pr82989() { + runTest("Compiler error due to a wrong exception check in try blocks"); + } + + public void testAnonymousInnerClassWithMethodReturningTypeParameter_pr107898() { + runTest("anonymous inner class with method returning type parameter"); + } + + public void testMatchingOfObjectArray() { + runTest("matching against Object[]"); + } + + public void testMultipleAnonymousInnerClasses_pr108104() { + runTest("multiple anonymous inner classes 2"); + } + + public void testSignatureMatchingInMultipleOverrideScenario() { + runTest("signature matching in override scenario"); + } + + public void testWildcardAnnotationMatching_pr108245() { + runTest("wildcard annotation matching - pr108245"); + } + + public void testInnerTypesAndTypeVariables() { + runTest("inner types and type variables"); + } + + public void testAtAfterThrowingWithNoFormal() { + runTest("@AfterThrowing with no formal specified"); + } + + public void testParameterizedVarArgsMatch() { + runTest("varargs with type variable"); + } + + public void testFieldAccessInsideITDM() { + runTest("itd field access inside itd method"); + } + + public void testTypeVarWithTypeVarBound() { + runTest("type variable with type variable bound"); + } + + public void testEnumSwitchInITD() { + runTest("switch on enum inside ITD method"); + } + + public void testInnerTypeOfGeneric() { + runTest("inner type of generic interface reference from parameterized type"); + } + + public void testDeclareParentsIntroducingCovariantReturnType() { + runTest("declare parents introducing override with covariance"); + } + + public void testInnerClassPassedToVarargs() { + runTest("inner class passed as argument to varargs method"); + } + + public void testInlinedFieldAccessInProceedCall() { + runTest("inlined field access in proceed call"); + } + + public void testVisibiltyInSignatureMatchingWithOverridesPart1() { + runTest("visibility in signature matching with overrides - 1"); + } + + public void testVisibiltyInSignatureMatchingWithOverridesPart2() { + runTest("visibility in signature matching with overrides - 2"); + } + + public void testVisibiltyInSignatureMatchingWithOverridesPart3() { + runTest("visibility in signature matching with overrides - 3"); + } + + public void testArgsGeneratedCorrectlyForAdviceExecution() { + runTest("args generated correctly for advice execution join point"); + } + + public void testNoUnusedWarningsOnAspectTypes() { + runTest("no unused warnings on aspect types"); + } + + public void testSyntheticArgumentsOnITDConstructorsNotUsedInMatching() { + runTest("synthetic arguments on itd cons are not used in matching"); + } + + public void testParsingOfGenericTypeSignature() { + runTest("parse generic type signature with parameterized type in interface"); + } + + public void testOverrideAndCovarianceWithDecPRuntime() { + runTest("override and covariance with decp - runtime"); + } + + public void testOverrideAndCovarianceWithDecPRuntimeMultiFiles() { + runTest("override and covariance with decp - runtime separate files"); + } + + public void testOverrideAndCovarianceWithDecPRuntimeMultiFilesBinaryWeaving() { + runTest("override and covariance with decp - binary weaving"); + } + + public void testAbstractSynchronizedITDMethods() { + runTest("abstract synchronized itdms not detected"); + } + + public void testSynchronizedITDInterfaceMethods() { + runTest("synchronized itd interface methods"); + } + + public void testNoWarningOnUnusedPointcut() { + runTest("unused private pointcuts"); + } + + public void testITDOnInterfaceWithExistingMember() { + runTest("itd interface method already existing on interface"); + } + + public void testFinalITDMOnInterface() { + runTest("final itd methods on interfaces"); + } + + public void testPrivatePointcutOverriding() { + runTest("can't override private pointcut in abstract aspect"); + } + + public void testAdviceOnCflow() { + runTest("advising cflow advice execution"); + } + + public void testNoTypeMismatchOnSameGenericTypes() { + runTest("no type mismatch on generic types in itds"); + } + + public void testSuperCallInITD() { + runTest("super call in ITD"); + } + + public void testSuperCallInITDPart2() { + runTest("super call in ITD - part 2"); + } + + public void testAtAnnotationBadTest_pr103740() { + runTest("Compiler failure on at_annotation"); + } + + public void testNoUnusedParameterWarningsForSyntheticAdviceArgs() { + runTest("no unused parameter warnings for synthetic advice args"); + } + + public void testNoVerifyErrorWithSetOnInnerType() { + runTest("no verify error with set on inner type"); + } + + public void testCantFindTypeErrorWithGenericReturnTypeOrParameter() { + runTest("cant find type error with generic return type or parameter"); + } + + public void testNoVerifyErrorOnGenericCollectionMemberAccess() { + runTest("no verify error on generic collection member access"); + } + + public void testRawAndGenericTypeConversionITDCons() { + runTest("raw and generic type conversion with itd cons"); + } + + public void testAtAnnotationBindingWithAround() { + runTest("@annotation binding with around advice"); + } + + public void testUnableToBuildShadows_pr109728() { + runTest("Unable to build shadows"); + } + + public void testMessageOnMissingTypeInDecP() { + runTest("declare parents on a missing type"); + } + + public void testParameterizedGenericMethods() { + runTest("parameterized generic methods"); + } + + public void testIllegalChangeToPointcutDeclaration_pr111915() { + runTest("test illegal change to pointcut declaration"); + } + + public void testCantProvideDefaultImplViaITD_pr110307_1() { + runTest("Cant provide default implementation via ITD - 1"); + } + + public void testCantProvideDefaultImplViaITD_pr110307_2() { + runTest("Cant provide default implementation via ITD - 2"); + } + + public void testCantProvideDefaultImplViaITD_pr110307_3() { + runTest("Cant provide default implementation via ITD - 3"); + } + + public void testCantProvideDefaultImplViaITD_pr110307_4() { + runTest("Cant provide default implementation via ITD - 4"); + } + + public void testCantProvideDefaultImplViaITD_pr110307_5() { + runTest("Cant provide default implementation via ITD - 5"); + } + + // Needs a change in the compiler so that getType() can be overridden in the intertype scope - thats + // where we can police whether a type variable has been used without being specified appropriately. + // public void testCantProvideDefaultImplViaITD_pr110307_6() {runTest("Cant provide default implementation via ITD - 6");} + + public void testCantProvideDefaultImplViaITD_pr110307_7() { + runTest("Cant provide default implementation via ITD - 7"); + } + + public void testCallJoinPointsInAnonymousInnerClasses() { + runTest("call join points in anonymous inner classes"); + } + + public void testNoRequirementForUnwovenTypesToBeExposedToWeaver() { + runTest("default impl of Runnable"); + } + + public void testArrayCloneCallJoinPoints() { + runTest("array clone call join points in 1.4 vs 1.3"); + } + + public void testDebugInfoForAroundAdvice() { + runTest("debug info in around advice inlining"); + } + + public void testCCEWithGenericWildcard_pr112602() { + runTest("ClassCastException with generic wildcard"); + } + + public void testVarArgsIITDInConstructor() { + runTest("ITD varargs in constructor"); + } + + public void testWeaveInfoMessageForDeclareAtMethodOnITDdMethod() { + runTest("weaveinfo message for declare at method on an ITDd method"); + } + + public void testITDCWithNoExplicitConsCall() { + runTest("ITDC with no explicit cons call"); + } + + public void testJava5SpecificFeaturesUsedAtJava14OrLower() { + if (LangUtil.is17VMOrGreater()) { + runTest("java 5 pointcuts and declares at pre-java 5 compliance levels - 1.7"); + } else { + runTest("java 5 pointcuts and declares at pre-java 5 compliance levels"); + } + } + + public void testAnonymousTypes() { + runTest("Anonymous types and nome matching"); + } + + public void testAdviceExecutionJPToStringForms() { + runTest("adviceexecution join point toString forms"); + } + + public void testAssertWithinPointcutExpression() { + runTest("pointcut expression containing 'assert'"); + } + + public void testNoVerifyErrorWithTwoThisPCDs_pr113447() { + runTest("no verify error with two this pcds"); + } + + public void testNoVerifyErrorWithTwoAtThisPCDs_pr113447() { + runTest("no verify error with two at this pcds"); + } + + public void testNoVerifyErrorWithAtWithinPCDs_pr113447() { + runTest("no verify error with at within pcds"); + } + + public void testNoVerifyErrorWithAtWithincodePCDs_pr113447() { + runTest("no verify error with at withincode pcds"); + } + + public void testNoVerifyErrorWithAtAnnotationPCDs_pr113447() { + runTest("no verify error with at annotation pcds"); + } + + public void testNoVerifyErrorWithTwoArgsPCDs_pr113447() { + runTest("no verify error with two args pcds"); + } + + public void testNoStackOverflowWithCircularPCDInGenericAspect() { + runTest("no StackOverflowError with circular pcd in generic aspect"); + } + + public void testNoStackOverflowWithCircularPCDInGenericAspect2() { + runTest("no StackOverflowError with circular pcd in generic aspect - 2"); + } + + public void testNPEInThisJoinPointStaticPart() { + runTest("thisJoinPointStaticPart in if test"); + } + + public void testPointcutParsingOfCompiledPointcuts() { + runTest("pointcut parsing with ajc compiled pointcut references"); + } + + public void testReflectionOfAbstractITDs() { + runTest("reflection on abstract ITDs (Billing example)"); + } + + public void testDeclareSoftWithAdviceExecution() { + runTest("declare soft and adviceexecution"); + } + + public void testDeclareSoftWithExclusions() { + runTest("declare soft and exclusions"); + } + + public void testReturningObjectBinding() { + runTest("returning(Object) binding"); + } + + public void testPerTargetAndNegation() { + runTest("pertarget and negated pointcut"); + } + + public void testParameterizedPointcutAndAdvice() { + runTest("parameterized pointcut and advice"); + } + + public void testDoublyParameterizedAbstractType() { + runTest("double parameter generic abstract type"); + } + + public void testArgNamesInAdviceAnnotations() { + runTest("arg names in advice annotations"); + } + + /* + * Load-time weaving bugs + */ + public void testNPEinWeavingAdaptor_pr116626() { + runTest("NPE in WeavingAdaptor"); + } + + public void testXlintMessageForImproperAnnotationType_pr115252_Exact() { + runTest("xlint message for improper exact annotation type"); + } + + public void testXlintMessageForImproperAnnotationType_pr115252_OR() { + runTest("xlint message for improper annotation type inside OR"); + } + + public void testXlintMessageForImproperAnnotationType_pr115252_AND() { + runTest("xlint message for improper annotation type inside AND"); + } + + public void testXlintMessageForImproperAnnotationType_pr115252_Return() { + runTest("xlint message for improper annotated return type"); + } + + public void testXlintMessageForImproperAnnotationType_pr115252_Declaring() { + runTest("xlint message for improper annotated declaring type"); + } + + public void testXlintMessageForImproperAnnotationType_pr115252_Parameter() { + runTest("xlint message for improper annotated parameter type"); + } + + public void testXlintMessageForImproperAnnotationType_pr115252_Throws() { + runTest("xlint message for improper annotated throws pattern"); + } + + public void testXlintMessageForImproperAnnotationType_pr115252_MoreThanOne() { + runTest("xlint message for more than one improper annotated parameter type"); + } + + public void testNoNPEWhenInaccessibleMethodIsCalledWithinITD_pr119019() { + runTest("no NPE when inaccessible method is called within itd"); + } + + public void testNoNPEWithOrPointcutAndMoreThanOneArgs_pr118149() { + runTest("no NPE with or pointcut and more than one args"); + } + + public void testNoSOBWithGenericInnerAspects_pr119543() { + runTest("no StringOutOfBoundsException with generic inner aspects"); + } + + public void testIllegalAccessErrorWithAroundAdvice_pr119657() { + runTest("IllegalAccessError with around advice on interface method call"); + } + + public void testIllegalAccessErrorWithAroundAdviceNotSelf_pr119657() { + runTest("IllegalAccessError with around advice on interface method call not self"); + } + + public void testIllegalAccessErrorWithAroundAdviceTerminateAfterCompilationLTW_pr119657() { + runTest("IllegalAccessError with around advice on interface method call using -XterminateAfterCompilation and LTW"); + } + + public void testIllegalAccessErrorWithAroundAdviceLTW_pr119657() { + runTest("IllegalAccessError with around advice on interface method call using LTW"); + } + + public void testIllegalAccessErrorWithAroundAdviceNotSelfLTW_pr119657() { + runTest("IllegalAccessError with around advice on interface method call not self using LTW"); + } + + public void testIllegalAccessErrorWithAroundAdviceSelfAndNotSelfLTW_pr119657() { + runTest("IllegalAccessError with around advice on interface method call self and not self using LTW"); + } + + public void testIllegalAccessErrorWithAroundAdviceLTWNoInline_pr119657() { + runTest("IllegalAccessError with around advice on interface method call using LTW and -XnoInline"); + } + + public void testReflectOnCodeStyleITDs() { + runTest("reflection on itds"); + } + + public void testReflectOnAtAspectJDecP() { + runTest("reflection on @DeclareParents"); + } + + public void testModifierOverrides() { + runTest("modifier overrides"); + } + + public void testAbstractPerThisInAtAspectJ() { + runTest("abstract perthis in @AspectJ"); + } + + public void testNPEInBcelAdviceWithConcreteAspect_pr121385() { + runTest("override protected pointcut in aop.xml concrete aspect"); + } + +} \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java new file mode 100644 index 000000000..1d750bb94 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/AllTestsAspectJ150.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.aspectj.systemtest.ajc150.ataspectj.AtAjLTWTests; +import org.aspectj.systemtest.ajc150.ataspectj.AtAjMisuseTests; +import org.aspectj.systemtest.ajc150.ataspectj.AtAjSyntaxTests; +import org.aspectj.systemtest.ajc150.ltw.LTWServerTests; +import org.aspectj.systemtest.ajc150.ltw.LTWTests; + +/** + * This pulls together tests we have written for AspectJ 1.5.0 that don't need Java 1.5 to run + */ +public class AllTestsAspectJ150 { + + public static Test suite() { + TestSuite suite = new TestSuite("AspectJ1.5.0 tests"); + // $JUnit-BEGIN$ + suite.addTestSuite(MigrationTests.class); + suite.addTest(Ajc150Tests.suite()); + suite.addTestSuite(SCCSFixTests.class); + + suite.addTest(AccBridgeMethods.suite()); + suite.addTestSuite(CovarianceTests.class); + suite.addTestSuite(Enums.class); + suite.addTest(AnnotationsBinaryWeaving.suite()); + suite.addTest(AnnotationPointcutsTests.suite()); + suite.addTestSuite(VarargsTests.class); + suite.addTestSuite(StaticImports.class); + suite.addTest(AnnotationRuntimeTests.suite()); + suite.addTestSuite(PerTypeWithinTests.class); + + suite.addTest(Autoboxing.suite()); + suite.addTest(Annotations.suite()); + suite.addTest(AnnotationBinding.suite()); + suite.addTest(RuntimeAnnotations.suite()); + + suite.addTest(SuppressedWarnings.suite()); + suite.addTest(DeclareAnnotationTests.suite()); + suite.addTest(GenericsTests.suite()); + suite.addTest(GenericITDsDesign.suite()); + suite.addTest(AtAjSyntaxTests.suite()); + suite.addTest(AtAjMisuseTests.suite()); + suite.addTest(AtAjLTWTests.suite()); + suite.addTest(HasMember.suite()); + + suite.addTestSuite(LTWTests.class); + suite.addTestSuite(LTWServerTests.class); + // $JUnit-END$ + return suite; + } +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationBinding.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationBinding.java new file mode 100644 index 000000000..466567641 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationBinding.java @@ -0,0 +1,402 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; +import java.util.List; + +import junit.framework.Test; + +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IHierarchy; +import org.aspectj.asm.IProgramElement; +import org.aspectj.asm.IRelationship; +import org.aspectj.asm.internal.Relationship; +import org.aspectj.testing.XMLBasedAjcTestCase; + +public class AnnotationBinding extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AnnotationBinding.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + // /////////////////////////////////// @ANNOTATION and CALL + + // Very simple annotation binding for 'call() && @annotation()' + public void testCallAnnotationBinding1() { + runTest("call annotation binding 1"); + } + + // 'call() && @annotation()' when the called method has multiple arguments + public void testCallAnnotationBinding2() { + runTest("call annotation binding 2"); + } + + // 'call() && @annotation()' when the called method takes primitive arguments (YUCK!) + public void testCallAnnotationBinding3() { + runTest("call annotation binding 3"); + } + + // 'call() && @annotation()' when runtime type will exhibit different annotation (due to interface implementing) + public void testCallAnnotationBinding4() { + runTest("call annotation binding 4"); + } + + // 'call() && @annotation()' when target doesnt have an annotation ! + public void testCallAnnotationBinding5() { + runTest("call annotation binding 5"); + } + + // 'call() && @annotation()' when runtime type will exhibit different annotation (due to subclassing) + public void testCallAnnotationBinding6() { + runTest("call annotation binding 6"); + } + + // 'call() && @annotation()' using named pointcut + public void testCallAnnotationBinding7() { + runTest("call annotation binding 7"); + } + + // /////////////////////////////////// @TARGET + + // 'call() && @target()' + public void testAtTargetAnnotationBinding1() { + runTest("@target annotation binding 1"); + } + + // 'call() && @target() && @target' + public void testAtTargetAnnotationBinding2() { + runTest("@target annotation binding 2"); + } + + // 'call() && @target()' - using a type hierarchy where some levels are missing annotations + public void testAtTargetAnnotationBinding3() { + 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() { + runTest("@target annotation binding 4"); + } + + // @target() with an annotation in a package + public void testAtTargetAnnotationBinding5() { + runTest("@target annotation binding 5"); + } + + // /////////////////////////////////// @THIS + + // 'call() && @this()' + public void testAtThisAnnotationBinding1() { + runTest("@this annotation binding 1"); + } + + // 'call() && @this() && @this' + public void testAtThisAnnotationBinding2() { + runTest("@this annotation binding 2"); + } + + // 'call() && @this()' - using a type hierarchy where some levels are missing annotations + public void testAtThisAnnotationBinding3() { + 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() { + runTest("@this annotation binding 4"); + } + + // '@this() and @target()' used together + public void testAtThisAtTargetAnnotationBinding() { + runTest("@this annotation binding 5"); + } + + // /////////////////////////////////// @ARGS + + // complex case when there are 3 parameters + public void testAtArgs1() { + runTest("@args annotation binding 1"); + } + + // simple case when there is only one parameter + public void testAtArgs2() { + runTest("@args annotation binding 2"); + } + + // simple case when there is only one parameter and no binding + public void testAtArgs3() { + runTest("@args annotation binding 3"); + } + + // complex case binding different annotation kinds + public void testAtArgs4() { + runTest("@args annotation binding 4"); + } + + // check @args and execution() + public void testAtArgs5() { + runTest("@args annotation binding 5"); + } + + // /////////////////////////////////// @ANNOTATION and EXECUTION + + // 'execution() && @annotation()' + public void testExecutionAnnotationBinding1() { + runTest("execution and @annotation"); + } + + // /////////////////////////////////// @ANNOTATION and SET + + // 'set() && @annotation()' + public void testFieldAnnotationBinding1() { + runTest("set and @annotation"); + } + + // 'get() && @annotation()' + public void testFieldAnnotationBinding2() { + runTest("get and @annotation"); + } + + // 'get() && @annotation()' when using array fields + public void testFieldAnnotationBinding3() { + runTest("get and @annotation with arrays"); + } + + // /////////////////////////////////// @ANNOTATION and CTOR-CALL + + // 'ctor-call(new) && @annotation()' + public void testCtorCallAnnotationBinding1() { + runTest("cons call and @annotation"); + } + + // /////////////////////////////////// @ANNOTATION and CTOR-CALL + + // 'ctor-execution() && @annotation()' + public void testCtorExecAnnotationBinding1() { + runTest("cons exe and @annotation"); + } + + // /////////////////////////////////// @ANNOTATION and STATICINITIALIZATION + + // 'staticinitialization() && @annotation()' + public void testStaticInitAnnotationBinding1() { + runTest("staticinit and @annotation"); + } + + // /////////////////////////////////// @ANNOTATION and PREINITIALIZATION + + // 'preinitialization() && @annotation()' + public void testPreInitAnnotationBinding1() { + runTest("preinit and @annotation"); + } + + // /////////////////////////////////// @ANNOTATION and INITIALIZATION + + // 'initialization() && @annotation()' + public void testInitAnnotationBinding1() { + runTest("init and @annotation"); + } + + // /////////////////////////////////// @ANNOTATION and ADVICEEXECUTION + + // 'adviceexecution() && @annotation()' + public void testAdviceExecAnnotationBinding1() { + runTest("adviceexecution and @annotation"); + } + + // /////////////////////////////////// @ANNOTATION and HANDLER + + // 'handler() && @annotation()' + public void testHandlerAnnotationBinding1() { + runTest("handler and @annotation"); + } + + // /////////////////////////////////// @WITHIN + + // '@within()' + public void testWithinBinding1() { + runTest("@within"); + } + + // '@within()' but multiple types around (some annotated) + public void testWithinBinding2() { + runTest("@within - multiple types"); + } + + // /////////////////////////////////// @WITHINCODE + + // '@withincode() && call(* println(..))' + public void testWithinCodeBinding1() { + runTest("@withincode() and call(* println(..))"); + } + + // /////////////////////////////////// @ANNOTATION complex tests + + // Using package names for the types (including the annotation) - NO BINDING + public void testPackageNamedTypesNoBinding() { + runTest("packages and no binding"); + } + + // Using package names for the types (including the annotation) - INCLUDES BINDING + public void testPackageNamedTypesWithBinding() { + runTest("packages and binding"); + } + + // declare parents: @Color * implements Serializable + public void testDeclareParentsWithAnnotatedAnyPattern() { + runTest("annotated any pattern"); + } + + // Should error (in a nice way!) on usage of an annotation that isnt imported + public void testAnnotationUsedButNotImported() { + runTest("annotation not imported"); + } + + // Binding with calls/executions of static methods + public void testCallsAndExecutionsOfStaticMethods() { + runTest("binding with static methods"); + } + + // /////////////////////////////////////////////////////////////////////////////// + // annotation binding with ITDs + + public void testAnnotationBindingAndITDs1() { + runTest("simple binding annotation values where itd method is annotated"); + } + + public void testAnnotationBindingAndITDs2() { + runTest("simple binding annotation values where itd field is annotated"); + } + + public void testAnnotationBindingAndITDs3() { + runTest("simple binding annotation values where itd ctor is annotated"); + } + + public void testAnnotationBindingAndITDs4() { + runTest("simple binding annotation values where itd method is annotated via declare"); + } + + public void testAnnotationBindingAndITDs5() { + runTest("simple binding annotation values where itd field is annotated via declare"); + } + + public void testAnnotationBindingAndITDs6() { + runTest("simple binding annotation values where itd field is annotated multiple times via declare"); + } + + public void testAnnotationBindingAndITDs7() { + runTest("simple binding annotation values where itd ctor is annotated via declare"); + } + + public void testAnnotationBindingAndITDs4_asmtest() { + // AsmManager.setReporting("c:/debug.txt",true,true,true,true); + runTest("simple binding annotation values where itd method is annotated via declare"); + + if (getCurrentTest().canRunOnThisVM()) { + AsmManager asm = AsmManager.lastActiveStructureModel; + IHierarchy top = asm.getHierarchy(); + + IProgramElement ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_METHOD, + "declare @method: int A.m() : @Fruit(\"orange\")"); + assertTrue("Couldn't find 'declare @method' element in the tree", ipe != null); + + List l = asm.getRelationshipMap().get(ipe); + assertTrue("Should have a relationship but does not ", l.size() > 0); + + ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_METHOD, + "declare @method: int A.n() : @Fruit(\"banana\")"); + assertTrue("Couldn't find 'declare @method element in the tree", ipe != null); + + l = asm.getRelationshipMap().get(ipe); + assertTrue("Should have a relationship but does not ", l.size() > 0); + + Relationship rel = (Relationship) l.get(0); + assertTrue("Should have 1 target but has " + rel.getTargets().size(), rel.getTargets().size() == 1); + String tgt = (String) rel.getTargets().get(0); + int lineNumber = asm.getHandleProvider().getLineNumberForHandle(tgt); + assertTrue("Should point to line 10 but doesnt: " + lineNumber, lineNumber == 10); + } + } + + public void testAnnotationBindingAndITDs5_asmtest() { + // AsmManager.setReporting("c:/debug.txt",true,true,true,true); + runTest("simple binding annotation values where itd field is annotated via declare"); + + if (getCurrentTest().canRunOnThisVM()) { + AsmManager asm = AsmManager.lastActiveStructureModel; + IHierarchy top = asm.getHierarchy(); + + IProgramElement ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_FIELD, + "declare @field: int A.i : @Fruit(\"orange\")"); + assertTrue("Couldn't find 'declare @type' element in the tree", ipe != null); + + List l = asm.getRelationshipMap().get(ipe); + assertTrue("Should have a relationship but does not ", l.size() > 0); + + ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_FIELD, + "declare @field: java.lang.String A.j : @Fruit(\"banana\")"); + assertTrue("Couldn't find 'declare @field element in the tree", ipe != null); + + l = asm.getRelationshipMap().get(ipe); + assertTrue("Should have a relationship but does not ", l.size() > 0); + + Relationship rel = (Relationship) l.get(0); + assertTrue("Should have 1 target but has " + rel.getTargets().size(), rel.getTargets().size() == 1); + String tgt = (String) rel.getTargets().get(0); + int lineNumber = asm.getHandleProvider().getLineNumberForHandle(tgt); + assertTrue("Should point to line 10 but doesnt: " + lineNumber, lineNumber == 10); + + } + } + + public void testAnnotationBindingAndITDs7_asmtest() { + // AsmManager.setReporting("c:/debug.txt",true,true,true,true); + runTest("simple binding annotation values where itd ctor is annotated via declare"); + + if (getCurrentTest().canRunOnThisVM()) { + + AsmManager asm = AsmManager.lastActiveStructureModel; + IHierarchy top = asm.getHierarchy(); + + IProgramElement ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_CONSTRUCTOR, + "declare @constructor: A.new(java.lang.String) : @Fruit(\"pear\")"); + assertTrue("Couldn't find 'declare @constructor' element in the tree", ipe != null); + + List l = asm.getRelationshipMap().get(ipe); + assertTrue("Should have a relationship but does not ", l.size() > 0); + + ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_CONSTRUCTOR, + "declare @constructor: A.new(int) : @Fruit(\"orange\")"); + assertTrue("Couldn't find 'declare @constructor element in the tree", ipe != null); + + l = asm.getRelationshipMap().get(ipe); + assertTrue("Should have a relationship but does not ", l.size() > 0); + + Relationship rel = (Relationship) l.get(0); + assertTrue("Should have 1 target but has " + rel.getTargets().size(), rel.getTargets().size() == 1); + String tgt = (String) rel.getTargets().get(0); + int lineNumber = asm.getHandleProvider().getLineNumberForHandle(tgt); + assertTrue("Should point to line 10 but doesnt: " + lineNumber, lineNumber == 10); + + } + } + + public void testAnnotationBindingArgsVerifyError_pr92053() { + runTest("AtArgs causes a VerifyError: Unable to pop operand off an empty stack"); + } + +} \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java new file mode 100644 index 000000000..4301a44c0 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationPointcutsTests.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + + +/** + * Tests the use of Annotations in pointcuts + */ +public class AnnotationPointcutsTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AnnotationPointcutsTests.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + // before(): call(@SimpleAnnotation * *(..)) { } + public void test001_usingAnnotationsInPointcuts() { + runTest("annotation matching on call"); + } + + public void test002_AtAnnotationMatching() { + runTest("at annotation matching"); + } + + public void test003_Within_Code() { + runTest("annotations and within(code)"); + } + + public void test004_Within() { + runTest("annotations and within"); + } + + // TODO extra tests + // 3) @annotation on the different join point kinds, matches with inherited annotation + +} \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java new file mode 100644 index 000000000..e1d83a6cc --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +/** +* Tests for @this, @target, @args +*/ +public class AnnotationRuntimeTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AnnotationRuntimeTests.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + +// No longer a limitation ASC 31Jan05 +// public void test001_BindingWithAtTargetAllowed() { +// CompilationResult cR = binaryWeave("TestingAnnotations.jar","BindingWithAtTarget.aj",0,0); +// List errors = cR.getErrorMessages(); +// RunResult rR = run("TestingAnnotations"); +// System.err.println(rR.getStdErr()); +// } + + public void test002_MustHaveRuntimeRetention() { + runTest("must have runtime retention"); + } + + public void test003_InheritableOrNot() { + runTest("inheritable or not"); + } + + public void test004_CantUseinDecEoW() { + runTest("use of @this/target in deow"); + } + + public void test005_ArgsSuite() { + runTest("@args tests"); + } + + public void test006_CantUseinDecEoW() { + runTest("use of @args in deow"); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/Annotations.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/Annotations.java new file mode 100644 index 000000000..f6cea64cb --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/Annotations.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.testing.XMLBasedAjcTestCase; + +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() { + runTest("compiling an annotation"); + } + + public void testCompilingAnnotatedFile() { + runTest("compiling annotated file"); + } + + public void testCompilingUsingWithinAndAnnotationTypePattern() { + runTest("annotations and within (src)"); + } + + /** + * We had a bug where annotations were not present in the output class file for methods + * that got woven. This was due to unpacking bugs in LazyMethodGen. This test compiles + * a simple program then checks the annotations were copied across. + */ + public void testBugWithAnnotationsLostOnWovenMethods() throws ClassNotFoundException { + runTest("losing annotations..."); + if (getCurrentTest().canRunOnThisVM()) { + + JavaClass jc = getClassFrom(ajc.getSandboxDirectory(),"Program"); + Method[] meths = jc.getMethods(); + for (int i = 0; i < meths.length; i++) { + Method method = meths[i]; + if (method.getName().equals("m1")) { + assertTrue("Didn't have annotations - were they lost? method="+method.getName(),method.getAnnotations().length==1); + } + } + } + } + + public void testAnnotatedAnnotations() { + runTest("annotated annotations (@Target)"); + } + + public void testSimpleAnnotatedAspectMembers() { + runTest("simple annotated aspect members"); + } + + public void testAnnotatedAspectMembersWithWrongAnnotationType() { + runTest("simple annotated aspect members with bad target"); + } + + // more implementation work needed before this test passes + public void testAnnotatedITDs() { + runTest("annotated itds"); + } + + public void testAnnotatedITDs2() { + runTest("annotated public itds"); + } + + public void testAnnotatedITDs3() { + runTest("annotated public itds - values"); + } + + public void testAnnotatedITDs4() { + runTest("annotated public itds - multiple complex annotations"); + } + + public void testAnnotatedITDsWithWrongAnnotationType() { + runTest("annotated itds with bad target"); + } + + public void testAnnotatedAdvice() { + runTest("annotated advice"); + } + + public void testAnnotatedAdviceWithWrongAnnotationType() { + runTest("annotated advice with bad target"); + } + + public void testAnnotatedPointcut() { + runTest("annotated pointcut"); + } + + // FIXME asc uncomment this test when parser is opened up +// public void testAnnotatedDeclareStatements() { +// runTest("annotated declare statements"); +// } + + public void testBasicDeclareAnnotation() { + runTest("basic declare annotation parse test"); + } + + public void testAJDKAnnotatingAspects() { + runTest("ajdk: annotating aspects chapter"); + } + + public void testAJDKAnnotatingAspects2() { + runTest("ajdk: annotating aspects chapter, ex 2"); + } + + public void testAnnotationPatterns() { + runTest("ajdk: annotation pattern matching"); + } + + public void testAnnotationTypePatterns() { + runTest("ajdk: annotation type pattern matching"); + } + + public void testAnnotationSigPatterns() { + runTest("ajdk: annotations in sig patterns"); + } + + public void testAnnotationRuntimeMatching() { + runTest("ajdk: runtime annotations"); + } + + public void testAnnotationRetentionChecking() { + runTest("ajdk: @retention checking"); + } + + public void testAnnotationInheritance() { + runTest("ajdk: @inherited"); + } + + public void testAnnotationDEOW() { + runTest("ajdk: deow-ann"); + } + + public void testAnnotationDecp() { + runTest("ajdk: decp-ann"); + } + + public void testAnnotationDecPrecedence() { + runTest("ajdk: dec precedence"); + } + + public void testAnnotationDecAnnotation() { + runTest("ajdk: dec annotation"); + } + + public void testAnnotationsAndITDs() { + runTest("nasty annotation and itds test"); + } + + // helper methods..... + +} \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationsBinaryWeaving.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationsBinaryWeaving.java new file mode 100644 index 000000000..cec4665a7 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/AnnotationsBinaryWeaving.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + + +/** + * Annotations, the rules/tests: + * + * 1. cannot make ITD (C,M or F) on an annotation + * 2. cannot use declare parents to change the super type of an annotation + * 3. cannot use decp to make an annotation type implement an interface + * 4. cannot use decp to dec java.lang.annotation.Annotation as the parent of any type + * 5. cannot extend set of values in an annotation via an ITD like construct + * 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 XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AnnotationsBinaryWeaving.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + // Cannot make ITD (c/m/f) on an annotation + public void test001_itdsOnAnnotationsNotAllowed() { + 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() { + 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() { + runTest("declare parents wildcards matching annotation types"); + } + +} \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/Autoboxing.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/Autoboxing.java new file mode 100644 index 000000000..46a261e24 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/Autoboxing.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +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 XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Autoboxing.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + public void testSimpleBoxing() { + runTest("simple boxing test"); + } + + public void testIntegerBoxing() { + runTest("integer boxing"); + } + + public void testCharacterBoxing() { + runTest("char boxing"); + } + + public void testDoubleBoxing() { + runTest("double boxing"); + } + + public void testFloatBoxing() { + runTest("float boxing"); + } + + public void testShortBoxing() { + runTest("short boxing"); + } + + public void testLongBoxing() { + runTest("long boxing"); + } + + public void testBooleanBoxing() { + runTest("boolean boxing"); + } + + public void testByteBoxing() { + runTest("byte boxing"); + } + + public void testBoxingAfterReturning() { + runTest("boxing in after returning"); + } +// 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/test/java/org/aspectj/systemtest/ajc150/CovarianceTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/CovarianceTests.java new file mode 100644 index 000000000..662394969 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/CovarianceTests.java @@ -0,0 +1,166 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +/* + +class Car {} + +class FastCar extends Car {} + +class Super { + Car getCar() { + return new Car(); + } +} + +class Sub extends Super { + FastCar getCar() { + return new FastCar(); + } +} + +public class CovBaseProgram01 { + public static void main(String[] argv) { + new CovBaseProgram01().run(); + } + + public void run() { + Super instance_super = new Super(); + Sub instance_sub = new Sub(); + + Car c1 = instance_super.getCar(); // Line 26 + Car c2 = instance_sub.getCar(); // Line 27 + } +} + +// Line26: callJPs: call(Car Super.getCar()) +// Line27: callJPs: call(FastCar Sub.getCar()) call(Car Super.getCar()) + + */ + +/** + * Covariance is simply where a type overrides some inherited implementation and narrows the return type. + */ +public class CovarianceTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(CovarianceTests.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + private boolean verbose = false; + + + /** + * call(* getCar()) should match both + */ + public void testCOV001() { + runTest("covariance 1"); + } + + + /** + * call(* Super.getCar()) should match both + * + * This test required a change to the compiler. When we are looking at signatures and comparing them we walk up + * the hierarchy looking for supertypes that declare the same method. The problem is that in the comparison for + * whether to methods are compatible we were including the return type - this meant 'Car getCar()' on Super was + * different to 'FastCar getCar()' on Sub - it thought they were entirely different methods. In fact the return + * type is irrelevant here, we just want to make sure the names and the parameter types are the same - so I + * added a parameterSignature to the Member class that looks like '()' where the full signature looks like + * '()LFastCar;' (which includes the return type). If the full signature comparison fails then it looks at the + * parameter signature - I did it that way to try and preserve some performance. I haven't changed the + * definition of 'signature' for a member as trimming the return type off it seems rather serious ! + * + * What might break: + * - 'matches' can now return true for things that have different return types - I guess whether this is a problem + * depends on what the caller of matches is expecting, their code will have been written before covariance was + * a possibility. All the tests pass so I'll leave it like this for now. + */ + public void testCOV002() { + runTest("covariance 2"); + } + + /** + * call(Car getCar()) should match both + * + * Had to implement proper covariance support here... + */ + public void testCOV003() { + runTest("covariance 3"); + } + + /** + * *** Different base program, where Sub does not extend Super. + * call(Car Super.getCar()) should only match first call to getCar() + */ + public void testCOV004() { + runTest("covariance 4"); + } + + /** + * *** Original base program + * call(Car Super.getCar()) should match both + */ + public void testCOV005() { + runTest("covariance 5"); + } + + /** + * call(Car Sub.getCar()) should not match anything + */ + public void testCOV006() { + runTest("covariance 6"); + } + + /** + * call(Car+ Sub.getCar()) should match 2nd call with xlint for the 1st call + */ + public void testCOV007() { + runTest("covariance 7"); + } + + /** + * *** aspect now contains two pointcuts and two pieces of advice + * call(FastCar getCar()) matches on 2nd call + * call(FastCar Sub.getCar()) matches on 2nd call + */ + public void testCOV008() { + runTest("covariance 8"); + } + + /** + * call(FastCar Super.getCar()) matches nothing + */ + public void testCOV009() { + runTest("covariance 9"); + } + + /** + * call(Car+ getCar()) matches both + */ + public void testCOV010() { + runTest("covariance 10"); + } + + public void testAJDKExamples() { + runTest("ajdk: covariance"); + } +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/DeclareAnnotationTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/DeclareAnnotationTests.java new file mode 100644 index 000000000..28d48c6ca --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/DeclareAnnotationTests.java @@ -0,0 +1,331 @@ +/******************************************************************************* + * Copyright (c) 2005 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement initial implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; +import java.util.List; + +import junit.framework.Test; + +import org.aspectj.asm.AsmManager; +import org.aspectj.asm.IHierarchy; +import org.aspectj.asm.IProgramElement; +import org.aspectj.asm.IRelationship; +import org.aspectj.testing.XMLBasedAjcTestCase; + +public class DeclareAnnotationTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(DeclareAnnotationTests.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + // parsing the various forms of declare @ + public void testDeclareAnnotationParsing() { + runTest("basic declare annotation parse test"); + } + + // declare @type + + // declare @type for one simple annotation on one specific type + public void testAtType_OneAnnotationHittingOneType_Src() { + runTest("declare @type 1"); + } + + // declare @type for one simple annotation to multiple types + public void testAtType_OneAnnotationHittingMultipleTypes_Src() { + runTest("declare @type 2"); + } + + // declare @type for one simple annotation and a pointcut that matches on it + public void testAtType_PointcutMatchingOnDeclaredAnnotation() { + runTest("declare @type - with matching pointcut"); + } + + // binary weaving declare @type, one annotation on one type + public void testAtType_OneAnnotationHittingOneType_Bin() { + runTest("declare @type - binary weaving"); + } + + // an annotation with multiple values (all the primitives and string) + // is declared upon a single type + public void testAtType_ComplexAnnotation_BinWeaving() { + runTest("declare @type - complex annotation - binary weaving"); + } + + public void testAtType_ComplexAnnotation_SrcWeaving() { + runTest("declare @type - complex annotation - source weaving"); + } + + // two annotations are declared on a type + public void testAtType_TwoAnnotationsOnOneType_BinWeaving() { + runTest("declare @type - two annotations hit one type - binary weaving"); + } + + public void testAtType_TwoAnnotationsOnOneType_SrcWeaving() { + runTest("declare @type - two annotations hit one type - source weaving"); + } + + // decp and deca can interact, let's try some variants that should + // result in the same thing + public void testAtType_InteractingWithDeclareParents1_BinWeaving() { + runTest("declare @type - declare parents interactions (order 1) - binary weaving"); + } + + public void testAtType_InteractingWithDeclareParents1_SrcWeaving() { + runTest("declare @type - declare parents interactions (order 1) - source weaving"); + } + + public void testAtType_InteractingWithDeclareParents2_BinWeaving() { + runTest("declare @type - declare parents interactions (order 2) - binary weaving"); + } + + public void testAtType_InteractingWithDeclareParents2_SrcWeaving() { + runTest("declare @type - declare parents interactions (order 2) - source weaving"); + } + + public void testAtType_InteractingWithDeclareParents3_BinWeaving() { + runTest("declare @type - declare parents interactions (order 3) - binary weaving"); + } + + public void testAtType_InteractingWithDeclareParents3_SrcWeaving() { + runTest("declare @type - declare parents interactions (order 3) - source weaving"); + } + + public void testAtType_InteractingWithDeclareParents4_BinWeaving() { + runTest("declare @type - declare parents interactions (order 4) - binary weaving"); + } + + public void testAtType_InteractingWithDeclareParents4_SrcWeaving() { + runTest("declare @type - declare parents interactions (order 4) - source weaving"); + } + + public void testAtType_AnnotatingAlreadyAnnotatedType_BinWeaving() { + runTest("declare @type - annotating an already annotated type - binary weaving"); + } + + public void testAtType_AnnotatingAlreadyAnnotatedType_SrcWeaving() { + runTest("declare @type - annotating an already annotated type - source weaving"); + } + + // testing for error messages when exact type patterns used + // public void testAtType_UsingWrongAnnotationOnAType_BinWeaving() + // runTest("declare @type - annotations with different targets - binary weaving"); + // } + public void testAtType_UsingWrongAnnotationOnAType_SrcWeaving() { + runTest("declare @type - annotations with different targets - source weaving"); + } + + // testing for the lint message when non exact patterns used + // public void testAtType_UsingWrongAnnotationOnAType_TypeSpecifiedByPattern_BinWeaving() { + // runTest("declare @type - annotations with different targets (using type patterns) - binary weaving"); + // } + public void testAtType_UsingWrongAnnotationOnAType_TypeSpecifiedByPattern_SrcWeaving() { + runTest("declare @type - annotations with different targets (using type patterns) - source weaving"); + } + + // testing how multiple decAtType/decps interact when they rely on each other + public void testAtType_ComplexDecpDecAtTypeInteractions_BinWeaving() { + runTest("declare @type - complex decp decAtType interactions - binary weaving"); + } + + public void testAtType_ComplexDecpDecAtTypeInteractions_SrcWeaving() { + runTest("declare @type - complex decp decAtType interactions - source weaving"); + } + + public void testAtType_PuttingIncorrectAnnosOnTypes_SrcWeaving() { + runTest("declare @type - trying to put annotation targetting annos on normal types - source weaving"); + } + + public void testAtType_PuttingIncorrectAnnosOnTypes_BinWeaving() { + runTest("declare @type - trying to put annotation targetting annos on normal types - binary weaving"); + } + + public void testAtType_PuttingIncorrectAnnosOnTypesWithPatterns_SrcWeaving() { + runTest("declare @type - trying to put annotation targetting annos on normal types (uses pattern) - source weaving"); + } + + public void testAtType_PuttingIncorrectAnnosOnTypesWithPatterns_BinWeaving() { + runTest("declare @type - trying to put annotation targetting annos on normal types (uses pattern) - binary weaving"); + } + + // I think this fails because of a freaky JDT compiler bug ... + // public void testAtType_UsingClassOrEnumElementValuesInAnnotations_SrcWeaving() { + // runTest("declare @type - covering enum and class element values - source weaving"); + // } + + public void testAtType_UsingClassOrEnumElementValuesInAnnotations_BinWeaving() { + runTest("declare @type - covering enum and class element values - binary weaving"); + } + + // /////////////////////////////////////////////////////////////////////////////// + // declare @field + + public void testAtField_SimpleSource() { + runTest("declare @field - simple source weaving"); + } + + public void testAtField_SimpleBinary() { + runTest("declare @field - simple binary weaving"); + } + + // lint warning + public void testAtField_TwoTheSameOnOneSource() { + runTest("declare @field - two the same on one - source weaving"); + } + + // lint warning + public void testAtField_TwoTheSameOnOneBinary() { + runTest("declare @field - two the same on one - binary weaving"); + } + + public void testAtField_TwoDifferentOnOneSource() { + runTest("declare @field - two different on one - source weaving"); + } + + public void testAtField_TwoDifferentOnOneBinary() { + runTest("declare @field - two different on one - binary weaving"); + } + + public void testAtField_WrongTargetSource() { + runTest("declare @field - wrong target - source weaving"); + } + + // Can't do a test like this - as verification of the declare @ is + // done when the aspect is first compiled. + // public void testAtField_WrongTargetBinary() { + // runTest("declare @field - wrong target - binary weaving"); + // } + + public void testAtField_RightTargetSource() { + runTest("declare @field - right target - source weaving"); + } + + public void testAtField_RightTargetBinary() { + runTest("declare @field - right target - binary weaving"); + } + + public void testAtField_RecursiveSource() { + runTest("declare @field - recursive application - source weaving"); + } + + public void testAtField_RecursiveBinary() { + runTest("declare @field - recursive application - binary weaving"); + } + + public void testAtField_RecursiveOtherOrderSource() { + runTest("declare @field - recursive application (other order) - source weaving"); + } + + public void testAtField_RecursiveOtherOrderBinary() { + runTest("declare @field - recursive application (other order) - binary weaving"); + } + + // /////////////////////////////////////////////////////////////////////////////// + // declare @method + + public void testAtMethod_SimpleSource() { + runTest("declare @method - simple source weaving"); + } + + public void testAtMethod_SimpleBinary() { + runTest("declare @method - simple binary weaving"); + } + + // /////////////////////////////////////////////////////////////////////////////// + // declare @constructor + + public void testAtCtor_SimpleSource() { + runTest("declare @constructor - simple source weaving"); + } + + public void testAtCtor_SimpleBinary() { + runTest("declare @constructor - simple binary weaving"); + } + + // /////////////////////////////////////////////////////////////////////////////// + // declare @method @constructor + + public void testAtMethodCtor_WrongTargetSource() { + runTest("declare @method @ctor - wrong target - source weaving"); + } + + public void testAtMethodCtor_RightTargetSource() { + runTest("declare @method @ctor - right target - source weaving"); + } + + public void testAtMethodCtor_RightTargetBinary() { + runTest("declare @method @ctor - right target - binary weaving"); + } + + // lint warning + public void testAtMethodCtor_TwoTheSameOnOneSource() { + runTest("declare @method @ctor - two the same on one - source weaving"); + } + + // lint warning + public void testAtMethodCtor_TwoTheSameOnOneBinary() { + runTest("declare @method @ctor - two the same on one - binary weaving"); + } + + public void testAtMethodCtor_TwoDifferentOnOneSource() { + runTest("declare @method @ctor - two different on one - source weaving"); + } + + public void testAtMethodCtor_TwoDifferentOnOneBinary() { + runTest("declare @method @ctor - two different on one - binary weaving"); + } + + // to debug this test, uncomment the first line which will give you a nice + // dump of the structure model in c:/debug.txt + public void testStructureModel() { + // AsmManager.setReporting("c:/debug.txt",true,true,true,true); + runTest("declare all annotations on one class - source weaving"); + + if (getCurrentTest().canRunOnThisVM()) { + IHierarchy top = AsmManager.lastActiveStructureModel.getHierarchy(); + + IProgramElement ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_TYPE, + "declare @type: p.q.DeathByAnnotations : @Colored(\"red\")"); + assertTrue("Couldn't find 'declare @type' element in the tree", ipe != null); + + List l = AsmManager.lastActiveStructureModel.getRelationshipMap().get(ipe); + assertTrue("Should have a relationship but does not ", l != null && l.size() > 0); + + ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_METHOD, + "declare @method: * m*(..) : @Fruit(\"tomato\")"); + assertTrue("Couldn't find 'declare @method element in the tree", ipe != null); + + l = AsmManager.lastActiveStructureModel.getRelationshipMap().get(ipe); + assertTrue("Should have a relationship but does not ", l.size() > 0); + + ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_CONSTRUCTOR, + "declare @constructor: p.q.DeathByAnnotations.new(..) : @Fruit(\"tomato\")"); + assertTrue("Couldn't find 'declare @constructor element in the tree", ipe != null); + l = AsmManager.lastActiveStructureModel.getRelationshipMap().get(ipe); + assertTrue("Should have a relationship but does not ", l.size() > 0); + + ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_FIELD, + "declare @field: * p.q.DeathByAnnotations.* : @Material(\"wood\")"); + assertTrue("Couldn't find 'declare @field element in the tree", ipe != null); + l = AsmManager.lastActiveStructureModel.getRelationshipMap().get(ipe); + assertTrue("Should have a relationship but does not ", l.size() > 0); + } + } + + public void testDeclareTypeMisspelled() { + runTest("declare @Type (should be @type)"); + } + +} \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/Enums.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/Enums.java new file mode 100644 index 000000000..7f7f8bac4 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/Enums.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + + +/** + * Enums, the rules/tests: + * + * 1. cannot make ITDC on an enum + * 2. cannot make ITDM or ITDF on an enum + * 3. cannot use declare parents to change the super type of an enum + * 4. cannot use decp to make an enum type implement an interface + * 5. cannot use decp to dec java.lang.Enum as the parent of any type + * 6. cannot extend set of values in an enum via an ITD like construct + * 7. Compilation error if you explicitly identify an Enum type. + * 8. Lint warning if a non-explicit type pattern would match an enum type. + * + */ +public class Enums extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(Enums.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + // Cannot make ITDC on an enum + public void test001_itdcsOnEnumNotAllowed() { + runTest("cant itd constructor on enum"); + } + + // Cannot make ITDM or ITDF on an enum + public void test002_itdFieldOrMethodOnEnumNotAllowed() { + 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() { + 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() { + 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/test/java/org/aspectj/systemtest/ajc150/GenericITDsDesign.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericITDsDesign.java new file mode 100644 index 000000000..6209298c1 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericITDsDesign.java @@ -0,0 +1,254 @@ +package org.aspectj.systemtest.ajc150; + +import java.io.File; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; + +import junit.framework.Test; + +import org.aspectj.apache.bcel.classfile.Attribute; +import org.aspectj.apache.bcel.classfile.Field; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Signature; +import org.aspectj.apache.bcel.util.ClassPath; +import org.aspectj.apache.bcel.util.SyntheticRepository; +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.tools.ajc.Ajc; +import org.aspectj.weaver.ConcreteTypeMunger; +import org.aspectj.weaver.CrosscuttingMembers; +import org.aspectj.weaver.ReferenceType; +import org.aspectj.weaver.ResolvedMember; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.ResolvedTypeMunger; +import org.aspectj.weaver.TypeVariable; +import org.aspectj.weaver.TypeVariableReference; +import org.aspectj.weaver.World; +import org.aspectj.weaver.bcel.BcelTypeMunger; +import org.aspectj.weaver.bcel.BcelWorld; + +public class GenericITDsDesign extends XMLBasedAjcTestCase { + + private World recentWorld; + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(GenericITDsDesign.class); + } + + @Override + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + private void verifyDebugString(ResolvedMember theMember, String string) { + assertTrue("Expected '" + string + "' but found " + theMember.toDebugString(), theMember.toDebugString().equals(string)); + } + + public static JavaClass getClassFromDisk(Ajc ajc, String classname) { + try { + ClassPath cp = new ClassPath(ajc.getSandboxDirectory() + File.pathSeparator + System.getProperty("java.class.path")); + SyntheticRepository sRepos = SyntheticRepository.getInstance(cp); + return sRepos.loadClass(classname); + } catch (ClassNotFoundException e) { + fail("Couldn't find class " + classname + " in the sandbox directory."); + } + return null; + } + + public static Signature getClassSignature(Ajc ajc, String classname) { + JavaClass clazz = getClassFromDisk(ajc, classname); + Signature sigAttr = null; + Attribute[] attrs = clazz.getAttributes(); + for (int i = 0; i < attrs.length; i++) { + Attribute attribute = attrs[i]; + if (attribute.getName().equals("Signature")) { + sigAttr = (Signature) attribute; + } + } + return sigAttr; + } + + // Check the signature attribute on a class is correct + public static void verifyClassSignature(Ajc ajc, String classname, String sig) { + Signature sigAttr = getClassSignature(ajc, classname); + assertTrue("Failed to find signature attribute for class " + classname, sigAttr != null); + assertTrue("Expected signature to be '" + sig + "' but was '" + sigAttr.getSignature() + "'", sigAttr.getSignature() + .equals(sig)); + } + + public List getTypeMunger(String classname) { + ClassPath cp = new ClassPath(ajc.getSandboxDirectory() + File.pathSeparator + System.getProperty("java.class.path")); + recentWorld = new BcelWorld(cp.toString()); + ReferenceType resolvedType = (ReferenceType) recentWorld.resolve(classname); + CrosscuttingMembers cmembers = resolvedType.collectCrosscuttingMembers(true); + List tmungers = cmembers.getTypeMungers(); + return tmungers; + } + + private BcelTypeMunger getMungerFromLine(String classname, int linenumber) { + List allMungers = getTypeMunger(classname); + for (Iterator iter = allMungers.iterator(); iter.hasNext();) { + BcelTypeMunger element = (BcelTypeMunger) iter.next(); + if (element.getMunger().getSourceLocation().getLine() == linenumber) { + return element; + } + } + for (Iterator iter = allMungers.iterator(); iter.hasNext();) { + BcelTypeMunger element = (BcelTypeMunger) iter.next(); + System.err.println("Line: " + element.getMunger().getSourceLocation().getLine() + " > " + element); + } + fail("Couldn't find a type munger from line " + linenumber + " in class " + classname); + return null; + } + + public Hashtable getMeTheFields(String classname) { + JavaClass theClass = getClassFromDisk(ajc, classname); + Hashtable retval = new Hashtable<>(); + org.aspectj.apache.bcel.classfile.Field[] fs = theClass.getFields(); + for (int i = 0; i < fs.length; i++) { + Field field = fs[i]; + retval.put(field.getName(), field); + } + return retval; + } + + /* + * test plan: 1. Serializing and recovering 'default bounds' type variable info: a. methods b. fields c. ctors 2. Serializing + * and recovering 'extends' with a class bounded type variable info: a. methods b. fields c. ctors 3. Serializing and recovering + * 'extends' with an interface bounded type variable info: a. methods b. fields c. ctors 4. Multiple interface bounds a. methods + * b. fields c. ctors 5. wildcard bounds '? extends/? super' a. methods b. fields c. ctors 6. using type variables in an ITD + * from the containing aspect, no bounds a. methods b. fields c. ctors + */ + + // Verify: a) After storing it in a class file and recovering it (through deserialization), we can see the type + // variable and that the parameter refers to the type variable. + public void testDesignA() { + runTest("generic itds - design A"); + BcelTypeMunger theBcelMunger = getMungerFromLine("X", 5); + ResolvedType typeC = recentWorld.resolve("C"); + ResolvedTypeMunger rtMunger = theBcelMunger.getMunger(); + ResolvedMember theMember = rtMunger.getSignature(); + // Let's check all parts of the member + assertTrue("Declaring type should be C: " + theMember, theMember.getDeclaringType().equals(typeC)); + + TypeVariable tVar = theMember.getTypeVariables()[0]; + TypeVariableReference tvrt = (TypeVariableReference) theMember.getParameterTypes()[0]; + + theMember.resolve(recentWorld); // resolution will join the type variables together (i.e. make them refer to the same + // instance) + + tVar = theMember.getTypeVariables()[0]; + tvrt = (TypeVariableReference) theMember.getParameterTypes()[0]; + + assertTrue( + "Post resolution, the type variable in the parameter should be identical to the type variable declared on the member", + tVar == tvrt.getTypeVariable()); + } + + // Verify: bounds are preserved and accessible after serialization + public void testDesignB() { + runTest("generic itds - design B"); + BcelTypeMunger theBcelMunger = getMungerFromLine("X", 7); + ResolvedTypeMunger rtMunger = theBcelMunger.getMunger(); + ResolvedMember theMember = rtMunger.getSignature(); + verifyDebugString(theMember, " void C.m0(T)"); + + theBcelMunger = getMungerFromLine("X", 9); + rtMunger = theBcelMunger.getMunger(); + theMember = rtMunger.getSignature(); + verifyDebugString(theMember, " void C.m1(Q)"); + + theBcelMunger = getMungerFromLine("X", 11); + rtMunger = theBcelMunger.getMunger(); + theMember = rtMunger.getSignature(); + verifyDebugString(theMember, " void C.m2(R)"); + } + + // Verify: a) multiple type variables work. + // b) type variables below the 'top level' (e.g. List) are preserved. + public void testDesignC() { + runTest("generic itds - design C"); + BcelTypeMunger theBcelMunger = getMungerFromLine("X", 9); + // System.err.println(theBcelMunger.getMunger().getSignature().toDebugString()); + verifyDebugString(theBcelMunger.getMunger().getSignature(), " void C.m0(T, Q)"); + + theBcelMunger = getMungerFromLine("X", 11); + // System.err.println(theBcelMunger.getMunger().getSignature().toDebugString()); + verifyDebugString(theBcelMunger.getMunger().getSignature(), " java.util.List C.m1(B, java.util.Collection)"); + } + + // Verify: a) sharing type vars with some target type results in the correct variable names in the serialized form + public void testDesignD() { + runTest("generic itds - design D"); + BcelTypeMunger theBcelMunger = getMungerFromLine("X", 9); + // System.err.println(theBcelMunger.getMunger().getSignature().toDebugString()); + verifyDebugString(theBcelMunger.getMunger().getSignature(), "void C.m0(R)"); + + theBcelMunger = getMungerFromLine("X", 11); + // System.err.println(theBcelMunger.getMunger().getSignature().toDebugString()); + verifyDebugString(theBcelMunger.getMunger().getSignature(), + "java.util.List C.m0(Q, int, java.util.List>)"); + } + + // Verify: a) for fields, sharing type vars with some target type results in the correct entries in the class file + public void testDesignE() { + runTest("generic itds - design E"); + BcelTypeMunger theBcelMunger = getMungerFromLine("X", 9); + verifyDebugString(theBcelMunger.getMunger().getSignature(), "java.util.List C.ln"); + assertTrue("Expected to find \"Z\": " + theBcelMunger.getTypeVariableAliases(), theBcelMunger.getTypeVariableAliases() + .contains("Z")); + + theBcelMunger = getMungerFromLine("X", 11); + verifyDebugString(theBcelMunger.getMunger().getSignature(), "Q C.n"); + assertTrue("Expected to find \"Q\": " + theBcelMunger.getTypeVariableAliases(), theBcelMunger.getTypeVariableAliases() + .contains("Q")); + } + + // Verifying what gets into a class targetted with a field ITD + public void testDesignF() { + runTest("generic itds - design F"); + Hashtable fields = getMeTheFields("C"); + + // Declared in src as: List C.list1; and List C.list2; + Field list1 = (Field) fields.get("list1");// ajc$interField$$list1"); + assertTrue("Field list1 should be of type 'Ljava/util/List;' but is " + list1.getSignature(), list1.getSignature().equals( + "Ljava/util/List;")); + Field list2 = (Field) fields.get("list2");// ajc$interField$$list1"); + assertTrue("Field list2 should be of type 'Ljava/util/List;' but is " + list2.getSignature(), list2.getSignature().equals( + "Ljava/util/List;")); + + // Declared in src as: String C.field1; and Q C.field2; + // bound for second field collapses to Object + Field field1 = (Field) fields.get("field1");// ajc$interField$$field1"); + assertTrue("Field list1 should be of type 'Ljava/lang/String;' but is " + field1.getSignature(), field1.getSignature() + .equals("Ljava/lang/String;")); + Field field2 = (Field) fields.get("field2");// ajc$interField$$field2"); + assertTrue("Field list2 should be of type 'Ljava/lang/Object;' but is " + field2.getSignature(), field2.getSignature() + .equals("Ljava/lang/Object;")); + } + + // Verifying what gets into a class when an interface it implements was targetted with a field ITD + public void testDesignG() { + runTest("generic itds - design G"); + Hashtable fields = getMeTheFields("C"); + + // The ITDs are targetting an interface. That interface is generic and is parameterized with + // 'String' when implemented in the class C. This means the fields that make it into C should + // be parameterized with String also. + + // List I.ln; and Q I.n; + // Field field1 = (Field)fields.get("ajc$interField$X$I$ln"); + // assertTrue("Field list1 should be of type 'Ljava/util/List;' but is "+field1.getSignature(), + // field1.getSignature().equals("Ljava/util/List;")); + // Field field2 = (Field)fields.get("ajc$interField$X$I$n"); + // assertTrue("Field list2 should be of type 'Ljava/lang/String;' but is "+field2.getSignature(), + // field2.getSignature().equals("Ljava/lang/String;")); + } + + // // Verify: a) sharing type vars with some target type results in the correct variable names in the serialized form + // public void testDesignE() { + // runTest("generic itds - design E"); + // + // } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericsTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericsTests.java new file mode 100644 index 000000000..907e3d7a5 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/GenericsTests.java @@ -0,0 +1,996 @@ +package org.aspectj.systemtest.ajc150; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.HashSet; +import java.util.Set; + +import org.aspectj.apache.bcel.classfile.Attribute; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Signature; +import org.aspectj.apache.bcel.util.ClassPath; +import org.aspectj.apache.bcel.util.SyntheticRepository; +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.tools.ajc.Ajc; +import org.aspectj.util.LangUtil; + +import junit.framework.Test; + +public class GenericsTests extends XMLBasedAjcTestCase { + + /*========================================== + * Generics test plan for pointcuts. + * + * handler PASS + * - does not permit type var spec + * - does not permit generic type (fail with type not found) + * - does not permit parameterized types + * if PASS + * - does not permit type vars + * cflow PASS + * - does not permit type vars + * cflowbelow PASS + * - does not permit type vars + * @this PASS + * - does not permit type vars PASS + * - does not permit parameterized type PASS + * @target PASS + * - does not permit type vars PASS + * - does not permit parameterized type PASS + * @args PASS + * - does not permit type vars PASS + * - does not permit parameterized type PASS + * @annotation PASS + * - does not permit type vars PASS + * - does not permit parameterized type PASS + * @within, @within code - as above PASS + * annotation type pattern with generic and parameterized types PASS + * - just make sure that annotation interfaces can never be generic first! VERIFIED + * - @Foo should fail PASS + * - @Foo should fail PASS + * - @(Foo || Bar) should fail DEFERRED (not critical) + * staticinitialization PASS + * - error on parameterized type PASS N/A + * - permit parameterized type + PASS N/A + * - matching with parameterized type + N/A + * - wrong number of parameters in parameterized type PASS N/A + * - generic type with one type parameter N/A + * - generic type with n type parameters N/A + * - generic type with bounds [extends, extends + i/f's] N/A + * - generic type with wrong number of type params N/A + * - wildcards in bounds N/A + * within PASS + * - as above, but allows parameterized type (disallowed in simplified plan) + * - wildcards in type parameters N/A + * this PASS + * - no type vars + * - parameterized types - disallowed in simplification plan + * - implements + * - instanceof + * target PASS + * - as this + * args + * - args(List) matches List, List, List PASS + * - args(List) -> invalid absolute type T + * - args(List) matches List but not List PASS + * - args(List) matches List with unchecked warning PASS + * - args(List) matches List with unchecked warning PASS + * - args(List) matches List, List, List with unchecked warning PASS + * matches List PASS, List PASS(with warning) + * - args(List) matches List, List, List, ... PASS + * - args(List, List, not List PASS + * matches List, List with unchecked warning PASS + * - args(List) matches List, List + * does not match List + * matches List, List with unchecked warning + * matches List + * matches List with unchecked warning + * matches List with unchecked warning + * get & set PASS + * - parameterized declaring type PASS + * - generic declaring type PASS + * - field type is type variable PASS + * - field type is parameterized PASS + * initialization, preinitialization PASS + * - generic declaring type PASS + * - type variables as params PASS + * - parameterized types as params PASS + * - no join points for init, preinit of parameterized types (as per staticinit) PASS + * withincode PASS + * - no generic or parameterized declaring type patterns PASS + * - no parameterized throws patterns PASS + * - return type as type variable PASS + * - return type as parameterized type PASS + * - parameter as type variable PASS + * - parameter as parameterized type PASS + * - no join points within bridge methods PASS + * execution PASS + * - no generic or parameterized declaring type patterns PASS + * - no parameterized throws patterns PASS + * - return type as type variable PASS + * - return type as parameterized type PASS + * - parameter as type variable PASS + * - parameter as parameterized type PASS + * - no join points for bridge methods PASS + * call PASS + * - no generic or parameterized declaring type patterns PASS + * - no parameterized throws patterns PASS + * - return type as type variable PASS + * - return type as parameterized type PASS + * - parameter as type variable PASS + * - parameter as parameterized type PASS + * - calls to a bridge methods PASS + * after throwing - can't use parameterized type pattern + * after returning - same as for args + */ + + /* ========================================== + * Generics test plan for ITDs. + * + * think about: + * - 'visibility' default/private/public + * - static/nonstatic + * - parameterized ITDs (methods/ctors/fields) + * - ITD target: interface/class/aspect + * - multiple type variables + * - constructor ITDs, method ITDs + * - ITDs sharing type variables with generic types + * - relating to above point, this makes generic ITD fields possible + * - signature attributes for generic ITDs (required? required only for public ITDs?) + * - binary weaving when target type changes over time (might start out 'simple' then sometime later be 'generic') + * - bridge methods - when to create them + * - multiple 'separate' ITDs in a file that share a type variable by 'name' + * - wildcards '?' 'extends' 'super' '&' + * - do type variables assigned to members need to persist across serialization + * - recursive type variable definitions eg. > + * - super/extends with parameterized types > + * - multiple ITDs defined in one type that reuse type variable letters, specifying different bounds + * - generic aspects + * + * PASS parsing generic ITDs + * PASS generic methods + * PASS generic constructors + * PASS ITD visibility + * PASS static/nonstatic + * PASS parameterizedITDs + * PASS differing targets (interface/class/aspect) + * PASS multiple type variables in an ITD + * PASS parsing ITDs that share type variables with target type + * PASS using type variables from the target type in your field ITD + * PASS using type variables from the target type in your method ITD (but no type vars of your own) + * PASS using type variables from the target type in your ctor ITD (but no type vars of your own) + * PASS using type variables from the target type and having your own too (methods) + * PASS using type variables from the target type and having your own too (ctors) + * PASS reusing type variable letter but differing spec across multiple ITDs in one aspect + * PASS wildcards + * PASS recursive type variable definitions + * PASS generic aspects + * PASS parameterizing ITDs with type variables + * PASS using type variables from the target type in your *STATIC* ITD (field/method/ctor) (error scenario) + * PASS basic binary weaving of generic itds + * + * TODO generic aspect binary weaving (or at least multi source file weaving) + * TODO binary weaving with changing types (moving between generic and simple) + * TODO bridge method creation (also relates to covariance overrides..) + * TODO exotic class/interface bounds ('? extends List','? super anything') + * TODO signature attributes for generic ITDs (public only?) + * + */ + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(GenericsTests.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + public void testITDReturningParameterizedType() { + runTest("ITD with parameterized type"); + } + + public void testPR91267_1() { + runTest("NPE using generic methods in aspects 1"); + } + + public void testParameterizedTypeAndAroundAdvice_PR115250() { + runTest("parameterized type and around advice"); + } + + public void testParameterizedTypeAndAroundAdvice_PR115250_2() { + runTest("parameterized type and around advice - 2"); + } + + public void testPR91267_2() { + runTest("NPE using generic methods in aspects 2"); + } + + public void testPR91053() { + runTest("Generics problem with Set"); + } + + public void testPR87282() { + runTest("Compilation error on generic member introduction"); + } + + public void testGenericsOverrides_1() { runTest("generics and ITD overrides - 1"); } + public void testGenericsOverrides_2() { runTest("generics and ITD overrides - 2"); } + public void testGenericsOverrides_3() { runTest("generics and ITD overrides - 3"); } + public void testGenericsOverrides_4() { runTest("generics and ITD overrides - 4"); } + + + public void testSelfBoundGenerics_pr117296() { + runTest("self bounding generic types"); + } + + public void testPR88606() { + runTest("Parameterized types on introduced fields not correctly recognized"); + } + + public void testPR97763() { + runTest("ITD method with generic arg"); + } + + public void testGenericsBang_pr95993() { + runTest("NPE at ClassScope.java:660 when compiling generic class"); + } + + + // generic aspects + public void testPR96220_GenericAspects1() {runTest("generic aspects - 1");} + public void testPR96220_GenericAspects2() {runTest("generic aspects - 2");} + public void testPR96220_GenericAspects3() {runTest("generic aspects - 3");} + public void testGenericAspects4() {runTest("generic aspects - 4");} + public void testGenericAspects5() {runTest("generic aspects - 5 (ajdk)");} // in separate files + public void testGenericAspects6() {runTest("generic aspects - 6 (ajdk)");} // all in one file + public void testTypeVariablesInDeclareWarning() { runTest("generic aspect with declare warning using type vars");} + public void testTypeVariablesInExecutionAdvice() { runTest("generic aspect with execution advice using type vars");} + public void testTypeVariablesInAnonymousPointcut() { runTest("generic aspect with anonymous pointcut");} + public void testDeclareParentWithParameterizedInterface() { + runTest("generic aspect declare parents"); + } + public void testDeclareSoftInGenericAspect() { + runTest("generic aspect declare soft"); + } + + ////////////////////////////////////////////////////////////////////////////// + // Generic/Parameterized ITDs - includes scenarios from developers notebook // + ////////////////////////////////////////////////////////////////////////////// + + + // parsing of generic ITD members + public void testParseItdNonStaticMethod() {runTest("Parsing generic ITDs - 1");} + public void testParseItdStaticMethod() {runTest("Parsing generic ITDs - 2");} + public void testParseItdCtor() {runTest("Parsing generic ITDs - 3");} + public void testParseItdComplexMethod() {runTest("Parsing generic ITDs - 4");} + public void testParseItdSharingVars1() {runTest("Parsing generic ITDs - 5");} + public void testParseItdSharingVars2() {runTest("Parsing generic ITDs - 6");} + + + // non static + public void testGenericMethodITD1() {runTest("generic method itd - 1");} // ... (List) + public void testGenericMethodITD2() {runTest("generic method itd - 2");} // ... (List) called incorrectly + public void testGenericMethodITD3() {runTest("generic method itd - 3");} // ... (List,List) + public void testGenericMethodITD4() {runTest("generic method itd - 4");} // ... (List,List) + public void testGenericMethodITD5() {runTest("generic method itd - 5");} // ... (List,List) called incorrectly + public void testGenericMethodITD6() {runTest("generic method itd - 6");} // ... (List) + public void testGenericMethodITD7() {runTest("generic method itd - 7"); } // ... (List,List) + public void testGenericMethodITD8() {runTest("generic method itd - 8"); } // ... (List,List) called incorrectly + public void testGenericMethodITD9() {runTest("generic method itd - 9"); } // > ... (List) + public void testGenericMethodITD10() {runTest("generic method itd - 10");} // > ... (List) called incorrectly + public void testGenericMethodITD11() {runTest("generic method itd - 11");} // > ... (List) + public void testGenericMethodITD12() {runTest("generic method itd - 12");} // > ... (List) called incorrectly + public void testGenericMethodITD13() {runTest("generic method itd - 13");} // > ... (List) called correctly in a clever way ;) + public void testGenericMethodITD14() {runTest("generic method itd - 14");} // > ... (List) called incorrectly in a clever way + public void testGenericMethodITD15() {runTest("generic method itd - 15");} // > ... (List) called correctly in a clever way + + + + // generic ctors + public void testGenericCtorITD1() {runTest("generic ctor itd - 1");} // new(List) + public void testGenericCtorITD2() {runTest("generic ctor itd - 2");} // new(List,List) + public void testGenericCtorITD3() {runTest("generic ctor itd - 3");} // new(List,Comparator) + + + // parameterized ITDs + public void testParameterizedMethodITD1() {runTest("parameterized method itd - 1");} // (List) + public void testParameterizedMethodITD2() {runTest("parameterized method itd - 2");} // (List) called incorrectly + public void testParameterizedMethodITD3() {runTest("parameterized method itd - 3");} // (List) called incorrectly + public void testParameterizedMethodITD4() {runTest("parameterized method itd - 4");} // (List) + + + // differing visibilities + public void testPublicITDs() {runTest("public itds");} + public void testPublicITDsErrors() {runTest("public itds with errors");} + public void testPrivateITDs() {runTest("private itds");} + public void testPackageITDs() {runTest("package itds");} + + + // targetting different types (interface/class/aspect) + public void testTargettingInterface() {runTest("targetting interface");} + public void testTargettingAspect() {runTest("targetting aspect");} + public void testTargettingClass() {runTest("targetting class");} + + + + // using a type variable from the target generic type in your ITD + public void testFieldITDsUsingTargetTypeVars1() {runTest("field itd using type variable from target type - 1");} + public void testFieldITDsUsingTargetTypeVars2() {runTest("field itd using type variable from target type - 2");} + public void testFieldITDsUsingTargetTypeVars3() {runTest("field itd using type variable from target type - 3");} + public void testFieldITDsUsingTargetTypeVars4() {runTest("field itd using type variable from target type - 4");} + public void testFieldITDsUsingTargetTypeVars5() {runTest("field itd using type variable from target type - 5");} + public void testFieldITDsUsingTargetTypeVars6() {runTest("field itd using type variable from target type - 6");} + public void testFieldITDsUsingTargetTypeVars7() {runTest("field itd using type variable from target type - 7");} + public void testFieldITDsUsingTargetTypeVars8() {runTest("field itd using type variable from target type - 8");} + public void testFieldITDsUsingTargetTypeVars9() {runTest("field itd using type variable from target type - 9");} + public void testFieldITDsUsingTargetTypeVars10(){runTest("field itd using type variable from target type -10");} + public void testFieldITDsUsingTargetTypeVars11(){runTest("field itd using type variable from target type -11");} + public void testFieldITDsUsingTargetTypeVars12(){runTest("field itd using type variable from target type -12");} + public void testFieldITDsUsingTargetTypeVars13(){runTest("field itd using type variable from target type -13");} + public void testFieldITDsUsingTargetTypeVars14(){runTest("field itd using type variable from target type -14");} + public void testFieldITDsUsingTargetTypeVars15(){runTest("field itd using type variable from target type -15");} + public void testFieldITDsUsingTargetTypeVars16(){runTest("field itd using type variable from target type -16");} + public void testFieldITDsUsingTargetTypeVars17(){runTest("field itd using type variable from target type -17");} + + + public void testMethodITDsUsingTargetTypeVarsA1() {runTest("method itd using type variable from target type - A1");} + public void testMethodITDsUsingTargetTypeVarsA2() {runTest("method itd using type variable from target type - A2");} + public void testMethodITDsUsingTargetTypeVarsA3() {runTest("method itd using type variable from target type - A3");} + public void testMethodITDsUsingTargetTypeVarsA4() {runTest("method itd using type variable from target type - A4");} + public void testMethodITDsUsingTargetTypeVarsB1() {runTest("method itd using type variable from target type - B1");} + public void testMethodITDsUsingTargetTypeVarsC1() {runTest("method itd using type variable from target type - C1");} + public void testMethodITDsUsingTargetTypeVarsD1() {runTest("method itd using type variable from target type - D1");} + public void testMethodITDsUsingTargetTypeVarsE1() {runTest("method itd using type variable from target type - E1");} + public void testMethodITDsUsingTargetTypeVarsF1() {runTest("method itd using type variable from target type - F1");} + public void testMethodITDsUsingTargetTypeVarsG1() {runTest("method itd using type variable from target type - G1");} + public void testMethodITDsUsingTargetTypeVarsH1() {runTest("method itd using type variable from target type - H1");} + public void testMethodITDsUsingTargetTypeVarsI1() {runTest("method itd using type variable from target type - I1");} + public void testMethodITDsUsingTargetTypeVarsI2() {runTest("method itd using type variable from target type - I2");} + public void testMethodITDsUsingTargetTypeVarsJ1() {runTest("method itd using type variable from target type - J1");} + public void testMethodITDsUsingTargetTypeVarsK1() {runTest("method itd using type variable from target type - K1");} + public void testMethodITDsUsingTargetTypeVarsL1() {runTest("method itd using type variable from target type - L1");} + public void testMethodITDsUsingTargetTypeVarsM1() {runTest("method itd using type variable from target type - M1");} + public void testMethodITDsUsingTargetTypeVarsM2() {runTest("method itd using type variable from target type - M2");} + public void testMethodITDsUsingTargetTypeVarsN1() {runTest("method itd using type variable from target type - N1");} + public void testMethodITDsUsingTargetTypeVarsO1() {runTest("method itd using type variable from target type - O1");} + public void testMethodITDsUsingTargetTypeVarsO2() {runTest("method itd using type variable from target type - O2");} + public void testMethodITDsUsingTargetTypeVarsP1() {runTest("method itd using type variable from target type - P1");} + public void testMethodITDsUsingTargetTypeVarsQ1() {runTest("method itd using type variable from target type - Q1");} + + public void testCtorITDsUsingTargetTypeVarsA1() {runTest("ctor itd using type variable from target type - A1");} + public void testCtorITDsUsingTargetTypeVarsB1() {runTest("ctor itd using type variable from target type - B1");} + public void testCtorITDsUsingTargetTypeVarsC1() {runTest("ctor itd using type variable from target type - C1");} + public void testCtorITDsUsingTargetTypeVarsD1() {runTest("ctor itd using type variable from target type - D1");} + public void testCtorITDsUsingTargetTypeVarsE1() {runTest("ctor itd using type variable from target type - E1");} + public void testCtorITDsUsingTargetTypeVarsF1() {runTest("ctor itd using type variable from target type - F1");} + public void testCtorITDsUsingTargetTypeVarsG1() {runTest("ctor itd using type variable from target type - G1");} + public void testCtorITDsUsingTargetTypeVarsH1() {runTest("ctor itd using type variable from target type - H1");} + public void testCtorITDsUsingTargetTypeVarsI1() {runTest("ctor itd using type variable from target type - I1");} + + public void testSophisticatedAspectsA() {runTest("uberaspects - A");} + public void testSophisticatedAspectsB() {runTest("uberaspects - B");} + public void testSophisticatedAspectsC() {runTest("uberaspects - C");} + public void testSophisticatedAspectsD() {runTest("uberaspects - D");} + public void testSophisticatedAspectsE() {runTest("uberaspects - E");} + public void testSophisticatedAspectsF() {runTest("uberaspects - F");} + public void testSophisticatedAspectsG() {runTest("uberaspects - G");} + public void testSophisticatedAspectsH() {runTest("uberaspects - H");} + public void testSophisticatedAspectsI() {runTest("uberaspects - I");} + public void testSophisticatedAspectsJ() {runTest("uberaspects - J");} + //public void testSophisticatedAspectsK() {runTest("uberaspects - K");} // FIXME asc bounds testing is tough! + public void testSophisticatedAspectsK2(){runTest("uberaspects - K2");} + public void testSophisticatedAspectsL() {runTest("uberaspects - L");} + public void testSophisticatedAspectsM() {runTest("uberaspects - M");} + public void testSophisticatedAspectsN() {runTest("uberaspects - N");} + public void testSophisticatedAspectsO() {runTest("uberaspects - O");} + public void testSophisticatedAspectsP() {runTest("uberaspects - P");} + public void testSophisticatedAspectsQ() {runTest("uberaspects - Q");} + public void testSophisticatedAspectsR() {runTest("uberaspects - R");} + public void testSophisticatedAspectsS() {runTest("uberaspects - S");} + public void testSophisticatedAspectsT() {runTest("uberaspects - T");} + public void testSophisticatedAspectsU() {runTest("uberaspects - U");} // includes nasty casts + public void testSophisticatedAspectsV() {runTest("uberaspects - V");} // casts are gone + public void testSophisticatedAspectsW() {runTest("uberaspects - W");} + public void testSophisticatedAspectsX() {runTest("uberaspects - X");} // from the AJDK + public void testSophisticatedAspectsY() {runTest("uberaspects - Y");} // pointcut matching + public void testSophisticatedAspectsZ() {runTest("uberaspects - Z");} + + // FIXME asc these two tests have peculiar error messages - generic aspect related +// public void testItdUsingTypeParameter() {runTest("itd using type parameter");} +// public void testItdIncorrectlyUsingTypeParameter() {runTest("itd incorrectly using type parameter");} + + + public void testUsingSameTypeVariable() {runTest("using same type variable in ITD");} + + public void testBinaryWeavingITDsA() {runTest("binary weaving ITDs - A");} + public void testBinaryWeavingITDsB() {runTest("binary weaving ITDs - B");} + public void testBinaryWeavingITDs1() {runTest("binary weaving ITDs - 1");} + public void testBinaryWeavingITDs2() {runTest("binary weaving ITDs - 2");} + public void testBinaryWeavingITDs3() {runTest("binary weaving ITDs - 3");} + public void testGenericITFSharingTypeVariable() {runTest("generic intertype field declaration, sharing type variable");} + + + // general tests ... usually just more complex scenarios + public void testReusingTypeVariableLetters() {runTest("reusing type variable letters");} + public void testMultipleGenericITDsInOneFile() {runTest("multiple generic itds in one file");} + public void testItdNonStaticMember() {runTest("itd of non static member");} + public void testItdStaticMember() {runTest("itd of static member");} + public void testStaticGenericMethodITD() {runTest("static generic method itd");} + + + public void testAtOverride0() {runTest("atOverride used with ITDs");} + public void testAtOverride1() {runTest("atOverride used with ITDs - 1");} + public void testAtOverride2() {runTest("atOverride used with ITDs - 2");} + public void testAtOverride3() {runTest("atOverride used with ITDs - 3");} + public void testAtOverride4() {runTest("atOverride used with ITDs - 4");} + public void testAtOverride5() {runTest("atOverride used with ITDs - 5");} + public void testAtOverride6() {runTest("atOverride used with ITDs - 6");} + public void testAtOverride7() {runTest("atOverride used with ITDs - 7");} + + + // bridge methods + public void testITDBridgeMethodsCovariance1() {runTest("bridging with covariance 1 - normal");} + public void testITDBridgeMethodsCovariance2() {runTest("bridging with covariance 1 - itd");} + public void testITDBridgeMethods1Normal() {runTest("basic bridging with type vars - 1 - normal");} + public void testITDBridgeMethods1Itd() {runTest("basic bridging with type vars - 1 - itd");} + public void testITDBridgeMethods2Normal() {runTest("basic bridging with type vars - 2 - normal");} + public void testITDBridgeMethods2Itd() {runTest("basic bridging with type vars - 2 - itd");} + public void testITDBridgeMethodsPr91381() {runTest("Abstract intertype method and covariant returns");} + + + // Just normal source compile of two types with a method override between them + public void testGenericITDsBridgeMethods1() { + runTest("bridge methods - 1"); + checkMethodsExist("Sub1",new String[]{ + "java.lang.Integer Sub1.m()", + "java.lang.Object Sub1.m() [BridgeMethod]"}); + } + // Now the same thing but the aspect (which doesn't do much!) is binary woven in. + public void testGenericITDsBridgeMethods1binary() { + runTest("bridge methods - 1 - binary"); + checkMethodsExist("Sub1",new String[]{ + "java.lang.Integer Sub1.m()", + "java.lang.Object Sub1.m() [BridgeMethod]"}); + } + // Now the method is put into the superclass via ITD - there should be a bridge method in the subclass + public void testGenericITDsBridgeMethods2() { + runTest("bridge methods - 2"); + checkMethodsExist("Sub2",new String[]{ + "java.lang.Integer Sub2.m()", + "java.lang.Object Sub2.m() [BridgeMethod]"}); + } + // Now the superclass ITD is done with binary weaving so the weaver (rather than compiler) has to create the bridge method + public void testGenericITDsBridgeMethods2binary() { + runTest("bridge methods - 2 - binary"); + checkMethodsExist("Sub2",new String[]{ + "java.lang.Integer Sub2.m()", + "java.lang.Object Sub2.m() [BridgeMethod]"}); + } + // Now the method is put into the subclass via ITD - there should be a bridge method alongside it in the subclass + public void testGenericITDsBridgeMethods3() { + runTest("bridge methods - 3"); + checkMethodsExist("Sub3",new String[]{ + "java.lang.Integer Sub3.m()", + "java.lang.Object Sub3.m() [BridgeMethod]"}); + } + // Now the subclass ITD is done with binary weaving - the weaver should create the necessary bridge method + public void testGenericITDsBridgeMethods3binary() { + runTest("bridge methods - 3 - binary"); + checkMethodsExist("Sub3",new String[]{ + "java.lang.Integer Sub3.m()", + "java.lang.Object Sub3.m() [BridgeMethod]"}); + } + // Now the two types are disconnected until the aspect supplies a declare parents relationship - + // the bridge method should still be created in the subtype + public void testGenericITDSBridgeMethods4() { + runTest("bridge methods - 4"); + checkMethodsExist("Sub4",new String[]{ + "java.lang.Integer Sub4.m()", + "java.lang.Object Sub4.m() [BridgeMethod]"}); + } + // now the aspect doing the decp between the types is applied via binary weaving - weaver should create the bridge method + public void testGenericITDSBridgeMethods4binary() { + runTest("bridge methods - 4 - binary"); + checkMethodsExist("Sub4",new String[]{ + "java.lang.Integer Sub4.m()", + "java.lang.Object Sub4.m() [BridgeMethod]"}); + } + + public void testBinaryBridgeMethodsOne() { + runTest("binary bridge methods - one"); + checkMethodsExist("OneB",new String[]{ + "java.lang.Number OneB.firstMethod() [BridgeMethod]", + "java.lang.Integer OneB.firstMethod()", + "void OneB.secondMethod(java.lang.Number) [BridgeMethod]", + "void OneB.secondMethod(java.lang.Integer)", + "void OneB.thirdMethod(java.lang.Number,java.lang.Number) [BridgeMethod]", + "void OneB.thirdMethod(java.lang.Integer,java.lang.Integer)", + "void OneB.fourthMethod(java.util.List)", + "java.lang.Number OneB.fifthMethod(java.lang.Number,java.util.List) [BridgeMethod]", + "java.lang.Integer OneB.fifthMethod(java.lang.Integer,java.util.List)" + }); + } + public void testBinaryBridgeMethodsTwo() { + runTest("binary bridge methods - two"); + checkMethodsExist("TwoB",new String[]{ + "java.lang.Number TwoB.firstMethod(java.io.Serializable) [BridgeMethod]", + "java.lang.Integer TwoB.firstMethod(java.lang.String)" + }); + } + public void testBinaryBridgeMethodsThree() { + runTest("binary bridge methods - three"); + checkMethodsExist("ThreeB",new String[]{ + "java.lang.Number ThreeB.m() [BridgeMethod]", + "java.lang.Double ThreeB.m()" + }); + } + + + public void testGenericITDsBridgeMethodsPR91381() {runTest("abstract intertype methods and covariant returns");} + public void testGenericITDsBridgeMethodsPR91381_2() {runTest("abstract intertype methods and covariant returns - error");} + + // ---------------------------------------------------------------------------------------- + // generic declare parents tests + // ---------------------------------------------------------------------------------------- + + public void testPR96220_GenericDecp() { + runTest("generic decp - simple"); + checkOneSignatureAttribute(ajc,"Basic"); + verifyClassSignature(ajc,"Basic","Ljava/lang/Object;LJ;LI;"); + } + + // Both the existing type decl and the one adding via decp are parameterized + public void testGenericDecpMultipleVariantsOfAParameterizedType1() { + runTest("generic decp - implementing two variants #1"); + } + + // Existing type decl is raw and the one added via decp is parameterized + public void testGenericDecpMultipleVariantsOfAParameterizedType2() { + runTest("generic decp - implementing two variants #2"); + } + + // Existing type decl is parameterized and the one added via decp is raw + public void testGenericDecpMultipleVariantsOfAParameterizedType3() { + runTest("generic decp - implementing two variants #3"); + } + + // decp is parameterized but it does match the one already on the type + public void testGenericDecpMultipleVariantsOfAParameterizedType4() { + runTest("generic decp - implementing two variants #4"); + } + + // same as above four tests for binary weaving + public void testGenericDecpMultipleVariantsOfAParameterizedType1_binaryWeaving() { + runTest("generic decp binary - implementing two variants #1"); + } + + public void testGenericDecpMultipleVariantsOfAParameterizedType2_binaryWeaving() { + runTest("generic decp binary - implementing two variants #2"); + } + + // Existing type decl is parameterized and the one added via decp is raw + public void testGenericDecpMultipleVariantsOfAParameterizedType3_binaryWeaving() { + runTest("generic decp binary - implementing two variants #3"); + } + + // decp is parameterized but it does match the one already on the type + public void testGenericDecpMultipleVariantsOfAParameterizedType4_binaryWeaving() { + runTest("generic decp binary - implementing two variants #4"); + } + + public void testGenericDecpParameterized() { + runTest("generic decp - with parameterized on the target"); + checkOneSignatureAttribute(ajc,"Basic6"); + verifyClassSignature(ajc,"Basic6","Ljava/lang/Object;LI;LK;"); + } + + public void testGenericDecpIncorrectNumberOfTypeParams() { + runTest("generic decp - incorrect number of type parameters"); + } + + public void testGenericDecpSpecifyingBounds() { + runTest("generic decp - specifying bounds"); + } + + public void testGenericDecpViolatingBounds() { + runTest("generic decp - specifying bounds but breaking them"); + } + + // need separate compilation test to verify signatures are ok +// +// public void testIllegalGenericDecp() { +// runTest("illegal generic decp"); +// } +// +// public void testPR95992_TypeResolvingProblemWithGenerics() { +// runTest("Problems resolving type name inside generic class"); +// } + + + // -- Pointcut tests... + + public void testHandlerWithGenerics() { + runTest("handler pcd and generics / type vars"); + } + + public void testPointcutsThatDontAllowTypeVars() { + runTest("pointcuts that dont allow type vars"); + } + + public void testParameterizedTypesInAtPCDs() { + runTest("annotation pcds with parameterized types"); + } + + public void testAnnotationPatternsWithParameterizedTypes() { + runTest("annotation patterns with parameterized types"); + } + + public void testStaticInitializationWithParameterizedTypes() { + runTest("staticinitialization and parameterized types"); + } + + // no longer a valid test with generics simplication +// public void testStaticInitializationMatchingWithParameterizedTypes() { +// runTest("staticinitialization and parameterized type matching"); +// } + +// no longer a valid test in simplified design +// public void testStaticInitializationWithGenericTypes() { +// runTest("staticinitialization with generic types"); +// } + +// no longer a valid test in simplified design +// public void testStaticInitializationWithGenericTypesAdvanced() { +// runTest("staticinitialization with generic types - advanced"); +// } + + public void testWithinPointcutErrors() { + runTest("within pcd with various parameterizations and generic types - errors"); + } + + public void testWithinPointcutWarnings() { + runTest("within pcd with various parameterizations and generic types - warnings"); + } + + public void testThisTargetPointcutErrors() { + runTest("this and target with various parameterizations and generic types - errors"); + } + + public void testThisTargetPointcutRuntime() { + runTest("this and target with various parameterizations and generic types - runtime"); + } + + public void testInitAndPreInitPointcutErrors() { + runTest("init and preinit with parameterized declaring types"); + } + + public void testInitAndPreInitPointcutMatchingWithGenericDeclaringTypes() { + runTest("init and preinit with raw declaring type pattern"); + } + + public void testInitAndPreInitPointcutMatchingWithParameterizedParameterTypes() { + runTest("init and preinit with parameterized parameter types"); + } + + public void testWithinCodePointcutErrors() { + runTest("withincode with various parameterizations and generic types - errors"); + } + + public void testWithinCodeMatching() { + runTest("withincode with various parameterizations and generic types - matching"); + } + + public void testWithinCodeOverrideMatchingWithGenericMembers() { + runTest("withincode with overriding of inherited generic members"); + } + + public void testExecutionWithRawType() { + runTest("execution pcd with raw type matching"); + } + + public void testExecutionWithRawSignature() { + runTest("execution pcd with raw signature matching"); + } + + public void testExecutionPointcutErrors() { + runTest("execution with various parameterizations and generic types - errors"); + } + + public void testExecutionMatching() { + runTest("execution with various parameterizations and generic types - matching"); + } + + public void testExecutionOverrideMatchingWithGenericMembers() { + runTest("execution with overriding of inherited generic members"); + } + + public void testCallPointcutErrors() { + runTest("call with various parameterizations and generic types - errors"); + } + + public void testCallMatching() { + runTest("call with various parameterizations and generic types - matching"); + } + + public void testCallOverrideMatchingWithGenericMembers() { + runTest("call with overriding of inherited generic members"); + } + + public void testCallWithBridgeMethods() { + runTest("call with bridge methods"); + } + + public void testGetAndSetPointcutErrors() { + runTest("get and set with various parameterizations and generic types - errors"); + } + + public void testGetAndSetPointcutMatchingWithGenericAndParameterizedTypes() { + runTest("get and set with various parameterizations and generic declaring types"); + } + + public void testGetAndSetPointcutMatchingWithGenericAndParameterizedFieldTypes() { + runTest("get and set with various parameterizations and generic field types"); + } + + public void testArgsWithRawType() { + runTest("args with raw type and generic / parameterized sigs"); + } + + public void testArgsParameterizedType() { + runTest("args with parameterized type and generic / parameterized sigs"); + } + + public void testArgsParameterizedAndWildcards() { + runTest("args with parameterized type and wildcards"); + } + + public void testArgsWithWildcardVar() { + runTest("args with generic wildcard"); + } + + public void testArgsWithWildcardExtendsVar() { + runTest("args with generic wildcard extends"); + } + + public void testArgsWithWildcardSuperVar() { + runTest("args with generic wildcard super"); + } + + public void testGenericMethodMatching() { + runTest("generic method matching"); + } + + public void testGenericWildcardsInSignatureMatching() { + runTest("generic wildcards in signature matching"); + } + + public void testAfterThrowing() { + runTest("after throwing with parameterized throw type"); + } + + public void testAfterReturningWithRawType() { + runTest("after returning with raw type and generic / parameterized sigs"); + } + + public void testAfterReturningParameterizedType() { + runTest("after returning with parameterized type and generic / parameterized sigs"); + } + + public void testAfterReturningParameterizedAndWildcards() { + runTest("after returning with parameterized type and wildcards"); + } + + public void testAfterReturningWithWildcardVar() { + if (LangUtil.is19VMOrGreater()) { + // See ReferenceType.isCoerceableFrom comments + return; + } + // Something to investigate here. The implementation of isCoerceable + runTest("after returning with generic wildcard"); + } + + public void testAfterReturningWithWildcardExtendsVar() { + runTest("after returning with generic wildcard extends"); + } + + public void testAfterReturningWithWildcardSuperVar() { + runTest("after returning with generic wildcard super"); + } + + public void testAJDKErasureMatchingExamples() { + runTest("ajdk notebook: erasure matching examples"); + } + + public void testAJDKParameterizedMatchingSimpleExamples() { + runTest("ajdk notebook: simple parameterized type matching examples"); + } + + public void testAJDKMixedTypeVarsAndParametersExample() { + runTest("ajdk notebook: mixed parameterized types and generic methods"); + } + + public void testAJDKSignatureAndWildcardExamples() { + runTest("ajdk notebook: signature matching with generic wildcards"); + } + + // had to remove at e37 level - although pointcuts are likely to work, we can't compile the code + // that invokes the bridge methods - seems the compiler is too smart and won't let them through. +// public void testAJDKBridgeMethodExamples() { +// runTest("ajdk notebook: bridge method examples"); +// } + + public void testAJDKArgsExamples() { + runTest("ajdk notebook: args examples"); + } + + public void testAJDKArgsAndWildcardsExamples() { + runTest("ajdk notebook: args and wildcards examples"); + } + + public void testAJDKAfterReturningExamples() { + runTest("ajdk notebook: after returning examples"); + } + + public void testAJDKPointcutInGenericClassExample() { + runTest("ajdk notebook: pointcut in generic class example"); + } + + // TESTS for generic abstract aspects that get extended and parameterized... + + public void testStaticPointcutParameterization() { + runTest("static pointcut parameterization suite"); + } + + public void testDynamicPointcutParameterization() { + runTest("dynamic pointcut parameterization suite"); + } + + public void testReferenceToPointcutInGenericClass() { + runTest("reference to pointcut in generic class"); + } + + public void testReferenceToPointcutInGenericClass2() { + runTest("reference to non-parameterized pointcut in generic class"); + } + + public void testDeclareParentsParameterized() { + runTest("declare parents parameterized"); + } + + public void testDeclarePrecedenceParameterized() { + runTest("declare precedence parameterized"); + } + + public void testDeclareAnnotationParameterized() { + runTest("declare annotation parameterized"); + } + + public void testMultiLevelGenericAspects() { + runTest("multi-level generic abstract aspects"); + } + + // --- helpers + + /** + * When a class has been written to the sandbox directory, you can ask this method to + * verify it contains a particular set of methods. Typically this is used to verify that + * bridge methods have been created. + */ + public void checkMethodsExist(String classname,String[] methods) { + Set methodsFound = new HashSet<>(); + StringBuffer debugString = new StringBuffer(); + try { + ClassLoader cl = new URLClassLoader(new URL[]{ajc.getSandboxDirectory().toURL()}); + Class clz = Class.forName(classname,false,cl); + java.lang.reflect.Method[] ms = clz.getDeclaredMethods(); + if (ms!=null) { + for (int i =0;i "+debugString); + } + } + StringBuffer unexpectedMethods = new StringBuffer(); + if (!methodsFound.isEmpty()) { + for (String element: methodsFound) { + unexpectedMethods.append("[").append(element).append("]"); + } + fail("These methods weren't expected: "+unexpectedMethods); + } + + } + + /** + * Use 1.5 API isBridge if available. + * See JLS3 15.12.4.5 Create Frame, Synchronize, Transfer Control + */ + public static boolean isBridge(java.lang.reflect.Method m) { + // why not importing java.lang.reflect.Method? No BCEL clash? + if (!LangUtil.is15VMOrGreater()) { + return false; + } + try { + final Class[] noparms = new Class[0]; + java.lang.reflect.Method isBridge + = java.lang.reflect.Method.class.getMethod("isBridge", noparms); + Boolean result = (Boolean) isBridge.invoke(m, new Object[0]); + return result.booleanValue(); + } catch (Throwable t) { + return false; + } + } + public static JavaClass getClass(Ajc ajc, String classname) { + try { + ClassPath cp = + new ClassPath(ajc.getSandboxDirectory() + File.pathSeparator + System.getProperty("java.class.path")); + SyntheticRepository sRepos = SyntheticRepository.getInstance(cp); + JavaClass clazz = sRepos.loadClass(classname); + return clazz; + } catch (ClassNotFoundException e) { + fail("Couldn't find class "+classname+" in the sandbox directory."); + } + return null; + } + + public static Signature getClassSignature(Ajc ajc,String classname) { + JavaClass clazz = getClass(ajc,classname); + Signature sigAttr = null; + Attribute[] attrs = clazz.getAttributes(); + for (int i = 0; i < attrs.length; i++) { + Attribute attribute = attrs[i]; + if (attribute.getName().equals("Signature")) sigAttr = (Signature)attribute; + } + return sigAttr; + } + + public static void checkOneSignatureAttribute(Ajc ajc,String classname) { + JavaClass clazz = getClass(ajc,classname); + Attribute[] attrs = clazz.getAttributes(); + int signatureCount = 0; + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < attrs.length; i++) { + Attribute attribute = attrs[i]; + if (attribute.getName().equals("Signature")) { + signatureCount++; + sb.append("\n"+((Signature)attribute).getSignature()); + } + } + if (signatureCount>1) fail("Should be only one signature attribute but found "+signatureCount+sb.toString()); + } + + // Check the signature attribute on a class is correct + public static void verifyClassSignature(Ajc ajc,String classname,String sig) { + Signature sigAttr = getClassSignature(ajc,classname); + assertTrue("Failed to find signature attribute for class "+classname,sigAttr!=null); + assertTrue("Expected signature to be '"+sig+"' but was '"+sigAttr.getSignature()+"'", + sigAttr.getSignature().equals(sig)); + } + + private static String stringify(Class[] clazzes) { + if (clazzes==null) return ""; + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < clazzes.length; i++) { + if (i>0) sb.append(","); + sb.append(clazzes[i].getName()); + } + return sb.toString(); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/HasMember.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/HasMember.java new file mode 100644 index 000000000..57e053b9b --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/HasMember.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Adrian Colyer - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +public class HasMember extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(HasMember.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + public void testSimpleDecPHasMethod() { + runTest("declare parents : hasmethod(..) - 1"); + } + + public void testSimpleDecPHasMethodInherited() { + runTest("declare parents : hasmethod(..) - 2"); + } + + public void testSimpleDecPHasMethodInheritedPrivate() { + runTest("declare parents : hasmethod(..) - 3"); + } + + // this test not passing yet, ITD integration not implemented +// public void testDecPHasMethodViaITD() { +// runTest("declare parents : hasmethod(..) - 4"); +// } + + public void testSimpleDecPHasField() { + runTest("declare parents : hasfield(..) - 1"); + } + + public void testSimpleDecPHasFieldInherited() { + runTest("declare parents : hasfield(..) - 2"); + } + + public void testSimpleDecPHasFieldInheritedPrivate() { + runTest("declare parents : hasfield(..) - 3"); + } + +} \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/MigrationTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/MigrationTests.java new file mode 100644 index 000000000..a9322b086 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/MigrationTests.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + + +/** + * Checks if we are obeying migration rules. + */ +public class MigrationTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(MigrationTests.class); + } + + protected File getSpecFile() { + return getClassResource("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 + * in the 'old way' + * + */ + public void testMigrationFrom121_pointcutsAndAdvice() { + 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"); + } + +// /** +// * We cannot support all aspects built prior to AspectJ 1.2.1 - so we don't support any. +// * There are probably many reasons but the first one I've hit is: +// * - Changes for cflow optimizations (counters instead of stacks where we can) mean that an aspect +// * compiled at AspectJ1.2.0 will contain stack cases but AspectJ1.5.0 will look for counter +// * fields in some cases. +// * +// * This means we should get a reasonable failure message in this case. +// */ +// public void testMigrationFrom120_pointcutsAndAdvice() { +// CompilationResult cR = ajc(baseDir,new String[]{"-aspectpath","aspects120.jar","Program.java"}); +// assertTrue("Should have failed",cR.getFailMessages().size()>0); +// assertTrue("Should have produced nice message",cR.getFailMessages().get(0).toString().indexOf("Unable to continue")!=-1); +// } + +} \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/PerTypeWithinTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/PerTypeWithinTests.java new file mode 100644 index 000000000..84b014392 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/PerTypeWithinTests.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2005 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.tools.ajc.CompilationResult; + + + +public class PerTypeWithinTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(PerTypeWithinTests.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + /** + * First few tests: + * + * Five types p.A, p.B, p.C, q.D, q.E and an aspect a.X. + * + * The aspect is pertypewithin(p..*) - this should match A,B,C but not D,E. + * + * Aspect instances should be accessible for A,B,C but not D,E. + * The aspect instances for A,B,C should be different. + * + * hasAspect(), aspectOf() should work. + * + * We test these assumptions in A,B,C,D,E. + */ + public void testDoesItWorkAtAll() { + runTest("basic ptw test"); + } + + public void testCheckHasAspectWorks() { + runTest("ptw hasAspect"); + } + + public void testCheckAspectOfWorks() { + runTest("ptw aspectOf"); + } + /** + * Aspects Q and R match P with a pertypewithin() - they shouldn't clash in any way + * + */ + public void testTwoAspectsHittingOneType() { + 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(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(); + + assertEquals("Expected same number of messages regardless of perclause", + weavingMessagesFromNormalDeploymentModel,weavingMessagesFromPerTypeWithin); + } + + + public void testBinaryWeaving_ClassesAreBinary() { + runTest("ptw binary"); + } + + public void testBinaryWeaving_AspectsAreBinary() { + runTest("ptw binary aspect"); + } + + public void testAJDKExamples() { + runTest("ajdk: ptw"); + } +// // 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/test/java/org/aspectj/systemtest/ajc150/RuntimeAnnotations.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/RuntimeAnnotations.java new file mode 100644 index 000000000..676c2b014 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/RuntimeAnnotations.java @@ -0,0 +1,138 @@ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +/** + * Checking that runtime visible annotations are visible at runtime (they get into the class file) + */ +public class RuntimeAnnotations extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(RuntimeAnnotations.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + public void test01() { + runTest("public method with declare @method"); + } + + public void test02() { + runTest("public method on the aspect that declares @method on it"); + } + + public void test03() { + runTest("public annotated method"); + } + + public void test04() { + runTest("public ITD method with declare @method"); + } + + public void test05() { + runTest("public annotated ITD method"); + } + + public void test06() { + runTest("public ITD-on-itself method with declare @method"); + } + + public void test07() { + runTest("public annotated ITD-on-itself method"); + } + + public void test08() { + runTest("public method on an Interface with declare @method"); + } + + public void test09() { + runTest("public annotated method on an Interface"); + } + + public void test10() { + runTest("public ITD method onto an Interface with declare @method"); + } + + public void test11() { + runTest("public annotated ITD method onto an Interface"); + } + + public void test12() { + runTest("public abstract method with declare @method"); + } + + public void test13() { + runTest("public abstract method on the aspect that declares @method on it"); + } + + public void test14() { + runTest("public abstract annotated method"); + } + + public void test15() { + runTest("public abstract ITD method with declare @method"); + } + + public void test16() { + runTest("public abstract annotated ITD method"); + } + + public void test17() { + runTest("public abstract ITD-on-itself method with declare @method"); + } + + public void test18() { + runTest("public abstract annotated ITD-on-itself method"); + } + + public void test19() { + runTest("public abstract method on an Interface with declare @method"); + } + + public void test20() { + runTest("public abstract annotated method on an Interface"); + } + + public void test21() { + runTest("public abstract ITD method onto an Interface with declare @method"); + } + + public void test22() { + runTest("public abstract annotated ITD method onto an Interface"); + } + + public void test23() { + runTest("public field with declare @field"); + } + + public void test24() { + runTest("public field on the aspect that declares @field on it"); + } + + public void test25() { + runTest("public annotated field"); + } + + public void test26() { + runTest("public ITD field with declare @field"); + } + + public void test27() { + runTest("public annotated ITD field"); + } + + public void test28() { + runTest("public ITD-on-itself field with declare @field"); + } + + public void test29() { + runTest("public annotated ITD-on-itself field"); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/SCCSFixTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/SCCSFixTests.java new file mode 100644 index 000000000..30dba129f --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/SCCSFixTests.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wes Isberg - initial implementation + *******************************************************************************/ + +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import org.aspectj.tools.ajc.AjcTestCase; +import org.aspectj.tools.ajc.CompilationResult; +import org.aspectj.util.FileUtil; + +/** + * SCCS/CVS directory fix. + * Would add to Ajc150TestsNoHarness, but can't share basedir/setup, etc. + */ +public class SCCSFixTests extends AjcTestCase { + File baseDir; + File sourceroot; + + public void setUp() throws Exception { + super.setUp(); + baseDir = FileUtil.getTempDir("BugFixTests"); + sourceroot = new File(baseDir, "sourceroot"); + sourceroot.mkdirs(); + } + public void tearDown() { + FileUtil.deleteContents(baseDir); + } + /** + * @see org/aspectj/util/FileUtil.java 1.17 + * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=48650 + */ + public void testSkipCVS() { + doTestSkip("CVS"); + } + + /** + * @see org/aspectj/util/FileUtil.java 1.17 + * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=48650 + */ + public void testSkipSCCS() { + doTestSkip("SCCS"); + } + + /** + * Can't check in "CVS" or "SCCS" directories, + * so construct for each test. + */ + private void doTestSkip(String name) { + File dir = new File(sourceroot, name); + sourceroot.mkdirs(); + File file = new File(dir, "Error.java"); + FileUtil.writeAsString(file, "public class Error { here }"); + file = new File(sourceroot, "Main.java"); + FileUtil.writeAsString(file, MAIN); + String[] args = { "-sourceroots", sourceroot.getPath() }; + CompilationResult result = ajc(baseDir, args); + assertNoMessages(result); + RunResult r = run("Main"); + String m = r.getStdOut().trim(); + assertEquals("I ran", m); + } + private static final String MAIN = + "public class Main { public static void main(String[] a) {System.out.println(\"I ran\");}}"; +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/StaticImports.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/StaticImports.java new file mode 100644 index 000000000..71b82f4e4 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/StaticImports.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Huff - initial implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +public class StaticImports extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(StaticImports.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + public void testImportStaticSystemDotOut() { + runTest("import static java.lang.System.out"); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/SuppressedWarnings.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/SuppressedWarnings.java new file mode 100644 index 000000000..0a830018e --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/SuppressedWarnings.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +public class SuppressedWarnings extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(SuppressedWarnings.class); + } + + protected File getSpecFile() { + return getClassResource("ajc150.xml"); + } + + // Check basic suppression + public void testSuppression1() { + runTest("suppressing non-matching advice warnings"); + } + + // Checks source contexts aren't put out incorrectly + // NOTE: Source contexts only come out if the primary source location in a message + // matches the file currently being dealt with. Because advice not matching + // messages come out at the last stage of compilation, you currently only + // get sourcecontext for advice not matching messages that point to places in + // the last file being processed. You do get source locations in all cases - + // you just don't always get context, we could revisit this sometime... + // (see bug 62073 reference in WeaverMessageHandler.handleMessage()) + public void testSuppression2() { + runTest("suppressing non-matching advice warnings when multiple source files involved"); + } + + public void testSuppressionWithCflow_pr93345() { + runTest("XLint warning for advice not applied with cflow(execution)"); + } + + public void testSuppressionOfMessagesIssuedDuringMatching() { + runTest("SuppressAjWarnings raised during matching"); + } +} \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/VarargsTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/VarargsTests.java new file mode 100644 index 000000000..7592f7c6d --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/VarargsTests.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + + +/** + * Varargs, the rules/tests: + * + * 1. cannot match on a varargs method by using 'Object[]' in your signature, + * this affects call/execution/initialization/withincode + */ +public class VarargsTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(VarargsTests.class); + } + + protected File getSpecFile() { + return getClassResource("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() { + runTest("varargs not matched by Object[] (call)"); + } + + // check when signature is from an execution PCD + public void test002_cantMatchVarargsWithObjectArray_execPCD() { + runTest("varargs not matched by Object[] (exe)"); + } + + // check when signature is from an initialization PCD + public void test003_cantMatchVarargsWithObjectArray_initPCD() { + runTest("varargs not matched by Object[] (init)"); + } + + // check when signature is from an withincode PCD + public void test003_cantMatchVarargsWithObjectArray_withincodePCD() { + runTest("varargs not matched by Object[] (withincode)"); + } + + // before(): call(* *(Integer...)) { } + public void test_usingVarargsInPointcuts1() { + runTest("call with varargs signature"); + } + + // before(): call(* *(int,Integer...)) { } - slightly more complex pcut + public void test_usingVarargsInPointcuts2() { + runTest("call with varargs multi-signature"); + } + + public void testAJDKExamples() { + runTest("ajdk: varargs"); + } + + public void testStarVarargs() { + runTest("star varargs pattern"); + } + + public void testVarargsWithDotDotInPointcut() { + runTest("Varargs with .. in pointcut"); + } + +} \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/test/java/org/aspectj/systemtest/ajc150/ajc150.xml new file mode 100644 index 000000000..9eda00b0c --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ajc150.xml @@ -0,0 +1,6308 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjAnnotationGenTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjAnnotationGenTests.java new file mode 100644 index 000000000..bfbc289f6 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjAnnotationGenTests.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * initial development Jonas Bon�r, Alexandre Vasseur + *******************************************************************************/ +package org.aspectj.systemtest.ajc150.ataspectj; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +/** + * A suite for @AspectJ aspects located in java5/ataspectj + * + * @author Alexandre Vasseur + */ +public class AtAjAnnotationGenTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AtAjAnnotationGenTests.class); + } + + protected File getSpecFile() { + return getClassResource("annotationgen.xml"); + } + + public void testSimpleAspect() { + runTest("annotation gen for simple aspect"); + } + + public void testSimpleAspectIn14Mode() { + runTest("annotation gen for simple aspect pre 1.5"); + } + + public void testAspectAlreadyAnnotated() { + runTest("annotation gen for simple annotated aspect"); + } + + public void testPrivilegedAspect() { + runTest("annotation gen for privileged aspect"); + } + + public void testPerThisAspect() { + runTest("annotation gen for perthis aspect"); + } + + public void testPerTargetAspect() { + runTest("annotation gen for pertarget aspect"); + } + + public void testPerCflowAspect() { + runTest("annotation gen for percflow aspect"); + } + + public void testPerCflowbelowAspect() { + runTest("annotation gen for percflowbelow aspect"); + } + + public void testPertypewithinAspect() { + runTest("annotation gen for pertypewithin aspect"); + } + + public void testInnerAspectOfClass() { + runTest("annotation gen for inner aspect of aspect"); + } + + public void testInnerAspectOfAspect() { + runTest("annotation gen for inner aspect of class"); + } + + public void testAdvice() { + runTest("annotation gen for advice declarations"); + } + + public void testSimplePointcut() { + runTest("annotation gen for simple pointcut"); + } + + public void testPointcutModifiers() { + runTest("annotation gen for pointcut modifiers"); + } + + public void testPointcutParams() { + runTest("annotation gen for pointcut params"); + } + + public void testPointcutRefs() { + runTest("annotation gen for pointcut refs"); + } + + public void testBeforeWithBadReturn() { + runTest("before ann with non-void return"); + } + + public void testTwoAnnotationsOnSameElement() { + runTest("two anns on same element"); + } + + public void testBadPcutInAdvice() { + runTest("bad pcut in after advice"); + } + + public void testBadParameterBinding() { + runTest("bad parameter binding in advice"); + } + + public void testSimpleAtPointcut() { + runTest("simple pointcut no params"); + } + + public void testPointcutMedley() { + runTest("pointcut medley"); + } + + public void testAdviceDeclaredInClass() { + runTest("advice in a class"); + } + + public void testDeows() { + runTest("ann gen for deows"); + } + + // no reliable way to get around classpath issues for + // running this test as part of release script :( +// public void testRuntimePointcutsReferencingCompiledPointcuts() { +// runTest("runtime pointcut resolution referencing compiled pointcuts"); +// } + + public void testDecP() { + runTest("ann gen for decp"); + } + + public void testDecPAdvanced() { + runTest("ann gen for decp 2"); + } + + public void testDecS() { + runTest("ann gen for decs"); + } + + public void testDecPrecedence() { + runTest("ann gen for dec precedence"); + } + + public void testDecAnnotation() { + runTest("ann gen for dec annotation"); + } + + public void testITDs() { + runTest("ann gen for itds"); + } +} + diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjLTWTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjLTWTests.java new file mode 100644 index 000000000..966642da2 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjLTWTests.java @@ -0,0 +1,237 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Vasseur initial implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150.ataspectj; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.util.FileUtil; + +/** + * @author Alexandre Vasseur + */ +public class AtAjLTWTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(org.aspectj.systemtest.ajc150.ataspectj.AtAjLTWTests.class); + } + + protected File getSpecFile() { + return getClassResource("ltw.xml"); + } + + public void testRunThemAllWithJavacCompiledAndLTW() { + runTest("RunThemAllWithJavacCompiledAndLTW"); + } + + public void testAjcLTWPerClauseTest_XterminateAfterCompilation() { + runTest("AjcLTW PerClauseTest -XterminateAfterCompilation"); + } + + public void testAjcLTWPerClauseTest_Xreweavable() { + runTest("AjcLTW PerClauseTest -Xreweavable"); + } + + public void testJavaCAjcLTWPerClauseTest() { + runTest("JavaCAjcLTW PerClauseTest"); + } + + public void testAjcLTWAroundInlineMungerTest_XterminateAfterCompilation() { + runTest("AjcLTW AroundInlineMungerTest -XterminateAfterCompilation"); + } + + public void testAjcLTWAroundInlineMungerTest_Xreweavable() { + runTest("AjcLTW AroundInlineMungerTest"); + } + + public void testAjcLTWAroundInlineMungerTest() { + runTest("AjcLTW AroundInlineMungerTest"); + } + + public void testAjcLTWAroundInlineMungerTest_XnoInline_Xreweavable() { + runTest("AjcLTW AroundInlineMungerTest -XnoInline -Xreweavable"); + } + + public void testAjcLTWAroundInlineMungerTest2() { + runTest("AjcLTW AroundInlineMungerTest2"); + } + + public void testLTWDumpNone() { + runTest("LTW DumpTest none"); + + File f = new File("_ajdump/ataspectj/DumpTest.class"); + assertFalse(f.exists()); + f = new File("_ajdump/_before/ataspectj/DumpTestTheDump.class"); + assertFalse(f.exists()); + f = new File("_ajdump/ataspectj/DumpTestTheDump.class"); + assertFalse(f.exists()); + } + + public void testLTWDump() { + runTest("LTW DumpTest"); + + File f = new File("_ajdump/ataspectj/DumpTest.class"); + assertFalse(f.exists()); + f = new File("_ajdump/_before/ataspectj/DumpTestTheDump.class"); + assertFalse(f.exists()); + f = new File("_ajdump/ataspectj/DumpTestTheDump.class"); + assertTrue(f.exists()); + + // tidy up... + f = new File("_ajdump"); + FileUtil.deleteContents(f); + f.delete(); + } + + public void testLTWDumpBeforeAndAfter() { + runTest("LTW DumpTest before and after"); + + // before + File f = new File("_ajdump/_before/com/foo/bar"); + CountingFilenameFilter cff = new CountingFilenameFilter(".class"); + f.listFiles(cff); + assertEquals("Expected dump file in " + f.getAbsolutePath(), 1, cff.getCount()); + + // after + f = new File("_ajdump/com/foo/bar"); + cff = new CountingFilenameFilter(".class"); + f.listFiles(cff); + assertEquals("Expected dump file in " + f.getAbsolutePath(), 1, cff.getCount()); + + // tidy up... + f = new File("_ajdump"); + FileUtil.deleteContents(f); + f.delete(); + } + + public void testLTWDumpClosure() { + runTest("LTW DumpTest closure"); + + File f = new File("_ajdump/ataspectj/DumpTestTheDump$AjcClosure1.class"); + assertTrue("Missing dump file " + f.getAbsolutePath(), f.exists()); + + // tidy up... + f = new File("_ajdump"); + FileUtil.deleteContents(f); + f.delete(); + } + + public void testLTWDumpProxy() { + runTest("LTW DumpTest proxy"); + + // The working directory is different because this test must be forked + File dir = new File("../tests/java5/ataspectj"); + File f = new File(dir, "_ajdump/_before/com/sun/proxy"); + CountingFilenameFilter cff = new CountingFilenameFilter(".class"); + f.listFiles(cff); + assertEquals("Expected dump file in " + f.getAbsolutePath(), 1, cff.getCount()); + f = new File(dir, "_ajdump/com/sun/proxy"); + cff = new CountingFilenameFilter(".class"); + f.listFiles(cff); + assertEquals(1, cff.getCount()); + + // tidy up... + f = new File(dir, "_ajdump"); + FileUtil.deleteContents(f); + f.delete(); + } + + public void testLTWDumpJSP() { + runTest("LTW DumpTest JSP"); + + // The working directory is different because this test must be forked + File f = new File("_ajdump/_before/com/ibm/_jsp"); + CountingFilenameFilter cff = new CountingFilenameFilter(".class"); + f.listFiles(cff); + assertEquals("Expected dump file in " + f.getAbsolutePath(), 1, cff.getCount()); + f = new File("_ajdump/com/ibm/_jsp"); + cff = new CountingFilenameFilter(".class"); + f.listFiles(cff); + assertEquals(1, cff.getCount()); + + // tidy up... + f = new File("_ajdump"); + FileUtil.deleteContents(f); + f.delete(); + } + + public void testAjcAspect1LTWAspect2_Xreweavable() { + runTest("Ajc Aspect1 LTW Aspect2 -Xreweavable"); + } + + public void testLTWLogSilent() { + runTest("LTW Log silent"); + } + + public void testLTWLogVerbose() { + runTest("LTW Log verbose"); + } + + public void testLTWLogVerboseAndShow() { + runTest("LTW Log verbose and showWeaveInfo"); + } + + public void testLTWLogMessageHandlerClass() { + runTest("LTW Log messageHandlerClass"); + } + + public void testLTWUnweavable() { + // actually test that we do LTW proxy and jit classes + runTest("LTW Unweavable"); + } + + public void testLTWDecp() { + runTest("LTW Decp"); + } + + public void testLTWDecp2() { + runTest("LTW Decp2"); + } + + public void testCompileTimeAspectsDeclaredToLTWWeaver() { + runTest("Compile time aspects declared to ltw weaver"); + } + + public void testConcreteAtAspect() { + runTest("Concrete@Aspect"); + } + + public void testConcreteAspect() { + runTest("ConcreteAspect"); + } + + public void testConcretePrecedenceAspect() { + runTest("ConcretePrecedenceAspect"); + } + + // public void testAspectOfWhenAspectNotInInclude() { + // runTest("AspectOfWhenAspectNotInInclude"); + // } + // + // public void testAspectOfWhenAspectExcluded_pr152873() { + // runTest("AspectOfWhenAspectExcluded"); + // } + + public void testAspectOfWhenNonAspectExcluded_pr152873() { + runTest("AspectOfWhenNonAspectExcluded"); + } + + public void testAppContainer() { + runTest("AppContainer"); + } + + public void testCflowBelowStack() { + runTest("CflowBelowStack"); + } +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjMisuseTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjMisuseTests.java new file mode 100644 index 000000000..0f13e8f8b --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjMisuseTests.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Vasseur initial implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150.ataspectj; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +/** + * @author Alexandre Vasseur + */ +public class AtAjMisuseTests extends XMLBasedAjcTestCase { + + protected File getSpecFile() { + return getClassResource("misuse.xml"); + } + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AtAjMisuseTests.class); + } + + public void testQAspectClassExtendingQAspectClass() { + runTest("@Aspect class extending @Aspect class"); + } + + // TODO asc commented out for now until Alex manages to get ajdtcore up to date... +// public void testClassWithQBeforeExtendingQAspectClass() { +// runTest("class with @Before extending @Aspect class"); +// } + + public void testQPointcutNotReturningVoid() { + runTest("@Pointcut not returning void"); + } + + public void testQPointcutWithGarbageString() { + runTest("@Pointcut with garbage string"); + } + + public void testQPointcutWithThrowsClause() { + runTest("@Pointcut with throws clause"); + } + + public void testQAfterReturningWithWrongNumberOfArgs() { + runTest("@AfterReturning with wrong number of args"); + } + + public void testQBeforeOnNon_publicMethod() { + runTest("@Before on non-public method"); + } + + public void testQBeforeOnMethodNotReturningVoid() { + runTest("@Before on method not returning void"); + } + + public void testQBeforeWithPJP() { + runTest("@Before with PJP"); + } +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java new file mode 100644 index 000000000..794fce907 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * initial implementation Alexandre Vasseur + *******************************************************************************/ +package org.aspectj.systemtest.ajc150.ataspectj; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +/** + * A suite for @AspectJ aspects located in java5/ataspectj + * + * @author Alexandre Vasseur + */ +public class AtAjSyntaxTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AtAjSyntaxTests.class); + } + + protected File getSpecFile() { + return getClassResource("syntax.xml"); + } + + public void testSimpleBefore() { + runTest("SimpleBefore"); + } + + public void testSimpleAfter() { + runTest("SimpleAfter"); + } + + public void testSingletonAspectBindings() { + // Note AV: uncomment setReporting to get it in modules/tests folder + // org.aspectj.asm.AsmManager.setReporting("debug.txt",true,true,true,true); + runTest("singletonAspectBindings"); + // same stuff with AJ + // org.aspectj.asm.AsmManager.setReporting("debug-aj.txt",true,true,true,true); + // runTest("singletonAspectBindings2"); + + } + + public void testCflowTest() { + runTest("CflowTest"); + } + + public void testPointcutReferenceTest() { + runTest("PointcutReferenceTest"); + } + + public void testXXJoinPointTest() { + runTest("XXJoinPointTest"); + } + + public void testPrecedenceTest() { + runTest("PrecedenceTest"); + } + + public void testAfterXTest() { + runTest("AfterXTest"); + } + + public void testBindingTest() { + runTest("BindingTest"); + } + + public void testBindingTestNoInline() { + runTest("BindingTest no inline"); + } + + public void testPerClause() { + runTest("PerClause"); + } + + public void testAroundInlineMunger_XnoInline() { + runTest("AroundInlineMunger -XnoInline"); + } + + public void testAroundInlineMunger() { + try { + runTest("AroundInlineMunger"); + } finally { + System.out.println(ajc.getLastCompilationResult().getStandardError()); + } + } + + public void testAroundInlineMunger2() { + runTest("AroundInlineMunger2"); + } + + public void testDeow() { + runTest("Deow"); + } + + public void testSingletonInheritance() { + runTest("singletonInheritance"); + } + + public void testPerClauseInheritance() { + runTest("perClauseInheritance"); + } + + public void testIfPointcut() { + runTest("IfPointcutTest"); + } + + public void testIfPointcut2() { + runTest("IfPointcut2Test"); + } + + public void testMultipleBinding() { + runTest("MultipleBinding"); + } + + public void testBug104212() { + runTest("Bug104212"); + } + + public void testDeclareParentsInterface() { + runTest("DeclareParentsInterface"); + } + + public void testDeclareParentsImplements() { + runTest("DeclareParentsImplements"); + } + + public void testAbstractAspectNPE() { + runTest("AbstractAspectNPE"); + } + + public void testAbstractInherited() { + runTest("AbstractInherited"); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/annotationgen.xml b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/annotationgen.xml new file mode 100644 index 000000000..3a8bda2ad --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/annotationgen.xml @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/coverage/CoverageTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/coverage/CoverageTests.java new file mode 100644 index 000000000..534c7e57d --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/coverage/CoverageTests.java @@ -0,0 +1,43 @@ +package org.aspectj.systemtest.ajc150.ataspectj.coverage; + +import java.io.File; + +import junit.framework.Test; +import junit.framework.TestResult; + +public class CoverageTests extends + org.aspectj.testing.AutowiredXMLBasedAjcTestCase { + + // set to false to debug tests + static final boolean failing = true; + + /** + * disabled here so Ant JUnit rule wrt running *Tests works. + */ + public static Test suite() { + if (failing) { + return new Test() { + public int countTestCases() { + return 1; + } + + public void run(TestResult r) { + r.startTest(this); + r.endTest(this); + } + + public String toString() { + return CoverageTests.class.getName() + " fail"; + } + }; + } + return org.aspectj.testing.AutowiredXMLBasedAjcTestCase + .loadSuite(CoverageTests.class); + } + + protected File getSpecFile() { + return new File( + "../tests/src/org/aspectj/systemtest/ajc150/ataspectj/coverage/coverage.xml"); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/coverage/coverage.xml b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/coverage/coverage.xml new file mode 100644 index 000000000..f0ad3f4d3 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/coverage/coverage.xml @@ -0,0 +1,320 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml new file mode 100644 index 000000000..a72fa4ebf --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml @@ -0,0 +1,349 @@ + + + + + + + + + + + + + + + + + + + + + aspectOf methods will be pushed in, ignore warning for adviceDidNotMatch but still do the logic for them + since such just added methods are an interesting case (percflow ajc$perCflowStack advice) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/misuse.xml b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/misuse.xml new file mode 100644 index 000000000..9aec9d7a4 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/misuse.xml @@ -0,0 +1,146 @@ + + + + + + + + + + + + + + + + + + a warning. We ignore the pointcut (TBD) - line is enclosing class (TBD Andy do better ?) + + + + + + + + + + + + + + line is enclosing class - TBD + + + + + + + + + + + + + line is enclosing class - TBD + + + + + + + very dirty hack - can't get this location to work properly so added match all error.. + amc - with new checks for binding of returning this was giving a different message, so I + tweaked the test slightly by swapping the order of the args + + + + + + + + line number is enclosing type + + + + + + + line number is enclosing type + + + + + + + + + + + + + + diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml new file mode 100644 index 000000000..69055af39 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/LTWServerTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/LTWServerTests.java new file mode 100644 index 000000000..d73e594b9 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/LTWServerTests.java @@ -0,0 +1,27 @@ +package org.aspectj.systemtest.ajc150.ltw; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +public class LTWServerTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return loadSuite(LTWServerTests.class); + } + + protected File getSpecFile() { + return getClassResource("ltw.xml"); + } + + public void testServerWithHelloWorld () { + runTest("TestServer with HelloWorld"); + } + + public void testServerWithParentAndChild () { + runTest("TestServer with Parent and Child"); + } + +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/LTWTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/LTWTests.java new file mode 100644 index 000000000..ff9e59339 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/LTWTests.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthew Webster initial implementation + *******************************************************************************/ +package org.aspectj.systemtest.ajc150.ltw; + +import java.io.File; +import java.util.Enumeration; +import java.util.Properties; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; +import org.aspectj.weaver.tools.WeavingAdaptor; + +public class LTWTests extends org.aspectj.testing.XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(LTWTests.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ltw/ltw.xml"); + } + + public void testInclusionAndPattern() { + runTest("Inclusion and patterns"); + } + + public void testExclusionAndPattern() { + runTest("Exclusion and patterns"); + } + + public void testAndPatternsAspects() { + runTest("And patterns aspects"); + } + + public void test001(){ + runTest("Ensure 1st aspect is rewoven when weaving 2nd aspect"); + } + + public void testOutxmlFile (){ + runTest("Ensure valid aop.xml file is generated"); + } + public void testOutxmlJar (){ + runTest("Ensure valid aop.xml is generated for -outjar"); + } + + public void testNoAopxml(){ + setSystemProperty(WeavingAdaptor.WEAVING_ADAPTOR_VERBOSE,"true"); + runTest("Ensure no weaving without visible aop.xml"); + } + + public void testDefineConcreteAspect(){ + runTest("Define concrete sub-aspect using aop.xml"); + } + + public void testDeclareAbstractAspect(){ +// setSystemProperty(WeavingAdaptor.WEAVING_ADAPTOR_VERBOSE,"true"); +// setSystemProperty(WeavingAdaptor.SHOW_WEAVE_INFO_PROPERTY,"true"); + runTest("Use abstract aspect for ITD using aop.xml"); + } + + public void testAspectsInclude () { + runTest("Ensure a subset of inherited aspects is used for weaving"); + } + + public void testAspectsIncludeWithLintWarning () { + runTest("Ensure weaver lint warning issued when an aspect is not used for weaving"); + } + + public void testXsetEnabled () { + runTest("Set Xset properties enabled"); + } + public void testXsetDisabled () { + runTest("Set Xset properties disabled"); + } + + public void testXlintfileEmpty () { + runTest("Empty Xlint.properties file"); + } + + public void testXlintfileMissing () { + runTest("Warning with missing Xlint.properties file"); + } + + public void testXlintWarningAdviceDidNotMatchSuppressed () { + runTest("Warning when advice doesn't match suppressed for LTW"); + } + + public void testXlintfile () { + runTest("Override suppressing of warning when advice doesn't match using -Xlintfile"); + } + + public void testXlintDefault () { + runTest("Warning when advice doesn't match using -Xlint:default"); + } + + public void testXlintWarning () { + runTest("Override suppressing of warning when advice doesn't match using -Xlint:warning"); + } + + public void testNonstandardJarFiles() { + runTest("Nonstandard jar file extensions"); + } + + public void testOddzipOnClasspath() { + runTest("Odd zip on classpath"); + } + + public void testJ14LTWWithXML() { + runTest("JDK14 LTW with XML"); + } + +// public void testJ14LTWWithASPECTPATH() { +// runTest("JDK14 LTW with ASPECTPATH"); +// } + + + //public void testDiscardingWovenTypes() { + // runTest("discarding woven types - 1"); + //} + + public void testWeavingTargetOfCallAggressivelyInLTW_DeclareParents_pr133770() { + runTest("aggressive ltw - decp"); + } + + public void testWeavingTargetOfCallAggressivelyInLTW_DeclareParents_pr133770_Deactivate() { + runTest("aggressive ltw - decp - deactivate"); + } + + public void testWeavingTargetOfCallAggressivelyInLTW_DeclareParents_Nested_pr133770() { + runTest("aggressive ltw - decp - 2"); + } + + public void testWeavingTargetOfCallAggressivelyInLTW_DeclareParents_Hierarchy_pr133770() { + runTest("aggressive ltw - hierarchy"); + } + + public void testSeparateCompilationDeclareParentsCall_pr133770() { + runTest("separate compilation with ltw: declare parents and call"); + } + + public void testConfigurationSystemProperty_pr149289() { + runTest("override default path using -Dorg.aspectj.weaver.loadtime.configuration"); + } + + public void testSimpleLTW_pr159854 () { + runTest("simple LTW"); + } + + public void testDumpOnError_pr155033 () { + runTest("dump on error"); + + File dir = getSandboxDirectory(); + CountingFilenameFilter cff = new CountingFilenameFilter(".txt"); + dir.listFiles(cff); + assertEquals("Missing ajcore file in " + dir.getAbsolutePath(),1,cff.getCount()); + } + + public void testMultipleDumpOnError_pr155033 () { + runTest("multiple dump on error"); + + File dir = getSandboxDirectory(); + CountingFilenameFilter cff = new CountingFilenameFilter(".txt"); + dir.listFiles(cff); + assertEquals("Missing ajcore file in " + dir.getAbsolutePath(),2,cff.getCount()); + } + + /* + * Allow system properties to be set and restored + * TODO maw move to XMLBasedAjcTestCase or RunSpec + */ + private final static String NULL = "null"; + + private Properties savedProperties; + + protected void setSystemProperty (String key, String value) { + Properties systemProperties = System.getProperties(); + copyProperty(key,systemProperties,savedProperties); + systemProperties.setProperty(key,value); + } + + private static void copyProperty (String key, Properties from, Properties to) { + String value = from.getProperty(key,NULL); + to.setProperty(key,value); + } + + protected void setUp() throws Exception { + super.setUp(); + savedProperties = new Properties(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + + /* Restore system properties */ + Properties systemProperties = System.getProperties(); + for (Enumeration enu = savedProperties.keys(); enu.hasMoreElements(); ) { + String key = (String)enu.nextElement(); + String value = savedProperties.getProperty(key); + if (value == NULL) systemProperties.remove(key); + else systemProperties.setProperty(key,value); + } + } +} \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml b/tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml new file mode 100644 index 000000000..0dcdbf142 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml @@ -0,0 +1,670 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/ltw.xml b/tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/ltw.xml new file mode 100644 index 000000000..311872c09 --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/ltw/ltw.xml @@ -0,0 +1,11 @@ + +]> + + + + + +&tests; + + diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/tests/.cvsignore b/tests/src/test/java/org/aspectj/systemtest/ajc150/tests/.cvsignore new file mode 100644 index 000000000..9d3c17f8d --- /dev/null +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/tests/.cvsignore @@ -0,0 +1 @@ +ajcTestSuite.dtd -- cgit v1.2.3