1185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel/* 2185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * Copyright (C) 2014 The Android Open Source Project 3185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * 4185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * use this file except in compliance with the License. You may obtain a copy of 6185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * the License at 7185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * 8185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * http://www.apache.org/licenses/LICENSE-2.0 9185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * 10185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * Unless required by applicable law or agreed to in writing, software 11185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * License for the specific language governing permissions and limitations under 14185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel * the License. 15185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel */ 16185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Rousselpackage com.android.multidexlegacytestapp; 17185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel 18185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Rousselimport android.test.ActivityInstrumentationTestCase2; 19185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel 20905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel/** 21905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel * Run the tests with: <code>adb shell am instrument -w 22905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel com.android.multidexlegacytestapp/android.test.InstrumentationTestRunner 23905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel</code> 24905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel */ 25185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Rousselpublic class Test extends ActivityInstrumentationTestCase2<MainActivity> { 26185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel public Test() { 27185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel super(MainActivity.class); 28185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel } 29185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel 30185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel public void testAllClassesAvailable() { 31185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel assertEquals(3366, getActivity().getValue()); 32185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel } 33905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel 3479b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel public void testAnnotation() throws Exception { 35905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel assertEquals(ReferencedByAnnotation.B, 36905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel ((AnnotationWithEnum) TestApplication.annotation).value()); 37905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel assertEquals(ReferencedByAnnotation.B, 38905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel ((AnnotationWithEnum) TestApplication.getAnnotationWithEnum()).value()); 39905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel // Just to verify that it doesn't crash 40905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel getActivity().getAnnotation2Value(); 41905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel 42905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel assertEquals(ReferencedByClassInAnnotation.class, 43905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel ((AnnotationWithClass) TestApplication.annotation3).value()); 44905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel // Just to verify that it doesn't crash 45905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel ReferencedByClassInAnnotation.A.get(); 4679b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel 4779b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel // Tests about bug https://code.google.com/p/android/issues/detail?id=78144 4879b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel // Dalvik may throw IllegalAccessError when a class is in a different dex than an enum 4979b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel // used in its annotations. 5079b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel String annotationPackage = "com.android.multidexlegacytestapp.annotation."; 5179b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel Class<?> clazz = Class.forName(annotationPackage + "Annotated"); 5279b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel // Just to verify that it doesn't crash 5379b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel clazz.getAnnotations(); 5479b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel clazz = Class.forName(annotationPackage + "Annotated2"); 5579b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel // Just to verify that it doesn't crash 5679b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel clazz.getAnnotations(); 5779b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel clazz = Class.forName(annotationPackage + "Annotated3"); 5879b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel // Just to verify that it doesn't crash 5979b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel clazz.getAnnotations(); 60905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel } 61905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel 62905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel public void testInterface() { 63905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel assertEquals(InterfaceWithEnum.class, 64905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel TestApplication.interfaceClass); 65905b33a486631d296670fa1fdf9d41daefb69a36Yohann Roussel } 6679b4ee8e970867890048d6084129b99e5f09c03bYohann Roussel 67185a7e38bc58abd341445ef9acdec9a4722a6946Yohann Roussel} 68