From 335ba49ef5dc86fcb5ffbda2782e1b16b84cfef8 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 30 Jun 2015 23:50:35 +0000 Subject: [PATCH] More NPOIFS ministream tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1688534 13f79535-47bb-0310-9956-ffa450edef68 --- src/testcases/org/apache/poi/POITestCase.java | 15 ++++ .../poifs/filesystem/TestNPOIFSMiniStore.java | 83 ++++++++++++++++++- 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/src/testcases/org/apache/poi/POITestCase.java b/src/testcases/org/apache/poi/POITestCase.java index 7a1a0274c7..e38e46d4fe 100644 --- a/src/testcases/org/apache/poi/POITestCase.java +++ b/src/testcases/org/apache/poi/POITestCase.java @@ -34,6 +34,21 @@ public class POITestCase extends TestCase { ); } + public static void assertEquals(T[] expected, T[] actual) + { + assertEquals("Non-matching lengths", expected.length, actual.length); + for (int i=0; i void assertContains(T needle, T[] haystack) { // Check diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java index f420683c37..44e066a6f7 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSMiniStore.java @@ -21,15 +21,15 @@ import java.io.ByteArrayInputStream; import java.nio.ByteBuffer; import java.util.Iterator; -import junit.framework.TestCase; - import org.apache.poi.POIDataSamples; +import org.apache.poi.POITestCase; import org.apache.poi.poifs.common.POIFSConstants; +import org.apache.poi.util.IOUtils; /** * Tests for the Mini Store in the NIO POIFS */ -public final class TestNPOIFSMiniStore extends TestCase { +public final class TestNPOIFSMiniStore extends POITestCase { private static final POIDataSamples _inst = POIDataSamples.getPOIFSInstance(); /** @@ -337,6 +337,8 @@ public final class TestNPOIFSMiniStore extends TestCase { public void testCreateMiniStoreFirst() throws Exception { NPOIFSFileSystem fs = new NPOIFSFileSystem(); NPOIFSMiniStore ministore = fs.getMiniStore(); + DocumentInputStream dis; + DocumentEntry entry; // Initially has Properties + BAT but nothing else assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0)); @@ -376,8 +378,83 @@ public final class TestNPOIFSMiniStore extends TestCase { assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(0)); assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(1)); assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(2)); + + // Check the data is unchanged and the right length + entry = (DocumentEntry)fs.getRoot().getEntry("mini"); + assertEquals(data.length, entry.getSize()); + byte[] rdata = new byte[data.length]; + dis = new DocumentInputStream(entry); + IOUtils.readFully(dis, rdata); + assertEquals(data, rdata); + dis.close(); + + entry = (DocumentEntry)fs.getRoot().getEntry("mini2"); + assertEquals(data.length, entry.getSize()); + rdata = new byte[data.length]; + dis = new DocumentInputStream(entry); + IOUtils.readFully(dis, rdata); + assertEquals(data, rdata); + dis.close(); // Done fs.close(); } + + public void testMultiBlockStream() throws Exception { + byte[] data1B = new byte[63]; + byte[] data2B = new byte[64+14]; + for (int i=0; i