summaryrefslogtreecommitdiffstats
path: root/test/unit/TestSingleClasses.java
diff options
context:
space:
mode:
authorStiver <stiver.mail@gmail.com>2014-08-09 17:34:24 +0200
committerStiver <stiver.mail@gmail.com>2014-08-09 17:34:24 +0200
commit70bf7f3f6993c6ea23dd568e39257b9c0dd6c8c7 (patch)
treec28f29fb61347743d7a236014d84e946368a9f9a /test/unit/TestSingleClasses.java
parent3b9b180d94cd259f34cf05e7275fe29e309103e2 (diff)
downloadfernflower-70bf7f3f6993c6ea23dd568e39257b9c0dd6c8c7.tar
fernflower-70bf7f3f6993c6ea23dd568e39257b9c0dd6c8c7.tar.gz
fernflower-70bf7f3f6993c6ea23dd568e39257b9c0dd6c8c7.tar.lz
fernflower-70bf7f3f6993c6ea23dd568e39257b9c0dd6c8c7.tar.xz
fernflower-70bf7f3f6993c6ea23dd568e39257b9c0dd6c8c7.zip
A couple of unit tests
Diffstat (limited to 'test/unit/TestSingleClasses.java')
-rw-r--r--test/unit/TestSingleClasses.java89
1 files changed, 89 insertions, 0 deletions
diff --git a/test/unit/TestSingleClasses.java b/test/unit/TestSingleClasses.java
new file mode 100644
index 0000000..2758316
--- /dev/null
+++ b/test/unit/TestSingleClasses.java
@@ -0,0 +1,89 @@
+package unit;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.Date;
+import java.util.HashMap;
+
+import org.junit.Test;
+
+import de.fernflower.main.decompiler.ConsoleDecompiler;
+import de.fernflower.main.extern.IFernflowerPreferences;
+
+public class TestSingleClasses {
+
+ @Test
+ public void test() throws IOException {
+
+ Date start = new Date();
+
+ String current_path = new File(".").getCanonicalPath().toString();
+
+ iterateDirectory(new File(current_path + "/bin/unit/classes/"));
+
+ System.out.println("\n\nTime elapsed " + (new Date().getTime() - start.getTime())/1000);
+ }
+
+ private void iterateDirectory(File dir) throws IOException {
+
+ for (File file : dir.listFiles()) {
+ if (file.isDirectory()) {
+ iterateDirectory(file);
+ } else if(file.getName().endsWith(".class")) {
+ decompileAndCheckFile(file);
+ }
+ }
+ }
+
+ private void decompileAndCheckFile(File file) throws IOException {
+
+ try {
+
+ ConsoleDecompiler decompiler = new ConsoleDecompiler(new HashMap<String, Object>(){{
+ put("log", "warn");
+ put("ren", "1");
+ put(IFernflowerPreferences.HIDE_DEFAULT_CONSTRUCTOR, "1");
+ put(IFernflowerPreferences.DECOMPILE_GENERIC_SIGNATURES, "0");
+ put(IFernflowerPreferences.IDEA_NOT_NULL_ANNOTATION, "1");
+ put(IFernflowerPreferences.LAMBDA_TO_ANONYMOUS_CLASS, "0");
+ put(IFernflowerPreferences.USE_DEBUG_VARNAMES, "0");
+ put(IFernflowerPreferences.NEW_LINE_SEPARATOR, "0");
+ }});
+
+ decompiler.addSpace(file, true);
+
+ // files
+ String current_path = new File(".").getCanonicalPath().toString();
+
+ String file_class_name = file.getName();
+ String file_name = file_class_name.substring(0, file_class_name.lastIndexOf(".class"));
+ String file_java_name = file_name+".java";
+
+ File reference_file = new File(current_path + "/test/unit/results/" + file_name + ".dec");
+ File temp_dir = new File(Files.createTempDirectory("tempdec_"+file_name).toString());
+
+ // decompile it
+ decompiler.decompileContext(temp_dir);
+
+ // get both the decompiled file content and the reference
+ // NOTE: reference files are saved with Windows-style line endings. Convert them if you are decompiling to Unix.
+ String decompiled_content = new String(Files.readAllBytes(new File(temp_dir, file_java_name).toPath()), "UTF-8");
+ String reference_content = new String(Files.readAllBytes(reference_file.toPath()), "UTF-8");
+
+ // clean up
+ //temp_dir.delete();
+
+ // compare file content with the reference
+ assertEquals(decompiled_content, reference_content);
+
+ } catch(Exception ex) {
+ System.out.println("ERROR: testing file " + file.getCanonicalPath());
+ ex.printStackTrace();
+ }
+
+ }
+
+}