summaryrefslogtreecommitdiff
path: root/test/cuchaz/enigma/TestJarIndexConstructorReferences.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/cuchaz/enigma/TestJarIndexConstructorReferences.java')
-rw-r--r--test/cuchaz/enigma/TestJarIndexConstructorReferences.java129
1 files changed, 129 insertions, 0 deletions
diff --git a/test/cuchaz/enigma/TestJarIndexConstructorReferences.java b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java
new file mode 100644
index 0000000..38882a0
--- /dev/null
+++ b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java
@@ -0,0 +1,129 @@
1/*******************************************************************************
2 * Copyright (c) 2014 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Public License v3.0
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/gpl.html
7 *
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11package cuchaz.enigma;
12
13import static cuchaz.enigma.EntryFactory.newBehaviorReferenceByConstructor;
14import static cuchaz.enigma.EntryFactory.newBehaviorReferenceByMethod;
15import static cuchaz.enigma.EntryFactory.newClass;
16import static org.hamcrest.MatcherAssert.assertThat;
17import static org.hamcrest.Matchers.containsInAnyOrder;
18import static org.hamcrest.Matchers.empty;
19import static org.hamcrest.Matchers.is;
20
21import java.util.jar.JarFile;
22
23import org.junit.Test;
24
25import cuchaz.enigma.analysis.JarIndex;
26import cuchaz.enigma.mapping.BehaviorEntry;
27import cuchaz.enigma.mapping.ClassEntry;
28import cuchaz.enigma.mapping.ConstructorEntry;
29
30public class TestJarIndexConstructorReferences
31{
32 private JarIndex m_index;
33
34 private ClassEntry m_baseClass = new ClassEntry( "none/a" );
35 private ClassEntry m_subClass = new ClassEntry( "none/c" );
36 private ClassEntry m_subsubClass = new ClassEntry( "none/d" );
37 private ClassEntry m_callerClass = new ClassEntry( "none/b" );
38
39 public TestJarIndexConstructorReferences( )
40 throws Exception
41 {
42 m_index = new JarIndex();
43 m_index.indexJar( new JarFile( "build/libs/testConstructors.obf.jar" ), false );
44 }
45
46 @Test
47 public void obfEntries( )
48 {
49 assertThat( m_index.getObfClassEntries(), containsInAnyOrder(
50 newClass( "cuchaz/enigma/inputs/Keep" ),
51 m_baseClass,
52 m_subClass,
53 m_subsubClass,
54 m_callerClass
55 ) );
56 }
57
58 @Test
59 @SuppressWarnings( "unchecked" )
60 public void baseDefault( )
61 {
62 BehaviorEntry source = new ConstructorEntry( m_baseClass, "()V" );
63 assertThat( m_index.getBehaviorReferences( source ), containsInAnyOrder(
64 newBehaviorReferenceByMethod( source, m_callerClass.getName(), "a", "()V" ),
65 newBehaviorReferenceByConstructor( source, m_subClass.getName(), "()V" ),
66 newBehaviorReferenceByConstructor( source, m_subClass.getName(), "(III)V" )
67 ) );
68 }
69
70 @Test
71 @SuppressWarnings( "unchecked" )
72 public void baseInt( )
73 {
74 BehaviorEntry source = new ConstructorEntry( m_baseClass, "(I)V" );
75 assertThat( m_index.getBehaviorReferences( source ), containsInAnyOrder(
76 newBehaviorReferenceByMethod( source, m_callerClass.getName(), "b", "()V" )
77 ) );
78 }
79
80 @Test
81 @SuppressWarnings( "unchecked" )
82 public void subDefault( )
83 {
84 BehaviorEntry source = new ConstructorEntry( m_subClass, "()V" );
85 assertThat( m_index.getBehaviorReferences( source ), containsInAnyOrder(
86 newBehaviorReferenceByMethod( source, m_callerClass.getName(), "c", "()V" ),
87 newBehaviorReferenceByConstructor( source, m_subClass.getName(), "(I)V" )
88 ) );
89 }
90
91 @Test
92 @SuppressWarnings( "unchecked" )
93 public void subInt( )
94 {
95 BehaviorEntry source = new ConstructorEntry( m_subClass, "(I)V" );
96 assertThat( m_index.getBehaviorReferences( source ), containsInAnyOrder(
97 newBehaviorReferenceByMethod( source, m_callerClass.getName(), "d", "()V" ),
98 newBehaviorReferenceByConstructor( source, m_subClass.getName(), "(II)V" ),
99 newBehaviorReferenceByConstructor( source, m_subsubClass.getName(), "(I)V" )
100 ) );
101 }
102
103 @Test
104 @SuppressWarnings( "unchecked" )
105 public void subIntInt( )
106 {
107 BehaviorEntry source = new ConstructorEntry( m_subClass, "(II)V" );
108 assertThat( m_index.getBehaviorReferences( source ), containsInAnyOrder(
109 newBehaviorReferenceByMethod( source, m_callerClass.getName(), "e", "()V" )
110 ) );
111 }
112
113 @Test
114 public void subIntIntInt( )
115 {
116 BehaviorEntry source = new ConstructorEntry( m_subClass, "(III)V" );
117 assertThat( m_index.getBehaviorReferences( source ), is( empty() ) );
118 }
119
120 @Test
121 @SuppressWarnings( "unchecked" )
122 public void subsubInt( )
123 {
124 BehaviorEntry source = new ConstructorEntry( m_subsubClass, "(I)V" );
125 assertThat( m_index.getBehaviorReferences( source ), containsInAnyOrder(
126 newBehaviorReferenceByMethod( source, m_callerClass.getName(), "f", "()V" )
127 ) );
128 }
129}