diff options
author | Nick Burch <nick@apache.org> | 2015-04-23 18:26:01 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2015-04-23 18:26:01 +0000 |
commit | 4a33fe786c119ad1b1310bdbd81dfb692db446f6 (patch) | |
tree | 5dcf6c55a3a25c0b1c5b7f47bd2132703899e2f1 /src/testcases/org/apache/poi/poifs | |
parent | 158a02f14431265f0642aa3b1c886d6389e59b07 (diff) | |
download | poi-4a33fe786c119ad1b1310bdbd81dfb692db446f6.tar.gz poi-4a33fe786c119ad1b1310bdbd81dfb692db446f6.zip |
Make the opening code generic
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1675700 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/poifs')
-rw-r--r-- | src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java b/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java index c5fe52f819..6033e0e494 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java @@ -17,7 +17,9 @@ package org.apache.poi.poifs.filesystem; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import junit.framework.TestCase; @@ -27,26 +29,40 @@ import org.apache.poi.POIDataSamples; * Tests bugs across both POIFSFileSystem and NPOIFSFileSystem */ public final class TestFileSystemBugs extends TestCase { + protected static POIDataSamples _samples = POIDataSamples.getPOIFSInstance(); + + protected List<NPOIFSFileSystem> openedFSs; + protected void tearDown() throws Exception { + if (openedFSs != null && !openedFSs.isEmpty()) { + for (NPOIFSFileSystem fs : openedFSs) { + try { + fs.close(); + } catch (Exception e) { + System.err.println("Error closing FS: " + e); + } + } + } + openedFSs = null; + } + protected DirectoryNode[] openSample(String name) throws Exception { + POIFSFileSystem ofs = new POIFSFileSystem( + _samples.openResourceAsStream(name)); + NPOIFSFileSystem nfs = new NPOIFSFileSystem( + _samples.openResourceAsStream(name)); + + if (openedFSs == null) openedFSs = new ArrayList<NPOIFSFileSystem>(); + openedFSs.add(nfs); + + return new DirectoryNode[] { ofs.getRoot(), nfs.getRoot() }; + } + /** * Test that we can open files that come via Lotus notes. * These have a top level directory without a name.... */ public void testNotesOLE2Files() throws Exception { - POIDataSamples _samples = POIDataSamples.getPOIFSInstance(); - - // Open the file up with the two FileSystems - @SuppressWarnings("resource") - DirectoryNode[] roots = new DirectoryNode[] { - new POIFSFileSystem( - _samples.openResourceAsStream("Notes.ole2") - ).getRoot(), - new NPOIFSFileSystem( - _samples.openResourceAsStream("Notes.ole2") - ).getRoot() - }; - // Check the contents - for (DirectoryNode root : roots) { + for (DirectoryNode root : openSample("Notes.ole2")) { assertEquals(1, root.getEntryCount()); Entry entry = root.getEntries().next(); @@ -69,10 +85,6 @@ public final class TestFileSystemBugs extends TestCase { entry = it.next(); assertEquals(true, entry.isDocumentEntry()); assertEquals("\u0001CompObj", entry.getName()); - - // Tidy - if (root.getNFileSystem() != null) - root.getNFileSystem().close(); } } } |