summaryrefslogtreecommitdiffstats
path: root/jack-tests/tests/com/android
diff options
context:
space:
mode:
authorJean-Marie Henaff <jmhenaff@google.com>2014-05-19 17:34:13 +0200
committerJean-Marie Henaff <jmhenaff@google.com>2014-10-14 10:35:18 +0200
commitf265ce821c48ed54ad8d00060664b55a8f8e1bb7 (patch)
tree798f4464e8669ce31fbd5bbe0a2e3404d4e47ff1 /jack-tests/tests/com/android
parent706b60417fe72a4a70bc61da2f915fe3693dd0c2 (diff)
downloadtoolchain_jack-f265ce821c48ed54ad8d00060664b55a8f8e1bb7.zip
toolchain_jack-f265ce821c48ed54ad8d00060664b55a8f8e1bb7.tar.gz
toolchain_jack-f265ce821c48ed54ad8d00060664b55a8f8e1bb7.tar.bz2
WIP Use JUnit for jack-tests.
(cherry picked from commit 452cbd7d69db557ecdbbd20875a669752cf2d9d7) Change-Id: I96a34b90c9525fa4403f6f940d6fcdf4656722ab
Diffstat (limited to 'jack-tests/tests/com/android')
-rw-r--r--jack-tests/tests/com/android/jack/AllTests.java54
-rw-r--r--jack-tests/tests/com/android/jack/AllWithRegressionTests.java35
-rw-r--r--jack-tests/tests/com/android/jack/RegressionTests.java56
-rw-r--r--jack-tests/tests/com/android/jack/annotation/AnnotationTests.java66
-rw-r--r--jack-tests/tests/com/android/jack/arithmetic/ArithmeticTests.java50
-rw-r--r--jack-tests/tests/com/android/jack/classpath/ClasspathTest.java77
-rw-r--r--jack-tests/tests/com/android/jack/enums/EnumTests.java43
-rw-r--r--jack-tests/tests/com/android/jack/enums/test003/test.properties4
-rw-r--r--jack-tests/tests/com/android/jack/error/AnnotationProcessorErrorTest.java241
-rw-r--r--jack-tests/tests/com/android/jack/error/CommandLineErrorTest.java95
-rw-r--r--jack-tests/tests/com/android/jack/error/FileAccessErrorTest.java180
-rw-r--r--jack-tests/tests/com/android/jack/experimenal/incremental/DependenciesTests005.java80
-rw-r--r--jack-tests/tests/com/android/jack/invoke/test001/jack/InvokeClone.java2
-rw-r--r--jack-tests/tests/com/android/jack/jarjar/JarjarTests.java48
-rw-r--r--jack-tests/tests/com/android/jack/java7/ExceptionsTest.java74
-rw-r--r--jack-tests/tests/com/android/jack/shrob/AbstractTest.java561
-rw-r--r--jack-tests/tests/com/android/jack/shrob/ObfuscationWithoutMappingTests.java166
-rw-r--r--jack-tests/tests/com/android/jack/tools/merger/MergerAllTests.java28
-rw-r--r--jack-tests/tests/com/android/jack/tools/merger/MergerTestTools.java59
-rw-r--r--jack-tests/tests/com/android/jack/tools/merger/test011/MergerTest011.java185
20 files changed, 2103 insertions, 1 deletions
diff --git a/jack-tests/tests/com/android/jack/AllTests.java b/jack-tests/tests/com/android/jack/AllTests.java
new file mode 100644
index 0000000..091867b
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/AllTests.java
@@ -0,0 +1,54 @@
+/*
+ * 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.jack;
+
+import com.android.jack.annotation.AnnotationTests;
+import com.android.jack.arithmetic.ArithmeticTests;
+import com.android.jack.classpath.ClasspathTest;
+import com.android.jack.enums.EnumTests;
+import com.android.jack.error.AnnotationProcessorErrorTest;
+import com.android.jack.error.CommandLineErrorTest;
+import com.android.jack.error.FileAccessErrorTest;
+import com.android.jack.experimenal.incremental.DependenciesTests005;
+import com.android.jack.jarjar.JarjarTests;
+import com.android.jack.shrob.ObfuscationWithoutMappingTests;
+import com.android.jack.tools.merger.MergerAllTests;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ * Test suite containing all tests (except for regression tests that must be run from the command
+ * line).
+ */
+@RunWith(Suite.class)
+@SuiteClasses(value = {
+ AnnotationTests.class,
+ ArithmeticTests.class,
+ ClasspathTest.class,
+ DependenciesTests005.class,
+ EnumTests.class,
+ JarjarTests.class,
+ MergerAllTests.class,
+ ObfuscationWithoutMappingTests.class,
+ AnnotationProcessorErrorTest.class,
+ FileAccessErrorTest.class,
+ CommandLineErrorTest.class
+ })
+public class AllTests {
+}
diff --git a/jack-tests/tests/com/android/jack/AllWithRegressionTests.java b/jack-tests/tests/com/android/jack/AllWithRegressionTests.java
new file mode 100644
index 0000000..4b89472
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/AllWithRegressionTests.java
@@ -0,0 +1,35 @@
+/*
+ * 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.jack;
+
+
+import com.android.jack.test.category.RuntimeRegressionTest;
+
+import org.junit.experimental.categories.Categories;
+import org.junit.experimental.categories.Categories.ExcludeCategory;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+
+/**
+ * Test suite containing tests that are too time-consuming and cannot be run before submitting each
+ * CL.
+ */
+@RunWith(Categories.class)
+@ExcludeCategory(RuntimeRegressionTest.class)
+@SuiteClasses(value = {AllTests.class, RegressionTests.class})
+public class AllWithRegressionTests {
+}
diff --git a/jack-tests/tests/com/android/jack/RegressionTests.java b/jack-tests/tests/com/android/jack/RegressionTests.java
new file mode 100644
index 0000000..3a7ecc6
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/RegressionTests.java
@@ -0,0 +1,56 @@
+/*
+ * 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.jack;
+
+import com.android.jack.annotation.AnnotationTests;
+import com.android.jack.arithmetic.ArithmeticTests;
+import com.android.jack.test.helper.RuntimeTestHelper;
+import com.android.jack.test.runtime.RuntimeTest;
+import com.android.jack.test.runtime.RuntimeTestInfo;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RegressionTests {
+
+ public RuntimeTest[] tests = {
+ new AnnotationTests(),
+ new ArithmeticTests()
+ };
+
+ @BeforeClass
+ public static void setUpClass() {
+ Main.class.getClassLoader().setDefaultAssertionStatus(true);
+ }
+
+ @Test
+ public void runRegressionTests() throws Exception {
+ List<RuntimeTestInfo> rtTestInfos = new ArrayList<RuntimeTestInfo>();
+
+ for (RuntimeTest test : tests) {
+ for (RuntimeTestInfo testInfos : test.getRuntimeTestInfos()) {
+ rtTestInfos.add(testInfos);
+ }
+ }
+ new RuntimeTestHelper(rtTestInfos.toArray(new RuntimeTestInfo[rtTestInfos.size()]))
+ .compileAndRunTest();
+ }
+
+}
diff --git a/jack-tests/tests/com/android/jack/annotation/AnnotationTests.java b/jack-tests/tests/com/android/jack/annotation/AnnotationTests.java
new file mode 100644
index 0000000..e68228e
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/annotation/AnnotationTests.java
@@ -0,0 +1,66 @@
+/*
+ * 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.jack.annotation;
+
+import com.android.jack.Main;
+import com.android.jack.test.category.RuntimeRegressionTest;
+import com.android.jack.test.helper.CheckDexStructureTestHelper;
+import com.android.jack.test.helper.RuntimeTestHelper;
+import com.android.jack.test.runtime.RuntimeTest;
+import com.android.jack.test.runtime.RuntimeTestInfo;
+import com.android.jack.test.toolchain.AbstractTestTools;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+
+public class AnnotationTests extends RuntimeTest {
+
+ private static final File ANNOTATION001_PATH =
+ AbstractTestTools.getTestRootDir("com.android.jack.annotation.test001.jack");
+
+ private RuntimeTestInfo TEST001 = new RuntimeTestInfo(
+ AbstractTestTools.getTestRootDir("com.android.jack.annotation.test001"),
+ "com.android.jack.annotation.test001.dx.Tests");
+
+ @BeforeClass
+ public static void setUpClass() {
+ Main.class.getClassLoader().setDefaultAssertionStatus(true);
+ }
+
+ @Test
+ public void checkStructure() throws Exception {
+ CheckDexStructureTestHelper env =
+ new CheckDexStructureTestHelper(new File(ANNOTATION001_PATH, "Annotation2.java"));
+ env.setWithDebugInfo(true);
+ env.compare();
+ }
+
+ @Test
+ @Category(RuntimeRegressionTest.class)
+ public void runtimeTest001() throws Exception {
+ new RuntimeTestHelper(TEST001).compileAndRunTest();
+ }
+
+ @Override
+ protected void fillRtTestInfos() {
+ rtTestInfos.add(TEST001);
+ }
+
+}
diff --git a/jack-tests/tests/com/android/jack/arithmetic/ArithmeticTests.java b/jack-tests/tests/com/android/jack/arithmetic/ArithmeticTests.java
new file mode 100644
index 0000000..1b6ee1a
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/arithmetic/ArithmeticTests.java
@@ -0,0 +1,50 @@
+/*
+ * 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.jack.arithmetic;
+
+import com.android.jack.test.category.RuntimeRegressionTest;
+import com.android.jack.test.helper.RuntimeTestHelper;
+import com.android.jack.test.runtime.RuntimeTest;
+import com.android.jack.test.runtime.RuntimeTestInfo;
+import com.android.jack.test.toolchain.AbstractTestTools;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+public class ArithmeticTests extends RuntimeTest {
+
+ private RuntimeTestInfo TEST001 = new RuntimeTestInfo(
+ AbstractTestTools.getTestRootDir("com.android.jack.arithmetic.test001"),
+ "com.android.jack.arithmetic.test001.dx.Tests");
+
+ @BeforeClass
+ public static void setUpClass() {
+ ArithmeticTests.class.getClassLoader().setDefaultAssertionStatus(true);
+ }
+
+ @Test
+ @Category(RuntimeRegressionTest.class)
+ public void test001() throws Exception {
+ new RuntimeTestHelper(TEST001).compileAndRunTest();
+ }
+
+ @Override
+ protected void fillRtTestInfos() {
+ rtTestInfos.add(TEST001);
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/classpath/ClasspathTest.java b/jack-tests/tests/com/android/jack/classpath/ClasspathTest.java
new file mode 100644
index 0000000..8fde038
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/classpath/ClasspathTest.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2012 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.jack.classpath;
+
+import com.android.jack.test.toolchain.AbstractTestTools;
+import com.android.jack.test.toolchain.IToolchain;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.File;
+
+public class ClasspathTest {
+
+ @BeforeClass
+ public static void setUpClass() {
+ ClasspathTest.class.getClassLoader().setDefaultAssertionStatus(true);
+ }
+
+ @Test
+ public void test001() throws Exception {
+ File libOut = AbstractTestTools.createTempDir();
+
+ IToolchain toolchain = AbstractTestTools.getCandidateToolchain();
+ toolchain.srcToLib(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()),
+ libOut, false,
+ new File(AbstractTestTools.getTestRootDir("com.android.jack.classpath.test001"), "lib"));
+
+ File testOut = AbstractTestTools.createTempDir();
+ toolchain.srcToLib(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath())
+ + File.pathSeparatorChar + libOut.getAbsolutePath(), testOut, false,
+ new File(AbstractTestTools.getTestRootDir("com.android.jack.classpath.test001"), "jack"));
+ }
+
+ @Test
+ public void test002() throws Exception {
+ IToolchain toolchain = AbstractTestTools.getCandidateToolchain();
+
+ File testFolder = AbstractTestTools.getTestRootDir("com.android.jack.classpath.test002");
+ File outFolder = AbstractTestTools.createTempDir();
+
+ File lib1Out = AbstractTestTools.createDir(outFolder, "lib1");
+ toolchain.srcToLib(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()),
+ lib1Out,
+ /* zipFiles = */ false, new File(testFolder, "lib1"));
+
+ File lib1BisOut = AbstractTestTools.createDir(outFolder, "lib1override");
+ toolchain.srcToLib(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath()),
+ lib1BisOut,
+ /* zipFiles = */false, new File(testFolder, "lib1override"));
+
+ File lib2Out = AbstractTestTools.createDir(outFolder, "lib2");
+ toolchain.srcToLib(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath())
+ + File.pathSeparatorChar + lib1Out.getAbsolutePath(), lib2Out,
+ /* zipFiles = */false, new File(testFolder, "lib2"));
+
+ toolchain.addStaticLibs(lib2Out);
+ toolchain.srcToExe(AbstractTestTools.getClasspathAsString(toolchain.getDefaultBootClasspath())
+ + File.pathSeparatorChar + lib1BisOut.getAbsolutePath(), outFolder,
+ new File(testFolder, "jack"));
+
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/enums/EnumTests.java b/jack-tests/tests/com/android/jack/enums/EnumTests.java
new file mode 100644
index 0000000..361e6a6
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/enums/EnumTests.java
@@ -0,0 +1,43 @@
+/*
+ * 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.jack.enums;
+
+import com.android.jack.test.helper.RuntimeTestHelper;
+import com.android.jack.test.runtime.RuntimeTestInfo;
+import com.android.jack.test.toolchain.AbstractTestTools;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+
+public class EnumTests {
+
+ private File baseDir;
+
+ @Before
+ public void setUp() {
+ baseDir = AbstractTestTools.getTestRootDir("com.android.jack.enums.test003");
+ }
+
+ @Test
+ public void compileAndRunTest() throws Exception {
+ new RuntimeTestHelper(new RuntimeTestInfo(baseDir, "com.android.jack.enums.test003.dx.Tests"))
+ .compileAndRunTest();
+ }
+
+}
diff --git a/jack-tests/tests/com/android/jack/enums/test003/test.properties b/jack-tests/tests/com/android/jack/enums/test003/test.properties
new file mode 100644
index 0000000..e3646b8
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/enums/test003/test.properties
@@ -0,0 +1,4 @@
+rt.args.DalvikRunnerHost=-Xdexopt:none -Xverify:none
+rt.args.DalvikRunnerDevice=-Xdexopt:none -Xverify:none
+rt.args.ArtRunnerHost=-Xdexopt:none -Xverify:none
+rt.args.ArtRunnerDevice=-Xdexopt:none -Xverify:none
diff --git a/jack-tests/tests/com/android/jack/error/AnnotationProcessorErrorTest.java b/jack-tests/tests/com/android/jack/error/AnnotationProcessorErrorTest.java
new file mode 100644
index 0000000..fea5b18
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/error/AnnotationProcessorErrorTest.java
@@ -0,0 +1,241 @@
+/*
+ * 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.jack.error;
+
+import com.google.common.io.Files;
+
+import com.android.jack.JackUserException;
+import com.android.jack.Main;
+import com.android.jack.errorhandling.annotationprocessor.ResourceAnnotationProcessor;
+import com.android.jack.errorhandling.annotationprocessor.ResourceAnnotationTest;
+import com.android.jack.errorhandling.annotationprocessor.SourceAnnotationProcessor;
+import com.android.jack.errorhandling.annotationprocessor.SourceAnnotationTest;
+import com.android.jack.errorhandling.annotationprocessor.SourceErrorAnnotationTest;
+import com.android.jack.frontend.FrontendCompilationException;
+import com.android.jack.test.helper.ErrorTestHelper;
+import com.android.jack.test.toolchain.AbstractTestTools;
+import com.android.jack.test.toolchain.JackApiToolchain;
+
+import junit.framework.Assert;
+
+import org.jf.dexlib.ClassDefItem;
+import org.jf.dexlib.DexFile;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileReader;
+import java.io.LineNumberReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Nonnull;
+
+/**
+ * JUnit test checking Jack behavior when using annotation processor.
+ */
+public class AnnotationProcessorErrorTest {
+
+ @BeforeClass
+ public static void setUpClass() {
+ Main.class.getClassLoader().setDefaultAssertionStatus(true);
+ }
+
+ /**
+ * Checks that compilation fails correctly when annotation processor is called without specifying
+ * output folder.
+ */
+ @Test
+ public void testAnnotationProcessorError001() throws Exception {
+ ErrorTestHelper te = new ErrorTestHelper();
+
+ AbstractTestTools.createJavaFile(te.getSourceFolder(),"jack.incremental", "A.java",
+ "package jack.incremental; \n"+
+ "public class A {} \n");
+
+ JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+ jackApiToolchain.setAnnotationProcessorClass(ResourceAnnotationProcessor.class);
+
+ try {
+ jackApiToolchain.srcToExe(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()),
+ te.getOutputDexFolder(), te.getSourceFolder());
+ Assert.fail();
+ } catch (JackUserException e) {
+ // Failure is ok since output for annotation processor is not specify.
+ Assert.assertTrue(e.getMessage().contains("Unknown location"));
+ }
+ }
+
+ /**
+ * Checks that compilation succeed when running annotation processor to generate resource file.
+ */
+ @Test
+ public void testAnnotationProcessorError002() throws Exception {
+ runAnnotProcBuildingResource(new ErrorTestHelper());
+ }
+
+ /**
+ * Checks that last compilation failed since the resource created by annotation processor already
+ * exist.
+ */
+ @Test
+ public void testAnnotationProcessorError003() throws Exception {
+ ErrorTestHelper te = new ErrorTestHelper();
+
+ runAnnotProcBuildingResource(te);
+
+ JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+ jackApiToolchain.setAnnotationProcessorClass(ResourceAnnotationProcessor.class);
+ jackApiToolchain.setAnnotationProcessorOutDir(te.getTestingFolder());
+ ByteArrayOutputStream errOut = new ByteArrayOutputStream();
+ jackApiToolchain.setErrorStream(errOut);
+
+ try {
+
+ jackApiToolchain.srcToExe(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath())
+ + File.pathSeparator + te.getJackFolder(), te.getOutputDexFolder(), te.getSourceFolder());
+
+ Assert.fail();
+ } catch (FrontendCompilationException e) {
+ // Failure is ok since created file already exists
+ } finally {
+ Assert.assertTrue(errOut.toString().contains("Resource already created"));
+ }
+ }
+
+ /**
+ * Checks that compilation failed since the source file generated by the annotation processor
+ * does not compile.
+ */
+ @Test
+ public void testAnnotationProcessorError004() throws Exception {
+ ErrorTestHelper te = new ErrorTestHelper();
+
+ buildAnnotationRequiredByAnnotationProc(te, new Class<?>[] {SourceAnnotationTest.class,
+ SourceErrorAnnotationTest.class});
+
+ AbstractTestTools.createJavaFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental;\n"
+ + "import " + SourceErrorAnnotationTest.class.getName() + ";\n"
+ + "@" + SourceErrorAnnotationTest.class.getSimpleName() + "\n"
+ + "public class A {}\n");
+
+
+ JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+ jackApiToolchain.setAnnotationProcessorClass(SourceAnnotationProcessor.class);
+ jackApiToolchain.setAnnotationProcessorOutDir(te.getTestingFolder());
+ ByteArrayOutputStream errOut = new ByteArrayOutputStream();
+ jackApiToolchain.setErrorStream(errOut);
+
+ try {
+ jackApiToolchain.srcToExe(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath())
+ + File.pathSeparator + te.getJackFolder(), te.getOutputDexFolder(), te.getSourceFolder());
+ Assert.fail();
+ } catch (FrontendCompilationException ex) {
+ // Failure is ok since source generated by annotation processor does not compile.
+ } finally {
+ Assert.assertTrue(errOut.toString().contains("Syntax error on tokens, delete these tokens"));
+ }
+ }
+
+ /**
+ * Checks that compilation succeed to compile source file generated by the annotation processor.
+ */
+ @Test
+ public void testAnnotationProcessorError005() throws Exception {
+ ErrorTestHelper te = new ErrorTestHelper();
+
+ buildAnnotationRequiredByAnnotationProc(te, new Class<?>[] {SourceAnnotationTest.class,
+ SourceErrorAnnotationTest.class});
+
+ AbstractTestTools.createJavaFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental;\n"
+ + "import " + SourceAnnotationTest.class.getName() + ";\n"
+ + "@" + SourceAnnotationTest.class.getSimpleName() + "\n"
+ + "public class A {}\n");
+
+ JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+ jackApiToolchain.setAnnotationProcessorClass(SourceAnnotationProcessor.class);
+ jackApiToolchain.setAnnotationProcessorOutDir(te.getTestingFolder());
+
+ File dexOutput = te.getOutputDexFolder();
+ jackApiToolchain.srcToExe(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath())
+ + File.pathSeparator + te.getJackFolder(), dexOutput, te.getSourceFolder());
+
+ DexFile dexFile = new DexFile(new File(dexOutput, jackApiToolchain.getBinaryFileName()));
+ List<String> sourceFileInDex = new ArrayList<String>();
+ for (ClassDefItem classDef : dexFile.ClassDefsSection.getItems()) {
+ sourceFileInDex.add(classDef.getSourceFile().getStringValue());
+ }
+
+ Assert.assertTrue(sourceFileInDex.contains("ADuplicated.java"));
+ Assert.assertTrue(sourceFileInDex.contains("A.java"));
+ }
+
+ private void runAnnotProcBuildingResource(@Nonnull ErrorTestHelper te) throws Exception {
+
+ buildAnnotationRequiredByAnnotationProc(te, new Class<?>[] {ResourceAnnotationTest.class});
+
+ AbstractTestTools.createJavaFile(te.getSourceFolder(), "jack.incremental", "A.java", "package jack.incremental;\n"
+ + "import " + ResourceAnnotationTest.class.getName() + ";\n"
+ + "@" + ResourceAnnotationTest.class.getSimpleName() + "\n"
+ + "public class A {}\n");
+
+ JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+ jackApiToolchain.setAnnotationProcessorClass(ResourceAnnotationProcessor.class);
+ jackApiToolchain.setAnnotationProcessorOutDir(te.getTestingFolder());
+
+ jackApiToolchain.srcToExe(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath())
+ + File.pathSeparator + te.getJackFolder(), te.getOutputDexFolder(), te.getSourceFolder());
+
+ File discoverFile = new File(te.getTestingFolder(), ResourceAnnotationProcessor.FILENAME);
+ Assert.assertTrue(discoverFile.exists());
+ LineNumberReader lnr = new LineNumberReader(new FileReader(discoverFile));
+ Assert.assertEquals(ResourceAnnotationTest.class.getName(), lnr.readLine());
+ Assert.assertEquals("jack.incremental.A", lnr.readLine());
+ Assert.assertNull(lnr.readLine());
+ lnr.close();
+ }
+
+ private void buildAnnotationRequiredByAnnotationProc(@Nonnull ErrorTestHelper te,
+ Class<?>[] annotationClasses) throws Exception {
+ File targetAnnotationFileFolder =
+ new File(te.getSourceFolder(), "com/android/jack/errorhandling/annotationprocessor/");
+ if (!targetAnnotationFileFolder.mkdirs()) {
+ Assert.fail("Fail to create folder " + targetAnnotationFileFolder.getAbsolutePath());
+ }
+
+ for (Class<?> annotationClass : annotationClasses) {
+ Files.copy(new File(AbstractTestTools.getJackRootDir(),
+ "toolchain/jack/jack/tests/com/android/jack/errorhandling/annotationprocessor/"
+ + annotationClass.getSimpleName() + ".java"), new File(
+ targetAnnotationFileFolder, annotationClass.getSimpleName() + ".java"));
+ }
+
+ // Compile annotation to a jack file
+ JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+ jackApiToolchain.srcToLib(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()),
+ te.getJackFolder(), false /* zipFiles = */, te.getSourceFolder());
+
+ AbstractTestTools.deleteTempDir(te.getSourceFolder());
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/error/CommandLineErrorTest.java b/jack-tests/tests/com/android/jack/error/CommandLineErrorTest.java
new file mode 100644
index 0000000..3e72329
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/error/CommandLineErrorTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.jack.error;
+
+import com.android.jack.IllegalOptionsException;
+import com.android.jack.Main;
+import com.android.jack.NothingToDoException;
+import com.android.jack.test.helper.ErrorTestHelper;
+import com.android.jack.test.toolchain.AbstractTestTools;
+import com.android.jack.test.toolchain.JackApiToolchain;
+
+import junit.framework.Assert;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+/**
+ * JUnit test checking Jack behavior on exceptions.
+ */
+public class CommandLineErrorTest {
+
+ @BeforeClass
+ public static void setUpClass() {
+ Main.class.getClassLoader().setDefaultAssertionStatus(true);
+ }
+
+ /**
+ * Checks that compilation fails correctly when an unsupported options is passed to ecj.
+ */
+ @Test
+ public void testCommandLineError001() throws Exception {
+ ErrorTestHelper ite = new ErrorTestHelper();
+
+ JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+ ByteArrayOutputStream errOut = new ByteArrayOutputStream();
+ jackApiToolchain.setErrorStream(errOut);
+ jackApiToolchain.addEcjArgs("-unsupported");
+ try {
+ jackApiToolchain.srcToExe(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath())
+ + File.pathSeparator + ite.getJackFolder(), ite.getOutputDexFolder(),
+ ite.getSourceFolder());
+ Assert.fail();
+ } catch (IllegalOptionsException e) {
+ // Failure is ok since a bad options is passed to ecj.
+ } finally {
+ Assert.assertEquals("", errOut.toString());
+ }
+ }
+
+ /**
+ * Checks that compilation fails correctly when no source files are passed to ecj.
+ */
+ @Test
+ public void testCommandLineError002() throws Exception {
+ ErrorTestHelper ite = new ErrorTestHelper();
+
+ JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+ ByteArrayOutputStream errOut = new ByteArrayOutputStream();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ jackApiToolchain.setErrorStream(errOut);
+ jackApiToolchain.setOutputStream(out);
+
+ try {
+ jackApiToolchain.srcToExe(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath())
+ + File.pathSeparator + ite.getJackFolder(), ite.getOutputDexFolder(),
+ ite.getSourceFolder());
+ Assert.fail();
+ } catch (NothingToDoException e) {
+ // Failure is ok since there is no source files.
+ } finally {
+ Assert.assertEquals("", errOut.toString());
+ Assert.assertTrue(out.toString().contains("Usage:"));
+ }
+ }
+
+}
diff --git a/jack-tests/tests/com/android/jack/error/FileAccessErrorTest.java b/jack-tests/tests/com/android/jack/error/FileAccessErrorTest.java
new file mode 100644
index 0000000..f9ce418
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/error/FileAccessErrorTest.java
@@ -0,0 +1,180 @@
+/*
+ * 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.jack.error;
+
+import com.android.jack.JackUserException;
+import com.android.jack.Main;
+import com.android.jack.frontend.FrontendCompilationException;
+import com.android.jack.load.JackLoadingException;
+import com.android.jack.test.helper.ErrorTestHelper;
+import com.android.jack.test.toolchain.AbstractTestTools;
+import com.android.jack.test.toolchain.JackApiToolchain;
+import com.android.sched.util.config.PropertyIdException;
+
+import junit.framework.Assert;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+/**
+ * JUnit test checking Jack behavior on file access error.
+ */
+public class FileAccessErrorTest {
+
+ @BeforeClass
+ public static void setUpClass() {
+ Main.class.getClassLoader().setDefaultAssertionStatus(true);
+ }
+
+ /**
+ * Checks that compilation fails correctly when folder to generate jack files is not readable.
+ */
+ @Test
+ public void testFileAccessError001() throws Exception {
+ ErrorTestHelper te = new ErrorTestHelper();
+
+ AbstractTestTools.createJavaFile(te.getSourceFolder(), "jack.incremental", "A.java",
+ "package jack.incremental; \n"+
+ "public class A {} \n");
+
+ File jackOutputFile = AbstractTestTools.createTempDir();
+ if (!jackOutputFile.setReadable(false)) {
+ Assert.fail("Fails to change file permissions of " + jackOutputFile.getAbsolutePath());
+ }
+ JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+
+ try {
+ jackApiToolchain.srcToLib(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()),
+ jackOutputFile, false, te.getSourceFolder());
+ Assert.fail();
+ } catch (PropertyIdException e) {
+ // Failure is ok since jack output folder is not readable
+ } finally {
+ if (!jackOutputFile.setReadable(true)) {
+ Assert.fail("Fails to change file permissions of " + jackOutputFile.getAbsolutePath());
+ }
+ }
+ }
+
+ /**
+ * Checks that compilation fails correctly when source file is not readable.
+ */
+ @Test
+ public void testFileAccessError003() throws Exception {
+ ErrorTestHelper te = new ErrorTestHelper();
+
+ File a = AbstractTestTools.createJavaFile(te.getSourceFolder(), "jack.incremental", "A.java",
+ "package jack.incremental; \n"+
+ "public class A {} \n");
+ if (!a.setReadable(false)) {
+ Assert.fail("Fails to change file permissions of " + a.getAbsolutePath());
+ }
+
+ JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+ ByteArrayOutputStream errOut = new ByteArrayOutputStream();
+ jackApiToolchain.setErrorStream(errOut);
+
+ try {
+ jackApiToolchain.srcToExe(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()),
+ te.getOutputDexFolder(), te.getSourceFolder());
+ Assert.fail();
+ } catch (FrontendCompilationException e) {
+ // Failure is ok since source file is not readable
+ } finally {
+ if (!a.setReadable(true)) {
+ Assert.fail("Fails to change file permissions of " + a.getAbsolutePath());
+ }
+ Assert.assertTrue(errOut.toString().contains("Permission denied"));
+ }
+ }
+
+ /**
+ * Checks that compilation fails correctly when jack file is not readable.
+ */
+ @Test
+ public void testFileAccessError004() throws Exception {
+ ErrorTestHelper te = new ErrorTestHelper();
+
+ AbstractTestTools.createJavaFile(te.getSourceFolder(), "jack.incremental", "A.java",
+ "package jack.incremental; \n"+
+ "public class A {} \n");
+
+ JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+
+ jackApiToolchain.srcToLib(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()),
+ te.getJackFolder(), false, te.getSourceFolder());
+
+ AbstractTestTools.deleteJavaFile(te.getSourceFolder(), "jack.incremental", "A.java");
+
+ AbstractTestTools.createJavaFile(te.getSourceFolder(),"jack.incremental", "B.java",
+ "package jack.incremental; \n"+
+ "public class B extends A {} \n");
+
+ ByteArrayOutputStream errOut = new ByteArrayOutputStream();
+ try {
+ for (File jackFile : AbstractTestTools.getFiles(te.getJackFolder(), ".jack")) {
+ if (!jackFile.setReadable(false)) {
+ Assert.fail("Fails to change file permissions of " + jackFile.getAbsolutePath());
+ }
+ }
+
+ jackApiToolchain.setErrorStream(errOut);
+ jackApiToolchain.srcToLib(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath())
+ + File.pathSeparator + te.getJackFolder().getAbsolutePath(),
+ AbstractTestTools.createTempDir(), false, te.getSourceFolder());
+ Assert.fail();
+ } catch (JackLoadingException e) {
+ // Failure is ok since jack file is not readable
+ } finally {
+ Assert.assertEquals("", errOut.toString());
+ for (File jackFile : AbstractTestTools.getFiles(te.getJackFolder(), ".jack")) {
+ if (!jackFile.setReadable(true)) {
+ Assert.fail("Fails to change file permissions of " + jackFile.getAbsolutePath());
+ }
+ }
+ }
+ }
+
+ /**
+ * Checks that compilation fails correctly when source file does not exist.
+ */
+ @Test
+ public void testFileAccessError005() throws Exception {
+ ErrorTestHelper te = new ErrorTestHelper();
+
+ JackApiToolchain jackApiToolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+
+ try {
+
+ jackApiToolchain.srcToExe(
+ AbstractTestTools.getClasspathAsString(jackApiToolchain.getDefaultBootClasspath()),
+ te.getOutputDexFolder(), new File(te.getSourceFolder(), "A.java"));
+
+ Assert.fail();
+ } catch (JackUserException e) {
+ // Failure is ok since source file is not readable
+ Assert.assertTrue(e.getMessage().contains("A.java is missing"));
+ }
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/experimenal/incremental/DependenciesTests005.java b/jack-tests/tests/com/android/jack/experimenal/incremental/DependenciesTests005.java
new file mode 100644
index 0000000..6b50799
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/experimenal/incremental/DependenciesTests005.java
@@ -0,0 +1,80 @@
+/*
+ * 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.jack.experimenal.incremental;
+
+import com.android.jack.Main;
+import com.android.jack.test.helper.IncrementalTestHelper;
+import com.android.jack.test.toolchain.AbstractTestTools;
+
+import junit.framework.Assert;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.List;
+
+/**
+ * JUnit test checking dependencies between Java files.
+ */
+public class DependenciesTests005 {
+
+ @BeforeClass
+ public static void setUpClass() {
+ Main.class.getClassLoader().setDefaultAssertionStatus(true);
+ }
+
+ /**
+ * Check that runtime is correct after incremental compilation due to a constant modification.
+ */
+ @Test
+ public void testDependency001() throws Exception {
+ IncrementalTestHelper ite =
+ new IncrementalTestHelper(AbstractTestTools.createTempDir());
+
+ ite.addJavaFile("jack.incremental", "A.java",
+ "package jack.incremental; \n"+
+ "public class A { public static void main(String[] args) {" +
+ "System.out.print(C.str + B.str);} " +
+ "} \n");
+
+ ite.addJavaFile("jack.incremental", "B.java",
+ "package jack.incremental; \n"+
+ "public class B { public static final String str = \"HELLO\"; } \n");
+
+ ite.addJavaFile("jack.incremental", "C.java",
+ "package jack.incremental; \n"+
+ "public class C { public static final String str = \"STRING:\"; } \n");
+
+ ite.incrementalBuildFromFolder();
+ ite.snapshotJackFilesModificationDate();
+
+ ite.addJavaFile("jack.incremental", "B.java",
+ "package jack.incremental; \n"+
+ "public class B { public static final String str = \"INCREMENTAL\"; } \n");
+
+ ite.incrementalBuildFromFolder();
+
+ List<String> fqnOfRebuiltTypes = ite.getFQNOfRebuiltTypes();
+ Assert.assertEquals(2, fqnOfRebuiltTypes.size());
+ Assert.assertTrue(fqnOfRebuiltTypes.contains("jack.incremental.A"));
+ Assert.assertTrue(fqnOfRebuiltTypes.contains("jack.incremental.B"));
+
+ Assert.assertEquals("STRING:INCREMENTAL", ite.run("jack.incremental.A"));
+ }
+
+
+}
diff --git a/jack-tests/tests/com/android/jack/invoke/test001/jack/InvokeClone.java b/jack-tests/tests/com/android/jack/invoke/test001/jack/InvokeClone.java
index 8d1296f..f06857a 100644
--- a/jack-tests/tests/com/android/jack/invoke/test001/jack/InvokeClone.java
+++ b/jack-tests/tests/com/android/jack/invoke/test001/jack/InvokeClone.java
@@ -19,7 +19,7 @@ package com.android.jack.invoke.test001.jack;
public class InvokeClone {
public static int[] getArray() {
- int []a = new int[] {1,2,3};
+ int[] a = new int[] {1,2,3};
return (a.clone());
}
}
diff --git a/jack-tests/tests/com/android/jack/jarjar/JarjarTests.java b/jack-tests/tests/com/android/jack/jarjar/JarjarTests.java
new file mode 100644
index 0000000..6bac5cc
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/jarjar/JarjarTests.java
@@ -0,0 +1,48 @@
+/*
+ * 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.jack.jarjar;
+
+import com.android.jack.test.helper.RuntimeTestHelper;
+import com.android.jack.test.runtime.RuntimeTestInfo;
+import com.android.jack.test.toolchain.AbstractTestTools;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+
+import javax.annotation.Nonnull;
+
+public class JarjarTests {
+
+ @Nonnull
+ private File baseDir;
+
+ @Before
+ public void setUp() {
+ baseDir = AbstractTestTools.getTestRootDir("com.android.jack.jarjar.test001");
+ }
+
+ @Test
+ public void compileAndRunTest() throws Exception {
+ RuntimeTestHelper rtEnv = new RuntimeTestHelper(
+ new RuntimeTestInfo(baseDir, "com.android.jack.jarjar.test001.dx.Tests"));
+ rtEnv.setJarjarRulesFileName("jarjar-rules.txt");
+ rtEnv.compileAndRunTest();
+ }
+
+}
diff --git a/jack-tests/tests/com/android/jack/java7/ExceptionsTest.java b/jack-tests/tests/com/android/jack/java7/ExceptionsTest.java
new file mode 100644
index 0000000..ecbe578
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/java7/ExceptionsTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.jack.java7;
+
+import com.android.jack.Main;
+import com.android.jack.test.toolchain.AbstractTestTools;
+import com.android.jack.test.toolchain.JackBasedToolchain;
+import com.android.jack.test.toolchain.Toolchain.SourceLevel;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.File;
+
+import javax.annotation.Nonnull;
+
+/**
+ * JUnit test for compilation of Java 7 features
+ */
+public class ExceptionsTest {
+
+ @BeforeClass
+ public static void setUpClass() {
+ Main.class.getClassLoader().setDefaultAssertionStatus(true);
+ }
+
+ @Test
+ public void java7Exception001() throws Exception {
+ compileJava7Test("test001");
+ }
+
+ @Test
+ public void java7Exception002() throws Exception {
+ compileJava7Test("test002");
+ }
+
+ @Test
+ public void java7Exception003() throws Exception {
+ compileJava7Test("test003");
+ }
+
+ @Test
+ public void java7Exception004() throws Exception {
+ compileJava7Test("test004");
+ }
+
+ @Test
+ public void java7Exception005() throws Exception {
+ compileJava7Test("test005");
+ }
+
+ private void compileJava7Test(@Nonnull String name) throws Exception {
+ JackBasedToolchain jackBasedToolchain =
+ AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class);
+ jackBasedToolchain.setSourceLevel(SourceLevel.JAVA_7).srcToExe(
+ AbstractTestTools.getClasspathAsString(jackBasedToolchain.getDefaultBootClasspath()),
+ AbstractTestTools.createTempDir(), new File(
+ AbstractTestTools.getTestRootDir("com.android.jack.java7.exceptions." + name), "jack"));
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/shrob/AbstractTest.java b/jack-tests/tests/com/android/jack/shrob/AbstractTest.java
new file mode 100644
index 0000000..319abaf
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/shrob/AbstractTest.java
@@ -0,0 +1,561 @@
+/*
+ * Copyright (C) 2012 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.jack.shrob;
+
+import com.android.jack.Main;
+import com.android.jack.ProguardFlags;
+import com.android.jack.TestTools;
+import com.android.jack.category.KnownBugs;
+import com.android.jack.category.SlowTests;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Abstract class for running shrob tests
+ */
+public abstract class AbstractTest {
+
+ @BeforeClass
+ public static void setUpClass() {
+ Main.class.getClassLoader().setDefaultAssertionStatus(true);
+ }
+
+ protected abstract void runTest(
+ @Nonnull String testNumber,
+ @Nonnull String flagNumber,
+ @Nonnull String mappingNumber)
+ throws Exception;
+
+ protected ProguardFlags generateApplyMapping(@Nonnull File mappingFile) throws IOException {
+ File applyMapping = TestTools.createTempFile("mapping.flags", null);
+ BufferedWriter writer = new BufferedWriter(new FileWriter(applyMapping));
+ writer.append("-applymapping ");
+ writer.append(mappingFile.getAbsolutePath());
+ writer.close();
+ return new ProguardFlags(applyMapping);
+ }
+
+ protected ProguardFlags generateInjars(@Nonnull File injar) throws IOException {
+ File injarFlags = TestTools.createTempFile("injars", ".flags");
+ BufferedWriter writer = new BufferedWriter(new FileWriter(injarFlags));
+ writer.append("-injars ");
+ writer.append(injar.getAbsolutePath());
+ writer.close();
+ return new ProguardFlags(injarFlags);
+ }
+
+ @Test
+ public void test1_001() throws Exception {
+ runTest("001", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_002() throws Exception {
+ runTest("001", "002", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_003() throws Exception {
+ runTest("001", "003", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_004() throws Exception {
+ runTest("001", "004", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_005() throws Exception {
+ runTest("001", "005", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_005_002() throws Exception {
+ runTest("001", "005", "002");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_005_003() throws Exception {
+ runTest("001", "005", "003");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_006() throws Exception {
+ runTest("001", "006", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_007() throws Exception {
+ runTest("001", "007", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_008() throws Exception {
+ runTest("001", "008", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_009() throws Exception {
+ runTest("001", "009", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_010() throws Exception {
+ runTest("001", "010", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_011() throws Exception {
+ runTest("001", "011", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_012() throws Exception {
+ runTest("001", "012", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_013() throws Exception {
+ runTest("001", "013", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_014() throws Exception {
+ runTest("001", "014", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_015() throws Exception {
+ runTest("001", "015", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_016() throws Exception {
+ runTest("001", "016", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_017() throws Exception {
+ runTest("001", "017", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_018() throws Exception {
+ runTest("001", "018", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_019() throws Exception {
+ runTest("001", "019", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_020() throws Exception {
+ runTest("001", "020", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_021() throws Exception {
+ runTest("001", "021", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test1_022() throws Exception {
+ runTest("001", "022", "");
+ }
+
+ @Test
+ public void test2_001() throws Exception {
+ runTest("002", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test2_002() throws Exception {
+ runTest("002", "002", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test2_003() throws Exception {
+ runTest("002", "003", "");
+ }
+
+ @Test
+ public void test4_001() throws Exception {
+ runTest("004", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test4_002() throws Exception {
+ runTest("004", "002", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test4_003() throws Exception {
+ runTest("004", "003", "");
+ }
+
+ @Test
+ public void test5_001() throws Exception {
+ runTest("005", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test5_002() throws Exception {
+ runTest("005", "002", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test5_003() throws Exception {
+ runTest("005", "003", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test5_004() throws Exception {
+ runTest("005", "004", "");
+ }
+
+ @Test
+ public void test5_005() throws Exception {
+ runTest("005", "005", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test5_006() throws Exception {
+ runTest("005", "006", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test5_007() throws Exception {
+ runTest("005", "007", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test5_008() throws Exception {
+ runTest("005", "008", "");
+ }
+
+ @Test
+ public void test6_001() throws Exception {
+ runTest("006", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test6_002() throws Exception {
+ runTest("006", "002", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test6_003() throws Exception {
+ runTest("006", "003", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test6_004() throws Exception {
+ runTest("006", "004", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test6_005() throws Exception {
+ runTest("006", "005", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test6_006() throws Exception {
+ runTest("006", "006", "");
+ }
+
+ @Test
+ public void test7_001() throws Exception {
+ runTest("007", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test7_002() throws Exception {
+ runTest("007", "002", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test7_003() throws Exception {
+ runTest("007", "003", "");
+ }
+
+ @Test
+ public void test8_001() throws Exception {
+ runTest("008", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test8_002() throws Exception {
+ runTest("008", "002", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test8_003() throws Exception {
+ runTest("008", "003", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test8_004() throws Exception {
+ runTest("008", "004", "");
+ }
+
+ @Test
+ public void test9_001() throws Exception {
+ runTest("009", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test9_002() throws Exception {
+ runTest("009", "002", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test9_003() throws Exception {
+ runTest("009", "003", "");
+ }
+
+ @Test
+ public void test10_001() throws Exception {
+ runTest("010", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test10_002() throws Exception {
+ runTest("010", "002", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test10_003() throws Exception {
+ runTest("010", "003", "");
+ }
+
+ @Test
+ public void test11_001() throws Exception {
+ runTest("011", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test11_002() throws Exception {
+ runTest("011", "002", "");
+ }
+
+ @Test
+ public void test12_001() throws Exception {
+ runTest("012", "001", "");
+ }
+
+ @Test
+ public void test13_001() throws Exception {
+ runTest("013", "001", "");
+ }
+
+ @Test
+ public void test14_001() throws Exception {
+ runTest("014", "001", "");
+ }
+
+ @Test
+ public void test15_001() throws Exception {
+ runTest("015", "001", "");
+ }
+
+ @Test
+ public void test16_001() throws Exception {
+ runTest("016", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test16_002() throws Exception {
+ runTest("016", "002", "");
+ }
+
+ @Test
+ public void test17_001() throws Exception {
+ runTest("017", "001", "");
+ }
+
+ @Test
+ public void test18_001() throws Exception {
+ runTest("018", "001", "");
+ }
+
+ @Test
+ public void test19_001() throws Exception {
+ runTest("019", "001", "");
+ }
+
+ @Test
+ public void test21_001() throws Exception {
+ runTest("021", "001", "");
+ }
+
+ @Test
+ public void test22_001() throws Exception {
+ runTest("022", "001", "");
+ }
+
+ @Test
+ public void test23_001() throws Exception {
+ runTest("023", "001", "");
+ }
+
+ @Test
+ public void test25_001() throws Exception {
+ runTest("025", "001", "");
+ }
+
+ @Test
+ public void test26_001() throws Exception {
+ runTest("026", "001", "");
+ }
+
+ @Test
+ public void test29_001() throws Exception {
+ runTest("029", "001", "");
+ }
+
+ @Test
+ public void test30_001() throws Exception {
+ runTest("030", "001", "");
+ }
+
+ @Test
+ public void test31_001() throws Exception {
+ runTest("031", "001", "");
+ }
+
+ @Test
+ public void test31_002() throws Exception {
+ runTest("031", "002", "");
+ }
+
+ @Test
+ public void test32_001() throws Exception {
+ runTest("032", "001", "");
+ }
+
+ @Test
+ public void test33_001() throws Exception {
+ runTest("033", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test33_002() throws Exception {
+ runTest("033", "002", "");
+ }
+
+ @Test
+ public void test34_001() throws Exception {
+ runTest("034", "001", "");
+ }
+
+ @Test
+ public void test35_001() throws Exception {
+ runTest("035", "001", "");
+ }
+
+ @Test
+ public void test36_001() throws Exception {
+ runTest("036", "001", "");
+ }
+
+ @Test
+ public void test37_001() throws Exception {
+ runTest("037", "001", "");
+ }
+
+ @Test
+ public void test38_001() throws Exception {
+ runTest("038", "001", "");
+ }
+
+ @Test
+ public void test39_001() throws Exception {
+ runTest("039", "001", "");
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void test40_001() throws Exception {
+ runTest("040", "001", "");
+ }
+
+ @Test
+ @Category(KnownBugs.class)
+ public void test41_001() throws Exception {
+ runTest("041", "001", "");
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/shrob/ObfuscationWithoutMappingTests.java b/jack-tests/tests/com/android/jack/shrob/ObfuscationWithoutMappingTests.java
new file mode 100644
index 0000000..26cba49
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/shrob/ObfuscationWithoutMappingTests.java
@@ -0,0 +1,166 @@
+/*
+ * Copyright (C) 2012 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.jack.shrob;
+
+import com.android.jack.Options;
+import com.android.jack.category.KnownBugs;
+import com.android.jack.shrob.obfuscation.NameProviderFactory;
+import com.android.jack.shrob.proguard.GrammarActions;
+import com.android.jack.shrob.spec.Flags;
+import com.android.jack.test.comparator.ComparatorMapping;
+import com.android.jack.test.helper.SourceToDexComparisonTestHelper;
+import com.android.jack.test.toolchain.AbstractTestTools;
+import com.android.jack.test.toolchain.DummyToolchain;
+import com.android.jack.test.toolchain.JackApiToolchain;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+
+import javax.annotation.Nonnull;
+
+public class ObfuscationWithoutMappingTests extends AbstractTest {
+
+ @Override
+ protected void runTest(
+ @Nonnull String testNumber,
+ @Nonnull String flagNumber,
+ @Nonnull String mappingNumber)
+ throws Exception {
+
+ String testName = "shrob/test" + testNumber;
+
+ String testPackageName = "com.android.jack.shrob.test" + testNumber;
+ File testFolder = AbstractTestTools.getTestRootDir(testPackageName);
+
+ JackApiToolchain toolchain = AbstractTestTools.getCandidateToolchain(JackApiToolchain.class);
+ Flags flags = new Flags();
+ toolchain.setShrobFlags(flags);
+ GrammarActions.parse("proguard.flags" + flagNumber, testFolder.getAbsolutePath(), flags);
+ File refFolder = new File(testFolder, "refsObfuscationWithoutMapping");
+
+ toolchain.addProperty(NameProviderFactory.NAMEPROVIDER.getName(), "rot13");
+ toolchain.addProperty(Options.METHOD_FILTER.getName(), "supported-methods");
+
+ File candidateOutputMapping = AbstractTestTools.createTempFile("mapping", ".txt");
+ File refOutputMapping = new File(refFolder, "expected-" + flagNumber + ".txt");
+ flags.setOutputMapping(candidateOutputMapping);
+ flags.setPrintMapping(true);
+
+ SourceToDexComparisonTestHelper env =
+ new SourceToDexComparisonTestHelper(new File(testFolder, "jack"));
+
+ env.setCandidateTestTools(toolchain);
+ env.setReferenceTestTools(new DummyToolchain());
+
+ env.runTest(new ComparatorMapping(candidateOutputMapping, refOutputMapping));
+
+ // // ==============================================================
+
+ /*
+ * Comment for reviewers: the following code is an attempt to use jack based toolchain.
+ * It works, but requires to manipulate (copy, write...) shrob flags.
+ * Here I added a shrob option manually, but ideally to be able to use
+ * a Flags like object for CLI based toochains, we must be able to dump
+ * the flags as a file (TBD). Plus, if flags have "-include" directives with relative
+ * paths, files must be in the same location.
+ */
+
+//
+// String testName = "shrob/test" + testNumber;
+// File testFolder = TestTools.getJackTestFolder(testName);
+// File refFolder = new File(testFolder, "refsObfuscationWithoutMapping");
+//
+// JackBasedToolchain jackToolchain = AbstractTestTools.getJackBasedToolchainAsCandidate();
+//
+// jackToolchain.addProperty(NameProviderFactory.NAMEPROVIDER.getName(), "rot13");
+// jackToolchain.addProperty(Options.METHOD_FILTER.getName(), "supported-methods");
+//
+// File candidateOutputMapping = TestTools.createTempFile("mapping", ".txt");
+// File refOutputMapping = new File(refFolder, "expected-" + flagNumber + ".txt");
+//
+// jackToolchain.getCompilationResult().proguardMappingFile = candidateOutputMapping;
+//
+// // TODO(jmhenaff): having to seems like a no go for JackBasedToolchain (i.e. cli)
+// File candidateFlags = new File(testFolder.getAbsolutePath(), "tmp-proguard.flags" + flagNumber);
+// candidateFlags.deleteOnExit();
+// appendStringToFileCopy(new File(testFolder.getAbsolutePath(), "proguard.flags" + flagNumber),
+// candidateFlags, "-printmapping " + candidateOutputMapping.getAbsolutePath());
+//
+// SourceToDexComparisonTestEnv env = new SourceToDexComparisonTestEnv(bootclasspath, classpath,
+// TestTools.getJackTestsWithJackFolder(testName));
+//
+// env.setProguardFlags(new ProguardFlags[] {new ProguardFlags(candidateFlags)});
+//
+// CompilationResult compilationResult = new CompilationResult();
+// compilationResult.proguardMappingFile = refOutputMapping;
+//
+// env.setCandidateTestTools(jackToolchain);
+// env.setReferenceTestTools(new DummyTestTools(compilationResult));
+//
+// env.addComparator(env.createMappingComparator());
+// env.compare();
+
+ }
+
+ @Override
+ @Test
+ @Category(KnownBugs.class)
+ public void test33_001() throws Exception {
+ super.test33_001();
+ }
+
+ @Override
+ @Test
+ @Category(KnownBugs.class)
+ public void test34_001() throws Exception {
+ super.test34_001();
+ }
+
+ @Override
+ @Test
+ @Category(KnownBugs.class)
+ public void test35_001() throws Exception {
+ super.test35_001();
+ }
+
+// private void appendStringToFileCopy(File source, File dest, String appended) throws IOException {
+// BufferedReader reader = null;
+// BufferedWriter writer = null;
+// try {
+// reader = new BufferedReader(new FileReader(source));
+// writer = new BufferedWriter(new FileWriter(dest));
+// String line;
+// while ((line = reader.readLine()) != null) {
+// writer.write(line);
+// writer.write("\n");
+// }
+// writer.write(appended);
+// } finally {
+// try {
+// reader.close();
+// } catch (IOException e) {
+// }
+// try {
+// writer.close();
+// } catch (IOException e) {
+// }
+// }
+// }
+
+}
diff --git a/jack-tests/tests/com/android/jack/tools/merger/MergerAllTests.java b/jack-tests/tests/com/android/jack/tools/merger/MergerAllTests.java
new file mode 100644
index 0000000..6d222de
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/tools/merger/MergerAllTests.java
@@ -0,0 +1,28 @@
+/*
+ * 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.jack.tools.merger;
+
+import com.android.jack.tools.merger.test011.MergerTest011;
+
+import org.junit.experimental.categories.Categories;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Categories.class)
+@SuiteClasses(
+value = {MergerTest011.class})
+public class MergerAllTests {
+} \ No newline at end of file
diff --git a/jack-tests/tests/com/android/jack/tools/merger/MergerTestTools.java b/jack-tests/tests/com/android/jack/tools/merger/MergerTestTools.java
new file mode 100644
index 0000000..dab9e7e
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/tools/merger/MergerTestTools.java
@@ -0,0 +1,59 @@
+/*
+ * 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.jack.tools.merger;
+
+import com.android.jack.Options;
+import com.android.jack.TestTools;
+import com.android.jack.backend.dex.DexFileWriter;
+import com.android.jack.test.toolchain.AbstractTestTools;
+import com.android.jack.test.toolchain.JackBasedToolchain;
+import com.android.sched.scheduler.ScheduleInstance;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+public class MergerTestTools {
+
+ @Nonnull
+ protected File buildOneDexPerType(@CheckForNull String classpath, @Nonnull File sourceFolder,
+ boolean withDebug) throws Exception {
+ JackBasedToolchain toolchain =
+ AbstractTestTools.getCandidateToolchain(JackBasedToolchain.class);
+ try {
+ File multiDexFolder = TestTools.createTempDir("multi", "dex");
+ File multiDex = new File(multiDexFolder, DexFileWriter.DEX_FILENAME);
+ File multiDexOnTypePerTypeFolder = TestTools.createTempDir("multiOnDexPerType", "dex");
+
+ toolchain.addProperty(Options.EMIT_LINE_NUMBER_DEBUG_INFO.getName(),
+ Boolean.toString(withDebug));
+ toolchain.addProperty(ScheduleInstance.DEFAULT_RUNNER.getName(), "single-threaded");
+ toolchain.addProperty(Options.TYPEDEX_DIR.getName(),
+ multiDexOnTypePerTypeFolder.getAbsolutePath());
+
+ toolchain.srcToExe(classpath, multiDexFolder, sourceFolder);
+
+ return multiDex;
+
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+}
diff --git a/jack-tests/tests/com/android/jack/tools/merger/test011/MergerTest011.java b/jack-tests/tests/com/android/jack/tools/merger/test011/MergerTest011.java
new file mode 100644
index 0000000..f00da22
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/tools/merger/test011/MergerTest011.java
@@ -0,0 +1,185 @@
+/*
+ * 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.jack.tools.merger.test011;
+
+import com.android.jack.JackUserException;
+import com.android.jack.Main;
+import com.android.jack.TestTools;
+import com.android.jack.category.SlowTests;
+import com.android.jack.tools.merger.FieldIdOverflowException;
+import com.android.jack.tools.merger.MergerTestTools;
+import com.android.jack.tools.merger.MethodIdOverflowException;
+import com.android.jack.tools.merger.TypeIdOverflowException;
+
+import junit.framework.Assert;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import javax.annotation.Nonnegative;
+import javax.annotation.Nonnull;
+
+/**
+ * JUnit test checking that merging can throw overflow exceptions.
+ */
+public class MergerTest011 extends MergerTestTools {
+
+ private static int fileCount = 655;
+
+ private static final String expectedExceptionMessage =
+ "Index overflow while merging dex files. Try using multidex";
+
+ @BeforeClass
+ public static void setUpClass() {
+ Main.class.getClassLoader().setDefaultAssertionStatus(true);
+ }
+
+ @Test
+ public void testMergerWithHighNumberOfMethods() throws Exception {
+ File srcFolder = TestTools.createTempDir("oneDexPerType", "SrcFolder");
+
+ // One CstMethodRef is also created for call to object.init()
+ for (int fileIdx = 0; fileIdx < fileCount; fileIdx++) {
+ generateJavaFileWithMethods(srcFolder, fileIdx, 100);
+ }
+ generateJavaFileWithMethods(srcFolder, fileCount, 36);
+
+ try {
+ buildOneDexPerType(TestTools.getDefaultBootclasspathString(), srcFolder, false /* withDebug */);
+ Assert.fail();
+ } catch (JackUserException e) {
+ Assert.assertEquals(expectedExceptionMessage, e.getMessage());
+ Throwable cause = e.getCause();
+ Assert.assertTrue(cause instanceof MethodIdOverflowException);
+ }
+ }
+
+ @Test
+ public void testMergerWithHighNumberOfFields() throws Exception {
+ File srcFolder = TestTools.createTempDir("oneDexPerType", "SrcFolder");
+
+ for (int fileIdx = 0; fileIdx < fileCount; fileIdx++) {
+ generateJavaFileWithFields(srcFolder, fileIdx, 100);
+ }
+ generateJavaFileWithFields(srcFolder, fileCount, 37);
+
+ try {
+ buildOneDexPerType(TestTools.getDefaultBootclasspathString(), srcFolder, false /* withDebug */);
+ Assert.fail();
+ } catch (JackUserException e) {
+ Assert.assertEquals(expectedExceptionMessage, e.getMessage());
+ Throwable cause = e.getCause();
+ Assert.assertTrue(cause instanceof FieldIdOverflowException);
+ }
+ }
+
+ @Test
+ @Category(SlowTests.class)
+ public void testMergerWithHighNumberOfTypes() throws Exception {
+ File srcFolder = TestTools.createTempDir("oneDexPerType", "SrcFolder");
+
+ for (int fileIdx = 0; fileIdx < fileCount; fileIdx++) {
+ generateJavaFileWithTypes(srcFolder, fileIdx, 100);
+ }
+ generateJavaFileWithTypes(srcFolder, fileCount, 36);
+
+ try {
+ buildOneDexPerType(TestTools.getDefaultBootclasspathString(), srcFolder, false /* withDebug */);
+ Assert.fail();
+ } catch (JackUserException e) {
+ Assert.assertEquals(expectedExceptionMessage, e.getMessage());
+ Throwable cause = e.getCause();
+ Assert.assertTrue(cause instanceof TypeIdOverflowException);
+ }
+ }
+
+ private void generateJavaFileWithMethods(@Nonnull File srcFolder, @Nonnegative int fileIdx,
+ @Nonnegative int methodCount) throws IOException, FileNotFoundException {
+ File javaFile = new File(srcFolder, "A" + fileIdx + ".java");
+ if (!javaFile.createNewFile()) {
+ throw new IOException("Failed to create file " + javaFile.getAbsolutePath());
+ }
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(javaFile);
+ StringBuilder content =
+ new StringBuilder("package jack.merger; \n" + "public class A" + fileIdx+ " {");
+ // -1 due to implicit init method
+ for (int mthIdx = 0; mthIdx < methodCount - 1; mthIdx++) {
+ content.append("public void m" + mthIdx + "() {}");
+ }
+ content.append("} \n");
+ fos.write(content.toString().getBytes());
+ } finally {
+ if (fos != null) {
+ fos.close();
+ }
+ }
+ }
+
+ private void generateJavaFileWithFields(@Nonnull File srcFolder, @Nonnegative int fileIdx,
+ @Nonnegative int fieldCount) throws IOException, FileNotFoundException {
+ File javaFile = new File(srcFolder, "A" + fileIdx + ".java");
+ if (!javaFile.createNewFile()) {
+ throw new IOException("Failed to create file " + javaFile.getAbsolutePath());
+ }
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(javaFile);
+ StringBuilder content =
+ new StringBuilder("package jack.merger; \n" + "public class A" + fileIdx+ " {");
+ for (int fieldIdx = 0; fieldIdx < fieldCount; fieldIdx++) {
+ content.append("public int f" + fieldIdx + ";");
+ }
+ content.append("} \n");
+ fos.write(content.toString().getBytes());
+ } finally {
+ if (fos != null) {
+ fos.close();
+ }
+ }
+ }
+
+ private void generateJavaFileWithTypes(@Nonnull File srcFolder, @Nonnegative int fileIdx,
+ @Nonnegative int typeCount) throws IOException, FileNotFoundException {
+ File javaFile = new File(srcFolder, "A" + fileIdx + ".java");
+ if (!javaFile.createNewFile()) {
+ throw new IOException("Failed to create file " + javaFile.getAbsolutePath());
+ }
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(javaFile);
+ StringBuilder content =
+ new StringBuilder("package jack.merger; \n" + "public class A" + fileIdx+ " {");
+ for (int typeIdx = 0; typeIdx < typeCount; typeIdx++) {
+ content.append("public class c" + typeIdx + " {}");
+ }
+ content.append("} \n");
+ fos.write(content.toString().getBytes());
+ } finally {
+ if (fos != null) {
+ fos.close();
+ }
+ }
+ }
+}