]> source.dussan.org Git - aspectj.git/commitdiff
testing for @args
authoracolyer <acolyer>
Fri, 10 Dec 2004 11:26:37 +0000 (11:26 +0000)
committeracolyer <acolyer>
Fri, 10 Dec 2004 11:26:37 +0000 (11:26 +0000)
tests/java5/annotations/args/AtArgsAspect.java [new file with mode: 0644]
tests/java5/annotations/args/TestingArgsAnnotations.jar [new file with mode: 0644]
tests/java5/annotations/args/TestingArgsAnnotations.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/AnnotationRuntimeTests.java

diff --git a/tests/java5/annotations/args/AtArgsAspect.java b/tests/java5/annotations/args/AtArgsAspect.java
new file mode 100644 (file)
index 0000000..5a5c8a4
--- /dev/null
@@ -0,0 +1,125 @@
+public aspect AtArgsAspect {
+       
+       
+       pointcut myMethod() : execution(* myMethod(..));
+               
+       // Exact number of args
+       // test 0
+       before() : myMethod() && @args(*,*,*,*,*) {
+               System.out.print("@args(*,*,*,*,*): ");
+               System.out.println(TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       before() : myMethod() && !@args(*,*,*,*,*) {
+               System.out.print("@args(*,*,*,*,*): ");
+               System.out.println(!TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       
+       // One too few
+       // test 1
+       before() : myMethod() && @args(*,*,*,*) {
+               System.out.print("@args(*,*,*,*): ");
+               System.out.println(TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       before() : myMethod() && !@args(*,*,*,*) {
+               System.out.print("@args(*,*,*,*): ");
+               System.out.println(!TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       
+       // One too many
+       // test 2
+       before() : myMethod() && @args(*,*,*,*,*,*) {
+               System.out.print("@args(*,*,*,*,*,*): ");
+               System.out.println(TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       before() : myMethod() && !@args(*,*,*,*,*,*) {
+               System.out.print("@args(*,*,*,*,*,*): ");
+               System.out.println(!TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+
+       // Exact number of args + ellipsis
+       // test 3
+       before() : myMethod() && @args(*,*,..,*,*,*) {
+               System.out.print("@args(*,*,..,*,*,*): ");
+               System.out.println(TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       before() : myMethod() && !@args(*,*,..,*,*,*) {
+               System.out.print("@args(*,*,..,*,*,*): ");
+               System.out.println(!TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+
+       // Too few + ellipsis
+       // test 4
+       before() : myMethod() && @args(*,*,*,..) {
+               System.out.print("@args(*,*,*,..): ");
+               System.out.println(TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       before() : myMethod() && !@args(*,*,*,..) {
+               System.out.print("@args(*,*,*,..): ");
+               System.out.println(!TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       
+       // Now we get to test some annotations!
+       
+       // Non-inherited 
+       // test 5
+       before() : myMethod() && @args(@MyAnnotation,..) {
+               System.out.print("@args(@MyAnnotation,..): ");
+               System.out.println(TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       before() : myMethod() && !@args(@MyAnnotation,..) {
+               System.out.print("@args(@MyAnnotation,..): ");
+               System.out.println(!TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+
+       // test 6
+       before() : myMethod() && @args(@MyAnnotation,*,*,@MyAnnotation,*) {
+               System.out.print("@args(@MyAnnotation,*,*,@MyAnnotation,*): ");
+               System.out.println(TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       before() : myMethod() && !@args(@MyAnnotation,*,*,@MyAnnotation,*) {
+               System.out.print("@args(@MyAnnotation,*,*,@MyAnnotation,*): ");
+               System.out.println(!TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+
+       // test 7
+       before() : myMethod() && @args(@MyAnnotation,*,*,@MyAnnotation,@MyAnnotation) {
+               System.out.print("@args(@MyAnnotation,*,*,@MyAnnotation,@MyAnnotation): ");
+               System.out.println(TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       before() : myMethod() && !@args(@MyAnnotation,*,*,@MyAnnotation,@MyAnnotation) {
+               System.out.print("@args(@MyAnnotation,*,*,@MyAnnotation,@MyAnnotation): ");
+               System.out.println(!TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       
+       // Inherited
+       // test 8
+       before() : myMethod() && @args(..,@MyInheritableAnnotation,*) {
+               System.out.print("@args(..,@MyInheritableAnnotation,*): ");
+               System.out.println(TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       before() : myMethod() && !@args(..,@MyInheritableAnnotation,*) {
+               System.out.print("@args(..,@MyInheritableAnnotation,*): ");
+               System.out.println(!TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+
+       // test 9
+       before() : myMethod() && @args(..,@MyInheritableAnnotation,@MyInheritableAnnotation) {
+               System.out.print("@args(..,@MyInheritableAnnotation,@MyInheritableAnnotation): ");
+               System.out.println(TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       before() : myMethod() && !@args(..,@MyInheritableAnnotation,@MyInheritableAnnotation) {
+               System.out.print("@args(..,@MyInheritableAnnotation,@MyInheritableAnnotation): ");
+               System.out.println(!TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+
+       // test 10
+       before() : myMethod() && @args(..,@MyInheritableAnnotation,@MyInheritableAnnotation,@MyInheritableAnnotation) {
+               System.out.print("@args(..,@MyInheritableAnnotation,@MyInheritableAnnotation,@MyInheritableAnnotation): ");
+               System.out.println(TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+       before() : myMethod() && !@args(..,@MyInheritableAnnotation,@MyInheritableAnnotation,@MyInheritableAnnotation) {
+               System.out.print("@args(..,@MyInheritableAnnotation,@MyInheritableAnnotation,@MyInheritableAnnotation): ");
+               System.out.println(!TestingArgsAnnotations.expected() ? "PASS" : "FAIL");
+       }
+
+}
\ No newline at end of file
diff --git a/tests/java5/annotations/args/TestingArgsAnnotations.jar b/tests/java5/annotations/args/TestingArgsAnnotations.jar
new file mode 100644 (file)
index 0000000..8068f1f
Binary files /dev/null and b/tests/java5/annotations/args/TestingArgsAnnotations.jar differ
diff --git a/tests/java5/annotations/args/TestingArgsAnnotations.java b/tests/java5/annotations/args/TestingArgsAnnotations.java
new file mode 100644 (file)
index 0000000..a6cb252
--- /dev/null
@@ -0,0 +1,84 @@
+public class TestingArgsAnnotations {
+
+       private static boolean[] expected;
+       private static int index = 0;
+
+       private static void setExpectedMatches(boolean[] matches) {
+               System.out.println();
+               System.out.println("New Test Run");
+               System.out.println("===============================");
+               expected = matches;
+               index = 0;
+       }
+       
+       public static boolean expected() {
+               System.out.print("Test " + index + ": ");
+               return expected[index++];
+       }
+       
+       public static void main(String[] args) {
+               A a = new A();
+               B b = new B();
+               C c = new C();
+               D d = new D();
+               E e = new E();
+               
+               A reallyB = new B();
+               C reallyD = new D();
+               D reallyE = new E();
+               
+               // now make some calls...
+               setExpectedMatches(new boolean[] {true,false,false,true,true,false,false,false,true,true,false});
+               myMethod(a,b,c,d,e);
+               
+               setExpectedMatches(new boolean[] {true,false,false,true,true,true,true,false,true,true,false});
+               myMethod(b,b,c,d,e);
+               
+               setExpectedMatches(new boolean[] {true,false,false,true,true,true,true,false,true,true,false});
+               myMethod(reallyB,b,c,d,e);
+               
+               setExpectedMatches(new boolean[] {true,false,false,true,true,false,false,false,true,true,true});
+               myMethod(a,b,reallyD,d,e);
+               
+               setExpectedMatches(new boolean[] {true,false,false,true,true,false,false,false,true,true,true});
+               myMethod(a,b,reallyD,reallyE,e);
+       }
+       
+       public static void myMethod(A a, B b, C c, D d, E e) {
+               return;
+       }
+       
+}
+
+@MyClassRetentionAnnotation
+class A {
+  public void doSomething() {}
+}
+
+
+@MyAnnotation
+class B extends A {
+  public void doSomething() {}
+}
+
+class C {}
+
+@MyInheritableAnnotation
+@MyAnnotation
+class D extends C {
+  public void doSomething() {}
+}
+
+class E extends D {
+  public void doSomething() {}
+}
+
+
+@interface MyClassRetentionAnnotation {}
+
+@java.lang.annotation.Retention(value=java.lang.annotation.RetentionPolicy.RUNTIME)
+@interface MyAnnotation {}
+
+@java.lang.annotation.Retention(value=java.lang.annotation.RetentionPolicy.RUNTIME)
+@java.lang.annotation.Inherited
+@interface MyInheritableAnnotation {}
\ No newline at end of file
index 8b5403bc154cfd7b768bdeb851333a5890cb5128..966bf884a262657f1add43e0ac02253da570d7bf 100644 (file)
@@ -44,10 +44,16 @@ public class AnnotationRuntimeTests extends TestUtils {
     
     public void test003_InheritableOrNot() {
         CompilationResult cR = binaryWeave("TestingAnnotations.jar","ThisOrTargetTests.aj",0,0);   
-        System.out.println(cR);
     }
     
     // TODO extra tests
     // run the result of test003 and validate matches (needs 1.5 runtime)
     // test inheritable annotation not present on type [should generate runtime test]
+    
+    public void test004_ArgsSuite() {
+       baseDir = new File("../tests/java5/annotations/args");
+        CompilationResult cR = binaryWeave("TestingArgsAnnotations.jar","AtArgsAspect.java",0,0);  
+        // TODO need to RUN the result of these tests...
+        System.out.println(cR);
+    }
 }