diff options
Diffstat (limited to 'enigma/src/test')
51 files changed, 2686 insertions, 0 deletions
diff --git a/enigma/src/test/java/cuchaz/enigma/PackageVisibilityIndexTest.java b/enigma/src/test/java/cuchaz/enigma/PackageVisibilityIndexTest.java new file mode 100644 index 0000000..1dc9748 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/PackageVisibilityIndexTest.java | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.analysis.ClassCache; | ||
| 15 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 16 | import cuchaz.enigma.analysis.index.PackageVisibilityIndex; | ||
| 17 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 18 | import org.junit.Test; | ||
| 19 | |||
| 20 | import java.nio.file.Paths; | ||
| 21 | |||
| 22 | import static cuchaz.enigma.TestEntryFactory.newClass; | ||
| 23 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 24 | import static org.hamcrest.Matchers.contains; | ||
| 25 | import static org.hamcrest.Matchers.containsInAnyOrder; | ||
| 26 | |||
| 27 | public class PackageVisibilityIndexTest { | ||
| 28 | |||
| 29 | private static final ClassEntry KEEP = newClass("cuchaz/enigma/inputs/Keep"); | ||
| 30 | private static final ClassEntry BASE = newClass("a"); | ||
| 31 | private static final ClassEntry SAME_PACKAGE_CHILD = newClass("b"); | ||
| 32 | private static final ClassEntry SAME_PACKAGE_CHILD_INNER = newClass("b$a"); | ||
| 33 | private static final ClassEntry OTHER_PACKAGE_CHILD = newClass("c"); | ||
| 34 | private static final ClassEntry OTHER_PACKAGE_CHILD_INNER = newClass("c$a"); | ||
| 35 | private final JarIndex jarIndex; | ||
| 36 | |||
| 37 | public PackageVisibilityIndexTest() throws Exception { | ||
| 38 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/packageAccess.jar")); | ||
| 39 | jarIndex = classCache.index(ProgressListener.none()); | ||
| 40 | } | ||
| 41 | |||
| 42 | @Test | ||
| 43 | public void test() { | ||
| 44 | PackageVisibilityIndex visibilityIndex = jarIndex.getPackageVisibilityIndex(); | ||
| 45 | assertThat(visibilityIndex.getPartition(BASE), containsInAnyOrder(BASE, SAME_PACKAGE_CHILD, SAME_PACKAGE_CHILD_INNER)); | ||
| 46 | System.out.println(visibilityIndex.getPartitions()); | ||
| 47 | assertThat(visibilityIndex.getPartitions(), containsInAnyOrder( | ||
| 48 | containsInAnyOrder(BASE, SAME_PACKAGE_CHILD, SAME_PACKAGE_CHILD_INNER), | ||
| 49 | containsInAnyOrder(OTHER_PACKAGE_CHILD, OTHER_PACKAGE_CHILD_INNER), | ||
| 50 | contains(KEEP) | ||
| 51 | )); | ||
| 52 | } | ||
| 53 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/TestDeobfed.java b/enigma/src/test/java/cuchaz/enigma/TestDeobfed.java new file mode 100644 index 0000000..494d959 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/TestDeobfed.java | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.analysis.ClassCache; | ||
| 15 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 16 | import cuchaz.enigma.source.Decompiler; | ||
| 17 | import cuchaz.enigma.source.Decompilers; | ||
| 18 | import cuchaz.enigma.source.SourceSettings; | ||
| 19 | import org.junit.BeforeClass; | ||
| 20 | import org.junit.Test; | ||
| 21 | |||
| 22 | import java.nio.file.Files; | ||
| 23 | import java.nio.file.Path; | ||
| 24 | import java.nio.file.Paths; | ||
| 25 | |||
| 26 | import static cuchaz.enigma.TestEntryFactory.newClass; | ||
| 27 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 28 | import static org.hamcrest.Matchers.containsInAnyOrder; | ||
| 29 | |||
| 30 | public class TestDeobfed { | ||
| 31 | private static Enigma enigma; | ||
| 32 | private static ClassCache classCache; | ||
| 33 | private static JarIndex index; | ||
| 34 | |||
| 35 | @BeforeClass | ||
| 36 | public static void beforeClass() throws Exception { | ||
| 37 | enigma = Enigma.create(); | ||
| 38 | |||
| 39 | Path obf = Paths.get("build/test-obf/translation.jar"); | ||
| 40 | Path deobf = Paths.get("build/test-deobf/translation.jar"); | ||
| 41 | Files.createDirectories(deobf.getParent()); | ||
| 42 | EnigmaProject project = enigma.openJar(obf, ProgressListener.none()); | ||
| 43 | project.exportRemappedJar(ProgressListener.none()).write(deobf, ProgressListener.none()); | ||
| 44 | |||
| 45 | classCache = ClassCache.of(deobf); | ||
| 46 | index = classCache.index(ProgressListener.none()); | ||
| 47 | } | ||
| 48 | |||
| 49 | @Test | ||
| 50 | public void obfEntries() { | ||
| 51 | assertThat(index.getEntryIndex().getClasses(), containsInAnyOrder( | ||
| 52 | newClass("cuchaz/enigma/inputs/Keep"), | ||
| 53 | newClass("a"), | ||
| 54 | newClass("b"), | ||
| 55 | newClass("c"), | ||
| 56 | newClass("d"), | ||
| 57 | newClass("d$1"), | ||
| 58 | newClass("e"), | ||
| 59 | newClass("f"), | ||
| 60 | newClass("g"), | ||
| 61 | newClass("g$a"), | ||
| 62 | newClass("g$a$a"), | ||
| 63 | newClass("g$b"), | ||
| 64 | newClass("g$b$a"), | ||
| 65 | newClass("h"), | ||
| 66 | newClass("h$a"), | ||
| 67 | newClass("h$a$a"), | ||
| 68 | newClass("h$b"), | ||
| 69 | newClass("h$b$a"), | ||
| 70 | newClass("h$b$a$a"), | ||
| 71 | newClass("h$b$a$b"), | ||
| 72 | newClass("i"), | ||
| 73 | newClass("i$a"), | ||
| 74 | newClass("i$b") | ||
| 75 | )); | ||
| 76 | } | ||
| 77 | |||
| 78 | @Test | ||
| 79 | public void decompile() { | ||
| 80 | EnigmaProject project = new EnigmaProject(enigma, classCache, index, new byte[20]); | ||
| 81 | Decompiler decompiler = Decompilers.PROCYON.create(project.getClassCache(), new SourceSettings(false, false)); | ||
| 82 | |||
| 83 | decompiler.getSource("a"); | ||
| 84 | decompiler.getSource("b"); | ||
| 85 | decompiler.getSource("c"); | ||
| 86 | decompiler.getSource("d"); | ||
| 87 | decompiler.getSource("d$1"); | ||
| 88 | decompiler.getSource("e"); | ||
| 89 | decompiler.getSource("f"); | ||
| 90 | decompiler.getSource("g"); | ||
| 91 | decompiler.getSource("g$a"); | ||
| 92 | decompiler.getSource("g$a$a"); | ||
| 93 | decompiler.getSource("g$b"); | ||
| 94 | decompiler.getSource("g$b$a"); | ||
| 95 | decompiler.getSource("h"); | ||
| 96 | decompiler.getSource("h$a"); | ||
| 97 | decompiler.getSource("h$a$a"); | ||
| 98 | decompiler.getSource("h$b"); | ||
| 99 | decompiler.getSource("h$b$a"); | ||
| 100 | decompiler.getSource("h$b$a$a"); | ||
| 101 | decompiler.getSource("h$b$a$b"); | ||
| 102 | decompiler.getSource("i"); | ||
| 103 | decompiler.getSource("i$a"); | ||
| 104 | decompiler.getSource("i$b"); | ||
| 105 | } | ||
| 106 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/TestDeobfuscator.java b/enigma/src/test/java/cuchaz/enigma/TestDeobfuscator.java new file mode 100644 index 0000000..6619d26 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/TestDeobfuscator.java | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.source.Decompiler; | ||
| 15 | import cuchaz.enigma.source.Decompilers; | ||
| 16 | import cuchaz.enigma.source.SourceSettings; | ||
| 17 | import org.junit.Test; | ||
| 18 | |||
| 19 | import java.io.IOException; | ||
| 20 | import java.nio.file.Paths; | ||
| 21 | |||
| 22 | public class TestDeobfuscator { | ||
| 23 | private EnigmaProject openProject() throws IOException { | ||
| 24 | Enigma enigma = Enigma.create(); | ||
| 25 | return enigma.openJar(Paths.get("build/test-obf/loneClass.jar"), ProgressListener.none()); | ||
| 26 | } | ||
| 27 | |||
| 28 | @Test | ||
| 29 | public void loadJar() | ||
| 30 | throws Exception { | ||
| 31 | openProject(); | ||
| 32 | } | ||
| 33 | |||
| 34 | @Test | ||
| 35 | public void decompileClass() throws Exception { | ||
| 36 | EnigmaProject project = openProject(); | ||
| 37 | Decompiler decompiler = Decompilers.PROCYON.create(project.getClassCache(), new SourceSettings(false, false)); | ||
| 38 | |||
| 39 | decompiler.getSource("a").asString(); | ||
| 40 | } | ||
| 41 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/TestEntryFactory.java b/enigma/src/test/java/cuchaz/enigma/TestEntryFactory.java new file mode 100644 index 0000000..9e1425a --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/TestEntryFactory.java | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.analysis.EntryReference; | ||
| 15 | import cuchaz.enigma.translation.representation.*; | ||
| 16 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 17 | import cuchaz.enigma.translation.representation.entry.FieldEntry; | ||
| 18 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 19 | |||
| 20 | public class TestEntryFactory { | ||
| 21 | |||
| 22 | public static ClassEntry newClass(String name) { | ||
| 23 | return new ClassEntry(name); | ||
| 24 | } | ||
| 25 | |||
| 26 | public static FieldEntry newField(String className, String fieldName, String fieldType) { | ||
| 27 | return newField(newClass(className), fieldName, fieldType); | ||
| 28 | } | ||
| 29 | |||
| 30 | public static FieldEntry newField(ClassEntry classEntry, String fieldName, String fieldType) { | ||
| 31 | return new FieldEntry(classEntry, fieldName, new TypeDescriptor(fieldType)); | ||
| 32 | } | ||
| 33 | |||
| 34 | public static MethodEntry newMethod(String className, String methodName, String methodSignature) { | ||
| 35 | return newMethod(newClass(className), methodName, methodSignature); | ||
| 36 | } | ||
| 37 | |||
| 38 | public static MethodEntry newMethod(ClassEntry classEntry, String methodName, String methodSignature) { | ||
| 39 | return new MethodEntry(classEntry, methodName, new MethodDescriptor(methodSignature)); | ||
| 40 | } | ||
| 41 | |||
| 42 | public static EntryReference<FieldEntry, MethodEntry> newFieldReferenceByMethod(FieldEntry fieldEntry, String callerClassName, String callerName, String callerSignature) { | ||
| 43 | return new EntryReference<>(fieldEntry, "", newMethod(callerClassName, callerName, callerSignature)); | ||
| 44 | } | ||
| 45 | |||
| 46 | public static EntryReference<MethodEntry, MethodEntry> newBehaviorReferenceByMethod(MethodEntry methodEntry, String callerClassName, String callerName, String callerSignature) { | ||
| 47 | return new EntryReference<>(methodEntry, "", newMethod(callerClassName, callerName, callerSignature)); | ||
| 48 | } | ||
| 49 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/TestInnerClasses.java b/enigma/src/test/java/cuchaz/enigma/TestInnerClasses.java new file mode 100644 index 0000000..85c72f8 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/TestInnerClasses.java | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.analysis.ClassCache; | ||
| 15 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 16 | import cuchaz.enigma.source.Decompiler; | ||
| 17 | import cuchaz.enigma.source.Decompilers; | ||
| 18 | import cuchaz.enigma.source.SourceSettings; | ||
| 19 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 20 | import org.junit.Test; | ||
| 21 | |||
| 22 | import java.nio.file.Paths; | ||
| 23 | |||
| 24 | import static cuchaz.enigma.TestEntryFactory.newClass; | ||
| 25 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 26 | import static org.hamcrest.Matchers.is; | ||
| 27 | |||
| 28 | public class TestInnerClasses { | ||
| 29 | |||
| 30 | private static final ClassEntry SimpleOuter = newClass("d"); | ||
| 31 | private static final ClassEntry SimpleInner = newClass("d$a"); | ||
| 32 | private static final ClassEntry ConstructorArgsOuter = newClass("c"); | ||
| 33 | private static final ClassEntry ConstructorArgsInner = newClass("c$a"); | ||
| 34 | private static final ClassEntry ClassTreeRoot = newClass("f"); | ||
| 35 | private static final ClassEntry ClassTreeLevel1 = newClass("f$a"); | ||
| 36 | private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a"); | ||
| 37 | private static final ClassEntry ClassTreeLevel3 = newClass("f$a$a$a"); | ||
| 38 | private final JarIndex index; | ||
| 39 | private final Decompiler decompiler; | ||
| 40 | |||
| 41 | public TestInnerClasses() throws Exception { | ||
| 42 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/innerClasses.jar")); | ||
| 43 | index = classCache.index(ProgressListener.none()); | ||
| 44 | decompiler = Decompilers.PROCYON.create(classCache, new SourceSettings(false, false)); | ||
| 45 | } | ||
| 46 | |||
| 47 | @Test | ||
| 48 | public void simple() { | ||
| 49 | decompile(SimpleOuter); | ||
| 50 | } | ||
| 51 | |||
| 52 | @Test | ||
| 53 | public void constructorArgs() { | ||
| 54 | decompile(ConstructorArgsOuter); | ||
| 55 | } | ||
| 56 | |||
| 57 | @Test | ||
| 58 | public void classTree() { | ||
| 59 | |||
| 60 | // root level | ||
| 61 | assertThat(index.getEntryIndex().hasClass(ClassTreeRoot), is(true)); | ||
| 62 | |||
| 63 | // level 1 | ||
| 64 | ClassEntry fullClassEntry = new ClassEntry(ClassTreeRoot.getName() | ||
| 65 | + "$" + ClassTreeLevel1.getSimpleName()); | ||
| 66 | assertThat(index.getEntryIndex().hasClass(fullClassEntry), is(true)); | ||
| 67 | |||
| 68 | // level 2 | ||
| 69 | fullClassEntry = new ClassEntry(ClassTreeRoot.getName() | ||
| 70 | + "$" + ClassTreeLevel1.getSimpleName() | ||
| 71 | + "$" + ClassTreeLevel2.getSimpleName()); | ||
| 72 | assertThat(index.getEntryIndex().hasClass(fullClassEntry), is(true)); | ||
| 73 | |||
| 74 | // level 3 | ||
| 75 | fullClassEntry = new ClassEntry(ClassTreeRoot.getName() | ||
| 76 | + "$" + ClassTreeLevel1.getSimpleName() | ||
| 77 | + "$" + ClassTreeLevel2.getSimpleName() | ||
| 78 | + "$" + ClassTreeLevel3.getSimpleName()); | ||
| 79 | assertThat(index.getEntryIndex().hasClass(fullClassEntry), is(true)); | ||
| 80 | } | ||
| 81 | |||
| 82 | private void decompile(ClassEntry classEntry) { | ||
| 83 | decompiler.getSource(classEntry.getName()); | ||
| 84 | } | ||
| 85 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java b/enigma/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java new file mode 100644 index 0000000..48975c8 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.analysis.ClassCache; | ||
| 15 | import cuchaz.enigma.analysis.EntryReference; | ||
| 16 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 17 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 18 | import cuchaz.enigma.translation.representation.entry.MethodDefEntry; | ||
| 19 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 20 | import org.junit.Test; | ||
| 21 | |||
| 22 | import java.nio.file.Paths; | ||
| 23 | import java.util.Collection; | ||
| 24 | |||
| 25 | import static cuchaz.enigma.TestEntryFactory.*; | ||
| 26 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 27 | import static org.hamcrest.Matchers.*; | ||
| 28 | |||
| 29 | public class TestJarIndexConstructorReferences { | ||
| 30 | |||
| 31 | private JarIndex index; | ||
| 32 | |||
| 33 | private ClassEntry baseClass = newClass("a"); | ||
| 34 | private ClassEntry subClass = newClass("d"); | ||
| 35 | private ClassEntry subsubClass = newClass("e"); | ||
| 36 | private ClassEntry defaultClass = newClass("c"); | ||
| 37 | private ClassEntry callerClass = newClass("b"); | ||
| 38 | |||
| 39 | public TestJarIndexConstructorReferences() throws Exception { | ||
| 40 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/constructors.jar")); | ||
| 41 | index = classCache.index(ProgressListener.none()); | ||
| 42 | } | ||
| 43 | |||
| 44 | @Test | ||
| 45 | public void obfEntries() { | ||
| 46 | assertThat(index.getEntryIndex().getClasses(), containsInAnyOrder(newClass("cuchaz/enigma/inputs/Keep"), baseClass, | ||
| 47 | subClass, subsubClass, defaultClass, callerClass)); | ||
| 48 | } | ||
| 49 | |||
| 50 | @Test | ||
| 51 | @SuppressWarnings("unchecked") | ||
| 52 | public void baseDefault() { | ||
| 53 | MethodEntry source = newMethod(baseClass, "<init>", "()V"); | ||
| 54 | Collection<EntryReference<MethodEntry, MethodDefEntry>> references = index.getReferenceIndex().getReferencesToMethod(source); | ||
| 55 | assertThat(references, containsInAnyOrder( | ||
| 56 | newBehaviorReferenceByMethod(source, callerClass.getName(), "a", "()V"), | ||
| 57 | newBehaviorReferenceByMethod(source, subClass.getName(), "<init>", "()V"), | ||
| 58 | newBehaviorReferenceByMethod(source, subClass.getName(), "<init>", "(III)V") | ||
| 59 | )); | ||
| 60 | } | ||
| 61 | |||
| 62 | @Test | ||
| 63 | @SuppressWarnings("unchecked") | ||
| 64 | public void baseInt() { | ||
| 65 | MethodEntry source = newMethod(baseClass, "<init>", "(I)V"); | ||
| 66 | assertThat(index.getReferenceIndex().getReferencesToMethod(source), containsInAnyOrder( | ||
| 67 | newBehaviorReferenceByMethod(source, callerClass.getName(), "b", "()V") | ||
| 68 | )); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Test | ||
| 72 | @SuppressWarnings("unchecked") | ||
| 73 | public void subDefault() { | ||
| 74 | MethodEntry source = newMethod(subClass, "<init>", "()V"); | ||
| 75 | assertThat(index.getReferenceIndex().getReferencesToMethod(source), containsInAnyOrder( | ||
| 76 | newBehaviorReferenceByMethod(source, callerClass.getName(), "c", "()V"), | ||
| 77 | newBehaviorReferenceByMethod(source, subClass.getName(), "<init>", "(I)V") | ||
| 78 | )); | ||
| 79 | } | ||
| 80 | |||
| 81 | @Test | ||
| 82 | @SuppressWarnings("unchecked") | ||
| 83 | public void subInt() { | ||
| 84 | MethodEntry source = newMethod(subClass, "<init>", "(I)V"); | ||
| 85 | assertThat(index.getReferenceIndex().getReferencesToMethod(source), containsInAnyOrder( | ||
| 86 | newBehaviorReferenceByMethod(source, callerClass.getName(), "d", "()V"), | ||
| 87 | newBehaviorReferenceByMethod(source, subClass.getName(), "<init>", "(II)V"), | ||
| 88 | newBehaviorReferenceByMethod(source, subsubClass.getName(), "<init>", "(I)V") | ||
| 89 | )); | ||
| 90 | } | ||
| 91 | |||
| 92 | @Test | ||
| 93 | @SuppressWarnings("unchecked") | ||
| 94 | public void subIntInt() { | ||
| 95 | MethodEntry source = newMethod(subClass, "<init>", "(II)V"); | ||
| 96 | assertThat(index.getReferenceIndex().getReferencesToMethod(source), containsInAnyOrder( | ||
| 97 | newBehaviorReferenceByMethod(source, callerClass.getName(), "e", "()V") | ||
| 98 | )); | ||
| 99 | } | ||
| 100 | |||
| 101 | @Test | ||
| 102 | public void subIntIntInt() { | ||
| 103 | MethodEntry source = newMethod(subClass, "<init>", "(III)V"); | ||
| 104 | assertThat(index.getReferenceIndex().getReferencesToMethod(source), is(empty())); | ||
| 105 | } | ||
| 106 | |||
| 107 | @Test | ||
| 108 | @SuppressWarnings("unchecked") | ||
| 109 | public void subsubInt() { | ||
| 110 | MethodEntry source = newMethod(subsubClass, "<init>", "(I)V"); | ||
| 111 | assertThat(index.getReferenceIndex().getReferencesToMethod(source), containsInAnyOrder( | ||
| 112 | newBehaviorReferenceByMethod(source, callerClass.getName(), "f", "()V") | ||
| 113 | )); | ||
| 114 | } | ||
| 115 | |||
| 116 | @Test | ||
| 117 | @SuppressWarnings("unchecked") | ||
| 118 | public void defaultConstructable() { | ||
| 119 | MethodEntry source = newMethod(defaultClass, "<init>", "()V"); | ||
| 120 | assertThat(index.getReferenceIndex().getReferencesToMethod(source), containsInAnyOrder( | ||
| 121 | newBehaviorReferenceByMethod(source, callerClass.getName(), "g", "()V") | ||
| 122 | )); | ||
| 123 | } | ||
| 124 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java b/enigma/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java new file mode 100644 index 0000000..76e379c --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java | |||
| @@ -0,0 +1,227 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.analysis.ClassCache; | ||
| 15 | import cuchaz.enigma.analysis.EntryReference; | ||
| 16 | import cuchaz.enigma.analysis.index.EntryIndex; | ||
| 17 | import cuchaz.enigma.analysis.index.InheritanceIndex; | ||
| 18 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 19 | import cuchaz.enigma.translation.mapping.EntryResolver; | ||
| 20 | import cuchaz.enigma.translation.mapping.IndexEntryResolver; | ||
| 21 | import cuchaz.enigma.translation.representation.AccessFlags; | ||
| 22 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 23 | import cuchaz.enigma.translation.representation.entry.FieldEntry; | ||
| 24 | import cuchaz.enigma.translation.representation.entry.MethodDefEntry; | ||
| 25 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 26 | import org.junit.Test; | ||
| 27 | import org.objectweb.asm.Opcodes; | ||
| 28 | |||
| 29 | import java.nio.file.Paths; | ||
| 30 | import java.util.Collection; | ||
| 31 | |||
| 32 | import static cuchaz.enigma.TestEntryFactory.*; | ||
| 33 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 34 | import static org.hamcrest.Matchers.*; | ||
| 35 | |||
| 36 | public class TestJarIndexInheritanceTree { | ||
| 37 | |||
| 38 | private JarIndex index; | ||
| 39 | |||
| 40 | private ClassEntry baseClass = newClass("a"); | ||
| 41 | private ClassEntry subClassA = newClass("b"); | ||
| 42 | private ClassEntry subClassAA = newClass("d"); | ||
| 43 | private ClassEntry subClassB = newClass("c"); | ||
| 44 | private FieldEntry nameField = newField(baseClass, "a", "Ljava/lang/String;"); | ||
| 45 | private FieldEntry numThingsField = newField(subClassB, "a", "I"); | ||
| 46 | |||
| 47 | public TestJarIndexInheritanceTree() | ||
| 48 | throws Exception { | ||
| 49 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/inheritanceTree.jar")); | ||
| 50 | index = classCache.index(ProgressListener.none()); | ||
| 51 | } | ||
| 52 | |||
| 53 | @Test | ||
| 54 | public void obfEntries() { | ||
| 55 | assertThat(index.getEntryIndex().getClasses(), containsInAnyOrder( | ||
| 56 | newClass("cuchaz/enigma/inputs/Keep"), baseClass, subClassA, subClassAA, subClassB | ||
| 57 | )); | ||
| 58 | } | ||
| 59 | |||
| 60 | @Test | ||
| 61 | public void translationIndex() { | ||
| 62 | |||
| 63 | InheritanceIndex index = this.index.getInheritanceIndex(); | ||
| 64 | |||
| 65 | // base class | ||
| 66 | assertThat(index.getParents(baseClass), is(empty())); | ||
| 67 | assertThat(index.getAncestors(baseClass), is(empty())); | ||
| 68 | assertThat(index.getChildren(baseClass), containsInAnyOrder(subClassA, subClassB | ||
| 69 | )); | ||
| 70 | |||
| 71 | // subclass a | ||
| 72 | assertThat(index.getParents(subClassA), contains(baseClass)); | ||
| 73 | assertThat(index.getAncestors(subClassA), containsInAnyOrder(baseClass)); | ||
| 74 | assertThat(index.getChildren(subClassA), contains(subClassAA)); | ||
| 75 | |||
| 76 | // subclass aa | ||
| 77 | assertThat(index.getParents(subClassAA), contains(subClassA)); | ||
| 78 | assertThat(index.getAncestors(subClassAA), containsInAnyOrder(subClassA, baseClass)); | ||
| 79 | assertThat(index.getChildren(subClassAA), is(empty())); | ||
| 80 | |||
| 81 | // subclass b | ||
| 82 | assertThat(index.getParents(subClassB), contains(baseClass)); | ||
| 83 | assertThat(index.getAncestors(subClassB), containsInAnyOrder(baseClass)); | ||
| 84 | assertThat(index.getChildren(subClassB), is(empty())); | ||
| 85 | } | ||
| 86 | |||
| 87 | @Test | ||
| 88 | public void access() { | ||
| 89 | assertThat(index.getEntryIndex().getFieldAccess(nameField), is(new AccessFlags(Opcodes.ACC_PRIVATE))); | ||
| 90 | assertThat(index.getEntryIndex().getFieldAccess(numThingsField), is(new AccessFlags(Opcodes.ACC_PRIVATE))); | ||
| 91 | } | ||
| 92 | |||
| 93 | @Test | ||
| 94 | public void relatedMethodImplementations() { | ||
| 95 | |||
| 96 | Collection<MethodEntry> entries; | ||
| 97 | |||
| 98 | EntryResolver resolver = new IndexEntryResolver(index); | ||
| 99 | // getName() | ||
| 100 | entries = resolver.resolveEquivalentMethods(newMethod(baseClass, "a", "()Ljava/lang/String;")); | ||
| 101 | assertThat(entries, containsInAnyOrder( | ||
| 102 | newMethod(baseClass, "a", "()Ljava/lang/String;"), | ||
| 103 | newMethod(subClassAA, "a", "()Ljava/lang/String;") | ||
| 104 | )); | ||
| 105 | entries = resolver.resolveEquivalentMethods(newMethod(subClassAA, "a", "()Ljava/lang/String;")); | ||
| 106 | assertThat(entries, containsInAnyOrder( | ||
| 107 | newMethod(baseClass, "a", "()Ljava/lang/String;"), | ||
| 108 | newMethod(subClassAA, "a", "()Ljava/lang/String;") | ||
| 109 | )); | ||
| 110 | |||
| 111 | // doBaseThings() | ||
| 112 | entries = resolver.resolveEquivalentMethods(newMethod(baseClass, "a", "()V")); | ||
| 113 | assertThat(entries, containsInAnyOrder( | ||
| 114 | newMethod(baseClass, "a", "()V"), | ||
| 115 | newMethod(subClassAA, "a", "()V"), | ||
| 116 | newMethod(subClassB, "a", "()V") | ||
| 117 | )); | ||
| 118 | entries = resolver.resolveEquivalentMethods(newMethod(subClassAA, "a", "()V")); | ||
| 119 | assertThat(entries, containsInAnyOrder( | ||
| 120 | newMethod(baseClass, "a", "()V"), | ||
| 121 | newMethod(subClassAA, "a", "()V"), | ||
| 122 | newMethod(subClassB, "a", "()V") | ||
| 123 | )); | ||
| 124 | entries = resolver.resolveEquivalentMethods(newMethod(subClassB, "a", "()V")); | ||
| 125 | assertThat(entries, containsInAnyOrder( | ||
| 126 | newMethod(baseClass, "a", "()V"), | ||
| 127 | newMethod(subClassAA, "a", "()V"), | ||
| 128 | newMethod(subClassB, "a", "()V") | ||
| 129 | )); | ||
| 130 | |||
| 131 | // doBThings | ||
| 132 | entries = resolver.resolveEquivalentMethods(newMethod(subClassB, "b", "()V")); | ||
| 133 | assertThat(entries, containsInAnyOrder(newMethod(subClassB, "b", "()V"))); | ||
| 134 | } | ||
| 135 | |||
| 136 | @Test | ||
| 137 | @SuppressWarnings("unchecked") | ||
| 138 | public void fieldReferences() { | ||
| 139 | Collection<EntryReference<FieldEntry, MethodDefEntry>> references; | ||
| 140 | |||
| 141 | // name | ||
| 142 | references = index.getReferenceIndex().getReferencesToField(nameField); | ||
| 143 | assertThat(references, containsInAnyOrder( | ||
| 144 | newFieldReferenceByMethod(nameField, baseClass.getName(), "<init>", "(Ljava/lang/String;)V"), | ||
| 145 | newFieldReferenceByMethod(nameField, baseClass.getName(), "a", "()Ljava/lang/String;") | ||
| 146 | )); | ||
| 147 | |||
| 148 | // numThings | ||
| 149 | references = index.getReferenceIndex().getReferencesToField(numThingsField); | ||
| 150 | assertThat(references, containsInAnyOrder( | ||
| 151 | newFieldReferenceByMethod(numThingsField, subClassB.getName(), "<init>", "()V"), | ||
| 152 | newFieldReferenceByMethod(numThingsField, subClassB.getName(), "b", "()V") | ||
| 153 | )); | ||
| 154 | } | ||
| 155 | |||
| 156 | @Test | ||
| 157 | @SuppressWarnings("unchecked") | ||
| 158 | public void behaviorReferences() { | ||
| 159 | |||
| 160 | MethodEntry source; | ||
| 161 | Collection<EntryReference<MethodEntry, MethodDefEntry>> references; | ||
| 162 | |||
| 163 | // baseClass constructor | ||
| 164 | source = newMethod(baseClass, "<init>", "(Ljava/lang/String;)V"); | ||
| 165 | references = index.getReferenceIndex().getReferencesToMethod(source); | ||
| 166 | assertThat(references, containsInAnyOrder( | ||
| 167 | newBehaviorReferenceByMethod(source, subClassA.getName(), "<init>", "(Ljava/lang/String;)V"), | ||
| 168 | newBehaviorReferenceByMethod(source, subClassB.getName(), "<init>", "()V") | ||
| 169 | )); | ||
| 170 | |||
| 171 | // subClassA constructor | ||
| 172 | source = newMethod(subClassA, "<init>", "(Ljava/lang/String;)V"); | ||
| 173 | references = index.getReferenceIndex().getReferencesToMethod(source); | ||
| 174 | assertThat(references, containsInAnyOrder( | ||
| 175 | newBehaviorReferenceByMethod(source, subClassAA.getName(), "<init>", "()V") | ||
| 176 | )); | ||
| 177 | |||
| 178 | // baseClass.getName() | ||
| 179 | source = newMethod(baseClass, "a", "()Ljava/lang/String;"); | ||
| 180 | references = index.getReferenceIndex().getReferencesToMethod(source); | ||
| 181 | assertThat(references, containsInAnyOrder( | ||
| 182 | newBehaviorReferenceByMethod(source, subClassAA.getName(), "a", "()Ljava/lang/String;"), | ||
| 183 | newBehaviorReferenceByMethod(source, subClassB.getName(), "a", "()V") | ||
| 184 | )); | ||
| 185 | |||
| 186 | // subclassAA.getName() | ||
| 187 | source = newMethod(subClassAA, "a", "()Ljava/lang/String;"); | ||
| 188 | references = index.getReferenceIndex().getReferencesToMethod(source); | ||
| 189 | assertThat(references, containsInAnyOrder( | ||
| 190 | newBehaviorReferenceByMethod(source, subClassAA.getName(), "a", "()V") | ||
| 191 | )); | ||
| 192 | } | ||
| 193 | |||
| 194 | @Test | ||
| 195 | public void containsEntries() { | ||
| 196 | EntryIndex entryIndex = index.getEntryIndex(); | ||
| 197 | // classes | ||
| 198 | assertThat(entryIndex.hasClass(baseClass), is(true)); | ||
| 199 | assertThat(entryIndex.hasClass(subClassA), is(true)); | ||
| 200 | assertThat(entryIndex.hasClass(subClassAA), is(true)); | ||
| 201 | assertThat(entryIndex.hasClass(subClassB), is(true)); | ||
| 202 | |||
| 203 | // fields | ||
| 204 | assertThat(entryIndex.hasField(nameField), is(true)); | ||
| 205 | assertThat(entryIndex.hasField(numThingsField), is(true)); | ||
| 206 | |||
| 207 | // methods | ||
| 208 | // getName() | ||
| 209 | assertThat(entryIndex.hasMethod(newMethod(baseClass, "a", "()Ljava/lang/String;")), is(true)); | ||
| 210 | assertThat(entryIndex.hasMethod(newMethod(subClassA, "a", "()Ljava/lang/String;")), is(false)); | ||
| 211 | assertThat(entryIndex.hasMethod(newMethod(subClassAA, "a", "()Ljava/lang/String;")), is(true)); | ||
| 212 | assertThat(entryIndex.hasMethod(newMethod(subClassB, "a", "()Ljava/lang/String;")), is(false)); | ||
| 213 | |||
| 214 | // doBaseThings() | ||
| 215 | assertThat(entryIndex.hasMethod(newMethod(baseClass, "a", "()V")), is(true)); | ||
| 216 | assertThat(entryIndex.hasMethod(newMethod(subClassA, "a", "()V")), is(false)); | ||
| 217 | assertThat(entryIndex.hasMethod(newMethod(subClassAA, "a", "()V")), is(true)); | ||
| 218 | assertThat(entryIndex.hasMethod(newMethod(subClassB, "a", "()V")), is(true)); | ||
| 219 | |||
| 220 | // doBThings() | ||
| 221 | assertThat(entryIndex.hasMethod(newMethod(baseClass, "b", "()V")), is(false)); | ||
| 222 | assertThat(entryIndex.hasMethod(newMethod(subClassA, "b", "()V")), is(false)); | ||
| 223 | assertThat(entryIndex.hasMethod(newMethod(subClassAA, "b", "()V")), is(false)); | ||
| 224 | assertThat(entryIndex.hasMethod(newMethod(subClassB, "b", "()V")), is(true)); | ||
| 225 | |||
| 226 | } | ||
| 227 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java b/enigma/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java new file mode 100644 index 0000000..103c366 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java | |||
| @@ -0,0 +1,157 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.analysis.*; | ||
| 15 | import cuchaz.enigma.analysis.index.EntryIndex; | ||
| 16 | import cuchaz.enigma.analysis.index.InheritanceIndex; | ||
| 17 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 18 | import cuchaz.enigma.translation.VoidTranslator; | ||
| 19 | import cuchaz.enigma.translation.representation.AccessFlags; | ||
| 20 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 21 | import cuchaz.enigma.translation.representation.entry.FieldEntry; | ||
| 22 | import cuchaz.enigma.translation.representation.entry.MethodDefEntry; | ||
| 23 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 24 | import org.junit.Test; | ||
| 25 | |||
| 26 | import java.nio.file.Paths; | ||
| 27 | import java.util.Collection; | ||
| 28 | import java.util.List; | ||
| 29 | |||
| 30 | import static cuchaz.enigma.TestEntryFactory.*; | ||
| 31 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 32 | import static org.hamcrest.Matchers.*; | ||
| 33 | |||
| 34 | public class TestJarIndexLoneClass { | ||
| 35 | |||
| 36 | private JarIndex index; | ||
| 37 | |||
| 38 | public TestJarIndexLoneClass() throws Exception { | ||
| 39 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/loneClass.jar")); | ||
| 40 | index = classCache.index(ProgressListener.none()); | ||
| 41 | } | ||
| 42 | |||
| 43 | @Test | ||
| 44 | public void obfEntries() { | ||
| 45 | assertThat(index.getEntryIndex().getClasses(), containsInAnyOrder( | ||
| 46 | newClass("cuchaz/enigma/inputs/Keep"), | ||
| 47 | newClass("a") | ||
| 48 | )); | ||
| 49 | } | ||
| 50 | |||
| 51 | @Test | ||
| 52 | public void translationIndex() { | ||
| 53 | InheritanceIndex inheritanceIndex = index.getInheritanceIndex(); | ||
| 54 | assertThat(inheritanceIndex.getParents(new ClassEntry("a")), is(empty())); | ||
| 55 | assertThat(inheritanceIndex.getParents(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); | ||
| 56 | assertThat(inheritanceIndex.getAncestors(new ClassEntry("a")), is(empty())); | ||
| 57 | assertThat(inheritanceIndex.getAncestors(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); | ||
| 58 | assertThat(inheritanceIndex.getChildren(new ClassEntry("a")), is(empty())); | ||
| 59 | assertThat(inheritanceIndex.getChildren(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); | ||
| 60 | } | ||
| 61 | |||
| 62 | @Test | ||
| 63 | public void access() { | ||
| 64 | EntryIndex entryIndex = index.getEntryIndex(); | ||
| 65 | assertThat(entryIndex.getFieldAccess(newField("a", "a", "Ljava/lang/String;")), is(AccessFlags.PRIVATE)); | ||
| 66 | assertThat(entryIndex.getMethodAccess(newMethod("a", "a", "()Ljava/lang/String;")), is(AccessFlags.PUBLIC)); | ||
| 67 | assertThat(entryIndex.getFieldAccess(newField("a", "b", "Ljava/lang/String;")), is(nullValue())); | ||
| 68 | assertThat(entryIndex.getFieldAccess(newField("a", "a", "LFoo;")), is(nullValue())); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Test | ||
| 72 | public void classInheritance() { | ||
| 73 | IndexTreeBuilder treeBuilder = new IndexTreeBuilder(index); | ||
| 74 | ClassInheritanceTreeNode node = treeBuilder.buildClassInheritance(VoidTranslator.INSTANCE, newClass("a")); | ||
| 75 | assertThat(node, is(not(nullValue()))); | ||
| 76 | assertThat(node.getObfClassName(), is("a")); | ||
| 77 | assertThat(node.getChildCount(), is(0)); | ||
| 78 | } | ||
| 79 | |||
| 80 | @Test | ||
| 81 | public void methodInheritance() { | ||
| 82 | IndexTreeBuilder treeBuilder = new IndexTreeBuilder(index); | ||
| 83 | MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;"); | ||
| 84 | MethodInheritanceTreeNode node = treeBuilder.buildMethodInheritance(VoidTranslator.INSTANCE, source); | ||
| 85 | assertThat(node, is(not(nullValue()))); | ||
| 86 | assertThat(node.getMethodEntry(), is(source)); | ||
| 87 | assertThat(node.getChildCount(), is(0)); | ||
| 88 | } | ||
| 89 | |||
| 90 | @Test | ||
| 91 | public void classImplementations() { | ||
| 92 | IndexTreeBuilder treeBuilder = new IndexTreeBuilder(index); | ||
| 93 | ClassImplementationsTreeNode node = treeBuilder.buildClassImplementations(VoidTranslator.INSTANCE, newClass("a")); | ||
| 94 | assertThat(node, is(nullValue())); | ||
| 95 | } | ||
| 96 | |||
| 97 | @Test | ||
| 98 | public void methodImplementations() { | ||
| 99 | IndexTreeBuilder treeBuilder = new IndexTreeBuilder(index); | ||
| 100 | MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;"); | ||
| 101 | |||
| 102 | List<MethodImplementationsTreeNode> nodes = treeBuilder.buildMethodImplementations(VoidTranslator.INSTANCE, source); | ||
| 103 | assertThat(nodes, hasSize(1)); | ||
| 104 | assertThat(nodes.get(0).getMethodEntry(), is(source)); | ||
| 105 | } | ||
| 106 | |||
| 107 | @Test | ||
| 108 | public void relatedMethodImplementations() { | ||
| 109 | Collection<MethodEntry> entries = index.getEntryResolver().resolveEquivalentMethods(newMethod("a", "a", "()Ljava/lang/String;")); | ||
| 110 | assertThat(entries, containsInAnyOrder( | ||
| 111 | newMethod("a", "a", "()Ljava/lang/String;") | ||
| 112 | )); | ||
| 113 | } | ||
| 114 | |||
| 115 | @Test | ||
| 116 | @SuppressWarnings("unchecked") | ||
| 117 | public void fieldReferences() { | ||
| 118 | FieldEntry source = newField("a", "a", "Ljava/lang/String;"); | ||
| 119 | Collection<EntryReference<FieldEntry, MethodDefEntry>> references = index.getReferenceIndex().getReferencesToField(source); | ||
| 120 | assertThat(references, containsInAnyOrder( | ||
| 121 | newFieldReferenceByMethod(source, "a", "<init>", "(Ljava/lang/String;)V"), | ||
| 122 | newFieldReferenceByMethod(source, "a", "a", "()Ljava/lang/String;") | ||
| 123 | )); | ||
| 124 | } | ||
| 125 | |||
| 126 | @Test | ||
| 127 | public void behaviorReferences() { | ||
| 128 | assertThat(index.getReferenceIndex().getReferencesToMethod(newMethod("a", "a", "()Ljava/lang/String;")), is(empty())); | ||
| 129 | } | ||
| 130 | |||
| 131 | @Test | ||
| 132 | public void interfaces() { | ||
| 133 | assertThat(index.getInheritanceIndex().getParents(new ClassEntry("a")), is(empty())); | ||
| 134 | } | ||
| 135 | |||
| 136 | @Test | ||
| 137 | public void implementingClasses() { | ||
| 138 | assertThat(index.getInheritanceIndex().getChildren(new ClassEntry("a")), is(empty())); | ||
| 139 | } | ||
| 140 | |||
| 141 | @Test | ||
| 142 | public void isInterface() { | ||
| 143 | assertThat(index.getInheritanceIndex().isParent(new ClassEntry("a")), is(false)); | ||
| 144 | } | ||
| 145 | |||
| 146 | @Test | ||
| 147 | public void testContains() { | ||
| 148 | EntryIndex entryIndex = index.getEntryIndex(); | ||
| 149 | assertThat(entryIndex.hasClass(newClass("a")), is(true)); | ||
| 150 | assertThat(entryIndex.hasClass(newClass("b")), is(false)); | ||
| 151 | assertThat(entryIndex.hasField(newField("a", "a", "Ljava/lang/String;")), is(true)); | ||
| 152 | assertThat(entryIndex.hasField(newField("a", "b", "Ljava/lang/String;")), is(false)); | ||
| 153 | assertThat(entryIndex.hasField(newField("a", "a", "LFoo;")), is(false)); | ||
| 154 | assertThat(entryIndex.hasMethod(newMethod("a", "a", "()Ljava/lang/String;")), is(true)); | ||
| 155 | assertThat(entryIndex.hasMethod(newMethod("a", "b", "()Ljava/lang/String;")), is(false)); | ||
| 156 | } | ||
| 157 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/TestMethodDescriptor.java b/enigma/src/test/java/cuchaz/enigma/TestMethodDescriptor.java new file mode 100644 index 0000000..a73880d --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/TestMethodDescriptor.java | |||
| @@ -0,0 +1,247 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.translation.representation.MethodDescriptor; | ||
| 15 | import cuchaz.enigma.translation.representation.TypeDescriptor; | ||
| 16 | import org.junit.Test; | ||
| 17 | |||
| 18 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 19 | import static org.hamcrest.Matchers.*; | ||
| 20 | |||
| 21 | public class TestMethodDescriptor { | ||
| 22 | |||
| 23 | @Test | ||
| 24 | public void easiest() { | ||
| 25 | final MethodDescriptor sig = new MethodDescriptor("()V"); | ||
| 26 | assertThat(sig.getArgumentDescs(), is(empty())); | ||
| 27 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V"))); | ||
| 28 | } | ||
| 29 | |||
| 30 | @Test | ||
| 31 | public void primitives() { | ||
| 32 | { | ||
| 33 | final MethodDescriptor sig = new MethodDescriptor("(I)V"); | ||
| 34 | assertThat(sig.getArgumentDescs(), contains( | ||
| 35 | new TypeDescriptor("I") | ||
| 36 | )); | ||
| 37 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V"))); | ||
| 38 | } | ||
| 39 | { | ||
| 40 | final MethodDescriptor sig = new MethodDescriptor("(I)I"); | ||
| 41 | assertThat(sig.getArgumentDescs(), contains( | ||
| 42 | new TypeDescriptor("I") | ||
| 43 | )); | ||
| 44 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("I"))); | ||
| 45 | } | ||
| 46 | { | ||
| 47 | final MethodDescriptor sig = new MethodDescriptor("(IBCJ)Z"); | ||
| 48 | assertThat(sig.getArgumentDescs(), contains( | ||
| 49 | new TypeDescriptor("I"), | ||
| 50 | new TypeDescriptor("B"), | ||
| 51 | new TypeDescriptor("C"), | ||
| 52 | new TypeDescriptor("J") | ||
| 53 | )); | ||
| 54 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("Z"))); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | @Test | ||
| 59 | public void classes() { | ||
| 60 | { | ||
| 61 | final MethodDescriptor sig = new MethodDescriptor("([LFoo;)V"); | ||
| 62 | assertThat(sig.getArgumentDescs().size(), is(1)); | ||
| 63 | assertThat(sig.getArgumentDescs().get(0), is(new TypeDescriptor("[LFoo;"))); | ||
| 64 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V"))); | ||
| 65 | } | ||
| 66 | { | ||
| 67 | final MethodDescriptor sig = new MethodDescriptor("(LFoo;)LBar;"); | ||
| 68 | assertThat(sig.getArgumentDescs(), contains( | ||
| 69 | new TypeDescriptor("LFoo;") | ||
| 70 | )); | ||
| 71 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("LBar;"))); | ||
| 72 | } | ||
| 73 | { | ||
| 74 | final MethodDescriptor sig = new MethodDescriptor("(LFoo;LMoo;LZoo;)LBar;"); | ||
| 75 | assertThat(sig.getArgumentDescs(), contains( | ||
| 76 | new TypeDescriptor("LFoo;"), | ||
| 77 | new TypeDescriptor("LMoo;"), | ||
| 78 | new TypeDescriptor("LZoo;") | ||
| 79 | )); | ||
| 80 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("LBar;"))); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | @Test | ||
| 85 | public void arrays() { | ||
| 86 | { | ||
| 87 | final MethodDescriptor sig = new MethodDescriptor("([I)V"); | ||
| 88 | assertThat(sig.getArgumentDescs(), contains( | ||
| 89 | new TypeDescriptor("[I") | ||
| 90 | )); | ||
| 91 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V"))); | ||
| 92 | } | ||
| 93 | { | ||
| 94 | final MethodDescriptor sig = new MethodDescriptor("([I)[J"); | ||
| 95 | assertThat(sig.getArgumentDescs(), contains( | ||
| 96 | new TypeDescriptor("[I") | ||
| 97 | )); | ||
| 98 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("[J"))); | ||
| 99 | } | ||
| 100 | { | ||
| 101 | final MethodDescriptor sig = new MethodDescriptor("([I[Z[F)[D"); | ||
| 102 | assertThat(sig.getArgumentDescs(), contains( | ||
| 103 | new TypeDescriptor("[I"), | ||
| 104 | new TypeDescriptor("[Z"), | ||
| 105 | new TypeDescriptor("[F") | ||
| 106 | )); | ||
| 107 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("[D"))); | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | @Test | ||
| 112 | public void mixed() { | ||
| 113 | { | ||
| 114 | final MethodDescriptor sig = new MethodDescriptor("(I[JLFoo;)Z"); | ||
| 115 | assertThat(sig.getArgumentDescs(), contains( | ||
| 116 | new TypeDescriptor("I"), | ||
| 117 | new TypeDescriptor("[J"), | ||
| 118 | new TypeDescriptor("LFoo;") | ||
| 119 | )); | ||
| 120 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("Z"))); | ||
| 121 | } | ||
| 122 | { | ||
| 123 | final MethodDescriptor sig = new MethodDescriptor("(III)[LFoo;"); | ||
| 124 | assertThat(sig.getArgumentDescs(), contains( | ||
| 125 | new TypeDescriptor("I"), | ||
| 126 | new TypeDescriptor("I"), | ||
| 127 | new TypeDescriptor("I") | ||
| 128 | )); | ||
| 129 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("[LFoo;"))); | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | @Test | ||
| 134 | public void replaceClasses() { | ||
| 135 | { | ||
| 136 | final MethodDescriptor oldSig = new MethodDescriptor("()V"); | ||
| 137 | final MethodDescriptor sig = oldSig.remap(s -> null); | ||
| 138 | assertThat(sig.getArgumentDescs(), is(empty())); | ||
| 139 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V"))); | ||
| 140 | } | ||
| 141 | { | ||
| 142 | final MethodDescriptor oldSig = new MethodDescriptor("(IJLFoo;)V"); | ||
| 143 | final MethodDescriptor sig = oldSig.remap(s -> null); | ||
| 144 | assertThat(sig.getArgumentDescs(), contains( | ||
| 145 | new TypeDescriptor("I"), | ||
| 146 | new TypeDescriptor("J"), | ||
| 147 | new TypeDescriptor("LFoo;") | ||
| 148 | )); | ||
| 149 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V"))); | ||
| 150 | } | ||
| 151 | { | ||
| 152 | final MethodDescriptor oldSig = new MethodDescriptor("(LFoo;LBar;)LMoo;"); | ||
| 153 | final MethodDescriptor sig = oldSig.remap(s -> { | ||
| 154 | if (s.equals("Foo")) { | ||
| 155 | return "Bar"; | ||
| 156 | } | ||
| 157 | return null; | ||
| 158 | }); | ||
| 159 | assertThat(sig.getArgumentDescs(), contains( | ||
| 160 | new TypeDescriptor("LBar;"), | ||
| 161 | new TypeDescriptor("LBar;") | ||
| 162 | )); | ||
| 163 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("LMoo;"))); | ||
| 164 | } | ||
| 165 | { | ||
| 166 | final MethodDescriptor oldSig = new MethodDescriptor("(LFoo;LBar;)LMoo;"); | ||
| 167 | final MethodDescriptor sig = oldSig.remap(s -> { | ||
| 168 | if (s.equals("Moo")) { | ||
| 169 | return "Cow"; | ||
| 170 | } | ||
| 171 | return null; | ||
| 172 | }); | ||
| 173 | assertThat(sig.getArgumentDescs(), contains( | ||
| 174 | new TypeDescriptor("LFoo;"), | ||
| 175 | new TypeDescriptor("LBar;") | ||
| 176 | )); | ||
| 177 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("LCow;"))); | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | @Test | ||
| 182 | public void replaceArrayClasses() { | ||
| 183 | { | ||
| 184 | final MethodDescriptor oldSig = new MethodDescriptor("([LFoo;)[[[LBar;"); | ||
| 185 | final MethodDescriptor sig = oldSig.remap(s -> { | ||
| 186 | if (s.equals("Foo")) { | ||
| 187 | return "Food"; | ||
| 188 | } else if (s.equals("Bar")) { | ||
| 189 | return "Beer"; | ||
| 190 | } | ||
| 191 | return null; | ||
| 192 | }); | ||
| 193 | assertThat(sig.getArgumentDescs(), contains( | ||
| 194 | new TypeDescriptor("[LFood;") | ||
| 195 | )); | ||
| 196 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("[[[LBeer;"))); | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | @Test | ||
| 201 | public void equals() { | ||
| 202 | |||
| 203 | // base | ||
| 204 | assertThat(new MethodDescriptor("()V"), is(new MethodDescriptor("()V"))); | ||
| 205 | |||
| 206 | // arguments | ||
| 207 | assertThat(new MethodDescriptor("(I)V"), is(new MethodDescriptor("(I)V"))); | ||
| 208 | assertThat(new MethodDescriptor("(ZIZ)V"), is(new MethodDescriptor("(ZIZ)V"))); | ||
| 209 | assertThat(new MethodDescriptor("(LFoo;)V"), is(new MethodDescriptor("(LFoo;)V"))); | ||
| 210 | assertThat(new MethodDescriptor("(LFoo;LBar;)V"), is(new MethodDescriptor("(LFoo;LBar;)V"))); | ||
| 211 | assertThat(new MethodDescriptor("([I)V"), is(new MethodDescriptor("([I)V"))); | ||
| 212 | assertThat(new MethodDescriptor("([[D[[[J)V"), is(new MethodDescriptor("([[D[[[J)V"))); | ||
| 213 | |||
| 214 | assertThat(new MethodDescriptor("()V"), is(not(new MethodDescriptor("(I)V")))); | ||
| 215 | assertThat(new MethodDescriptor("(I)V"), is(not(new MethodDescriptor("()V")))); | ||
| 216 | assertThat(new MethodDescriptor("(IJ)V"), is(not(new MethodDescriptor("(JI)V")))); | ||
| 217 | assertThat(new MethodDescriptor("([[Z)V"), is(not(new MethodDescriptor("([[LFoo;)V")))); | ||
| 218 | assertThat(new MethodDescriptor("(LFoo;LBar;)V"), is(not(new MethodDescriptor("(LFoo;LCow;)V")))); | ||
| 219 | assertThat(new MethodDescriptor("([LFoo;LBar;)V"), is(not(new MethodDescriptor("(LFoo;LCow;)V")))); | ||
| 220 | |||
| 221 | // return desc | ||
| 222 | assertThat(new MethodDescriptor("()I"), is(new MethodDescriptor("()I"))); | ||
| 223 | assertThat(new MethodDescriptor("()Z"), is(new MethodDescriptor("()Z"))); | ||
| 224 | assertThat(new MethodDescriptor("()[D"), is(new MethodDescriptor("()[D"))); | ||
| 225 | assertThat(new MethodDescriptor("()[[[Z"), is(new MethodDescriptor("()[[[Z"))); | ||
| 226 | assertThat(new MethodDescriptor("()LFoo;"), is(new MethodDescriptor("()LFoo;"))); | ||
| 227 | assertThat(new MethodDescriptor("()[LFoo;"), is(new MethodDescriptor("()[LFoo;"))); | ||
| 228 | |||
| 229 | assertThat(new MethodDescriptor("()I"), is(not(new MethodDescriptor("()Z")))); | ||
| 230 | assertThat(new MethodDescriptor("()Z"), is(not(new MethodDescriptor("()I")))); | ||
| 231 | assertThat(new MethodDescriptor("()[D"), is(not(new MethodDescriptor("()[J")))); | ||
| 232 | assertThat(new MethodDescriptor("()[[[Z"), is(not(new MethodDescriptor("()[[Z")))); | ||
| 233 | assertThat(new MethodDescriptor("()LFoo;"), is(not(new MethodDescriptor("()LBar;")))); | ||
| 234 | assertThat(new MethodDescriptor("()[LFoo;"), is(not(new MethodDescriptor("()[LBar;")))); | ||
| 235 | } | ||
| 236 | |||
| 237 | @Test | ||
| 238 | public void testToString() { | ||
| 239 | assertThat(new MethodDescriptor("()V").toString(), is("()V")); | ||
| 240 | assertThat(new MethodDescriptor("(I)V").toString(), is("(I)V")); | ||
| 241 | assertThat(new MethodDescriptor("(ZIZ)V").toString(), is("(ZIZ)V")); | ||
| 242 | assertThat(new MethodDescriptor("(LFoo;)V").toString(), is("(LFoo;)V")); | ||
| 243 | assertThat(new MethodDescriptor("(LFoo;LBar;)V").toString(), is("(LFoo;LBar;)V")); | ||
| 244 | assertThat(new MethodDescriptor("([I)V").toString(), is("([I)V")); | ||
| 245 | assertThat(new MethodDescriptor("([[D[[[J)V").toString(), is("([[D[[[J)V")); | ||
| 246 | } | ||
| 247 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/TestTokensConstructors.java b/enigma/src/test/java/cuchaz/enigma/TestTokensConstructors.java new file mode 100644 index 0000000..0398de4 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/TestTokensConstructors.java | |||
| @@ -0,0 +1,137 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 15 | import org.junit.Test; | ||
| 16 | |||
| 17 | import java.nio.file.Paths; | ||
| 18 | |||
| 19 | import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod; | ||
| 20 | import static cuchaz.enigma.TestEntryFactory.newMethod; | ||
| 21 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 22 | import static org.hamcrest.Matchers.*; | ||
| 23 | |||
| 24 | public class TestTokensConstructors extends TokenChecker { | ||
| 25 | |||
| 26 | public TestTokensConstructors() | ||
| 27 | throws Exception { | ||
| 28 | super(Paths.get("build/test-obf/constructors.jar")); | ||
| 29 | } | ||
| 30 | |||
| 31 | @Test | ||
| 32 | public void baseDeclarations() { | ||
| 33 | assertThat(getDeclarationToken(newMethod("a", "<init>", "()V")), is("a")); | ||
| 34 | assertThat(getDeclarationToken(newMethod("a", "<init>", "(I)V")), is("a")); | ||
| 35 | } | ||
| 36 | |||
| 37 | @Test | ||
| 38 | public void subDeclarations() { | ||
| 39 | assertThat(getDeclarationToken(newMethod("d", "<init>", "()V")), is("d")); | ||
| 40 | assertThat(getDeclarationToken(newMethod("d", "<init>", "(I)V")), is("d")); | ||
| 41 | assertThat(getDeclarationToken(newMethod("d", "<init>", "(II)V")), is("d")); | ||
| 42 | assertThat(getDeclarationToken(newMethod("d", "<init>", "(III)V")), is("d")); | ||
| 43 | } | ||
| 44 | |||
| 45 | @Test | ||
| 46 | public void subsubDeclarations() { | ||
| 47 | assertThat(getDeclarationToken(newMethod("e", "<init>", "(I)V")), is("e")); | ||
| 48 | } | ||
| 49 | |||
| 50 | @Test | ||
| 51 | public void defaultDeclarations() { | ||
| 52 | assertThat(getDeclarationToken(newMethod("c", "<init>", "()V")), nullValue()); | ||
| 53 | } | ||
| 54 | |||
| 55 | @Test | ||
| 56 | public void baseDefaultReferences() { | ||
| 57 | MethodEntry source = newMethod("a", "<init>", "()V"); | ||
| 58 | assertThat( | ||
| 59 | getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "a", "()V")), | ||
| 60 | containsInAnyOrder("a") | ||
| 61 | ); | ||
| 62 | assertThat( | ||
| 63 | getReferenceTokens(newBehaviorReferenceByMethod(source, "d", "<init>", "()V")), | ||
| 64 | is(empty()) // implicit call, not decompiled to token | ||
| 65 | ); | ||
| 66 | assertThat( | ||
| 67 | getReferenceTokens(newBehaviorReferenceByMethod(source, "d", "<init>", "(III)V")), | ||
| 68 | is(empty()) // implicit call, not decompiled to token | ||
| 69 | ); | ||
| 70 | } | ||
| 71 | |||
| 72 | @Test | ||
| 73 | public void baseIntReferences() { | ||
| 74 | MethodEntry source = newMethod("a", "<init>", "(I)V"); | ||
| 75 | assertThat( | ||
| 76 | getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "b", "()V")), | ||
| 77 | containsInAnyOrder("a") | ||
| 78 | ); | ||
| 79 | } | ||
| 80 | |||
| 81 | @Test | ||
| 82 | public void subDefaultReferences() { | ||
| 83 | MethodEntry source = newMethod("d", "<init>", "()V"); | ||
| 84 | assertThat( | ||
| 85 | getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "c", "()V")), | ||
| 86 | containsInAnyOrder("d") | ||
| 87 | ); | ||
| 88 | assertThat( | ||
| 89 | getReferenceTokens(newBehaviorReferenceByMethod(source, "d", "<init>", "(I)V")), | ||
| 90 | containsInAnyOrder("this") | ||
| 91 | ); | ||
| 92 | } | ||
| 93 | |||
| 94 | @Test | ||
| 95 | public void subIntReferences() { | ||
| 96 | MethodEntry source = newMethod("d", "<init>", "(I)V"); | ||
| 97 | assertThat(getReferenceTokens( | ||
| 98 | newBehaviorReferenceByMethod(source, "b", "d", "()V")), | ||
| 99 | containsInAnyOrder("d") | ||
| 100 | ); | ||
| 101 | assertThat(getReferenceTokens( | ||
| 102 | newBehaviorReferenceByMethod(source, "d", "<init>", "(II)V")), | ||
| 103 | containsInAnyOrder("this") | ||
| 104 | ); | ||
| 105 | assertThat(getReferenceTokens( | ||
| 106 | newBehaviorReferenceByMethod(source, "e", "<init>", "(I)V")), | ||
| 107 | containsInAnyOrder("super") | ||
| 108 | ); | ||
| 109 | } | ||
| 110 | |||
| 111 | @Test | ||
| 112 | public void subIntIntReferences() { | ||
| 113 | MethodEntry source = newMethod("d", "<init>", "(II)V"); | ||
| 114 | assertThat( | ||
| 115 | getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "e", "()V")), | ||
| 116 | containsInAnyOrder("d") | ||
| 117 | ); | ||
| 118 | } | ||
| 119 | |||
| 120 | @Test | ||
| 121 | public void subsubIntReferences() { | ||
| 122 | MethodEntry source = newMethod("e", "<init>", "(I)V"); | ||
| 123 | assertThat( | ||
| 124 | getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "f", "()V")), | ||
| 125 | containsInAnyOrder("e") | ||
| 126 | ); | ||
| 127 | } | ||
| 128 | |||
| 129 | @Test | ||
| 130 | public void defaultConstructableReferences() { | ||
| 131 | MethodEntry source = newMethod("c", "<init>", "()V"); | ||
| 132 | assertThat( | ||
| 133 | getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "g", "()V")), | ||
| 134 | containsInAnyOrder("c") | ||
| 135 | ); | ||
| 136 | } | ||
| 137 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/TestTranslator.java b/enigma/src/test/java/cuchaz/enigma/TestTranslator.java new file mode 100644 index 0000000..a420afe --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/TestTranslator.java | |||
| @@ -0,0 +1,155 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.translation.representation.entry.Entry; | ||
| 15 | import org.junit.BeforeClass; | ||
| 16 | import org.junit.Test; | ||
| 17 | |||
| 18 | import static cuchaz.enigma.TestEntryFactory.*; | ||
| 19 | |||
| 20 | public class TestTranslator { | ||
| 21 | |||
| 22 | @BeforeClass | ||
| 23 | public static void beforeClass() | ||
| 24 | throws Exception { | ||
| 25 | //TODO FIx | ||
| 26 | //deobfuscator = new Enigma(new JarFile("build/test-obf/translation.jar")); | ||
| 27 | //try (InputStream in = TestTranslator.class.getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { | ||
| 28 | // mappings = new MappingsJsonReader().read(new InputStreamReader(in)); | ||
| 29 | // deobfuscator.setMappings(mappings); | ||
| 30 | // deobfTranslator = deobfuscator.getTranslator(TranslationDirection.Deobfuscating); | ||
| 31 | // obfTranslator = deobfuscator.getTranslator(TranslationDirection.Obfuscating); | ||
| 32 | //} | ||
| 33 | } | ||
| 34 | |||
| 35 | @Test | ||
| 36 | public void basicClasses() { | ||
| 37 | assertMapping(newClass("a"), newClass("deobf/A_Basic")); | ||
| 38 | assertMapping(newClass("b"), newClass("deobf/B_BaseClass")); | ||
| 39 | assertMapping(newClass("c"), newClass("deobf/C_SubClass")); | ||
| 40 | } | ||
| 41 | |||
| 42 | @Test | ||
| 43 | public void basicFields() { | ||
| 44 | assertMapping(newField("a", "a", "I"), newField("deobf/A_Basic", "f1", "I")); | ||
| 45 | assertMapping(newField("a", "a", "F"), newField("deobf/A_Basic", "f2", "F")); | ||
| 46 | assertMapping(newField("a", "a", "Ljava/lang/String;"), newField("deobf/A_Basic", "f3", "Ljava/lang/String;")); | ||
| 47 | } | ||
| 48 | |||
| 49 | @Test | ||
| 50 | public void basicMethods() { | ||
| 51 | assertMapping(newMethod("a", "a", "()V"), newMethod("deobf/A_Basic", "m1", "()V")); | ||
| 52 | assertMapping(newMethod("a", "a", "()I"), newMethod("deobf/A_Basic", "m2", "()I")); | ||
| 53 | assertMapping(newMethod("a", "a", "(I)V"), newMethod("deobf/A_Basic", "m3", "(I)V")); | ||
| 54 | assertMapping(newMethod("a", "a", "(I)I"), newMethod("deobf/A_Basic", "m4", "(I)I")); | ||
| 55 | } | ||
| 56 | |||
| 57 | // TODO: basic constructors | ||
| 58 | |||
| 59 | @Test | ||
| 60 | public void inheritanceFields() { | ||
| 61 | assertMapping(newField("b", "a", "I"), newField("deobf/B_BaseClass", "f1", "I")); | ||
| 62 | assertMapping(newField("b", "a", "C"), newField("deobf/B_BaseClass", "f2", "C")); | ||
| 63 | assertMapping(newField("c", "b", "I"), newField("deobf/C_SubClass", "f3", "I")); | ||
| 64 | assertMapping(newField("c", "c", "I"), newField("deobf/C_SubClass", "f4", "I")); | ||
| 65 | } | ||
| 66 | |||
| 67 | @Test | ||
| 68 | public void inheritanceFieldsShadowing() { | ||
| 69 | assertMapping(newField("c", "b", "C"), newField("deobf/C_SubClass", "f2", "C")); | ||
| 70 | } | ||
| 71 | |||
| 72 | @Test | ||
| 73 | public void inheritanceFieldsBySubClass() { | ||
| 74 | assertMapping(newField("c", "a", "I"), newField("deobf/C_SubClass", "f1", "I")); | ||
| 75 | // NOTE: can't reference b.C by subclass since it's shadowed | ||
| 76 | } | ||
| 77 | |||
| 78 | @Test | ||
| 79 | public void inheritanceMethods() { | ||
| 80 | assertMapping(newMethod("b", "a", "()I"), newMethod("deobf/B_BaseClass", "m1", "()I")); | ||
| 81 | assertMapping(newMethod("b", "b", "()I"), newMethod("deobf/B_BaseClass", "m2", "()I")); | ||
| 82 | assertMapping(newMethod("c", "c", "()I"), newMethod("deobf/C_SubClass", "m3", "()I")); | ||
| 83 | } | ||
| 84 | |||
| 85 | @Test | ||
| 86 | public void inheritanceMethodsOverrides() { | ||
| 87 | assertMapping(newMethod("c", "a", "()I"), newMethod("deobf/C_SubClass", "m1", "()I")); | ||
| 88 | } | ||
| 89 | |||
| 90 | @Test | ||
| 91 | public void inheritanceMethodsBySubClass() { | ||
| 92 | assertMapping(newMethod("c", "b", "()I"), newMethod("deobf/C_SubClass", "m2", "()I")); | ||
| 93 | } | ||
| 94 | |||
| 95 | @Test | ||
| 96 | public void innerClasses() { | ||
| 97 | |||
| 98 | // classes | ||
| 99 | assertMapping(newClass("g"), newClass("deobf/G_OuterClass")); | ||
| 100 | assertMapping(newClass("g$a"), newClass("deobf/G_OuterClass$A_InnerClass")); | ||
| 101 | assertMapping(newClass("g$a$a"), newClass("deobf/G_OuterClass$A_InnerClass$A_InnerInnerClass")); | ||
| 102 | assertMapping(newClass("g$b"), newClass("deobf/G_OuterClass$b")); | ||
| 103 | assertMapping(newClass("g$b$a"), newClass("deobf/G_OuterClass$b$A_NamedInnerClass")); | ||
| 104 | |||
| 105 | // fields | ||
| 106 | assertMapping(newField("g$a", "a", "I"), newField("deobf/G_OuterClass$A_InnerClass", "f1", "I")); | ||
| 107 | assertMapping(newField("g$a", "a", "Ljava/lang/String;"), newField("deobf/G_OuterClass$A_InnerClass", "f2", "Ljava/lang/String;")); | ||
| 108 | assertMapping(newField("g$a$a", "a", "I"), newField("deobf/G_OuterClass$A_InnerClass$A_InnerInnerClass", "f3", "I")); | ||
| 109 | assertMapping(newField("g$b$a", "a", "I"), newField("deobf/G_OuterClass$b$A_NamedInnerClass", "f4", "I")); | ||
| 110 | |||
| 111 | // methods | ||
| 112 | assertMapping(newMethod("g$a", "a", "()V"), newMethod("deobf/G_OuterClass$A_InnerClass", "m1", "()V")); | ||
| 113 | assertMapping(newMethod("g$a$a", "a", "()V"), newMethod("deobf/G_OuterClass$A_InnerClass$A_InnerInnerClass", "m2", "()V")); | ||
| 114 | } | ||
| 115 | |||
| 116 | @Test | ||
| 117 | public void namelessClass() { | ||
| 118 | assertMapping(newClass("h"), newClass("h")); | ||
| 119 | } | ||
| 120 | |||
| 121 | @Test | ||
| 122 | public void testGenerics() { | ||
| 123 | |||
| 124 | // classes | ||
| 125 | assertMapping(newClass("i"), newClass("deobf/I_Generics")); | ||
| 126 | assertMapping(newClass("i$a"), newClass("deobf/I_Generics$A_Type")); | ||
| 127 | assertMapping(newClass("i$b"), newClass("deobf/I_Generics$B_Generic")); | ||
| 128 | |||
| 129 | // fields | ||
| 130 | assertMapping(newField("i", "a", "Ljava/util/List;"), newField("deobf/I_Generics", "f1", "Ljava/util/List;")); | ||
| 131 | assertMapping(newField("i", "b", "Ljava/util/List;"), newField("deobf/I_Generics", "f2", "Ljava/util/List;")); | ||
| 132 | assertMapping(newField("i", "a", "Ljava/util/Map;"), newField("deobf/I_Generics", "f3", "Ljava/util/Map;")); | ||
| 133 | assertMapping(newField("i$b", "a", "Ljava/lang/Object;"), newField("deobf/I_Generics$B_Generic", "f4", "Ljava/lang/Object;")); | ||
| 134 | assertMapping(newField("i", "a", "Li$b;"), newField("deobf/I_Generics", "f5", "Ldeobf/I_Generics$B_Generic;")); | ||
| 135 | assertMapping(newField("i", "b", "Li$b;"), newField("deobf/I_Generics", "f6", "Ldeobf/I_Generics$B_Generic;")); | ||
| 136 | |||
| 137 | // methods | ||
| 138 | assertMapping(newMethod("i$b", "a", "()Ljava/lang/Object;"), newMethod("deobf/I_Generics$B_Generic", "m1", "()Ljava/lang/Object;")); | ||
| 139 | } | ||
| 140 | |||
| 141 | private void assertMapping(Entry<?> obf, Entry<?> deobf) { | ||
| 142 | //assertThat(deobfTranslator.translateEntry(obf), is(deobf)); | ||
| 143 | //assertThat(obfTranslator.translateEntry(deobf), is(obf)); | ||
| 144 | |||
| 145 | //String deobfName = deobfTranslator.translate(obf); | ||
| 146 | //if (deobfName != null) { | ||
| 147 | // assertThat(deobfName, is(deobf.getName())); | ||
| 148 | //} | ||
| 149 | |||
| 150 | //String obfName = obfTranslator.translate(deobf); | ||
| 151 | //if (obfName != null) { | ||
| 152 | // assertThat(obfName, is(obf.getName())); | ||
| 153 | //} | ||
| 154 | } | ||
| 155 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/TestTypeDescriptor.java b/enigma/src/test/java/cuchaz/enigma/TestTypeDescriptor.java new file mode 100644 index 0000000..b9ebe55 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/TestTypeDescriptor.java | |||
| @@ -0,0 +1,243 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.translation.representation.TypeDescriptor; | ||
| 15 | import org.junit.Test; | ||
| 16 | |||
| 17 | import static cuchaz.enigma.TestEntryFactory.newClass; | ||
| 18 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 19 | import static org.hamcrest.Matchers.is; | ||
| 20 | import static org.hamcrest.Matchers.not; | ||
| 21 | |||
| 22 | public class TestTypeDescriptor { | ||
| 23 | |||
| 24 | @Test | ||
| 25 | public void isVoid() { | ||
| 26 | assertThat(new TypeDescriptor("V").isVoid(), is(true)); | ||
| 27 | assertThat(new TypeDescriptor("Z").isVoid(), is(false)); | ||
| 28 | assertThat(new TypeDescriptor("B").isVoid(), is(false)); | ||
| 29 | assertThat(new TypeDescriptor("C").isVoid(), is(false)); | ||
| 30 | assertThat(new TypeDescriptor("I").isVoid(), is(false)); | ||
| 31 | assertThat(new TypeDescriptor("J").isVoid(), is(false)); | ||
| 32 | assertThat(new TypeDescriptor("F").isVoid(), is(false)); | ||
| 33 | assertThat(new TypeDescriptor("D").isVoid(), is(false)); | ||
| 34 | assertThat(new TypeDescriptor("LFoo;").isVoid(), is(false)); | ||
| 35 | assertThat(new TypeDescriptor("[I").isVoid(), is(false)); | ||
| 36 | } | ||
| 37 | |||
| 38 | @Test | ||
| 39 | public void isPrimitive() { | ||
| 40 | assertThat(new TypeDescriptor("V").isPrimitive(), is(false)); | ||
| 41 | assertThat(new TypeDescriptor("Z").isPrimitive(), is(true)); | ||
| 42 | assertThat(new TypeDescriptor("B").isPrimitive(), is(true)); | ||
| 43 | assertThat(new TypeDescriptor("C").isPrimitive(), is(true)); | ||
| 44 | assertThat(new TypeDescriptor("I").isPrimitive(), is(true)); | ||
| 45 | assertThat(new TypeDescriptor("J").isPrimitive(), is(true)); | ||
| 46 | assertThat(new TypeDescriptor("F").isPrimitive(), is(true)); | ||
| 47 | assertThat(new TypeDescriptor("D").isPrimitive(), is(true)); | ||
| 48 | assertThat(new TypeDescriptor("LFoo;").isPrimitive(), is(false)); | ||
| 49 | assertThat(new TypeDescriptor("[I").isPrimitive(), is(false)); | ||
| 50 | } | ||
| 51 | |||
| 52 | @Test | ||
| 53 | public void getPrimitive() { | ||
| 54 | assertThat(new TypeDescriptor("Z").getPrimitive(), is(TypeDescriptor.Primitive.BOOLEAN)); | ||
| 55 | assertThat(new TypeDescriptor("B").getPrimitive(), is(TypeDescriptor.Primitive.BYTE)); | ||
| 56 | assertThat(new TypeDescriptor("C").getPrimitive(), is(TypeDescriptor.Primitive.CHARACTER)); | ||
| 57 | assertThat(new TypeDescriptor("I").getPrimitive(), is(TypeDescriptor.Primitive.INTEGER)); | ||
| 58 | assertThat(new TypeDescriptor("J").getPrimitive(), is(TypeDescriptor.Primitive.LONG)); | ||
| 59 | assertThat(new TypeDescriptor("F").getPrimitive(), is(TypeDescriptor.Primitive.FLOAT)); | ||
| 60 | assertThat(new TypeDescriptor("D").getPrimitive(), is(TypeDescriptor.Primitive.DOUBLE)); | ||
| 61 | } | ||
| 62 | |||
| 63 | @Test | ||
| 64 | public void isClass() { | ||
| 65 | assertThat(new TypeDescriptor("V").isType(), is(false)); | ||
| 66 | assertThat(new TypeDescriptor("Z").isType(), is(false)); | ||
| 67 | assertThat(new TypeDescriptor("B").isType(), is(false)); | ||
| 68 | assertThat(new TypeDescriptor("C").isType(), is(false)); | ||
| 69 | assertThat(new TypeDescriptor("I").isType(), is(false)); | ||
| 70 | assertThat(new TypeDescriptor("J").isType(), is(false)); | ||
| 71 | assertThat(new TypeDescriptor("F").isType(), is(false)); | ||
| 72 | assertThat(new TypeDescriptor("D").isType(), is(false)); | ||
| 73 | assertThat(new TypeDescriptor("LFoo;").isType(), is(true)); | ||
| 74 | assertThat(new TypeDescriptor("[I").isType(), is(false)); | ||
| 75 | } | ||
| 76 | |||
| 77 | @Test | ||
| 78 | public void getClassEntry() { | ||
| 79 | assertThat(new TypeDescriptor("LFoo;").getTypeEntry(), is(newClass("Foo"))); | ||
| 80 | assertThat(new TypeDescriptor("Ljava/lang/String;").getTypeEntry(), is(newClass("java/lang/String"))); | ||
| 81 | } | ||
| 82 | |||
| 83 | @Test | ||
| 84 | public void getArrayClassEntry() { | ||
| 85 | assertThat(new TypeDescriptor("[LFoo;").getTypeEntry(), is(newClass("Foo"))); | ||
| 86 | assertThat(new TypeDescriptor("[[[Ljava/lang/String;").getTypeEntry(), is(newClass("java/lang/String"))); | ||
| 87 | } | ||
| 88 | |||
| 89 | @Test | ||
| 90 | public void isArray() { | ||
| 91 | assertThat(new TypeDescriptor("V").isArray(), is(false)); | ||
| 92 | assertThat(new TypeDescriptor("Z").isArray(), is(false)); | ||
| 93 | assertThat(new TypeDescriptor("B").isArray(), is(false)); | ||
| 94 | assertThat(new TypeDescriptor("C").isArray(), is(false)); | ||
| 95 | assertThat(new TypeDescriptor("I").isArray(), is(false)); | ||
| 96 | assertThat(new TypeDescriptor("J").isArray(), is(false)); | ||
| 97 | assertThat(new TypeDescriptor("F").isArray(), is(false)); | ||
| 98 | assertThat(new TypeDescriptor("D").isArray(), is(false)); | ||
| 99 | assertThat(new TypeDescriptor("LFoo;").isArray(), is(false)); | ||
| 100 | assertThat(new TypeDescriptor("[I").isArray(), is(true)); | ||
| 101 | } | ||
| 102 | |||
| 103 | @Test | ||
| 104 | public void getArrayDimension() { | ||
| 105 | assertThat(new TypeDescriptor("[I").getArrayDimension(), is(1)); | ||
| 106 | assertThat(new TypeDescriptor("[[I").getArrayDimension(), is(2)); | ||
| 107 | assertThat(new TypeDescriptor("[[[I").getArrayDimension(), is(3)); | ||
| 108 | } | ||
| 109 | |||
| 110 | @Test | ||
| 111 | public void getArrayType() { | ||
| 112 | assertThat(new TypeDescriptor("[I").getArrayType(), is(new TypeDescriptor("I"))); | ||
| 113 | assertThat(new TypeDescriptor("[[I").getArrayType(), is(new TypeDescriptor("I"))); | ||
| 114 | assertThat(new TypeDescriptor("[[[I").getArrayType(), is(new TypeDescriptor("I"))); | ||
| 115 | assertThat(new TypeDescriptor("[Ljava/lang/String;").getArrayType(), is(new TypeDescriptor("Ljava/lang/String;"))); | ||
| 116 | } | ||
| 117 | |||
| 118 | @Test | ||
| 119 | public void hasClass() { | ||
| 120 | assertThat(new TypeDescriptor("LFoo;").containsType(), is(true)); | ||
| 121 | assertThat(new TypeDescriptor("Ljava/lang/String;").containsType(), is(true)); | ||
| 122 | assertThat(new TypeDescriptor("[LBar;").containsType(), is(true)); | ||
| 123 | assertThat(new TypeDescriptor("[[[LCat;").containsType(), is(true)); | ||
| 124 | |||
| 125 | assertThat(new TypeDescriptor("V").containsType(), is(false)); | ||
| 126 | assertThat(new TypeDescriptor("[I").containsType(), is(false)); | ||
| 127 | assertThat(new TypeDescriptor("[[[I").containsType(), is(false)); | ||
| 128 | assertThat(new TypeDescriptor("Z").containsType(), is(false)); | ||
| 129 | } | ||
| 130 | |||
| 131 | @Test | ||
| 132 | public void parseVoid() { | ||
| 133 | final String answer = "V"; | ||
| 134 | assertThat(TypeDescriptor.parseFirst("V"), is(answer)); | ||
| 135 | assertThat(TypeDescriptor.parseFirst("VVV"), is(answer)); | ||
| 136 | assertThat(TypeDescriptor.parseFirst("VIJ"), is(answer)); | ||
| 137 | assertThat(TypeDescriptor.parseFirst("V[I"), is(answer)); | ||
| 138 | assertThat(TypeDescriptor.parseFirst("VLFoo;"), is(answer)); | ||
| 139 | assertThat(TypeDescriptor.parseFirst("V[LFoo;"), is(answer)); | ||
| 140 | } | ||
| 141 | |||
| 142 | @Test | ||
| 143 | public void parsePrimitive() { | ||
| 144 | final String answer = "I"; | ||
| 145 | assertThat(TypeDescriptor.parseFirst("I"), is(answer)); | ||
| 146 | assertThat(TypeDescriptor.parseFirst("III"), is(answer)); | ||
| 147 | assertThat(TypeDescriptor.parseFirst("IJZ"), is(answer)); | ||
| 148 | assertThat(TypeDescriptor.parseFirst("I[I"), is(answer)); | ||
| 149 | assertThat(TypeDescriptor.parseFirst("ILFoo;"), is(answer)); | ||
| 150 | assertThat(TypeDescriptor.parseFirst("I[LFoo;"), is(answer)); | ||
| 151 | } | ||
| 152 | |||
| 153 | @Test | ||
| 154 | public void parseClass() { | ||
| 155 | { | ||
| 156 | final String answer = "LFoo;"; | ||
| 157 | assertThat(TypeDescriptor.parseFirst("LFoo;"), is(answer)); | ||
| 158 | assertThat(TypeDescriptor.parseFirst("LFoo;I"), is(answer)); | ||
| 159 | assertThat(TypeDescriptor.parseFirst("LFoo;JZ"), is(answer)); | ||
| 160 | assertThat(TypeDescriptor.parseFirst("LFoo;[I"), is(answer)); | ||
| 161 | assertThat(TypeDescriptor.parseFirst("LFoo;LFoo;"), is(answer)); | ||
| 162 | assertThat(TypeDescriptor.parseFirst("LFoo;[LFoo;"), is(answer)); | ||
| 163 | } | ||
| 164 | { | ||
| 165 | final String answer = "Ljava/lang/String;"; | ||
| 166 | assertThat(TypeDescriptor.parseFirst("Ljava/lang/String;"), is(answer)); | ||
| 167 | assertThat(TypeDescriptor.parseFirst("Ljava/lang/String;I"), is(answer)); | ||
| 168 | assertThat(TypeDescriptor.parseFirst("Ljava/lang/String;JZ"), is(answer)); | ||
| 169 | assertThat(TypeDescriptor.parseFirst("Ljava/lang/String;[I"), is(answer)); | ||
| 170 | assertThat(TypeDescriptor.parseFirst("Ljava/lang/String;LFoo;"), is(answer)); | ||
| 171 | assertThat(TypeDescriptor.parseFirst("Ljava/lang/String;[LFoo;"), is(answer)); | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | @Test | ||
| 176 | public void parseArray() { | ||
| 177 | { | ||
| 178 | final String answer = "[I"; | ||
| 179 | assertThat(TypeDescriptor.parseFirst("[I"), is(answer)); | ||
| 180 | assertThat(TypeDescriptor.parseFirst("[III"), is(answer)); | ||
| 181 | assertThat(TypeDescriptor.parseFirst("[IJZ"), is(answer)); | ||
| 182 | assertThat(TypeDescriptor.parseFirst("[I[I"), is(answer)); | ||
| 183 | assertThat(TypeDescriptor.parseFirst("[ILFoo;"), is(answer)); | ||
| 184 | } | ||
| 185 | { | ||
| 186 | final String answer = "[[I"; | ||
| 187 | assertThat(TypeDescriptor.parseFirst("[[I"), is(answer)); | ||
| 188 | assertThat(TypeDescriptor.parseFirst("[[III"), is(answer)); | ||
| 189 | assertThat(TypeDescriptor.parseFirst("[[IJZ"), is(answer)); | ||
| 190 | assertThat(TypeDescriptor.parseFirst("[[I[I"), is(answer)); | ||
| 191 | assertThat(TypeDescriptor.parseFirst("[[ILFoo;"), is(answer)); | ||
| 192 | } | ||
| 193 | { | ||
| 194 | final String answer = "[LFoo;"; | ||
| 195 | assertThat(TypeDescriptor.parseFirst("[LFoo;"), is(answer)); | ||
| 196 | assertThat(TypeDescriptor.parseFirst("[LFoo;II"), is(answer)); | ||
| 197 | assertThat(TypeDescriptor.parseFirst("[LFoo;JZ"), is(answer)); | ||
| 198 | assertThat(TypeDescriptor.parseFirst("[LFoo;[I"), is(answer)); | ||
| 199 | assertThat(TypeDescriptor.parseFirst("[LFoo;LFoo;"), is(answer)); | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | @Test | ||
| 204 | public void equals() { | ||
| 205 | assertThat(new TypeDescriptor("V"), is(new TypeDescriptor("V"))); | ||
| 206 | assertThat(new TypeDescriptor("Z"), is(new TypeDescriptor("Z"))); | ||
| 207 | assertThat(new TypeDescriptor("B"), is(new TypeDescriptor("B"))); | ||
| 208 | assertThat(new TypeDescriptor("C"), is(new TypeDescriptor("C"))); | ||
| 209 | assertThat(new TypeDescriptor("I"), is(new TypeDescriptor("I"))); | ||
| 210 | assertThat(new TypeDescriptor("J"), is(new TypeDescriptor("J"))); | ||
| 211 | assertThat(new TypeDescriptor("F"), is(new TypeDescriptor("F"))); | ||
| 212 | assertThat(new TypeDescriptor("D"), is(new TypeDescriptor("D"))); | ||
| 213 | assertThat(new TypeDescriptor("LFoo;"), is(new TypeDescriptor("LFoo;"))); | ||
| 214 | assertThat(new TypeDescriptor("[I"), is(new TypeDescriptor("[I"))); | ||
| 215 | assertThat(new TypeDescriptor("[[[I"), is(new TypeDescriptor("[[[I"))); | ||
| 216 | assertThat(new TypeDescriptor("[LFoo;"), is(new TypeDescriptor("[LFoo;"))); | ||
| 217 | |||
| 218 | assertThat(new TypeDescriptor("V"), is(not(new TypeDescriptor("I")))); | ||
| 219 | assertThat(new TypeDescriptor("I"), is(not(new TypeDescriptor("J")))); | ||
| 220 | assertThat(new TypeDescriptor("I"), is(not(new TypeDescriptor("LBar;")))); | ||
| 221 | assertThat(new TypeDescriptor("I"), is(not(new TypeDescriptor("[I")))); | ||
| 222 | assertThat(new TypeDescriptor("LFoo;"), is(not(new TypeDescriptor("LBar;")))); | ||
| 223 | assertThat(new TypeDescriptor("[I"), is(not(new TypeDescriptor("[Z")))); | ||
| 224 | assertThat(new TypeDescriptor("[[[I"), is(not(new TypeDescriptor("[I")))); | ||
| 225 | assertThat(new TypeDescriptor("[LFoo;"), is(not(new TypeDescriptor("[LBar;")))); | ||
| 226 | } | ||
| 227 | |||
| 228 | @Test | ||
| 229 | public void testToString() { | ||
| 230 | assertThat(new TypeDescriptor("V").toString(), is("V")); | ||
| 231 | assertThat(new TypeDescriptor("Z").toString(), is("Z")); | ||
| 232 | assertThat(new TypeDescriptor("B").toString(), is("B")); | ||
| 233 | assertThat(new TypeDescriptor("C").toString(), is("C")); | ||
| 234 | assertThat(new TypeDescriptor("I").toString(), is("I")); | ||
| 235 | assertThat(new TypeDescriptor("J").toString(), is("J")); | ||
| 236 | assertThat(new TypeDescriptor("F").toString(), is("F")); | ||
| 237 | assertThat(new TypeDescriptor("D").toString(), is("D")); | ||
| 238 | assertThat(new TypeDescriptor("LFoo;").toString(), is("LFoo;")); | ||
| 239 | assertThat(new TypeDescriptor("[I").toString(), is("[I")); | ||
| 240 | assertThat(new TypeDescriptor("[[[I").toString(), is("[[[I")); | ||
| 241 | assertThat(new TypeDescriptor("[LFoo;").toString(), is("[LFoo;")); | ||
| 242 | } | ||
| 243 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/TokenChecker.java b/enigma/src/test/java/cuchaz/enigma/TokenChecker.java new file mode 100644 index 0000000..96fc6da --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/TokenChecker.java | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import com.google.common.collect.Lists; | ||
| 15 | import cuchaz.enigma.analysis.ClassCache; | ||
| 16 | import cuchaz.enigma.analysis.EntryReference; | ||
| 17 | import cuchaz.enigma.source.SourceIndex; | ||
| 18 | import cuchaz.enigma.source.*; | ||
| 19 | import cuchaz.enigma.source.Token; | ||
| 20 | import cuchaz.enigma.translation.representation.entry.Entry; | ||
| 21 | |||
| 22 | import java.io.IOException; | ||
| 23 | import java.nio.file.Path; | ||
| 24 | import java.util.Collection; | ||
| 25 | import java.util.List; | ||
| 26 | |||
| 27 | public class TokenChecker { | ||
| 28 | private final Decompiler decompiler; | ||
| 29 | |||
| 30 | protected TokenChecker(Path path) throws IOException { | ||
| 31 | ClassCache classCache = ClassCache.of(path); | ||
| 32 | decompiler = Decompilers.PROCYON.create(classCache, new SourceSettings(false, false)); | ||
| 33 | } | ||
| 34 | |||
| 35 | protected String getDeclarationToken(Entry<?> entry) { | ||
| 36 | // decompile the class | ||
| 37 | Source source = decompiler.getSource(entry.getContainingClass().getFullName()); | ||
| 38 | // DEBUG | ||
| 39 | // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); | ||
| 40 | String string = source.asString(); | ||
| 41 | SourceIndex index = source.index(); | ||
| 42 | |||
| 43 | // get the token value | ||
| 44 | Token token = index.getDeclarationToken(entry); | ||
| 45 | if (token == null) { | ||
| 46 | return null; | ||
| 47 | } | ||
| 48 | return string.substring(token.start, token.end); | ||
| 49 | } | ||
| 50 | |||
| 51 | @SuppressWarnings("unchecked") | ||
| 52 | protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) { | ||
| 53 | // decompile the class | ||
| 54 | Source source = decompiler.getSource(reference.context.getContainingClass().getFullName()); | ||
| 55 | String string = source.asString(); | ||
| 56 | SourceIndex index = source.index(); | ||
| 57 | |||
| 58 | // get the token values | ||
| 59 | List<String> values = Lists.newArrayList(); | ||
| 60 | for (Token token : index.getReferenceTokens((EntryReference<Entry<?>, Entry<?>>) reference)) { | ||
| 61 | values.add(string.substring(token.start, token.end)); | ||
| 62 | } | ||
| 63 | return values; | ||
| 64 | } | ||
| 65 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/Keep.java b/enigma/src/test/java/cuchaz/enigma/inputs/Keep.java new file mode 100644 index 0000000..4dbe8e2 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/Keep.java | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs; | ||
| 13 | |||
| 14 | public class Keep { | ||
| 15 | public static void main(String[] args) { | ||
| 16 | System.out.println("Keep me!"); | ||
| 17 | } | ||
| 18 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/constructors/BaseClass.java b/enigma/src/test/java/cuchaz/enigma/inputs/constructors/BaseClass.java new file mode 100644 index 0000000..f07e1f8 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/constructors/BaseClass.java | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.constructors; | ||
| 13 | |||
| 14 | // a | ||
| 15 | public class BaseClass { | ||
| 16 | |||
| 17 | // <init>()V | ||
| 18 | public BaseClass() { | ||
| 19 | System.out.println("Default constructor"); | ||
| 20 | } | ||
| 21 | |||
| 22 | // <init>(I)V | ||
| 23 | public BaseClass(int i) { | ||
| 24 | System.out.println("Int constructor " + i); | ||
| 25 | } | ||
| 26 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/constructors/Caller.java b/enigma/src/test/java/cuchaz/enigma/inputs/constructors/Caller.java new file mode 100644 index 0000000..71439fd --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/constructors/Caller.java | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.constructors; | ||
| 13 | |||
| 14 | // b | ||
| 15 | public class Caller { | ||
| 16 | |||
| 17 | // a()V | ||
| 18 | public void callBaseDefault() { | ||
| 19 | // a.<init>()V | ||
| 20 | System.out.println(new BaseClass()); | ||
| 21 | } | ||
| 22 | |||
| 23 | // b()V | ||
| 24 | public void callBaseInt() { | ||
| 25 | // a.<init>(I)V | ||
| 26 | System.out.println(new BaseClass(5)); | ||
| 27 | } | ||
| 28 | |||
| 29 | // c()V | ||
| 30 | public void callSubDefault() { | ||
| 31 | // d.<init>()V | ||
| 32 | System.out.println(new SubClass()); | ||
| 33 | } | ||
| 34 | |||
| 35 | // d()V | ||
| 36 | public void callSubInt() { | ||
| 37 | // d.<init>(I)V | ||
| 38 | System.out.println(new SubClass(6)); | ||
| 39 | } | ||
| 40 | |||
| 41 | // e()V | ||
| 42 | public void callSubIntInt() { | ||
| 43 | // d.<init>(II)V | ||
| 44 | System.out.println(new SubClass(4, 2)); | ||
| 45 | } | ||
| 46 | |||
| 47 | // f()V | ||
| 48 | public void callSubSubInt() { | ||
| 49 | // e.<init>(I)V | ||
| 50 | System.out.println(new SubSubClass(3)); | ||
| 51 | } | ||
| 52 | |||
| 53 | // g()V | ||
| 54 | public void callDefaultConstructable() { | ||
| 55 | // c.<init>()V | ||
| 56 | System.out.println(new DefaultConstructable()); | ||
| 57 | } | ||
| 58 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/constructors/DefaultConstructable.java b/enigma/src/test/java/cuchaz/enigma/inputs/constructors/DefaultConstructable.java new file mode 100644 index 0000000..c3d4170 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/constructors/DefaultConstructable.java | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.constructors; | ||
| 13 | |||
| 14 | public class DefaultConstructable { | ||
| 15 | // only default constructor | ||
| 16 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/constructors/SubClass.java b/enigma/src/test/java/cuchaz/enigma/inputs/constructors/SubClass.java new file mode 100644 index 0000000..bc56b3b --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/constructors/SubClass.java | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.constructors; | ||
| 13 | |||
| 14 | // d extends a | ||
| 15 | public class SubClass extends BaseClass { | ||
| 16 | |||
| 17 | // <init>()V | ||
| 18 | public SubClass() { | ||
| 19 | // a.<init>()V | ||
| 20 | } | ||
| 21 | |||
| 22 | // <init>(I)V | ||
| 23 | public SubClass(int num) { | ||
| 24 | // <init>()V | ||
| 25 | this(); | ||
| 26 | System.out.println("SubClass " + num); | ||
| 27 | } | ||
| 28 | |||
| 29 | // <init>(II)V | ||
| 30 | public SubClass(int a, int b) { | ||
| 31 | // <init>(I)V | ||
| 32 | this(a + b); | ||
| 33 | } | ||
| 34 | |||
| 35 | // <init>(III)V | ||
| 36 | public SubClass(int a, int b, int c) { | ||
| 37 | // a.<init>()V | ||
| 38 | } | ||
| 39 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/constructors/SubSubClass.java b/enigma/src/test/java/cuchaz/enigma/inputs/constructors/SubSubClass.java new file mode 100644 index 0000000..87b69d3 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/constructors/SubSubClass.java | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.constructors; | ||
| 13 | |||
| 14 | // e extends d | ||
| 15 | public class SubSubClass extends SubClass { | ||
| 16 | |||
| 17 | // <init>(I)V | ||
| 18 | public SubSubClass(int i) { | ||
| 19 | // c.<init>(I)V | ||
| 20 | super(i); | ||
| 21 | } | ||
| 22 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java b/enigma/src/test/java/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java new file mode 100644 index 0000000..b9c4929 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.inheritanceTree; | ||
| 13 | |||
| 14 | // a | ||
| 15 | public abstract class BaseClass { | ||
| 16 | |||
| 17 | // a | ||
| 18 | private String name; | ||
| 19 | |||
| 20 | // <init>(Ljava/lang/String;)V | ||
| 21 | protected BaseClass(String name) { | ||
| 22 | this.name = name; | ||
| 23 | } | ||
| 24 | |||
| 25 | // a()Ljava/lang/String; | ||
| 26 | public String getName() { | ||
| 27 | return name; | ||
| 28 | } | ||
| 29 | |||
| 30 | // a()V | ||
| 31 | public abstract void doBaseThings(); | ||
| 32 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java b/enigma/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java new file mode 100644 index 0000000..50e963c --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.inheritanceTree; | ||
| 13 | |||
| 14 | // b extends a | ||
| 15 | public abstract class SubclassA extends BaseClass { | ||
| 16 | |||
| 17 | // <init>(Ljava/lang/String;)V | ||
| 18 | protected SubclassA(String name) { | ||
| 19 | // call to a.<init>(Ljava/lang/String)V | ||
| 20 | super(name); | ||
| 21 | } | ||
| 22 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java b/enigma/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java new file mode 100644 index 0000000..d0dd664 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.inheritanceTree; | ||
| 13 | |||
| 14 | // c extends a | ||
| 15 | public class SubclassB extends BaseClass { | ||
| 16 | |||
| 17 | // a | ||
| 18 | private int numThings; | ||
| 19 | |||
| 20 | // <init>()V | ||
| 21 | protected SubclassB() { | ||
| 22 | // a.<init>(Ljava/lang/String;)V | ||
| 23 | super("B"); | ||
| 24 | |||
| 25 | // access to a | ||
| 26 | numThings = 4; | ||
| 27 | } | ||
| 28 | |||
| 29 | @Override | ||
| 30 | // a()V | ||
| 31 | public void doBaseThings() { | ||
| 32 | // call to a.a()Ljava/lang/String; | ||
| 33 | System.out.println("Base things by B! " + getName()); | ||
| 34 | } | ||
| 35 | |||
| 36 | // b()V | ||
| 37 | public void doBThings() { | ||
| 38 | // access to a | ||
| 39 | System.out.println("" + numThings + " B things!"); | ||
| 40 | } | ||
| 41 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java b/enigma/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java new file mode 100644 index 0000000..c584570 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.inheritanceTree; | ||
| 13 | |||
| 14 | // d extends b | ||
| 15 | public class SubsubclassAA extends SubclassA { | ||
| 16 | |||
| 17 | protected SubsubclassAA() { | ||
| 18 | // call to b.<init>(Ljava/lang/String;)V | ||
| 19 | super("AA"); | ||
| 20 | } | ||
| 21 | |||
| 22 | @Override | ||
| 23 | // a()Ljava/lang/String; | ||
| 24 | public String getName() { | ||
| 25 | // call to b.a()Ljava/lang/String; | ||
| 26 | return "subsub" + super.getName(); | ||
| 27 | } | ||
| 28 | |||
| 29 | @Override | ||
| 30 | // a()V | ||
| 31 | public void doBaseThings() { | ||
| 32 | // call to d.a()Ljava/lang/String; | ||
| 33 | System.out.println("Base things by " + getName()); | ||
| 34 | } | ||
| 35 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java b/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java new file mode 100644 index 0000000..f652d87 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.innerClasses; | ||
| 13 | |||
| 14 | public class A_Anonymous { | ||
| 15 | |||
| 16 | public void foo() { | ||
| 17 | Runnable runnable = new Runnable() { | ||
| 18 | @Override | ||
| 19 | public void run() { | ||
| 20 | // don't care | ||
| 21 | } | ||
| 22 | }; | ||
| 23 | runnable.run(); | ||
| 24 | } | ||
| 25 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java b/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java new file mode 100644 index 0000000..d1b7601 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.innerClasses; | ||
| 13 | |||
| 14 | public class B_AnonymousWithScopeArgs { | ||
| 15 | |||
| 16 | public static void foo(final D_Simple arg) { | ||
| 17 | System.out.println(new Object() { | ||
| 18 | @Override | ||
| 19 | public String toString() { | ||
| 20 | return arg.toString(); | ||
| 21 | } | ||
| 22 | }); | ||
| 23 | } | ||
| 24 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java b/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java new file mode 100644 index 0000000..94061fa --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.innerClasses; | ||
| 13 | |||
| 14 | @SuppressWarnings("unused") | ||
| 15 | public class C_ConstructorArgs { | ||
| 16 | |||
| 17 | Inner i; | ||
| 18 | |||
| 19 | public void foo() { | ||
| 20 | i = new Inner(5); | ||
| 21 | } | ||
| 22 | |||
| 23 | class Inner { | ||
| 24 | |||
| 25 | private int a; | ||
| 26 | |||
| 27 | public Inner(int a) { | ||
| 28 | this.a = a; | ||
| 29 | } | ||
| 30 | } | ||
| 31 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/D_Simple.java b/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/D_Simple.java new file mode 100644 index 0000000..71b3a6d --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/D_Simple.java | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.innerClasses; | ||
| 13 | |||
| 14 | public class D_Simple { | ||
| 15 | |||
| 16 | class Inner { | ||
| 17 | // nothing to do | ||
| 18 | } | ||
| 19 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java b/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java new file mode 100644 index 0000000..976ec42 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.innerClasses; | ||
| 13 | |||
| 14 | public class E_AnonymousWithOuterAccess { | ||
| 15 | |||
| 16 | // reproduction of error case documented at: | ||
| 17 | // https://bitbucket.org/cuchaz/enigma/issue/61/stackoverflowerror-when-deobfuscating | ||
| 18 | |||
| 19 | public Object makeInner() { | ||
| 20 | outerMethod(); | ||
| 21 | return new Object() { | ||
| 22 | @Override | ||
| 23 | public String toString() { | ||
| 24 | return outerMethod(); | ||
| 25 | } | ||
| 26 | }; | ||
| 27 | } | ||
| 28 | |||
| 29 | private String outerMethod() { | ||
| 30 | return "foo"; | ||
| 31 | } | ||
| 32 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java b/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java new file mode 100644 index 0000000..b1de3c9 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.innerClasses; | ||
| 13 | |||
| 14 | public class F_ClassTree { | ||
| 15 | |||
| 16 | public class Level1 { | ||
| 17 | |||
| 18 | public int f1; | ||
| 19 | |||
| 20 | public class Level2 { | ||
| 21 | |||
| 22 | public int f2; | ||
| 23 | |||
| 24 | public class Level3 { | ||
| 25 | |||
| 26 | public int f3; | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
| 30 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/loneClass/LoneClass.java b/enigma/src/test/java/cuchaz/enigma/inputs/loneClass/LoneClass.java new file mode 100644 index 0000000..ddc4e31 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/loneClass/LoneClass.java | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.loneClass; | ||
| 13 | |||
| 14 | public class LoneClass { | ||
| 15 | |||
| 16 | private String name; | ||
| 17 | |||
| 18 | public LoneClass(String name) { | ||
| 19 | this.name = name; | ||
| 20 | } | ||
| 21 | |||
| 22 | public String getName() { | ||
| 23 | return name; | ||
| 24 | } | ||
| 25 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/packageAccess/Base.java b/enigma/src/test/java/cuchaz/enigma/inputs/packageAccess/Base.java new file mode 100644 index 0000000..6f5fe30 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/packageAccess/Base.java | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | package cuchaz.enigma.inputs.packageAccess; | ||
| 2 | |||
| 3 | public class Base { | ||
| 4 | protected int make() { | ||
| 5 | return 42; | ||
| 6 | } | ||
| 7 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/packageAccess/SamePackageChild.java b/enigma/src/test/java/cuchaz/enigma/inputs/packageAccess/SamePackageChild.java new file mode 100644 index 0000000..cf0f657 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/packageAccess/SamePackageChild.java | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | package cuchaz.enigma.inputs.packageAccess; | ||
| 2 | |||
| 3 | public class SamePackageChild extends Base { | ||
| 4 | |||
| 5 | class Inner { | ||
| 6 | final int value; | ||
| 7 | |||
| 8 | Inner() { | ||
| 9 | value = SamePackageChild.this.make(); // no synthetic method | ||
| 10 | } | ||
| 11 | } | ||
| 12 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/packageAccess/sub/OtherPackageChild.java b/enigma/src/test/java/cuchaz/enigma/inputs/packageAccess/sub/OtherPackageChild.java new file mode 100644 index 0000000..19fb19c --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/packageAccess/sub/OtherPackageChild.java | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | package cuchaz.enigma.inputs.packageAccess.sub; | ||
| 2 | |||
| 3 | import cuchaz.enigma.inputs.packageAccess.Base; | ||
| 4 | |||
| 5 | public class OtherPackageChild extends Base { | ||
| 6 | |||
| 7 | class Inner { | ||
| 8 | final int value; | ||
| 9 | |||
| 10 | Inner() { | ||
| 11 | value = OtherPackageChild.this.make(); // synthetic method call | ||
| 12 | } | ||
| 13 | } | ||
| 14 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/translation/A_Basic.java b/enigma/src/test/java/cuchaz/enigma/inputs/translation/A_Basic.java new file mode 100644 index 0000000..26f3718 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/translation/A_Basic.java | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.translation; | ||
| 13 | |||
| 14 | public class A_Basic { | ||
| 15 | |||
| 16 | public int one; | ||
| 17 | public float two; | ||
| 18 | public String three; | ||
| 19 | |||
| 20 | public void m1() { | ||
| 21 | } | ||
| 22 | |||
| 23 | public int m2() { | ||
| 24 | return 42; | ||
| 25 | } | ||
| 26 | |||
| 27 | public void m3(int a1) { | ||
| 28 | } | ||
| 29 | |||
| 30 | public int m4(int a1) { | ||
| 31 | return 5; // chosen by fair die roll, guaranteed to be random | ||
| 32 | } | ||
| 33 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/translation/B_BaseClass.java b/enigma/src/test/java/cuchaz/enigma/inputs/translation/B_BaseClass.java new file mode 100644 index 0000000..fd7f6e7 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/translation/B_BaseClass.java | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.translation; | ||
| 13 | |||
| 14 | public class B_BaseClass { | ||
| 15 | |||
| 16 | public int f1; | ||
| 17 | public char f2; | ||
| 18 | |||
| 19 | public int m1() { | ||
| 20 | return 5; | ||
| 21 | } | ||
| 22 | |||
| 23 | public int m2() { | ||
| 24 | return 42; | ||
| 25 | } | ||
| 26 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/translation/C_SubClass.java b/enigma/src/test/java/cuchaz/enigma/inputs/translation/C_SubClass.java new file mode 100644 index 0000000..9d74e44 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/translation/C_SubClass.java | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.translation; | ||
| 13 | |||
| 14 | public class C_SubClass extends B_BaseClass { | ||
| 15 | |||
| 16 | public char f2; // shadows B_BaseClass.f2 | ||
| 17 | public int f3; | ||
| 18 | public int f4; | ||
| 19 | |||
| 20 | @Override | ||
| 21 | public int m1() { | ||
| 22 | return 32; | ||
| 23 | } | ||
| 24 | |||
| 25 | public int m3() { | ||
| 26 | return 7; | ||
| 27 | } | ||
| 28 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java b/enigma/src/test/java/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java new file mode 100644 index 0000000..99c83bb --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.translation; | ||
| 13 | |||
| 14 | import java.util.ArrayList; | ||
| 15 | import java.util.List; | ||
| 16 | |||
| 17 | public class D_AnonymousTesting { | ||
| 18 | |||
| 19 | public List<Object> getObjs() { | ||
| 20 | List<Object> objs = new ArrayList<Object>(); | ||
| 21 | objs.add(new Object() { | ||
| 22 | @Override | ||
| 23 | public String toString() { | ||
| 24 | return "Object!"; | ||
| 25 | } | ||
| 26 | }); | ||
| 27 | return objs; | ||
| 28 | } | ||
| 29 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/translation/E_Bridges.java b/enigma/src/test/java/cuchaz/enigma/inputs/translation/E_Bridges.java new file mode 100644 index 0000000..0b8cf2a --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/translation/E_Bridges.java | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.translation; | ||
| 13 | |||
| 14 | import java.util.Iterator; | ||
| 15 | |||
| 16 | public class E_Bridges implements Iterator<Object> { | ||
| 17 | |||
| 18 | @Override | ||
| 19 | public boolean hasNext() { | ||
| 20 | return false; | ||
| 21 | } | ||
| 22 | |||
| 23 | @Override | ||
| 24 | public String next() { | ||
| 25 | // the compiler will generate a bridge for this method | ||
| 26 | return "foo"; | ||
| 27 | } | ||
| 28 | |||
| 29 | @Override | ||
| 30 | public void remove() { | ||
| 31 | } | ||
| 32 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/translation/F_ObjectMethods.java b/enigma/src/test/java/cuchaz/enigma/inputs/translation/F_ObjectMethods.java new file mode 100644 index 0000000..8a92792 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/translation/F_ObjectMethods.java | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.translation; | ||
| 13 | |||
| 14 | @SuppressWarnings("FinalizeCalledExplicitly") | ||
| 15 | public class F_ObjectMethods { | ||
| 16 | |||
| 17 | public void callEmAll() | ||
| 18 | throws Throwable { | ||
| 19 | clone(); | ||
| 20 | equals(this); | ||
| 21 | finalize(); | ||
| 22 | getClass(); | ||
| 23 | hashCode(); | ||
| 24 | notify(); | ||
| 25 | notifyAll(); | ||
| 26 | toString(); | ||
| 27 | wait(); | ||
| 28 | wait(0); | ||
| 29 | wait(0, 0); | ||
| 30 | } | ||
| 31 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/translation/G_OuterClass.java b/enigma/src/test/java/cuchaz/enigma/inputs/translation/G_OuterClass.java new file mode 100644 index 0000000..a1e6a85 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/translation/G_OuterClass.java | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.translation; | ||
| 13 | |||
| 14 | public class G_OuterClass { | ||
| 15 | |||
| 16 | public class A_InnerClass { | ||
| 17 | |||
| 18 | public int f1; | ||
| 19 | public String f2; | ||
| 20 | |||
| 21 | public void m1() {} | ||
| 22 | |||
| 23 | public class A_InnerInnerClass { | ||
| 24 | |||
| 25 | public int f3; | ||
| 26 | |||
| 27 | public void m2() {} | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | public class B_NamelessClass { | ||
| 32 | public class A_NamedInnerClass { | ||
| 33 | public int f4; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/translation/H_NamelessClass.java b/enigma/src/test/java/cuchaz/enigma/inputs/translation/H_NamelessClass.java new file mode 100644 index 0000000..013c55a --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/translation/H_NamelessClass.java | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.translation; | ||
| 13 | |||
| 14 | public class H_NamelessClass { | ||
| 15 | |||
| 16 | public class A_InnerClass { | ||
| 17 | |||
| 18 | public int f1; | ||
| 19 | public String f2; | ||
| 20 | |||
| 21 | public void m1() {} | ||
| 22 | |||
| 23 | public class A_InnerInnerClass { | ||
| 24 | |||
| 25 | public int f3; | ||
| 26 | |||
| 27 | public void m2() {} | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | public class B_NamelessClass { | ||
| 32 | public class A_NamedInnerClass { | ||
| 33 | public int f4; | ||
| 34 | |||
| 35 | public class A_AnotherInnerClass {} | ||
| 36 | |||
| 37 | public class B_YetAnotherInnerClass {} | ||
| 38 | } | ||
| 39 | } | ||
| 40 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/inputs/translation/I_Generics.java b/enigma/src/test/java/cuchaz/enigma/inputs/translation/I_Generics.java new file mode 100644 index 0000000..fd2ebdd --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/inputs/translation/I_Generics.java | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.inputs.translation; | ||
| 13 | |||
| 14 | import java.util.List; | ||
| 15 | import java.util.Map; | ||
| 16 | |||
| 17 | public class I_Generics { | ||
| 18 | |||
| 19 | public List<Integer> f1; | ||
| 20 | public List<A_Type> f2; | ||
| 21 | public Map<A_Type, A_Type> f3; | ||
| 22 | public B_Generic<Integer> f5; | ||
| 23 | public B_Generic<A_Type> f6; | ||
| 24 | |||
| 25 | public class A_Type { | ||
| 26 | } | ||
| 27 | |||
| 28 | public class B_Generic<T> { | ||
| 29 | public T f4; | ||
| 30 | |||
| 31 | public T m1() { | ||
| 32 | return null; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/translation/mapping/TestComments.java b/enigma/src/test/java/cuchaz/enigma/translation/mapping/TestComments.java new file mode 100644 index 0000000..e831943 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/translation/mapping/TestComments.java | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | package cuchaz.enigma.translation.mapping; | ||
| 2 | |||
| 3 | import java.io.IOException; | ||
| 4 | import java.net.URISyntaxException; | ||
| 5 | import java.nio.file.Path; | ||
| 6 | import java.nio.file.Paths; | ||
| 7 | |||
| 8 | import cuchaz.enigma.ProgressListener; | ||
| 9 | import cuchaz.enigma.translation.mapping.serde.MappingFileNameFormat; | ||
| 10 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | ||
| 11 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | ||
| 12 | import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsReader; | ||
| 13 | import cuchaz.enigma.translation.mapping.serde.tinyv2.TinyV2Writer; | ||
| 14 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | ||
| 15 | import org.junit.Test; | ||
| 16 | |||
| 17 | public class TestComments { | ||
| 18 | private static Path DIRECTORY; | ||
| 19 | |||
| 20 | static { | ||
| 21 | try { | ||
| 22 | DIRECTORY = Paths.get(TestTinyV2InnerClasses.class.getResource("/comments/").toURI()); | ||
| 23 | } catch (URISyntaxException e) { | ||
| 24 | throw new RuntimeException(e); | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | @Test | ||
| 29 | public void testParseAndWrite() throws IOException, MappingParseException { | ||
| 30 | ProgressListener progressListener = ProgressListener.none(); | ||
| 31 | MappingSaveParameters params = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); | ||
| 32 | EntryTree<EntryMapping> mappings = EnigmaMappingsReader.DIRECTORY.read( | ||
| 33 | DIRECTORY, progressListener, params); | ||
| 34 | |||
| 35 | new TinyV2Writer("intermediary", "named") | ||
| 36 | .write(mappings, DIRECTORY.resolve("convertedtiny.tiny"), progressListener, params); | ||
| 37 | } | ||
| 38 | |||
| 39 | } \ No newline at end of file | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/translation/mapping/TestTinyV2InnerClasses.java b/enigma/src/test/java/cuchaz/enigma/translation/mapping/TestTinyV2InnerClasses.java new file mode 100644 index 0000000..65941e5 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/translation/mapping/TestTinyV2InnerClasses.java | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma.translation.mapping; | ||
| 13 | |||
| 14 | import cuchaz.enigma.Enigma; | ||
| 15 | import cuchaz.enigma.EnigmaProject; | ||
| 16 | import cuchaz.enigma.ProgressListener; | ||
| 17 | import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsReader; | ||
| 18 | |||
| 19 | import java.nio.file.Path; | ||
| 20 | import java.nio.file.Paths; | ||
| 21 | |||
| 22 | public final class TestTinyV2InnerClasses { | ||
| 23 | private Path jar; | ||
| 24 | private Path mappings; | ||
| 25 | |||
| 26 | public TestTinyV2InnerClasses() throws Exception { | ||
| 27 | jar = Paths.get("build/test-obf/innerClasses.jar"); | ||
| 28 | mappings = Paths.get(TestTinyV2InnerClasses.class.getResource("/tinyV2InnerClasses/").toURI()); | ||
| 29 | } | ||
| 30 | |||
| 31 | // @Test | ||
| 32 | public void testMappings() throws Exception { | ||
| 33 | EnigmaProject project = Enigma.create().openJar(jar, ProgressListener.none()); | ||
| 34 | project.setMappings(EnigmaMappingsReader.DIRECTORY.read(mappings, ProgressListener.none(), project.getEnigma().getProfile().getMappingSaveParameters())); | ||
| 35 | |||
| 36 | } | ||
| 37 | } | ||
diff --git a/enigma/src/test/java/cuchaz/enigma/translation/mapping/TestV2Main.java b/enigma/src/test/java/cuchaz/enigma/translation/mapping/TestV2Main.java new file mode 100644 index 0000000..6e4d7b9 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/translation/mapping/TestV2Main.java | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | package cuchaz.enigma.translation.mapping; | ||
| 2 | |||
| 3 | import cuchaz.enigma.ProgressListener; | ||
| 4 | import cuchaz.enigma.translation.mapping.serde.MappingFileNameFormat; | ||
| 5 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | ||
| 6 | import cuchaz.enigma.translation.mapping.serde.enigma.EnigmaMappingsReader; | ||
| 7 | import cuchaz.enigma.translation.mapping.serde.tinyv2.TinyV2Writer; | ||
| 8 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | ||
| 9 | |||
| 10 | import java.nio.file.Path; | ||
| 11 | import java.nio.file.Paths; | ||
| 12 | |||
| 13 | public final class TestV2Main { | ||
| 14 | public static void main(String... args) throws Exception { | ||
| 15 | Path path = Paths.get(TestV2Main.class.getResource("/tinyV2InnerClasses/").toURI()); | ||
| 16 | |||
| 17 | MappingSaveParameters parameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); | ||
| 18 | |||
| 19 | EntryTree<EntryMapping> tree = EnigmaMappingsReader.DIRECTORY.read(path, ProgressListener.none(), parameters); | ||
| 20 | |||
| 21 | new TinyV2Writer("obf", "deobf").write(tree, Paths.get("currentYarn.tiny"), ProgressListener.none(), parameters); | ||
| 22 | } | ||
| 23 | } | ||
diff --git a/enigma/src/test/resources/comments/test.mapping b/enigma/src/test/resources/comments/test.mapping new file mode 100644 index 0000000..d134558 --- /dev/null +++ b/enigma/src/test/resources/comments/test.mapping | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | CLASS net/minecraft/class_1158 net/minecraft/util/math/Quaternion | ||
| 2 | COMMENT it circel | ||
| 3 | COMMENT next line | ||
| 4 | FIELD field_21493 IDENTITY Lnet/minecraft/class_1158; | ||
| 5 | COMMENT moar comment thing | ||
| 6 | COMMENT near field | ||
| 7 | METHOD foo bar (FFFF)V | ||
| 8 | COMMENT method comment | ||
| 9 | COMMENT second line | ||
| 10 | COMMENT third line | ||
| 11 | ARG 1 b | ||
| 12 | COMMENT arg comment | ||
| 13 | CLASS old new | ||
| 14 | COMMENT inner comment | ||
| 15 | FIELD field_19263 iterator Lnet/minecraft/class_3980; | ||
| 16 | METHOD tryAdvance (Ljava/util/function/Consumer;)Z | ||
| 17 | ARG 1 consumer | ||
| 18 | COMMENT very inner comment \ No newline at end of file | ||
diff --git a/enigma/src/test/resources/proguard-build.conf b/enigma/src/test/resources/proguard-build.conf new file mode 100644 index 0000000..691d8a2 --- /dev/null +++ b/enigma/src/test/resources/proguard-build.conf | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | -dontoptimize | ||
| 2 | -dontobfuscate | ||
| 3 | -dontwarn | ||
| 4 | -keep class cuchaz.enigma.Main { static void main(java.lang.String[]); } | ||
| 5 | -keep class cuchaz.enigma.command.Main { static void main(java.lang.String[]); } | ||
| 6 | -keep class de.sciss.syntaxpane.** { *; } | ||
diff --git a/enigma/src/test/resources/proguard-test.conf b/enigma/src/test/resources/proguard-test.conf new file mode 100644 index 0000000..9411d26 --- /dev/null +++ b/enigma/src/test/resources/proguard-test.conf | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | -overloadaggressively | ||
| 2 | -repackageclasses | ||
| 3 | -allowaccessmodification | ||
| 4 | -dontoptimize | ||
| 5 | -dontshrink | ||
| 6 | -keepparameternames | ||
| 7 | -keepattributes | ||
| 8 | -keep class cuchaz.enigma.inputs.Keep | ||
diff --git a/enigma/src/test/resources/tinyV2InnerClasses/c.mapping b/enigma/src/test/resources/tinyV2InnerClasses/c.mapping new file mode 100644 index 0000000..f9b0442 --- /dev/null +++ b/enigma/src/test/resources/tinyV2InnerClasses/c.mapping | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | CLASS c | ||
| 2 | CLASS a Kid | ||
diff --git a/enigma/src/test/resources/tinyV2InnerClasses/cuchaz/enigma/Dad.mapping b/enigma/src/test/resources/tinyV2InnerClasses/cuchaz/enigma/Dad.mapping new file mode 100644 index 0000000..8d43ba9 --- /dev/null +++ b/enigma/src/test/resources/tinyV2InnerClasses/cuchaz/enigma/Dad.mapping | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | CLASS f cuchaz/enigma/Dad | ||
| 2 | CLASS a One | ||
| 3 | CLASS a Two | ||
| 4 | CLASS a | ||
| 5 | FIELD a value I | ||
diff --git a/enigma/src/test/resources/translation.mappings b/enigma/src/test/resources/translation.mappings new file mode 100644 index 0000000..c08765c --- /dev/null +++ b/enigma/src/test/resources/translation.mappings | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | CLASS a deobf/A_Basic | ||
| 2 | FIELD a f1 I | ||
| 3 | FIELD a f2 F | ||
| 4 | FIELD a f3 Ljava/lang/String; | ||
| 5 | METHOD a m1 ()V | ||
| 6 | METHOD a m2 ()I | ||
| 7 | METHOD a m3 (I)V | ||
| 8 | METHOD a m4 (I)I | ||
| 9 | CLASS b deobf/B_BaseClass | ||
| 10 | FIELD a f1 I | ||
| 11 | FIELD a f2 C | ||
| 12 | METHOD a m1 ()I | ||
| 13 | METHOD b m2 ()I | ||
| 14 | CLASS c deobf/C_SubClass | ||
| 15 | FIELD b f2 C | ||
| 16 | FIELD b f3 I | ||
| 17 | FIELD c f4 I | ||
| 18 | METHOD a m1 ()I | ||
| 19 | METHOD c m3 ()I | ||
| 20 | CLASS g deobf/G_OuterClass | ||
| 21 | CLASS g$a A_InnerClass | ||
| 22 | CLASS g$a$a A_InnerInnerClass | ||
| 23 | FIELD a f3 I | ||
| 24 | METHOD a m2 ()V | ||
| 25 | FIELD a f1 I | ||
| 26 | FIELD a f2 Ljava/lang/String; | ||
| 27 | METHOD a m1 ()V | ||
| 28 | CLASS g$b | ||
| 29 | CLASS g$b$a A_NamedInnerClass | ||
| 30 | FIELD a f4 I | ||
| 31 | CLASS h | ||
| 32 | CLASS i deobf/I_Generics | ||
| 33 | CLASS i$a A_Type | ||
| 34 | CLASS i$b B_Generic | ||
| 35 | FIELD a f4 Ljava/lang/Object; | ||
| 36 | METHOD a m1 ()Ljava/lang/Object; | ||
| 37 | FIELD a f1 Ljava/util/List; | ||
| 38 | FIELD b f2 Ljava/util/List; | ||
| 39 | FIELD a f3 Ljava/util/Map; | ||
| 40 | FIELD a f5 Li$b; | ||
| 41 | FIELD b f6 Li$b; | ||