From 680740dc252be1a172dc5d298b4ee09b30431665 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 11 May 2015 18:00:45 +0000 Subject: [PATCH] Add a deep re-write NPOIFS test git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678781 13f79535-47bb-0310-9956-ffa450edef68 --- .../poifs/filesystem/TestFileSystemBugs.java | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java b/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java index fc3d4a958d..3de3ccb8dc 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java @@ -21,8 +21,10 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import junit.framework.TestCase; @@ -125,9 +127,11 @@ public final class TestFileSystemBugs extends TestCase { /** * With heavily nested documents, ensure we still re-write the same */ - public void IGNOREDtestHeavilyNestedReWrite() throws Exception { + public void testHeavilyNestedReWrite() throws Exception { for (DirectoryNode root : openSSSample("ex42570-20305.xls", false)) { - // TODO Record the structure + // Record the structure + Map entries = new HashMap(); + fetchSizes("/", root, entries); // Prepare to copy DirectoryNode dest; @@ -150,7 +154,33 @@ public final class TestFileSystemBugs extends TestCase { NPOIFSFileSystem read = new NPOIFSFileSystem( new ByteArrayInputStream(baos.toByteArray())); - // TODO Check the structure matches + // Check the structure matches + checkSizes("/", read.getRoot(), entries); + } + } + private void fetchSizes(String path, DirectoryNode dir, Map entries) { + for (Entry entry : dir) { + if (entry instanceof DirectoryNode) { + String ourPath = path + entry.getName() + "/"; + entries.put(ourPath, -1); + fetchSizes(ourPath, (DirectoryNode)entry, entries); + } else { + DocumentNode doc = (DocumentNode)entry; + entries.put(path+entry.getName(), doc.getSize()); + } + } + } + private void checkSizes(String path, DirectoryNode dir, Map entries) { + for (Entry entry : dir) { + if (entry instanceof DirectoryNode) { + String ourPath = path + entry.getName() + "/"; + assertTrue(entries.containsKey(ourPath)); + assertEquals(-1, entries.get(ourPath).intValue()); + checkSizes(ourPath, (DirectoryNode)entry, entries); + } else { + DocumentNode doc = (DocumentNode)entry; + assertEquals(entries.get(path+entry.getName()).intValue(), doc.getSize()); + } } } } -- 2.39.5