diff options
| author | 2015-02-06 00:01:42 -0500 | |
|---|---|---|
| committer | 2015-02-06 00:01:42 -0500 | |
| commit | 5a406268664e7a8db4991f421503afcf64780432 (patch) | |
| tree | ae4b319ac65de40b2c6307a193cbe363b2f80385 /test | |
| parent | explicitly add jre 7 to classpath (diff) | |
| parent | start some translation tests (diff) | |
| download | enigma-fork-5a406268664e7a8db4991f421503afcf64780432.tar.gz enigma-fork-5a406268664e7a8db4991f421503afcf64780432.tar.xz enigma-fork-5a406268664e7a8db4991f421503afcf64780432.zip | |
Merge with a04907514a113e299dc667aa221a67573c5faa1b
Diffstat (limited to 'test')
| -rw-r--r-- | test/cuchaz/enigma/TestBehaviorSignature.java | 196 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestDeobfuscator.java | 12 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestInnerClasses.java | 3 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestJarIndexConstructorReferences.java | 3 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestJarIndexInheritanceTree.java | 3 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestJarIndexLoneClass.java | 3 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestSourceIndex.java | 5 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestTokensConstructors.java | 3 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestTranslator.java | 39 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestType.java | 183 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TokenChecker.java | 3 | ||||
| -rw-r--r-- | test/cuchaz/enigma/inputs/translation/A.java | 8 | ||||
| -rw-r--r-- | test/cuchaz/enigma/resources/translation.mappings | 4 |
13 files changed, 453 insertions, 12 deletions
diff --git a/test/cuchaz/enigma/TestBehaviorSignature.java b/test/cuchaz/enigma/TestBehaviorSignature.java new file mode 100644 index 0000000..4705cd1 --- /dev/null +++ b/test/cuchaz/enigma/TestBehaviorSignature.java | |||
| @@ -0,0 +1,196 @@ | |||
| 1 | package cuchaz.enigma; | ||
| 2 | |||
| 3 | import static org.hamcrest.MatcherAssert.*; | ||
| 4 | import static org.hamcrest.Matchers.*; | ||
| 5 | |||
| 6 | import org.junit.Test; | ||
| 7 | |||
| 8 | import cuchaz.enigma.mapping.BehaviorSignature; | ||
| 9 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 10 | import cuchaz.enigma.mapping.Type; | ||
| 11 | |||
| 12 | |||
| 13 | public class TestBehaviorSignature { | ||
| 14 | |||
| 15 | @Test | ||
| 16 | public void easiest() { | ||
| 17 | final BehaviorSignature sig = new BehaviorSignature("()V"); | ||
| 18 | assertThat(sig.getArgumentTypes(), is(empty())); | ||
| 19 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 20 | } | ||
| 21 | |||
| 22 | @Test | ||
| 23 | public void primitives() { | ||
| 24 | { | ||
| 25 | final BehaviorSignature sig = new BehaviorSignature("(I)V"); | ||
| 26 | assertThat(sig.getArgumentTypes(), contains( | ||
| 27 | new Type("I") | ||
| 28 | )); | ||
| 29 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 30 | } | ||
| 31 | { | ||
| 32 | final BehaviorSignature sig = new BehaviorSignature("(I)I"); | ||
| 33 | assertThat(sig.getArgumentTypes(), contains( | ||
| 34 | new Type("I") | ||
| 35 | )); | ||
| 36 | assertThat(sig.getReturnType(), is(new Type("I"))); | ||
| 37 | } | ||
| 38 | { | ||
| 39 | final BehaviorSignature sig = new BehaviorSignature("(IBCJ)Z"); | ||
| 40 | assertThat(sig.getArgumentTypes(), contains( | ||
| 41 | new Type("I"), | ||
| 42 | new Type("B"), | ||
| 43 | new Type("C"), | ||
| 44 | new Type("J") | ||
| 45 | )); | ||
| 46 | assertThat(sig.getReturnType(), is(new Type("Z"))); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | @Test | ||
| 51 | public void classes() { | ||
| 52 | { | ||
| 53 | final BehaviorSignature sig = new BehaviorSignature("([LFoo;)V"); | ||
| 54 | assertThat(sig.getArgumentTypes().size(), is(1)); | ||
| 55 | assertThat(sig.getArgumentTypes().get(0), is(new Type("[LFoo;"))); | ||
| 56 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 57 | } | ||
| 58 | { | ||
| 59 | final BehaviorSignature sig = new BehaviorSignature("(LFoo;)LBar;"); | ||
| 60 | assertThat(sig.getArgumentTypes(), contains( | ||
| 61 | new Type("LFoo;") | ||
| 62 | )); | ||
| 63 | assertThat(sig.getReturnType(), is(new Type("LBar;"))); | ||
| 64 | } | ||
| 65 | { | ||
| 66 | final BehaviorSignature sig = new BehaviorSignature("(LFoo;LMoo;LZoo;)LBar;"); | ||
| 67 | assertThat(sig.getArgumentTypes(), contains( | ||
| 68 | new Type("LFoo;"), | ||
| 69 | new Type("LMoo;"), | ||
| 70 | new Type("LZoo;") | ||
| 71 | )); | ||
| 72 | assertThat(sig.getReturnType(), is(new Type("LBar;"))); | ||
| 73 | } | ||
| 74 | { | ||
| 75 | final BehaviorSignature sig = new BehaviorSignature("(LFoo<LParm;>;LMoo<LParm;>;)LBar<LParm;>;"); | ||
| 76 | assertThat(sig.getArgumentTypes(), contains( | ||
| 77 | new Type("LFoo<LParm;>;"), | ||
| 78 | new Type("LMoo<LParm;>;") | ||
| 79 | )); | ||
| 80 | assertThat(sig.getReturnType(), is(new Type("LBar<LParm;>;"))); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | @Test | ||
| 85 | public void arrays() { | ||
| 86 | { | ||
| 87 | final BehaviorSignature sig = new BehaviorSignature("([I)V"); | ||
| 88 | assertThat(sig.getArgumentTypes(), contains( | ||
| 89 | new Type("[I") | ||
| 90 | )); | ||
| 91 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 92 | } | ||
| 93 | { | ||
| 94 | final BehaviorSignature sig = new BehaviorSignature("([I)[J"); | ||
| 95 | assertThat(sig.getArgumentTypes(), contains( | ||
| 96 | new Type("[I") | ||
| 97 | )); | ||
| 98 | assertThat(sig.getReturnType(), is(new Type("[J"))); | ||
| 99 | } | ||
| 100 | { | ||
| 101 | final BehaviorSignature sig = new BehaviorSignature("([I[Z[F)[D"); | ||
| 102 | assertThat(sig.getArgumentTypes(), contains( | ||
| 103 | new Type("[I"), | ||
| 104 | new Type("[Z"), | ||
| 105 | new Type("[F") | ||
| 106 | )); | ||
| 107 | assertThat(sig.getReturnType(), is(new Type("[D"))); | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | @Test | ||
| 112 | public void mixed() { | ||
| 113 | { | ||
| 114 | final BehaviorSignature sig = new BehaviorSignature("(I[JLFoo;)Z"); | ||
| 115 | assertThat(sig.getArgumentTypes(), contains( | ||
| 116 | new Type("I"), | ||
| 117 | new Type("[J"), | ||
| 118 | new Type("LFoo;") | ||
| 119 | )); | ||
| 120 | assertThat(sig.getReturnType(), is(new Type("Z"))); | ||
| 121 | } | ||
| 122 | { | ||
| 123 | final BehaviorSignature sig = new BehaviorSignature("(III)[LFoo;"); | ||
| 124 | assertThat(sig.getArgumentTypes(), contains( | ||
| 125 | new Type("I"), | ||
| 126 | new Type("I"), | ||
| 127 | new Type("I") | ||
| 128 | )); | ||
| 129 | assertThat(sig.getReturnType(), is(new Type("[LFoo;"))); | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | @Test | ||
| 134 | public void replaceClasses() { | ||
| 135 | { | ||
| 136 | final BehaviorSignature oldSig = new BehaviorSignature("()V"); | ||
| 137 | final BehaviorSignature sig = new BehaviorSignature(oldSig, new BehaviorSignature.ClassReplacer() { | ||
| 138 | @Override | ||
| 139 | public ClassEntry replace(ClassEntry entry) { | ||
| 140 | return null; | ||
| 141 | } | ||
| 142 | }); | ||
| 143 | assertThat(sig.getArgumentTypes(), is(empty())); | ||
| 144 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 145 | } | ||
| 146 | { | ||
| 147 | final BehaviorSignature oldSig = new BehaviorSignature("(IJLFoo;)V"); | ||
| 148 | final BehaviorSignature sig = new BehaviorSignature(oldSig, new BehaviorSignature.ClassReplacer() { | ||
| 149 | @Override | ||
| 150 | public ClassEntry replace(ClassEntry entry) { | ||
| 151 | return null; | ||
| 152 | } | ||
| 153 | }); | ||
| 154 | assertThat(sig.getArgumentTypes(), contains( | ||
| 155 | new Type("I"), | ||
| 156 | new Type("J"), | ||
| 157 | new Type("LFoo;") | ||
| 158 | )); | ||
| 159 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 160 | } | ||
| 161 | { | ||
| 162 | final BehaviorSignature oldSig = new BehaviorSignature("(LFoo;LBar;)LMoo;"); | ||
| 163 | final BehaviorSignature sig = new BehaviorSignature(oldSig, new BehaviorSignature.ClassReplacer() { | ||
| 164 | @Override | ||
| 165 | public ClassEntry replace(ClassEntry entry) { | ||
| 166 | if (entry.getName().equals("Foo")) { | ||
| 167 | return new ClassEntry("Bar"); | ||
| 168 | } | ||
| 169 | return null; | ||
| 170 | } | ||
| 171 | }); | ||
| 172 | assertThat(sig.getArgumentTypes(), contains( | ||
| 173 | new Type("LBar;"), | ||
| 174 | new Type("LBar;") | ||
| 175 | )); | ||
| 176 | assertThat(sig.getReturnType(), is(new Type("LMoo;"))); | ||
| 177 | } | ||
| 178 | { | ||
| 179 | final BehaviorSignature oldSig = new BehaviorSignature("(LFoo;LBar;)LMoo;"); | ||
| 180 | final BehaviorSignature sig = new BehaviorSignature(oldSig, new BehaviorSignature.ClassReplacer() { | ||
| 181 | @Override | ||
| 182 | public ClassEntry replace(ClassEntry entry) { | ||
| 183 | if (entry.getName().equals("Moo")) { | ||
| 184 | return new ClassEntry("Cow"); | ||
| 185 | } | ||
| 186 | return null; | ||
| 187 | } | ||
| 188 | }); | ||
| 189 | assertThat(sig.getArgumentTypes(), contains( | ||
| 190 | new Type("LFoo;"), | ||
| 191 | new Type("LBar;") | ||
| 192 | )); | ||
| 193 | assertThat(sig.getReturnType(), is(new Type("LCow;"))); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | } | ||
diff --git a/test/cuchaz/enigma/TestDeobfuscator.java b/test/cuchaz/enigma/TestDeobfuscator.java index 129d7b2..26d492d 100644 --- a/test/cuchaz/enigma/TestDeobfuscator.java +++ b/test/cuchaz/enigma/TestDeobfuscator.java | |||
| @@ -25,17 +25,20 @@ import cuchaz.enigma.mapping.ClassEntry; | |||
| 25 | 25 | ||
| 26 | public class TestDeobfuscator { | 26 | public class TestDeobfuscator { |
| 27 | 27 | ||
| 28 | private Deobfuscator getDeobfuscator() throws IOException { | 28 | private Deobfuscator getDeobfuscator() |
| 29 | throws IOException { | ||
| 29 | return new Deobfuscator(new JarFile("build/testLoneClass.obf.jar")); | 30 | return new Deobfuscator(new JarFile("build/testLoneClass.obf.jar")); |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | @Test | 33 | @Test |
| 33 | public void loadJar() throws Exception { | 34 | public void loadJar() |
| 35 | throws Exception { | ||
| 34 | getDeobfuscator(); | 36 | getDeobfuscator(); |
| 35 | } | 37 | } |
| 36 | 38 | ||
| 37 | @Test | 39 | @Test |
| 38 | public void getClasses() throws Exception { | 40 | public void getClasses() |
| 41 | throws Exception { | ||
| 39 | Deobfuscator deobfuscator = getDeobfuscator(); | 42 | Deobfuscator deobfuscator = getDeobfuscator(); |
| 40 | List<ClassEntry> obfClasses = Lists.newArrayList(); | 43 | List<ClassEntry> obfClasses = Lists.newArrayList(); |
| 41 | List<ClassEntry> deobfClasses = Lists.newArrayList(); | 44 | List<ClassEntry> deobfClasses = Lists.newArrayList(); |
| @@ -47,7 +50,8 @@ public class TestDeobfuscator { | |||
| 47 | } | 50 | } |
| 48 | 51 | ||
| 49 | @Test | 52 | @Test |
| 50 | public void decompileClass() throws Exception { | 53 | public void decompileClass() |
| 54 | throws Exception { | ||
| 51 | Deobfuscator deobfuscator = getDeobfuscator(); | 55 | Deobfuscator deobfuscator = getDeobfuscator(); |
| 52 | deobfuscator.getSource(deobfuscator.getSourceTree("none/a")); | 56 | deobfuscator.getSource(deobfuscator.getSourceTree("none/a")); |
| 53 | } | 57 | } |
diff --git a/test/cuchaz/enigma/TestInnerClasses.java b/test/cuchaz/enigma/TestInnerClasses.java index 63c9b71..2e16a33 100644 --- a/test/cuchaz/enigma/TestInnerClasses.java +++ b/test/cuchaz/enigma/TestInnerClasses.java | |||
| @@ -36,7 +36,8 @@ public class TestInnerClasses { | |||
| 36 | private static final String AnonymousWithOuterAccessOuter = "none/i"; | 36 | private static final String AnonymousWithOuterAccessOuter = "none/i"; |
| 37 | private static final String AnonymousWithOuterAccessInner = "j"; | 37 | private static final String AnonymousWithOuterAccessInner = "j"; |
| 38 | 38 | ||
| 39 | public TestInnerClasses() throws Exception { | 39 | public TestInnerClasses() |
| 40 | throws Exception { | ||
| 40 | m_index = new JarIndex(); | 41 | m_index = new JarIndex(); |
| 41 | JarFile jar = new JarFile("build/testInnerClasses.obf.jar"); | 42 | JarFile jar = new JarFile("build/testInnerClasses.obf.jar"); |
| 42 | m_index.indexJar(jar, true); | 43 | m_index.indexJar(jar, true); |
diff --git a/test/cuchaz/enigma/TestJarIndexConstructorReferences.java b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java index 8e3ad6d..a735de7 100644 --- a/test/cuchaz/enigma/TestJarIndexConstructorReferences.java +++ b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java | |||
| @@ -36,7 +36,8 @@ public class TestJarIndexConstructorReferences { | |||
| 36 | private ClassEntry m_defaultClass = new ClassEntry("none/c"); | 36 | private ClassEntry m_defaultClass = new ClassEntry("none/c"); |
| 37 | private ClassEntry m_callerClass = new ClassEntry("none/b"); | 37 | private ClassEntry m_callerClass = new ClassEntry("none/b"); |
| 38 | 38 | ||
| 39 | public TestJarIndexConstructorReferences() throws Exception { | 39 | public TestJarIndexConstructorReferences() |
| 40 | throws Exception { | ||
| 40 | File jarFile = new File("build/testConstructors.obf.jar"); | 41 | File jarFile = new File("build/testConstructors.obf.jar"); |
| 41 | m_index = new JarIndex(); | 42 | m_index = new JarIndex(); |
| 42 | m_index.indexJar(new JarFile(jarFile), false); | 43 | m_index.indexJar(new JarFile(jarFile), false); |
diff --git a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java index 4d66397..26499f0 100644 --- a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java +++ b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java | |||
| @@ -41,7 +41,8 @@ public class TestJarIndexInheritanceTree { | |||
| 41 | private FieldEntry m_nameField = new FieldEntry(m_baseClass, "a"); | 41 | private FieldEntry m_nameField = new FieldEntry(m_baseClass, "a"); |
| 42 | private FieldEntry m_numThingsField = new FieldEntry(m_subClassB, "a"); | 42 | private FieldEntry m_numThingsField = new FieldEntry(m_subClassB, "a"); |
| 43 | 43 | ||
| 44 | public TestJarIndexInheritanceTree() throws Exception { | 44 | public TestJarIndexInheritanceTree() |
| 45 | throws Exception { | ||
| 45 | m_index = new JarIndex(); | 46 | m_index = new JarIndex(); |
| 46 | m_index.indexJar(new JarFile("build/testInheritanceTree.obf.jar"), false); | 47 | m_index.indexJar(new JarFile("build/testInheritanceTree.obf.jar"), false); |
| 47 | } | 48 | } |
diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index a061b72..108c623 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java | |||
| @@ -38,7 +38,8 @@ public class TestJarIndexLoneClass { | |||
| 38 | 38 | ||
| 39 | private JarIndex m_index; | 39 | private JarIndex m_index; |
| 40 | 40 | ||
| 41 | public TestJarIndexLoneClass() throws Exception { | 41 | public TestJarIndexLoneClass() |
| 42 | throws Exception { | ||
| 42 | m_index = new JarIndex(); | 43 | m_index = new JarIndex(); |
| 43 | m_index.indexJar(new JarFile("build/testLoneClass.obf.jar"), false); | 44 | m_index.indexJar(new JarFile("build/testLoneClass.obf.jar"), false); |
| 44 | } | 45 | } |
diff --git a/test/cuchaz/enigma/TestSourceIndex.java b/test/cuchaz/enigma/TestSourceIndex.java index 70a5ee4..357acb6 100644 --- a/test/cuchaz/enigma/TestSourceIndex.java +++ b/test/cuchaz/enigma/TestSourceIndex.java | |||
| @@ -24,8 +24,9 @@ import cuchaz.enigma.mapping.ClassEntry; | |||
| 24 | public class TestSourceIndex { | 24 | public class TestSourceIndex { |
| 25 | 25 | ||
| 26 | // TEMP | 26 | // TEMP |
| 27 | @Test | 27 | //@Test |
| 28 | public void indexEverything() throws Exception { | 28 | public void indexEverything() |
| 29 | throws Exception { | ||
| 29 | Deobfuscator deobfuscator = new Deobfuscator(new JarFile("input/1.8.jar")); | 30 | Deobfuscator deobfuscator = new Deobfuscator(new JarFile("input/1.8.jar")); |
| 30 | 31 | ||
| 31 | // get all classes that aren't inner classes | 32 | // get all classes that aren't inner classes |
diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java index 56424ae..6758d2a 100644 --- a/test/cuchaz/enigma/TestTokensConstructors.java +++ b/test/cuchaz/enigma/TestTokensConstructors.java | |||
| @@ -22,7 +22,8 @@ import cuchaz.enigma.mapping.BehaviorEntry; | |||
| 22 | 22 | ||
| 23 | public class TestTokensConstructors extends TokenChecker { | 23 | public class TestTokensConstructors extends TokenChecker { |
| 24 | 24 | ||
| 25 | public TestTokensConstructors() throws Exception { | 25 | public TestTokensConstructors() |
| 26 | throws Exception { | ||
| 26 | super(new JarFile("build/testConstructors.obf.jar")); | 27 | super(new JarFile("build/testConstructors.obf.jar")); |
| 27 | } | 28 | } |
| 28 | 29 | ||
diff --git a/test/cuchaz/enigma/TestTranslator.java b/test/cuchaz/enigma/TestTranslator.java new file mode 100644 index 0000000..290f6f0 --- /dev/null +++ b/test/cuchaz/enigma/TestTranslator.java | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | package cuchaz.enigma; | ||
| 2 | |||
| 3 | import static cuchaz.enigma.EntryFactory.*; | ||
| 4 | import static org.hamcrest.MatcherAssert.*; | ||
| 5 | import static org.hamcrest.Matchers.*; | ||
| 6 | |||
| 7 | import java.io.InputStream; | ||
| 8 | import java.io.InputStreamReader; | ||
| 9 | import java.util.jar.JarFile; | ||
| 10 | |||
| 11 | import org.junit.Test; | ||
| 12 | |||
| 13 | import cuchaz.enigma.mapping.Mappings; | ||
| 14 | import cuchaz.enigma.mapping.MappingsReader; | ||
| 15 | import cuchaz.enigma.mapping.TranslationDirection; | ||
| 16 | import cuchaz.enigma.mapping.Translator; | ||
| 17 | |||
| 18 | |||
| 19 | public class TestTranslator { | ||
| 20 | |||
| 21 | private Deobfuscator m_deobfuscator; | ||
| 22 | private Mappings m_mappings; | ||
| 23 | |||
| 24 | public TestTranslator() | ||
| 25 | throws Exception { | ||
| 26 | m_deobfuscator = new Deobfuscator(new JarFile("build/testTranslation.obf.jar")); | ||
| 27 | try (InputStream in = getClass().getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { | ||
| 28 | m_mappings = new MappingsReader().read(new InputStreamReader(in)); | ||
| 29 | m_deobfuscator.setMappings(m_mappings); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | @Test | ||
| 34 | public void deobfuscatingTranslations() | ||
| 35 | throws Exception { | ||
| 36 | Translator translator = m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating); | ||
| 37 | assertThat(translator.translateEntry(newClass("none/a")), is(newClass("deobf/A"))); | ||
| 38 | } | ||
| 39 | } | ||
diff --git a/test/cuchaz/enigma/TestType.java b/test/cuchaz/enigma/TestType.java new file mode 100644 index 0000000..efc6a4c --- /dev/null +++ b/test/cuchaz/enigma/TestType.java | |||
| @@ -0,0 +1,183 @@ | |||
| 1 | package cuchaz.enigma; | ||
| 2 | |||
| 3 | import org.junit.Test; | ||
| 4 | |||
| 5 | import static org.hamcrest.MatcherAssert.*; | ||
| 6 | import static org.hamcrest.Matchers.*; | ||
| 7 | |||
| 8 | import cuchaz.enigma.mapping.Type; | ||
| 9 | |||
| 10 | import static cuchaz.enigma.EntryFactory.*; | ||
| 11 | |||
| 12 | |||
| 13 | public class TestType { | ||
| 14 | |||
| 15 | @Test | ||
| 16 | public void isVoid() { | ||
| 17 | assertThat(new Type("V").isVoid(), is(true)); | ||
| 18 | assertThat(new Type("Z").isVoid(), is(false)); | ||
| 19 | assertThat(new Type("B").isVoid(), is(false)); | ||
| 20 | assertThat(new Type("C").isVoid(), is(false)); | ||
| 21 | assertThat(new Type("I").isVoid(), is(false)); | ||
| 22 | assertThat(new Type("J").isVoid(), is(false)); | ||
| 23 | assertThat(new Type("F").isVoid(), is(false)); | ||
| 24 | assertThat(new Type("D").isVoid(), is(false)); | ||
| 25 | assertThat(new Type("LFoo;").isVoid(), is(false)); | ||
| 26 | assertThat(new Type("[I").isVoid(), is(false)); | ||
| 27 | } | ||
| 28 | |||
| 29 | @Test | ||
| 30 | public void isPrimitive() { | ||
| 31 | assertThat(new Type("V").isPrimitive(), is(false)); | ||
| 32 | assertThat(new Type("Z").isPrimitive(), is(true)); | ||
| 33 | assertThat(new Type("B").isPrimitive(), is(true)); | ||
| 34 | assertThat(new Type("C").isPrimitive(), is(true)); | ||
| 35 | assertThat(new Type("I").isPrimitive(), is(true)); | ||
| 36 | assertThat(new Type("J").isPrimitive(), is(true)); | ||
| 37 | assertThat(new Type("F").isPrimitive(), is(true)); | ||
| 38 | assertThat(new Type("D").isPrimitive(), is(true)); | ||
| 39 | assertThat(new Type("LFoo;").isPrimitive(), is(false)); | ||
| 40 | assertThat(new Type("[I").isPrimitive(), is(false)); | ||
| 41 | } | ||
| 42 | |||
| 43 | @Test | ||
| 44 | public void getPrimitive() { | ||
| 45 | assertThat(new Type("Z").getPrimitive(), is(Type.Primitive.Boolean)); | ||
| 46 | assertThat(new Type("B").getPrimitive(), is(Type.Primitive.Byte)); | ||
| 47 | assertThat(new Type("C").getPrimitive(), is(Type.Primitive.Character)); | ||
| 48 | assertThat(new Type("I").getPrimitive(), is(Type.Primitive.Integer)); | ||
| 49 | assertThat(new Type("J").getPrimitive(), is(Type.Primitive.Long)); | ||
| 50 | assertThat(new Type("F").getPrimitive(), is(Type.Primitive.Float)); | ||
| 51 | assertThat(new Type("D").getPrimitive(), is(Type.Primitive.Double)); | ||
| 52 | } | ||
| 53 | |||
| 54 | @Test | ||
| 55 | public void isClass() { | ||
| 56 | assertThat(new Type("V").isClass(), is(false)); | ||
| 57 | assertThat(new Type("Z").isClass(), is(false)); | ||
| 58 | assertThat(new Type("B").isClass(), is(false)); | ||
| 59 | assertThat(new Type("C").isClass(), is(false)); | ||
| 60 | assertThat(new Type("I").isClass(), is(false)); | ||
| 61 | assertThat(new Type("J").isClass(), is(false)); | ||
| 62 | assertThat(new Type("F").isClass(), is(false)); | ||
| 63 | assertThat(new Type("D").isClass(), is(false)); | ||
| 64 | assertThat(new Type("LFoo;").isClass(), is(true)); | ||
| 65 | assertThat(new Type("[I").isClass(), is(false)); | ||
| 66 | } | ||
| 67 | |||
| 68 | @Test | ||
| 69 | public void getClassEntry() { | ||
| 70 | assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); | ||
| 71 | assertThat(new Type("LFoo<Ljava/lang/String;>;").getClassEntry(), is(newClass("Foo"))); | ||
| 72 | } | ||
| 73 | |||
| 74 | @Test | ||
| 75 | public void isArray() { | ||
| 76 | assertThat(new Type("V").isArray(), is(false)); | ||
| 77 | assertThat(new Type("Z").isArray(), is(false)); | ||
| 78 | assertThat(new Type("B").isArray(), is(false)); | ||
| 79 | assertThat(new Type("C").isArray(), is(false)); | ||
| 80 | assertThat(new Type("I").isArray(), is(false)); | ||
| 81 | assertThat(new Type("J").isArray(), is(false)); | ||
| 82 | assertThat(new Type("F").isArray(), is(false)); | ||
| 83 | assertThat(new Type("D").isArray(), is(false)); | ||
| 84 | assertThat(new Type("LFoo;").isArray(), is(false)); | ||
| 85 | assertThat(new Type("[I").isArray(), is(true)); | ||
| 86 | } | ||
| 87 | |||
| 88 | @Test | ||
| 89 | public void getArrayDimension() { | ||
| 90 | assertThat(new Type("[I").getArrayDimension(), is(1)); | ||
| 91 | assertThat(new Type("[[I").getArrayDimension(), is(2)); | ||
| 92 | assertThat(new Type("[[[I").getArrayDimension(), is(3)); | ||
| 93 | } | ||
| 94 | |||
| 95 | @Test | ||
| 96 | public void getArrayType() { | ||
| 97 | assertThat(new Type("[I").getArrayType(), is(new Type("I"))); | ||
| 98 | assertThat(new Type("[[I").getArrayType(), is(new Type("I"))); | ||
| 99 | assertThat(new Type("[[[I").getArrayType(), is(new Type("I"))); | ||
| 100 | assertThat(new Type("[Ljava/lang/String;").getArrayType(), is(new Type("Ljava/lang/String;"))); | ||
| 101 | } | ||
| 102 | |||
| 103 | @Test | ||
| 104 | public void parseVoid() { | ||
| 105 | final String answer = "V"; | ||
| 106 | assertThat(Type.parseFirst("V"), is(answer)); | ||
| 107 | assertThat(Type.parseFirst("VVV"), is(answer)); | ||
| 108 | assertThat(Type.parseFirst("VIJ"), is(answer)); | ||
| 109 | assertThat(Type.parseFirst("V[I"), is(answer)); | ||
| 110 | assertThat(Type.parseFirst("VLFoo;"), is(answer)); | ||
| 111 | assertThat(Type.parseFirst("V[LFoo;"), is(answer)); | ||
| 112 | } | ||
| 113 | |||
| 114 | @Test | ||
| 115 | public void parsePrimitive() { | ||
| 116 | final String answer = "I"; | ||
| 117 | assertThat(Type.parseFirst("I"), is(answer)); | ||
| 118 | assertThat(Type.parseFirst("III"), is(answer)); | ||
| 119 | assertThat(Type.parseFirst("IJZ"), is(answer)); | ||
| 120 | assertThat(Type.parseFirst("I[I"), is(answer)); | ||
| 121 | assertThat(Type.parseFirst("ILFoo;"), is(answer)); | ||
| 122 | assertThat(Type.parseFirst("I[LFoo;"), is(answer)); | ||
| 123 | } | ||
| 124 | |||
| 125 | @Test | ||
| 126 | public void parseClass() { | ||
| 127 | { | ||
| 128 | final String answer = "LFoo;"; | ||
| 129 | assertThat(Type.parseFirst("LFoo;"), is(answer)); | ||
| 130 | assertThat(Type.parseFirst("LFoo;I"), is(answer)); | ||
| 131 | assertThat(Type.parseFirst("LFoo;JZ"), is(answer)); | ||
| 132 | assertThat(Type.parseFirst("LFoo;[I"), is(answer)); | ||
| 133 | assertThat(Type.parseFirst("LFoo;LFoo;"), is(answer)); | ||
| 134 | assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); | ||
| 135 | } | ||
| 136 | { | ||
| 137 | final String answer = "LFoo<LFoo;>;"; | ||
| 138 | assertThat(Type.parseFirst("LFoo<LFoo;>;"), is(answer)); | ||
| 139 | assertThat(Type.parseFirst("LFoo<LFoo;>;I"), is(answer)); | ||
| 140 | assertThat(Type.parseFirst("LFoo<LFoo;>;JZ"), is(answer)); | ||
| 141 | assertThat(Type.parseFirst("LFoo<LFoo;>;[I"), is(answer)); | ||
| 142 | assertThat(Type.parseFirst("LFoo<LFoo;>;LFoo;"), is(answer)); | ||
| 143 | assertThat(Type.parseFirst("LFoo<LFoo;>;[LFoo;"), is(answer)); | ||
| 144 | } | ||
| 145 | { | ||
| 146 | final String answer = "LFoo<LFoo;,LBar;>;"; | ||
| 147 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;"), is(answer)); | ||
| 148 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;I"), is(answer)); | ||
| 149 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;JZ"), is(answer)); | ||
| 150 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;[I"), is(answer)); | ||
| 151 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;LFoo;"), is(answer)); | ||
| 152 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;[LFoo;"), is(answer)); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 156 | @Test | ||
| 157 | public void parseArray() { | ||
| 158 | { | ||
| 159 | final String answer = "[I"; | ||
| 160 | assertThat(Type.parseFirst("[I"), is(answer)); | ||
| 161 | assertThat(Type.parseFirst("[III"), is(answer)); | ||
| 162 | assertThat(Type.parseFirst("[IJZ"), is(answer)); | ||
| 163 | assertThat(Type.parseFirst("[I[I"), is(answer)); | ||
| 164 | assertThat(Type.parseFirst("[ILFoo;"), is(answer)); | ||
| 165 | } | ||
| 166 | { | ||
| 167 | final String answer = "[[I"; | ||
| 168 | assertThat(Type.parseFirst("[[I"), is(answer)); | ||
| 169 | assertThat(Type.parseFirst("[[III"), is(answer)); | ||
| 170 | assertThat(Type.parseFirst("[[IJZ"), is(answer)); | ||
| 171 | assertThat(Type.parseFirst("[[I[I"), is(answer)); | ||
| 172 | assertThat(Type.parseFirst("[[ILFoo;"), is(answer)); | ||
| 173 | } | ||
| 174 | { | ||
| 175 | final String answer = "[LFoo;"; | ||
| 176 | assertThat(Type.parseFirst("[LFoo;"), is(answer)); | ||
| 177 | assertThat(Type.parseFirst("[LFoo;II"), is(answer)); | ||
| 178 | assertThat(Type.parseFirst("[LFoo;JZ"), is(answer)); | ||
| 179 | assertThat(Type.parseFirst("[LFoo;[I"), is(answer)); | ||
| 180 | assertThat(Type.parseFirst("[LFoo;LFoo;"), is(answer)); | ||
| 181 | } | ||
| 182 | } | ||
| 183 | } | ||
diff --git a/test/cuchaz/enigma/TokenChecker.java b/test/cuchaz/enigma/TokenChecker.java index febea2a..a72c2fc 100644 --- a/test/cuchaz/enigma/TokenChecker.java +++ b/test/cuchaz/enigma/TokenChecker.java | |||
| @@ -27,7 +27,8 @@ public class TokenChecker { | |||
| 27 | 27 | ||
| 28 | private Deobfuscator m_deobfuscator; | 28 | private Deobfuscator m_deobfuscator; |
| 29 | 29 | ||
| 30 | protected TokenChecker(JarFile jarFile) throws IOException { | 30 | protected TokenChecker(JarFile jarFile) |
| 31 | throws IOException { | ||
| 31 | m_deobfuscator = new Deobfuscator(jarFile); | 32 | m_deobfuscator = new Deobfuscator(jarFile); |
| 32 | } | 33 | } |
| 33 | 34 | ||
diff --git a/test/cuchaz/enigma/inputs/translation/A.java b/test/cuchaz/enigma/inputs/translation/A.java new file mode 100644 index 0000000..b8aaf11 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/A.java | |||
| @@ -0,0 +1,8 @@ | |||
| 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/resources/translation.mappings b/test/cuchaz/enigma/resources/translation.mappings new file mode 100644 index 0000000..70755bf --- /dev/null +++ b/test/cuchaz/enigma/resources/translation.mappings | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | CLASS none/a deobf/A | ||
| 2 | FIELD a one | ||
| 3 | FIELD b two | ||
| 4 | FIELD c three \ No newline at end of file | ||