]> source.dussan.org Git - poi.git/commitdiff
Add unit test for using HSSF with both POIFS and NPOIFS
authorNick Burch <nick@apache.org>
Sat, 1 Jan 2011 05:30:11 +0000 (05:30 +0000)
committerNick Burch <nick@apache.org>
Sat, 1 Jan 2011 05:30:11 +0000 (05:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1054190 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java
src/testcases/org/apache/poi/hssf/HSSFTestDataSamples.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java

index 09536d4ade5e5f2330ca01f77becbcc90ce14393..3a2c28602336e2e0328ee23cdc68a22bfef4f05b 100644 (file)
@@ -51,7 +51,7 @@ public final class NPOIFSDocument implements POIFSViewable {
       this._property = property;
       this._filesystem = filesystem;
 
-      if(property.getSize() <= POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE) {
+      if(property.getSize() < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE) {
          _stream = new NPOIFSStream(_filesystem.getMiniStore(), property.getStartBlock());
          _block_size = _filesystem.getMiniStore().getBlockStoreBlockSize();
       } else {
index 2e4553ff71a5c5eb2d709e5374cef5ed654ded99..46e4ec55ef97b3c5ff4ed8bc4f2ec57521410902 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.poi.hssf;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -37,6 +38,9 @@ public final class HSSFTestDataSamples {
        public static InputStream openSampleFileStream(String sampleFileName) {
                return _inst.openResourceAsStream(sampleFileName);
        }
+       public static File getSampeFile(String sampleFileName) {
+          return _inst.getFile(sampleFileName);
+       }
        public static byte[] getTestDataFileContent(String fileName) {
                return _inst.readFile(fileName);
        }
index 56ad37b2d55c22caf82a4913f84b188e0699c3bb..81da9971bd224f5e6549e74acf729609b4d057d2 100644 (file)
@@ -36,6 +36,8 @@ import org.apache.poi.ss.formula.ptg.Area3DPtg;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.TempFile;
 import org.apache.poi.ss.usermodel.BaseTestWorkbook;
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hpsf.ClassID;
@@ -530,4 +532,31 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
 
         assertTrue(clsid1.equals(clsid2));
     }
+    
+    /**
+     * Tests that we can work with both {@link POIFSFileSystem}
+     *  and {@link NPOIFSFileSystem}
+     */
+    public void testDifferentPOIFS() throws Exception {
+       // Open the two filesystems
+       DirectoryNode[] files = new DirectoryNode[2];
+       files[0] = (new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("Simple.xls"))).getRoot();
+       files[1] = (new NPOIFSFileSystem(HSSFTestDataSamples.getSampeFile("Simple.xls"))).getRoot();
+       
+       // Open without preserving nodes 
+       for(DirectoryNode dir : files) {
+          HSSFWorkbook workbook = new HSSFWorkbook(dir, false);
+          HSSFSheet sheet = workbook.getSheetAt(0);
+          HSSFCell cell = sheet.getRow(0).getCell(0);
+          assertEquals("replaceMe", cell .getRichStringCellValue().getString());
+       }
+
+       // Now re-check with preserving
+       for(DirectoryNode dir : files) {
+          HSSFWorkbook workbook = new HSSFWorkbook(dir, true);
+          HSSFSheet sheet = workbook.getSheetAt(0);
+          HSSFCell cell = sheet.getRow(0).getCell(0);
+          assertEquals("replaceMe", cell .getRichStringCellValue().getString());
+       }
+    }
 }