[vmkit-commits] [vmkit] r180425 - test files

Peter Senna Tschudin peter.senna at gmail.com
Thu Apr 25 10:10:11 PDT 2013


Author: peter.senna
Date: Thu Apr 25 12:08:36 2013
New Revision: 180425

URL: http://llvm.org/viewvc/llvm-project?rev=180425&view=rev
Log:
test files
(cherry picked from commit 37539cfaef6145c72c9b2314a515c54f47f62020)

Added:
    vmkit/trunk/tests/AnnotationClassTest.java
    vmkit/trunk/tests/MyAnnotation.java

Added: vmkit/trunk/tests/AnnotationClassTest.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tests/AnnotationClassTest.java?rev=180425&view=auto
==============================================================================
--- vmkit/trunk/tests/AnnotationClassTest.java (added)
+++ vmkit/trunk/tests/AnnotationClassTest.java Thu Apr 25 12:08:36 2013
@@ -0,0 +1,52 @@
+import java.lang.Deprecated;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+
+public class AnnotationClassTest {
+
+	@MyAnnotation (property = 13, property4 = System.class)
+  static class Sample {
+    @Deprecated
+    @MyAnnotation (property=5, property4=String.class)
+    public int x;
+    
+    @MyAnnotation (property=7, property4=String.class)
+    public int y() {
+    	return x*x;
+    }
+  }
+
+  public static void main(String[] args) throws Exception {
+    Field f = Sample.class.getField("x");
+    Method m = Sample.class.getMethod("y");
+    Sample sample = new Sample();
+    sample.x = 14;
+    
+    Annotation [] fAnno = f.getDeclaredAnnotations();
+    Annotation [] mAnno = m.getAnnotations();
+    Annotation [] cAnno = Sample.class.getDeclaredAnnotations();
+
+    MyAnnotation xx = (MyAnnotation)f.getAnnotation(MyAnnotation.class);
+		MyAnnotation yy = (MyAnnotation)m.getAnnotation(MyAnnotation.class);
+		
+		
+
+    check(f.getInt(sample) == 14);
+    f.setInt(sample, 17);
+    check(f.getInt(sample) == 17);
+    check(xx != null);
+    check(yy != null);
+    check(mAnno.length == 1);
+		check(fAnno.length == 2);
+		check(cAnno != null && cAnno.length == 1 && cAnno[0]!= null);
+    //int s = yy.property();
+    //check(s == 5);
+    
+  }
+
+  private static void check(boolean b) throws Exception {
+    if (!b) throw new Exception("Test failed!!!");
+  }
+}

Added: vmkit/trunk/tests/MyAnnotation.java
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tests/MyAnnotation.java?rev=180425&view=auto
==============================================================================
--- vmkit/trunk/tests/MyAnnotation.java (added)
+++ vmkit/trunk/tests/MyAnnotation.java Thu Apr 25 12:08:36 2013
@@ -0,0 +1,8 @@
+import java.lang.annotation.*;
+ at Retention(value=RetentionPolicy.RUNTIME)
+public @interface MyAnnotation {
+	int property();
+	int[] primes() default {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
+	String property3() default "Default value";
+	Class property4();
+}





More information about the vmkit-commits mailing list