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