Add unit test for using HSSF with both POIFS and NPOIFS

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1054190 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2011-01-01 05:30:11 +00:00
parent bc2f0eb994
commit 981b7cbd8e
3 changed files with 34 additions and 1 deletions

View File

@ -51,7 +51,7 @@ public final class NPOIFSDocument implements POIFSViewable {
this._property = property; this._property = property;
this._filesystem = filesystem; 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()); _stream = new NPOIFSStream(_filesystem.getMiniStore(), property.getStartBlock());
_block_size = _filesystem.getMiniStore().getBlockStoreBlockSize(); _block_size = _filesystem.getMiniStore().getBlockStoreBlockSize();
} else { } else {

View File

@ -19,6 +19,7 @@ package org.apache.poi.hssf;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -37,6 +38,9 @@ public final class HSSFTestDataSamples {
public static InputStream openSampleFileStream(String sampleFileName) { public static InputStream openSampleFileStream(String sampleFileName) {
return _inst.openResourceAsStream(sampleFileName); return _inst.openResourceAsStream(sampleFileName);
} }
public static File getSampeFile(String sampleFileName) {
return _inst.getFile(sampleFileName);
}
public static byte[] getTestDataFileContent(String fileName) { public static byte[] getTestDataFileContent(String fileName) {
return _inst.readFile(fileName); return _inst.readFile(fileName);
} }

View File

@ -36,6 +36,8 @@ import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.TempFile; import org.apache.poi.util.TempFile;
import org.apache.poi.ss.usermodel.BaseTestWorkbook; 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.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.hpsf.ClassID; import org.apache.poi.hpsf.ClassID;
@ -530,4 +532,31 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
assertTrue(clsid1.equals(clsid2)); 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());
}
}
} }