Changed test to test byte-by-byte instead of a String, since some of the data files are binary.

This commit is contained in:
Robert Greene 2008-06-27 18:41:15 +00:00
parent acb0912244
commit d93c504165

View File

@ -1,11 +1,10 @@
package com.webcodepro.shrinkit.io; package com.webcodepro.shrinkit.io;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
import junit.framework.TestCase;
import com.webcodepro.shrinkit.HeaderBlock; import com.webcodepro.shrinkit.HeaderBlock;
import com.webcodepro.shrinkit.NuFileArchive; import com.webcodepro.shrinkit.NuFileArchive;
import com.webcodepro.shrinkit.ThreadRecord; import com.webcodepro.shrinkit.ThreadRecord;
@ -16,7 +15,7 @@ import com.webcodepro.shrinkit.ThreadRecord;
* *
* @author robgreene@users.sourceforge.net * @author robgreene@users.sourceforge.net
*/ */
public class NufxLzwTest extends TestCase { public class NufxLzwTest extends TestCaseHelper {
public void testNufxLzw1() throws IOException { public void testNufxLzw1() throws IOException {
check("APPLE.II-LZW1.SHK", "APPLE.II", "APPLE.II.txt"); check("APPLE.II-LZW1.SHK", "APPLE.II", "APPLE.II.txt");
} }
@ -44,28 +43,28 @@ public class NufxLzwTest extends TestCase {
protected void check(String archiveName, String archiveFile, String expectedContentFile) throws IOException { protected void check(String archiveName, String archiveFile, String expectedContentFile) throws IOException {
NuFileArchive archive = new NuFileArchive(getClass().getResourceAsStream(archiveName)); NuFileArchive archive = new NuFileArchive(getClass().getResourceAsStream(archiveName));
List<HeaderBlock> headers = archive.getHeaderBlocks(); List<HeaderBlock> headers = archive.getHeaderBlocks();
String actual = null; byte[] actual = null;
for (HeaderBlock header : headers) { for (HeaderBlock header : headers) {
if (archiveFile.equals(header.getFilename())) { if (archiveFile.equals(header.getFilename())) {
ThreadRecord r = header.getDataForkInputStream(); ThreadRecord r = header.getDataForkInputStream();
long bytes = r.getThreadEof(); long bytes = r.getThreadEof();
StringBuffer buf = new StringBuffer(); ByteArrayOutputStream buf = new ByteArrayOutputStream();
InputStream is = r.getInputStream(); InputStream is = r.getInputStream();
while ( bytes-- > 0 ) { while ( bytes-- > 0 ) {
buf.append((char)is.read()); buf.write(is.read());
} }
actual = buf.toString(); actual = buf.toByteArray();
is.close(); is.close();
break; break;
} }
} }
InputStream is = getClass().getResourceAsStream(expectedContentFile); InputStream is = getClass().getResourceAsStream(expectedContentFile);
StringBuffer buf = new StringBuffer(); ByteArrayOutputStream buf = new ByteArrayOutputStream();
int ch; int b;
while ( (ch = is.read()) != -1 ) { while ( (b = is.read()) != -1 ) {
buf.append((char)ch); buf.write(b);
} }
String expected = buf.toString(); byte[] expected = buf.toByteArray();
assertEquals(expected, actual); assertEquals(expected, actual);
} }
} }