diff options
author | Yohann Roussel <yroussel@google.com> | 2014-05-15 09:14:46 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-15 09:14:47 +0000 |
commit | 4d806214767ec010cef1d58e706ba59e1f0b9ad0 (patch) | |
tree | 3d5eb02c2befe603157df7c9e7897297598c03e3 /core/tests | |
parent | d04cf4ccf426f70d80e98b46dc74c4dfb18f338f (diff) | |
parent | 905b33a486631d296670fa1fdf9d41daefb69a36 (diff) | |
download | frameworks_base-4d806214767ec010cef1d58e706ba59e1f0b9ad0.zip frameworks_base-4d806214767ec010cef1d58e706ba59e1f0b9ad0.tar.gz frameworks_base-4d806214767ec010cef1d58e706ba59e1f0b9ad0.tar.bz2 |
Merge "Test multidex and annotations access."
Diffstat (limited to 'core/tests')
15 files changed, 366 insertions, 4 deletions
diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/AndroidManifest.xml b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/AndroidManifest.xml index d69a63b..6bd47c2 100644 --- a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/AndroidManifest.xml +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/AndroidManifest.xml @@ -7,6 +7,7 @@ <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18"/> <application + android:name=".TestApplication" android:label="multidexlegacytestapp" > <activity diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/Annotated.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/Annotated.java new file mode 100644 index 0000000..603c573 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/Annotated.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2014 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 com.android.multidexlegacytestapp; + +@AnnotationWithEnum2(ReferencedByAnnotationWithOtherReferences.A) +public class Annotated { + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/Annotated2.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/Annotated2.java new file mode 100644 index 0000000..eed6875 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/Annotated2.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2014 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 com.android.multidexlegacytestapp; + +@AnnotationWithClass(ReferencedByClassInAnnotation.class) +public class Annotated2 { + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/AnnotationWithClass.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/AnnotationWithClass.java new file mode 100644 index 0000000..378a024 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/AnnotationWithClass.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2014 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 com.android.multidexlegacytestapp; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface AnnotationWithClass { + + Class<?> value(); + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/AnnotationWithEnum.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/AnnotationWithEnum.java new file mode 100644 index 0000000..15855d5 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/AnnotationWithEnum.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2014 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 com.android.multidexlegacytestapp; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface AnnotationWithEnum { + + ReferencedByAnnotation value(); + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/AnnotationWithEnum2.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/AnnotationWithEnum2.java new file mode 100644 index 0000000..ce37b18 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/AnnotationWithEnum2.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2014 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 com.android.multidexlegacytestapp; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface AnnotationWithEnum2 { + + ReferencedByAnnotationWithOtherReferences value(); + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/InterfaceWithEnum.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/InterfaceWithEnum.java new file mode 100644 index 0000000..085c0a3 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/InterfaceWithEnum.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2014 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 com.android.multidexlegacytestapp; + +public interface InterfaceWithEnum { + + ReferencedByInterface getEnum(); + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/MainActivity.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/MainActivity.java index 3228825..5bc03f1 100644 --- a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/MainActivity.java +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/MainActivity.java @@ -17,7 +17,6 @@ package com.android.multidexlegacytestapp; import android.app.Activity; import android.os.Bundle; -import android.support.multidex.MultiDex; import android.util.Log; import android.widget.TextView; @@ -36,9 +35,6 @@ public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { - Log.i(TAG, "onCreate"); - MultiDex.install(getApplicationContext()); - Log.i(TAG, "Multi dex installation done."); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); int value = getValue(); @@ -94,4 +90,8 @@ public class MainActivity extends Activity { return value; } + public int getAnnotation2Value() { + return ((AnnotationWithEnum2) TestApplication.annotation2).value().get(); + } + } diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByAnnotation.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByAnnotation.java new file mode 100644 index 0000000..0aa6995 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByAnnotation.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2014 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 com.android.multidexlegacytestapp; + +public enum ReferencedByAnnotation { + + A, + B; + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByAnnotationWithOtherReferences.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByAnnotationWithOtherReferences.java new file mode 100644 index 0000000..8cc0d9d --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByAnnotationWithOtherReferences.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2014 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 com.android.multidexlegacytestapp; + +public enum ReferencedByAnnotationWithOtherReferences { + + A { + private ReferencedByEnum a = new ReferencedByEnum(); + @Override + public int get() { + return a.hashCode(); + } + }, + B { + private ReferencedByEnum b = new ReferencedByEnum(); + @Override + public int get() { + return b.hashCode(); + } + }; + + + public abstract int get(); +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByClassInAnnotation.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByClassInAnnotation.java new file mode 100644 index 0000000..06aa560 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByClassInAnnotation.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2014 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 com.android.multidexlegacytestapp; + +public enum ReferencedByClassInAnnotation { + + A { + private ReferencedByEnum a = new ReferencedByEnum(); + @Override + public int get() { + return a.hashCode(); + } + }, + B { + private ReferencedByEnum b = new ReferencedByEnum(); + @Override + public int get() { + return b.hashCode(); + } + }; + + + public abstract int get(); +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByEnum.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByEnum.java new file mode 100644 index 0000000..1ceb3d3 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByEnum.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2014 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 com.android.multidexlegacytestapp; + +public class ReferencedByEnum { + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByInterface.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByInterface.java new file mode 100644 index 0000000..17f1449 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/ReferencedByInterface.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2014 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 com.android.multidexlegacytestapp; + +public enum ReferencedByInterface { + + A, + B; + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/Test.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/Test.java index 59cac07..bbdd3e5 100644 --- a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/Test.java +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/Test.java @@ -17,6 +17,11 @@ package com.android.multidexlegacytestapp; import android.test.ActivityInstrumentationTestCase2; +/** + * Run the tests with: <code>adb shell am instrument -w + com.android.multidexlegacytestapp/android.test.InstrumentationTestRunner +</code> + */ public class Test extends ActivityInstrumentationTestCase2<MainActivity> { public Test() { super(MainActivity.class); @@ -25,4 +30,23 @@ public class Test extends ActivityInstrumentationTestCase2<MainActivity> { public void testAllClassesAvailable() { assertEquals(3366, getActivity().getValue()); } + + public void testAnnotation() { + assertEquals(ReferencedByAnnotation.B, + ((AnnotationWithEnum) TestApplication.annotation).value()); + assertEquals(ReferencedByAnnotation.B, + ((AnnotationWithEnum) TestApplication.getAnnotationWithEnum()).value()); + // Just to verify that it doesn't crash + getActivity().getAnnotation2Value(); + + assertEquals(ReferencedByClassInAnnotation.class, + ((AnnotationWithClass) TestApplication.annotation3).value()); + // Just to verify that it doesn't crash + ReferencedByClassInAnnotation.A.get(); + } + + public void testInterface() { + assertEquals(InterfaceWithEnum.class, + TestApplication.interfaceClass); + } } diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/TestApplication.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/TestApplication.java new file mode 100644 index 0000000..c52ad29 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/src/com/android/multidexlegacytestapp/TestApplication.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2014 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 com.android.multidexlegacytestapp; + +import android.support.multidex.MultiDexApplication; + +import java.lang.annotation.Annotation; + +@AnnotationWithEnum(ReferencedByAnnotation.B) +public class TestApplication extends MultiDexApplication { + + public static Annotation annotation = getAnnotationWithEnum(); + public static Annotation annotation2 = getSoleAnnotation(Annotated.class); + public static Annotation annotation3 = getSoleAnnotation(Annotated2.class); + public static Class<?> interfaceClass = InterfaceWithEnum.class; + + public static Annotation getAnnotationWithEnum() { + return getSoleAnnotation(TestApplication.class); + } + + public static Annotation getSoleAnnotation(Class<?> annotated) { + Annotation[] annot = annotated.getAnnotations(); + if (annot.length == 1) { + return annot[0]; + } + + throw new AssertionError(); + } + +} |