diff options
author | Nick Burch <nick@apache.org> | 2015-05-11 14:58:43 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2015-05-11 14:58:43 +0000 |
commit | 3e2fa9befaa8e4312abdef743cef9ece92ae8f9d (patch) | |
tree | ba1479c75baef03e2c22970cd1af052c4c7a2935 /src | |
parent | 55d20266dc6c8141c9ef72cd78f317a39d910a1a (diff) | |
download | poi-3e2fa9befaa8e4312abdef743cef9ece92ae8f9d.tar.gz poi-3e2fa9befaa8e4312abdef743cef9ece92ae8f9d.zip |
Add a (disabled) failing unit test on heavily nested NPOIFS copies, found working on #56791
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678764 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java b/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java index f6540b4d30..fc3d4a958d 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java @@ -17,6 +17,9 @@ package org.apache.poi.poifs.filesystem; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -30,6 +33,7 @@ import org.apache.poi.POIDataSamples; */ public final class TestFileSystemBugs extends TestCase { protected static POIDataSamples _samples = POIDataSamples.getPOIFSInstance(); + protected static POIDataSamples _ssSamples = POIDataSamples.getSpreadSheetInstance(); protected List<NPOIFSFileSystem> openedFSs; protected void tearDown() throws Exception { @@ -45,15 +49,25 @@ public final class TestFileSystemBugs extends TestCase { openedFSs = null; } protected DirectoryNode[] openSample(String name, boolean oldFails) throws Exception { - NPOIFSFileSystem nfs = new NPOIFSFileSystem( - _samples.openResourceAsStream(name)); + return openSamples(new InputStream[] { + _samples.openResourceAsStream(name), + _samples.openResourceAsStream(name) + }, oldFails); + } + protected DirectoryNode[] openSSSample(String name, boolean oldFails) throws Exception { + return openSamples(new InputStream[] { + _ssSamples.openResourceAsStream(name), + _ssSamples.openResourceAsStream(name) + }, oldFails); + } + protected DirectoryNode[] openSamples(InputStream[] inps, boolean oldFails) throws Exception { + NPOIFSFileSystem nfs = new NPOIFSFileSystem(inps[0]); if (openedFSs == null) openedFSs = new ArrayList<NPOIFSFileSystem>(); openedFSs.add(nfs); POIFSFileSystem ofs = null; try { - ofs = new POIFSFileSystem( - _samples.openResourceAsStream(name)); + ofs = new POIFSFileSystem(inps[1]); if (oldFails) fail("POIFSFileSystem should have failed but didn't"); } catch (Exception e) { if (!oldFails) throw e; @@ -107,4 +121,36 @@ public final class TestFileSystemBugs extends TestCase { assertEquals(42, root.getEntryCount()); } } + + /** + * With heavily nested documents, ensure we still re-write the same + */ + public void IGNOREDtestHeavilyNestedReWrite() throws Exception { + for (DirectoryNode root : openSSSample("ex42570-20305.xls", false)) { + // TODO Record the structure + + // Prepare to copy + DirectoryNode dest; + if (root.getNFileSystem() != null) { + dest = (new NPOIFSFileSystem()).getRoot(); + } else { + dest = (new OPOIFSFileSystem()).getRoot(); + } + + // Copy over + EntryUtils.copyNodes(root, dest); + + // Re-load, always as NPOIFS + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + if (root.getNFileSystem() != null) { + root.getNFileSystem().writeFilesystem(baos); + } else { + root.getOFileSystem().writeFilesystem(baos); + } + NPOIFSFileSystem read = new NPOIFSFileSystem( + new ByteArrayInputStream(baos.toByteArray())); + + // TODO Check the structure matches + } + } } |