diff options
| author | 2016-06-30 00:49:21 +1000 | |
|---|---|---|
| committer | 2016-06-30 00:49:21 +1000 | |
| commit | 4be005617b3b8c3578cca07c5d085d12916f0d1d (patch) | |
| tree | db163431f38703e26da417ef05eaea2b27a498b9 /test/cuchaz/enigma/TestJarIndexInheritanceTree.java | |
| parent | Some small changes to fix idea importing (diff) | |
| download | enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.tar.gz enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.tar.xz enigma-fork-4be005617b3b8c3578cca07c5d085d12916f0d1d.zip | |
Json format (#2)
* Added new format
* Fixed bug
* Updated Version
Diffstat (limited to 'test/cuchaz/enigma/TestJarIndexInheritanceTree.java')
| -rw-r--r-- | test/cuchaz/enigma/TestJarIndexInheritanceTree.java | 239 |
1 files changed, 0 insertions, 239 deletions
diff --git a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java deleted file mode 100644 index 84d2115..0000000 --- a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java +++ /dev/null | |||
| @@ -1,239 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByConstructor; | ||
| 14 | import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod; | ||
| 15 | import static cuchaz.enigma.TestEntryFactory.newClass; | ||
| 16 | import static cuchaz.enigma.TestEntryFactory.newConstructor; | ||
| 17 | import static cuchaz.enigma.TestEntryFactory.newField; | ||
| 18 | import static cuchaz.enigma.TestEntryFactory.newFieldReferenceByConstructor; | ||
| 19 | import static cuchaz.enigma.TestEntryFactory.newFieldReferenceByMethod; | ||
| 20 | import static cuchaz.enigma.TestEntryFactory.newMethod; | ||
| 21 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 22 | import static org.hamcrest.Matchers.contains; | ||
| 23 | import static org.hamcrest.Matchers.containsInAnyOrder; | ||
| 24 | import static org.hamcrest.Matchers.empty; | ||
| 25 | import static org.hamcrest.Matchers.is; | ||
| 26 | |||
| 27 | import java.util.Collection; | ||
| 28 | import java.util.Set; | ||
| 29 | import java.util.jar.JarFile; | ||
| 30 | |||
| 31 | import org.junit.Test; | ||
| 32 | |||
| 33 | import cuchaz.enigma.analysis.Access; | ||
| 34 | import cuchaz.enigma.analysis.EntryReference; | ||
| 35 | import cuchaz.enigma.analysis.JarIndex; | ||
| 36 | import cuchaz.enigma.analysis.TranslationIndex; | ||
| 37 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 38 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 39 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 40 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 41 | |||
| 42 | public class TestJarIndexInheritanceTree { | ||
| 43 | |||
| 44 | private JarIndex m_index; | ||
| 45 | |||
| 46 | private ClassEntry m_objectClass = newClass("java/lang/Object"); | ||
| 47 | private ClassEntry m_baseClass = newClass("none/a"); | ||
| 48 | private ClassEntry m_subClassA = newClass("none/b"); | ||
| 49 | private ClassEntry m_subClassAA = newClass("none/d"); | ||
| 50 | private ClassEntry m_subClassB = newClass("none/c"); | ||
| 51 | private FieldEntry m_nameField = newField(m_baseClass, "a", "Ljava/lang/String;"); | ||
| 52 | private FieldEntry m_numThingsField = newField(m_subClassB, "a", "I"); | ||
| 53 | |||
| 54 | public TestJarIndexInheritanceTree() | ||
| 55 | throws Exception { | ||
| 56 | m_index = new JarIndex(); | ||
| 57 | m_index.indexJar(new JarFile("build/test-obf/inheritanceTree.jar"), false); | ||
| 58 | } | ||
| 59 | |||
| 60 | @Test | ||
| 61 | public void obfEntries() { | ||
| 62 | assertThat(m_index.getObfClassEntries(), containsInAnyOrder( | ||
| 63 | newClass("cuchaz/enigma/inputs/Keep"), | ||
| 64 | m_baseClass, | ||
| 65 | m_subClassA, | ||
| 66 | m_subClassAA, | ||
| 67 | m_subClassB | ||
| 68 | )); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Test | ||
| 72 | public void translationIndex() { | ||
| 73 | |||
| 74 | TranslationIndex index = m_index.getTranslationIndex(); | ||
| 75 | |||
| 76 | // base class | ||
| 77 | assertThat(index.getSuperclass(m_baseClass), is(m_objectClass)); | ||
| 78 | assertThat(index.getAncestry(m_baseClass), contains(m_objectClass)); | ||
| 79 | assertThat(index.getSubclass(m_baseClass), containsInAnyOrder( | ||
| 80 | m_subClassA, | ||
| 81 | m_subClassB | ||
| 82 | )); | ||
| 83 | |||
| 84 | // subclass a | ||
| 85 | assertThat(index.getSuperclass(m_subClassA), is(m_baseClass)); | ||
| 86 | assertThat(index.getAncestry(m_subClassA), contains(m_baseClass, m_objectClass)); | ||
| 87 | assertThat(index.getSubclass(m_subClassA), contains(m_subClassAA)); | ||
| 88 | |||
| 89 | // subclass aa | ||
| 90 | assertThat(index.getSuperclass(m_subClassAA), is(m_subClassA)); | ||
| 91 | assertThat(index.getAncestry(m_subClassAA), contains(m_subClassA, m_baseClass, m_objectClass)); | ||
| 92 | assertThat(index.getSubclass(m_subClassAA), is(empty())); | ||
| 93 | |||
| 94 | // subclass b | ||
| 95 | assertThat(index.getSuperclass(m_subClassB), is(m_baseClass)); | ||
| 96 | assertThat(index.getAncestry(m_subClassB), contains(m_baseClass, m_objectClass)); | ||
| 97 | assertThat(index.getSubclass(m_subClassB), is(empty())); | ||
| 98 | } | ||
| 99 | |||
| 100 | @Test | ||
| 101 | public void access() { | ||
| 102 | assertThat(m_index.getAccess(m_nameField), is(Access.Private)); | ||
| 103 | assertThat(m_index.getAccess(m_numThingsField), is(Access.Private)); | ||
| 104 | } | ||
| 105 | |||
| 106 | @Test | ||
| 107 | public void relatedMethodImplementations() { | ||
| 108 | |||
| 109 | Set<MethodEntry> entries; | ||
| 110 | |||
| 111 | // getName() | ||
| 112 | entries = m_index.getRelatedMethodImplementations(newMethod(m_baseClass, "a", "()Ljava/lang/String;")); | ||
| 113 | assertThat(entries, containsInAnyOrder( | ||
| 114 | newMethod(m_baseClass, "a", "()Ljava/lang/String;"), | ||
| 115 | newMethod(m_subClassAA, "a", "()Ljava/lang/String;") | ||
| 116 | )); | ||
| 117 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassAA, "a", "()Ljava/lang/String;")); | ||
| 118 | assertThat(entries, containsInAnyOrder( | ||
| 119 | newMethod(m_baseClass, "a", "()Ljava/lang/String;"), | ||
| 120 | newMethod(m_subClassAA, "a", "()Ljava/lang/String;") | ||
| 121 | )); | ||
| 122 | |||
| 123 | // doBaseThings() | ||
| 124 | entries = m_index.getRelatedMethodImplementations(newMethod(m_baseClass, "a", "()V")); | ||
| 125 | assertThat(entries, containsInAnyOrder( | ||
| 126 | newMethod(m_baseClass, "a", "()V"), | ||
| 127 | newMethod(m_subClassAA, "a", "()V"), | ||
| 128 | newMethod(m_subClassB, "a", "()V") | ||
| 129 | )); | ||
| 130 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassAA, "a", "()V")); | ||
| 131 | assertThat(entries, containsInAnyOrder( | ||
| 132 | newMethod(m_baseClass, "a", "()V"), | ||
| 133 | newMethod(m_subClassAA, "a", "()V"), | ||
| 134 | newMethod(m_subClassB, "a", "()V") | ||
| 135 | )); | ||
| 136 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassB, "a", "()V")); | ||
| 137 | assertThat(entries, containsInAnyOrder( | ||
| 138 | newMethod(m_baseClass, "a", "()V"), | ||
| 139 | newMethod(m_subClassAA, "a", "()V"), | ||
| 140 | newMethod(m_subClassB, "a", "()V") | ||
| 141 | )); | ||
| 142 | |||
| 143 | // doBThings | ||
| 144 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassB, "b", "()V")); | ||
| 145 | assertThat(entries, containsInAnyOrder(newMethod(m_subClassB, "b", "()V"))); | ||
| 146 | } | ||
| 147 | |||
| 148 | @Test | ||
| 149 | @SuppressWarnings("unchecked") | ||
| 150 | public void fieldReferences() { | ||
| 151 | Collection<EntryReference<FieldEntry,BehaviorEntry>> references; | ||
| 152 | |||
| 153 | // name | ||
| 154 | references = m_index.getFieldReferences(m_nameField); | ||
| 155 | assertThat(references, containsInAnyOrder( | ||
| 156 | newFieldReferenceByConstructor(m_nameField, m_baseClass.getName(), "(Ljava/lang/String;)V"), | ||
| 157 | newFieldReferenceByMethod(m_nameField, m_baseClass.getName(), "a", "()Ljava/lang/String;") | ||
| 158 | )); | ||
| 159 | |||
| 160 | // numThings | ||
| 161 | references = m_index.getFieldReferences(m_numThingsField); | ||
| 162 | assertThat(references, containsInAnyOrder( | ||
| 163 | newFieldReferenceByConstructor(m_numThingsField, m_subClassB.getName(), "()V"), | ||
| 164 | newFieldReferenceByMethod(m_numThingsField, m_subClassB.getName(), "b", "()V") | ||
| 165 | )); | ||
| 166 | } | ||
| 167 | |||
| 168 | @Test | ||
| 169 | @SuppressWarnings("unchecked") | ||
| 170 | public void behaviorReferences() { | ||
| 171 | |||
| 172 | BehaviorEntry source; | ||
| 173 | Collection<EntryReference<BehaviorEntry,BehaviorEntry>> references; | ||
| 174 | |||
| 175 | // baseClass constructor | ||
| 176 | source = newConstructor(m_baseClass, "(Ljava/lang/String;)V"); | ||
| 177 | references = m_index.getBehaviorReferences(source); | ||
| 178 | assertThat(references, containsInAnyOrder( | ||
| 179 | newBehaviorReferenceByConstructor(source, m_subClassA.getName(), "(Ljava/lang/String;)V"), | ||
| 180 | newBehaviorReferenceByConstructor(source, m_subClassB.getName(), "()V") | ||
| 181 | )); | ||
| 182 | |||
| 183 | // subClassA constructor | ||
| 184 | source = newConstructor(m_subClassA, "(Ljava/lang/String;)V"); | ||
| 185 | references = m_index.getBehaviorReferences(source); | ||
| 186 | assertThat(references, containsInAnyOrder( | ||
| 187 | newBehaviorReferenceByConstructor(source, m_subClassAA.getName(), "()V") | ||
| 188 | )); | ||
| 189 | |||
| 190 | // baseClass.getName() | ||
| 191 | source = newMethod(m_baseClass, "a", "()Ljava/lang/String;"); | ||
| 192 | references = m_index.getBehaviorReferences(source); | ||
| 193 | assertThat(references, containsInAnyOrder( | ||
| 194 | newBehaviorReferenceByMethod(source, m_subClassAA.getName(), "a", "()Ljava/lang/String;"), | ||
| 195 | newBehaviorReferenceByMethod(source, m_subClassB.getName(), "a", "()V") | ||
| 196 | )); | ||
| 197 | |||
| 198 | // subclassAA.getName() | ||
| 199 | source = newMethod(m_subClassAA, "a", "()Ljava/lang/String;"); | ||
| 200 | references = m_index.getBehaviorReferences(source); | ||
| 201 | assertThat(references, containsInAnyOrder( | ||
| 202 | newBehaviorReferenceByMethod(source, m_subClassAA.getName(), "a", "()V") | ||
| 203 | )); | ||
| 204 | } | ||
| 205 | |||
| 206 | @Test | ||
| 207 | public void containsEntries() { | ||
| 208 | |||
| 209 | // classes | ||
| 210 | assertThat(m_index.containsObfClass(m_baseClass), is(true)); | ||
| 211 | assertThat(m_index.containsObfClass(m_subClassA), is(true)); | ||
| 212 | assertThat(m_index.containsObfClass(m_subClassAA), is(true)); | ||
| 213 | assertThat(m_index.containsObfClass(m_subClassB), is(true)); | ||
| 214 | |||
| 215 | // fields | ||
| 216 | assertThat(m_index.containsObfField(m_nameField), is(true)); | ||
| 217 | assertThat(m_index.containsObfField(m_numThingsField), is(true)); | ||
| 218 | |||
| 219 | // methods | ||
| 220 | // getName() | ||
| 221 | assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "a", "()Ljava/lang/String;")), is(true)); | ||
| 222 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "a", "()Ljava/lang/String;")), is(false)); | ||
| 223 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "a", "()Ljava/lang/String;")), is(true)); | ||
| 224 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "a", "()Ljava/lang/String;")), is(false)); | ||
| 225 | |||
| 226 | // doBaseThings() | ||
| 227 | assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "a", "()V")), is(true)); | ||
| 228 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "a", "()V")), is(false)); | ||
| 229 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "a", "()V")), is(true)); | ||
| 230 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "a", "()V")), is(true)); | ||
| 231 | |||
| 232 | // doBThings() | ||
| 233 | assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "b", "()V")), is(false)); | ||
| 234 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "b", "()V")), is(false)); | ||
| 235 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "b", "()V")), is(false)); | ||
| 236 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "b", "()V")), is(true)); | ||
| 237 | |||
| 238 | } | ||
| 239 | } | ||