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