1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package com.android.multidexlegacytestapp;
17
18import android.test.ActivityInstrumentationTestCase2;
19
20/**
21 * Run the tests with: <code>adb shell am instrument -w
22 com.android.multidexlegacytestapp/android.test.InstrumentationTestRunner
23</code>
24 */
25public class Test extends ActivityInstrumentationTestCase2<MainActivity> {
26    public Test() {
27        super(MainActivity.class);
28    }
29
30    public void testAllClassesAvailable() {
31        assertEquals(3366, getActivity().getValue());
32    }
33
34    public void testAnnotation() throws Exception {
35        assertEquals(ReferencedByAnnotation.B,
36                ((AnnotationWithEnum) TestApplication.annotation).value());
37        assertEquals(ReferencedByAnnotation.B,
38                ((AnnotationWithEnum) TestApplication.getAnnotationWithEnum()).value());
39        // Just to verify that it doesn't crash
40        getActivity().getAnnotation2Value();
41
42        assertEquals(ReferencedByClassInAnnotation.class,
43                ((AnnotationWithClass) TestApplication.annotation3).value());
44        // Just to verify that it doesn't crash
45        ReferencedByClassInAnnotation.A.get();
46
47        // Tests about bug https://code.google.com/p/android/issues/detail?id=78144
48        // Dalvik may throw IllegalAccessError when a class is in a different dex than an enum
49        // used in its annotations.
50        String annotationPackage = "com.android.multidexlegacytestapp.annotation.";
51        Class<?> clazz = Class.forName(annotationPackage + "Annotated");
52        // Just to verify that it doesn't crash
53        clazz.getAnnotations();
54        clazz = Class.forName(annotationPackage + "Annotated2");
55        // Just to verify that it doesn't crash
56        clazz.getAnnotations();
57        clazz = Class.forName(annotationPackage + "Annotated3");
58        // Just to verify that it doesn't crash
59        clazz.getAnnotations();
60    }
61
62    public void testInterface() {
63        assertEquals(InterfaceWithEnum.class,
64                TestApplication.interfaceClass);
65    }
66
67}
68