From dc29b8f7098f1427b93f3ec3603fb69fe74931d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 13 Jul 2013 13:06:51 +0200 Subject: [PATCH] updated tests Export test for exporting all files in testdata/decompile dir --- .../decompiler/flash/ActionScript2Test.java | 4 +- .../jpexs/decompiler/flash/ExportTest.java | 97 +++++++++++++++++++ .../flash/generators/AS2Generator.java | 2 +- 3 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 trunk/test/com/jpexs/decompiler/flash/ExportTest.java diff --git a/trunk/test/com/jpexs/decompiler/flash/ActionScript2Test.java b/trunk/test/com/jpexs/decompiler/flash/ActionScript2Test.java index 578ad4e4b..c690059b1 100644 --- a/trunk/test/com/jpexs/decompiler/flash/ActionScript2Test.java +++ b/trunk/test/com/jpexs/decompiler/flash/ActionScript2Test.java @@ -37,14 +37,14 @@ public class ActionScript2Test { @BeforeClass public void init() throws IOException { - swf = new SWF(new FileInputStream("testdata/as2/as2.swf"), false); Configuration.setConfig("autoDeobfuscate", false); + swf = new SWF(new FileInputStream("testdata/as2/as2.swf"), false); } private void compareSrc(int frame, String expectedResult) { DoActionTag doa = getFrameSource(frame); assertNotNull(doa); - String actualResult = Highlighting.stripHilights(Action.actionsToSource(doa.getActions(swf.version), swf.version)); + String actualResult = Highlighting.stripHilights(Action.actionsToSource(doa.getActions(swf.version), swf.version,"")); actualResult = actualResult.replaceAll("[ \r\n]", ""); expectedResult = expectedResult.replaceAll("[ \r\n]", ""); assertEquals(actualResult, expectedResult); diff --git a/trunk/test/com/jpexs/decompiler/flash/ExportTest.java b/trunk/test/com/jpexs/decompiler/flash/ExportTest.java new file mode 100644 index 000000000..43169d453 --- /dev/null +++ b/trunk/test/com/jpexs/decompiler/flash/ExportTest.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FilenameFilter; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import static org.testng.Assert.*; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * + * @author JPEXS + */ +public class ExportTest { + + public static final String TESTDATADIR = "testdata/decompile"; + + @BeforeClass + public void addLogger(){ + Configuration.setConfig("autoDeobfuscate", Boolean.TRUE); + Logger logger = Logger.getLogger(""); + logger.addHandler(new Handler() { + + @Override + public void publish(LogRecord record) { + if(record.getLevel()==Level.SEVERE){ + fail("Error during decompilation",record.getThrown()); + } + } + + @Override + public void flush() { + + } + + @Override + public void close() throws SecurityException { + + } + }); + } + + + @DataProvider(name = "swfFiles") + public Object[][] createData() { + File dir = new File(TESTDATADIR); + if (!dir.exists()) { + return new Object[0][0]; + } + File files[] = dir.listFiles(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.toLowerCase().endsWith(".swf"); + } + }); + Object[][] ret = new Object[files.length][1]; + for (int i = 0; i < files.length; i++) { + ret[i][0] = files[i]; + } + return ret; + } + + @Test(dataProvider = "swfFiles") + public void testDecompile(File f) { + try { + SWF swf = new SWF(new FileInputStream(f), false); + Configuration.DEBUG_COPY = true; + File fdir = new File(TESTDATADIR + File.separator + "output" + File.separator + f.getName()); + fdir.mkdirs(); + + swf.exportActionScript(fdir.getAbsolutePath(), false, false); + } catch (Exception ex) { + fail(); + } + } +} diff --git a/trunk/test/com/jpexs/decompiler/flash/generators/AS2Generator.java b/trunk/test/com/jpexs/decompiler/flash/generators/AS2Generator.java index 1ae91f432..22035ccf8 100644 --- a/trunk/test/com/jpexs/decompiler/flash/generators/AS2Generator.java +++ b/trunk/test/com/jpexs/decompiler/flash/generators/AS2Generator.java @@ -35,7 +35,7 @@ public class AS2Generator { if (doa == null) { continue; } - String src = Highlighting.stripHilights(Action.actionsToSource(doa.getActions(swf.version), swf.version)); + String src = Highlighting.stripHilights(Action.actionsToSource(doa.getActions(swf.version), swf.version,"")); if (src.trim().equals("")) { doa = null; continue;