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