]> source.dussan.org Git - jackcess.git/commitdiff
tweak oleblob tests
authorJames Ahlborn <jtahlborn@yahoo.com>
Wed, 18 Sep 2013 04:00:02 +0000 (04:00 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Wed, 18 Sep 2013 04:00:02 +0000 (04:00 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@806 f203690c-595d-4dc9-a70b-905162fa7fd2

src/main/java/com/healthmarketscience/jackcess/util/OleBlob.java
src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java
src/test/java/com/healthmarketscience/jackcess/util/OleBlobTest.java

index bcc807ec1139d8c64d86e6a1d5c7354e2664cc9a..6cc9a6406b8e1d6cbeef170e596047680d308dc3 100644 (file)
@@ -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());
     }
 
index a21fb0b1ab951d0ad8cd710193d607f9c45826d7..5d6746352a3fdbfcc8d2dcafaa4119d1f74768c8 100644 (file)
@@ -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;
index c8ea7784617ea04bc0a09cf1e82418fc9877bac8..1c3e10473442e4579874c3b7a9630f9296a8d6da 100644 (file)
@@ -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);
         }
       }