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