summaryrefslogtreecommitdiff
path: root/src/test/java/cuchaz
diff options
context:
space:
mode:
authorGravatar gegy10002019-06-18 20:20:40 +0200
committerGravatar gegy10002019-06-18 20:20:40 +0200
commit42243fa65e1d87f6a0498f6e2d83505605409411 (patch)
treec4127d7928c752360639b42b221c96678cdc5807 /src/test/java/cuchaz
parentPlugin rework along with API rework: Enigma split from EnigmaProject; plugins... (diff)
parentfix unwanted declaration navigation during Quick Find (diff)
downloadenigma-fork-42243fa65e1d87f6a0498f6e2d83505605409411.tar.gz
enigma-fork-42243fa65e1d87f6a0498f6e2d83505605409411.tar.xz
enigma-fork-42243fa65e1d87f6a0498f6e2d83505605409411.zip
Mostly resolve test failures
Diffstat (limited to 'src/test/java/cuchaz')
-rw-r--r--src/test/java/cuchaz/enigma/TestDeobfed.java7
-rw-r--r--src/test/java/cuchaz/enigma/TestDeobfuscator.java36
-rw-r--r--src/test/java/cuchaz/enigma/TestInnerClasses.java11
-rw-r--r--src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java12
-rw-r--r--src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java9
-rw-r--r--src/test/java/cuchaz/enigma/TestSourceIndex.java32
-rw-r--r--src/test/java/cuchaz/enigma/TestTokensConstructors.java4
-rw-r--r--src/test/java/cuchaz/enigma/TokenChecker.java15
8 files changed, 60 insertions, 66 deletions
diff --git a/src/test/java/cuchaz/enigma/TestDeobfed.java b/src/test/java/cuchaz/enigma/TestDeobfed.java
index 3d875df..3ee86cb 100644
--- a/src/test/java/cuchaz/enigma/TestDeobfed.java
+++ b/src/test/java/cuchaz/enigma/TestDeobfed.java
@@ -66,11 +66,12 @@ public class TestDeobfed {
66 } 66 }
67 67
68 @Test 68 @Test
69 public void decompile() 69 public void decompile() {
70 throws Exception {
71 EnigmaProject project = new EnigmaProject(enigma, classCache, index); 70 EnigmaProject project = new EnigmaProject(enigma, classCache, index);
72 71
73 SourceProvider sourceProvider = project.getObfSourceProvider(); 72 CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(project.getClassCache());
73 SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader);
74
74 sourceProvider.getSources("a"); 75 sourceProvider.getSources("a");
75 sourceProvider.getSources("b"); 76 sourceProvider.getSources("b");
76 sourceProvider.getSources("c"); 77 sourceProvider.getSources("c");
diff --git a/src/test/java/cuchaz/enigma/TestDeobfuscator.java b/src/test/java/cuchaz/enigma/TestDeobfuscator.java
index 5b9611c..2a6fec4 100644
--- a/src/test/java/cuchaz/enigma/TestDeobfuscator.java
+++ b/src/test/java/cuchaz/enigma/TestDeobfuscator.java
@@ -11,47 +11,31 @@
11 11
12package cuchaz.enigma; 12package cuchaz.enigma;
13 13
14import com.google.common.collect.Lists;
15import cuchaz.enigma.translation.representation.entry.ClassEntry;
16import org.junit.Test; 14import org.junit.Test;
17 15
18import java.io.IOException; 16import java.io.IOException;
19import java.util.List; 17import java.nio.file.Paths;
20import java.util.jar.JarFile;
21
22import static org.junit.Assert.assertEquals;
23 18
24public class TestDeobfuscator { 19public class TestDeobfuscator {
25 20
26 private Enigma getDeobfuscator() 21 private EnigmaProject openProject() throws IOException {
27 throws IOException { 22 Enigma enigma = Enigma.create();
28 return new Enigma(new JarFile("build/test-obf/loneClass.jar")); 23 return enigma.openJar(Paths.get("build/test-obf/loneClass.jar"), ProgressListener.none());
29 } 24 }
30 25
31 @Test 26 @Test
32 public void loadJar() 27 public void loadJar()
33 throws Exception { 28 throws Exception {
34 getDeobfuscator(); 29 openProject();
35 } 30 }
36 31
37 @Test 32 @Test
38 public void getClasses() 33 public void decompileClass() throws Exception {
39 throws Exception { 34 EnigmaProject project = openProject();
40 Enigma enigma = getDeobfuscator(); 35
41 List<ClassEntry> obfClasses = Lists.newArrayList(); 36 CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(project.getClassCache());
42 List<ClassEntry> deobfClasses = Lists.newArrayList(); 37 SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader);
43 enigma.getSeparatedClasses(obfClasses, deobfClasses);
44 assertEquals(1, obfClasses.size());
45 assertEquals("a", obfClasses.get(0).getName());
46 assertEquals(1, deobfClasses.size());
47 assertEquals("cuchaz/enigma/inputs/Keep", deobfClasses.get(0).getName());
48 }
49 38
50 @Test
51 public void decompileClass()
52 throws Exception {
53 Enigma enigma = getDeobfuscator();
54 SourceProvider sourceProvider = enigma.getObfSourceProvider();
55 sourceProvider.writeSourceToString(sourceProvider.getSources("a")); 39 sourceProvider.writeSourceToString(sourceProvider.getSources("a"));
56 } 40 }
57} 41}
diff --git a/src/test/java/cuchaz/enigma/TestInnerClasses.java b/src/test/java/cuchaz/enigma/TestInnerClasses.java
index b6e4e2d..18e4936 100644
--- a/src/test/java/cuchaz/enigma/TestInnerClasses.java
+++ b/src/test/java/cuchaz/enigma/TestInnerClasses.java
@@ -17,7 +17,6 @@ import cuchaz.enigma.translation.representation.entry.ClassEntry;
17import org.junit.Test; 17import org.junit.Test;
18 18
19import java.nio.file.Paths; 19import java.nio.file.Paths;
20import java.util.jar.JarFile;
21 20
22import static cuchaz.enigma.TestEntryFactory.newClass; 21import static cuchaz.enigma.TestEntryFactory.newClass;
23import static org.hamcrest.MatcherAssert.assertThat; 22import static org.hamcrest.MatcherAssert.assertThat;
@@ -34,14 +33,14 @@ public class TestInnerClasses {
34 private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a"); 33 private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a");
35 private static final ClassEntry ClassTreeLevel3 = newClass("f$a$a$a"); 34 private static final ClassEntry ClassTreeLevel3 = newClass("f$a$a$a");
36 private JarIndex index; 35 private JarIndex index;
37 private Enigma enigma; 36 private SourceProvider sourceProvider;
38 37
39 public TestInnerClasses() 38 public TestInnerClasses() throws Exception {
40 throws Exception {
41 ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/innerClasses.jar")); 39 ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/innerClasses.jar"));
42 index = classCache.index(ProgressListener.none()); 40 index = classCache.index(ProgressListener.none());
43 41
44 enigma = new Enigma(jar); 42 CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache);
43 sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader);
45 } 44 }
46 45
47 @Test 46 @Test
@@ -80,6 +79,6 @@ public class TestInnerClasses {
80 } 79 }
81 80
82 private void decompile(ClassEntry classEntry) { 81 private void decompile(ClassEntry classEntry) {
83 enigma.getObfSourceProvider().getSources(classEntry.getName()); 82 sourceProvider.getSources(classEntry.getName());
84 } 83 }
85} 84}
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java
index 0712ccf..48975c8 100644
--- a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java
+++ b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java
@@ -11,6 +11,7 @@
11 11
12package cuchaz.enigma; 12package cuchaz.enigma;
13 13
14import cuchaz.enigma.analysis.ClassCache;
14import cuchaz.enigma.analysis.EntryReference; 15import cuchaz.enigma.analysis.EntryReference;
15import cuchaz.enigma.analysis.index.JarIndex; 16import cuchaz.enigma.analysis.index.JarIndex;
16import cuchaz.enigma.translation.representation.entry.ClassEntry; 17import cuchaz.enigma.translation.representation.entry.ClassEntry;
@@ -18,9 +19,8 @@ import cuchaz.enigma.translation.representation.entry.MethodDefEntry;
18import cuchaz.enigma.translation.representation.entry.MethodEntry; 19import cuchaz.enigma.translation.representation.entry.MethodEntry;
19import org.junit.Test; 20import org.junit.Test;
20 21
21import java.io.File; 22import java.nio.file.Paths;
22import java.util.Collection; 23import java.util.Collection;
23import java.util.jar.JarFile;
24 24
25import static cuchaz.enigma.TestEntryFactory.*; 25import static cuchaz.enigma.TestEntryFactory.*;
26import static org.hamcrest.MatcherAssert.assertThat; 26import static org.hamcrest.MatcherAssert.assertThat;
@@ -36,11 +36,9 @@ public class TestJarIndexConstructorReferences {
36 private ClassEntry defaultClass = newClass("c"); 36 private ClassEntry defaultClass = newClass("c");
37 private ClassEntry callerClass = newClass("b"); 37 private ClassEntry callerClass = newClass("b");
38 38
39 public TestJarIndexConstructorReferences() 39 public TestJarIndexConstructorReferences() throws Exception {
40 throws Exception { 40 ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/constructors.jar"));
41 File jarFile = new File("build/test-obf/constructors.jar"); 41 index = classCache.index(ProgressListener.none());
42 index = JarIndex.empty();
43 index.indexJar(new ParsedJar(new JarFile(jarFile)), s -> {});
44 } 42 }
45 43
46 @Test 44 @Test
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java
index 1299bcc..103c366 100644
--- a/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java
+++ b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java
@@ -23,9 +23,9 @@ import cuchaz.enigma.translation.representation.entry.MethodDefEntry;
23import cuchaz.enigma.translation.representation.entry.MethodEntry; 23import cuchaz.enigma.translation.representation.entry.MethodEntry;
24import org.junit.Test; 24import org.junit.Test;
25 25
26import java.nio.file.Paths;
26import java.util.Collection; 27import java.util.Collection;
27import java.util.List; 28import java.util.List;
28import java.util.jar.JarFile;
29 29
30import static cuchaz.enigma.TestEntryFactory.*; 30import static cuchaz.enigma.TestEntryFactory.*;
31import static org.hamcrest.MatcherAssert.assertThat; 31import static org.hamcrest.MatcherAssert.assertThat;
@@ -35,10 +35,9 @@ public class TestJarIndexLoneClass {
35 35
36 private JarIndex index; 36 private JarIndex index;
37 37
38 public TestJarIndexLoneClass() 38 public TestJarIndexLoneClass() throws Exception {
39 throws Exception { 39 ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/loneClass.jar"));
40 index = JarIndex.empty(); 40 index = classCache.index(ProgressListener.none());
41 index.indexJar(new ParsedJar(new JarFile("build/test-obf/loneClass.jar")), s -> {});
42 } 41 }
43 42
44 @Test 43 @Test
diff --git a/src/test/java/cuchaz/enigma/TestSourceIndex.java b/src/test/java/cuchaz/enigma/TestSourceIndex.java
index 8a604f8..b1d1182 100644
--- a/src/test/java/cuchaz/enigma/TestSourceIndex.java
+++ b/src/test/java/cuchaz/enigma/TestSourceIndex.java
@@ -13,13 +13,15 @@ package cuchaz.enigma;
13 13
14import com.google.common.collect.Sets; 14import com.google.common.collect.Sets;
15import com.strobel.decompiler.languages.java.ast.CompilationUnit; 15import com.strobel.decompiler.languages.java.ast.CompilationUnit;
16import cuchaz.enigma.analysis.ClassCache;
16import cuchaz.enigma.analysis.SourceIndex; 17import cuchaz.enigma.analysis.SourceIndex;
18import cuchaz.enigma.analysis.index.JarIndex;
17import cuchaz.enigma.translation.representation.entry.ClassEntry; 19import cuchaz.enigma.translation.representation.entry.ClassEntry;
18import org.junit.Test; 20import org.junit.Test;
19 21
20import java.io.File; 22import java.nio.file.Path;
23import java.nio.file.Paths;
21import java.util.Set; 24import java.util.Set;
22import java.util.jar.JarFile;
23 25
24public class TestSourceIndex { 26public class TestSourceIndex {
25 @Test 27 @Test
@@ -27,31 +29,41 @@ public class TestSourceIndex {
27 throws Exception { 29 throws Exception {
28 // Figure out where Minecraft is... 30 // Figure out where Minecraft is...
29 final String mcDir = System.getProperty("enigma.test.minecraftdir"); 31 final String mcDir = System.getProperty("enigma.test.minecraftdir");
30 File mcJar = null; 32 Path mcJar = null;
31 if (mcDir == null) { 33 if (mcDir == null) {
32 String osname = System.getProperty("os.name").toLowerCase(); 34 String osname = System.getProperty("os.name").toLowerCase();
33 if (osname.contains("nix") || osname.contains("nux") || osname.contains("solaris")) { 35 if (osname.contains("nix") || osname.contains("nux") || osname.contains("solaris")) {
34 mcJar = new File(System.getProperty("user.home"), ".minecraft/versions/1.8.3/1.8.3.jar"); 36 mcJar = Paths.get(System.getProperty("user.home"), ".minecraft/versions/1.8.3/1.8.3.jar");
35 } else if (osname.contains("mac") || osname.contains("darwin")) { 37 } else if (osname.contains("mac") || osname.contains("darwin")) {
36 mcJar = new File(System.getProperty("user.home"), "Library/Application Support/minecraft/versions/1.8.3/1.8.3.jar"); 38 mcJar = Paths.get(System.getProperty("user.home"), "Library/Application Support/minecraft/versions/1.8.3/1.8.3.jar");
37 } else if (osname.contains("win")) { 39 } else if (osname.contains("win")) {
38 mcJar = new File(System.getenv("AppData"), ".minecraft/versions/1.8.3/1.8.3.jar"); 40 mcJar = Paths.get(System.getenv("AppData"), ".minecraft/versions/1.8.3/1.8.3.jar");
39 } 41 }
40 } else { 42 } else {
41 mcJar = new File(mcDir, "versions/1.8.3/1.8.3.jar"); 43 mcJar = Paths.get(mcDir, "versions/1.8.3/1.8.3.jar");
42 } 44 }
43 45
44 Enigma enigma = new Enigma(new JarFile(mcJar)); 46 if (mcJar == null) {
47 throw new NullPointerException("Couldn't find jar");
48 }
49
50 Enigma enigma = Enigma.create();
51 EnigmaProject project = enigma.openJar(mcJar, ProgressListener.none());
52
53 ClassCache classCache = project.getClassCache();
54 JarIndex index = project.getJarIndex();
55
56 CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache);
57 SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader);
45 58
46 // get all classes that aren't inner classes 59 // get all classes that aren't inner classes
47 Set<ClassEntry> classEntries = Sets.newHashSet(); 60 Set<ClassEntry> classEntries = Sets.newHashSet();
48 for (ClassEntry obfClassEntry : enigma.getJarIndex().getEntryIndex().getClasses()) { 61 for (ClassEntry obfClassEntry : index.getEntryIndex().getClasses()) {
49 if (!obfClassEntry.isInnerClass()) { 62 if (!obfClassEntry.isInnerClass()) {
50 classEntries.add(obfClassEntry); 63 classEntries.add(obfClassEntry);
51 } 64 }
52 } 65 }
53 66
54 SourceProvider sourceProvider = enigma.getObfSourceProvider();
55 for (ClassEntry obfClassEntry : classEntries) { 67 for (ClassEntry obfClassEntry : classEntries) {
56 try { 68 try {
57 CompilationUnit tree = sourceProvider.getSources(obfClassEntry.getName()); 69 CompilationUnit tree = sourceProvider.getSources(obfClassEntry.getName());
diff --git a/src/test/java/cuchaz/enigma/TestTokensConstructors.java b/src/test/java/cuchaz/enigma/TestTokensConstructors.java
index 1ee0bde..0398de4 100644
--- a/src/test/java/cuchaz/enigma/TestTokensConstructors.java
+++ b/src/test/java/cuchaz/enigma/TestTokensConstructors.java
@@ -14,7 +14,7 @@ package cuchaz.enigma;
14import cuchaz.enigma.translation.representation.entry.MethodEntry; 14import cuchaz.enigma.translation.representation.entry.MethodEntry;
15import org.junit.Test; 15import org.junit.Test;
16 16
17import java.util.jar.JarFile; 17import java.nio.file.Paths;
18 18
19import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod; 19import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod;
20import static cuchaz.enigma.TestEntryFactory.newMethod; 20import static cuchaz.enigma.TestEntryFactory.newMethod;
@@ -25,7 +25,7 @@ public class TestTokensConstructors extends TokenChecker {
25 25
26 public TestTokensConstructors() 26 public TestTokensConstructors()
27 throws Exception { 27 throws Exception {
28 super(new JarFile("build/test-obf/constructors.jar")); 28 super(Paths.get("build/test-obf/constructors.jar"));
29 } 29 }
30 30
31 @Test 31 @Test
diff --git a/src/test/java/cuchaz/enigma/TokenChecker.java b/src/test/java/cuchaz/enigma/TokenChecker.java
index 9e0c696..1dde034 100644
--- a/src/test/java/cuchaz/enigma/TokenChecker.java
+++ b/src/test/java/cuchaz/enigma/TokenChecker.java
@@ -13,28 +13,30 @@ package cuchaz.enigma;
13 13
14import com.google.common.collect.Lists; 14import com.google.common.collect.Lists;
15import com.strobel.decompiler.languages.java.ast.CompilationUnit; 15import com.strobel.decompiler.languages.java.ast.CompilationUnit;
16import cuchaz.enigma.analysis.ClassCache;
16import cuchaz.enigma.analysis.EntryReference; 17import cuchaz.enigma.analysis.EntryReference;
17import cuchaz.enigma.analysis.SourceIndex; 18import cuchaz.enigma.analysis.SourceIndex;
18import cuchaz.enigma.analysis.Token; 19import cuchaz.enigma.analysis.Token;
19import cuchaz.enigma.translation.representation.entry.Entry; 20import cuchaz.enigma.translation.representation.entry.Entry;
20 21
21import java.io.IOException; 22import java.io.IOException;
23import java.nio.file.Path;
22import java.util.Collection; 24import java.util.Collection;
23import java.util.List; 25import java.util.List;
24import java.util.jar.JarFile;
25 26
26public class TokenChecker { 27public class TokenChecker {
27 28
28 private Enigma enigma; 29 private SourceProvider sourceProvider;
29 30
30 protected TokenChecker(JarFile jarFile) 31 protected TokenChecker(Path path) throws IOException {
31 throws IOException { 32 ClassCache classCache = ClassCache.of(path);
32 enigma = new Enigma(jarFile); 33
34 CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache);
35 sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader);
33 } 36 }
34 37
35 protected String getDeclarationToken(Entry<?> entry) { 38 protected String getDeclarationToken(Entry<?> entry) {
36 // decompile the class 39 // decompile the class
37 SourceProvider sourceProvider = enigma.getObfSourceProvider();
38 CompilationUnit tree = sourceProvider.getSources(entry.getContainingClass().getFullName()); 40 CompilationUnit tree = sourceProvider.getSources(entry.getContainingClass().getFullName());
39 // DEBUG 41 // DEBUG
40 // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); 42 // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null );
@@ -52,7 +54,6 @@ public class TokenChecker {
52 @SuppressWarnings("unchecked") 54 @SuppressWarnings("unchecked")
53 protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) { 55 protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) {
54 // decompile the class 56 // decompile the class
55 SourceProvider sourceProvider = enigma.getObfSourceProvider();
56 CompilationUnit tree = sourceProvider.getSources(reference.context.getContainingClass().getFullName()); 57 CompilationUnit tree = sourceProvider.getSources(reference.context.getContainingClass().getFullName());
57 String source = sourceProvider.writeSourceToString(tree); 58 String source = sourceProvider.writeSourceToString(tree);
58 SourceIndex index = SourceIndex.buildIndex(source, tree, true); 59 SourceIndex index = SourceIndex.buildIndex(source, tree, true);