diff options
| author | 2017-03-07 21:24:39 +0100 | |
|---|---|---|
| committer | 2017-03-07 21:30:02 +0100 | |
| commit | b4aaff683d78ab92b83f3a7257c33b8e27d1affa (patch) | |
| tree | f23c9bb0927d83cc7302881266b7df8fd37959c7 /src/test | |
| parent | Avoid crash of the matcher when the obf name is invalid (set a deob it using ... (diff) | |
| download | enigma-b4aaff683d78ab92b83f3a7257c33b8e27d1affa.tar.gz enigma-b4aaff683d78ab92b83f3a7257c33b8e27d1affa.tar.xz enigma-b4aaff683d78ab92b83f3a7257c33b8e27d1affa.zip | |
Drop unix case style and implement hashCode when equals is overrided
Also update Guava to version 21
Diffstat (limited to 'src/test')
11 files changed, 228 insertions, 232 deletions
diff --git a/src/test/java/cuchaz/enigma/TestDeobfed.java b/src/test/java/cuchaz/enigma/TestDeobfed.java index 2f318c80..76a3d3b5 100644 --- a/src/test/java/cuchaz/enigma/TestDeobfed.java +++ b/src/test/java/cuchaz/enigma/TestDeobfed.java | |||
| @@ -25,20 +25,20 @@ import cuchaz.enigma.analysis.JarIndex; | |||
| 25 | 25 | ||
| 26 | public class TestDeobfed { | 26 | public class TestDeobfed { |
| 27 | 27 | ||
| 28 | private static JarFile m_jar; | 28 | private static JarFile jar; |
| 29 | private static JarIndex m_index; | 29 | private static JarIndex index; |
| 30 | 30 | ||
| 31 | @BeforeClass | 31 | @BeforeClass |
| 32 | public static void beforeClass() | 32 | public static void beforeClass() |
| 33 | throws Exception { | 33 | throws Exception { |
| 34 | m_jar = new JarFile("build/test-deobf/translation.jar"); | 34 | jar = new JarFile("build/test-deobf/translation.jar"); |
| 35 | m_index = new JarIndex(); | 35 | index = new JarIndex(); |
| 36 | m_index.indexJar(m_jar, true); | 36 | index.indexJar(jar, true); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | @Test | 39 | @Test |
| 40 | public void obfEntries() { | 40 | public void obfEntries() { |
| 41 | assertThat(m_index.getObfClassEntries(), containsInAnyOrder( | 41 | assertThat(index.getObfClassEntries(), containsInAnyOrder( |
| 42 | newClass("cuchaz/enigma/inputs/Keep"), | 42 | newClass("cuchaz/enigma/inputs/Keep"), |
| 43 | newClass("a"), | 43 | newClass("a"), |
| 44 | newClass("b"), | 44 | newClass("b"), |
| @@ -68,7 +68,7 @@ public class TestDeobfed { | |||
| 68 | @Test | 68 | @Test |
| 69 | public void decompile() | 69 | public void decompile() |
| 70 | throws Exception { | 70 | throws Exception { |
| 71 | Deobfuscator deobfuscator = new Deobfuscator(m_jar); | 71 | Deobfuscator deobfuscator = new Deobfuscator(jar); |
| 72 | deobfuscator.getSourceTree("a"); | 72 | deobfuscator.getSourceTree("a"); |
| 73 | deobfuscator.getSourceTree("b"); | 73 | deobfuscator.getSourceTree("b"); |
| 74 | deobfuscator.getSourceTree("c"); | 74 | deobfuscator.getSourceTree("c"); |
diff --git a/src/test/java/cuchaz/enigma/TestInnerClasses.java b/src/test/java/cuchaz/enigma/TestInnerClasses.java index 70765e32..64a695a9 100644 --- a/src/test/java/cuchaz/enigma/TestInnerClasses.java +++ b/src/test/java/cuchaz/enigma/TestInnerClasses.java | |||
| @@ -24,8 +24,8 @@ import cuchaz.enigma.mapping.ClassEntry; | |||
| 24 | 24 | ||
| 25 | public class TestInnerClasses { | 25 | public class TestInnerClasses { |
| 26 | 26 | ||
| 27 | private JarIndex m_index; | 27 | private JarIndex index; |
| 28 | private Deobfuscator m_deobfuscator; | 28 | private Deobfuscator deobfuscator; |
| 29 | 29 | ||
| 30 | private static final ClassEntry AnonymousOuter = newClass("a"); | 30 | private static final ClassEntry AnonymousOuter = newClass("a"); |
| 31 | private static final ClassEntry AnonymousInner = newClass("a$1"); | 31 | private static final ClassEntry AnonymousInner = newClass("a$1"); |
| @@ -44,49 +44,49 @@ public class TestInnerClasses { | |||
| 44 | 44 | ||
| 45 | public TestInnerClasses() | 45 | public TestInnerClasses() |
| 46 | throws Exception { | 46 | throws Exception { |
| 47 | m_index = new JarIndex(); | 47 | index = new JarIndex(); |
| 48 | JarFile jar = new JarFile("build/test-obf/innerClasses.jar"); | 48 | JarFile jar = new JarFile("build/test-obf/innerClasses.jar"); |
| 49 | m_index.indexJar(jar, true); | 49 | index.indexJar(jar, true); |
| 50 | m_deobfuscator = new Deobfuscator(jar); | 50 | deobfuscator = new Deobfuscator(jar); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | @Test | 53 | @Test |
| 54 | public void simple() { | 54 | public void simple() { |
| 55 | assertThat(m_index.getOuterClass(SimpleInner), is(SimpleOuter)); | 55 | assertThat(index.getOuterClass(SimpleInner), is(SimpleOuter)); |
| 56 | assertThat(m_index.getInnerClasses(SimpleOuter), containsInAnyOrder(SimpleInner)); | 56 | assertThat(index.getInnerClasses(SimpleOuter), containsInAnyOrder(SimpleInner)); |
| 57 | assertThat(m_index.isAnonymousClass(SimpleInner), is(false)); | 57 | assertThat(index.isAnonymousClass(SimpleInner), is(false)); |
| 58 | decompile(SimpleOuter); | 58 | decompile(SimpleOuter); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | @Test | 61 | @Test |
| 62 | public void anonymous() { | 62 | public void anonymous() { |
| 63 | assertThat(m_index.getOuterClass(AnonymousInner), is(AnonymousOuter)); | 63 | assertThat(index.getOuterClass(AnonymousInner), is(AnonymousOuter)); |
| 64 | assertThat(m_index.getInnerClasses(AnonymousOuter), containsInAnyOrder(AnonymousInner)); | 64 | assertThat(index.getInnerClasses(AnonymousOuter), containsInAnyOrder(AnonymousInner)); |
| 65 | assertThat(m_index.isAnonymousClass(AnonymousInner), is(true)); | 65 | assertThat(index.isAnonymousClass(AnonymousInner), is(true)); |
| 66 | decompile(AnonymousOuter); | 66 | decompile(AnonymousOuter); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | @Test | 69 | @Test |
| 70 | public void constructorArgs() { | 70 | public void constructorArgs() { |
| 71 | assertThat(m_index.getOuterClass(ConstructorArgsInner), is(ConstructorArgsOuter)); | 71 | assertThat(index.getOuterClass(ConstructorArgsInner), is(ConstructorArgsOuter)); |
| 72 | assertThat(m_index.getInnerClasses(ConstructorArgsOuter), containsInAnyOrder(ConstructorArgsInner)); | 72 | assertThat(index.getInnerClasses(ConstructorArgsOuter), containsInAnyOrder(ConstructorArgsInner)); |
| 73 | assertThat(m_index.isAnonymousClass(ConstructorArgsInner), is(false)); | 73 | assertThat(index.isAnonymousClass(ConstructorArgsInner), is(false)); |
| 74 | decompile(ConstructorArgsOuter); | 74 | decompile(ConstructorArgsOuter); |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | @Test | 77 | @Test |
| 78 | public void anonymousWithScopeArgs() { | 78 | public void anonymousWithScopeArgs() { |
| 79 | assertThat(m_index.getOuterClass(AnonymousWithScopeArgsInner), is(AnonymousWithScopeArgsOuter)); | 79 | assertThat(index.getOuterClass(AnonymousWithScopeArgsInner), is(AnonymousWithScopeArgsOuter)); |
| 80 | assertThat(m_index.getInnerClasses(AnonymousWithScopeArgsOuter), containsInAnyOrder(AnonymousWithScopeArgsInner)); | 80 | assertThat(index.getInnerClasses(AnonymousWithScopeArgsOuter), containsInAnyOrder(AnonymousWithScopeArgsInner)); |
| 81 | assertThat(m_index.isAnonymousClass(AnonymousWithScopeArgsInner), is(true)); | 81 | assertThat(index.isAnonymousClass(AnonymousWithScopeArgsInner), is(true)); |
| 82 | decompile(AnonymousWithScopeArgsOuter); | 82 | decompile(AnonymousWithScopeArgsOuter); |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | @Test | 85 | @Test |
| 86 | public void anonymousWithOuterAccess() { | 86 | public void anonymousWithOuterAccess() { |
| 87 | assertThat(m_index.getOuterClass(AnonymousWithOuterAccessInner), is(AnonymousWithOuterAccessOuter)); | 87 | assertThat(index.getOuterClass(AnonymousWithOuterAccessInner), is(AnonymousWithOuterAccessOuter)); |
| 88 | assertThat(m_index.getInnerClasses(AnonymousWithOuterAccessOuter), containsInAnyOrder(AnonymousWithOuterAccessInner)); | 88 | assertThat(index.getInnerClasses(AnonymousWithOuterAccessOuter), containsInAnyOrder(AnonymousWithOuterAccessInner)); |
| 89 | assertThat(m_index.isAnonymousClass(AnonymousWithOuterAccessInner), is(true)); | 89 | assertThat(index.isAnonymousClass(AnonymousWithOuterAccessInner), is(true)); |
| 90 | decompile(AnonymousWithOuterAccessOuter); | 90 | decompile(AnonymousWithOuterAccessOuter); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| @@ -94,26 +94,26 @@ public class TestInnerClasses { | |||
| 94 | public void classTree() { | 94 | public void classTree() { |
| 95 | 95 | ||
| 96 | // root level | 96 | // root level |
| 97 | assertThat(m_index.containsObfClass(ClassTreeRoot), is(true)); | 97 | assertThat(index.containsObfClass(ClassTreeRoot), is(true)); |
| 98 | assertThat(m_index.getOuterClass(ClassTreeRoot), is(nullValue())); | 98 | assertThat(index.getOuterClass(ClassTreeRoot), is(nullValue())); |
| 99 | assertThat(m_index.getInnerClasses(ClassTreeRoot), containsInAnyOrder(ClassTreeLevel1)); | 99 | assertThat(index.getInnerClasses(ClassTreeRoot), containsInAnyOrder(ClassTreeLevel1)); |
| 100 | 100 | ||
| 101 | // level 1 | 101 | // level 1 |
| 102 | ClassEntry fullClassEntry = new ClassEntry(ClassTreeRoot.getName() | 102 | ClassEntry fullClassEntry = new ClassEntry(ClassTreeRoot.getName() |
| 103 | + "$" + ClassTreeLevel1.getInnermostClassName() | 103 | + "$" + ClassTreeLevel1.getInnermostClassName() |
| 104 | ); | 104 | ); |
| 105 | assertThat(m_index.containsObfClass(fullClassEntry), is(true)); | 105 | assertThat(index.containsObfClass(fullClassEntry), is(true)); |
| 106 | assertThat(m_index.getOuterClass(ClassTreeLevel1), is(ClassTreeRoot)); | 106 | assertThat(index.getOuterClass(ClassTreeLevel1), is(ClassTreeRoot)); |
| 107 | assertThat(m_index.getInnerClasses(ClassTreeLevel1), containsInAnyOrder(ClassTreeLevel2)); | 107 | assertThat(index.getInnerClasses(ClassTreeLevel1), containsInAnyOrder(ClassTreeLevel2)); |
| 108 | 108 | ||
| 109 | // level 2 | 109 | // level 2 |
| 110 | fullClassEntry = new ClassEntry(ClassTreeRoot.getName() | 110 | fullClassEntry = new ClassEntry(ClassTreeRoot.getName() |
| 111 | + "$" + ClassTreeLevel1.getInnermostClassName() | 111 | + "$" + ClassTreeLevel1.getInnermostClassName() |
| 112 | + "$" + ClassTreeLevel2.getInnermostClassName() | 112 | + "$" + ClassTreeLevel2.getInnermostClassName() |
| 113 | ); | 113 | ); |
| 114 | assertThat(m_index.containsObfClass(fullClassEntry), is(true)); | 114 | assertThat(index.containsObfClass(fullClassEntry), is(true)); |
| 115 | assertThat(m_index.getOuterClass(ClassTreeLevel2), is(ClassTreeLevel1)); | 115 | assertThat(index.getOuterClass(ClassTreeLevel2), is(ClassTreeLevel1)); |
| 116 | assertThat(m_index.getInnerClasses(ClassTreeLevel2), containsInAnyOrder(ClassTreeLevel3)); | 116 | assertThat(index.getInnerClasses(ClassTreeLevel2), containsInAnyOrder(ClassTreeLevel3)); |
| 117 | 117 | ||
| 118 | // level 3 | 118 | // level 3 |
| 119 | fullClassEntry = new ClassEntry(ClassTreeRoot.getName() | 119 | fullClassEntry = new ClassEntry(ClassTreeRoot.getName() |
| @@ -121,12 +121,12 @@ public class TestInnerClasses { | |||
| 121 | + "$" + ClassTreeLevel2.getInnermostClassName() | 121 | + "$" + ClassTreeLevel2.getInnermostClassName() |
| 122 | + "$" + ClassTreeLevel3.getInnermostClassName() | 122 | + "$" + ClassTreeLevel3.getInnermostClassName() |
| 123 | ); | 123 | ); |
| 124 | assertThat(m_index.containsObfClass(fullClassEntry), is(true)); | 124 | assertThat(index.containsObfClass(fullClassEntry), is(true)); |
| 125 | assertThat(m_index.getOuterClass(ClassTreeLevel3), is(ClassTreeLevel2)); | 125 | assertThat(index.getOuterClass(ClassTreeLevel3), is(ClassTreeLevel2)); |
| 126 | assertThat(m_index.getInnerClasses(ClassTreeLevel3), is(empty())); | 126 | assertThat(index.getInnerClasses(ClassTreeLevel3), is(empty())); |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | private void decompile(ClassEntry classEntry) { | 129 | private void decompile(ClassEntry classEntry) { |
| 130 | m_deobfuscator.getSourceTree(classEntry.getName()); | 130 | deobfuscator.getSourceTree(classEntry.getName()); |
| 131 | } | 131 | } |
| 132 | } | 132 | } |
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java index cb65cd07..01d4bab6 100644 --- a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java +++ b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java | |||
| @@ -27,98 +27,99 @@ import cuchaz.enigma.mapping.ClassEntry; | |||
| 27 | 27 | ||
| 28 | public class TestJarIndexConstructorReferences { | 28 | public class TestJarIndexConstructorReferences { |
| 29 | 29 | ||
| 30 | private JarIndex m_index; | 30 | private JarIndex index; |
| 31 | 31 | ||
| 32 | private ClassEntry m_baseClass = newClass("a"); | 32 | private ClassEntry baseClass = newClass("a"); |
| 33 | private ClassEntry m_subClass = newClass("d"); | 33 | private ClassEntry subClass = newClass("d"); |
| 34 | private ClassEntry m_subsubClass = newClass("e"); | 34 | private ClassEntry subsubClass = newClass("e"); |
| 35 | private ClassEntry m_defaultClass = newClass("c"); | 35 | private ClassEntry defaultClass = newClass("c"); |
| 36 | private ClassEntry m_callerClass = newClass("b"); | 36 | private ClassEntry callerClass = newClass("b"); |
| 37 | 37 | ||
| 38 | public TestJarIndexConstructorReferences() | 38 | public TestJarIndexConstructorReferences() |
| 39 | throws Exception { | 39 | throws Exception { |
| 40 | File jarFile = new File("build/test-obf/constructors.jar"); | 40 | File jarFile = new File("build/test-obf/constructors.jar"); |
| 41 | m_index = new JarIndex(); | 41 | index = new JarIndex(); |
| 42 | m_index.indexJar(new JarFile(jarFile), false); | 42 | index.indexJar(new JarFile(jarFile), false); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | @Test | 45 | @Test |
| 46 | public void obfEntries() { | 46 | public void obfEntries() { |
| 47 | assertThat(m_index.getObfClassEntries(), containsInAnyOrder(newClass("cuchaz/enigma/inputs/Keep"), m_baseClass, m_subClass, m_subsubClass, m_defaultClass, m_callerClass)); | 47 | assertThat(index.getObfClassEntries(), containsInAnyOrder(newClass("cuchaz/enigma/inputs/Keep"), baseClass, |
| 48 | subClass, subsubClass, defaultClass, callerClass)); | ||
| 48 | } | 49 | } |
| 49 | 50 | ||
| 50 | @Test | 51 | @Test |
| 51 | @SuppressWarnings("unchecked") | 52 | @SuppressWarnings("unchecked") |
| 52 | public void baseDefault() { | 53 | public void baseDefault() { |
| 53 | BehaviorEntry source = newConstructor(m_baseClass, "()V"); | 54 | BehaviorEntry source = newConstructor(baseClass, "()V"); |
| 54 | Collection<EntryReference<BehaviorEntry,BehaviorEntry>> references = m_index.getBehaviorReferences(source); | 55 | Collection<EntryReference<BehaviorEntry,BehaviorEntry>> references = index.getBehaviorReferences(source); |
| 55 | assertThat(references, containsInAnyOrder( | 56 | assertThat(references, containsInAnyOrder( |
| 56 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "a", "()V"), | 57 | newBehaviorReferenceByMethod(source, callerClass.getName(), "a", "()V"), |
| 57 | newBehaviorReferenceByConstructor(source, m_subClass.getName(), "()V"), | 58 | newBehaviorReferenceByConstructor(source, subClass.getName(), "()V"), |
| 58 | newBehaviorReferenceByConstructor(source, m_subClass.getName(), "(III)V") | 59 | newBehaviorReferenceByConstructor(source, subClass.getName(), "(III)V") |
| 59 | )); | 60 | )); |
| 60 | } | 61 | } |
| 61 | 62 | ||
| 62 | @Test | 63 | @Test |
| 63 | @SuppressWarnings("unchecked") | 64 | @SuppressWarnings("unchecked") |
| 64 | public void baseInt() { | 65 | public void baseInt() { |
| 65 | BehaviorEntry source = newConstructor(m_baseClass, "(I)V"); | 66 | BehaviorEntry source = newConstructor(baseClass, "(I)V"); |
| 66 | assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( | 67 | assertThat(index.getBehaviorReferences(source), containsInAnyOrder( |
| 67 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "b", "()V") | 68 | newBehaviorReferenceByMethod(source, callerClass.getName(), "b", "()V") |
| 68 | )); | 69 | )); |
| 69 | } | 70 | } |
| 70 | 71 | ||
| 71 | @Test | 72 | @Test |
| 72 | @SuppressWarnings("unchecked") | 73 | @SuppressWarnings("unchecked") |
| 73 | public void subDefault() { | 74 | public void subDefault() { |
| 74 | BehaviorEntry source = newConstructor(m_subClass, "()V"); | 75 | BehaviorEntry source = newConstructor(subClass, "()V"); |
| 75 | assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( | 76 | assertThat(index.getBehaviorReferences(source), containsInAnyOrder( |
| 76 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "c", "()V"), | 77 | newBehaviorReferenceByMethod(source, callerClass.getName(), "c", "()V"), |
| 77 | newBehaviorReferenceByConstructor(source, m_subClass.getName(), "(I)V") | 78 | newBehaviorReferenceByConstructor(source, subClass.getName(), "(I)V") |
| 78 | )); | 79 | )); |
| 79 | } | 80 | } |
| 80 | 81 | ||
| 81 | @Test | 82 | @Test |
| 82 | @SuppressWarnings("unchecked") | 83 | @SuppressWarnings("unchecked") |
| 83 | public void subInt() { | 84 | public void subInt() { |
| 84 | BehaviorEntry source = newConstructor(m_subClass, "(I)V"); | 85 | BehaviorEntry source = newConstructor(subClass, "(I)V"); |
| 85 | assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( | 86 | assertThat(index.getBehaviorReferences(source), containsInAnyOrder( |
| 86 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "d", "()V"), | 87 | newBehaviorReferenceByMethod(source, callerClass.getName(), "d", "()V"), |
| 87 | newBehaviorReferenceByConstructor(source, m_subClass.getName(), "(II)V"), | 88 | newBehaviorReferenceByConstructor(source, subClass.getName(), "(II)V"), |
| 88 | newBehaviorReferenceByConstructor(source, m_subsubClass.getName(), "(I)V") | 89 | newBehaviorReferenceByConstructor(source, subsubClass.getName(), "(I)V") |
| 89 | )); | 90 | )); |
| 90 | } | 91 | } |
| 91 | 92 | ||
| 92 | @Test | 93 | @Test |
| 93 | @SuppressWarnings("unchecked") | 94 | @SuppressWarnings("unchecked") |
| 94 | public void subIntInt() { | 95 | public void subIntInt() { |
| 95 | BehaviorEntry source = newConstructor(m_subClass, "(II)V"); | 96 | BehaviorEntry source = newConstructor(subClass, "(II)V"); |
| 96 | assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( | 97 | assertThat(index.getBehaviorReferences(source), containsInAnyOrder( |
| 97 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "e", "()V") | 98 | newBehaviorReferenceByMethod(source, callerClass.getName(), "e", "()V") |
| 98 | )); | 99 | )); |
| 99 | } | 100 | } |
| 100 | 101 | ||
| 101 | @Test | 102 | @Test |
| 102 | public void subIntIntInt() { | 103 | public void subIntIntInt() { |
| 103 | BehaviorEntry source = newConstructor(m_subClass, "(III)V"); | 104 | BehaviorEntry source = newConstructor(subClass, "(III)V"); |
| 104 | assertThat(m_index.getBehaviorReferences(source), is(empty())); | 105 | assertThat(index.getBehaviorReferences(source), is(empty())); |
| 105 | } | 106 | } |
| 106 | 107 | ||
| 107 | @Test | 108 | @Test |
| 108 | @SuppressWarnings("unchecked") | 109 | @SuppressWarnings("unchecked") |
| 109 | public void subsubInt() { | 110 | public void subsubInt() { |
| 110 | BehaviorEntry source = newConstructor(m_subsubClass, "(I)V"); | 111 | BehaviorEntry source = newConstructor(subsubClass, "(I)V"); |
| 111 | assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( | 112 | assertThat(index.getBehaviorReferences(source), containsInAnyOrder( |
| 112 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "f", "()V") | 113 | newBehaviorReferenceByMethod(source, callerClass.getName(), "f", "()V") |
| 113 | )); | 114 | )); |
| 114 | } | 115 | } |
| 115 | 116 | ||
| 116 | @Test | 117 | @Test |
| 117 | @SuppressWarnings("unchecked") | 118 | @SuppressWarnings("unchecked") |
| 118 | public void defaultConstructable() { | 119 | public void defaultConstructable() { |
| 119 | BehaviorEntry source = newConstructor(m_defaultClass, "()V"); | 120 | BehaviorEntry source = newConstructor(defaultClass, "()V"); |
| 120 | assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( | 121 | assertThat(index.getBehaviorReferences(source), containsInAnyOrder( |
| 121 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "g", "()V") | 122 | newBehaviorReferenceByMethod(source, callerClass.getName(), "g", "()V") |
| 122 | )); | 123 | )); |
| 123 | } | 124 | } |
| 124 | } | 125 | } |
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java b/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java index 28408f2a..4d9c8dc1 100644 --- a/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java +++ b/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java | |||
| @@ -41,66 +41,60 @@ import cuchaz.enigma.mapping.MethodEntry; | |||
| 41 | 41 | ||
| 42 | public class TestJarIndexInheritanceTree { | 42 | public class TestJarIndexInheritanceTree { |
| 43 | 43 | ||
| 44 | private JarIndex m_index; | 44 | private JarIndex index; |
| 45 | 45 | ||
| 46 | private ClassEntry m_objectClass = newClass("java/lang/Object"); | 46 | private ClassEntry objectClass = newClass("java/lang/Object"); |
| 47 | private ClassEntry m_baseClass = newClass("a"); | 47 | private ClassEntry baseClass = newClass("a"); |
| 48 | private ClassEntry m_subClassA = newClass("b"); | 48 | private ClassEntry subClassA = newClass("b"); |
| 49 | private ClassEntry m_subClassAA = newClass("d"); | 49 | private ClassEntry subClassAA = newClass("d"); |
| 50 | private ClassEntry m_subClassB = newClass("c"); | 50 | private ClassEntry subClassB = newClass("c"); |
| 51 | private FieldEntry m_nameField = newField(m_baseClass, "a", "Ljava/lang/String;"); | 51 | private FieldEntry nameField = newField(baseClass, "a", "Ljava/lang/String;"); |
| 52 | private FieldEntry m_numThingsField = newField(m_subClassB, "a", "I"); | 52 | private FieldEntry numThingsField = newField(subClassB, "a", "I"); |
| 53 | 53 | ||
| 54 | public TestJarIndexInheritanceTree() | 54 | public TestJarIndexInheritanceTree() |
| 55 | throws Exception { | 55 | throws Exception { |
| 56 | m_index = new JarIndex(); | 56 | index = new JarIndex(); |
| 57 | m_index.indexJar(new JarFile("build/test-obf/inheritanceTree.jar"), false); | 57 | index.indexJar(new JarFile("build/test-obf/inheritanceTree.jar"), false); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | @Test | 60 | @Test |
| 61 | public void obfEntries() { | 61 | public void obfEntries() { |
| 62 | assertThat(m_index.getObfClassEntries(), containsInAnyOrder( | 62 | assertThat(index.getObfClassEntries(), containsInAnyOrder( |
| 63 | newClass("cuchaz/enigma/inputs/Keep"), | 63 | newClass("cuchaz/enigma/inputs/Keep"), baseClass, subClassA, subClassAA, subClassB |
| 64 | m_baseClass, | ||
| 65 | m_subClassA, | ||
| 66 | m_subClassAA, | ||
| 67 | m_subClassB | ||
| 68 | )); | 64 | )); |
| 69 | } | 65 | } |
| 70 | 66 | ||
| 71 | @Test | 67 | @Test |
| 72 | public void translationIndex() { | 68 | public void translationIndex() { |
| 73 | 69 | ||
| 74 | TranslationIndex index = m_index.getTranslationIndex(); | 70 | TranslationIndex index = this.index.getTranslationIndex(); |
| 75 | 71 | ||
| 76 | // base class | 72 | // base class |
| 77 | assertThat(index.getSuperclass(m_baseClass), is(m_objectClass)); | 73 | assertThat(index.getSuperclass(baseClass), is(objectClass)); |
| 78 | assertThat(index.getAncestry(m_baseClass), contains(m_objectClass)); | 74 | assertThat(index.getAncestry(baseClass), contains(objectClass)); |
| 79 | assertThat(index.getSubclass(m_baseClass), containsInAnyOrder( | 75 | assertThat(index.getSubclass(baseClass), containsInAnyOrder(subClassA, subClassB |
| 80 | m_subClassA, | ||
| 81 | m_subClassB | ||
| 82 | )); | 76 | )); |
| 83 | 77 | ||
| 84 | // subclass a | 78 | // subclass a |
| 85 | assertThat(index.getSuperclass(m_subClassA), is(m_baseClass)); | 79 | assertThat(index.getSuperclass(subClassA), is(baseClass)); |
| 86 | assertThat(index.getAncestry(m_subClassA), contains(m_baseClass, m_objectClass)); | 80 | assertThat(index.getAncestry(subClassA), contains(baseClass, objectClass)); |
| 87 | assertThat(index.getSubclass(m_subClassA), contains(m_subClassAA)); | 81 | assertThat(index.getSubclass(subClassA), contains(subClassAA)); |
| 88 | 82 | ||
| 89 | // subclass aa | 83 | // subclass aa |
| 90 | assertThat(index.getSuperclass(m_subClassAA), is(m_subClassA)); | 84 | assertThat(index.getSuperclass(subClassAA), is(subClassA)); |
| 91 | assertThat(index.getAncestry(m_subClassAA), contains(m_subClassA, m_baseClass, m_objectClass)); | 85 | assertThat(index.getAncestry(subClassAA), contains(subClassA, baseClass, objectClass)); |
| 92 | assertThat(index.getSubclass(m_subClassAA), is(empty())); | 86 | assertThat(index.getSubclass(subClassAA), is(empty())); |
| 93 | 87 | ||
| 94 | // subclass b | 88 | // subclass b |
| 95 | assertThat(index.getSuperclass(m_subClassB), is(m_baseClass)); | 89 | assertThat(index.getSuperclass(subClassB), is(baseClass)); |
| 96 | assertThat(index.getAncestry(m_subClassB), contains(m_baseClass, m_objectClass)); | 90 | assertThat(index.getAncestry(subClassB), contains(baseClass, objectClass)); |
| 97 | assertThat(index.getSubclass(m_subClassB), is(empty())); | 91 | assertThat(index.getSubclass(subClassB), is(empty())); |
| 98 | } | 92 | } |
| 99 | 93 | ||
| 100 | @Test | 94 | @Test |
| 101 | public void access() { | 95 | public void access() { |
| 102 | assertThat(m_index.getAccess(m_nameField), is(Access.Private)); | 96 | assertThat(index.getAccess(nameField), is(Access.PRIVATE)); |
| 103 | assertThat(m_index.getAccess(m_numThingsField), is(Access.Private)); | 97 | assertThat(index.getAccess(numThingsField), is(Access.PRIVATE)); |
| 104 | } | 98 | } |
| 105 | 99 | ||
| 106 | @Test | 100 | @Test |
| @@ -109,40 +103,40 @@ public class TestJarIndexInheritanceTree { | |||
| 109 | Set<MethodEntry> entries; | 103 | Set<MethodEntry> entries; |
| 110 | 104 | ||
| 111 | // getName() | 105 | // getName() |
| 112 | entries = m_index.getRelatedMethodImplementations(newMethod(m_baseClass, "a", "()Ljava/lang/String;")); | 106 | entries = index.getRelatedMethodImplementations(newMethod(baseClass, "a", "()Ljava/lang/String;")); |
| 113 | assertThat(entries, containsInAnyOrder( | 107 | assertThat(entries, containsInAnyOrder( |
| 114 | newMethod(m_baseClass, "a", "()Ljava/lang/String;"), | 108 | newMethod(baseClass, "a", "()Ljava/lang/String;"), |
| 115 | newMethod(m_subClassAA, "a", "()Ljava/lang/String;") | 109 | newMethod(subClassAA, "a", "()Ljava/lang/String;") |
| 116 | )); | 110 | )); |
| 117 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassAA, "a", "()Ljava/lang/String;")); | 111 | entries = index.getRelatedMethodImplementations(newMethod(subClassAA, "a", "()Ljava/lang/String;")); |
| 118 | assertThat(entries, containsInAnyOrder( | 112 | assertThat(entries, containsInAnyOrder( |
| 119 | newMethod(m_baseClass, "a", "()Ljava/lang/String;"), | 113 | newMethod(baseClass, "a", "()Ljava/lang/String;"), |
| 120 | newMethod(m_subClassAA, "a", "()Ljava/lang/String;") | 114 | newMethod(subClassAA, "a", "()Ljava/lang/String;") |
| 121 | )); | 115 | )); |
| 122 | 116 | ||
| 123 | // doBaseThings() | 117 | // doBaseThings() |
| 124 | entries = m_index.getRelatedMethodImplementations(newMethod(m_baseClass, "a", "()V")); | 118 | entries = index.getRelatedMethodImplementations(newMethod(baseClass, "a", "()V")); |
| 125 | assertThat(entries, containsInAnyOrder( | 119 | assertThat(entries, containsInAnyOrder( |
| 126 | newMethod(m_baseClass, "a", "()V"), | 120 | newMethod(baseClass, "a", "()V"), |
| 127 | newMethod(m_subClassAA, "a", "()V"), | 121 | newMethod(subClassAA, "a", "()V"), |
| 128 | newMethod(m_subClassB, "a", "()V") | 122 | newMethod(subClassB, "a", "()V") |
| 129 | )); | 123 | )); |
| 130 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassAA, "a", "()V")); | 124 | entries = index.getRelatedMethodImplementations(newMethod(subClassAA, "a", "()V")); |
| 131 | assertThat(entries, containsInAnyOrder( | 125 | assertThat(entries, containsInAnyOrder( |
| 132 | newMethod(m_baseClass, "a", "()V"), | 126 | newMethod(baseClass, "a", "()V"), |
| 133 | newMethod(m_subClassAA, "a", "()V"), | 127 | newMethod(subClassAA, "a", "()V"), |
| 134 | newMethod(m_subClassB, "a", "()V") | 128 | newMethod(subClassB, "a", "()V") |
| 135 | )); | 129 | )); |
| 136 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassB, "a", "()V")); | 130 | entries = index.getRelatedMethodImplementations(newMethod(subClassB, "a", "()V")); |
| 137 | assertThat(entries, containsInAnyOrder( | 131 | assertThat(entries, containsInAnyOrder( |
| 138 | newMethod(m_baseClass, "a", "()V"), | 132 | newMethod(baseClass, "a", "()V"), |
| 139 | newMethod(m_subClassAA, "a", "()V"), | 133 | newMethod(subClassAA, "a", "()V"), |
| 140 | newMethod(m_subClassB, "a", "()V") | 134 | newMethod(subClassB, "a", "()V") |
| 141 | )); | 135 | )); |
| 142 | 136 | ||
| 143 | // doBThings | 137 | // doBThings |
| 144 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassB, "b", "()V")); | 138 | entries = index.getRelatedMethodImplementations(newMethod(subClassB, "b", "()V")); |
| 145 | assertThat(entries, containsInAnyOrder(newMethod(m_subClassB, "b", "()V"))); | 139 | assertThat(entries, containsInAnyOrder(newMethod(subClassB, "b", "()V"))); |
| 146 | } | 140 | } |
| 147 | 141 | ||
| 148 | @Test | 142 | @Test |
| @@ -151,17 +145,17 @@ public class TestJarIndexInheritanceTree { | |||
| 151 | Collection<EntryReference<FieldEntry,BehaviorEntry>> references; | 145 | Collection<EntryReference<FieldEntry,BehaviorEntry>> references; |
| 152 | 146 | ||
| 153 | // name | 147 | // name |
| 154 | references = m_index.getFieldReferences(m_nameField); | 148 | references = index.getFieldReferences(nameField); |
| 155 | assertThat(references, containsInAnyOrder( | 149 | assertThat(references, containsInAnyOrder( |
| 156 | newFieldReferenceByConstructor(m_nameField, m_baseClass.getName(), "(Ljava/lang/String;)V"), | 150 | newFieldReferenceByConstructor(nameField, baseClass.getName(), "(Ljava/lang/String;)V"), |
| 157 | newFieldReferenceByMethod(m_nameField, m_baseClass.getName(), "a", "()Ljava/lang/String;") | 151 | newFieldReferenceByMethod(nameField, baseClass.getName(), "a", "()Ljava/lang/String;") |
| 158 | )); | 152 | )); |
| 159 | 153 | ||
| 160 | // numThings | 154 | // numThings |
| 161 | references = m_index.getFieldReferences(m_numThingsField); | 155 | references = index.getFieldReferences(numThingsField); |
| 162 | assertThat(references, containsInAnyOrder( | 156 | assertThat(references, containsInAnyOrder( |
| 163 | newFieldReferenceByConstructor(m_numThingsField, m_subClassB.getName(), "()V"), | 157 | newFieldReferenceByConstructor(numThingsField, subClassB.getName(), "()V"), |
| 164 | newFieldReferenceByMethod(m_numThingsField, m_subClassB.getName(), "b", "()V") | 158 | newFieldReferenceByMethod(numThingsField, subClassB.getName(), "b", "()V") |
| 165 | )); | 159 | )); |
| 166 | } | 160 | } |
| 167 | 161 | ||
| @@ -173,33 +167,33 @@ public class TestJarIndexInheritanceTree { | |||
| 173 | Collection<EntryReference<BehaviorEntry,BehaviorEntry>> references; | 167 | Collection<EntryReference<BehaviorEntry,BehaviorEntry>> references; |
| 174 | 168 | ||
| 175 | // baseClass constructor | 169 | // baseClass constructor |
| 176 | source = newConstructor(m_baseClass, "(Ljava/lang/String;)V"); | 170 | source = newConstructor(baseClass, "(Ljava/lang/String;)V"); |
| 177 | references = m_index.getBehaviorReferences(source); | 171 | references = index.getBehaviorReferences(source); |
| 178 | assertThat(references, containsInAnyOrder( | 172 | assertThat(references, containsInAnyOrder( |
| 179 | newBehaviorReferenceByConstructor(source, m_subClassA.getName(), "(Ljava/lang/String;)V"), | 173 | newBehaviorReferenceByConstructor(source, subClassA.getName(), "(Ljava/lang/String;)V"), |
| 180 | newBehaviorReferenceByConstructor(source, m_subClassB.getName(), "()V") | 174 | newBehaviorReferenceByConstructor(source, subClassB.getName(), "()V") |
| 181 | )); | 175 | )); |
| 182 | 176 | ||
| 183 | // subClassA constructor | 177 | // subClassA constructor |
| 184 | source = newConstructor(m_subClassA, "(Ljava/lang/String;)V"); | 178 | source = newConstructor(subClassA, "(Ljava/lang/String;)V"); |
| 185 | references = m_index.getBehaviorReferences(source); | 179 | references = index.getBehaviorReferences(source); |
| 186 | assertThat(references, containsInAnyOrder( | 180 | assertThat(references, containsInAnyOrder( |
| 187 | newBehaviorReferenceByConstructor(source, m_subClassAA.getName(), "()V") | 181 | newBehaviorReferenceByConstructor(source, subClassAA.getName(), "()V") |
| 188 | )); | 182 | )); |
| 189 | 183 | ||
| 190 | // baseClass.getName() | 184 | // baseClass.getName() |
| 191 | source = newMethod(m_baseClass, "a", "()Ljava/lang/String;"); | 185 | source = newMethod(baseClass, "a", "()Ljava/lang/String;"); |
| 192 | references = m_index.getBehaviorReferences(source); | 186 | references = index.getBehaviorReferences(source); |
| 193 | assertThat(references, containsInAnyOrder( | 187 | assertThat(references, containsInAnyOrder( |
| 194 | newBehaviorReferenceByMethod(source, m_subClassAA.getName(), "a", "()Ljava/lang/String;"), | 188 | newBehaviorReferenceByMethod(source, subClassAA.getName(), "a", "()Ljava/lang/String;"), |
| 195 | newBehaviorReferenceByMethod(source, m_subClassB.getName(), "a", "()V") | 189 | newBehaviorReferenceByMethod(source, subClassB.getName(), "a", "()V") |
| 196 | )); | 190 | )); |
| 197 | 191 | ||
| 198 | // subclassAA.getName() | 192 | // subclassAA.getName() |
| 199 | source = newMethod(m_subClassAA, "a", "()Ljava/lang/String;"); | 193 | source = newMethod(subClassAA, "a", "()Ljava/lang/String;"); |
| 200 | references = m_index.getBehaviorReferences(source); | 194 | references = index.getBehaviorReferences(source); |
| 201 | assertThat(references, containsInAnyOrder( | 195 | assertThat(references, containsInAnyOrder( |
| 202 | newBehaviorReferenceByMethod(source, m_subClassAA.getName(), "a", "()V") | 196 | newBehaviorReferenceByMethod(source, subClassAA.getName(), "a", "()V") |
| 203 | )); | 197 | )); |
| 204 | } | 198 | } |
| 205 | 199 | ||
| @@ -207,33 +201,33 @@ public class TestJarIndexInheritanceTree { | |||
| 207 | public void containsEntries() { | 201 | public void containsEntries() { |
| 208 | 202 | ||
| 209 | // classes | 203 | // classes |
| 210 | assertThat(m_index.containsObfClass(m_baseClass), is(true)); | 204 | assertThat(index.containsObfClass(baseClass), is(true)); |
| 211 | assertThat(m_index.containsObfClass(m_subClassA), is(true)); | 205 | assertThat(index.containsObfClass(subClassA), is(true)); |
| 212 | assertThat(m_index.containsObfClass(m_subClassAA), is(true)); | 206 | assertThat(index.containsObfClass(subClassAA), is(true)); |
| 213 | assertThat(m_index.containsObfClass(m_subClassB), is(true)); | 207 | assertThat(index.containsObfClass(subClassB), is(true)); |
| 214 | 208 | ||
| 215 | // fields | 209 | // fields |
| 216 | assertThat(m_index.containsObfField(m_nameField), is(true)); | 210 | assertThat(index.containsObfField(nameField), is(true)); |
| 217 | assertThat(m_index.containsObfField(m_numThingsField), is(true)); | 211 | assertThat(index.containsObfField(numThingsField), is(true)); |
| 218 | 212 | ||
| 219 | // methods | 213 | // methods |
| 220 | // getName() | 214 | // getName() |
| 221 | assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "a", "()Ljava/lang/String;")), is(true)); | 215 | assertThat(index.containsObfBehavior(newMethod(baseClass, "a", "()Ljava/lang/String;")), is(true)); |
| 222 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "a", "()Ljava/lang/String;")), is(false)); | 216 | assertThat(index.containsObfBehavior(newMethod(subClassA, "a", "()Ljava/lang/String;")), is(false)); |
| 223 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "a", "()Ljava/lang/String;")), is(true)); | 217 | assertThat(index.containsObfBehavior(newMethod(subClassAA, "a", "()Ljava/lang/String;")), is(true)); |
| 224 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "a", "()Ljava/lang/String;")), is(false)); | 218 | assertThat(index.containsObfBehavior(newMethod(subClassB, "a", "()Ljava/lang/String;")), is(false)); |
| 225 | 219 | ||
| 226 | // doBaseThings() | 220 | // doBaseThings() |
| 227 | assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "a", "()V")), is(true)); | 221 | assertThat(index.containsObfBehavior(newMethod(baseClass, "a", "()V")), is(true)); |
| 228 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "a", "()V")), is(false)); | 222 | assertThat(index.containsObfBehavior(newMethod(subClassA, "a", "()V")), is(false)); |
| 229 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "a", "()V")), is(true)); | 223 | assertThat(index.containsObfBehavior(newMethod(subClassAA, "a", "()V")), is(true)); |
| 230 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "a", "()V")), is(true)); | 224 | assertThat(index.containsObfBehavior(newMethod(subClassB, "a", "()V")), is(true)); |
| 231 | 225 | ||
| 232 | // doBThings() | 226 | // doBThings() |
| 233 | assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "b", "()V")), is(false)); | 227 | assertThat(index.containsObfBehavior(newMethod(baseClass, "b", "()V")), is(false)); |
| 234 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "b", "()V")), is(false)); | 228 | assertThat(index.containsObfBehavior(newMethod(subClassA, "b", "()V")), is(false)); |
| 235 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "b", "()V")), is(false)); | 229 | assertThat(index.containsObfBehavior(newMethod(subClassAA, "b", "()V")), is(false)); |
| 236 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "b", "()V")), is(true)); | 230 | assertThat(index.containsObfBehavior(newMethod(subClassB, "b", "()V")), is(true)); |
| 237 | 231 | ||
| 238 | } | 232 | } |
| 239 | } | 233 | } |
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java index 65af6d83..8efa57c6 100644 --- a/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java | |||
| @@ -34,17 +34,17 @@ import cuchaz.enigma.mapping.Translator; | |||
| 34 | 34 | ||
| 35 | public class TestJarIndexLoneClass { | 35 | public class TestJarIndexLoneClass { |
| 36 | 36 | ||
| 37 | private JarIndex m_index; | 37 | private JarIndex index; |
| 38 | 38 | ||
| 39 | public TestJarIndexLoneClass() | 39 | public TestJarIndexLoneClass() |
| 40 | throws Exception { | 40 | throws Exception { |
| 41 | m_index = new JarIndex(); | 41 | index = new JarIndex(); |
| 42 | m_index.indexJar(new JarFile("build/test-obf/loneClass.jar"), false); | 42 | index.indexJar(new JarFile("build/test-obf/loneClass.jar"), false); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | @Test | 45 | @Test |
| 46 | public void obfEntries() { | 46 | public void obfEntries() { |
| 47 | assertThat(m_index.getObfClassEntries(), containsInAnyOrder( | 47 | assertThat(index.getObfClassEntries(), containsInAnyOrder( |
| 48 | newClass("cuchaz/enigma/inputs/Keep"), | 48 | newClass("cuchaz/enigma/inputs/Keep"), |
| 49 | newClass("a") | 49 | newClass("a") |
| 50 | )); | 50 | )); |
| @@ -52,25 +52,25 @@ public class TestJarIndexLoneClass { | |||
| 52 | 52 | ||
| 53 | @Test | 53 | @Test |
| 54 | public void translationIndex() { | 54 | public void translationIndex() { |
| 55 | assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("a")), is(new ClassEntry("java/lang/Object"))); | 55 | assertThat(index.getTranslationIndex().getSuperclass(new ClassEntry("a")), is(new ClassEntry("java/lang/Object"))); |
| 56 | assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(new ClassEntry("java/lang/Object"))); | 56 | assertThat(index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(new ClassEntry("java/lang/Object"))); |
| 57 | assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("a")), contains(new ClassEntry("java/lang/Object"))); | 57 | assertThat(index.getTranslationIndex().getAncestry(new ClassEntry("a")), contains(new ClassEntry("java/lang/Object"))); |
| 58 | assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), contains(new ClassEntry("java/lang/Object"))); | 58 | assertThat(index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), contains(new ClassEntry("java/lang/Object"))); |
| 59 | assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("a")), is(empty())); | 59 | assertThat(index.getTranslationIndex().getSubclass(new ClassEntry("a")), is(empty())); |
| 60 | assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); | 60 | assertThat(index.getTranslationIndex().getSubclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | @Test | 63 | @Test |
| 64 | public void access() { | 64 | public void access() { |
| 65 | assertThat(m_index.getAccess(newField("a", "a", "Ljava/lang/String;")), is(Access.Private)); | 65 | assertThat(index.getAccess(newField("a", "a", "Ljava/lang/String;")), is(Access.PRIVATE)); |
| 66 | assertThat(m_index.getAccess(newMethod("a", "a", "()Ljava/lang/String;")), is(Access.Public)); | 66 | assertThat(index.getAccess(newMethod("a", "a", "()Ljava/lang/String;")), is(Access.PUBLIC)); |
| 67 | assertThat(m_index.getAccess(newField("a", "b", "Ljava/lang/String;")), is(nullValue())); | 67 | assertThat(index.getAccess(newField("a", "b", "Ljava/lang/String;")), is(nullValue())); |
| 68 | assertThat(m_index.getAccess(newField("a", "a", "LFoo;")), is(nullValue())); | 68 | assertThat(index.getAccess(newField("a", "a", "LFoo;")), is(nullValue())); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | @Test | 71 | @Test |
| 72 | public void classInheritance() { | 72 | public void classInheritance() { |
| 73 | ClassInheritanceTreeNode node = m_index.getClassInheritance(new Translator(), newClass("a")); | 73 | ClassInheritanceTreeNode node = index.getClassInheritance(new Translator(), newClass("a")); |
| 74 | assertThat(node, is(not(nullValue()))); | 74 | assertThat(node, is(not(nullValue()))); |
| 75 | assertThat(node.getObfClassName(), is("a")); | 75 | assertThat(node.getObfClassName(), is("a")); |
| 76 | assertThat(node.getChildCount(), is(0)); | 76 | assertThat(node.getChildCount(), is(0)); |
| @@ -79,7 +79,7 @@ public class TestJarIndexLoneClass { | |||
| 79 | @Test | 79 | @Test |
| 80 | public void methodInheritance() { | 80 | public void methodInheritance() { |
| 81 | MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;"); | 81 | MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;"); |
| 82 | MethodInheritanceTreeNode node = m_index.getMethodInheritance(new Translator(), source); | 82 | MethodInheritanceTreeNode node = index.getMethodInheritance(new Translator(), source); |
| 83 | assertThat(node, is(not(nullValue()))); | 83 | assertThat(node, is(not(nullValue()))); |
| 84 | assertThat(node.getMethodEntry(), is(source)); | 84 | assertThat(node.getMethodEntry(), is(source)); |
| 85 | assertThat(node.getChildCount(), is(0)); | 85 | assertThat(node.getChildCount(), is(0)); |
| @@ -87,19 +87,19 @@ public class TestJarIndexLoneClass { | |||
| 87 | 87 | ||
| 88 | @Test | 88 | @Test |
| 89 | public void classImplementations() { | 89 | public void classImplementations() { |
| 90 | ClassImplementationsTreeNode node = m_index.getClassImplementations(new Translator(), newClass("a")); | 90 | ClassImplementationsTreeNode node = index.getClassImplementations(new Translator(), newClass("a")); |
| 91 | assertThat(node, is(nullValue())); | 91 | assertThat(node, is(nullValue())); |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | @Test | 94 | @Test |
| 95 | public void methodImplementations() { | 95 | public void methodImplementations() { |
| 96 | MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;"); | 96 | MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;"); |
| 97 | assertThat(m_index.getMethodImplementations(new Translator(), source), is(empty())); | 97 | assertThat(index.getMethodImplementations(new Translator(), source), is(empty())); |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | @Test | 100 | @Test |
| 101 | public void relatedMethodImplementations() { | 101 | public void relatedMethodImplementations() { |
| 102 | Set<MethodEntry> entries = m_index.getRelatedMethodImplementations(newMethod("a", "a", "()Ljava/lang/String;")); | 102 | Set<MethodEntry> entries = index.getRelatedMethodImplementations(newMethod("a", "a", "()Ljava/lang/String;")); |
| 103 | assertThat(entries, containsInAnyOrder( | 103 | assertThat(entries, containsInAnyOrder( |
| 104 | newMethod("a", "a", "()Ljava/lang/String;") | 104 | newMethod("a", "a", "()Ljava/lang/String;") |
| 105 | )); | 105 | )); |
| @@ -109,7 +109,7 @@ public class TestJarIndexLoneClass { | |||
| 109 | @SuppressWarnings("unchecked") | 109 | @SuppressWarnings("unchecked") |
| 110 | public void fieldReferences() { | 110 | public void fieldReferences() { |
| 111 | FieldEntry source = newField("a", "a", "Ljava/lang/String;"); | 111 | FieldEntry source = newField("a", "a", "Ljava/lang/String;"); |
| 112 | Collection<EntryReference<FieldEntry,BehaviorEntry>> references = m_index.getFieldReferences(source); | 112 | Collection<EntryReference<FieldEntry,BehaviorEntry>> references = index.getFieldReferences(source); |
| 113 | assertThat(references, containsInAnyOrder( | 113 | assertThat(references, containsInAnyOrder( |
| 114 | newFieldReferenceByConstructor(source, "a", "(Ljava/lang/String;)V"), | 114 | newFieldReferenceByConstructor(source, "a", "(Ljava/lang/String;)V"), |
| 115 | newFieldReferenceByMethod(source, "a", "a", "()Ljava/lang/String;") | 115 | newFieldReferenceByMethod(source, "a", "a", "()Ljava/lang/String;") |
| @@ -118,47 +118,47 @@ public class TestJarIndexLoneClass { | |||
| 118 | 118 | ||
| 119 | @Test | 119 | @Test |
| 120 | public void behaviorReferences() { | 120 | public void behaviorReferences() { |
| 121 | assertThat(m_index.getBehaviorReferences(newMethod("a", "a", "()Ljava/lang/String;")), is(empty())); | 121 | assertThat(index.getBehaviorReferences(newMethod("a", "a", "()Ljava/lang/String;")), is(empty())); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | @Test | 124 | @Test |
| 125 | public void innerClasses() { | 125 | public void innerClasses() { |
| 126 | assertThat(m_index.getInnerClasses(newClass("a")), is(empty())); | 126 | assertThat(index.getInnerClasses(newClass("a")), is(empty())); |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | @Test | 129 | @Test |
| 130 | public void outerClass() { | 130 | public void outerClass() { |
| 131 | assertThat(m_index.getOuterClass(newClass("a")), is(nullValue())); | 131 | assertThat(index.getOuterClass(newClass("a")), is(nullValue())); |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | @Test | 134 | @Test |
| 135 | public void isAnonymousClass() { | 135 | public void isAnonymousClass() { |
| 136 | assertThat(m_index.isAnonymousClass(newClass("a")), is(false)); | 136 | assertThat(index.isAnonymousClass(newClass("a")), is(false)); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | @Test | 139 | @Test |
| 140 | public void interfaces() { | 140 | public void interfaces() { |
| 141 | assertThat(m_index.getInterfaces("a"), is(empty())); | 141 | assertThat(index.getInterfaces("a"), is(empty())); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | @Test | 144 | @Test |
| 145 | public void implementingClasses() { | 145 | public void implementingClasses() { |
| 146 | assertThat(m_index.getImplementingClasses("a"), is(empty())); | 146 | assertThat(index.getImplementingClasses("a"), is(empty())); |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | @Test | 149 | @Test |
| 150 | public void isInterface() { | 150 | public void isInterface() { |
| 151 | assertThat(m_index.isInterface("a"), is(false)); | 151 | assertThat(index.isInterface("a"), is(false)); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | @Test | 154 | @Test |
| 155 | public void testContains() { | 155 | public void testContains() { |
| 156 | assertThat(m_index.containsObfClass(newClass("a")), is(true)); | 156 | assertThat(index.containsObfClass(newClass("a")), is(true)); |
| 157 | assertThat(m_index.containsObfClass(newClass("b")), is(false)); | 157 | assertThat(index.containsObfClass(newClass("b")), is(false)); |
| 158 | assertThat(m_index.containsObfField(newField("a", "a", "Ljava/lang/String;")), is(true)); | 158 | assertThat(index.containsObfField(newField("a", "a", "Ljava/lang/String;")), is(true)); |
| 159 | assertThat(m_index.containsObfField(newField("a", "b", "Ljava/lang/String;")), is(false)); | 159 | assertThat(index.containsObfField(newField("a", "b", "Ljava/lang/String;")), is(false)); |
| 160 | assertThat(m_index.containsObfField(newField("a", "a", "LFoo;")), is(false)); | 160 | assertThat(index.containsObfField(newField("a", "a", "LFoo;")), is(false)); |
| 161 | assertThat(m_index.containsObfBehavior(newMethod("a", "a", "()Ljava/lang/String;")), is(true)); | 161 | assertThat(index.containsObfBehavior(newMethod("a", "a", "()Ljava/lang/String;")), is(true)); |
| 162 | assertThat(m_index.containsObfBehavior(newMethod("a", "b", "()Ljava/lang/String;")), is(false)); | 162 | assertThat(index.containsObfBehavior(newMethod("a", "b", "()Ljava/lang/String;")), is(false)); |
| 163 | } | 163 | } |
| 164 | } | 164 | } |
diff --git a/src/test/java/cuchaz/enigma/TestTranslator.java b/src/test/java/cuchaz/enigma/TestTranslator.java index c8af307b..2c54603b 100644 --- a/src/test/java/cuchaz/enigma/TestTranslator.java +++ b/src/test/java/cuchaz/enigma/TestTranslator.java | |||
| @@ -22,21 +22,21 @@ import cuchaz.enigma.mapping.Translator; | |||
| 22 | 22 | ||
| 23 | public class TestTranslator { | 23 | public class TestTranslator { |
| 24 | 24 | ||
| 25 | private static Deobfuscator m_deobfuscator; | 25 | private static Deobfuscator deobfuscator; |
| 26 | private static Mappings m_mappings; | 26 | private static Mappings mappings; |
| 27 | private static Translator m_deobfTranslator; | 27 | private static Translator deobfTranslator; |
| 28 | private static Translator m_obfTranslator; | 28 | private static Translator obfTranslator; |
| 29 | 29 | ||
| 30 | @BeforeClass | 30 | @BeforeClass |
| 31 | public static void beforeClass() | 31 | public static void beforeClass() |
| 32 | throws Exception { | 32 | throws Exception { |
| 33 | //TODO FIx | 33 | //TODO FIx |
| 34 | //m_deobfuscator = new Deobfuscator(new JarFile("build/test-obf/translation.jar")); | 34 | //deobfuscator = new Deobfuscator(new JarFile("build/test-obf/translation.jar")); |
| 35 | //try (InputStream in = TestTranslator.class.getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { | 35 | //try (InputStream in = TestTranslator.class.getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { |
| 36 | // m_mappings = new MappingsJsonReader().read(new InputStreamReader(in)); | 36 | // mappings = new MappingsJsonReader().read(new InputStreamReader(in)); |
| 37 | // m_deobfuscator.setMappings(m_mappings); | 37 | // deobfuscator.setMappings(mappings); |
| 38 | // m_deobfTranslator = m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating); | 38 | // deobfTranslator = deobfuscator.getTranslator(TranslationDirection.Deobfuscating); |
| 39 | // m_obfTranslator = m_deobfuscator.getTranslator(TranslationDirection.Obfuscating); | 39 | // obfTranslator = deobfuscator.getTranslator(TranslationDirection.Obfuscating); |
| 40 | //} | 40 | //} |
| 41 | } | 41 | } |
| 42 | 42 | ||
| @@ -147,15 +147,15 @@ public class TestTranslator { | |||
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | private void assertMapping(Entry obf, Entry deobf) { | 149 | private void assertMapping(Entry obf, Entry deobf) { |
| 150 | //assertThat(m_deobfTranslator.translateEntry(obf), is(deobf)); | 150 | //assertThat(deobfTranslator.translateEntry(obf), is(deobf)); |
| 151 | //assertThat(m_obfTranslator.translateEntry(deobf), is(obf)); | 151 | //assertThat(obfTranslator.translateEntry(deobf), is(obf)); |
| 152 | 152 | ||
| 153 | //String deobfName = m_deobfTranslator.translate(obf); | 153 | //String deobfName = deobfTranslator.translate(obf); |
| 154 | //if (deobfName != null) { | 154 | //if (deobfName != null) { |
| 155 | // assertThat(deobfName, is(deobf.getName())); | 155 | // assertThat(deobfName, is(deobf.getName())); |
| 156 | //} | 156 | //} |
| 157 | 157 | ||
| 158 | //String obfName = m_obfTranslator.translate(deobf); | 158 | //String obfName = obfTranslator.translate(deobf); |
| 159 | //if (obfName != null) { | 159 | //if (obfName != null) { |
| 160 | // assertThat(obfName, is(obf.getName())); | 160 | // assertThat(obfName, is(obf.getName())); |
| 161 | //} | 161 | //} |
diff --git a/src/test/java/cuchaz/enigma/TokenChecker.java b/src/test/java/cuchaz/enigma/TokenChecker.java index 7afb4cfe..07463206 100644 --- a/src/test/java/cuchaz/enigma/TokenChecker.java +++ b/src/test/java/cuchaz/enigma/TokenChecker.java | |||
| @@ -25,20 +25,20 @@ import cuchaz.enigma.mapping.Entry; | |||
| 25 | 25 | ||
| 26 | public class TokenChecker { | 26 | public class TokenChecker { |
| 27 | 27 | ||
| 28 | private Deobfuscator m_deobfuscator; | 28 | private Deobfuscator deobfuscator; |
| 29 | 29 | ||
| 30 | protected TokenChecker(JarFile jarFile) | 30 | protected TokenChecker(JarFile jarFile) |
| 31 | throws IOException { | 31 | throws IOException { |
| 32 | m_deobfuscator = new Deobfuscator(jarFile); | 32 | deobfuscator = new Deobfuscator(jarFile); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | protected String getDeclarationToken(Entry entry) { | 35 | protected String getDeclarationToken(Entry entry) { |
| 36 | // decompile the class | 36 | // decompile the class |
| 37 | CompilationUnit tree = m_deobfuscator.getSourceTree(entry.getClassName()); | 37 | CompilationUnit tree = deobfuscator.getSourceTree(entry.getClassName()); |
| 38 | // DEBUG | 38 | // DEBUG |
| 39 | // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); | 39 | // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); |
| 40 | String source = m_deobfuscator.getSource(tree); | 40 | String source = deobfuscator.getSource(tree); |
| 41 | SourceIndex index = m_deobfuscator.getSourceIndex(tree, source); | 41 | SourceIndex index = deobfuscator.getSourceIndex(tree, source); |
| 42 | 42 | ||
| 43 | // get the token value | 43 | // get the token value |
| 44 | Token token = index.getDeclarationToken(entry); | 44 | Token token = index.getDeclarationToken(entry); |
| @@ -51,9 +51,9 @@ public class TokenChecker { | |||
| 51 | @SuppressWarnings("unchecked") | 51 | @SuppressWarnings("unchecked") |
| 52 | protected Collection<String> getReferenceTokens(EntryReference<? extends Entry,? extends Entry> reference) { | 52 | protected Collection<String> getReferenceTokens(EntryReference<? extends Entry,? extends Entry> reference) { |
| 53 | // decompile the class | 53 | // decompile the class |
| 54 | CompilationUnit tree = m_deobfuscator.getSourceTree(reference.context.getClassName()); | 54 | CompilationUnit tree = deobfuscator.getSourceTree(reference.context.getClassName()); |
| 55 | String source = m_deobfuscator.getSource(tree); | 55 | String source = deobfuscator.getSource(tree); |
| 56 | SourceIndex index = m_deobfuscator.getSourceIndex(tree, source); | 56 | SourceIndex index = deobfuscator.getSourceIndex(tree, source); |
| 57 | 57 | ||
| 58 | // get the token values | 58 | // get the token values |
| 59 | List<String> values = Lists.newArrayList(); | 59 | List<String> values = Lists.newArrayList(); |
diff --git a/src/test/java/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java b/src/test/java/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java index d676ba24..1b1f3694 100644 --- a/src/test/java/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java +++ b/src/test/java/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java | |||
| @@ -14,16 +14,16 @@ package cuchaz.enigma.inputs.inheritanceTree; | |||
| 14 | public abstract class BaseClass { | 14 | public abstract class BaseClass { |
| 15 | 15 | ||
| 16 | // a | 16 | // a |
| 17 | private String m_name; | 17 | private String name; |
| 18 | 18 | ||
| 19 | // <init>(Ljava/lang/String;)V | 19 | // <init>(Ljava/lang/String;)V |
| 20 | protected BaseClass(String name) { | 20 | protected BaseClass(String name) { |
| 21 | m_name = name; | 21 | this.name = name; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | // a()Ljava/lang/String; | 24 | // a()Ljava/lang/String; |
| 25 | public String getName() { | 25 | public String getName() { |
| 26 | return m_name; | 26 | return name; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | // a()V | 29 | // a()V |
diff --git a/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java b/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java index 751fdd16..6d3b0d0f 100644 --- a/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java +++ b/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java | |||
| @@ -14,7 +14,7 @@ package cuchaz.enigma.inputs.inheritanceTree; | |||
| 14 | public class SubclassB extends BaseClass { | 14 | public class SubclassB extends BaseClass { |
| 15 | 15 | ||
| 16 | // a | 16 | // a |
| 17 | private int m_numThings; | 17 | private int numThings; |
| 18 | 18 | ||
| 19 | // <init>()V | 19 | // <init>()V |
| 20 | protected SubclassB() { | 20 | protected SubclassB() { |
| @@ -22,7 +22,7 @@ public class SubclassB extends BaseClass { | |||
| 22 | super("B"); | 22 | super("B"); |
| 23 | 23 | ||
| 24 | // access to a | 24 | // access to a |
| 25 | m_numThings = 4; | 25 | numThings = 4; |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | @Override | 28 | @Override |
| @@ -35,6 +35,6 @@ public class SubclassB extends BaseClass { | |||
| 35 | // b()V | 35 | // b()V |
| 36 | public void doBThings() { | 36 | public void doBThings() { |
| 37 | // access to a | 37 | // access to a |
| 38 | System.out.println("" + m_numThings + " B things!"); | 38 | System.out.println("" + numThings + " B things!"); |
| 39 | } | 39 | } |
| 40 | } | 40 | } |
diff --git a/src/test/java/cuchaz/enigma/inputs/loneClass/LoneClass.java b/src/test/java/cuchaz/enigma/inputs/loneClass/LoneClass.java index bf264fa5..d28ae97c 100644 --- a/src/test/java/cuchaz/enigma/inputs/loneClass/LoneClass.java +++ b/src/test/java/cuchaz/enigma/inputs/loneClass/LoneClass.java | |||
| @@ -12,13 +12,13 @@ package cuchaz.enigma.inputs.loneClass; | |||
| 12 | 12 | ||
| 13 | public class LoneClass { | 13 | public class LoneClass { |
| 14 | 14 | ||
| 15 | private String m_name; | 15 | private String name; |
| 16 | 16 | ||
| 17 | public LoneClass(String name) { | 17 | public LoneClass(String name) { |
| 18 | m_name = name; | 18 | this.name = name; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | public String getName() { | 21 | public String getName() { |
| 22 | return m_name; | 22 | return name; |
| 23 | } | 23 | } |
| 24 | } | 24 | } |
diff --git a/src/test/java/cuchaz/enigma/inputs/translation/F_ObjectMethods.java b/src/test/java/cuchaz/enigma/inputs/translation/F_ObjectMethods.java index 32c246cb..845d62b0 100644 --- a/src/test/java/cuchaz/enigma/inputs/translation/F_ObjectMethods.java +++ b/src/test/java/cuchaz/enigma/inputs/translation/F_ObjectMethods.java | |||
| @@ -10,6 +10,7 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.inputs.translation; | 11 | package cuchaz.enigma.inputs.translation; |
| 12 | 12 | ||
| 13 | @SuppressWarnings("FinalizeCalledExplicitly") | ||
| 13 | public class F_ObjectMethods { | 14 | public class F_ObjectMethods { |
| 14 | 15 | ||
| 15 | public void callEmAll() | 16 | public void callEmAll() |