From 50f811c8fc31fbae4ae41f825d5d7b1166c6b4d4 Mon Sep 17 00:00:00 2001 From: Yohann Roussel Date: Wed, 3 Aug 2016 17:34:45 +0200 Subject: [PATCH] Add tests on MultiDex.installInstrumentation Either with dedicated Instrumentation or with MultiDexTestRunner. Bug: 30575093 Test: Those are tests Change-Id: I97a22625409fd587e1d63fa4207eb72ca67f2c82 --- .../MultiDexLegacyAndException/Android.mk | 13 +--- .../AndroidManifest.xml | 10 ++- .../{Test.java => tests/ActivityTest.java} | 25 +++++-- .../tests/MultiDexAndroidJUnitRunner.java | 31 ++++++++ .../tests/NoActivityIntermediate.java | 25 +++++++ .../tests/NoActivityJUnit3Test.java | 73 +++++++++++++++++++ .../tests/NoActivityJUnit4Test.java | 38 ++++++++++ .../tests/NoActivitySubTest.java | 25 +++++++ .../MultiDexLegacyAndException/test.jpp | 3 - .../MultiDexLegacyTestApp/Android.mk | 4 + .../MultiDexLegacyTestAppTests/Android.mk | 40 ++++++++++ .../AndroidManifest.xml | 19 +++++ .../test/InstrumentationTest.java | 39 ++++++++++ .../test/Intermediate.java | 9 +++ .../multidexlegacytestapp/test/SubTest.java | 11 +++ .../MultiDexLegacyTestAppTests2/Android.mk | 63 ++++++++++++++++ .../AndroidManifest.xml | 16 ++++ .../test2/InstrumentationTest.java | 44 +++++++++++ .../test2/Intermediate.java | 9 +++ .../test2/MultiDexAndroidJUnitRunner.java | 15 ++++ .../multidexlegacytestapp/test2/SubTest.java | 11 +++ 21 files changed, 505 insertions(+), 18 deletions(-) rename core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/{Test.java => tests/ActivityTest.java} (63%) create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/MultiDexAndroidJUnitRunner.java create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivityIntermediate.java create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivityJUnit3Test.java create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivityJUnit4Test.java create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivitySubTest.java delete mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyAndException/test.jpp create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/Android.mk create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/AndroidManifest.xml create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/src/com/android/multidexlegacytestapp/test/InstrumentationTest.java create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/src/com/android/multidexlegacytestapp/test/Intermediate.java create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/src/com/android/multidexlegacytestapp/test/SubTest.java create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/Android.mk create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/AndroidManifest.xml create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/InstrumentationTest.java create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/Intermediate.java create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/MultiDexAndroidJUnitRunner.java create mode 100644 core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/SubTest.java diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/Android.mk b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/Android.mk index 14b032e37f4ce..c66a10cc31f7b 100644 --- a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/Android.mk +++ b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/Android.mk @@ -18,7 +18,7 @@ LOCAL_PATH:= $(call my-dir) ## The application with a minimal main dex include $(CLEAR_VARS) -LOCAL_STATIC_JAVA_LIBRARIES := android-support-multidex +LOCAL_STATIC_JAVA_LIBRARIES := android-support-multidex android-support-multidex-instrumentation android-support-test LOCAL_MODULE_TAGS := tests LOCAL_SRC_FILES := $(call all-java-files-under, src) @@ -35,16 +35,11 @@ mainDexList:= \ $(call intermediates-dir-for,APPS,$(LOCAL_PACKAGE_NAME),$(LOCAL_IS_HOST_MODULE),common)/maindex.list LOCAL_DX_FLAGS := --multi-dex --main-dex-list=$(mainDexList) --minimal-main-dex -LOCAL_JACK_FLAGS := -D jack.dex.output.policy=minimal-multidex -D jack.preprocessor=true\ - -D jack.preprocessor.file=$(LOCAL_PATH)/test.jpp -D jack.dex.output.multidex.legacy=true -################################# -include $(BUILD_SYSTEM)/configure_local_jack.mk -################################# +LOCAL_MIN_SDK_VERSION := 8 -ifdef LOCAL_JACK_ENABLED -LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/test.jpp -endif +LOCAL_JACK_FLAGS := -D jack.dex.output.policy=minimal-multidex \ + -D jack.dex.output.multidex.legacy=true include $(BUILD_PACKAGE) diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/AndroidManifest.xml b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/AndroidManifest.xml index 7fff711186048..98d8f27179fda 100644 --- a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/AndroidManifest.xml +++ b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/AndroidManifest.xml @@ -22,7 +22,15 @@ - + + + + diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/Test.java b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/ActivityTest.java similarity index 63% rename from core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/Test.java rename to core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/ActivityTest.java index 8d065a43ac612..d6ac3e57242bd 100644 --- a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/Test.java +++ b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/ActivityTest.java @@ -13,16 +13,31 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.android.multidexlegacyandexception; +package com.android.multidexlegacyandexception.tests; + +import com.android.multidexlegacyandexception.CaughtOnlyByIntermediateException; +import com.android.multidexlegacyandexception.CaughtOnlyException; +import com.android.multidexlegacyandexception.ExceptionInMainDex; +import com.android.multidexlegacyandexception.ExceptionInMainDex2; +import com.android.multidexlegacyandexception.ExceptionInSecondaryDex; +import com.android.multidexlegacyandexception.ExceptionInSecondaryDex2; +import com.android.multidexlegacyandexception.ExceptionInSecondaryDexWithSuperInMain; +import com.android.multidexlegacyandexception.IntermediateClass; +import com.android.multidexlegacyandexception.MainActivity; +import com.android.multidexlegacyandexception.MiniIntermediateClass; +import com.android.multidexlegacyandexception.SuperExceptionInMainDex; +import com.android.multidexlegacyandexception.SuperExceptionInSecondaryDex; +import com.android.multidexlegacyandexception.TestApplication; /** - * Run the tests with: adb shell am instrument -w - com.android.multidexlegacyandexception/android.test.InstrumentationTestRunner + * Run the tests with: + * +adb shell am instrument -w com.android.multidexlegacyandexception/com.android.multidexlegacyandexception.tests.MultiDexAndroidJUnitRunner */ @SuppressWarnings("deprecation") -public class Test extends android.test.ActivityInstrumentationTestCase2 { - public Test() { +public class ActivityTest extends android.test.ActivityInstrumentationTestCase2 { + public ActivityTest() { super(MainActivity.class); } diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/MultiDexAndroidJUnitRunner.java b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/MultiDexAndroidJUnitRunner.java new file mode 100644 index 0000000000000..758ac1dcb4a05 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/MultiDexAndroidJUnitRunner.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2016 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.multidexlegacyandexception.tests; + +import android.os.Bundle; +import android.support.multidex.MultiDex; +import android.support.test.runner.AndroidJUnitRunner; + +public class MultiDexAndroidJUnitRunner extends AndroidJUnitRunner { + + @Override + public void onCreate(Bundle arguments) { + MultiDex.installInstrumentation(getContext(), getTargetContext()); + super.onCreate(arguments); + } + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivityIntermediate.java b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivityIntermediate.java new file mode 100644 index 0000000000000..3a8acc6b59bef --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivityIntermediate.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2016 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.multidexlegacyandexception.tests; + +public class NoActivityIntermediate { + + public static int get() { + return NoActivitySubTest.get(); + } + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivityJUnit3Test.java b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivityJUnit3Test.java new file mode 100644 index 0000000000000..31cb939813d3c --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivityJUnit3Test.java @@ -0,0 +1,73 @@ +/* + * 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.multidexlegacyandexception.tests; + +import android.test.InstrumentationTestCase; +import com.android.multidexlegacyandexception.CaughtOnlyByIntermediateException; +import com.android.multidexlegacyandexception.CaughtOnlyException; +import com.android.multidexlegacyandexception.ExceptionInMainDex; +import com.android.multidexlegacyandexception.ExceptionInMainDex2; +import com.android.multidexlegacyandexception.ExceptionInSecondaryDex; +import com.android.multidexlegacyandexception.ExceptionInSecondaryDex2; +import com.android.multidexlegacyandexception.ExceptionInSecondaryDexWithSuperInMain; +import com.android.multidexlegacyandexception.IntermediateClass; +import com.android.multidexlegacyandexception.MiniIntermediateClass; +import com.android.multidexlegacyandexception.SuperExceptionInMainDex; +import com.android.multidexlegacyandexception.SuperExceptionInSecondaryDex; +import com.android.multidexlegacyandexception.TestApplication; +import junit.framework.Assert; + +/** + * Run the tests with: +adb shell am instrument -w com.android.multidexlegacyandexception/com.android.test.runner.MultiDexTestRunner + + * or +adb shell am instrument -w com.android.multidexlegacyandexception/com.android.multidexlegacyandexception.tests.MultiDexAndroidJUnitRunner + + */ +@SuppressWarnings("deprecation") +public class NoActivityJUnit3Test extends InstrumentationTestCase { + + @org.junit.Test + public void testExceptionInMainDex() { + Assert.assertEquals(10, TestApplication.get(true)); + } + + @org.junit.Test + public void testExceptionInIntermediate() { + Assert.assertEquals(11, IntermediateClass.get3(true)); + Assert.assertEquals(11, MiniIntermediateClass.get3(true)); + Assert.assertEquals(11, IntermediateClass.get4(true)); + Assert.assertEquals(1, IntermediateClass.get5(null)); + Assert.assertEquals(10, IntermediateClass.get5(new ExceptionInMainDex())); + Assert.assertEquals(11, IntermediateClass.get5(new ExceptionInSecondaryDex())); + Assert.assertEquals(12, IntermediateClass.get5(new ExceptionInMainDex2())); + Assert.assertEquals(13, IntermediateClass.get5(new ExceptionInSecondaryDex2())); + Assert.assertEquals(14, IntermediateClass.get5(new OutOfMemoryError())); + Assert.assertEquals(17, IntermediateClass.get5(new CaughtOnlyException())); + Assert.assertEquals(39, IntermediateClass.get5(new ExceptionInSecondaryDexWithSuperInMain())); + Assert.assertEquals(23, IntermediateClass.get5(new SuperExceptionInSecondaryDex())); + Assert.assertEquals(23, IntermediateClass.get5(new SuperExceptionInMainDex())); + Assert.assertEquals(23, IntermediateClass.get5(new CaughtOnlyByIntermediateException())); + Assert.assertEquals(37, IntermediateClass.get5(new ArrayIndexOutOfBoundsException())); + } + + @org.junit.Test + public void testMultidexedTest() { + Assert.assertEquals(7, NoActivityIntermediate.get()); + } + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivityJUnit4Test.java b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivityJUnit4Test.java new file mode 100644 index 0000000000000..94a5b7fa66f26 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivityJUnit4Test.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2016 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.multidexlegacyandexception.tests; + +import android.support.test.runner.AndroidJUnit4; +import org.junit.runner.RunWith; + +/** + * Run the tests with: +adb shell am instrument -w com.android.multidexlegacyandexception/com.android.test.runner.MultiDexTestRunner + + * or +adb shell am instrument -w com.android.multidexlegacyandexception/com.android.multidexlegacyandexception.tests.MultiDexAndroidJUnitRunner + + */ +@RunWith(AndroidJUnit4.class) +public class NoActivityJUnit4Test extends NoActivityJUnit3Test { + + @org.junit.Test + public void multidexedTestJUnit4() { + super.testMultidexedTest(); + } + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivitySubTest.java b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivitySubTest.java new file mode 100644 index 0000000000000..4885c2ef58657 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/src/com/android/multidexlegacyandexception/tests/NoActivitySubTest.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2016 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.multidexlegacyandexception.tests; + +public class NoActivitySubTest { + + public static int get() { + return 7; + } + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/test.jpp b/core/tests/hosttests/test-apps/MultiDexLegacyAndException/test.jpp deleted file mode 100644 index 0d027ed236fb9..0000000000000 --- a/core/tests/hosttests/test-apps/MultiDexLegacyAndException/test.jpp +++ /dev/null @@ -1,3 +0,0 @@ -test: - @@com.android.jack.annotations.ForceInMainDex - class com.android.multidexlegacyandexception.Test diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/Android.mk b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/Android.mk index 208eceb6273d9..278419315779e 100644 --- a/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/Android.mk +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestApp/Android.mk @@ -44,6 +44,8 @@ ifdef LOCAL_JACK_ENABLED LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/test.jpp endif +LOCAL_MIN_SDK_VERSION := 8 + include $(BUILD_PACKAGE) ifndef LOCAL_JACK_ENABLED @@ -85,6 +87,8 @@ ifdef LOCAL_JACK_ENABLED LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/test.jpp endif +LOCAL_MIN_SDK_VERSION := 8 + include $(BUILD_PACKAGE) ifndef LOCAL_JACK_ENABLED diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/Android.mk b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/Android.mk new file mode 100644 index 0000000000000..69ec5ceb1daf9 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/Android.mk @@ -0,0 +1,40 @@ +# 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. + +LOCAL_PATH:= $(call my-dir) + + +## The application with a minimal main dex +include $(CLEAR_VARS) + +LOCAL_STATIC_JAVA_LIBRARIES := android-support-multidex-instrumentation +LOCAL_MODULE_TAGS := tests + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_SDK_VERSION := 8 + +LOCAL_PACKAGE_NAME := MultiDexLegacyTestAppTests + +LOCAL_DEX_PREOPT := false + +LOCAL_JAVACFLAGS := -nowarn + +LOCAL_MIN_SDK_VERSION := 8 + +LOCAL_INSTRUMENTATION_FOR := MultiDexLegacyTestApp + +LOCAL_JACK_FLAGS := -D jack.dex.output.policy=minimal-multidex -D jack.dex.output.multidex.legacy=true + +include $(BUILD_PACKAGE) diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/AndroidManifest.xml b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/AndroidManifest.xml new file mode 100644 index 0000000000000..35369c7da6a14 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/src/com/android/multidexlegacytestapp/test/InstrumentationTest.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/src/com/android/multidexlegacytestapp/test/InstrumentationTest.java new file mode 100644 index 0000000000000..a0288f2e0d9c2 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/src/com/android/multidexlegacytestapp/test/InstrumentationTest.java @@ -0,0 +1,39 @@ +/* + * 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.test; + +import android.test.InstrumentationTestCase; +import com.android.multidexlegacytestapp.manymethods.Big001; +import com.android.multidexlegacytestapp.manymethods.Big079; +import junit.framework.Assert; + +/** + * Run the tests with: +adb shell am instrument -w com.android.multidexlegacytestapp.test/com.android.test.runner.MultiDexTestRunner + + */ +public class InstrumentationTest extends InstrumentationTestCase { + + public void testExceptionInMainDex() { + Assert.assertEquals(0, new Big001().get0()); + Assert.assertEquals(100, new Big079().get100()); + } + + public void testMultidexedTest() { + Assert.assertEquals(7, Intermediate.get()); + } + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/src/com/android/multidexlegacytestapp/test/Intermediate.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/src/com/android/multidexlegacytestapp/test/Intermediate.java new file mode 100644 index 0000000000000..9a79c7aa4db70 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/src/com/android/multidexlegacytestapp/test/Intermediate.java @@ -0,0 +1,9 @@ +package com.android.multidexlegacytestapp.test; + +public class Intermediate { + + public static int get() { + return SubTest.get(); + } + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/src/com/android/multidexlegacytestapp/test/SubTest.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/src/com/android/multidexlegacytestapp/test/SubTest.java new file mode 100644 index 0000000000000..e28584b5f321b --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests/src/com/android/multidexlegacytestapp/test/SubTest.java @@ -0,0 +1,11 @@ +package com.android.multidexlegacytestapp.test; + +import com.android.multidexlegacytestapp.manymethods.Big080; + +public class SubTest { + + public static int get() { + return new Big080().get7(); + } + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/Android.mk b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/Android.mk new file mode 100644 index 0000000000000..f2bd353630033 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/Android.mk @@ -0,0 +1,63 @@ +# 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. + +LOCAL_PATH:= $(call my-dir) + + +## The tests with only one dex +include $(CLEAR_VARS) + +LOCAL_STATIC_JAVA_LIBRARIES := android-support-multidex-instrumentation android-support-test +LOCAL_MODULE_TAGS := tests + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_SDK_VERSION := current + +LOCAL_PACKAGE_NAME := MultiDexLegacyTestAppTests2 + +LOCAL_DEX_PREOPT := false + +LOCAL_JAVACFLAGS := -nowarn + +LOCAL_MIN_SDK_VERSION := 8 + +LOCAL_INSTRUMENTATION_FOR := MultiDexLegacyTestApp + +include $(BUILD_PACKAGE) + + +## The tests with a minimal main dex +include $(CLEAR_VARS) + +LOCAL_STATIC_JAVA_LIBRARIES := android-support-multidex-instrumentation android-support-test +LOCAL_MODULE_TAGS := tests + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_SDK_VERSION := 8 + +LOCAL_PACKAGE_NAME := MultiDexLegacyTestAppTests2-multidex + +LOCAL_DEX_PREOPT := false + +LOCAL_JAVACFLAGS := -nowarn + +LOCAL_MIN_SDK_VERSION := 8 + +LOCAL_INSTRUMENTATION_FOR := MultiDexLegacyTestApp + +LOCAL_JACK_FLAGS := -D jack.dex.output.policy=minimal-multidex -D jack.dex.output.multidex.legacy=true + +include $(BUILD_PACKAGE) diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/AndroidManifest.xml b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/AndroidManifest.xml new file mode 100644 index 0000000000000..1cadfcdf3b810 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/AndroidManifest.xml @@ -0,0 +1,16 @@ + + + + + + + + + + \ No newline at end of file diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/InstrumentationTest.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/InstrumentationTest.java new file mode 100644 index 0000000000000..4e6ec142e690b --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/InstrumentationTest.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.test2; + +import android.support.test.runner.AndroidJUnit4; +import com.android.multidexlegacytestapp.manymethods.Big001; +import com.android.multidexlegacytestapp.manymethods.Big079; +import junit.framework.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Run the tests with: adb shell am instrument -w + com.android.multidexlegacytestapp.test2/com.android.multidexlegacytestapp.test2.MultiDexAndroidJUnitRunner + + */ +@RunWith(AndroidJUnit4.class) +public class InstrumentationTest { + + @Test + public void exceptionInMainDex() { + Assert.assertEquals(0, new Big001().get0()); + Assert.assertEquals(100, new Big079().get100()); + } + + @Test + public void multidexedTest() { + Assert.assertEquals(7, Intermediate.get()); + } + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/Intermediate.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/Intermediate.java new file mode 100644 index 0000000000000..3e5e81e5babb1 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/Intermediate.java @@ -0,0 +1,9 @@ +package com.android.multidexlegacytestapp.test2; + +public class Intermediate { + + public static int get() { + return SubTest.get(); + } + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/MultiDexAndroidJUnitRunner.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/MultiDexAndroidJUnitRunner.java new file mode 100644 index 0000000000000..963f90432dd76 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/MultiDexAndroidJUnitRunner.java @@ -0,0 +1,15 @@ +package com.android.multidexlegacytestapp.test2; + +import android.os.Bundle; +import android.support.multidex.MultiDex; +import android.support.test.runner.AndroidJUnitRunner; + +public class MultiDexAndroidJUnitRunner extends AndroidJUnitRunner { + + @Override + public void onCreate(Bundle arguments) { + MultiDex.installInstrumentation(getContext(), getTargetContext()); + super.onCreate(arguments); + } + +} diff --git a/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/SubTest.java b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/SubTest.java new file mode 100644 index 0000000000000..acff80fdd8468 --- /dev/null +++ b/core/tests/hosttests/test-apps/MultiDexLegacyTestAppTests2/src/com/android/multidexlegacytestapp/test2/SubTest.java @@ -0,0 +1,11 @@ +package com.android.multidexlegacytestapp.test2; + +import com.android.multidexlegacytestapp.manymethods.Big080; + +public class SubTest { + + public static int get() { + return new Big080().get7(); + } + +}