From 34eea4b0f7e56f4153cc9e22924140c48bdc217e Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Wed, 18 Sep 2013 04:00:02 +0000 Subject: [PATCH] tweak oleblob tests git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@806 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/util/OleBlob.java | 2 +- .../jackcess/DatabaseTest.java | 1 + .../jackcess/util/OleBlobTest.java | 74 +++++++++++-------- 3 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/healthmarketscience/jackcess/util/OleBlob.java b/src/main/java/com/healthmarketscience/jackcess/util/OleBlob.java index bcc807e..6cc9a64 100644 --- a/src/main/java/com/healthmarketscience/jackcess/util/OleBlob.java +++ b/src/main/java/com/healthmarketscience/jackcess/util/OleBlob.java @@ -380,7 +380,7 @@ public interface OleBlob extends Blob, Closeable return this; } - public Builder setOther(File f) { + public Builder setOther(File f) throws FileNotFoundException { return setOtherStream(new FileInputStream(f), f.length()); } diff --git a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java index a21fb0b..5d67463 100644 --- a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -27,6 +27,7 @@ King of Prussia, PA 19406 package com.healthmarketscience.jackcess; +import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; diff --git a/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java b/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java index c8ea778..1c3e104 100644 --- a/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java @@ -19,7 +19,20 @@ USA package com.healthmarketscience.jackcess.util; +import java.io.File; +import java.util.Arrays; + +import com.healthmarketscience.jackcess.ColumnBuilder; +import com.healthmarketscience.jackcess.DataType; +import com.healthmarketscience.jackcess.Database; +import com.healthmarketscience.jackcess.Database.FileFormat; import static com.healthmarketscience.jackcess.DatabaseTest.*; +import com.healthmarketscience.jackcess.Row; +import com.healthmarketscience.jackcess.Table; +import com.healthmarketscience.jackcess.TableBuilder; +import com.healthmarketscience.jackcess.impl.ByteUtil; +import static com.healthmarketscience.jackcess.impl.JetFormatTest.*; +import junit.framework.TestCase; /** * @@ -35,11 +48,11 @@ public class OleBlobTest extends TestCase public void testCreateBlob() throws Exception { File sampleFile = new File("src/test/data/sample-input.tab"); - String sampleFilePath = sampleFileStr.getAbsolutePath(); + String sampleFilePath = sampleFile.getAbsolutePath(); String sampleFileName = sampleFile.getName(); byte[] sampleFileBytes = toByteArray(sampleFile); - for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { + for(FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = create(fileFormat); Table t = new TableBuilder("TestOle") @@ -79,54 +92,57 @@ public class OleBlobTest extends TestCase } for(Row row : t) { - OleBlob blob = null; try { blob = OleBlob.Builder.fromInternalData( (byte[])row.get("ole")); - Content content = blob.getContent(); + OleBlob.Content content = blob.getContent(); assertSame(blob, content.getBlob()); assertSame(content, blob.getContent()); switch((Integer)row.get("id")) { case 1: assertEquals(OleBlob.ContentType.SIMPLE_PACKAGE, content.getType()); - assertEquals(sampleFilePath, content.getFilePath()); - assertEquals(sampleFilePath, content.getLocalFilePath()); - assertEquals(sampleFileName, content.getFileName()); + OleBlob.SimplePackageContent spc = (OleBlob.SimplePackageContent)content; + assertEquals(sampleFilePath, spc.getFilePath()); + assertEquals(sampleFilePath, spc.getLocalFilePath()); + assertEquals(sampleFileName, spc.getFileName()); assertEquals(OleBlob.Builder.PACKAGE_PRETTY_NAME, - content.getPrettyName()); + spc.getPrettyName()); assertEquals(OleBlob.Builder.PACKAGE_TYPE_NAME, - content.getTypeName()); + spc.getTypeName()); assertEquals(OleBlob.Builder.PACKAGE_TYPE_NAME, - content.getClassName()); - assertEquals(sampleFileBytes.length, content.length()); - assertEquals(sampleFileBytes, toByteArray(content.getStream())); + spc.getClassName()); + assertEquals(sampleFileBytes.length, spc.length()); + assertTrue(Arrays.equals(sampleFileBytes, + toByteArray(spc.getStream(), spc.length()))); break; + case 2: - assertEquals(OleBlob.ContentType.LINK, content.getType()); - assertEquals(sampleFilePath, content.getLinkPath()); - assertEquals(sampleFilePath, content.getFilePath()); - assertEquals(sampleFileName, content.getFileName()); - assertEquals(OleBlob.Builder.PACKAGE_PRETTY_NAME, - content.getPrettyName()); - assertEquals(OleBlob.Builder.PACKAGE_TYPE_NAME, - content.getTypeName()); - assertEquals(OleBlob.Builder.PACKAGE_TYPE_NAME, - content.getClassName()); + OleBlob.LinkContent lc = (OleBlob.LinkContent)content; + assertEquals(OleBlob.ContentType.LINK, lc.getType()); + assertEquals(sampleFilePath, lc.getLinkPath()); + assertEquals(sampleFilePath, lc.getFilePath()); + assertEquals(sampleFileName, lc.getFileName()); + assertEquals(OleBlob.Builder.PACKAGE_PRETTY_NAME, lc.getPrettyName()); + assertEquals(OleBlob.Builder.PACKAGE_TYPE_NAME, lc.getTypeName()); + assertEquals(OleBlob.Builder.PACKAGE_TYPE_NAME, lc.getClassName()); break; + case 3: - assertEquals(OleBlob.ContentType.OTHER, content.getType()); - assertEquals("Text File", content.getPrettyName()); - assertEquals("Text.File", content.getClassName()); - assertEquals("TextFile", content.getTypeName()); - assertEquals(sampleFileBytes.length, content.length()); - assertEquals(sampleFileBytes, toByteArray(content.getStream())); + OleBlob.OtherContent oc = (OleBlob.OtherContent)content; + assertEquals(OleBlob.ContentType.OTHER, oc.getType()); + assertEquals("Text File", oc.getPrettyName()); + assertEquals("Text.File", oc.getClassName()); + assertEquals("TextFile", oc.getTypeName()); + assertEquals(sampleFileBytes.length, oc.length()); + assertTrue(Arrays.equals(sampleFileBytes, + toByteArray(oc.getStream(), oc.length()))); break; default: throw new RuntimeException("unexpected id " + row); } } finally { - ByteUtil.closeQuietly(oleBlob); + ByteUtil.closeQuietly(blob); } } -- 2.39.5