summaryrefslogtreecommitdiffstats
path: root/annotation/src/test/java
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:28:47 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:28:47 -0800
commitadc854b798c1cfe3bfd4c27d68d5cee38ca617da (patch)
tree6aed8b4923ca428942cbaa7e848d50237a3d31e0 /annotation/src/test/java
parent1c0fed63c71ddb230f3b304aac12caffbedf2f21 (diff)
downloadlibcore-adc854b798c1cfe3bfd4c27d68d5cee38ca617da.zip
libcore-adc854b798c1cfe3bfd4c27d68d5cee38ca617da.tar.gz
libcore-adc854b798c1cfe3bfd4c27d68d5cee38ca617da.tar.bz2
auto import from //depot/cupcake/@135843
Diffstat (limited to 'annotation/src/test/java')
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AllTests.java43
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java80
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTest.java471
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java72
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java83
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java87
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java78
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation1.java25
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation2.java15
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation3.java28
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation3b.java28
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation4.java12
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestEnum1.java5
-rw-r--r--annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestEnum1b.java5
-rw-r--r--annotation/src/test/java/tests/annotation/AllTests.java38
15 files changed, 1070 insertions, 0 deletions
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AllTests.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AllTests.java
new file mode 100644
index 0000000..a5453df
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AllTests.java
@@ -0,0 +1,43 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+import org.apache.harmony.nio_char.tests.java.nio.charset.ASCIICharsetEncoderTest;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite for java.nio.charset package.
+ */
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = tests.TestSuiteFactory.createTestSuite("Test for java.lang.annotation");
+ // $JUnit-BEGIN$
+
+ suite.addTestSuite(AnnotationTest.class);
+ suite.addTestSuite(AnnotationFormatErrorTest.class);
+ suite.addTestSuite(AnnotationTypeMismatchExceptionTest.class);
+ suite.addTestSuite(ElementTypeTest.class);
+ suite.addTestSuite(IncompleteAnnotationExceptionTest.class);
+ suite.addTestSuite(RetentionPolicyTest.class);
+
+ // $JUnit-END$
+ return suite;
+ }
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java
new file mode 100644
index 0000000..c2a32b8
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationFormatErrorTest.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+import junit.framework.TestCase;
+
+import java.lang.annotation.AnnotationFormatError;
+
+/**
+ * Test case of java.lang.annotation.AnnotationFormatError
+ */
+@TestTargetClass(AnnotationFormatError.class)
+public class AnnotationFormatErrorTest extends TestCase {
+ /**
+ * @tests java.lang.annotation.AnnotationFormatError#AnnotationFormatError(String)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "AnnotationFormatError",
+ args = {java.lang.String.class}
+ )
+ @SuppressWarnings("nls")
+ public void test_constructorLjava_lang_String() {
+ AnnotationFormatError e = new AnnotationFormatError("some message");
+ assertEquals("some message", e.getMessage());
+ }
+
+ /**
+ * @tests java.lang.annotation.AnnotationFormatError#AnnotationFormatError(Throwable)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "AnnotationFormatError",
+ args = {java.lang.Throwable.class}
+ )
+ public void test_constructorLjava_lang_Throwable() {
+ IllegalArgumentException iae = new IllegalArgumentException();
+ AnnotationFormatError e = new AnnotationFormatError(iae);
+ assertSame(iae, e.getCause());
+ }
+
+ /**
+ * @tests java.lang.annotation.AnnotationFormatError#AnnotationFormatError(String,Throwable)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "AnnotationFormatError",
+ args = {java.lang.String.class, java.lang.Throwable.class}
+ )
+ @SuppressWarnings("nls")
+ public void test_constructorLjava_lang_StringLjava_lang_Throwable() {
+ IllegalArgumentException iae = new IllegalArgumentException();
+ AnnotationFormatError e = new AnnotationFormatError("some message", iae);
+ assertEquals("some message", e.getMessage());
+ assertSame(iae, e.getCause());
+ }
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTest.java
new file mode 100644
index 0000000..c50c0e8
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTest.java
@@ -0,0 +1,471 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+import junit.framework.TestCase;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Test case of java.lang.annotation.Annotation
+ */
+@TestTargetClass(value = Annotation.class,
+ untestedMethods = {
+ @TestTargetNew(
+ level = TestLevel.NOT_NECESSARY,
+ notes = "the spec does not require any specific output (although @something is probable)",
+ method = "toString",
+ args = {}
+ )}
+)
+public class AnnotationTest extends TestCase {
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "annotationType",
+ args = {}
+ )
+ public void test_annotationType() {
+ Annotation [] annotations = AnnotatedClass.class.getDeclaredAnnotations();
+ assertEquals(1, annotations.length);
+ Annotation anno = annotations[0];
+ assertEquals(TestAnnotation1.class, anno.annotationType());
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "equals",
+ args = { Object.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "hashCode",
+ args = {}
+ )
+ })
+ public void test_equals() throws Exception {
+ // test type
+ Method m1 = AnnotatedClass2.class
+ .getDeclaredMethod("a", new Class[] {});
+ Method m2 = AnnotatedClass2.class
+ .getDeclaredMethod("b", new Class[] {});
+ assertFalse("other annotation class type",
+ m1.getDeclaredAnnotations()[0].equals(m2
+ .getDeclaredAnnotations()[0]));
+
+ // test equality / non equality for base types and compound types
+ List<Method> methods = Arrays.asList(AnnotatedClass.class.getDeclaredMethods());
+ Map<String, List<Method>> eqs = new HashMap<String, List<Method>>();
+ Map<String, List<Method>> neqs = new HashMap<String, List<Method>>();
+ for (Method m : methods) {
+ String name = m.getName();
+ //System.out.println("name "+name);
+ Map<String, List<Method>> curT = name.charAt(0) == 'e'? eqs : neqs;
+ String testNum = name.substring(1,3); // 01
+ List<Method> mlist = curT.get(testNum);
+ if (mlist == null) {
+ mlist = new ArrayList<Method>();
+ curT.put(testNum, mlist);
+ }
+ mlist.add(AnnotatedClass.class.getDeclaredMethod(name, new Class[] {}));
+ }
+
+ for (List<Method> eqList : eqs.values()) {
+ for (int i = 0; i < eqList.size() -1; i++) {
+ for (int j = i+1; j < eqList.size(); j++) {
+ Method me1 = eqList.get(i);
+ Method me2 = eqList.get(j);
+ //System.out.println("eq test for "+me1.getName()+", "+me2.getName());
+ Annotation a1 = me1.getDeclaredAnnotations()[0];
+ Annotation a2 = me2.getDeclaredAnnotations()[0];
+ assertEquals("must be equal : method1:"+me1.getName()+", method2: "+me2.getName(), a1, a2);
+ assertEquals("same hashcode", a1.hashCode(), a2.hashCode());
+ }
+ }
+ }
+
+ for (List<Method> eqList : neqs.values()) {
+ for (int i = 0; i < eqList.size() -1; i++) {
+ for (int j = i+1; j < eqList.size(); j++) {
+ Method me1 = eqList.get(i);
+ Method me2 = eqList.get(j);
+ Annotation a1 = me1.getDeclaredAnnotations()[0];
+ Annotation a2 = me2.getDeclaredAnnotations()[0];
+ //System.out.println("ne test for "+me1.getName()+", "+me2.getName());
+ assertFalse("must not be equal : method1:"+me1.getName()+", method2: "+me2.getName(),
+ a1.equals(a2));
+ if (a1.hashCode() != a2.hashCode()) {
+ assertFalse("not same hashcode -> not equals", a1.equals(a2));
+ }
+ }
+
+ }
+ }
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "hashCode",
+ args = {}
+ )
+ public void test_hashCode() throws SecurityException, NoSuchMethodException {
+ Annotation a1 = AnnotatedClass.class.getDeclaredAnnotations()[0];
+ assertEquals(a1.hashCode(), (127 * "value".hashCode() ^ "foobar".hashCode()));
+ // i+= 127 *(key.hashCode() ^ memberValHashCode(value);
+
+ Method m1 = AnnotatedClass.class.getDeclaredMethod("e34c", new Class[] {});
+ int arrHc = Arrays.hashCode(new Object[]{});
+ /*
+ TestAnnotation3[] arrAnno() default {};
+ String[] arrString() default {};
+ Class[] arrClass() default {};
+ TestEnum1[] arrEnum() default {};
+ */
+ assertEquals(
+ (127 * "arrAnno".hashCode() ^ arrHc) +
+ (127 * "arrString".hashCode() ^ arrHc)+
+ (127 * "arrClass".hashCode() ^ arrHc) +
+ (127 * "arrEnum".hashCode() ^ arrHc)
+ ,
+ m1.getDeclaredAnnotations()[0].hashCode());
+
+ Method m2 = AnnotatedClass3.class.getDeclaredMethod("a", new Class[] {});
+ assertEquals(
+ (127 * "i".hashCode() ^ 12345),
+ m2.getDeclaredAnnotations()[0].hashCode());
+
+ }
+}
+
+class AnnotatedClass2 {
+ @TestAnnotation3()
+ void a() {}
+ @TestAnnotation3b()
+ void b() {}
+}
+
+class AnnotatedClass3 {
+ @TestAnnotation4(i = 12345)
+ void a() {}
+}
+
+@TestAnnotation1("foobar")
+class AnnotatedClass {
+
+ // ----- boolean -----
+ @TestAnnotation3(z = false)
+ void e01a() {}
+ @TestAnnotation3(z = false)
+ void e01b() {}
+ @TestAnnotation3()
+ void e01c() {}
+
+ @TestAnnotation3(z = true)
+ void e02a() {}
+ @TestAnnotation3(z = true)
+ void e02b() {}
+
+ @TestAnnotation3(z = false)
+ void n03a() {}
+ @TestAnnotation3(z = true)
+ void n03b() {}
+
+
+ // ----- byte -----
+ @TestAnnotation3(b = 0)
+ void e04a() {}
+ @TestAnnotation3(b = 0)
+ void e04b() {}
+ @TestAnnotation3()
+ void e04c() {}
+
+ @TestAnnotation3(b= 127)
+ void e05a() {}
+ @TestAnnotation3(b = 127)
+ void e05b() {}
+
+ @TestAnnotation3(b = -128)
+ void n06a() {}
+ @TestAnnotation3(b = 127)
+ void n06b() {}
+
+
+ // ----- short -----
+ @TestAnnotation3(s = 0)
+ void e07a() {}
+ @TestAnnotation3(s = 0)
+ void e07b() {}
+ @TestAnnotation3()
+ void e07c() {}
+
+ @TestAnnotation3(s= 32767)
+ void e08a() {}
+ @TestAnnotation3(s = 32767)
+ void e08b() {}
+
+ @TestAnnotation3(s = -32768)
+ void n09a() {}
+ @TestAnnotation3(s = 32767)
+ void n09b() {}
+
+
+ // ----- int -----
+ @TestAnnotation3(i = 100)
+ void e10a() {}
+ @TestAnnotation3(i = 100)
+ void e10b() {}
+ @TestAnnotation3()
+ void e10c() {}
+
+ @TestAnnotation3(i = Integer.MAX_VALUE)
+ void e11a() {}
+ @TestAnnotation3(i = Integer.MAX_VALUE)
+ void e11b() {}
+
+ @TestAnnotation3(i = Integer.MAX_VALUE)
+ void n12a() {}
+ @TestAnnotation3(i = Integer.MIN_VALUE)
+ void n12b() {}
+
+
+ // ----- long -----
+ @TestAnnotation3(j = 0)
+ void e13a() {}
+ @TestAnnotation3(j = 0)
+ void e13b() {}
+ @TestAnnotation3()
+ void e13c() {}
+
+ @TestAnnotation3(j = Long.MAX_VALUE)
+ void e14a() {}
+ @TestAnnotation3(j = Long.MAX_VALUE)
+ void e14b() {}
+
+ @TestAnnotation3(j = Long.MAX_VALUE)
+ void n15a() {}
+ @TestAnnotation3(j = Long.MIN_VALUE)
+ void n15b() {}
+
+
+ // ----- float -----
+ @TestAnnotation3(f = 0.0f)
+ void e16a() {}
+ @TestAnnotation3(f = 0.0f)
+ void e16b() {}
+ @TestAnnotation3()
+ void e16c() {}
+
+ @TestAnnotation3(f = Float.MAX_VALUE)
+ void e17a() {}
+ @TestAnnotation3(f = Float.MAX_VALUE)
+ void e17b() {}
+
+ @TestAnnotation3(f = Float.NaN)
+ void e18a() {}
+ @TestAnnotation3(f = Float.NaN)
+ void e18b() {}
+
+ @TestAnnotation3(f = Long.MAX_VALUE)
+ void n19a() {}
+ @TestAnnotation3(f = Long.MIN_VALUE)
+ void n19b() {}
+
+ @TestAnnotation3(f = 0.0f)
+ void n20a() {}
+ @TestAnnotation3(f = -0.0f)
+ void n20b() {}
+
+
+ // ----- double -----
+ @TestAnnotation3(d = 0.0d)
+ void e21a() {}
+ @TestAnnotation3(d = 0.0d)
+ void e21b() {}
+ @TestAnnotation3()
+ void e21c() {}
+
+ @TestAnnotation3(d = Double.MAX_VALUE)
+ void e22a() {}
+ @TestAnnotation3(d = Double.MAX_VALUE)
+ void e22b() {}
+
+ @TestAnnotation3(d = Double.NaN)
+ void e23a() {}
+ @TestAnnotation3(d = Double.NaN)
+ void e23b() {}
+
+
+ @TestAnnotation3(d = Double.MAX_VALUE)
+ void n24a() {}
+ @TestAnnotation3(d = Double.MIN_VALUE)
+ void n24b() {}
+
+ @TestAnnotation3(d = 0.0d)
+ void n25a() {}
+ @TestAnnotation3(d = -0.0d)
+ void n25b() {}
+
+
+ // ----- String -----
+ @TestAnnotation3(aString = "")
+ void e26a() {}
+ @TestAnnotation3(aString = "")
+ void e26b() {}
+ @TestAnnotation3()
+ void e26c() {}
+
+ @TestAnnotation3(aString = "asjdfk jkls dfjklsd fklsd jklds kflds jfkldsfjd"+"d")
+ void e27a() {}
+ @TestAnnotation3(aString = "asjdfk jkls dfjklsd fklsd jklds kflds jfkldsfj"+"dd")
+ void e27b() {}
+
+ @TestAnnotation3(aString = "a")
+ void n28a() {}
+ @TestAnnotation3(aString = "b")
+ void n28b() {}
+
+
+ // ----- Class-----
+ @TestAnnotation3(aClazz = Void.class)
+ void e29a() {}
+ @TestAnnotation3(aClazz = Void.class)
+ void e29b() {}
+ @TestAnnotation3()
+ void e29c() {}
+
+ @TestAnnotation3(aClazz = Integer.class)
+ void n30a() {}
+ @TestAnnotation3(aClazz = int.class)
+ void n30b() {}
+
+
+ // ----- Enum-----
+ @TestAnnotation3(aEnum = TestEnum1.F)
+ void e31a() {}
+ @TestAnnotation3(aEnum = TestEnum1.F)
+ void e31b() {}
+ @TestAnnotation3()
+ void e31c() {}
+
+ @TestAnnotation3(aEnum = TestEnum1.F)
+ void n32a() {}
+ @TestAnnotation3(aEnum = TestEnum1.A)
+ void n32b() {}
+
+ @TestAnnotation3(aEnum = TestEnum1.F)
+ void n33a() {}
+ @TestAnnotation3(aEnum = TestEnum1.L)
+ void n33b() {}
+
+
+ // ----- String arr-----
+ @TestAnnotation2(arrString = {})
+ void e34a() {}
+ @TestAnnotation2(arrString = {})
+ void e34b() {}
+ @TestAnnotation2(arrString = {})
+ void e34c() {}
+
+ @TestAnnotation2(arrString = { "a", "b"})
+ void e35a() {}
+ @TestAnnotation2(arrString = { "a", "b" })
+ void e35b() {}
+
+ @TestAnnotation2(arrString = { "a", "b"})
+ void n36a() {}
+ @TestAnnotation2(arrString = { "a", "c" })
+ void n36b() {}
+
+
+ // ----- Class arr-----
+ @TestAnnotation2(arrClass= {})
+ void e37a() {}
+ @TestAnnotation2(arrClass = {})
+ void e37b() {}
+ @TestAnnotation2(arrClass = {})
+ void e37c() {}
+
+ @TestAnnotation2(arrClass = { Void.class, Integer.class})
+ void e38a() {}
+ @TestAnnotation2(arrClass = { Void.class, Integer.class})
+ void e38b() {}
+
+ @TestAnnotation2(arrClass = { Void.class, Integer.class})
+ void n39a() {}
+ @TestAnnotation2(arrClass = { Void.class, int.class})
+ void n39b() {}
+
+ // ----- Enum arr-----
+ @TestAnnotation2(arrEnum= {})
+ void e40a() {}
+ @TestAnnotation2(arrEnum = {})
+ void e40b() {}
+ @TestAnnotation2(arrEnum = {})
+ void e40c() {}
+
+ @TestAnnotation2(arrEnum = { TestEnum1.A, TestEnum1.F })
+ void e41a() {}
+ @TestAnnotation2(arrEnum = { TestEnum1.A, TestEnum1.F })
+ void e41b() {}
+
+ @TestAnnotation2(arrEnum = { TestEnum1.A, TestEnum1.F })
+ void n42a() {}
+ @TestAnnotation2(arrEnum = { TestEnum1.A, TestEnum1.L })
+ void n42b() {}
+
+
+ // ----- Annotation arr-----
+ @TestAnnotation2(arrAnno= {})
+ void e43a() {}
+ @TestAnnotation2(arrAnno = {})
+ void e43b() {}
+ @TestAnnotation2()
+ void e43c() {}
+
+ @TestAnnotation2(arrAnno = { @TestAnnotation3(i = 20), @TestAnnotation3(j = 123)})
+ void e44a() {}
+ @TestAnnotation2(arrAnno = { @TestAnnotation3(i = 20), @TestAnnotation3(j = 123)})
+ void e44b() {}
+
+ @TestAnnotation2(arrAnno = { @TestAnnotation3(i = 20), @TestAnnotation3(j = 123)})
+ void n45a() {}
+ @TestAnnotation2(arrAnno = { @TestAnnotation3(i = 20), @TestAnnotation3(j = 124)})
+ void n45b() {}
+
+ @TestAnnotation2(arrAnno = { @TestAnnotation3(i = 20), @TestAnnotation3(j = 123)})
+ void n46a() {}
+ @TestAnnotation2(arrAnno = { @TestAnnotation3(i = -20), @TestAnnotation3(j = 123)})
+ void n46b() {}
+
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java
new file mode 100644
index 0000000..1134887
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/AnnotationTypeMismatchExceptionTest.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+import junit.framework.TestCase;
+
+import java.lang.annotation.AnnotationTypeMismatchException;
+import java.lang.reflect.Method;
+
+/**
+ * Test case of java.lang.annotation.AnnotationTypeMismatchException
+ */
+@TestTargetClass(AnnotationTypeMismatchException.class)
+public class AnnotationTypeMismatchExceptionTest extends TestCase {
+
+ /**
+ * @throws ClassNotFoundException
+ * @throws SecurityException
+ * @tests java.lang.annotation.AnnotationTypeMismatchException#AnnotationTypeMismatchException(Method,
+ * String)
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "AnnotationTypeMismatchException",
+ args = {java.lang.reflect.Method.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "element",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "foundType",
+ args = {}
+ )
+ })
+ @SuppressWarnings("nls")
+ public void test_constructorLjava_lang_reflect_MethodLjava_lang_String() throws SecurityException, ClassNotFoundException {
+ Method[] methods = Class.forName("java.lang.String").getMethods();
+ Method m = methods[0];
+ AnnotationTypeMismatchException e = new AnnotationTypeMismatchException(
+ m, "some type");
+ assertNotNull("can not instanciate AnnotationTypeMismatchException", e);
+ assertSame("wrong method name", m, e.element());
+ assertEquals("wrong found type", "some type", e.foundType());
+ }
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java
new file mode 100644
index 0000000..dec9bf7
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ElementTypeTest.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+import junit.framework.TestCase;
+
+import java.lang.annotation.ElementType;
+import java.util.Arrays;
+
+/**
+ * Test case of java.lang.annotation.ElementType
+ */
+@TestTargetClass(ElementType.class)
+public class ElementTypeTest extends TestCase {
+
+ /**
+ * @throws Exception
+ * @tests java.lang.annotation.ElementType#valueOf(String)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "valueOf",
+ args = {java.lang.String.class}
+ )
+ @SuppressWarnings("nls")
+ public void test_valueOfLjava_lang_String() throws Exception {
+ assertSame(ElementType.ANNOTATION_TYPE, ElementType
+ .valueOf("ANNOTATION_TYPE"));
+ assertSame(ElementType.CONSTRUCTOR, ElementType.valueOf("CONSTRUCTOR"));
+ assertSame(ElementType.FIELD, ElementType.valueOf("FIELD"));
+ assertSame(ElementType.LOCAL_VARIABLE, ElementType
+ .valueOf("LOCAL_VARIABLE"));
+ assertSame(ElementType.METHOD, ElementType.valueOf("METHOD"));
+ assertSame(ElementType.PACKAGE, ElementType.valueOf("PACKAGE"));
+ assertSame(ElementType.PARAMETER, ElementType.valueOf("PARAMETER"));
+ assertSame(ElementType.TYPE, ElementType.valueOf("TYPE"));
+ try {
+ ElementType.valueOf("OTHER");
+ fail("Should throw an IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @throws Exception
+ * @tests java.lang.annotation.ElementType#values()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "values",
+ args = {}
+ )
+ @SuppressWarnings("nls")
+ public void test_values() throws Exception {
+ ElementType[] values = ElementType.values();
+ assertTrue(values.length > 1);
+ Arrays.sort(values);
+ assertTrue(Arrays.binarySearch(values, ElementType.METHOD) >= 0);
+ }
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java
new file mode 100644
index 0000000..de56330
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/IncompleteAnnotationExceptionTest.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+import junit.framework.TestCase;
+
+import java.lang.annotation.IncompleteAnnotationException;
+
+@TestTargetClass(IncompleteAnnotationException.class)
+public class IncompleteAnnotationExceptionTest extends TestCase {
+
+ /*
+ * Class under test for void IncompleteAnnotationException(String)
+ * Regression for HARMONY-2477
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Verifies NullPointerException.",
+ method = "IncompleteAnnotationException",
+ args = {java.lang.Class.class, java.lang.String.class}
+ )
+ public void testNullType() {
+ try {
+ new IncompleteAnnotationException(null, "str");
+ fail("NullPointerException must be thrown");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+ }
+
+ /**
+ * @throws Exception
+ * @tests java.lang.annotation.IncompleteAnnotationException#IncompleteAnnotationException(Class,
+ * String)
+ */
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "IncompleteAnnotationException",
+ args = {java.lang.Class.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "annotationType",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "elementName",
+ args = {}
+ )
+ })
+ @SuppressWarnings("nls")
+ public void test_constructorLjava_lang_Class_Ljava_lang_String()
+ throws Exception {
+ Class clazz = String.class;
+ String elementName = "some element";
+ IncompleteAnnotationException e = new IncompleteAnnotationException(
+ clazz, elementName);
+ assertNotNull("can not instanciate IncompleteAnnotationException", e);
+ assertSame("wrong annotation type", clazz, e.annotationType());
+ assertSame("wrong element name", elementName, e.elementName());
+ }
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java
new file mode 100644
index 0000000..1827b7d
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/RetentionPolicyTest.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+import dalvik.annotation.TestTargets;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+import junit.framework.TestCase;
+
+import java.lang.annotation.RetentionPolicy;
+import java.util.Arrays;
+
+/**
+ * Test case of java.lang.annotation.RetentionPolicy
+ */
+@TestTargetClass(RetentionPolicy.class)
+public class RetentionPolicyTest extends TestCase {
+ /**
+ * @throws Exception
+ * @tests java.lang.annotation.RetentionPolicy#valueOf(String)
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "valueOf",
+ args = {java.lang.String.class}
+ )
+ @SuppressWarnings("nls")
+ public void test_valueOfLjava_lang_String() throws Exception {
+ assertSame(RetentionPolicy.CLASS, RetentionPolicy
+ .valueOf("CLASS"));
+ assertSame(RetentionPolicy.RUNTIME, RetentionPolicy
+ .valueOf("RUNTIME"));
+ assertSame(RetentionPolicy.SOURCE, RetentionPolicy
+ .valueOf("SOURCE"));
+ try {
+ RetentionPolicy.valueOf("OTHER");
+ fail("Should throw an IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @throws Exception
+ * @tests java.lang.annotation.RetentionPolicy#values()
+ */
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "values",
+ args = {}
+ )
+ @SuppressWarnings("nls")
+ public void test_values() throws Exception {
+ RetentionPolicy[] values = RetentionPolicy.values();
+ assertTrue(values.length > 1);
+ Arrays.sort(values);
+ assertTrue(Arrays.binarySearch(values, RetentionPolicy.RUNTIME) >= 0);
+ }
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation1.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation1.java
new file mode 100644
index 0000000..64393ef
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation1.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface TestAnnotation1 {
+ String value();
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation2.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation2.java
new file mode 100644
index 0000000..d3c7d42
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation2.java
@@ -0,0 +1,15 @@
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target( {ElementType.METHOD})
+public @interface TestAnnotation2 {
+ TestAnnotation3[] arrAnno() default {};
+ String[] arrString() default {};
+ Class[] arrClass() default {};
+ TestEnum1[] arrEnum() default {};
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation3.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation3.java
new file mode 100644
index 0000000..3228c66
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation3.java
@@ -0,0 +1,28 @@
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target( {ElementType.METHOD})
+public @interface TestAnnotation3 {
+ /*
+ * only primitive type, String, Class, annotation,
+ * enumeration are permitted
+ * or 1-dimensional arrays thereof
+ */
+ boolean z() default false;
+ byte b() default 0;
+ short s() default 0;
+ int i() default 100;
+ long j() default 0;
+
+ float f() default 0.0f;
+ double d() default 0.0d;
+
+ String aString() default "";
+ Class aClazz() default Void.class;
+ TestEnum1 aEnum() default TestEnum1.F;
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation3b.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation3b.java
new file mode 100644
index 0000000..5411011
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation3b.java
@@ -0,0 +1,28 @@
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target( {ElementType.METHOD})
+public @interface TestAnnotation3b {
+ /*
+ * only primitive type, String, Class, annotation,
+ * enumeration are permitted
+ * or 1-dimensional arrays thereof
+ */
+ boolean z() default false;
+ byte b() default 0;
+ short s() default 0;
+ int i() default 100;
+ long l() default 0;
+
+ float f() default 0.0f;
+ double d() default 0.0d;
+
+ String aString() default "";
+ Class aClazz() default Void.class;
+ TestEnum1 aEnum() default TestEnum1.F;
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation4.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation4.java
new file mode 100644
index 0000000..2267536
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestAnnotation4.java
@@ -0,0 +1,12 @@
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target( {ElementType.METHOD})
+public @interface TestAnnotation4 {
+ int i() default 0;
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestEnum1.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestEnum1.java
new file mode 100644
index 0000000..f8ed73d
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestEnum1.java
@@ -0,0 +1,5 @@
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+public enum TestEnum1 {
+ Z, F, L, A, B
+}
diff --git a/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestEnum1b.java b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestEnum1b.java
new file mode 100644
index 0000000..874d893
--- /dev/null
+++ b/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/TestEnum1b.java
@@ -0,0 +1,5 @@
+package org.apache.harmony.annotation.tests.java.lang.annotation;
+
+public enum TestEnum1b {
+ Z, F, L, A, B
+}
diff --git a/annotation/src/test/java/tests/annotation/AllTests.java b/annotation/src/test/java/tests/annotation/AllTests.java
new file mode 100644
index 0000000..172cc10
--- /dev/null
+++ b/annotation/src/test/java/tests/annotation/AllTests.java
@@ -0,0 +1,38 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package tests.annotation;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all tests for the NIO_Char project.
+ */
+public class AllTests {
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(AllTests.suite());
+ }
+
+ public static Test suite() {
+ TestSuite suite = tests.TestSuiteFactory.createTestSuite("All Annotation test suites");
+ // $JUnit-BEGIN$
+ suite.addTest(org.apache.harmony.annotation.tests.java.lang.annotation.AllTests.suite());
+ // $JUnit-END$
+ return suite;
+ }
+}