aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2013-09-18 04:00:02 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2013-09-18 04:00:02 +0000
commit34eea4b0f7e56f4153cc9e22924140c48bdc217e (patch)
treeec554f05818fb056e2f895c85d838e5655e6f13c /src/test/java
parent14afae193e91dad61180ab23ffbd2bc39dcfec2d (diff)
downloadjackcess-34eea4b0f7e56f4153cc9e22924140c48bdc217e.tar.gz
jackcess-34eea4b0f7e56f4153cc9e22924140c48bdc217e.zip
tweak oleblob tests
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@806 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java1
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java74
2 files changed, 46 insertions, 29 deletions
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);
}
}