diff options
| author | 2015-02-09 22:23:45 -0500 | |
|---|---|---|
| committer | 2015-02-09 22:23:45 -0500 | |
| commit | af1041731c8c0ce1846ff7e7b6052ed7327a5dbc (patch) | |
| tree | e781b93f526a6c1ba7b6f5e14c319450199aa1df /test | |
| parent | Don't automatically move mappings around. We're more interested in stability ... (diff) | |
| download | enigma-fork-af1041731c8c0ce1846ff7e7b6052ed7327a5dbc.tar.gz enigma-fork-af1041731c8c0ce1846ff7e7b6052ed7327a5dbc.tar.xz enigma-fork-af1041731c8c0ce1846ff7e7b6052ed7327a5dbc.zip | |
fix translation issues, particularly with fields
Diffstat (limited to 'test')
| -rw-r--r-- | test/cuchaz/enigma/TestEntryFactory.java (renamed from test/cuchaz/enigma/EntryFactory.java) | 2 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestJarIndexConstructorReferences.java | 2 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestJarIndexInheritanceTree.java | 2 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestJarIndexLoneClass.java | 5 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestTokensConstructors.java | 2 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestTranslator.java | 86 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestType.java | 2 | ||||
| -rw-r--r-- | test/cuchaz/enigma/inputs/translation/A.java | 8 | ||||
| -rw-r--r-- | test/cuchaz/enigma/inputs/translation/A_Basic.java | 22 | ||||
| -rw-r--r-- | test/cuchaz/enigma/inputs/translation/B_BaseClass.java | 15 | ||||
| -rw-r--r-- | test/cuchaz/enigma/inputs/translation/C_SubClass.java | 17 | ||||
| -rw-r--r-- | test/cuchaz/enigma/resources/translation.mappings | 23 |
12 files changed, 154 insertions, 32 deletions
diff --git a/test/cuchaz/enigma/EntryFactory.java b/test/cuchaz/enigma/TestEntryFactory.java index 8c94bdf..754f308 100644 --- a/test/cuchaz/enigma/EntryFactory.java +++ b/test/cuchaz/enigma/TestEntryFactory.java | |||
| @@ -20,7 +20,7 @@ import cuchaz.enigma.mapping.MethodEntry; | |||
| 20 | import cuchaz.enigma.mapping.Signature; | 20 | import cuchaz.enigma.mapping.Signature; |
| 21 | import cuchaz.enigma.mapping.Type; | 21 | import cuchaz.enigma.mapping.Type; |
| 22 | 22 | ||
| 23 | public class EntryFactory { | 23 | public class TestEntryFactory { |
| 24 | 24 | ||
| 25 | public static ClassEntry newClass(String name) { | 25 | public static ClassEntry newClass(String name) { |
| 26 | return new ClassEntry(name); | 26 | return new ClassEntry(name); |
diff --git a/test/cuchaz/enigma/TestJarIndexConstructorReferences.java b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java index 22812fe..e1a3022 100644 --- a/test/cuchaz/enigma/TestJarIndexConstructorReferences.java +++ b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma; | 11 | package cuchaz.enigma; |
| 12 | 12 | ||
| 13 | import static cuchaz.enigma.EntryFactory.*; | 13 | import static cuchaz.enigma.TestEntryFactory.*; |
| 14 | import static org.hamcrest.MatcherAssert.*; | 14 | import static org.hamcrest.MatcherAssert.*; |
| 15 | import static org.hamcrest.Matchers.*; | 15 | import static org.hamcrest.Matchers.*; |
| 16 | 16 | ||
diff --git a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java index 349d33b..6e2c1ad 100644 --- a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java +++ b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma; | 11 | package cuchaz.enigma; |
| 12 | 12 | ||
| 13 | import static cuchaz.enigma.EntryFactory.*; | 13 | import static cuchaz.enigma.TestEntryFactory.*; |
| 14 | import static org.hamcrest.MatcherAssert.*; | 14 | import static org.hamcrest.MatcherAssert.*; |
| 15 | import static org.hamcrest.Matchers.*; | 15 | import static org.hamcrest.Matchers.*; |
| 16 | 16 | ||
diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index c0ac8d7..768284f 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | ******************************************************************************/ | 11 | ******************************************************************************/ |
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import static cuchaz.enigma.EntryFactory.*; | 14 | import static cuchaz.enigma.TestEntryFactory.*; |
| 15 | import static org.hamcrest.MatcherAssert.*; | 15 | import static org.hamcrest.MatcherAssert.*; |
| 16 | import static org.hamcrest.Matchers.*; | 16 | import static org.hamcrest.Matchers.*; |
| 17 | 17 | ||
| @@ -96,8 +96,7 @@ public class TestJarIndexLoneClass { | |||
| 96 | @Test | 96 | @Test |
| 97 | public void methodImplementations() { | 97 | public void methodImplementations() { |
| 98 | MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); | 98 | MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); |
| 99 | MethodImplementationsTreeNode node = m_index.getMethodImplementations(new Translator(), source); | 99 | assertThat(m_index.getMethodImplementations(new Translator(), source), is(empty())); |
| 100 | assertThat(node, is(nullValue())); | ||
| 101 | } | 100 | } |
| 102 | 101 | ||
| 103 | @Test | 102 | @Test |
diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java index 6758d2a..a563f83 100644 --- a/test/cuchaz/enigma/TestTokensConstructors.java +++ b/test/cuchaz/enigma/TestTokensConstructors.java | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma; | 11 | package cuchaz.enigma; |
| 12 | 12 | ||
| 13 | import static cuchaz.enigma.EntryFactory.*; | 13 | import static cuchaz.enigma.TestEntryFactory.*; |
| 14 | import static org.hamcrest.MatcherAssert.*; | 14 | import static org.hamcrest.MatcherAssert.*; |
| 15 | import static org.hamcrest.Matchers.*; | 15 | import static org.hamcrest.Matchers.*; |
| 16 | 16 | ||
diff --git a/test/cuchaz/enigma/TestTranslator.java b/test/cuchaz/enigma/TestTranslator.java index f91c585..3fe1680 100644 --- a/test/cuchaz/enigma/TestTranslator.java +++ b/test/cuchaz/enigma/TestTranslator.java | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | package cuchaz.enigma; | 1 | package cuchaz.enigma; |
| 2 | 2 | ||
| 3 | import static cuchaz.enigma.EntryFactory.*; | 3 | import static cuchaz.enigma.TestEntryFactory.*; |
| 4 | import static org.hamcrest.MatcherAssert.*; | 4 | import static org.hamcrest.MatcherAssert.*; |
| 5 | import static org.hamcrest.Matchers.*; | 5 | import static org.hamcrest.Matchers.*; |
| 6 | 6 | ||
| @@ -8,8 +8,10 @@ import java.io.InputStream; | |||
| 8 | import java.io.InputStreamReader; | 8 | import java.io.InputStreamReader; |
| 9 | import java.util.jar.JarFile; | 9 | import java.util.jar.JarFile; |
| 10 | 10 | ||
| 11 | import org.junit.BeforeClass; | ||
| 11 | import org.junit.Test; | 12 | import org.junit.Test; |
| 12 | 13 | ||
| 14 | import cuchaz.enigma.mapping.Entry; | ||
| 13 | import cuchaz.enigma.mapping.Mappings; | 15 | import cuchaz.enigma.mapping.Mappings; |
| 14 | import cuchaz.enigma.mapping.MappingsReader; | 16 | import cuchaz.enigma.mapping.MappingsReader; |
| 15 | import cuchaz.enigma.mapping.TranslationDirection; | 17 | import cuchaz.enigma.mapping.TranslationDirection; |
| @@ -18,25 +20,85 @@ import cuchaz.enigma.mapping.Translator; | |||
| 18 | 20 | ||
| 19 | public class TestTranslator { | 21 | public class TestTranslator { |
| 20 | 22 | ||
| 21 | private Deobfuscator m_deobfuscator; | 23 | private static Deobfuscator m_deobfuscator; |
| 22 | private Mappings m_mappings; | 24 | private static Mappings m_mappings; |
| 25 | private static Translator m_deobfTranslator; | ||
| 26 | private static Translator m_obfTranslator; | ||
| 23 | 27 | ||
| 24 | public TestTranslator() | 28 | @BeforeClass |
| 29 | public static void beforeClass() | ||
| 25 | throws Exception { | 30 | throws Exception { |
| 26 | m_deobfuscator = new Deobfuscator(new JarFile("build/testTranslation.obf.jar")); | 31 | m_deobfuscator = new Deobfuscator(new JarFile("build/testTranslation.obf.jar")); |
| 27 | try (InputStream in = getClass().getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { | 32 | try (InputStream in = TestTranslator.class.getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { |
| 28 | m_mappings = new MappingsReader().read(new InputStreamReader(in)); | 33 | m_mappings = new MappingsReader().read(new InputStreamReader(in)); |
| 29 | m_deobfuscator.setMappings(m_mappings); | 34 | m_deobfuscator.setMappings(m_mappings); |
| 35 | m_deobfTranslator = m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating); | ||
| 36 | m_obfTranslator = m_deobfuscator.getTranslator(TranslationDirection.Obfuscating); | ||
| 30 | } | 37 | } |
| 31 | } | 38 | } |
| 32 | 39 | ||
| 33 | @Test | 40 | @Test |
| 34 | public void deobfuscatingTranslations() | 41 | public void basicClasses() { |
| 35 | throws Exception { | 42 | assertMapping(newClass("none/a"), newClass("deobf/A_Basic")); |
| 36 | Translator translator = m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating); | 43 | assertMapping(newClass("none/b"), newClass("deobf/B_BaseClass")); |
| 37 | assertThat(translator.translateEntry(newClass("none/a")), is(newClass("deobf/A"))); | 44 | assertMapping(newClass("none/c"), newClass("deobf/C_SubClass")); |
| 38 | assertThat(translator.translateEntry(newField("none/a", "a", "I")), is(newField("deobf/A", "one", "I"))); | 45 | } |
| 39 | assertThat(translator.translateEntry(newField("none/a", "a", "F")), is(newField("deobf/A", "two", "F"))); | 46 | |
| 40 | assertThat(translator.translateEntry(newField("none/a", "a", "Ljava/lang/String;")), is(newField("deobf/A", "three", "Ljava/lang/String;"))); | 47 | @Test |
| 48 | public void basicFields() { | ||
| 49 | assertMapping(newField("none/a", "a", "I"), newField("deobf/A_Basic", "f1", "I")); | ||
| 50 | assertMapping(newField("none/a", "a", "F"), newField("deobf/A_Basic", "f2", "F")); | ||
| 51 | assertMapping(newField("none/a", "a", "Ljava/lang/String;"), newField("deobf/A_Basic", "f3", "Ljava/lang/String;")); | ||
| 52 | } | ||
| 53 | |||
| 54 | @Test | ||
| 55 | public void basicMethods() { | ||
| 56 | assertMapping(newMethod("none/a", "a", "()V"), newMethod("deobf/A_Basic", "m1", "()V")); | ||
| 57 | assertMapping(newMethod("none/a", "a", "()I"), newMethod("deobf/A_Basic", "m2", "()I")); | ||
| 58 | assertMapping(newMethod("none/a", "a", "(I)V"), newMethod("deobf/A_Basic", "m3", "(I)V")); | ||
| 59 | assertMapping(newMethod("none/a", "a", "(I)I"), newMethod("deobf/A_Basic", "m4", "(I)I")); | ||
| 60 | } | ||
| 61 | |||
| 62 | // TODO: basic constructors | ||
| 63 | |||
| 64 | @Test | ||
| 65 | public void inheritanceFields() { | ||
| 66 | assertMapping(newField("none/b", "a", "I"), newField("deobf/B_BaseClass", "f1", "I")); | ||
| 67 | assertMapping(newField("none/b", "a", "C"), newField("deobf/B_BaseClass", "f2", "C")); | ||
| 68 | assertMapping(newField("none/c", "b", "I"), newField("deobf/C_SubClass", "f3", "I")); | ||
| 69 | assertMapping(newField("none/c", "c", "I"), newField("deobf/C_SubClass", "f4", "I")); | ||
| 70 | } | ||
| 71 | |||
| 72 | @Test | ||
| 73 | public void inheritanceFieldsShadowing() { | ||
| 74 | assertMapping(newField("none/c", "b", "C"), newField("deobf/C_SubClass", "f2", "C")); | ||
| 75 | } | ||
| 76 | |||
| 77 | @Test | ||
| 78 | public void inheritanceFieldsBySubClass() { | ||
| 79 | assertMapping(newField("none/c", "a", "I"), newField("deobf/C_SubClass", "f1", "I")); | ||
| 80 | // NOTE: can't reference b.C by subclass since it's shadowed | ||
| 81 | } | ||
| 82 | |||
| 83 | @Test | ||
| 84 | public void inheritanceMethods() { | ||
| 85 | assertMapping(newMethod("none/b", "a", "()I"), newMethod("deobf/B_BaseClass", "m1", "()I")); | ||
| 86 | assertMapping(newMethod("none/b", "b", "()I"), newMethod("deobf/B_BaseClass", "m2", "()I")); | ||
| 87 | assertMapping(newMethod("none/c", "c", "()I"), newMethod("deobf/C_SubClass", "m3", "()I")); | ||
| 88 | } | ||
| 89 | |||
| 90 | @Test | ||
| 91 | public void inheritanceMethodsOverrides() { | ||
| 92 | assertMapping(newMethod("none/c", "a", "()I"), newMethod("deobf/C_SubClass", "m1", "()I")); | ||
| 93 | } | ||
| 94 | |||
| 95 | @Test | ||
| 96 | public void inheritanceMethodsBySubClass() { | ||
| 97 | assertMapping(newMethod("none/c", "b", "()I"), newMethod("deobf/C_SubClass", "m2", "()I")); | ||
| 98 | } | ||
| 99 | |||
| 100 | private void assertMapping(Entry obf, Entry deobf) { | ||
| 101 | assertThat(m_deobfTranslator.translateEntry(obf), is(deobf)); | ||
| 102 | assertThat(m_obfTranslator.translateEntry(deobf), is(obf)); | ||
| 41 | } | 103 | } |
| 42 | } | 104 | } |
diff --git a/test/cuchaz/enigma/TestType.java b/test/cuchaz/enigma/TestType.java index 7c3cebe..93f864b 100644 --- a/test/cuchaz/enigma/TestType.java +++ b/test/cuchaz/enigma/TestType.java | |||
| @@ -7,7 +7,7 @@ import static org.hamcrest.Matchers.*; | |||
| 7 | 7 | ||
| 8 | import cuchaz.enigma.mapping.Type; | 8 | import cuchaz.enigma.mapping.Type; |
| 9 | 9 | ||
| 10 | import static cuchaz.enigma.EntryFactory.*; | 10 | import static cuchaz.enigma.TestEntryFactory.*; |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | public class TestType { | 13 | public class TestType { |
diff --git a/test/cuchaz/enigma/inputs/translation/A.java b/test/cuchaz/enigma/inputs/translation/A.java deleted file mode 100644 index b8aaf11..0000000 --- a/test/cuchaz/enigma/inputs/translation/A.java +++ /dev/null | |||
| @@ -1,8 +0,0 @@ | |||
| 1 | package cuchaz.enigma.inputs.translation; | ||
| 2 | |||
| 3 | public class A { | ||
| 4 | |||
| 5 | public int one; | ||
| 6 | public float two; | ||
| 7 | public String three; | ||
| 8 | } | ||
diff --git a/test/cuchaz/enigma/inputs/translation/A_Basic.java b/test/cuchaz/enigma/inputs/translation/A_Basic.java new file mode 100644 index 0000000..8930763 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/A_Basic.java | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | package cuchaz.enigma.inputs.translation; | ||
| 2 | |||
| 3 | public class A_Basic { | ||
| 4 | |||
| 5 | public int one; | ||
| 6 | public float two; | ||
| 7 | public String three; | ||
| 8 | |||
| 9 | public void m1() { | ||
| 10 | } | ||
| 11 | |||
| 12 | public int m2() { | ||
| 13 | return 42; | ||
| 14 | } | ||
| 15 | |||
| 16 | public void m3(int a1) { | ||
| 17 | } | ||
| 18 | |||
| 19 | public int m4(int a1) { | ||
| 20 | return 5; // chosen by fair die roll, guaranteed to be random | ||
| 21 | } | ||
| 22 | } | ||
diff --git a/test/cuchaz/enigma/inputs/translation/B_BaseClass.java b/test/cuchaz/enigma/inputs/translation/B_BaseClass.java new file mode 100644 index 0000000..44fbc8d --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/B_BaseClass.java | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | package cuchaz.enigma.inputs.translation; | ||
| 2 | |||
| 3 | public class B_BaseClass { | ||
| 4 | |||
| 5 | public int f1; | ||
| 6 | public char f2; | ||
| 7 | |||
| 8 | public int m1() { | ||
| 9 | return 5; | ||
| 10 | } | ||
| 11 | |||
| 12 | public int m2() { | ||
| 13 | return 42; | ||
| 14 | } | ||
| 15 | } | ||
diff --git a/test/cuchaz/enigma/inputs/translation/C_SubClass.java b/test/cuchaz/enigma/inputs/translation/C_SubClass.java new file mode 100644 index 0000000..8fe0b79 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/C_SubClass.java | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | package cuchaz.enigma.inputs.translation; | ||
| 2 | |||
| 3 | public class C_SubClass extends B_BaseClass { | ||
| 4 | |||
| 5 | public char f2; // shadows B_BaseClass.f2 | ||
| 6 | public int f3; | ||
| 7 | public int f4; | ||
| 8 | |||
| 9 | @Override | ||
| 10 | public int m1() { | ||
| 11 | return 32; | ||
| 12 | } | ||
| 13 | |||
| 14 | public int m3() { | ||
| 15 | return 7; | ||
| 16 | } | ||
| 17 | } | ||
diff --git a/test/cuchaz/enigma/resources/translation.mappings b/test/cuchaz/enigma/resources/translation.mappings index c71493e..d87d437 100644 --- a/test/cuchaz/enigma/resources/translation.mappings +++ b/test/cuchaz/enigma/resources/translation.mappings | |||
| @@ -1,4 +1,19 @@ | |||
| 1 | CLASS none/a deobf/A | 1 | CLASS none/a deobf/A_Basic |
| 2 | FIELD a one I | 2 | FIELD a f1 I |
| 3 | FIELD a two F | 3 | FIELD a f2 F |
| 4 | FIELD a three Ljava/lang/String; \ No newline at end of file | 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 none/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 none/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 | ||