tag writing fixes + test

This commit is contained in:
honfika@gmail.com
2014-12-18 00:07:15 +01:00
parent 596dc31137
commit 98957a1453
4 changed files with 46 additions and 16 deletions

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash;
import com.jpexs.decompiler.flash.configuration.Configuration;
@@ -67,18 +68,20 @@ public class ExportTest {
@DataProvider(name = "swfFiles")
public Object[][] createData() {
File dir = new File(TESTDATADIR);
File dir = new File(TESTDATADIR);
if (!dir.exists()) {
File[] files = new File[0];
if (dir.exists()) {
files = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".swf");
}
});
}
}
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++) {
Object[][] ret = new Object[files.length + 2][1];
ret[0][0] = new File(TESTDATADIR + File.separator + "../as2/as2.swf");
ret[1][0] = new File(TESTDATADIR + File.separator + "../as3/as3.swf");
for (int f = 0; f < files.length; f++) {
ret[f + 2][0] = files[f];
}
return ret;
}

View File

@@ -30,6 +30,8 @@ import com.jpexs.decompiler.flash.helpers.CodeFormatting;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.collections.MyEntry;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.TagStub;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.TranslateException;
@@ -148,6 +150,27 @@ public class RecompileTest {
}
}
@Test(dataProvider = "provideFiles")
public void testTagEditing(String filename) throws IOException, InterruptedException {
try {
SWF swf = new SWF(new BufferedInputStream(new FileInputStream(TESTDATADIR + File.separator + filename)), false);
for (Tag tag : swf.tags) {
if (!(tag instanceof TagStub)) {
byte[] data = tag.getData();
SWFInputStream tagDataStream = new SWFInputStream(swf, data, tag.getDataPos(), data.length);
TagStub copy = new TagStub(swf, tag.getId(), "Unresolved", tag.getOriginalRange(), tagDataStream);
copy.forceWriteAsLong = tag.forceWriteAsLong;
Tag tag2 = SWFInputStream.resolveTag(copy, 0, false, true, false);
if (tag2 instanceof TagStub) {
fail("Recompile failed. Tag: " + tag.getId() + " " + tag.getName());
}
}
}
} catch (Exception ex) {
// ignore
}
}
@DataProvider(name = "provideFiles")
public Object[][] provideFiles() {
File dir = new File(TESTDATADIR);