summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/cuchaz/enigma/TestDeobfed.java6
-rw-r--r--src/test/java/cuchaz/enigma/TestEntryFactory.java28
-rw-r--r--src/test/java/cuchaz/enigma/TestInnerClasses.java47
-rw-r--r--src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java78
-rw-r--r--src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java111
-rw-r--r--src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java37
-rw-r--r--src/test/java/cuchaz/enigma/TestMethodDescriptor.java247
-rw-r--r--src/test/java/cuchaz/enigma/TestSignature.java270
-rw-r--r--src/test/java/cuchaz/enigma/TestTokensConstructors.java90
-rw-r--r--src/test/java/cuchaz/enigma/TestTypeDescriptor.java243
10 files changed, 655 insertions, 502 deletions
diff --git a/src/test/java/cuchaz/enigma/TestDeobfed.java b/src/test/java/cuchaz/enigma/TestDeobfed.java
index e6c1b746..fbdebd61 100644
--- a/src/test/java/cuchaz/enigma/TestDeobfed.java
+++ b/src/test/java/cuchaz/enigma/TestDeobfed.java
@@ -12,6 +12,8 @@
12package cuchaz.enigma; 12package cuchaz.enigma;
13 13
14import cuchaz.enigma.analysis.JarIndex; 14import cuchaz.enigma.analysis.JarIndex;
15import cuchaz.enigma.analysis.ParsedJar;
16import cuchaz.enigma.mapping.ReferencedEntryPool;
15import org.junit.BeforeClass; 17import org.junit.BeforeClass;
16import org.junit.Test; 18import org.junit.Test;
17 19
@@ -30,8 +32,8 @@ public class TestDeobfed {
30 public static void beforeClass() 32 public static void beforeClass()
31 throws Exception { 33 throws Exception {
32 jar = new JarFile("build/test-deobf/translation.jar"); 34 jar = new JarFile("build/test-deobf/translation.jar");
33 index = new JarIndex(); 35 index = new JarIndex(new ReferencedEntryPool());
34 index.indexJar(jar, true); 36 index.indexJar(new ParsedJar(jar), true);
35 } 37 }
36 38
37 @Test 39 @Test
diff --git a/src/test/java/cuchaz/enigma/TestEntryFactory.java b/src/test/java/cuchaz/enigma/TestEntryFactory.java
index 1c527f53..067dcbfe 100644
--- a/src/test/java/cuchaz/enigma/TestEntryFactory.java
+++ b/src/test/java/cuchaz/enigma/TestEntryFactory.java
@@ -25,7 +25,7 @@ public class TestEntryFactory {
25 } 25 }
26 26
27 public static FieldEntry newField(ClassEntry classEntry, String fieldName, String fieldType) { 27 public static FieldEntry newField(ClassEntry classEntry, String fieldName, String fieldType) {
28 return new FieldEntry(classEntry, fieldName, new Type(fieldType)); 28 return new FieldEntry(classEntry, fieldName, new TypeDescriptor(fieldType));
29 } 29 }
30 30
31 public static MethodEntry newMethod(String className, String methodName, String methodSignature) { 31 public static MethodEntry newMethod(String className, String methodName, String methodSignature) {
@@ -33,30 +33,14 @@ public class TestEntryFactory {
33 } 33 }
34 34
35 public static MethodEntry newMethod(ClassEntry classEntry, String methodName, String methodSignature) { 35 public static MethodEntry newMethod(ClassEntry classEntry, String methodName, String methodSignature) {
36 return new MethodEntry(classEntry, methodName, new Signature(methodSignature)); 36 return new MethodEntry(classEntry, methodName, new MethodDescriptor(methodSignature));
37 } 37 }
38 38
39 public static ConstructorEntry newConstructor(String className, String signature) { 39 public static EntryReference<FieldEntry, MethodEntry> newFieldReferenceByMethod(FieldEntry fieldEntry, String callerClassName, String callerName, String callerSignature) {
40 return newConstructor(newClass(className), signature); 40 return new EntryReference<>(fieldEntry, "", newMethod(callerClassName, callerName, callerSignature));
41 } 41 }
42 42
43 public static ConstructorEntry newConstructor(ClassEntry classEntry, String signature) { 43 public static EntryReference<MethodEntry, MethodEntry> newBehaviorReferenceByMethod(MethodEntry methodEntry, String callerClassName, String callerName, String callerSignature) {
44 return new ConstructorEntry(classEntry, new Signature(signature)); 44 return new EntryReference<>(methodEntry, "", newMethod(callerClassName, callerName, callerSignature));
45 }
46
47 public static EntryReference<FieldEntry, BehaviorEntry> newFieldReferenceByMethod(FieldEntry fieldEntry, String callerClassName, String callerName, String callerSignature) {
48 return new EntryReference<FieldEntry, BehaviorEntry>(fieldEntry, "", newMethod(callerClassName, callerName, callerSignature));
49 }
50
51 public static EntryReference<FieldEntry, BehaviorEntry> newFieldReferenceByConstructor(FieldEntry fieldEntry, String callerClassName, String callerSignature) {
52 return new EntryReference<FieldEntry, BehaviorEntry>(fieldEntry, "", newConstructor(callerClassName, callerSignature));
53 }
54
55 public static EntryReference<BehaviorEntry, BehaviorEntry> newBehaviorReferenceByMethod(BehaviorEntry behaviorEntry, String callerClassName, String callerName, String callerSignature) {
56 return new EntryReference<BehaviorEntry, BehaviorEntry>(behaviorEntry, "", newMethod(callerClassName, callerName, callerSignature));
57 }
58
59 public static EntryReference<BehaviorEntry, BehaviorEntry> newBehaviorReferenceByConstructor(BehaviorEntry behaviorEntry, String callerClassName, String callerSignature) {
60 return new EntryReference<BehaviorEntry, BehaviorEntry>(behaviorEntry, "", newConstructor(callerClassName, callerSignature));
61 } 45 }
62} 46}
diff --git a/src/test/java/cuchaz/enigma/TestInnerClasses.java b/src/test/java/cuchaz/enigma/TestInnerClasses.java
index 38db0df9..30e127e6 100644
--- a/src/test/java/cuchaz/enigma/TestInnerClasses.java
+++ b/src/test/java/cuchaz/enigma/TestInnerClasses.java
@@ -12,7 +12,9 @@
12package cuchaz.enigma; 12package cuchaz.enigma;
13 13
14import cuchaz.enigma.analysis.JarIndex; 14import cuchaz.enigma.analysis.JarIndex;
15import cuchaz.enigma.analysis.ParsedJar;
15import cuchaz.enigma.mapping.ClassEntry; 16import cuchaz.enigma.mapping.ClassEntry;
17import cuchaz.enigma.mapping.ReferencedEntryPool;
16import org.junit.Test; 18import org.junit.Test;
17 19
18import java.util.jar.JarFile; 20import java.util.jar.JarFile;
@@ -26,16 +28,10 @@ import static org.hamcrest.Matchers.nullValue;
26 28
27public class TestInnerClasses { 29public class TestInnerClasses {
28 30
29 private static final ClassEntry AnonymousOuter = newClass("a");
30 private static final ClassEntry AnonymousInner = newClass("a$1");
31 private static final ClassEntry SimpleOuter = newClass("d"); 31 private static final ClassEntry SimpleOuter = newClass("d");
32 private static final ClassEntry SimpleInner = newClass("d$a"); 32 private static final ClassEntry SimpleInner = newClass("d$a");
33 private static final ClassEntry ConstructorArgsOuter = newClass("c"); 33 private static final ClassEntry ConstructorArgsOuter = newClass("c");
34 private static final ClassEntry ConstructorArgsInner = newClass("c$a"); 34 private static final ClassEntry ConstructorArgsInner = newClass("c$a");
35 private static final ClassEntry AnonymousWithScopeArgsOuter = newClass("b");
36 private static final ClassEntry AnonymousWithScopeArgsInner = newClass("b$1");
37 private static final ClassEntry AnonymousWithOuterAccessOuter = newClass("e");
38 private static final ClassEntry AnonymousWithOuterAccessInner = newClass("e$1");
39 private static final ClassEntry ClassTreeRoot = newClass("f"); 35 private static final ClassEntry ClassTreeRoot = newClass("f");
40 private static final ClassEntry ClassTreeLevel1 = newClass("f$a"); 36 private static final ClassEntry ClassTreeLevel1 = newClass("f$a");
41 private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a"); 37 private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a");
@@ -45,9 +41,9 @@ public class TestInnerClasses {
45 41
46 public TestInnerClasses() 42 public TestInnerClasses()
47 throws Exception { 43 throws Exception {
48 index = new JarIndex(); 44 index = new JarIndex(new ReferencedEntryPool());
49 JarFile jar = new JarFile("build/test-obf/innerClasses.jar"); 45 JarFile jar = new JarFile("build/test-obf/innerClasses.jar");
50 index.indexJar(jar, true); 46 index.indexJar(new ParsedJar(jar), true);
51 deobfuscator = new Deobfuscator(jar); 47 deobfuscator = new Deobfuscator(jar);
52 } 48 }
53 49
@@ -55,43 +51,17 @@ public class TestInnerClasses {
55 public void simple() { 51 public void simple() {
56 assertThat(index.getOuterClass(SimpleInner), is(SimpleOuter)); 52 assertThat(index.getOuterClass(SimpleInner), is(SimpleOuter));
57 assertThat(index.getInnerClasses(SimpleOuter), containsInAnyOrder(SimpleInner)); 53 assertThat(index.getInnerClasses(SimpleOuter), containsInAnyOrder(SimpleInner));
58 assertThat(index.isAnonymousClass(SimpleInner), is(false));
59 decompile(SimpleOuter); 54 decompile(SimpleOuter);
60 } 55 }
61 56
62 @Test 57 @Test
63 public void anonymous() {
64 assertThat(index.getOuterClass(AnonymousInner), is(AnonymousOuter));
65 assertThat(index.getInnerClasses(AnonymousOuter), containsInAnyOrder(AnonymousInner));
66 assertThat(index.isAnonymousClass(AnonymousInner), is(true));
67 decompile(AnonymousOuter);
68 }
69
70 @Test
71 public void constructorArgs() { 58 public void constructorArgs() {
72 assertThat(index.getOuterClass(ConstructorArgsInner), is(ConstructorArgsOuter)); 59 assertThat(index.getOuterClass(ConstructorArgsInner), is(ConstructorArgsOuter));
73 assertThat(index.getInnerClasses(ConstructorArgsOuter), containsInAnyOrder(ConstructorArgsInner)); 60 assertThat(index.getInnerClasses(ConstructorArgsOuter), containsInAnyOrder(ConstructorArgsInner));
74 assertThat(index.isAnonymousClass(ConstructorArgsInner), is(false));
75 decompile(ConstructorArgsOuter); 61 decompile(ConstructorArgsOuter);
76 } 62 }
77 63
78 @Test 64 @Test
79 public void anonymousWithScopeArgs() {
80 assertThat(index.getOuterClass(AnonymousWithScopeArgsInner), is(AnonymousWithScopeArgsOuter));
81 assertThat(index.getInnerClasses(AnonymousWithScopeArgsOuter), containsInAnyOrder(AnonymousWithScopeArgsInner));
82 assertThat(index.isAnonymousClass(AnonymousWithScopeArgsInner), is(true));
83 decompile(AnonymousWithScopeArgsOuter);
84 }
85
86 @Test
87 public void anonymousWithOuterAccess() {
88 assertThat(index.getOuterClass(AnonymousWithOuterAccessInner), is(AnonymousWithOuterAccessOuter));
89 assertThat(index.getInnerClasses(AnonymousWithOuterAccessOuter), containsInAnyOrder(AnonymousWithOuterAccessInner));
90 assertThat(index.isAnonymousClass(AnonymousWithOuterAccessInner), is(true));
91 decompile(AnonymousWithOuterAccessOuter);
92 }
93
94 @Test
95 public void classTree() { 65 public void classTree() {
96 66
97 // root level 67 // root level
@@ -101,8 +71,7 @@ public class TestInnerClasses {
101 71
102 // level 1 72 // level 1
103 ClassEntry fullClassEntry = new ClassEntry(ClassTreeRoot.getName() 73 ClassEntry fullClassEntry = new ClassEntry(ClassTreeRoot.getName()
104 + "$" + ClassTreeLevel1.getInnermostClassName() 74 + "$" + ClassTreeLevel1.getInnermostClassName());
105 );
106 assertThat(index.containsObfClass(fullClassEntry), is(true)); 75 assertThat(index.containsObfClass(fullClassEntry), is(true));
107 assertThat(index.getOuterClass(ClassTreeLevel1), is(ClassTreeRoot)); 76 assertThat(index.getOuterClass(ClassTreeLevel1), is(ClassTreeRoot));
108 assertThat(index.getInnerClasses(ClassTreeLevel1), containsInAnyOrder(ClassTreeLevel2)); 77 assertThat(index.getInnerClasses(ClassTreeLevel1), containsInAnyOrder(ClassTreeLevel2));
@@ -110,8 +79,7 @@ public class TestInnerClasses {
110 // level 2 79 // level 2
111 fullClassEntry = new ClassEntry(ClassTreeRoot.getName() 80 fullClassEntry = new ClassEntry(ClassTreeRoot.getName()
112 + "$" + ClassTreeLevel1.getInnermostClassName() 81 + "$" + ClassTreeLevel1.getInnermostClassName()
113 + "$" + ClassTreeLevel2.getInnermostClassName() 82 + "$" + ClassTreeLevel2.getInnermostClassName());
114 );
115 assertThat(index.containsObfClass(fullClassEntry), is(true)); 83 assertThat(index.containsObfClass(fullClassEntry), is(true));
116 assertThat(index.getOuterClass(ClassTreeLevel2), is(ClassTreeLevel1)); 84 assertThat(index.getOuterClass(ClassTreeLevel2), is(ClassTreeLevel1));
117 assertThat(index.getInnerClasses(ClassTreeLevel2), containsInAnyOrder(ClassTreeLevel3)); 85 assertThat(index.getInnerClasses(ClassTreeLevel2), containsInAnyOrder(ClassTreeLevel3));
@@ -120,8 +88,7 @@ public class TestInnerClasses {
120 fullClassEntry = new ClassEntry(ClassTreeRoot.getName() 88 fullClassEntry = new ClassEntry(ClassTreeRoot.getName()
121 + "$" + ClassTreeLevel1.getInnermostClassName() 89 + "$" + ClassTreeLevel1.getInnermostClassName()
122 + "$" + ClassTreeLevel2.getInnermostClassName() 90 + "$" + ClassTreeLevel2.getInnermostClassName()
123 + "$" + ClassTreeLevel3.getInnermostClassName() 91 + "$" + ClassTreeLevel3.getInnermostClassName());
124 );
125 assertThat(index.containsObfClass(fullClassEntry), is(true)); 92 assertThat(index.containsObfClass(fullClassEntry), is(true));
126 assertThat(index.getOuterClass(ClassTreeLevel3), is(ClassTreeLevel2)); 93 assertThat(index.getOuterClass(ClassTreeLevel3), is(ClassTreeLevel2));
127 assertThat(index.getInnerClasses(ClassTreeLevel3), is(empty())); 94 assertThat(index.getInnerClasses(ClassTreeLevel3), is(empty()));
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java
index edb859a7..b20b27b6 100644
--- a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java
+++ b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java
@@ -13,22 +13,20 @@ package cuchaz.enigma;
13 13
14import cuchaz.enigma.analysis.EntryReference; 14import cuchaz.enigma.analysis.EntryReference;
15import cuchaz.enigma.analysis.JarIndex; 15import cuchaz.enigma.analysis.JarIndex;
16import cuchaz.enigma.mapping.BehaviorEntry; 16import cuchaz.enigma.analysis.ParsedJar;
17import cuchaz.enigma.mapping.ClassEntry; 17import cuchaz.enigma.mapping.ClassEntry;
18import cuchaz.enigma.mapping.MethodDefEntry;
19import cuchaz.enigma.mapping.MethodEntry;
20import cuchaz.enigma.mapping.ReferencedEntryPool;
18import org.junit.Test; 21import org.junit.Test;
19 22
20import java.io.File; 23import java.io.File;
21import java.util.Collection; 24import java.util.Collection;
22import java.util.jar.JarFile; 25import java.util.jar.JarFile;
23 26
24import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByConstructor; 27import static cuchaz.enigma.TestEntryFactory.*;
25import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod;
26import static cuchaz.enigma.TestEntryFactory.newClass;
27import static cuchaz.enigma.TestEntryFactory.newConstructor;
28import static org.hamcrest.MatcherAssert.assertThat; 28import static org.hamcrest.MatcherAssert.assertThat;
29import static org.hamcrest.Matchers.containsInAnyOrder; 29import static org.hamcrest.Matchers.*;
30import static org.hamcrest.Matchers.empty;
31import static org.hamcrest.Matchers.is;
32 30
33public class TestJarIndexConstructorReferences { 31public class TestJarIndexConstructorReferences {
34 32
@@ -41,90 +39,90 @@ public class TestJarIndexConstructorReferences {
41 private ClassEntry callerClass = newClass("b"); 39 private ClassEntry callerClass = newClass("b");
42 40
43 public TestJarIndexConstructorReferences() 41 public TestJarIndexConstructorReferences()
44 throws Exception { 42 throws Exception {
45 File jarFile = new File("build/test-obf/constructors.jar"); 43 File jarFile = new File("build/test-obf/constructors.jar");
46 index = new JarIndex(); 44 index = new JarIndex(new ReferencedEntryPool());
47 index.indexJar(new JarFile(jarFile), false); 45 index.indexJar(new ParsedJar(new JarFile(jarFile)), false);
48 } 46 }
49 47
50 @Test 48 @Test
51 public void obfEntries() { 49 public void obfEntries() {
52 assertThat(index.getObfClassEntries(), containsInAnyOrder(newClass("cuchaz/enigma/inputs/Keep"), baseClass, 50 assertThat(index.getObfClassEntries(), containsInAnyOrder(newClass("cuchaz/enigma/inputs/Keep"), baseClass,
53 subClass, subsubClass, defaultClass, callerClass)); 51 subClass, subsubClass, defaultClass, callerClass));
54 } 52 }
55 53
56 @Test 54 @Test
57 @SuppressWarnings("unchecked") 55 @SuppressWarnings("unchecked")
58 public void baseDefault() { 56 public void baseDefault() {
59 BehaviorEntry source = newConstructor(baseClass, "()V"); 57 MethodEntry source = newMethod(baseClass, "<init>", "()V");
60 Collection<EntryReference<BehaviorEntry, BehaviorEntry>> references = index.getBehaviorReferences(source); 58 Collection<EntryReference<MethodEntry, MethodDefEntry>> references = index.getMethodReferences(source);
61 assertThat(references, containsInAnyOrder( 59 assertThat(references, containsInAnyOrder(
62 newBehaviorReferenceByMethod(source, callerClass.getName(), "a", "()V"), 60 newBehaviorReferenceByMethod(source, callerClass.getName(), "a", "()V"),
63 newBehaviorReferenceByConstructor(source, subClass.getName(), "()V"), 61 newBehaviorReferenceByMethod(source, subClass.getName(), "<init>", "()V"),
64 newBehaviorReferenceByConstructor(source, subClass.getName(), "(III)V") 62 newBehaviorReferenceByMethod(source, subClass.getName(), "<init>", "(III)V")
65 )); 63 ));
66 } 64 }
67 65
68 @Test 66 @Test
69 @SuppressWarnings("unchecked") 67 @SuppressWarnings("unchecked")
70 public void baseInt() { 68 public void baseInt() {
71 BehaviorEntry source = newConstructor(baseClass, "(I)V"); 69 MethodEntry source = newMethod(baseClass, "<init>", "(I)V");
72 assertThat(index.getBehaviorReferences(source), containsInAnyOrder( 70 assertThat(index.getMethodReferences(source), containsInAnyOrder(
73 newBehaviorReferenceByMethod(source, callerClass.getName(), "b", "()V") 71 newBehaviorReferenceByMethod(source, callerClass.getName(), "b", "()V")
74 )); 72 ));
75 } 73 }
76 74
77 @Test 75 @Test
78 @SuppressWarnings("unchecked") 76 @SuppressWarnings("unchecked")
79 public void subDefault() { 77 public void subDefault() {
80 BehaviorEntry source = newConstructor(subClass, "()V"); 78 MethodEntry source = newMethod(subClass, "<init>", "()V");
81 assertThat(index.getBehaviorReferences(source), containsInAnyOrder( 79 assertThat(index.getMethodReferences(source), containsInAnyOrder(
82 newBehaviorReferenceByMethod(source, callerClass.getName(), "c", "()V"), 80 newBehaviorReferenceByMethod(source, callerClass.getName(), "c", "()V"),
83 newBehaviorReferenceByConstructor(source, subClass.getName(), "(I)V") 81 newBehaviorReferenceByMethod(source, subClass.getName(), "<init>", "(I)V")
84 )); 82 ));
85 } 83 }
86 84
87 @Test 85 @Test
88 @SuppressWarnings("unchecked") 86 @SuppressWarnings("unchecked")
89 public void subInt() { 87 public void subInt() {
90 BehaviorEntry source = newConstructor(subClass, "(I)V"); 88 MethodEntry source = newMethod(subClass, "<init>", "(I)V");
91 assertThat(index.getBehaviorReferences(source), containsInAnyOrder( 89 assertThat(index.getMethodReferences(source), containsInAnyOrder(
92 newBehaviorReferenceByMethod(source, callerClass.getName(), "d", "()V"), 90 newBehaviorReferenceByMethod(source, callerClass.getName(), "d", "()V"),
93 newBehaviorReferenceByConstructor(source, subClass.getName(), "(II)V"), 91 newBehaviorReferenceByMethod(source, subClass.getName(), "<init>", "(II)V"),
94 newBehaviorReferenceByConstructor(source, subsubClass.getName(), "(I)V") 92 newBehaviorReferenceByMethod(source, subsubClass.getName(), "<init>", "(I)V")
95 )); 93 ));
96 } 94 }
97 95
98 @Test 96 @Test
99 @SuppressWarnings("unchecked") 97 @SuppressWarnings("unchecked")
100 public void subIntInt() { 98 public void subIntInt() {
101 BehaviorEntry source = newConstructor(subClass, "(II)V"); 99 MethodEntry source = newMethod(subClass, "<init>", "(II)V");
102 assertThat(index.getBehaviorReferences(source), containsInAnyOrder( 100 assertThat(index.getMethodReferences(source), containsInAnyOrder(
103 newBehaviorReferenceByMethod(source, callerClass.getName(), "e", "()V") 101 newBehaviorReferenceByMethod(source, callerClass.getName(), "e", "()V")
104 )); 102 ));
105 } 103 }
106 104
107 @Test 105 @Test
108 public void subIntIntInt() { 106 public void subIntIntInt() {
109 BehaviorEntry source = newConstructor(subClass, "(III)V"); 107 MethodEntry source = newMethod(subClass, "<init>", "(III)V");
110 assertThat(index.getBehaviorReferences(source), is(empty())); 108 assertThat(index.getMethodReferences(source), is(empty()));
111 } 109 }
112 110
113 @Test 111 @Test
114 @SuppressWarnings("unchecked") 112 @SuppressWarnings("unchecked")
115 public void subsubInt() { 113 public void subsubInt() {
116 BehaviorEntry source = newConstructor(subsubClass, "(I)V"); 114 MethodEntry source = newMethod(subsubClass, "<init>", "(I)V");
117 assertThat(index.getBehaviorReferences(source), containsInAnyOrder( 115 assertThat(index.getMethodReferences(source), containsInAnyOrder(
118 newBehaviorReferenceByMethod(source, callerClass.getName(), "f", "()V") 116 newBehaviorReferenceByMethod(source, callerClass.getName(), "f", "()V")
119 )); 117 ));
120 } 118 }
121 119
122 @Test 120 @Test
123 @SuppressWarnings("unchecked") 121 @SuppressWarnings("unchecked")
124 public void defaultConstructable() { 122 public void defaultConstructable() {
125 BehaviorEntry source = newConstructor(defaultClass, "()V"); 123 MethodEntry source = newMethod(defaultClass, "<init>", "()V");
126 assertThat(index.getBehaviorReferences(source), containsInAnyOrder( 124 assertThat(index.getMethodReferences(source), containsInAnyOrder(
127 newBehaviorReferenceByMethod(source, callerClass.getName(), "g", "()V") 125 newBehaviorReferenceByMethod(source, callerClass.getName(), "g", "()V")
128 )); 126 ));
129 } 127 }
130} 128}
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java b/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java
index 62469780..d1c85964 100644
--- a/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java
+++ b/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java
@@ -11,14 +11,8 @@
11 11
12package cuchaz.enigma; 12package cuchaz.enigma;
13 13
14import cuchaz.enigma.analysis.Access; 14import cuchaz.enigma.analysis.*;
15import cuchaz.enigma.analysis.EntryReference; 15import cuchaz.enigma.mapping.*;
16import cuchaz.enigma.analysis.JarIndex;
17import cuchaz.enigma.analysis.TranslationIndex;
18import cuchaz.enigma.mapping.BehaviorEntry;
19import cuchaz.enigma.mapping.ClassEntry;
20import cuchaz.enigma.mapping.FieldEntry;
21import cuchaz.enigma.mapping.MethodEntry;
22import org.junit.Test; 16import org.junit.Test;
23 17
24import java.util.Collection; 18import java.util.Collection;
@@ -27,10 +21,7 @@ import java.util.jar.JarFile;
27 21
28import static cuchaz.enigma.TestEntryFactory.*; 22import static cuchaz.enigma.TestEntryFactory.*;
29import static org.hamcrest.MatcherAssert.assertThat; 23import static org.hamcrest.MatcherAssert.assertThat;
30import static org.hamcrest.Matchers.contains; 24import static org.hamcrest.Matchers.*;
31import static org.hamcrest.Matchers.containsInAnyOrder;
32import static org.hamcrest.Matchers.empty;
33import static org.hamcrest.Matchers.is;
34 25
35public class TestJarIndexInheritanceTree { 26public class TestJarIndexInheritanceTree {
36 27
@@ -45,15 +36,15 @@ public class TestJarIndexInheritanceTree {
45 private FieldEntry numThingsField = newField(subClassB, "a", "I"); 36 private FieldEntry numThingsField = newField(subClassB, "a", "I");
46 37
47 public TestJarIndexInheritanceTree() 38 public TestJarIndexInheritanceTree()
48 throws Exception { 39 throws Exception {
49 index = new JarIndex(); 40 index = new JarIndex(new ReferencedEntryPool());
50 index.indexJar(new JarFile("build/test-obf/inheritanceTree.jar"), false); 41 index.indexJar(new ParsedJar(new JarFile("build/test-obf/inheritanceTree.jar")), false);
51 } 42 }
52 43
53 @Test 44 @Test
54 public void obfEntries() { 45 public void obfEntries() {
55 assertThat(index.getObfClassEntries(), containsInAnyOrder( 46 assertThat(index.getObfClassEntries(), containsInAnyOrder(
56 newClass("cuchaz/enigma/inputs/Keep"), baseClass, subClassA, subClassAA, subClassB 47 newClass("cuchaz/enigma/inputs/Keep"), baseClass, subClassA, subClassAA, subClassB
57 )); 48 ));
58 } 49 }
59 50
@@ -98,33 +89,33 @@ public class TestJarIndexInheritanceTree {
98 // getName() 89 // getName()
99 entries = index.getRelatedMethodImplementations(newMethod(baseClass, "a", "()Ljava/lang/String;")); 90 entries = index.getRelatedMethodImplementations(newMethod(baseClass, "a", "()Ljava/lang/String;"));
100 assertThat(entries, containsInAnyOrder( 91 assertThat(entries, containsInAnyOrder(
101 newMethod(baseClass, "a", "()Ljava/lang/String;"), 92 newMethod(baseClass, "a", "()Ljava/lang/String;"),
102 newMethod(subClassAA, "a", "()Ljava/lang/String;") 93 newMethod(subClassAA, "a", "()Ljava/lang/String;")
103 )); 94 ));
104 entries = index.getRelatedMethodImplementations(newMethod(subClassAA, "a", "()Ljava/lang/String;")); 95 entries = index.getRelatedMethodImplementations(newMethod(subClassAA, "a", "()Ljava/lang/String;"));
105 assertThat(entries, containsInAnyOrder( 96 assertThat(entries, containsInAnyOrder(
106 newMethod(baseClass, "a", "()Ljava/lang/String;"), 97 newMethod(baseClass, "a", "()Ljava/lang/String;"),
107 newMethod(subClassAA, "a", "()Ljava/lang/String;") 98 newMethod(subClassAA, "a", "()Ljava/lang/String;")
108 )); 99 ));
109 100
110 // doBaseThings() 101 // doBaseThings()
111 entries = index.getRelatedMethodImplementations(newMethod(baseClass, "a", "()V")); 102 entries = index.getRelatedMethodImplementations(newMethod(baseClass, "a", "()V"));
112 assertThat(entries, containsInAnyOrder( 103 assertThat(entries, containsInAnyOrder(
113 newMethod(baseClass, "a", "()V"), 104 newMethod(baseClass, "a", "()V"),
114 newMethod(subClassAA, "a", "()V"), 105 newMethod(subClassAA, "a", "()V"),
115 newMethod(subClassB, "a", "()V") 106 newMethod(subClassB, "a", "()V")
116 )); 107 ));
117 entries = index.getRelatedMethodImplementations(newMethod(subClassAA, "a", "()V")); 108 entries = index.getRelatedMethodImplementations(newMethod(subClassAA, "a", "()V"));
118 assertThat(entries, containsInAnyOrder( 109 assertThat(entries, containsInAnyOrder(
119 newMethod(baseClass, "a", "()V"), 110 newMethod(baseClass, "a", "()V"),
120 newMethod(subClassAA, "a", "()V"), 111 newMethod(subClassAA, "a", "()V"),
121 newMethod(subClassB, "a", "()V") 112 newMethod(subClassB, "a", "()V")
122 )); 113 ));
123 entries = index.getRelatedMethodImplementations(newMethod(subClassB, "a", "()V")); 114 entries = index.getRelatedMethodImplementations(newMethod(subClassB, "a", "()V"));
124 assertThat(entries, containsInAnyOrder( 115 assertThat(entries, containsInAnyOrder(
125 newMethod(baseClass, "a", "()V"), 116 newMethod(baseClass, "a", "()V"),
126 newMethod(subClassAA, "a", "()V"), 117 newMethod(subClassAA, "a", "()V"),
127 newMethod(subClassB, "a", "()V") 118 newMethod(subClassB, "a", "()V")
128 )); 119 ));
129 120
130 // doBThings 121 // doBThings
@@ -135,20 +126,20 @@ public class TestJarIndexInheritanceTree {
135 @Test 126 @Test
136 @SuppressWarnings("unchecked") 127 @SuppressWarnings("unchecked")
137 public void fieldReferences() { 128 public void fieldReferences() {
138 Collection<EntryReference<FieldEntry, BehaviorEntry>> references; 129 Collection<EntryReference<FieldEntry, MethodDefEntry>> references;
139 130
140 // name 131 // name
141 references = index.getFieldReferences(nameField); 132 references = index.getFieldReferences(nameField);
142 assertThat(references, containsInAnyOrder( 133 assertThat(references, containsInAnyOrder(
143 newFieldReferenceByConstructor(nameField, baseClass.getName(), "(Ljava/lang/String;)V"), 134 newFieldReferenceByMethod(nameField, baseClass.getName(), "<init>", "(Ljava/lang/String;)V"),
144 newFieldReferenceByMethod(nameField, baseClass.getName(), "a", "()Ljava/lang/String;") 135 newFieldReferenceByMethod(nameField, baseClass.getName(), "a", "()Ljava/lang/String;")
145 )); 136 ));
146 137
147 // numThings 138 // numThings
148 references = index.getFieldReferences(numThingsField); 139 references = index.getFieldReferences(numThingsField);
149 assertThat(references, containsInAnyOrder( 140 assertThat(references, containsInAnyOrder(
150 newFieldReferenceByConstructor(numThingsField, subClassB.getName(), "()V"), 141 newFieldReferenceByMethod(numThingsField, subClassB.getName(), "<init>", "()V"),
151 newFieldReferenceByMethod(numThingsField, subClassB.getName(), "b", "()V") 142 newFieldReferenceByMethod(numThingsField, subClassB.getName(), "b", "()V")
152 )); 143 ));
153 } 144 }
154 145
@@ -156,37 +147,37 @@ public class TestJarIndexInheritanceTree {
156 @SuppressWarnings("unchecked") 147 @SuppressWarnings("unchecked")
157 public void behaviorReferences() { 148 public void behaviorReferences() {
158 149
159 BehaviorEntry source; 150 MethodEntry source;
160 Collection<EntryReference<BehaviorEntry, BehaviorEntry>> references; 151 Collection<EntryReference<MethodEntry, MethodDefEntry>> references;
161 152
162 // baseClass constructor 153 // baseClass constructor
163 source = newConstructor(baseClass, "(Ljava/lang/String;)V"); 154 source = newMethod(baseClass, "<init>", "(Ljava/lang/String;)V");
164 references = index.getBehaviorReferences(source); 155 references = index.getMethodReferences(source);
165 assertThat(references, containsInAnyOrder( 156 assertThat(references, containsInAnyOrder(
166 newBehaviorReferenceByConstructor(source, subClassA.getName(), "(Ljava/lang/String;)V"), 157 newBehaviorReferenceByMethod(source, subClassA.getName(), "<init>", "(Ljava/lang/String;)V"),
167 newBehaviorReferenceByConstructor(source, subClassB.getName(), "()V") 158 newBehaviorReferenceByMethod(source, subClassB.getName(), "<init>", "()V")
168 )); 159 ));
169 160
170 // subClassA constructor 161 // subClassA constructor
171 source = newConstructor(subClassA, "(Ljava/lang/String;)V"); 162 source = newMethod(subClassA, "<init>", "(Ljava/lang/String;)V");
172 references = index.getBehaviorReferences(source); 163 references = index.getMethodReferences(source);
173 assertThat(references, containsInAnyOrder( 164 assertThat(references, containsInAnyOrder(
174 newBehaviorReferenceByConstructor(source, subClassAA.getName(), "()V") 165 newBehaviorReferenceByMethod(source, subClassAA.getName(), "<init>", "()V")
175 )); 166 ));
176 167
177 // baseClass.getName() 168 // baseClass.getName()
178 source = newMethod(baseClass, "a", "()Ljava/lang/String;"); 169 source = newMethod(baseClass, "a", "()Ljava/lang/String;");
179 references = index.getBehaviorReferences(source); 170 references = index.getMethodReferences(source);
180 assertThat(references, containsInAnyOrder( 171 assertThat(references, containsInAnyOrder(
181 newBehaviorReferenceByMethod(source, subClassAA.getName(), "a", "()Ljava/lang/String;"), 172 newBehaviorReferenceByMethod(source, subClassAA.getName(), "a", "()Ljava/lang/String;"),
182 newBehaviorReferenceByMethod(source, subClassB.getName(), "a", "()V") 173 newBehaviorReferenceByMethod(source, subClassB.getName(), "a", "()V")
183 )); 174 ));
184 175
185 // subclassAA.getName() 176 // subclassAA.getName()
186 source = newMethod(subClassAA, "a", "()Ljava/lang/String;"); 177 source = newMethod(subClassAA, "a", "()Ljava/lang/String;");
187 references = index.getBehaviorReferences(source); 178 references = index.getMethodReferences(source);
188 assertThat(references, containsInAnyOrder( 179 assertThat(references, containsInAnyOrder(
189 newBehaviorReferenceByMethod(source, subClassAA.getName(), "a", "()V") 180 newBehaviorReferenceByMethod(source, subClassAA.getName(), "a", "()V")
190 )); 181 ));
191 } 182 }
192 183
@@ -205,22 +196,22 @@ public class TestJarIndexInheritanceTree {
205 196
206 // methods 197 // methods
207 // getName() 198 // getName()
208 assertThat(index.containsObfBehavior(newMethod(baseClass, "a", "()Ljava/lang/String;")), is(true)); 199 assertThat(index.containsObfMethod(newMethod(baseClass, "a", "()Ljava/lang/String;")), is(true));
209 assertThat(index.containsObfBehavior(newMethod(subClassA, "a", "()Ljava/lang/String;")), is(false)); 200 assertThat(index.containsObfMethod(newMethod(subClassA, "a", "()Ljava/lang/String;")), is(false));
210 assertThat(index.containsObfBehavior(newMethod(subClassAA, "a", "()Ljava/lang/String;")), is(true)); 201 assertThat(index.containsObfMethod(newMethod(subClassAA, "a", "()Ljava/lang/String;")), is(true));
211 assertThat(index.containsObfBehavior(newMethod(subClassB, "a", "()Ljava/lang/String;")), is(false)); 202 assertThat(index.containsObfMethod(newMethod(subClassB, "a", "()Ljava/lang/String;")), is(false));
212 203
213 // doBaseThings() 204 // doBaseThings()
214 assertThat(index.containsObfBehavior(newMethod(baseClass, "a", "()V")), is(true)); 205 assertThat(index.containsObfMethod(newMethod(baseClass, "a", "()V")), is(true));
215 assertThat(index.containsObfBehavior(newMethod(subClassA, "a", "()V")), is(false)); 206 assertThat(index.containsObfMethod(newMethod(subClassA, "a", "()V")), is(false));
216 assertThat(index.containsObfBehavior(newMethod(subClassAA, "a", "()V")), is(true)); 207 assertThat(index.containsObfMethod(newMethod(subClassAA, "a", "()V")), is(true));
217 assertThat(index.containsObfBehavior(newMethod(subClassB, "a", "()V")), is(true)); 208 assertThat(index.containsObfMethod(newMethod(subClassB, "a", "()V")), is(true));
218 209
219 // doBThings() 210 // doBThings()
220 assertThat(index.containsObfBehavior(newMethod(baseClass, "b", "()V")), is(false)); 211 assertThat(index.containsObfMethod(newMethod(baseClass, "b", "()V")), is(false));
221 assertThat(index.containsObfBehavior(newMethod(subClassA, "b", "()V")), is(false)); 212 assertThat(index.containsObfMethod(newMethod(subClassA, "b", "()V")), is(false));
222 assertThat(index.containsObfBehavior(newMethod(subClassAA, "b", "()V")), is(false)); 213 assertThat(index.containsObfMethod(newMethod(subClassAA, "b", "()V")), is(false));
223 assertThat(index.containsObfBehavior(newMethod(subClassB, "b", "()V")), is(true)); 214 assertThat(index.containsObfMethod(newMethod(subClassB, "b", "()V")), is(true));
224 215
225 } 216 }
226} 217}
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java
index 6cab1c84..d03f3fb4 100644
--- a/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java
+++ b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java
@@ -28,16 +28,16 @@ public class TestJarIndexLoneClass {
28 private JarIndex index; 28 private JarIndex index;
29 29
30 public TestJarIndexLoneClass() 30 public TestJarIndexLoneClass()
31 throws Exception { 31 throws Exception {
32 index = new JarIndex(); 32 index = new JarIndex(new ReferencedEntryPool());
33 index.indexJar(new JarFile("build/test-obf/loneClass.jar"), false); 33 index.indexJar(new ParsedJar(new JarFile("build/test-obf/loneClass.jar")), false);
34 } 34 }
35 35
36 @Test 36 @Test
37 public void obfEntries() { 37 public void obfEntries() {
38 assertThat(index.getObfClassEntries(), containsInAnyOrder( 38 assertThat(index.getObfClassEntries(), containsInAnyOrder(
39 newClass("cuchaz/enigma/inputs/Keep"), 39 newClass("cuchaz/enigma/inputs/Keep"),
40 newClass("a") 40 newClass("a")
41 )); 41 ));
42 } 42 }
43 43
@@ -61,7 +61,7 @@ public class TestJarIndexLoneClass {
61 61
62 @Test 62 @Test
63 public void classInheritance() { 63 public void classInheritance() {
64 ClassInheritanceTreeNode node = index.getClassInheritance(new Translator(), newClass("a")); 64 ClassInheritanceTreeNode node = index.getClassInheritance(new DirectionalTranslator(new ReferencedEntryPool()), newClass("a"));
65 assertThat(node, is(not(nullValue()))); 65 assertThat(node, is(not(nullValue())));
66 assertThat(node.getObfClassName(), is("a")); 66 assertThat(node.getObfClassName(), is("a"));
67 assertThat(node.getChildCount(), is(0)); 67 assertThat(node.getChildCount(), is(0));
@@ -70,7 +70,7 @@ public class TestJarIndexLoneClass {
70 @Test 70 @Test
71 public void methodInheritance() { 71 public void methodInheritance() {
72 MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;"); 72 MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;");
73 MethodInheritanceTreeNode node = index.getMethodInheritance(new Translator(), source); 73 MethodInheritanceTreeNode node = index.getMethodInheritance(new DirectionalTranslator(new ReferencedEntryPool()), source);
74 assertThat(node, is(not(nullValue()))); 74 assertThat(node, is(not(nullValue())));
75 assertThat(node.getMethodEntry(), is(source)); 75 assertThat(node.getMethodEntry(), is(source));
76 assertThat(node.getChildCount(), is(0)); 76 assertThat(node.getChildCount(), is(0));
@@ -78,21 +78,21 @@ public class TestJarIndexLoneClass {
78 78
79 @Test 79 @Test
80 public void classImplementations() { 80 public void classImplementations() {
81 ClassImplementationsTreeNode node = index.getClassImplementations(new Translator(), newClass("a")); 81 ClassImplementationsTreeNode node = index.getClassImplementations(new DirectionalTranslator(new ReferencedEntryPool()), newClass("a"));
82 assertThat(node, is(nullValue())); 82 assertThat(node, is(nullValue()));
83 } 83 }
84 84
85 @Test 85 @Test
86 public void methodImplementations() { 86 public void methodImplementations() {
87 MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;"); 87 MethodEntry source = newMethod("a", "a", "()Ljava/lang/String;");
88 assertThat(index.getMethodImplementations(new Translator(), source), is(empty())); 88 assertThat(index.getMethodImplementations(new DirectionalTranslator(new ReferencedEntryPool()), source), is(empty()));
89 } 89 }
90 90
91 @Test 91 @Test
92 public void relatedMethodImplementations() { 92 public void relatedMethodImplementations() {
93 Set<MethodEntry> entries = index.getRelatedMethodImplementations(newMethod("a", "a", "()Ljava/lang/String;")); 93 Set<MethodEntry> entries = index.getRelatedMethodImplementations(newMethod("a", "a", "()Ljava/lang/String;"));
94 assertThat(entries, containsInAnyOrder( 94 assertThat(entries, containsInAnyOrder(
95 newMethod("a", "a", "()Ljava/lang/String;") 95 newMethod("a", "a", "()Ljava/lang/String;")
96 )); 96 ));
97 } 97 }
98 98
@@ -100,16 +100,16 @@ public class TestJarIndexLoneClass {
100 @SuppressWarnings("unchecked") 100 @SuppressWarnings("unchecked")
101 public void fieldReferences() { 101 public void fieldReferences() {
102 FieldEntry source = newField("a", "a", "Ljava/lang/String;"); 102 FieldEntry source = newField("a", "a", "Ljava/lang/String;");
103 Collection<EntryReference<FieldEntry, BehaviorEntry>> references = index.getFieldReferences(source); 103 Collection<EntryReference<FieldEntry, MethodDefEntry>> references = index.getFieldReferences(source);
104 assertThat(references, containsInAnyOrder( 104 assertThat(references, containsInAnyOrder(
105 newFieldReferenceByConstructor(source, "a", "(Ljava/lang/String;)V"), 105 newFieldReferenceByMethod(source, "a", "<init>", "(Ljava/lang/String;)V"),
106 newFieldReferenceByMethod(source, "a", "a", "()Ljava/lang/String;") 106 newFieldReferenceByMethod(source, "a", "a", "()Ljava/lang/String;")
107 )); 107 ));
108 } 108 }
109 109
110 @Test 110 @Test
111 public void behaviorReferences() { 111 public void behaviorReferences() {
112 assertThat(index.getBehaviorReferences(newMethod("a", "a", "()Ljava/lang/String;")), is(empty())); 112 assertThat(index.getMethodReferences(newMethod("a", "a", "()Ljava/lang/String;")), is(empty()));
113 } 113 }
114 114
115 @Test 115 @Test
@@ -123,11 +123,6 @@ public class TestJarIndexLoneClass {
123 } 123 }
124 124
125 @Test 125 @Test
126 public void isAnonymousClass() {
127 assertThat(index.isAnonymousClass(newClass("a")), is(false));
128 }
129
130 @Test
131 public void interfaces() { 126 public void interfaces() {
132 assertThat(index.getInterfaces("a"), is(empty())); 127 assertThat(index.getInterfaces("a"), is(empty()));
133 } 128 }
@@ -149,7 +144,7 @@ public class TestJarIndexLoneClass {
149 assertThat(index.containsObfField(newField("a", "a", "Ljava/lang/String;")), is(true)); 144 assertThat(index.containsObfField(newField("a", "a", "Ljava/lang/String;")), is(true));
150 assertThat(index.containsObfField(newField("a", "b", "Ljava/lang/String;")), is(false)); 145 assertThat(index.containsObfField(newField("a", "b", "Ljava/lang/String;")), is(false));
151 assertThat(index.containsObfField(newField("a", "a", "LFoo;")), is(false)); 146 assertThat(index.containsObfField(newField("a", "a", "LFoo;")), is(false));
152 assertThat(index.containsObfBehavior(newMethod("a", "a", "()Ljava/lang/String;")), is(true)); 147 assertThat(index.containsObfMethod(newMethod("a", "a", "()Ljava/lang/String;")), is(true));
153 assertThat(index.containsObfBehavior(newMethod("a", "b", "()Ljava/lang/String;")), is(false)); 148 assertThat(index.containsObfMethod(newMethod("a", "b", "()Ljava/lang/String;")), is(false));
154 } 149 }
155} 150}
diff --git a/src/test/java/cuchaz/enigma/TestMethodDescriptor.java b/src/test/java/cuchaz/enigma/TestMethodDescriptor.java
new file mode 100644
index 00000000..48c46e52
--- /dev/null
+++ b/src/test/java/cuchaz/enigma/TestMethodDescriptor.java
@@ -0,0 +1,247 @@
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.mapping.MethodDescriptor;
15import cuchaz.enigma.mapping.TypeDescriptor;
16import org.junit.Test;
17
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.*;
20
21public class TestMethodDescriptor {
22
23 @Test
24 public void easiest() {
25 final MethodDescriptor sig = new MethodDescriptor("()V");
26 assertThat(sig.getArgumentDescs(), is(empty()));
27 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V")));
28 }
29
30 @Test
31 public void primitives() {
32 {
33 final MethodDescriptor sig = new MethodDescriptor("(I)V");
34 assertThat(sig.getArgumentDescs(), contains(
35 new TypeDescriptor("I")
36 ));
37 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V")));
38 }
39 {
40 final MethodDescriptor sig = new MethodDescriptor("(I)I");
41 assertThat(sig.getArgumentDescs(), contains(
42 new TypeDescriptor("I")
43 ));
44 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("I")));
45 }
46 {
47 final MethodDescriptor sig = new MethodDescriptor("(IBCJ)Z");
48 assertThat(sig.getArgumentDescs(), contains(
49 new TypeDescriptor("I"),
50 new TypeDescriptor("B"),
51 new TypeDescriptor("C"),
52 new TypeDescriptor("J")
53 ));
54 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("Z")));
55 }
56 }
57
58 @Test
59 public void classes() {
60 {
61 final MethodDescriptor sig = new MethodDescriptor("([LFoo;)V");
62 assertThat(sig.getArgumentDescs().size(), is(1));
63 assertThat(sig.getArgumentDescs().get(0), is(new TypeDescriptor("[LFoo;")));
64 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V")));
65 }
66 {
67 final MethodDescriptor sig = new MethodDescriptor("(LFoo;)LBar;");
68 assertThat(sig.getArgumentDescs(), contains(
69 new TypeDescriptor("LFoo;")
70 ));
71 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("LBar;")));
72 }
73 {
74 final MethodDescriptor sig = new MethodDescriptor("(LFoo;LMoo;LZoo;)LBar;");
75 assertThat(sig.getArgumentDescs(), contains(
76 new TypeDescriptor("LFoo;"),
77 new TypeDescriptor("LMoo;"),
78 new TypeDescriptor("LZoo;")
79 ));
80 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("LBar;")));
81 }
82 }
83
84 @Test
85 public void arrays() {
86 {
87 final MethodDescriptor sig = new MethodDescriptor("([I)V");
88 assertThat(sig.getArgumentDescs(), contains(
89 new TypeDescriptor("[I")
90 ));
91 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V")));
92 }
93 {
94 final MethodDescriptor sig = new MethodDescriptor("([I)[J");
95 assertThat(sig.getArgumentDescs(), contains(
96 new TypeDescriptor("[I")
97 ));
98 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("[J")));
99 }
100 {
101 final MethodDescriptor sig = new MethodDescriptor("([I[Z[F)[D");
102 assertThat(sig.getArgumentDescs(), contains(
103 new TypeDescriptor("[I"),
104 new TypeDescriptor("[Z"),
105 new TypeDescriptor("[F")
106 ));
107 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("[D")));
108 }
109 }
110
111 @Test
112 public void mixed() {
113 {
114 final MethodDescriptor sig = new MethodDescriptor("(I[JLFoo;)Z");
115 assertThat(sig.getArgumentDescs(), contains(
116 new TypeDescriptor("I"),
117 new TypeDescriptor("[J"),
118 new TypeDescriptor("LFoo;")
119 ));
120 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("Z")));
121 }
122 {
123 final MethodDescriptor sig = new MethodDescriptor("(III)[LFoo;");
124 assertThat(sig.getArgumentDescs(), contains(
125 new TypeDescriptor("I"),
126 new TypeDescriptor("I"),
127 new TypeDescriptor("I")
128 ));
129 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("[LFoo;")));
130 }
131 }
132
133 @Test
134 public void replaceClasses() {
135 {
136 final MethodDescriptor oldSig = new MethodDescriptor("()V");
137 final MethodDescriptor sig = oldSig.remap(s -> null);
138 assertThat(sig.getArgumentDescs(), is(empty()));
139 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V")));
140 }
141 {
142 final MethodDescriptor oldSig = new MethodDescriptor("(IJLFoo;)V");
143 final MethodDescriptor sig = oldSig.remap(s -> null);
144 assertThat(sig.getArgumentDescs(), contains(
145 new TypeDescriptor("I"),
146 new TypeDescriptor("J"),
147 new TypeDescriptor("LFoo;")
148 ));
149 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V")));
150 }
151 {
152 final MethodDescriptor oldSig = new MethodDescriptor("(LFoo;LBar;)LMoo;");
153 final MethodDescriptor sig = oldSig.remap(s -> {
154 if (s.equals("Foo")) {
155 return "Bar";
156 }
157 return null;
158 });
159 assertThat(sig.getArgumentDescs(), contains(
160 new TypeDescriptor("LBar;"),
161 new TypeDescriptor("LBar;")
162 ));
163 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("LMoo;")));
164 }
165 {
166 final MethodDescriptor oldSig = new MethodDescriptor("(LFoo;LBar;)LMoo;");
167 final MethodDescriptor sig = oldSig.remap(s -> {
168 if (s.equals("Moo")) {
169 return "Cow";
170 }
171 return null;
172 });
173 assertThat(sig.getArgumentDescs(), contains(
174 new TypeDescriptor("LFoo;"),
175 new TypeDescriptor("LBar;")
176 ));
177 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("LCow;")));
178 }
179 }
180
181 @Test
182 public void replaceArrayClasses() {
183 {
184 final MethodDescriptor oldSig = new MethodDescriptor("([LFoo;)[[[LBar;");
185 final MethodDescriptor sig = oldSig.remap(s -> {
186 if (s.equals("Foo")) {
187 return "Food";
188 } else if (s.equals("Bar")) {
189 return "Beer";
190 }
191 return null;
192 });
193 assertThat(sig.getArgumentDescs(), contains(
194 new TypeDescriptor("[LFood;")
195 ));
196 assertThat(sig.getReturnDesc(), is(new TypeDescriptor("[[[LBeer;")));
197 }
198 }
199
200 @Test
201 public void equals() {
202
203 // base
204 assertThat(new MethodDescriptor("()V"), is(new MethodDescriptor("()V")));
205
206 // arguments
207 assertThat(new MethodDescriptor("(I)V"), is(new MethodDescriptor("(I)V")));
208 assertThat(new MethodDescriptor("(ZIZ)V"), is(new MethodDescriptor("(ZIZ)V")));
209 assertThat(new MethodDescriptor("(LFoo;)V"), is(new MethodDescriptor("(LFoo;)V")));
210 assertThat(new MethodDescriptor("(LFoo;LBar;)V"), is(new MethodDescriptor("(LFoo;LBar;)V")));
211 assertThat(new MethodDescriptor("([I)V"), is(new MethodDescriptor("([I)V")));
212 assertThat(new MethodDescriptor("([[D[[[J)V"), is(new MethodDescriptor("([[D[[[J)V")));
213
214 assertThat(new MethodDescriptor("()V"), is(not(new MethodDescriptor("(I)V"))));
215 assertThat(new MethodDescriptor("(I)V"), is(not(new MethodDescriptor("()V"))));
216 assertThat(new MethodDescriptor("(IJ)V"), is(not(new MethodDescriptor("(JI)V"))));
217 assertThat(new MethodDescriptor("([[Z)V"), is(not(new MethodDescriptor("([[LFoo;)V"))));
218 assertThat(new MethodDescriptor("(LFoo;LBar;)V"), is(not(new MethodDescriptor("(LFoo;LCow;)V"))));
219 assertThat(new MethodDescriptor("([LFoo;LBar;)V"), is(not(new MethodDescriptor("(LFoo;LCow;)V"))));
220
221 // return desc
222 assertThat(new MethodDescriptor("()I"), is(new MethodDescriptor("()I")));
223 assertThat(new MethodDescriptor("()Z"), is(new MethodDescriptor("()Z")));
224 assertThat(new MethodDescriptor("()[D"), is(new MethodDescriptor("()[D")));
225 assertThat(new MethodDescriptor("()[[[Z"), is(new MethodDescriptor("()[[[Z")));
226 assertThat(new MethodDescriptor("()LFoo;"), is(new MethodDescriptor("()LFoo;")));
227 assertThat(new MethodDescriptor("()[LFoo;"), is(new MethodDescriptor("()[LFoo;")));
228
229 assertThat(new MethodDescriptor("()I"), is(not(new MethodDescriptor("()Z"))));
230 assertThat(new MethodDescriptor("()Z"), is(not(new MethodDescriptor("()I"))));
231 assertThat(new MethodDescriptor("()[D"), is(not(new MethodDescriptor("()[J"))));
232 assertThat(new MethodDescriptor("()[[[Z"), is(not(new MethodDescriptor("()[[Z"))));
233 assertThat(new MethodDescriptor("()LFoo;"), is(not(new MethodDescriptor("()LBar;"))));
234 assertThat(new MethodDescriptor("()[LFoo;"), is(not(new MethodDescriptor("()[LBar;"))));
235 }
236
237 @Test
238 public void testToString() {
239 assertThat(new MethodDescriptor("()V").toString(), is("()V"));
240 assertThat(new MethodDescriptor("(I)V").toString(), is("(I)V"));
241 assertThat(new MethodDescriptor("(ZIZ)V").toString(), is("(ZIZ)V"));
242 assertThat(new MethodDescriptor("(LFoo;)V").toString(), is("(LFoo;)V"));
243 assertThat(new MethodDescriptor("(LFoo;LBar;)V").toString(), is("(LFoo;LBar;)V"));
244 assertThat(new MethodDescriptor("([I)V").toString(), is("([I)V"));
245 assertThat(new MethodDescriptor("([[D[[[J)V").toString(), is("([[D[[[J)V"));
246 }
247}
diff --git a/src/test/java/cuchaz/enigma/TestSignature.java b/src/test/java/cuchaz/enigma/TestSignature.java
deleted file mode 100644
index 534b43ae..00000000
--- a/src/test/java/cuchaz/enigma/TestSignature.java
+++ /dev/null
@@ -1,270 +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.mapping.ClassNameReplacer;
15import cuchaz.enigma.mapping.Signature;
16import cuchaz.enigma.mapping.Type;
17import org.junit.Test;
18
19import static org.hamcrest.MatcherAssert.assertThat;
20import static org.hamcrest.Matchers.contains;
21import static org.hamcrest.Matchers.empty;
22import static org.hamcrest.Matchers.is;
23import static org.hamcrest.Matchers.not;
24
25public class TestSignature {
26
27 @Test
28 public void easiest() {
29 final Signature sig = new Signature("()V");
30 assertThat(sig.getArgumentTypes(), is(empty()));
31 assertThat(sig.getReturnType(), is(new Type("V")));
32 }
33
34 @Test
35 public void primitives() {
36 {
37 final Signature sig = new Signature("(I)V");
38 assertThat(sig.getArgumentTypes(), contains(
39 new Type("I")
40 ));
41 assertThat(sig.getReturnType(), is(new Type("V")));
42 }
43 {
44 final Signature sig = new Signature("(I)I");
45 assertThat(sig.getArgumentTypes(), contains(
46 new Type("I")
47 ));
48 assertThat(sig.getReturnType(), is(new Type("I")));
49 }
50 {
51 final Signature sig = new Signature("(IBCJ)Z");
52 assertThat(sig.getArgumentTypes(), contains(
53 new Type("I"),
54 new Type("B"),
55 new Type("C"),
56 new Type("J")
57 ));
58 assertThat(sig.getReturnType(), is(new Type("Z")));
59 }
60 }
61
62 @Test
63 public void classes() {
64 {
65 final Signature sig = new Signature("([LFoo;)V");
66 assertThat(sig.getArgumentTypes().size(), is(1));
67 assertThat(sig.getArgumentTypes().get(0), is(new Type("[LFoo;")));
68 assertThat(sig.getReturnType(), is(new Type("V")));
69 }
70 {
71 final Signature sig = new Signature("(LFoo;)LBar;");
72 assertThat(sig.getArgumentTypes(), contains(
73 new Type("LFoo;")
74 ));
75 assertThat(sig.getReturnType(), is(new Type("LBar;")));
76 }
77 {
78 final Signature sig = new Signature("(LFoo;LMoo;LZoo;)LBar;");
79 assertThat(sig.getArgumentTypes(), contains(
80 new Type("LFoo;"),
81 new Type("LMoo;"),
82 new Type("LZoo;")
83 ));
84 assertThat(sig.getReturnType(), is(new Type("LBar;")));
85 }
86 }
87
88 @Test
89 public void arrays() {
90 {
91 final Signature sig = new Signature("([I)V");
92 assertThat(sig.getArgumentTypes(), contains(
93 new Type("[I")
94 ));
95 assertThat(sig.getReturnType(), is(new Type("V")));
96 }
97 {
98 final Signature sig = new Signature("([I)[J");
99 assertThat(sig.getArgumentTypes(), contains(
100 new Type("[I")
101 ));
102 assertThat(sig.getReturnType(), is(new Type("[J")));
103 }
104 {
105 final Signature sig = new Signature("([I[Z[F)[D");
106 assertThat(sig.getArgumentTypes(), contains(
107 new Type("[I"),
108 new Type("[Z"),
109 new Type("[F")
110 ));
111 assertThat(sig.getReturnType(), is(new Type("[D")));
112 }
113 }
114
115 @Test
116 public void mixed() {
117 {
118 final Signature sig = new Signature("(I[JLFoo;)Z");
119 assertThat(sig.getArgumentTypes(), contains(
120 new Type("I"),
121 new Type("[J"),
122 new Type("LFoo;")
123 ));
124 assertThat(sig.getReturnType(), is(new Type("Z")));
125 }
126 {
127 final Signature sig = new Signature("(III)[LFoo;");
128 assertThat(sig.getArgumentTypes(), contains(
129 new Type("I"),
130 new Type("I"),
131 new Type("I")
132 ));
133 assertThat(sig.getReturnType(), is(new Type("[LFoo;")));
134 }
135 }
136
137 @Test
138 public void replaceClasses() {
139 {
140 final Signature oldSig = new Signature("()V");
141 final Signature sig = new Signature(oldSig, new ClassNameReplacer() {
142 @Override
143 public String replace(String val) {
144 return null;
145 }
146 });
147 assertThat(sig.getArgumentTypes(), is(empty()));
148 assertThat(sig.getReturnType(), is(new Type("V")));
149 }
150 {
151 final Signature oldSig = new Signature("(IJLFoo;)V");
152 final Signature sig = new Signature(oldSig, new ClassNameReplacer() {
153 @Override
154 public String replace(String val) {
155 return null;
156 }
157 });
158 assertThat(sig.getArgumentTypes(), contains(
159 new Type("I"),
160 new Type("J"),
161 new Type("LFoo;")
162 ));
163 assertThat(sig.getReturnType(), is(new Type("V")));
164 }
165 {
166 final Signature oldSig = new Signature("(LFoo;LBar;)LMoo;");
167 final Signature sig = new Signature(oldSig, new ClassNameReplacer() {
168 @Override
169 public String replace(String val) {
170 if (val.equals("Foo")) {
171 return "Bar";
172 }
173 return null;
174 }
175 });
176 assertThat(sig.getArgumentTypes(), contains(
177 new Type("LBar;"),
178 new Type("LBar;")
179 ));
180 assertThat(sig.getReturnType(), is(new Type("LMoo;")));
181 }
182 {
183 final Signature oldSig = new Signature("(LFoo;LBar;)LMoo;");
184 final Signature sig = new Signature(oldSig, new ClassNameReplacer() {
185 @Override
186 public String replace(String val) {
187 if (val.equals("Moo")) {
188 return "Cow";
189 }
190 return null;
191 }
192 });
193 assertThat(sig.getArgumentTypes(), contains(
194 new Type("LFoo;"),
195 new Type("LBar;")
196 ));
197 assertThat(sig.getReturnType(), is(new Type("LCow;")));
198 }
199 }
200
201 @Test
202 public void replaceArrayClasses() {
203 {
204 final Signature oldSig = new Signature("([LFoo;)[[[LBar;");
205 final Signature sig = new Signature(oldSig, new ClassNameReplacer() {
206 @Override
207 public String replace(String val) {
208 if (val.equals("Foo")) {
209 return "Food";
210 } else if (val.equals("Bar")) {
211 return "Beer";
212 }
213 return null;
214 }
215 });
216 assertThat(sig.getArgumentTypes(), contains(
217 new Type("[LFood;")
218 ));
219 assertThat(sig.getReturnType(), is(new Type("[[[LBeer;")));
220 }
221 }
222
223 @Test
224 public void equals() {
225
226 // base
227 assertThat(new Signature("()V"), is(new Signature("()V")));
228
229 // arguments
230 assertThat(new Signature("(I)V"), is(new Signature("(I)V")));
231 assertThat(new Signature("(ZIZ)V"), is(new Signature("(ZIZ)V")));
232 assertThat(new Signature("(LFoo;)V"), is(new Signature("(LFoo;)V")));
233 assertThat(new Signature("(LFoo;LBar;)V"), is(new Signature("(LFoo;LBar;)V")));
234 assertThat(new Signature("([I)V"), is(new Signature("([I)V")));
235 assertThat(new Signature("([[D[[[J)V"), is(new Signature("([[D[[[J)V")));
236
237 assertThat(new Signature("()V"), is(not(new Signature("(I)V"))));
238 assertThat(new Signature("(I)V"), is(not(new Signature("()V"))));
239 assertThat(new Signature("(IJ)V"), is(not(new Signature("(JI)V"))));
240 assertThat(new Signature("([[Z)V"), is(not(new Signature("([[LFoo;)V"))));
241 assertThat(new Signature("(LFoo;LBar;)V"), is(not(new Signature("(LFoo;LCow;)V"))));
242 assertThat(new Signature("([LFoo;LBar;)V"), is(not(new Signature("(LFoo;LCow;)V"))));
243
244 // return type
245 assertThat(new Signature("()I"), is(new Signature("()I")));
246 assertThat(new Signature("()Z"), is(new Signature("()Z")));
247 assertThat(new Signature("()[D"), is(new Signature("()[D")));
248 assertThat(new Signature("()[[[Z"), is(new Signature("()[[[Z")));
249 assertThat(new Signature("()LFoo;"), is(new Signature("()LFoo;")));
250 assertThat(new Signature("()[LFoo;"), is(new Signature("()[LFoo;")));
251
252 assertThat(new Signature("()I"), is(not(new Signature("()Z"))));
253 assertThat(new Signature("()Z"), is(not(new Signature("()I"))));
254 assertThat(new Signature("()[D"), is(not(new Signature("()[J"))));
255 assertThat(new Signature("()[[[Z"), is(not(new Signature("()[[Z"))));
256 assertThat(new Signature("()LFoo;"), is(not(new Signature("()LBar;"))));
257 assertThat(new Signature("()[LFoo;"), is(not(new Signature("()[LBar;"))));
258 }
259
260 @Test
261 public void testToString() {
262 assertThat(new Signature("()V").toString(), is("()V"));
263 assertThat(new Signature("(I)V").toString(), is("(I)V"));
264 assertThat(new Signature("(ZIZ)V").toString(), is("(ZIZ)V"));
265 assertThat(new Signature("(LFoo;)V").toString(), is("(LFoo;)V"));
266 assertThat(new Signature("(LFoo;LBar;)V").toString(), is("(LFoo;LBar;)V"));
267 assertThat(new Signature("([I)V").toString(), is("([I)V"));
268 assertThat(new Signature("([[D[[[J)V").toString(), is("([[D[[[J)V"));
269 }
270}
diff --git a/src/test/java/cuchaz/enigma/TestTokensConstructors.java b/src/test/java/cuchaz/enigma/TestTokensConstructors.java
index e40d5fdc..0148f2c3 100644
--- a/src/test/java/cuchaz/enigma/TestTokensConstructors.java
+++ b/src/test/java/cuchaz/enigma/TestTokensConstructors.java
@@ -11,131 +11,127 @@
11 11
12package cuchaz.enigma; 12package cuchaz.enigma;
13 13
14import cuchaz.enigma.mapping.BehaviorEntry; 14import cuchaz.enigma.mapping.MethodEntry;
15import org.junit.Test; 15import org.junit.Test;
16 16
17import java.util.jar.JarFile; 17import java.util.jar.JarFile;
18 18
19import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByConstructor;
20import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod; 19import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod;
21import static cuchaz.enigma.TestEntryFactory.newConstructor; 20import static cuchaz.enigma.TestEntryFactory.newMethod;
22import static org.hamcrest.MatcherAssert.assertThat; 21import static org.hamcrest.MatcherAssert.assertThat;
23import static org.hamcrest.Matchers.containsInAnyOrder; 22import static org.hamcrest.Matchers.*;
24import static org.hamcrest.Matchers.empty;
25import static org.hamcrest.Matchers.is;
26import static org.hamcrest.Matchers.nullValue;
27 23
28public class TestTokensConstructors extends TokenChecker { 24public class TestTokensConstructors extends TokenChecker {
29 25
30 public TestTokensConstructors() 26 public TestTokensConstructors()
31 throws Exception { 27 throws Exception {
32 super(new JarFile("build/test-obf/constructors.jar")); 28 super(new JarFile("build/test-obf/constructors.jar"));
33 } 29 }
34 30
35 @Test 31 @Test
36 public void baseDeclarations() { 32 public void baseDeclarations() {
37 assertThat(getDeclarationToken(newConstructor("a", "()V")), is("a")); 33 assertThat(getDeclarationToken(newMethod("a", "<init>", "()V")), is("a"));
38 assertThat(getDeclarationToken(newConstructor("a", "(I)V")), is("a")); 34 assertThat(getDeclarationToken(newMethod("a", "<init>", "(I)V")), is("a"));
39 } 35 }
40 36
41 @Test 37 @Test
42 public void subDeclarations() { 38 public void subDeclarations() {
43 assertThat(getDeclarationToken(newConstructor("d", "()V")), is("d")); 39 assertThat(getDeclarationToken(newMethod("d", "<init>", "()V")), is("d"));
44 assertThat(getDeclarationToken(newConstructor("d", "(I)V")), is("d")); 40 assertThat(getDeclarationToken(newMethod("d", "<init>", "(I)V")), is("d"));
45 assertThat(getDeclarationToken(newConstructor("d", "(II)V")), is("d")); 41 assertThat(getDeclarationToken(newMethod("d", "<init>", "(II)V")), is("d"));
46 assertThat(getDeclarationToken(newConstructor("d", "(III)V")), is("d")); 42 assertThat(getDeclarationToken(newMethod("d", "<init>", "(III)V")), is("d"));
47 } 43 }
48 44
49 @Test 45 @Test
50 public void subsubDeclarations() { 46 public void subsubDeclarations() {
51 assertThat(getDeclarationToken(newConstructor("e", "(I)V")), is("e")); 47 assertThat(getDeclarationToken(newMethod("e", "<init>", "(I)V")), is("e"));
52 } 48 }
53 49
54 @Test 50 @Test
55 public void defaultDeclarations() { 51 public void defaultDeclarations() {
56 assertThat(getDeclarationToken(newConstructor("c", "()V")), nullValue()); 52 assertThat(getDeclarationToken(newMethod("c", "<init>", "()V")), nullValue());
57 } 53 }
58 54
59 @Test 55 @Test
60 public void baseDefaultReferences() { 56 public void baseDefaultReferences() {
61 BehaviorEntry source = newConstructor("a", "()V"); 57 MethodEntry source = newMethod("a", "<init>", "()V");
62 assertThat( 58 assertThat(
63 getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "a", "()V")), 59 getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "a", "()V")),
64 containsInAnyOrder("a") 60 containsInAnyOrder("a")
65 ); 61 );
66 assertThat( 62 assertThat(
67 getReferenceTokens(newBehaviorReferenceByConstructor(source, "d", "()V")), 63 getReferenceTokens(newBehaviorReferenceByMethod(source, "d", "<init>", "()V")),
68 is(empty()) // implicit call, not decompiled to token 64 is(empty()) // implicit call, not decompiled to token
69 ); 65 );
70 assertThat( 66 assertThat(
71 getReferenceTokens(newBehaviorReferenceByConstructor(source, "d", "(III)V")), 67 getReferenceTokens(newBehaviorReferenceByMethod(source, "d", "<init>", "(III)V")),
72 is(empty()) // implicit call, not decompiled to token 68 is(empty()) // implicit call, not decompiled to token
73 ); 69 );
74 } 70 }
75 71
76 @Test 72 @Test
77 public void baseIntReferences() { 73 public void baseIntReferences() {
78 BehaviorEntry source = newConstructor("a", "(I)V"); 74 MethodEntry source = newMethod("a", "<init>", "(I)V");
79 assertThat( 75 assertThat(
80 getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "b", "()V")), 76 getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "b", "()V")),
81 containsInAnyOrder("a") 77 containsInAnyOrder("a")
82 ); 78 );
83 } 79 }
84 80
85 @Test 81 @Test
86 public void subDefaultReferences() { 82 public void subDefaultReferences() {
87 BehaviorEntry source = newConstructor("d", "()V"); 83 MethodEntry source = newMethod("d", "<init>", "()V");
88 assertThat( 84 assertThat(
89 getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "c", "()V")), 85 getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "c", "()V")),
90 containsInAnyOrder("d") 86 containsInAnyOrder("d")
91 ); 87 );
92 assertThat( 88 assertThat(
93 getReferenceTokens(newBehaviorReferenceByConstructor(source, "d", "(I)V")), 89 getReferenceTokens(newBehaviorReferenceByMethod(source, "d", "<init>", "(I)V")),
94 containsInAnyOrder("this") 90 containsInAnyOrder("this")
95 ); 91 );
96 } 92 }
97 93
98 @Test 94 @Test
99 public void subIntReferences() { 95 public void subIntReferences() {
100 BehaviorEntry source = newConstructor("d", "(I)V"); 96 MethodEntry source = newMethod("d", "<init>", "(I)V");
101 assertThat(getReferenceTokens( 97 assertThat(getReferenceTokens(
102 newBehaviorReferenceByMethod(source, "b", "d", "()V")), 98 newBehaviorReferenceByMethod(source, "b", "d", "()V")),
103 containsInAnyOrder("d") 99 containsInAnyOrder("d")
104 ); 100 );
105 assertThat(getReferenceTokens( 101 assertThat(getReferenceTokens(
106 newBehaviorReferenceByConstructor(source, "d", "(II)V")), 102 newBehaviorReferenceByMethod(source, "d", "<init>", "(II)V")),
107 containsInAnyOrder("this") 103 containsInAnyOrder("this")
108 ); 104 );
109 assertThat(getReferenceTokens( 105 assertThat(getReferenceTokens(
110 newBehaviorReferenceByConstructor(source, "e", "(I)V")), 106 newBehaviorReferenceByMethod(source, "e", "<init>", "(I)V")),
111 containsInAnyOrder("super") 107 containsInAnyOrder("super")
112 ); 108 );
113 } 109 }
114 110
115 @Test 111 @Test
116 public void subIntIntReferences() { 112 public void subIntIntReferences() {
117 BehaviorEntry source = newConstructor("d", "(II)V"); 113 MethodEntry source = newMethod("d", "<init>", "(II)V");
118 assertThat( 114 assertThat(
119 getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "e", "()V")), 115 getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "e", "()V")),
120 containsInAnyOrder("d") 116 containsInAnyOrder("d")
121 ); 117 );
122 } 118 }
123 119
124 @Test 120 @Test
125 public void subsubIntReferences() { 121 public void subsubIntReferences() {
126 BehaviorEntry source = newConstructor("e", "(I)V"); 122 MethodEntry source = newMethod("e", "<init>", "(I)V");
127 assertThat( 123 assertThat(
128 getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "f", "()V")), 124 getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "f", "()V")),
129 containsInAnyOrder("e") 125 containsInAnyOrder("e")
130 ); 126 );
131 } 127 }
132 128
133 @Test 129 @Test
134 public void defaultConstructableReferences() { 130 public void defaultConstructableReferences() {
135 BehaviorEntry source = newConstructor("c", "()V"); 131 MethodEntry source = newMethod("c", "<init>", "()V");
136 assertThat( 132 assertThat(
137 getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "g", "()V")), 133 getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "g", "()V")),
138 containsInAnyOrder("c") 134 containsInAnyOrder("c")
139 ); 135 );
140 } 136 }
141} 137}
diff --git a/src/test/java/cuchaz/enigma/TestTypeDescriptor.java b/src/test/java/cuchaz/enigma/TestTypeDescriptor.java
new file mode 100644
index 00000000..b874f629
--- /dev/null
+++ b/src/test/java/cuchaz/enigma/TestTypeDescriptor.java
@@ -0,0 +1,243 @@
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.mapping.TypeDescriptor;
15import org.junit.Test;
16
17import static cuchaz.enigma.TestEntryFactory.newClass;
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.is;
20import static org.hamcrest.Matchers.not;
21
22public class TestTypeDescriptor {
23
24 @Test
25 public void isVoid() {
26 assertThat(new TypeDescriptor("V").isVoid(), is(true));
27 assertThat(new TypeDescriptor("Z").isVoid(), is(false));
28 assertThat(new TypeDescriptor("B").isVoid(), is(false));
29 assertThat(new TypeDescriptor("C").isVoid(), is(false));
30 assertThat(new TypeDescriptor("I").isVoid(), is(false));
31 assertThat(new TypeDescriptor("J").isVoid(), is(false));
32 assertThat(new TypeDescriptor("F").isVoid(), is(false));
33 assertThat(new TypeDescriptor("D").isVoid(), is(false));
34 assertThat(new TypeDescriptor("LFoo;").isVoid(), is(false));
35 assertThat(new TypeDescriptor("[I").isVoid(), is(false));
36 }
37
38 @Test
39 public void isPrimitive() {
40 assertThat(new TypeDescriptor("V").isPrimitive(), is(false));
41 assertThat(new TypeDescriptor("Z").isPrimitive(), is(true));
42 assertThat(new TypeDescriptor("B").isPrimitive(), is(true));
43 assertThat(new TypeDescriptor("C").isPrimitive(), is(true));
44 assertThat(new TypeDescriptor("I").isPrimitive(), is(true));
45 assertThat(new TypeDescriptor("J").isPrimitive(), is(true));
46 assertThat(new TypeDescriptor("F").isPrimitive(), is(true));
47 assertThat(new TypeDescriptor("D").isPrimitive(), is(true));
48 assertThat(new TypeDescriptor("LFoo;").isPrimitive(), is(false));
49 assertThat(new TypeDescriptor("[I").isPrimitive(), is(false));
50 }
51
52 @Test
53 public void getPrimitive() {
54 assertThat(new TypeDescriptor("Z").getPrimitive(), is(TypeDescriptor.Primitive.Boolean));
55 assertThat(new TypeDescriptor("B").getPrimitive(), is(TypeDescriptor.Primitive.Byte));
56 assertThat(new TypeDescriptor("C").getPrimitive(), is(TypeDescriptor.Primitive.Character));
57 assertThat(new TypeDescriptor("I").getPrimitive(), is(TypeDescriptor.Primitive.Integer));
58 assertThat(new TypeDescriptor("J").getPrimitive(), is(TypeDescriptor.Primitive.Long));
59 assertThat(new TypeDescriptor("F").getPrimitive(), is(TypeDescriptor.Primitive.Float));
60 assertThat(new TypeDescriptor("D").getPrimitive(), is(TypeDescriptor.Primitive.Double));
61 }
62
63 @Test
64 public void isClass() {
65 assertThat(new TypeDescriptor("V").isType(), is(false));
66 assertThat(new TypeDescriptor("Z").isType(), is(false));
67 assertThat(new TypeDescriptor("B").isType(), is(false));
68 assertThat(new TypeDescriptor("C").isType(), is(false));
69 assertThat(new TypeDescriptor("I").isType(), is(false));
70 assertThat(new TypeDescriptor("J").isType(), is(false));
71 assertThat(new TypeDescriptor("F").isType(), is(false));
72 assertThat(new TypeDescriptor("D").isType(), is(false));
73 assertThat(new TypeDescriptor("LFoo;").isType(), is(true));
74 assertThat(new TypeDescriptor("[I").isType(), is(false));
75 }
76
77 @Test
78 public void getClassEntry() {
79 assertThat(new TypeDescriptor("LFoo;").getOwnerEntry(), is(newClass("Foo")));
80 assertThat(new TypeDescriptor("Ljava/lang/String;").getOwnerEntry(), is(newClass("java/lang/String")));
81 }
82
83 @Test
84 public void getArrayClassEntry() {
85 assertThat(new TypeDescriptor("[LFoo;").getOwnerEntry(), is(newClass("Foo")));
86 assertThat(new TypeDescriptor("[[[Ljava/lang/String;").getOwnerEntry(), is(newClass("java/lang/String")));
87 }
88
89 @Test
90 public void isArray() {
91 assertThat(new TypeDescriptor("V").isArray(), is(false));
92 assertThat(new TypeDescriptor("Z").isArray(), is(false));
93 assertThat(new TypeDescriptor("B").isArray(), is(false));
94 assertThat(new TypeDescriptor("C").isArray(), is(false));
95 assertThat(new TypeDescriptor("I").isArray(), is(false));
96 assertThat(new TypeDescriptor("J").isArray(), is(false));
97 assertThat(new TypeDescriptor("F").isArray(), is(false));
98 assertThat(new TypeDescriptor("D").isArray(), is(false));
99 assertThat(new TypeDescriptor("LFoo;").isArray(), is(false));
100 assertThat(new TypeDescriptor("[I").isArray(), is(true));
101 }
102
103 @Test
104 public void getArrayDimension() {
105 assertThat(new TypeDescriptor("[I").getArrayDimension(), is(1));
106 assertThat(new TypeDescriptor("[[I").getArrayDimension(), is(2));
107 assertThat(new TypeDescriptor("[[[I").getArrayDimension(), is(3));
108 }
109
110 @Test
111 public void getArrayType() {
112 assertThat(new TypeDescriptor("[I").getArrayType(), is(new TypeDescriptor("I")));
113 assertThat(new TypeDescriptor("[[I").getArrayType(), is(new TypeDescriptor("I")));
114 assertThat(new TypeDescriptor("[[[I").getArrayType(), is(new TypeDescriptor("I")));
115 assertThat(new TypeDescriptor("[Ljava/lang/String;").getArrayType(), is(new TypeDescriptor("Ljava/lang/String;")));
116 }
117
118 @Test
119 public void hasClass() {
120 assertThat(new TypeDescriptor("LFoo;").containsType(), is(true));
121 assertThat(new TypeDescriptor("Ljava/lang/String;").containsType(), is(true));
122 assertThat(new TypeDescriptor("[LBar;").containsType(), is(true));
123 assertThat(new TypeDescriptor("[[[LCat;").containsType(), is(true));
124
125 assertThat(new TypeDescriptor("V").containsType(), is(false));
126 assertThat(new TypeDescriptor("[I").containsType(), is(false));
127 assertThat(new TypeDescriptor("[[[I").containsType(), is(false));
128 assertThat(new TypeDescriptor("Z").containsType(), is(false));
129 }
130
131 @Test
132 public void parseVoid() {
133 final String answer = "V";
134 assertThat(TypeDescriptor.parseFirst("V"), is(answer));
135 assertThat(TypeDescriptor.parseFirst("VVV"), is(answer));
136 assertThat(TypeDescriptor.parseFirst("VIJ"), is(answer));
137 assertThat(TypeDescriptor.parseFirst("V[I"), is(answer));
138 assertThat(TypeDescriptor.parseFirst("VLFoo;"), is(answer));
139 assertThat(TypeDescriptor.parseFirst("V[LFoo;"), is(answer));
140 }
141
142 @Test
143 public void parsePrimitive() {
144 final String answer = "I";
145 assertThat(TypeDescriptor.parseFirst("I"), is(answer));
146 assertThat(TypeDescriptor.parseFirst("III"), is(answer));
147 assertThat(TypeDescriptor.parseFirst("IJZ"), is(answer));
148 assertThat(TypeDescriptor.parseFirst("I[I"), is(answer));
149 assertThat(TypeDescriptor.parseFirst("ILFoo;"), is(answer));
150 assertThat(TypeDescriptor.parseFirst("I[LFoo;"), is(answer));
151 }
152
153 @Test
154 public void parseClass() {
155 {
156 final String answer = "LFoo;";
157 assertThat(TypeDescriptor.parseFirst("LFoo;"), is(answer));
158 assertThat(TypeDescriptor.parseFirst("LFoo;I"), is(answer));
159 assertThat(TypeDescriptor.parseFirst("LFoo;JZ"), is(answer));
160 assertThat(TypeDescriptor.parseFirst("LFoo;[I"), is(answer));
161 assertThat(TypeDescriptor.parseFirst("LFoo;LFoo;"), is(answer));
162 assertThat(TypeDescriptor.parseFirst("LFoo;[LFoo;"), is(answer));
163 }
164 {
165 final String answer = "Ljava/lang/String;";
166 assertThat(TypeDescriptor.parseFirst("Ljava/lang/String;"), is(answer));
167 assertThat(TypeDescriptor.parseFirst("Ljava/lang/String;I"), is(answer));
168 assertThat(TypeDescriptor.parseFirst("Ljava/lang/String;JZ"), is(answer));
169 assertThat(TypeDescriptor.parseFirst("Ljava/lang/String;[I"), is(answer));
170 assertThat(TypeDescriptor.parseFirst("Ljava/lang/String;LFoo;"), is(answer));
171 assertThat(TypeDescriptor.parseFirst("Ljava/lang/String;[LFoo;"), is(answer));
172 }
173 }
174
175 @Test
176 public void parseArray() {
177 {
178 final String answer = "[I";
179 assertThat(TypeDescriptor.parseFirst("[I"), is(answer));
180 assertThat(TypeDescriptor.parseFirst("[III"), is(answer));
181 assertThat(TypeDescriptor.parseFirst("[IJZ"), is(answer));
182 assertThat(TypeDescriptor.parseFirst("[I[I"), is(answer));
183 assertThat(TypeDescriptor.parseFirst("[ILFoo;"), is(answer));
184 }
185 {
186 final String answer = "[[I";
187 assertThat(TypeDescriptor.parseFirst("[[I"), is(answer));
188 assertThat(TypeDescriptor.parseFirst("[[III"), is(answer));
189 assertThat(TypeDescriptor.parseFirst("[[IJZ"), is(answer));
190 assertThat(TypeDescriptor.parseFirst("[[I[I"), is(answer));
191 assertThat(TypeDescriptor.parseFirst("[[ILFoo;"), is(answer));
192 }
193 {
194 final String answer = "[LFoo;";
195 assertThat(TypeDescriptor.parseFirst("[LFoo;"), is(answer));
196 assertThat(TypeDescriptor.parseFirst("[LFoo;II"), is(answer));
197 assertThat(TypeDescriptor.parseFirst("[LFoo;JZ"), is(answer));
198 assertThat(TypeDescriptor.parseFirst("[LFoo;[I"), is(answer));
199 assertThat(TypeDescriptor.parseFirst("[LFoo;LFoo;"), is(answer));
200 }
201 }
202
203 @Test
204 public void equals() {
205 assertThat(new TypeDescriptor("V"), is(new TypeDescriptor("V")));
206 assertThat(new TypeDescriptor("Z"), is(new TypeDescriptor("Z")));
207 assertThat(new TypeDescriptor("B"), is(new TypeDescriptor("B")));
208 assertThat(new TypeDescriptor("C"), is(new TypeDescriptor("C")));
209 assertThat(new TypeDescriptor("I"), is(new TypeDescriptor("I")));
210 assertThat(new TypeDescriptor("J"), is(new TypeDescriptor("J")));
211 assertThat(new TypeDescriptor("F"), is(new TypeDescriptor("F")));
212 assertThat(new TypeDescriptor("D"), is(new TypeDescriptor("D")));
213 assertThat(new TypeDescriptor("LFoo;"), is(new TypeDescriptor("LFoo;")));
214 assertThat(new TypeDescriptor("[I"), is(new TypeDescriptor("[I")));
215 assertThat(new TypeDescriptor("[[[I"), is(new TypeDescriptor("[[[I")));
216 assertThat(new TypeDescriptor("[LFoo;"), is(new TypeDescriptor("[LFoo;")));
217
218 assertThat(new TypeDescriptor("V"), is(not(new TypeDescriptor("I"))));
219 assertThat(new TypeDescriptor("I"), is(not(new TypeDescriptor("J"))));
220 assertThat(new TypeDescriptor("I"), is(not(new TypeDescriptor("LBar;"))));
221 assertThat(new TypeDescriptor("I"), is(not(new TypeDescriptor("[I"))));
222 assertThat(new TypeDescriptor("LFoo;"), is(not(new TypeDescriptor("LBar;"))));
223 assertThat(new TypeDescriptor("[I"), is(not(new TypeDescriptor("[Z"))));
224 assertThat(new TypeDescriptor("[[[I"), is(not(new TypeDescriptor("[I"))));
225 assertThat(new TypeDescriptor("[LFoo;"), is(not(new TypeDescriptor("[LBar;"))));
226 }
227
228 @Test
229 public void testToString() {
230 assertThat(new TypeDescriptor("V").toString(), is("V"));
231 assertThat(new TypeDescriptor("Z").toString(), is("Z"));
232 assertThat(new TypeDescriptor("B").toString(), is("B"));
233 assertThat(new TypeDescriptor("C").toString(), is("C"));
234 assertThat(new TypeDescriptor("I").toString(), is("I"));
235 assertThat(new TypeDescriptor("J").toString(), is("J"));
236 assertThat(new TypeDescriptor("F").toString(), is("F"));
237 assertThat(new TypeDescriptor("D").toString(), is("D"));
238 assertThat(new TypeDescriptor("LFoo;").toString(), is("LFoo;"));
239 assertThat(new TypeDescriptor("[I").toString(), is("[I"));
240 assertThat(new TypeDescriptor("[[[I").toString(), is("[[[I"));
241 assertThat(new TypeDescriptor("[LFoo;").toString(), is("[LFoo;"));
242 }
243}