diff options
Diffstat (limited to 'src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java')
| -rw-r--r-- | src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java | 93 |
1 files changed, 50 insertions, 43 deletions
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java index b4529dd..1299bcc 100644 --- a/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java | |||
| @@ -12,12 +12,19 @@ | |||
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.analysis.*; | 14 | import cuchaz.enigma.analysis.*; |
| 15 | import cuchaz.enigma.mapping.*; | 15 | import cuchaz.enigma.analysis.index.EntryIndex; |
| 16 | import cuchaz.enigma.mapping.entry.*; | 16 | import cuchaz.enigma.analysis.index.InheritanceIndex; |
| 17 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 18 | import cuchaz.enigma.translation.VoidTranslator; | ||
| 19 | import cuchaz.enigma.translation.representation.AccessFlags; | ||
| 20 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 21 | import cuchaz.enigma.translation.representation.entry.FieldEntry; | ||
| 22 | import cuchaz.enigma.translation.representation.entry.MethodDefEntry; | ||
| 23 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | ||
| 17 | import org.junit.Test; | 24 | import org.junit.Test; |
| 18 | 25 | ||
| 19 | import java.util.Collection; | 26 | import java.util.Collection; |
| 20 | import java.util.Set; | 27 | import java.util.List; |
| 21 | import java.util.jar.JarFile; | 28 | import java.util.jar.JarFile; |
| 22 | 29 | ||
| 23 | import static cuchaz.enigma.TestEntryFactory.*; | 30 | import static cuchaz.enigma.TestEntryFactory.*; |
| @@ -30,13 +37,13 @@ public class TestJarIndexLoneClass { | |||
| 30 | 37 | ||
| 31 | public TestJarIndexLoneClass() | 38 | public TestJarIndexLoneClass() |
| 32 | throws Exception { | 39 | throws Exception { |
| 33 | index = new JarIndex(new ReferencedEntryPool()); | 40 | index = JarIndex.empty(); |
| 34 | index.indexJar(new ParsedJar(new JarFile("build/test-obf/loneClass.jar")), false); | 41 | index.indexJar(new ParsedJar(new JarFile("build/test-obf/loneClass.jar")), s -> {}); |
| 35 | } | 42 | } |
| 36 | 43 | ||
| 37 | @Test | 44 | @Test |
| 38 | public void obfEntries() { | 45 | public void obfEntries() { |
| 39 | assertThat(index.getObfClassEntries(), containsInAnyOrder( | 46 | assertThat(index.getEntryIndex().getClasses(), containsInAnyOrder( |
| 40 | newClass("cuchaz/enigma/inputs/Keep"), | 47 | newClass("cuchaz/enigma/inputs/Keep"), |
| 41 | newClass("a") | 48 | newClass("a") |
| 42 | )); | 49 | )); |
| @@ -44,25 +51,28 @@ public class TestJarIndexLoneClass { | |||
| 44 | 51 | ||
| 45 | @Test | 52 | @Test |
| 46 | public void translationIndex() { | 53 | public void translationIndex() { |
| 47 | assertThat(index.getTranslationIndex().getSuperclass(new ClassEntry("a")), is(new ClassEntry("java/lang/Object"))); | 54 | InheritanceIndex inheritanceIndex = index.getInheritanceIndex(); |
| 48 | assertThat(index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(new ClassEntry("java/lang/Object"))); | 55 | assertThat(inheritanceIndex.getParents(new ClassEntry("a")), is(empty())); |
| 49 | assertThat(index.getTranslationIndex().getAncestry(new ClassEntry("a")), contains(new ClassEntry("java/lang/Object"))); | 56 | assertThat(inheritanceIndex.getParents(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); |
| 50 | assertThat(index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), contains(new ClassEntry("java/lang/Object"))); | 57 | assertThat(inheritanceIndex.getAncestors(new ClassEntry("a")), is(empty())); |
| 51 | assertThat(index.getTranslationIndex().getSubclass(new ClassEntry("a")), is(empty())); | 58 | assertThat(inheritanceIndex.getAncestors(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); |
| 52 | assertThat(index.getTranslationIndex().getSubclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); | 59 | assertThat(inheritanceIndex.getChildren(new ClassEntry("a")), is(empty())); |
| 60 | assertThat(inheritanceIndex.getChildren(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); | ||
| 53 | } | 61 | } |
| 54 | 62 | ||
| 55 | @Test | 63 | @Test |
| 56 | public void access() { | 64 | public void access() { |
| 57 | assertThat(index.getAccess(newField("a", "a", "Ljava/lang/String;")), is(Access.PRIVATE)); | 65 | EntryIndex entryIndex = index.getEntryIndex(); |
| 58 | assertThat(index.getAccess(newMethod("a", "a", "()Ljava/lang/String;")), is(Access.PUBLIC)); | 66 | assertThat(entryIndex.getFieldAccess(newField("a", "a", "Ljava/lang/String;")), is(AccessFlags.PRIVATE)); |
| 59 | assertThat(index.getAccess(newField("a", "b", "Ljava/lang/String;")), is(nullValue())); | 67 | assertThat(entryIndex.getMethodAccess(newMethod("a", "a", "()Ljava/lang/String;")), is(AccessFlags.PUBLIC)); |
| 60 | assertThat(index.getAccess(newField("a", "a", "LFoo;")), is(nullValue())); | 68 | assertThat(entryIndex.getFieldAccess(newField("a", "b", "Ljava/lang/String;")), is(nullValue())); |
| 69 | assertThat(entryIndex.getFieldAccess(newField("a", "a", "LFoo;")), is(nullValue())); | ||
| 61 | } | 70 | } |
| 62 | 71 | ||
| 63 | @Test | 72 | @Test |
| 64 | public void classInheritance() { | 73 | public void classInheritance() { |
| 65 | ClassInheritanceTreeNode node = index.getClassInheritance(new DirectionalTranslator(new ReferencedEntryPool()), newClass("a")); | 74 | IndexTreeBuilder treeBuilder = new IndexTreeBuilder(index); |
| 75 | ClassInheritanceTreeNode node = treeBuilder.buildClassInheritance(VoidTranslator.INSTANCE, newClass("a")); | ||
| 66 | assertThat(node, is(not(nullValue()))); | 76 | assertThat(node, is(not(nullValue()))); |
| 67 | assertThat(node.getObfClassName(), is("a")); | 77 | assertThat(node.getObfClassName(), is("a")); |
| 68 | assertThat(node.getChildCount(), is(0)); | 78 | assertThat(node.getChildCount(), is(0)); |
| @@ -70,8 +80,9 @@ public class TestJarIndexLoneClass { | |||
| 70 | 80 | ||
| 71 | @Test | 81 | @Test |
| 72 | public void methodInheritance() { | 82 | public void methodInheritance() { |
| 83 | IndexTreeBuilder treeBuilder = new IndexTreeBuilder(index); | ||
| 73 | MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;"); | 84 | MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;"); |
| 74 | MethodInheritanceTreeNode node = index.getMethodInheritance(new DirectionalTranslator(new ReferencedEntryPool()), source); | 85 | MethodInheritanceTreeNode node = treeBuilder.buildMethodInheritance(VoidTranslator.INSTANCE, source); |
| 75 | assertThat(node, is(not(nullValue()))); | 86 | assertThat(node, is(not(nullValue()))); |
| 76 | assertThat(node.getMethodEntry(), is(source)); | 87 | assertThat(node.getMethodEntry(), is(source)); |
| 77 | assertThat(node.getChildCount(), is(0)); | 88 | assertThat(node.getChildCount(), is(0)); |
| @@ -79,19 +90,24 @@ public class TestJarIndexLoneClass { | |||
| 79 | 90 | ||
| 80 | @Test | 91 | @Test |
| 81 | public void classImplementations() { | 92 | public void classImplementations() { |
| 82 | ClassImplementationsTreeNode node = index.getClassImplementations(new DirectionalTranslator(new ReferencedEntryPool()), newClass("a")); | 93 | IndexTreeBuilder treeBuilder = new IndexTreeBuilder(index); |
| 94 | ClassImplementationsTreeNode node = treeBuilder.buildClassImplementations(VoidTranslator.INSTANCE, newClass("a")); | ||
| 83 | assertThat(node, is(nullValue())); | 95 | assertThat(node, is(nullValue())); |
| 84 | } | 96 | } |
| 85 | 97 | ||
| 86 | @Test | 98 | @Test |
| 87 | public void methodImplementations() { | 99 | public void methodImplementations() { |
| 100 | IndexTreeBuilder treeBuilder = new IndexTreeBuilder(index); | ||
| 88 | MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;"); | 101 | MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;"); |
| 89 | assertThat(index.getMethodImplementations(new DirectionalTranslator(new ReferencedEntryPool()), source), is(empty())); | 102 | |
| 103 | List<MethodImplementationsTreeNode> nodes = treeBuilder.buildMethodImplementations(VoidTranslator.INSTANCE, source); | ||
| 104 | assertThat(nodes, hasSize(1)); | ||
| 105 | assertThat(nodes.get(0).getMethodEntry(), is(source)); | ||
| 90 | } | 106 | } |
| 91 | 107 | ||
| 92 | @Test | 108 | @Test |
| 93 | public void relatedMethodImplementations() { | 109 | public void relatedMethodImplementations() { |
| 94 | Set<MethodEntry> entries = index.getRelatedMethodImplementations(newMethod("a", "a", "()Ljava/lang/String;")); | 110 | Collection<MethodEntry> entries = index.getEntryResolver().resolveEquivalentMethods(newMethod("a", "a", "()Ljava/lang/String;")); |
| 95 | assertThat(entries, containsInAnyOrder( | 111 | assertThat(entries, containsInAnyOrder( |
| 96 | newMethod("a", "a", "()Ljava/lang/String;") | 112 | newMethod("a", "a", "()Ljava/lang/String;") |
| 97 | )); | 113 | )); |
| @@ -101,7 +117,7 @@ public class TestJarIndexLoneClass { | |||
| 101 | @SuppressWarnings("unchecked") | 117 | @SuppressWarnings("unchecked") |
| 102 | public void fieldReferences() { | 118 | public void fieldReferences() { |
| 103 | FieldEntry source = newField("a", "a", "Ljava/lang/String;"); | 119 | FieldEntry source = newField("a", "a", "Ljava/lang/String;"); |
| 104 | Collection<EntryReference<FieldEntry, MethodDefEntry>> references = index.getFieldReferences(source); | 120 | Collection<EntryReference<FieldEntry, MethodDefEntry>> references = index.getReferenceIndex().getReferencesToField(source); |
| 105 | assertThat(references, containsInAnyOrder( | 121 | assertThat(references, containsInAnyOrder( |
| 106 | newFieldReferenceByMethod(source, "a", "<init>", "(Ljava/lang/String;)V"), | 122 | newFieldReferenceByMethod(source, "a", "<init>", "(Ljava/lang/String;)V"), |
| 107 | newFieldReferenceByMethod(source, "a", "a", "()Ljava/lang/String;") | 123 | newFieldReferenceByMethod(source, "a", "a", "()Ljava/lang/String;") |
| @@ -110,42 +126,33 @@ public class TestJarIndexLoneClass { | |||
| 110 | 126 | ||
| 111 | @Test | 127 | @Test |
| 112 | public void behaviorReferences() { | 128 | public void behaviorReferences() { |
| 113 | assertThat(index.getMethodsReferencing(newMethod("a", "a", "()Ljava/lang/String;")), is(empty())); | 129 | assertThat(index.getReferenceIndex().getReferencesToMethod(newMethod("a", "a", "()Ljava/lang/String;")), is(empty())); |
| 114 | } | ||
| 115 | |||
| 116 | @Test | ||
| 117 | public void innerClasses() { | ||
| 118 | assertThat(index.getInnerClasses(newClass("a")), is(empty())); | ||
| 119 | } | ||
| 120 | |||
| 121 | @Test | ||
| 122 | public void outerClass() { | ||
| 123 | assertThat(index.getOuterClass(newClass("a")), is(nullValue())); | ||
| 124 | } | 130 | } |
| 125 | 131 | ||
| 126 | @Test | 132 | @Test |
| 127 | public void interfaces() { | 133 | public void interfaces() { |
| 128 | assertThat(index.getInterfaces("a"), is(empty())); | 134 | assertThat(index.getInheritanceIndex().getParents(new ClassEntry("a")), is(empty())); |
| 129 | } | 135 | } |
| 130 | 136 | ||
| 131 | @Test | 137 | @Test |
| 132 | public void implementingClasses() { | 138 | public void implementingClasses() { |
| 133 | assertThat(index.getImplementingClasses("a"), is(empty())); | 139 | assertThat(index.getInheritanceIndex().getChildren(new ClassEntry("a")), is(empty())); |
| 134 | } | 140 | } |
| 135 | 141 | ||
| 136 | @Test | 142 | @Test |
| 137 | public void isInterface() { | 143 | public void isInterface() { |
| 138 | assertThat(index.isInterface("a"), is(false)); | 144 | assertThat(index.getInheritanceIndex().isParent(new ClassEntry("a")), is(false)); |
| 139 | } | 145 | } |
| 140 | 146 | ||
| 141 | @Test | 147 | @Test |
| 142 | public void testContains() { | 148 | public void testContains() { |
| 143 | assertThat(index.containsObfClass(newClass("a")), is(true)); | 149 | EntryIndex entryIndex = index.getEntryIndex(); |
| 144 | assertThat(index.containsObfClass(newClass("b")), is(false)); | 150 | assertThat(entryIndex.hasClass(newClass("a")), is(true)); |
| 145 | assertThat(index.containsObfField(newField("a", "a", "Ljava/lang/String;")), is(true)); | 151 | assertThat(entryIndex.hasClass(newClass("b")), is(false)); |
| 146 | assertThat(index.containsObfField(newField("a", "b", "Ljava/lang/String;")), is(false)); | 152 | assertThat(entryIndex.hasField(newField("a", "a", "Ljava/lang/String;")), is(true)); |
| 147 | assertThat(index.containsObfField(newField("a", "a", "LFoo;")), is(false)); | 153 | assertThat(entryIndex.hasField(newField("a", "b", "Ljava/lang/String;")), is(false)); |
| 148 | assertThat(index.containsObfMethod(newMethod("a", "a", "()Ljava/lang/String;")), is(true)); | 154 | assertThat(entryIndex.hasField(newField("a", "a", "LFoo;")), is(false)); |
| 149 | assertThat(index.containsObfMethod(newMethod("a", "b", "()Ljava/lang/String;")), is(false)); | 155 | assertThat(entryIndex.hasMethod(newMethod("a", "a", "()Ljava/lang/String;")), is(true)); |
| 156 | assertThat(entryIndex.hasMethod(newMethod("a", "b", "()Ljava/lang/String;")), is(false)); | ||
| 150 | } | 157 | } |
| 151 | } | 158 | } |