diff options
Diffstat (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java')
| -rw-r--r-- | test/cuchaz/enigma/TestJarIndexLoneClass.java | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java new file mode 100644 index 0000000..09479bb --- /dev/null +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java | |||
| @@ -0,0 +1,164 @@ | |||
| 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.*; | ||
| 14 | import static org.hamcrest.MatcherAssert.*; | ||
| 15 | import static org.hamcrest.Matchers.*; | ||
| 16 | |||
| 17 | import java.util.Collection; | ||
| 18 | import java.util.Set; | ||
| 19 | import java.util.jar.JarFile; | ||
| 20 | |||
| 21 | import org.junit.Test; | ||
| 22 | |||
| 23 | import cuchaz.enigma.analysis.Access; | ||
| 24 | import cuchaz.enigma.analysis.ClassImplementationsTreeNode; | ||
| 25 | import cuchaz.enigma.analysis.ClassInheritanceTreeNode; | ||
| 26 | import cuchaz.enigma.analysis.EntryReference; | ||
| 27 | import cuchaz.enigma.analysis.JarIndex; | ||
| 28 | import cuchaz.enigma.analysis.MethodInheritanceTreeNode; | ||
| 29 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 30 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 31 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 32 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 33 | import cuchaz.enigma.mapping.Translator; | ||
| 34 | |||
| 35 | public class TestJarIndexLoneClass { | ||
| 36 | |||
| 37 | private JarIndex m_index; | ||
| 38 | |||
| 39 | public TestJarIndexLoneClass() | ||
| 40 | throws Exception { | ||
| 41 | m_index = new JarIndex(); | ||
| 42 | m_index.indexJar(new JarFile("build/test-obf/loneClass.jar"), false); | ||
| 43 | } | ||
| 44 | |||
| 45 | @Test | ||
| 46 | public void obfEntries() { | ||
| 47 | assertThat(m_index.getObfClassEntries(), containsInAnyOrder( | ||
| 48 | newClass("cuchaz/enigma/inputs/Keep"), | ||
| 49 | newClass("none/a") | ||
| 50 | )); | ||
| 51 | } | ||
| 52 | |||
| 53 | @Test | ||
| 54 | public void translationIndex() { | ||
| 55 | assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("none/a")), is(nullValue())); | ||
| 56 | assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(nullValue())); | ||
| 57 | assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("none/a")), is(empty())); | ||
| 58 | assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); | ||
| 59 | assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("none/a")), is(empty())); | ||
| 60 | assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); | ||
| 61 | } | ||
| 62 | |||
| 63 | @Test | ||
| 64 | public void access() { | ||
| 65 | assertThat(m_index.getAccess(newField("none/a", "a", "Ljava/lang/String;")), is(Access.Private)); | ||
| 66 | assertThat(m_index.getAccess(newMethod("none/a", "a", "()Ljava/lang/String;")), is(Access.Public)); | ||
| 67 | assertThat(m_index.getAccess(newField("none/a", "b", "Ljava/lang/String;")), is(nullValue())); | ||
| 68 | assertThat(m_index.getAccess(newField("none/a", "a", "LFoo;")), is(nullValue())); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Test | ||
| 72 | public void classInheritance() { | ||
| 73 | ClassInheritanceTreeNode node = m_index.getClassInheritance(new Translator(), newClass("none/a")); | ||
| 74 | assertThat(node, is(not(nullValue()))); | ||
| 75 | assertThat(node.getObfClassName(), is("none/a")); | ||
| 76 | assertThat(node.getChildCount(), is(0)); | ||
| 77 | } | ||
| 78 | |||
| 79 | @Test | ||
| 80 | public void methodInheritance() { | ||
| 81 | MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); | ||
| 82 | MethodInheritanceTreeNode node = m_index.getMethodInheritance(new Translator(), source); | ||
| 83 | assertThat(node, is(not(nullValue()))); | ||
| 84 | assertThat(node.getMethodEntry(), is(source)); | ||
| 85 | assertThat(node.getChildCount(), is(0)); | ||
| 86 | } | ||
| 87 | |||
| 88 | @Test | ||
| 89 | public void classImplementations() { | ||
| 90 | ClassImplementationsTreeNode node = m_index.getClassImplementations(new Translator(), newClass("none/a")); | ||
| 91 | assertThat(node, is(nullValue())); | ||
| 92 | } | ||
| 93 | |||
| 94 | @Test | ||
| 95 | public void methodImplementations() { | ||
| 96 | MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); | ||
| 97 | assertThat(m_index.getMethodImplementations(new Translator(), source), is(empty())); | ||
| 98 | } | ||
| 99 | |||
| 100 | @Test | ||
| 101 | public void relatedMethodImplementations() { | ||
| 102 | Set<MethodEntry> entries = m_index.getRelatedMethodImplementations(newMethod("none/a", "a", "()Ljava/lang/String;")); | ||
| 103 | assertThat(entries, containsInAnyOrder( | ||
| 104 | newMethod("none/a", "a", "()Ljava/lang/String;") | ||
| 105 | )); | ||
| 106 | } | ||
| 107 | |||
| 108 | @Test | ||
| 109 | @SuppressWarnings("unchecked") | ||
| 110 | public void fieldReferences() { | ||
| 111 | FieldEntry source = newField("none/a", "a", "Ljava/lang/String;"); | ||
| 112 | Collection<EntryReference<FieldEntry,BehaviorEntry>> references = m_index.getFieldReferences(source); | ||
| 113 | assertThat(references, containsInAnyOrder( | ||
| 114 | newFieldReferenceByConstructor(source, "none/a", "(Ljava/lang/String;)V"), | ||
| 115 | newFieldReferenceByMethod(source, "none/a", "a", "()Ljava/lang/String;") | ||
| 116 | )); | ||
| 117 | } | ||
| 118 | |||
| 119 | @Test | ||
| 120 | public void behaviorReferences() { | ||
| 121 | assertThat(m_index.getBehaviorReferences(newMethod("none/a", "a", "()Ljava/lang/String;")), is(empty())); | ||
| 122 | } | ||
| 123 | |||
| 124 | @Test | ||
| 125 | public void innerClasses() { | ||
| 126 | assertThat(m_index.getInnerClasses(newClass("none/a")), is(empty())); | ||
| 127 | } | ||
| 128 | |||
| 129 | @Test | ||
| 130 | public void outerClass() { | ||
| 131 | assertThat(m_index.getOuterClass(newClass("a")), is(nullValue())); | ||
| 132 | } | ||
| 133 | |||
| 134 | @Test | ||
| 135 | public void isAnonymousClass() { | ||
| 136 | assertThat(m_index.isAnonymousClass(newClass("none/a")), is(false)); | ||
| 137 | } | ||
| 138 | |||
| 139 | @Test | ||
| 140 | public void interfaces() { | ||
| 141 | assertThat(m_index.getInterfaces("none/a"), is(empty())); | ||
| 142 | } | ||
| 143 | |||
| 144 | @Test | ||
| 145 | public void implementingClasses() { | ||
| 146 | assertThat(m_index.getImplementingClasses("none/a"), is(empty())); | ||
| 147 | } | ||
| 148 | |||
| 149 | @Test | ||
| 150 | public void isInterface() { | ||
| 151 | assertThat(m_index.isInterface("none/a"), is(false)); | ||
| 152 | } | ||
| 153 | |||
| 154 | @Test | ||
| 155 | public void contains() { | ||
| 156 | assertThat(m_index.containsObfClass(newClass("none/a")), is(true)); | ||
| 157 | assertThat(m_index.containsObfClass(newClass("none/b")), is(false)); | ||
| 158 | assertThat(m_index.containsObfField(newField("none/a", "a", "Ljava/lang/String;")), is(true)); | ||
| 159 | assertThat(m_index.containsObfField(newField("none/a", "b", "Ljava/lang/String;")), is(false)); | ||
| 160 | assertThat(m_index.containsObfField(newField("none/a", "a", "LFoo;")), is(false)); | ||
| 161 | assertThat(m_index.containsObfBehavior(newMethod("none/a", "a", "()Ljava/lang/String;")), is(true)); | ||
| 162 | assertThat(m_index.containsObfBehavior(newMethod("none/a", "b", "()Ljava/lang/String;")), is(false)); | ||
| 163 | } | ||
| 164 | } | ||