forked from helios-decompiler/transformer-api
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStandardTransformersTest.java
More file actions
162 lines (132 loc) · 6.97 KB
/
StandardTransformersTest.java
File metadata and controls
162 lines (132 loc) · 6.97 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package com.heliosdecompiler.transformerapi;
import org.apache.commons.io.IOUtils;
import org.jd.core.v1.loader.ClassPathLoader;
import org.junit.Test;
import com.heliosdecompiler.transformerapi.common.Loader;
import com.heliosdecompiler.transformerapi.decompilers.cfr.CFRSettings;
import com.heliosdecompiler.transformerapi.decompilers.fernflower.FernflowerSettings;
import com.heliosdecompiler.transformerapi.decompilers.jadx.MapJadxArgs;
import com.heliosdecompiler.transformerapi.decompilers.jd.JDSettings;
import com.heliosdecompiler.transformerapi.decompilers.procyon.MapDecompilerSettings;
import com.heliosdecompiler.transformerapi.decompilers.vineflower.VineflowerSettings;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Map;
import static com.heliosdecompiler.transformerapi.StandardTransformers.Decompilers.ENGINE_CFR;
import static com.heliosdecompiler.transformerapi.StandardTransformers.Decompilers.ENGINE_FERNFLOWER;
import static com.heliosdecompiler.transformerapi.StandardTransformers.Decompilers.ENGINE_JADX;
import static com.heliosdecompiler.transformerapi.StandardTransformers.Decompilers.ENGINE_JD_CORE_V0;
import static com.heliosdecompiler.transformerapi.StandardTransformers.Decompilers.ENGINE_JD_CORE_V1;
import static com.heliosdecompiler.transformerapi.StandardTransformers.Decompilers.ENGINE_PROCYON;
import static com.heliosdecompiler.transformerapi.StandardTransformers.Decompilers.ENGINE_VINEFLOWER;
import static org.junit.Assert.assertEquals;
import jd.core.DecompilationResult;
public class StandardTransformersTest {
@Test
public void testDecompileCFR() throws Exception {
testDecompile("/TestCompactCFR.txt", ENGINE_CFR, CFRSettings.defaults());
}
@Test
public void testDecompileCFRFromClassPath() throws Exception {
testDecompileFromClassPath("/TestThrowableCFR.txt", ENGINE_CFR, CFRSettings.defaults());
}
@Test
public void testDecompileProcyonFromClassPath() throws Exception {
testDecompileFromClassPath("/TestThrowableProcyon.txt", ENGINE_PROCYON, MapDecompilerSettings.defaults());
}
@Test
public void testDecompileProcyon() throws Exception {
testDecompile("/TestCompactProcyon.txt", ENGINE_PROCYON, MapDecompilerSettings.defaults());
}
@Test
public void testDecompileProcyonByteCode() throws Exception {
testDecompile("/TestCompactProcyonByteCode.txt", ENGINE_PROCYON, MapDecompilerSettings.byteCodeSettings());
}
@Test
public void testDecompileJADXFromClassPath() throws Exception {
testDecompileFromClassPath("/TestThrowableJADX.txt", ENGINE_JADX, Collections.emptyMap());
}
@Test
public void testDecompileJADX() throws Exception {
testDecompile("/TestCompactJADX.txt", ENGINE_JADX, Collections.emptyMap());
}
@Test
public void testDecompileJADXWithLineNumbers() throws Exception {
testDecompile("/TestCompactJADXWithLineNumbers.txt", ENGINE_JADX, MapJadxArgs.lineNumbers());
}
@Test
public void testDecompileFernflower() throws Exception {
testDecompile("/TestCompactFernflower.txt", ENGINE_FERNFLOWER, Collections.emptyMap());
}
@Test
public void testDecompileFernflowerFromClassPath() throws Exception {
testDecompileFromClassPath("/TestThrowableFernflower.txt", ENGINE_FERNFLOWER, Collections.emptyMap());
}
@Test
public void testDecompileFernflowerWithLineNumbers() throws Exception {
testDecompile("/TestCompactFernflowerWithLineNumbers.txt", ENGINE_FERNFLOWER, FernflowerSettings.lineNumbers());
}
@Test
public void testDecompileVineflower() throws Exception {
testDecompile("/TestCompactVineflower.txt", ENGINE_VINEFLOWER, Collections.emptyMap());
}
@Test
public void testDecompileVineflowerFromClassPath() throws Exception {
testDecompileFromClassPath("/TestThrowableVineflower.txt", ENGINE_VINEFLOWER, Collections.emptyMap());
}
@Test
public void testDecompileVineflowerWithLineNumbers() throws Exception {
testDecompile("/TestCompactVineflowerWithLineNumbers.txt", ENGINE_VINEFLOWER, VineflowerSettings.lineNumbers());
}
@Test
public void testDecompileJDCoreV0() throws Exception {
testDecompile("/TestCompactJDCoreV0.txt", ENGINE_JD_CORE_V0, JDSettings.defaults());
}
@Test
public void testDecompileJDCoreV0FromClassPath() throws Exception {
testDecompileFromClassPath("/TestThrowableJDCoreV0.txt", ENGINE_JD_CORE_V0, JDSettings.defaults());
}
@Test
public void testDecompileJDCoreV0WithLineNumbers() throws Exception {
testDecompile("/TestCompactJDCoreV0WithLineNumbers.txt", ENGINE_JD_CORE_V0, JDSettings.lineNumbers());
}
@Test
public void testDecompileJDCoreV1() throws Exception {
testDecompile("/TestCompactJDCoreV1.txt", ENGINE_JD_CORE_V1, JDSettings.defaults());
}
@Test
public void testDecompileJDCoreV1FromClassPath() throws Exception {
testDecompileFromClassPath("/TestThrowableJDCoreV1.txt", ENGINE_JD_CORE_V1, JDSettings.defaults());
}
@Test
public void testDecompileJDCoreV1WithLineNumbers() throws Exception {
testDecompile("/TestCompactJDCoreV1WithLineNumbers.txt", ENGINE_JD_CORE_V1, JDSettings.lineNumbers());
}
private void testDecompile(String path, String engineName, Map<String, String> preferences)
throws IOException, IllegalAccessException, InvocationTargetException, URISyntaxException {
URI resource = getClass().getResource("/test-compact-expand-inline.jar").toURI();
ZipLoader zipLoader = new ZipLoader(resource.toURL().openStream());
Loader loader = new Loader(zipLoader::canLoad, zipLoader::load, resource);
String internalName = "test/TestCompact";
DecompilationResult result = StandardTransformers.decompile(loader, internalName, preferences, engineName);
assertEqualsIgnoreEOL(getResourceAsString(path), result.getDecompiledOutput());
}
private void testDecompileFromClassPath(String path, String engineName, Map<String, String> preferences)
throws IOException, IllegalAccessException, InvocationTargetException {
ClassPathLoader zipLoader = new ClassPathLoader();
Loader loader = new Loader(zipLoader::canLoad, zipLoader::load);
String internalName = "java/lang/Throwable";
DecompilationResult result = StandardTransformers.decompile(loader, internalName, preferences, engineName);
assertEqualsIgnoreEOL(getResourceAsString(path), result.getDecompiledOutput());
}
private void assertEqualsIgnoreEOL(String expected, String actual) {
assertEquals(expected.replaceAll("\s*\r?\n", "\n"), actual.replaceAll("\s*\r?\n", "\n"));
}
private String getResourceAsString(String path) throws IOException {
return IOUtils.toString(getClass().getResource(path), StandardCharsets.UTF_8);
}
}