summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/cuchaz/enigma/EntryFactory.java52
-rw-r--r--test/cuchaz/enigma/TestDeobfuscator.java13
-rw-r--r--test/cuchaz/enigma/TestJarIndexLoneClass.java201
-rw-r--r--test/cuchaz/enigma/inputs/loneClass/LoneClass.java (renamed from test/cuchaz/enigma/inputs/LoneClass.java)2
4 files changed, 266 insertions, 2 deletions
diff --git a/test/cuchaz/enigma/EntryFactory.java b/test/cuchaz/enigma/EntryFactory.java
new file mode 100644
index 00000000..b275719b
--- /dev/null
+++ b/test/cuchaz/enigma/EntryFactory.java
@@ -0,0 +1,52 @@
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 ******************************************************************************/
12package cuchaz.enigma;
13
14import cuchaz.enigma.analysis.EntryReference;
15import cuchaz.enigma.mapping.BehaviorEntry;
16import cuchaz.enigma.mapping.ClassEntry;
17import cuchaz.enigma.mapping.ConstructorEntry;
18import cuchaz.enigma.mapping.FieldEntry;
19import cuchaz.enigma.mapping.MethodEntry;
20
21public class EntryFactory
22{
23 public static ClassEntry newClass( String name )
24 {
25 return new ClassEntry( name );
26 }
27
28 public static FieldEntry newField( String className, String fieldName )
29 {
30 return new FieldEntry( newClass( className ), fieldName );
31 }
32
33 public static MethodEntry newMethod( String className, String methodName, String methodSignature )
34 {
35 return new MethodEntry( newClass( className ), methodName, methodSignature );
36 }
37
38 public static ConstructorEntry newConstructor( String className, String signature )
39 {
40 return new ConstructorEntry( newClass( className ), signature );
41 }
42
43 public static EntryReference<FieldEntry,BehaviorEntry> newFieldReferenceByMethod( String fieldClassName, String fieldName, String callerClassName, String callerName, String callerSignature )
44 {
45 return new EntryReference<FieldEntry,BehaviorEntry>( newField( fieldClassName, fieldName ), newMethod( callerClassName, callerName, callerSignature ) );
46 }
47
48 public static EntryReference<FieldEntry,BehaviorEntry> newFieldReferenceByConstructor( String fieldClassName, String fieldName, String callerClassName, String callerSignature )
49 {
50 return new EntryReference<FieldEntry,BehaviorEntry>( newField( fieldClassName, fieldName ), newConstructor( callerClassName, callerSignature ) );
51 }
52}
diff --git a/test/cuchaz/enigma/TestDeobfuscator.java b/test/cuchaz/enigma/TestDeobfuscator.java
index 3310fbcc..3e679fb9 100644
--- a/test/cuchaz/enigma/TestDeobfuscator.java
+++ b/test/cuchaz/enigma/TestDeobfuscator.java
@@ -1,3 +1,14 @@
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 ******************************************************************************/
1package cuchaz.enigma; 12package cuchaz.enigma;
2 13
3import static org.junit.Assert.*; 14import static org.junit.Assert.*;
@@ -17,7 +28,7 @@ public class TestDeobfuscator
17 private Deobfuscator getDeobfuscator( ) 28 private Deobfuscator getDeobfuscator( )
18 throws IOException 29 throws IOException
19 { 30 {
20 return new Deobfuscator( new File( "build/libs/testCases.obf.jar" ) ); 31 return new Deobfuscator( new File( "build/libs/testLoneClass.obf.jar" ) );
21 } 32 }
22 33
23 @Test 34 @Test
diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java
new file mode 100644
index 00000000..56031ddc
--- /dev/null
+++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java
@@ -0,0 +1,201 @@
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 ******************************************************************************/
12package cuchaz.enigma;
13
14import static cuchaz.enigma.EntryFactory.newClass;
15import static cuchaz.enigma.EntryFactory.newField;
16import static cuchaz.enigma.EntryFactory.newFieldReferenceByConstructor;
17import static cuchaz.enigma.EntryFactory.newFieldReferenceByMethod;
18import static cuchaz.enigma.EntryFactory.newMethod;
19import static org.hamcrest.MatcherAssert.assertThat;
20import static org.hamcrest.Matchers.containsInAnyOrder;
21import static org.hamcrest.Matchers.empty;
22import static org.hamcrest.Matchers.is;
23import static org.hamcrest.Matchers.not;
24import static org.hamcrest.Matchers.nullValue;
25
26import java.util.Collection;
27import java.util.Set;
28import java.util.jar.JarFile;
29
30import org.junit.Test;
31
32import cuchaz.enigma.analysis.Access;
33import cuchaz.enigma.analysis.ClassImplementationsTreeNode;
34import cuchaz.enigma.analysis.ClassInheritanceTreeNode;
35import cuchaz.enigma.analysis.EntryReference;
36import cuchaz.enigma.analysis.JarIndex;
37import cuchaz.enigma.analysis.MethodImplementationsTreeNode;
38import cuchaz.enigma.analysis.MethodInheritanceTreeNode;
39import cuchaz.enigma.mapping.BehaviorEntry;
40import cuchaz.enigma.mapping.FieldEntry;
41import cuchaz.enigma.mapping.MethodEntry;
42import cuchaz.enigma.mapping.Translator;
43
44public class TestJarIndexLoneClass
45{
46 private JarIndex m_index;
47
48 public TestJarIndexLoneClass( )
49 throws Exception
50 {
51 m_index = new JarIndex();
52 m_index.indexJar( new JarFile( "build/libs/testLoneClass.obf.jar" ), false );
53 }
54
55 @Test
56 public void obfEntries( )
57 {
58 assertThat( m_index.getObfClassEntries(), containsInAnyOrder(
59 newClass( "cuchaz/enigma/inputs/Keep" ),
60 newClass( "none/a" )
61 ) );
62 }
63
64 @Test
65 public void translationIndex( )
66 {
67 assertThat( m_index.getTranslationIndex().getSuperclassName( "none/a" ), is( nullValue() ) );
68 assertThat( m_index.getTranslationIndex().getSuperclassName( "cuchaz/enigma/inputs/Keep" ), is( nullValue() ) );
69 assertThat( m_index.getTranslationIndex().getAncestry( "none/a" ), is( empty() ) );
70 assertThat( m_index.getTranslationIndex().getAncestry( "cuchaz/enigma/inputs/Keep" ), is( empty() ) );
71 assertThat( m_index.getTranslationIndex().getSubclassNames( "none/a" ), is( empty() ) );
72 assertThat( m_index.getTranslationIndex().getSubclassNames( "cuchaz/enigma/inputs/Keep" ), is( empty() ) );
73 }
74
75 @Test
76 public void access( )
77 {
78 assertThat( m_index.getAccess( newField( "none/a", "a" ) ), is( Access.Private ) );
79 assertThat( m_index.getAccess( newMethod( "none/a", "a", "()Ljava/lang/String;" ) ), is( Access.Public ) );
80 assertThat( m_index.getAccess( newField( "none/a", "b" ) ), is( nullValue() ) );
81 }
82
83 @Test
84 public void isImplemented( )
85 {
86 assertThat( m_index.isMethodImplemented( newMethod( "none/a", "a", "()Ljava/lang/String;" ) ), is( true ) );
87 assertThat( m_index.isMethodImplemented( newMethod( "none/a", "b", "()Ljava/lang/String;" ) ), is( false ) );
88 }
89
90 @Test
91 public void classInheritance( )
92 {
93 ClassInheritanceTreeNode node = m_index.getClassInheritance( new Translator(), newClass( "none/a" ) );
94 assertThat( node, is( not( nullValue() ) ) );
95 assertThat( node.getObfClassName(), is( "none/a" ) );
96 assertThat( node.getChildCount(), is( 0 ) );
97 }
98
99
100 @Test
101 public void methodInheritance( )
102 {
103 MethodEntry source = newMethod( "none/a", "a", "()Ljava/lang/String;" );
104 MethodInheritanceTreeNode node = m_index.getMethodInheritance( new Translator(), source );
105 assertThat( node, is( not( nullValue() ) ) );
106 assertThat( node.getMethodEntry(), is( source ) );
107 assertThat( node.getChildCount(), is( 0 ) );
108 }
109
110 @Test
111 public void classImplementations( )
112 {
113 ClassImplementationsTreeNode node = m_index.getClassImplementations( new Translator(), newClass( "none/a" ) );
114 assertThat( node, is( nullValue() ) );
115 }
116
117 @Test
118 public void methodImplementations( )
119 {
120 MethodEntry source = newMethod( "none/a", "a", "()Ljava/lang/String;" );
121 MethodImplementationsTreeNode node = m_index.getMethodImplementations( new Translator(), source );
122 assertThat( node, is( nullValue() ) );
123 }
124
125 @Test
126 public void relatedMethodImplementations( )
127 {
128 Set<MethodEntry> entries = m_index.getRelatedMethodImplementations( newMethod( "none/a", "a", "()Ljava/lang/String;" ) );
129 assertThat( entries, containsInAnyOrder( newMethod( "none/a", "a", "()Ljava/lang/String;" ) ) );
130 }
131
132 @Test
133 @SuppressWarnings( "unchecked" )
134 public void fieldReferences( )
135 {
136 Collection<EntryReference<FieldEntry,BehaviorEntry>> references = m_index.getFieldReferences( newField( "none/a", "a" ) );
137 assertThat( references, containsInAnyOrder(
138 newFieldReferenceByConstructor( "none/a", "a", "none/a", "(Ljava/lang/String;)V" ),
139 newFieldReferenceByMethod( "none/a", "a", "none/a", "a", "()Ljava/lang/String;" )
140 ) );
141 }
142
143 @Test
144 public void behaviorReferences( )
145 {
146 assertThat( m_index.getBehaviorReferences( newMethod( "none/a", "a", "()Ljava/lang/String;" ) ), is( empty() ) );
147 }
148
149 @Test
150 public void innerClasses( )
151 {
152 assertThat( m_index.getInnerClasses( "none/a" ), is( empty() ) );
153 }
154
155 @Test
156 public void outerClass( )
157 {
158 assertThat( m_index.getOuterClass( "none/a" ), is( nullValue() ) );
159 }
160
161 @Test
162 public void isAnonymousClass( )
163 {
164 assertThat( m_index.isAnonymousClass( "none/a" ), is( false ) );
165 }
166
167 @Test
168 public void interfaces( )
169 {
170 assertThat( m_index.getInterfaces( "none/a" ), is( empty() ) );
171 }
172
173 @Test
174 public void implementingClasses( )
175 {
176 assertThat( m_index.getImplementingClasses( "none/a" ), is( empty() ) );
177 }
178
179 @Test
180 public void isInterface( )
181 {
182 assertThat( m_index.isInterface( "none/a" ), is( false ) );
183 }
184
185 @Test
186 public void bridgeMethods( )
187 {
188 assertThat( m_index.getBridgeMethod( newMethod( "none/a", "a", "()Ljava/lang/String;" ) ), is( nullValue() ) );
189 }
190
191 @Test
192 public void contains( )
193 {
194 assertThat( m_index.containsObfClass( newClass( "none/a" ) ), is( true ) );
195 assertThat( m_index.containsObfClass( newClass( "none/b" ) ), is( false ) );
196 assertThat( m_index.containsObfField( newField( "none/a", "a" ) ), is( true ) );
197 assertThat( m_index.containsObfField( newField( "none/a", "b" ) ), is( false ) );
198 assertThat( m_index.containsObfMethod( newMethod( "none/a", "a", "()Ljava/lang/String;" ) ), is( true ) );
199 assertThat( m_index.containsObfMethod( newMethod( "none/a", "b", "()Ljava/lang/String;" ) ), is( false ) );
200 }
201}
diff --git a/test/cuchaz/enigma/inputs/LoneClass.java b/test/cuchaz/enigma/inputs/loneClass/LoneClass.java
index a3d8cded..961b012e 100644
--- a/test/cuchaz/enigma/inputs/LoneClass.java
+++ b/test/cuchaz/enigma/inputs/loneClass/LoneClass.java
@@ -1,4 +1,4 @@
1package cuchaz.enigma.inputs; 1package cuchaz.enigma.inputs.loneClass;
2 2
3public class LoneClass 3public class LoneClass
4{ 4{