Skip to content
Browse files

test to decode files created with lzma(1)

  • Loading branch information...
1 parent 2b849dc commit 60fa2f77e7ad863c83be117d86d22985521ad675 @league committed Sep 4, 2009
View
64 net/contrapunctus/lzma/LzmaCompatTest.java
@@ -1,4 +1,4 @@
-// LzmaCompat.java -- test program for compatibility with lzma(1)
+// LzmaCompatTest.java -- test program for compatibility with lzma(1)
// Copyright (c)2009 Christopher League <league@contrapunctus.net>
// This is free software, but it comes with ABSOLUTELY NO WARRANTY.
@@ -7,9 +7,69 @@
package net.contrapunctus.lzma;
import java.io.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.zip.CRC32;
+import java.util.zip.CheckedInputStream;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized.Parameters;
+import org.junit.runners.Parameterized;
+import static org.junit.Assert.assertTrue;
-public class LzmaCompat
+@RunWith(Parameterized.class)
+public class LzmaCompatTest
{
+ @Parameters public static Collection<Object[]> parameters()
+ throws FileNotFoundException
+ {
+ File dir = new File("tests/lzma-cmd");
+ File[] fs = dir.listFiles();
+ if(null == fs)
+ {
+ throw new FileNotFoundException
+ ("directory tests/lzma-cmd not found");
+ }
+ Collection<Object[]> args = new ArrayList<Object[]>();
+ for(File f : fs)
+ {
+ args.add(new Object[] { f });
+ }
+ return args;
+ }
+
+ File file;
+
+ public LzmaCompatTest(File file)
+ {
+ this.file = file;
+ }
+
+ public String toString()
+ {
+ return file.toString();
+ }
+
+ @Test public void decode()
+ throws IOException
+ {
+ System.out.printf("%s:", this);
+ FileInputStream fis = new FileInputStream(file);
+ LzmaInputStream lis = new LzmaInputStream(fis);
+ CRC32 sum = new CRC32();
+ CheckedInputStream cis = new CheckedInputStream(lis, sum);
+ byte[] buf = new byte[4096];
+ int k, n = 0;
+ while( -1 != (k = cis.read(buf)))
+ {
+ n += k;
+ }
+ cis.close();
+ long val = sum.getValue();
+ System.out.printf("%d bytes, sum %x\n", n, val);
+ assertTrue(file.getName().startsWith(Long.toHexString(val)));
+ }
+
public static void writeFile( String name ) throws IOException
{
System.out.printf("writing %s with%s header\n",
View
BIN tests/lzma-cmd/f3d7485d.1.lzma
Binary file not shown.
View
BIN tests/lzma-cmd/f3d7485d.2.lzma
Binary file not shown.
View
BIN tests/lzma-cmd/f3d7485d.3.lzma
Binary file not shown.
View
BIN tests/lzma-cmd/f3d7485d.4.lzma
Binary file not shown.
View
BIN tests/lzma-cmd/f3d7485d.5.lzma
Binary file not shown.
View
BIN tests/lzma-cmd/f3d7485d.6.lzma
Binary file not shown.
View
BIN tests/lzma-cmd/f3d7485d.7.lzma
Binary file not shown.
View
BIN tests/lzma-cmd/f3d7485d.8.lzma
Binary file not shown.
View
BIN tests/lzma-cmd/f3d7485d.9.lzma
Binary file not shown.

0 comments on commit 60fa2f7

Please sign in to comment.
Something went wrong with that request. Please try again.