summaryrefslogtreecommitdiff
path: root/test/cuchaz/enigma/TestTokensConstructors.java
diff options
context:
space:
mode:
authorGravatar jeff2014-09-14 23:56:43 -0400
committerGravatar jeff2014-09-14 23:56:43 -0400
commit72e918a5134c2bf747a476284bcfa1bd2ef2fa21 (patch)
tree2fd256d6a8bbe38b7b9fe1892f444a8c29de08ef /test/cuchaz/enigma/TestTokensConstructors.java
parentadded test to check constructor references (diff)
downloadenigma-fork-72e918a5134c2bf747a476284bcfa1bd2ef2fa21.tar.gz
enigma-fork-72e918a5134c2bf747a476284bcfa1bd2ef2fa21.tar.xz
enigma-fork-72e918a5134c2bf747a476284bcfa1bd2ef2fa21.zip
added tests to check constructor tokens
fixed a bug with constructor tokens too
Diffstat (limited to '')
-rw-r--r--test/cuchaz/enigma/TestTokensConstructors.java152
1 files changed, 152 insertions, 0 deletions
diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java
new file mode 100644
index 0000000..2409153
--- /dev/null
+++ b/test/cuchaz/enigma/TestTokensConstructors.java
@@ -0,0 +1,152 @@
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.newConstructor;
16import static org.hamcrest.MatcherAssert.assertThat;
17import static org.hamcrest.Matchers.containsInAnyOrder;
18import static org.hamcrest.Matchers.is;
19import static org.hamcrest.Matchers.nullValue;
20
21import java.io.File;
22
23import org.junit.Test;
24
25import cuchaz.enigma.mapping.BehaviorEntry;
26
27public class TestTokensConstructors extends TokenChecker
28{
29 public TestTokensConstructors( )
30 throws Exception
31 {
32 super( new File( "build/libs/testConstructors.obf.jar" ) );
33 }
34
35 @Test
36 public void baseDeclarations( )
37 {
38 assertThat( getDeclarationToken( newConstructor( "none/a", "()V" ) ), is( "a" ) );
39 assertThat( getDeclarationToken( newConstructor( "none/a", "(I)V" ) ), is( "a" ) );
40 }
41
42 @Test
43 public void subDeclarations( )
44 {
45 assertThat( getDeclarationToken( newConstructor( "none/d", "()V" ) ), is( "d" ) );
46 assertThat( getDeclarationToken( newConstructor( "none/d", "(I)V" ) ), is( "d" ) );
47 assertThat( getDeclarationToken( newConstructor( "none/d", "(II)V" ) ), is( "d" ) );
48 assertThat( getDeclarationToken( newConstructor( "none/d", "(III)V" ) ), is( "d" ) );
49 }
50
51 @Test
52 public void subsubDeclarations( )
53 {
54 assertThat( getDeclarationToken( newConstructor( "none/e", "(I)V" ) ), is( "e" ) );
55 }
56
57 @Test
58 public void defaultDeclarations( )
59 {
60 assertThat( getDeclarationToken( newConstructor( "none/c", "()V" ) ), nullValue() );
61 }
62
63 @Test
64 public void baseDefaultReferences( )
65 {
66 BehaviorEntry source = newConstructor( "none/a", "()V" );
67 assertThat(
68 getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "a", "()V" ) ),
69 containsInAnyOrder( "a" )
70 );
71 assertThat(
72 getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/d", "()V" ) ),
73 containsInAnyOrder( "super" ) // implicit call, decompiled to "super"
74 );
75 assertThat(
76 getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/d", "(III)V" ) ),
77 containsInAnyOrder( "super" ) // implicit call, decompiled to "super"
78 );
79 }
80
81 @Test
82 public void baseIntReferences( )
83 {
84 BehaviorEntry source = newConstructor( "none/a", "(I)V" );
85 assertThat(
86 getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "b", "()V" ) ),
87 containsInAnyOrder( "a" )
88 );
89 }
90
91 @Test
92 public void subDefaultReferences( )
93 {
94 BehaviorEntry source = newConstructor( "none/d", "()V" );
95 assertThat(
96 getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "c", "()V" ) ),
97 containsInAnyOrder( "d" )
98 );
99 assertThat(
100 getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/d", "(I)V" ) ),
101 containsInAnyOrder( "this" )
102 );
103 }
104
105 @Test
106 public void subIntReferences( )
107 {
108 BehaviorEntry source = newConstructor( "none/d", "(I)V" );
109 assertThat(
110 getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "d", "()V" ) ),
111 containsInAnyOrder( "d" )
112 );
113 assertThat(
114 getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/d", "(II)V" ) ),
115 containsInAnyOrder( "this" )
116 );
117 assertThat(
118 getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/e", "(I)V" ) ),
119 containsInAnyOrder( "super" )
120 );
121 }
122
123 @Test
124 public void subIntIntReferences( )
125 {
126 BehaviorEntry source = newConstructor( "none/d", "(II)V" );
127 assertThat(
128 getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "e", "()V" ) ),
129 containsInAnyOrder( "d" )
130 );
131 }
132
133 @Test
134 public void subsubIntReferences( )
135 {
136 BehaviorEntry source = newConstructor( "none/e", "(I)V" );
137 assertThat(
138 getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "f", "()V" ) ),
139 containsInAnyOrder( "e" )
140 );
141 }
142
143 @Test
144 public void defaultConstructableReferences( )
145 {
146 BehaviorEntry source = newConstructor( "none/c", "()V" );
147 assertThat(
148 getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "g", "()V" ) ),
149 containsInAnyOrder( "c" )
150 );
151 }
152}