You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2020/12/24 18:42:38 UTC
svn commit: r1884783 [28/40] - in /poi:
site/src/documentation/content/xdocs/ trunk/ trunk/sonar/
trunk/sonar/integration-test/ trunk/sonar/ooxml/
trunk/src/excelant/poi-ant-contrib/
trunk/src/excelant/testcases/org/apache/poi/ss/excelant/ trunk/src/ex...
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileMagic.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileMagic.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileMagic.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileMagic.java Thu Dec 24 18:42:29 2020
@@ -17,13 +17,13 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.BufferedInputStream;
import java.io.File;
@@ -37,7 +37,7 @@ import java.util.Random;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.TempFile;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestFileMagic {
@Test
@@ -62,12 +62,7 @@ public class TestFileMagic {
assertEquals(FileMagic.UNKNOWN, FileMagic.valueOf("something".getBytes(StandardCharsets.UTF_8)));
assertEquals(FileMagic.UNKNOWN, FileMagic.valueOf(new byte[0]));
- try {
- FileMagic.valueOf("some string");
- fail("Should catch exception here");
- } catch (IllegalArgumentException e) {
- // expected here
- }
+ assertThrows(IllegalArgumentException.class, () -> FileMagic.valueOf("some string"));
}
@Test
@@ -134,7 +129,7 @@ public class TestFileMagic {
}
}
- @Test(expected = IOException.class)
+ @Test
public void testMarkRequired() throws IOException {
byte[] data = new byte[] { -1, -40, -1, -32, 0 };
@@ -148,7 +143,7 @@ public class TestFileMagic {
try (FileInputStream str = new FileInputStream(file)) {
assertFalse(str.markSupported());
- FileMagic.valueOf(str);
+ assertThrows(IOException.class, () -> FileMagic.valueOf(str));
}
} finally {
assertTrue(file.delete());
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java Thu Dec 24 18:42:29 2020
@@ -17,8 +17,8 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -30,8 +30,8 @@ import java.util.List;
import java.util.Map;
import org.apache.poi.POIDataSamples;
-import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
/**
* Tests bugs for POIFSFileSystem
@@ -42,7 +42,7 @@ public final class TestFileSystemBugs {
private List<POIFSFileSystem> openedFSs;
- @After
+ @AfterEach
public void tearDown() {
if (openedFSs != null && !openedFSs.isEmpty()) {
for (POIFSFileSystem fs : openedFSs) {
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFilteringDirectoryNode.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFilteringDirectoryNode.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFilteringDirectoryNode.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFilteringDirectoryNode.java Thu Dec 24 18:42:29 2020
@@ -18,11 +18,10 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
@@ -32,177 +31,134 @@ import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
/**
* Class to test FilteringDirectoryNode functionality
*/
public final class TestFilteringDirectoryNode {
- private POIFSFileSystem fs;
- private DirectoryEntry dirA;
- private DirectoryEntry dirAA;
- private DirectoryEntry dirB;
- private DocumentEntry eRoot;
- private DocumentEntry eA;
- private DocumentEntry eAA;
-
- @Before
- public void setUp() throws Exception {
- fs = new POIFSFileSystem();
- dirA = fs.createDirectory("DirA");
- dirB = fs.createDirectory("DirB");
- dirAA = dirA.createDirectory("DirAA");
- eRoot = fs.getRoot().createDocument("Root", new ByteArrayInputStream(new byte[]{}));
- eA = dirA.createDocument("NA", new ByteArrayInputStream(new byte[]{}));
- eAA = dirAA.createDocument("NAA", new ByteArrayInputStream(new byte[]{}));
- }
-
- @Test
- public void testNoFiltering() throws Exception {
- FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), new HashSet<>());
- assertEquals(3, d.getEntryCount());
- assertEquals(dirA.getName(), d.getEntry(dirA.getName()).getName());
-
- assertTrue(d.getEntry(dirA.getName()).isDirectoryEntry());
- assertFalse(d.getEntry(dirA.getName()).isDocumentEntry());
-
- assertTrue(d.getEntry(dirB.getName()).isDirectoryEntry());
- assertFalse(d.getEntry(dirB.getName()).isDocumentEntry());
-
- assertFalse(d.getEntry(eRoot.getName()).isDirectoryEntry());
- assertTrue(d.getEntry(eRoot.getName()).isDocumentEntry());
-
- Iterator<Entry> i = d.getEntries();
- assertEquals(dirA, i.next());
- assertEquals(dirB, i.next());
- assertEquals(eRoot, i.next());
- try {
- assertNull(i.next());
- fail("Should throw NoSuchElementException when depleted");
- } catch (NoSuchElementException ignored) {
- }
- }
-
- @Test
- public void testChildFiltering() throws Exception {
- List<String> excl = Arrays.asList("NotThere", "AlsoNotThere", eRoot.getName());
- FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), excl);
-
- assertEquals(2, d.getEntryCount());
- assertTrue(d.hasEntry(dirA.getName()));
- assertTrue(d.hasEntry(dirB.getName()));
- assertFalse(d.hasEntry(eRoot.getName()));
-
- assertEquals(dirA, d.getEntry(dirA.getName()));
- assertEquals(dirB, d.getEntry(dirB.getName()));
- try {
- d.getEntry(eRoot.getName());
- fail("Should be filtered");
- } catch (FileNotFoundException e) {
- }
-
- Iterator<Entry> i = d.getEntries();
- assertEquals(dirA, i.next());
- assertEquals(dirB, i.next());
- try {
- assertNull(i.next());
- fail("Should throw NoSuchElementException when depleted");
- } catch (NoSuchElementException ignored) {
- }
-
-
- // Filter more
- excl = Arrays.asList("NotThere", "AlsoNotThere", eRoot.getName(), dirA.getName());
- d = new FilteringDirectoryNode(fs.getRoot(), excl);
-
- assertEquals(1, d.getEntryCount());
- assertFalse(d.hasEntry(dirA.getName()));
- assertTrue(d.hasEntry(dirB.getName()));
- assertFalse(d.hasEntry(eRoot.getName()));
-
- try {
- d.getEntry(dirA.getName());
- fail("Should be filtered");
- } catch (FileNotFoundException e) {
- }
- assertEquals(dirB, d.getEntry(dirB.getName()));
- try {
- d.getEntry(eRoot.getName());
- fail("Should be filtered");
- } catch (FileNotFoundException e) {
- }
-
- i = d.getEntries();
- assertEquals(dirB, i.next());
- try {
- assertNull(i.next());
- fail("Should throw NoSuchElementException when depleted");
- } catch (NoSuchElementException ignored) {
- }
-
-
- // Filter everything
- excl = Arrays.asList("NotThere", eRoot.getName(), dirA.getName(), dirB.getName());
- d = new FilteringDirectoryNode(fs.getRoot(), excl);
-
- assertEquals(0, d.getEntryCount());
- assertFalse(d.hasEntry(dirA.getName()));
- assertFalse(d.hasEntry(dirB.getName()));
- assertFalse(d.hasEntry(eRoot.getName()));
-
- try {
- d.getEntry(dirA.getName());
- fail("Should be filtered");
- } catch (FileNotFoundException e) {
- }
- try {
- d.getEntry(dirB.getName());
- fail("Should be filtered");
- } catch (FileNotFoundException e) {
- }
- try {
- d.getEntry(eRoot.getName());
- fail("Should be filtered");
- } catch (FileNotFoundException e) {
- }
-
- i = d.getEntries();
- try {
- assertNull(i.next());
- fail("Should throw NoSuchElementException when depleted");
- } catch (NoSuchElementException ignored) {
- }
- }
-
- @Test
- public void testNestedFiltering() throws Exception {
- List<String> excl = Arrays.asList(dirA.getName() + "/" + "MadeUp",
- dirA.getName() + "/" + eA.getName(),
- dirA.getName() + "/" + dirAA.getName() + "/Test",
- eRoot.getName());
- FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), excl);
-
- // Check main
- assertEquals(2, d.getEntryCount());
- assertTrue(d.hasEntry(dirA.getName()));
- assertTrue(d.hasEntry(dirB.getName()));
- assertFalse(d.hasEntry(eRoot.getName()));
-
- // Check filtering down
- assertTrue(d.getEntry(dirA.getName()) instanceof FilteringDirectoryNode);
- assertFalse(d.getEntry(dirB.getName()) instanceof FilteringDirectoryNode);
-
- DirectoryEntry fdA = (DirectoryEntry) d.getEntry(dirA.getName());
- assertFalse(fdA.hasEntry(eA.getName()));
- assertTrue(fdA.hasEntry(dirAA.getName()));
-
- DirectoryEntry fdAA = (DirectoryEntry) fdA.getEntry(dirAA.getName());
- assertTrue(fdAA.hasEntry(eAA.getName()));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNullDirectory() {
- new FilteringDirectoryNode(null, null);
- }
+ private POIFSFileSystem fs;
+ private DirectoryEntry dirA;
+ private DirectoryEntry dirAA;
+ private DirectoryEntry dirB;
+ private DocumentEntry eRoot;
+ private DocumentEntry eA;
+ private DocumentEntry eAA;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ fs = new POIFSFileSystem();
+ dirA = fs.createDirectory("DirA");
+ dirB = fs.createDirectory("DirB");
+ dirAA = dirA.createDirectory("DirAA");
+ eRoot = fs.getRoot().createDocument("Root", new ByteArrayInputStream(new byte[]{}));
+ eA = dirA.createDocument("NA", new ByteArrayInputStream(new byte[]{}));
+ eAA = dirAA.createDocument("NAA", new ByteArrayInputStream(new byte[]{}));
+ }
+
+ @Test
+ public void testNoFiltering() throws Exception {
+ FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), new HashSet<>());
+ assertEquals(3, d.getEntryCount());
+ assertEquals(dirA.getName(), d.getEntry(dirA.getName()).getName());
+
+ assertTrue(d.getEntry(dirA.getName()).isDirectoryEntry());
+ assertFalse(d.getEntry(dirA.getName()).isDocumentEntry());
+
+ assertTrue(d.getEntry(dirB.getName()).isDirectoryEntry());
+ assertFalse(d.getEntry(dirB.getName()).isDocumentEntry());
+
+ assertFalse(d.getEntry(eRoot.getName()).isDirectoryEntry());
+ assertTrue(d.getEntry(eRoot.getName()).isDocumentEntry());
+
+ Iterator<Entry> i = d.getEntries();
+ assertEquals(dirA, i.next());
+ assertEquals(dirB, i.next());
+ assertEquals(eRoot, i.next());
+ assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted");
+ }
+
+ @Test
+ public void testChildFiltering() throws Exception {
+ List<String> excl = Arrays.asList("NotThere", "AlsoNotThere", eRoot.getName());
+ FilteringDirectoryNode d1 = new FilteringDirectoryNode(fs.getRoot(), excl);
+
+ assertEquals(2, d1.getEntryCount());
+ assertTrue(d1.hasEntry(dirA.getName()));
+ assertTrue(d1.hasEntry(dirB.getName()));
+ assertFalse(d1.hasEntry(eRoot.getName()));
+
+ assertEquals(dirA, d1.getEntry(dirA.getName()));
+ assertEquals(dirB, d1.getEntry(dirB.getName()));
+ assertThrows(FileNotFoundException.class, () -> d1.getEntry(eRoot.getName()));
+
+ Iterator<Entry> i = d1.getEntries();
+ assertEquals(dirA, i.next());
+ assertEquals(dirB, i.next());
+ assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted");
+
+
+ // Filter more
+ excl = Arrays.asList("NotThere", "AlsoNotThere", eRoot.getName(), dirA.getName());
+ FilteringDirectoryNode d2 = new FilteringDirectoryNode(fs.getRoot(), excl);
+
+ assertEquals(1, d2.getEntryCount());
+ assertFalse(d2.hasEntry(dirA.getName()));
+ assertTrue(d2.hasEntry(dirB.getName()));
+ assertFalse(d2.hasEntry(eRoot.getName()));
+ assertThrows(FileNotFoundException.class, () -> d2.getEntry(dirA.getName()), "Should be filtered");
+ assertEquals(dirB, d2.getEntry(dirB.getName()));
+ assertThrows(FileNotFoundException.class, () -> d2.getEntry(eRoot.getName()), "Should be filtered");
+
+ i = d2.getEntries();
+ assertEquals(dirB, i.next());
+ assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted");
+
+ // Filter everything
+ excl = Arrays.asList("NotThere", eRoot.getName(), dirA.getName(), dirB.getName());
+ FilteringDirectoryNode d3 = new FilteringDirectoryNode(fs.getRoot(), excl);
+
+ assertEquals(0, d3.getEntryCount());
+ assertFalse(d3.hasEntry(dirA.getName()));
+ assertFalse(d3.hasEntry(dirB.getName()));
+ assertFalse(d3.hasEntry(eRoot.getName()));
+ assertThrows(FileNotFoundException.class, () -> d3.getEntry(dirA.getName()), "Should be filtered");
+ assertThrows(FileNotFoundException.class, () -> d3.getEntry(dirB.getName()), "Should be filtered");
+ assertThrows(FileNotFoundException.class, () -> d3.getEntry(eRoot.getName()), "Should be filtered");
+
+ i = d3.getEntries();
+ assertThrows(NoSuchElementException.class, i::next, "Should throw NoSuchElementException when depleted");
+ }
+
+ @Test
+ public void testNestedFiltering() throws Exception {
+ List<String> excl = Arrays.asList(dirA.getName() + "/" + "MadeUp",
+ dirA.getName() + "/" + eA.getName(),
+ dirA.getName() + "/" + dirAA.getName() + "/Test",
+ eRoot.getName());
+ FilteringDirectoryNode d = new FilteringDirectoryNode(fs.getRoot(), excl);
+
+ // Check main
+ assertEquals(2, d.getEntryCount());
+ assertTrue(d.hasEntry(dirA.getName()));
+ assertTrue(d.hasEntry(dirB.getName()));
+ assertFalse(d.hasEntry(eRoot.getName()));
+
+ // Check filtering down
+ assertTrue(d.getEntry(dirA.getName()) instanceof FilteringDirectoryNode);
+ assertFalse(d.getEntry(dirB.getName()) instanceof FilteringDirectoryNode);
+
+ DirectoryEntry fdA = (DirectoryEntry) d.getEntry(dirA.getName());
+ assertFalse(fdA.hasEntry(eA.getName()));
+ assertTrue(fdA.hasEntry(dirAA.getName()));
+
+ DirectoryEntry fdAA = (DirectoryEntry) fdA.getEntry(dirAA.getName());
+ assertTrue(fdAA.hasEntry(eAA.getName()));
+ }
+
+ @Test
+ public void testNullDirectory() {
+ assertThrows(IllegalArgumentException.class, () -> new FilteringDirectoryNode(null, null));
+ }
}
\ No newline at end of file
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java Thu Dec 24 18:42:29 2020
@@ -18,7 +18,7 @@
package org.apache.poi.poifs.filesystem;
import static org.apache.poi.POITestCase.assertContains;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.IOException;
import java.io.InputStream;
@@ -26,7 +26,7 @@ import java.io.InputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.OldExcelFormatException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test that POIFS complains when given older non-OLE2
@@ -44,10 +44,7 @@ public class TestNotOLE2Exception {
@Test
public void testRawXMLException() throws IOException {
try (InputStream in = openXLSSampleStream("SampleSS.xml")) {
- new POIFSFileSystem(in).close();
- fail("expected exception was not thrown");
- } catch(NotOLE2FileException e) {
- // expected during successful test
+ NotOLE2FileException e = assertThrows(NotOLE2FileException.class, () -> new POIFSFileSystem(in));
assertContains(e.getMessage(), "The supplied data appears to be a raw XML file");
assertContains(e.getMessage(), "Formats such as Office 2003 XML");
}
@@ -56,10 +53,7 @@ public class TestNotOLE2Exception {
@Test
public void testMSWriteException() throws IOException {
try (InputStream in = openDOCSampleStream("MSWriteOld.wri")) {
- new POIFSFileSystem(in).close();
- fail("expected exception was not thrown");
- } catch(NotOLE2FileException e) {
- // expected during successful test
+ NotOLE2FileException e = assertThrows(NotOLE2FileException.class, () -> new POIFSFileSystem(in));
assertContains(e.getMessage(), "The supplied data appears to be in the old MS Write");
assertContains(e.getMessage(), "doesn't currently support");
}
@@ -68,10 +62,7 @@ public class TestNotOLE2Exception {
@Test
public void testBiff3Exception() throws IOException {
try (InputStream in = openXLSSampleStream("testEXCEL_3.xls")) {
- new POIFSFileSystem(in).close();
- fail("expected exception was not thrown");
- } catch(OldExcelFormatException e) {
- // expected during successful test
+ OldExcelFormatException e = assertThrows(OldExcelFormatException.class, () -> new POIFSFileSystem(in));
assertContains(e.getMessage(), "The supplied data appears to be in BIFF3 format");
assertContains(e.getMessage(), "try OldExcelExtractor");
}
@@ -80,10 +71,7 @@ public class TestNotOLE2Exception {
@Test
public void testBiff4Exception() throws IOException {
try (InputStream in = openXLSSampleStream("testEXCEL_4.xls")) {
- new POIFSFileSystem(in).close();
- fail("expected exception was not thrown");
- } catch(OldExcelFormatException e) {
- // expected during successful test
+ OldExcelFormatException e = assertThrows(OldExcelFormatException.class, () -> new POIFSFileSystem(in));
assertContains(e.getMessage(), "The supplied data appears to be in BIFF4 format");
assertContains(e.getMessage(), "try OldExcelExtractor");
}
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestOfficeXMLException.java Thu Dec 24 18:42:29 2020
@@ -17,11 +17,11 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -29,7 +29,7 @@ import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test that POIFS complains when given an Office 2003 XML
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestOle10Native.java Thu Dec 24 18:42:29 2020
@@ -19,9 +19,9 @@ package org.apache.poi.poifs.filesystem;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -34,7 +34,7 @@ import java.util.List;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.RecordFormatException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestOle10Native {
private static final POIDataSamples dataSamples = POIDataSamples.getPOIFSInstance();
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java Thu Dec 24 18:42:29 2020
@@ -17,15 +17,16 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.Arrays;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to test POIFSDocumentPath functionality
@@ -73,14 +74,8 @@ public final class TestPOIFSDocumentPath
// test weird variants
assertEquals(0, new POIFSDocumentPath(null).length());
- try {
- new POIFSDocumentPath(new String[]{"fu", ""});
- fail("should have caught IllegalArgumentException");
- } catch (IllegalArgumentException ignored) { }
- try {
- new POIFSDocumentPath(new String[]{"fu", null});
- fail("should have caught IllegalArgumentException");
- } catch (IllegalArgumentException ignored) { }
+ assertThrows(IllegalArgumentException.class, () -> new POIFSDocumentPath(new String[]{"fu", ""}));
+ assertThrows(IllegalArgumentException.class, () -> new POIFSDocumentPath(new String[]{"fu", null}));
}
/**
@@ -129,16 +124,10 @@ public final class TestPOIFSDocumentPath
new POIFSDocumentPath(base, new String[]{"", "fu"});
// This one shouldn't be allowed
- try {
- new POIFSDocumentPath(base, new String[]{"fu", null});
- fail("should have caught IllegalArgumentException");
- } catch (IllegalArgumentException ignored) { }
+ assertThrows(IllegalArgumentException.class, () -> new POIFSDocumentPath(base, new String[]{"fu", null}));
// Ditto
- try {
- new POIFSDocumentPath(base, new String[]{null, "fu"});
- fail("should have caught IllegalArgumentException");
- } catch (IllegalArgumentException ignored) { }
+ assertThrows(IllegalArgumentException.class, () -> new POIFSDocumentPath(base, new String[]{null, "fu"}));
}
}
@@ -157,7 +146,7 @@ public final class TestPOIFSDocumentPath
for (int j = 0; j < paths.length; j++) {
for (int k = 0; k < paths.length; k++) {
- assertEquals(j + "<>" + k, paths[ j ], paths[ k ]);
+ assertEquals(paths[ j ], paths[ k ], j + "<>" + k);
}
}
a2 = new POIFSDocumentPath(a1, new String[]{"foo"});
@@ -178,7 +167,7 @@ public final class TestPOIFSDocumentPath
for (int k = 0; k < builtUpPaths.length; k++) {
for (int j = 0; j < fullPaths.length; j++) {
if (k == j) {
- assertEquals(j + "<>" + k, fullPaths[ j ], builtUpPaths[ k ]);
+ assertEquals(fullPaths[ j ], builtUpPaths[ k ], j + "<>" + k);
} else {
assertNotEquals(fullPaths[j], builtUpPaths[k]);
}
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java Thu Dec 24 18:42:29 2020
@@ -18,10 +18,9 @@
package org.apache.poi.poifs.filesystem;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -42,7 +41,7 @@ import org.apache.poi.poifs.common.POIFS
import org.apache.poi.poifs.storage.BATBlock;
import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.util.IOUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for the older OPOIFS-based POIFSFileSystem
@@ -113,23 +112,17 @@ public final class TestPOIFSFileSystem {
*/
@Test
public void testAlwaysClose() throws IOException {
- TestIS testIS;
-
// Normal case - read until EOF and close
- testIS = new TestIS(openSampleStream("13224.xls"), -1);
- try (POIFSFileSystem ignored = new POIFSFileSystem(testIS)){
- assertTrue("input stream was not closed", testIS.isClosed());
+ try (TestIS testIS = new TestIS(openSampleStream("13224.xls"), -1);
+ POIFSFileSystem ignored = new POIFSFileSystem(testIS)){
+ assertTrue(testIS.isClosed(), "input stream was not closed");
}
// intended to crash after reading 10000 bytes
- testIS = new TestIS(openSampleStream("13224.xls"), 10000);
- try (POIFSFileSystem ignored = new POIFSFileSystem(testIS)){
- fail("ex should have been thrown");
- } catch (MyEx e) {
- // expected
- assertTrue("input stream was not closed", testIS.isClosed()); // but still should close
- } catch (Exception e) {
- fail("MyEx is expected to be thrown");
+ try (TestIS testIS = new TestIS(openSampleStream("13224.xls"), 10000)){
+ assertThrows(MyEx.class, () -> new POIFSFileSystem(testIS));
+ // but still should close
+ assertTrue(testIS.isClosed(), "input stream was not closed");
}
}
@@ -173,9 +166,9 @@ public final class TestPOIFSFileSystem {
public void testFATandDIFATsectors() throws Exception {
try (InputStream stream = _samples.openResourceAsStream("ReferencesInvalidSectors.mpp")) {
IndexOutOfBoundsException ex = assertThrows(
- "File is corrupt and shouldn't have been opened",
IndexOutOfBoundsException.class,
- () -> new POIFSFileSystem(stream)
+ () -> new POIFSFileSystem(stream),
+ "File is corrupt and shouldn't have been opened"
);
assertTrue(ex.getMessage().contains("Block 1148 not found"));
}
@@ -302,8 +295,7 @@ public final class TestPOIFSFileSystem {
try (POIFSFileSystem poiFS = new POIFSFileSystem(_samples.getFile("64322.ole2"))) {
int count = recurseDir(poiFS.getRoot());
- assertEquals("Expecting a fixed number of entries being found in the test-document",
- 1285, count);
+ assertEquals(1285, count, "Expecting a fixed number of entries being found in the test-document");
}
}
@@ -312,8 +304,7 @@ public final class TestPOIFSFileSystem {
try (POIFSFileSystem poiFS = new POIFSFileSystem(_samples.openResourceAsStream("64322.ole2"))) {
int count = recurseDir(poiFS.getRoot());
- assertEquals("Expecting a fixed number of entries being found in the test-document",
- 1285, count);
+ assertEquals(1285, count, "Expecting a fixed number of entries being found in the test-document");
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSMiniStore.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSMiniStore.java?rev=1884783&r1=1884782&r2=1884783&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSMiniStore.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSMiniStore.java Thu Dec 24 18:42:29 2020
@@ -17,11 +17,12 @@
package org.apache.poi.poifs.filesystem;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
@@ -31,451 +32,443 @@ import java.util.NoSuchElementException;
import org.apache.poi.POIDataSamples;
import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.IOUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Tests for the Mini Store in the NIO POIFS
*/
@SuppressWarnings("CatchMayIgnoreException")
public final class TestPOIFSMiniStore {
- private static final POIDataSamples _inst = POIDataSamples.getPOIFSInstance();
+ private static final POIDataSamples _inst = POIDataSamples.getPOIFSInstance();
- /**
- * Check that for a given mini block, we can correctly figure
- * out what the next one is
- */
- @Test
- public void testNextBlock() throws Exception {
- // It's the same on 512 byte and 4096 byte block files!
- POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
- POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- POIFSFileSystem fsC = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
- POIFSFileSystem fsD = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
- for(POIFSFileSystem fs : new POIFSFileSystem[] {fsA,fsB,fsC,fsD}) {
- POIFSMiniStore ministore = fs.getMiniStore();
-
- // 0 -> 51 is one stream
- for(int i=0; i<50; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(50));
-
- // 51 -> 103 is the next
- for(int i=51; i<103; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(103));
-
- // Then there are 3 one block ones
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(104));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(105));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(106));
-
- // 107 -> 154 is the next
- for(int i=107; i<154; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(154));
-
- // 155 -> 160 is the next
- for(int i=155; i<160; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(160));
-
- // 161 -> 166 is the next
- for(int i=161; i<166; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(166));
-
- // 167 -> 172 is the next
- for(int i=167; i<172; i++) {
- assertEquals(i+1, ministore.getNextBlock(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(172));
-
- // Now some short ones
- assertEquals(174 , ministore.getNextBlock(173));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(174));
-
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(175));
-
- assertEquals(177 , ministore.getNextBlock(176));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(177));
-
- assertEquals(179 , ministore.getNextBlock(178));
- assertEquals(180 , ministore.getNextBlock(179));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
+ /**
+ * Check that for a given mini block, we can correctly figure
+ * out what the next one is
+ */
+ @Test
+ public void testNextBlock() throws Exception {
+ // It's the same on 512 byte and 4096 byte block files!
+ POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+ POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ POIFSFileSystem fsC = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+ POIFSFileSystem fsD = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
+ for (POIFSFileSystem fs : new POIFSFileSystem[]{fsA, fsB, fsC, fsD}) {
+ POIFSMiniStore ministore = fs.getMiniStore();
+
+ // 0 -> 51 is one stream
+ for (int i = 0; i < 50; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(50));
+
+ // 51 -> 103 is the next
+ for (int i = 51; i < 103; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(103));
+
+ // Then there are 3 one block ones
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(104));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(105));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(106));
+
+ // 107 -> 154 is the next
+ for (int i = 107; i < 154; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(154));
+
+ // 155 -> 160 is the next
+ for (int i = 155; i < 160; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(160));
+
+ // 161 -> 166 is the next
+ for (int i = 161; i < 166; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(166));
+
+ // 167 -> 172 is the next
+ for (int i = 167; i < 172; i++) {
+ assertEquals(i + 1, ministore.getNextBlock(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(172));
+
+ // Now some short ones
+ assertEquals(174, ministore.getNextBlock(173));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(174));
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(175));
+
+ assertEquals(177, ministore.getNextBlock(176));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(177));
+
+ assertEquals(179, ministore.getNextBlock(178));
+ assertEquals(180, ministore.getNextBlock(179));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
+
+ // 181 onwards is free
+ for (int i = 181; i < fs.getBigBlockSizeDetails().getBATEntriesPerBlock(); i++) {
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
+ }
+ }
+ fsD.close();
+ fsC.close();
+ fsB.close();
+ fsA.close();
+ }
+
+ /**
+ * Check we get the right data back for each block
+ */
+ @Test
+ public void testGetBlock() throws Exception {
+ // It's the same on 512 byte and 4096 byte block files!
+ POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+ POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ POIFSFileSystem fsC = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
+ POIFSFileSystem fsD = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
+ for (POIFSFileSystem fs : new POIFSFileSystem[]{fsA, fsB, fsC, fsD}) {
+ // Mini stream should be at big block zero
+ assertEquals(0, fs._get_property_table().getRoot().getStartBlock());
+
+ // Grab the ministore
+ POIFSMiniStore ministore = fs.getMiniStore();
+ ByteBuffer b;
+
+ // Runs from the start of the data section in 64 byte chungs
+ b = ministore.getBlockAt(0);
+ assertEquals((byte) 0x9e, b.get());
+ assertEquals((byte) 0x75, b.get());
+ assertEquals((byte) 0x97, b.get());
+ assertEquals((byte) 0xf6, b.get());
+ assertEquals((byte) 0xff, b.get());
+ assertEquals((byte) 0x21, b.get());
+ assertEquals((byte) 0xd2, b.get());
+ assertEquals((byte) 0x11, b.get());
+
+ // And the next block
+ b = ministore.getBlockAt(1);
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x03, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x12, b.get());
+ assertEquals((byte) 0x02, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+
+ // Check the last data block
+ b = ministore.getBlockAt(180);
+ assertEquals((byte) 0x30, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x00, b.get());
+ assertEquals((byte) 0x80, b.get());
+
+ // And the rest until the end of the big block is zeros
+ for (int i = 181; i < 184; i++) {
+ b = ministore.getBlockAt(i);
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ assertEquals((byte) 0, b.get());
+ }
+ }
+ fsD.close();
+ fsC.close();
+ fsB.close();
+ fsA.close();
+ }
+
+ /**
+ * Ask for free blocks where there are some already
+ * to be had from the SFAT
+ */
+ @Test
+ public void testGetFreeBlockWithSpare() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
+ POIFSMiniStore ministore = fs.getMiniStore();
+
+ // Our 2nd SBAT block has spares
+ assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+ assertTrue(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
+
+ // First free one at 181
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(181));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(182));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(183));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(184));
+
+ // Ask, will get 181
+ assertEquals(181, ministore.getFreeBlock());
+
+ // Ask again, will still get 181 as not written to
+ assertEquals(181, ministore.getFreeBlock());
+
+ // Allocate it, then ask again
+ ministore.setNextBlock(181, POIFSConstants.END_OF_CHAIN);
+ assertEquals(182, ministore.getFreeBlock());
+
+ fs.close();
+ }
+
+ /**
+ * Ask for free blocks where no free ones exist, and so the
+ * stream needs to be extended and another SBAT added
+ */
+ @Test
+ public void testGetFreeBlockWithNoneSpare() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ POIFSMiniStore ministore = fs.getMiniStore();
- // 181 onwards is free
- for(int i=181; i<fs.getBigBlockSizeDetails().getBATEntriesPerBlock(); i++) {
+ // We've spare ones from 181 to 255
+ for (int i = 181; i < 256; i++) {
assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
- }
- }
- fsD.close();
- fsC.close();
- fsB.close();
- fsA.close();
- }
-
- /**
- * Check we get the right data back for each block
- */
- @Test
- public void testGetBlock() throws Exception {
- // It's the same on 512 byte and 4096 byte block files!
- POIFSFileSystem fsA = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
- POIFSFileSystem fsB = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- POIFSFileSystem fsC = new POIFSFileSystem(_inst.getFile("BlockSize4096.zvi"));
- POIFSFileSystem fsD = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize4096.zvi"));
- for(POIFSFileSystem fs : new POIFSFileSystem[] {fsA,fsB,fsC,fsD}) {
- // Mini stream should be at big block zero
- assertEquals(0, fs._get_property_table().getRoot().getStartBlock());
-
- // Grab the ministore
- POIFSMiniStore ministore = fs.getMiniStore();
- ByteBuffer b;
-
- // Runs from the start of the data section in 64 byte chungs
- b = ministore.getBlockAt(0);
- assertEquals((byte)0x9e, b.get());
- assertEquals((byte)0x75, b.get());
- assertEquals((byte)0x97, b.get());
- assertEquals((byte)0xf6, b.get());
- assertEquals((byte)0xff, b.get());
- assertEquals((byte)0x21, b.get());
- assertEquals((byte)0xd2, b.get());
- assertEquals((byte)0x11, b.get());
-
- // And the next block
- b = ministore.getBlockAt(1);
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x03, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x12, b.get());
- assertEquals((byte)0x02, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
-
- // Check the last data block
- b = ministore.getBlockAt(180);
- assertEquals((byte)0x30, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x00, b.get());
- assertEquals((byte)0x80, b.get());
-
- // And the rest until the end of the big block is zeros
- for(int i=181; i<184; i++) {
- b = ministore.getBlockAt(i);
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- assertEquals((byte)0, b.get());
- }
- }
- fsD.close();
- fsC.close();
- fsB.close();
- fsA.close();
- }
-
- /**
- * Ask for free blocks where there are some already
- * to be had from the SFAT
- */
- @Test
- public void testGetFreeBlockWithSpare() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.getFile("BlockSize512.zvi"));
- POIFSMiniStore ministore = fs.getMiniStore();
-
- // Our 2nd SBAT block has spares
- assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
- assertTrue(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
-
- // First free one at 181
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(181));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(182));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(183));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(184));
-
- // Ask, will get 181
- assertEquals(181, ministore.getFreeBlock());
-
- // Ask again, will still get 181 as not written to
- assertEquals(181, ministore.getFreeBlock());
-
- // Allocate it, then ask again
- ministore.setNextBlock(181, POIFSConstants.END_OF_CHAIN);
- assertEquals(182, ministore.getFreeBlock());
-
- fs.close();
- }
-
- /**
- * Ask for free blocks where no free ones exist, and so the
- * stream needs to be extended and another SBAT added
- */
- @Test
- public void testGetFreeBlockWithNoneSpare() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- POIFSMiniStore ministore = fs.getMiniStore();
-
- // We've spare ones from 181 to 255
- for(int i=181; i<256; i++) {
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
- }
-
- // Check our SBAT free stuff is correct
- assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
- assertTrue(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
-
- // Allocate all the spare ones
- for(int i=181; i<256; i++) {
- ministore.setNextBlock(i, POIFSConstants.END_OF_CHAIN);
- }
-
- // SBAT are now full, but there's only the two
- assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
- assertFalse(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
- try {
- assertFalse(ministore.getBATBlockAndIndex(256).getBlock().hasFreeSectors());
- fail("Should only be two SBATs");
- } catch(IndexOutOfBoundsException e) {}
-
- // Now ask for a free one, will need to extend the SBAT chain
- assertEquals(256, ministore.getFreeBlock());
-
- assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
- assertFalse(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
- assertTrue(ministore.getBATBlockAndIndex(256).getBlock().hasFreeSectors());
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(254)); // 2nd SBAT
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(255)); // 2nd SBAT
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(256)); // 3rd SBAT
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(257)); // 3rd SBAT
-
- fs.close();
- }
-
- /**
- * Test that we will extend the underlying chain of
- * big blocks that make up the ministream as needed
- */
- @Test
- public void testCreateBlockIfNeeded() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
- POIFSMiniStore ministore = fs.getMiniStore();
-
- // 178 -> 179 -> 180, 181+ is free
- assertEquals(179 , ministore.getNextBlock(178));
- assertEquals(180 , ministore.getNextBlock(179));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
- for(int i=181; i<256; i++) {
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
- }
-
- // However, the ministore data only covers blocks to 183
- for(int i=0; i<=183; i++) {
- ministore.getBlockAt(i);
- }
- try {
- ministore.getBlockAt(184);
- fail("No block at 184");
- } catch(NoSuchElementException e) {}
-
- // The ministore itself is made up of 23 big blocks
- Iterator<ByteBuffer> it = new POIFSStream(fs, fs.getRoot().getProperty().getStartBlock()).getBlockIterator();
- int count = 0;
- while(it.hasNext()) {
- count++;
- it.next();
- }
- assertEquals(23, count);
-
- // Ask it to get block 184 with creating, it will do
- ministore.createBlockIfNeeded(184);
-
- // The ministore should be one big block bigger now
- it = new POIFSStream(fs, fs.getRoot().getProperty().getStartBlock()).getBlockIterator();
- count = 0;
- while(it.hasNext()) {
- count++;
- it.next();
- }
- assertEquals(24, count);
-
- // The mini block block counts now run to 191
- for(int i=0; i<=191; i++) {
- ministore.getBlockAt(i);
- }
- try {
- ministore.getBlockAt(192);
- fail("No block at 192");
- } catch(NoSuchElementException e) {}
-
-
- // Now try writing through to 192, check that the SBAT and blocks are there
- byte[] data = new byte[15*64];
- POIFSStream stream = new POIFSStream(ministore, 178);
- stream.updateContents(data);
-
- // Check now
- assertEquals(179 , ministore.getNextBlock(178));
- assertEquals(180 , ministore.getNextBlock(179));
- assertEquals(181 , ministore.getNextBlock(180));
- assertEquals(182 , ministore.getNextBlock(181));
- assertEquals(183 , ministore.getNextBlock(182));
- assertEquals(184 , ministore.getNextBlock(183));
- assertEquals(185 , ministore.getNextBlock(184));
- assertEquals(186 , ministore.getNextBlock(185));
- assertEquals(187 , ministore.getNextBlock(186));
- assertEquals(188 , ministore.getNextBlock(187));
- assertEquals(189 , ministore.getNextBlock(188));
- assertEquals(190 , ministore.getNextBlock(189));
- assertEquals(191 , ministore.getNextBlock(190));
- assertEquals(192 , ministore.getNextBlock(191));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(192));
- for(int i=193; i<256; i++) {
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
- }
-
- fs.close();
- }
-
- @Test
- public void testCreateMiniStoreFirst() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem();
- POIFSMiniStore ministore = fs.getMiniStore();
- DocumentInputStream dis;
- DocumentEntry entry;
-
- // Initially has Properties + BAT but nothing else
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2));
- // Ministore has no blocks, so can't iterate until used
- try {
- ministore.getNextBlock(0);
- } catch (IndexOutOfBoundsException e) {}
-
- // Write a very small new document, will populate the ministore for us
- byte[] data = new byte[8];
- for (int i=0; i<data.length; i++) {
- data[i] = (byte)(i+42);
- }
- fs.getRoot().createDocument("mini", new ByteArrayInputStream(data));
-
- // Should now have a mini-fat and a mini-stream
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,fs.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
- assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(0));
- assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(1));
-
- // Re-fetch the mini store, and add it a second time
- ministore = fs.getMiniStore();
- fs.getRoot().createDocument("mini2", new ByteArrayInputStream(data));
-
- // Main unchanged, ministore has a second
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK,fs.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
- 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);
- assertArrayEquals(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);
- assertArrayEquals(data, rdata);
- dis.close();
-
- // Done
- fs.close();
- }
-
- @Test
- public void testMultiBlockStream() throws Exception {
- byte[] data1B = new byte[63];
- byte[] data2B = new byte[64+14];
- for (int i=0; i<data1B.length; i++) {
- data1B[i] = (byte)(i+2);
- }
- for (int i=0; i<data2B.length; i++) {
- data2B[i] = (byte)(i+4);
- }
-
- // New filesystem and store to use
- POIFSFileSystem fs = new POIFSFileSystem();
-
- // Initially has Properties + BAT but nothing else
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2));
-
- // Store the 2 block one, should use 2 mini blocks, and request
- // the use of 2 big blocks
- POIFSMiniStore ministore = fs.getMiniStore();
- fs.getRoot().createDocument("mini2", new ByteArrayInputStream(data2B));
-
- // Check
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); // SBAT
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); // Mini
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
-
- // First 2 Mini blocks will be used
- assertEquals(2, ministore.getFreeBlock());
-
- // Add one more mini-stream, and check
- fs.getRoot().createDocument("mini1", new ByteArrayInputStream(data1B));
-
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
- assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); // SBAT
- assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); // Mini
- assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
-
- // One more mini-block will be used
- assertEquals(3, ministore.getFreeBlock());
-
- // Check the contents too
- byte[] r1 = new byte[data1B.length];
- DocumentInputStream dis = fs.createDocumentInputStream("mini1");
- IOUtils.readFully(dis, r1);
- dis.close();
- assertArrayEquals(data1B, r1);
-
- byte[] r2 = new byte[data2B.length];
- dis = fs.createDocumentInputStream("mini2");
- IOUtils.readFully(dis, r2);
- dis.close();
- assertArrayEquals(data2B, r2);
- fs.close();
- }
+ }
+
+ // Check our SBAT free stuff is correct
+ assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+ assertTrue(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
+
+ // Allocate all the spare ones
+ for (int i = 181; i < 256; i++) {
+ ministore.setNextBlock(i, POIFSConstants.END_OF_CHAIN);
+ }
+
+ // SBAT are now full, but there's only the two
+ assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+ assertFalse(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
+ assertThrows(IndexOutOfBoundsException.class, () -> ministore.getBATBlockAndIndex(256), "Should only be two SBATs");
+
+ // Now ask for a free one, will need to extend the SBAT chain
+ assertEquals(256, ministore.getFreeBlock());
+
+ assertFalse(ministore.getBATBlockAndIndex(0).getBlock().hasFreeSectors());
+ assertFalse(ministore.getBATBlockAndIndex(128).getBlock().hasFreeSectors());
+ assertTrue(ministore.getBATBlockAndIndex(256).getBlock().hasFreeSectors());
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(254)); // 2nd SBAT
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(255)); // 2nd SBAT
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(256)); // 3rd SBAT
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(257)); // 3rd SBAT
+
+ fs.close();
+ }
+
+ /**
+ * Test that we will extend the underlying chain of
+ * big blocks that make up the ministream as needed
+ */
+ @Test
+ public void testCreateBlockIfNeeded() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(_inst.openResourceAsStream("BlockSize512.zvi"));
+ POIFSMiniStore ministore = fs.getMiniStore();
+
+ // 178 -> 179 -> 180, 181+ is free
+ assertEquals(179, ministore.getNextBlock(178));
+ assertEquals(180, ministore.getNextBlock(179));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(180));
+ for (int i = 181; i < 256; i++) {
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
+ }
+
+ // However, the ministore data only covers blocks to 183
+ for (int i = 0; i <= 183; i++) {
+ ministore.getBlockAt(i);
+ }
+ assertThrows(NoSuchElementException.class, () -> ministore.getBlockAt(184), "No block at 184");
+
+ // The ministore itself is made up of 23 big blocks
+ Iterator<ByteBuffer> it = new POIFSStream(fs, fs.getRoot().getProperty().getStartBlock()).getBlockIterator();
+ int count = 0;
+ while (it.hasNext()) {
+ count++;
+ it.next();
+ }
+ assertEquals(23, count);
+
+ // Ask it to get block 184 with creating, it will do
+ ministore.createBlockIfNeeded(184);
+
+ // The ministore should be one big block bigger now
+ it = new POIFSStream(fs, fs.getRoot().getProperty().getStartBlock()).getBlockIterator();
+ count = 0;
+ while (it.hasNext()) {
+ count++;
+ it.next();
+ }
+ assertEquals(24, count);
+
+ // The mini block block counts now run to 191
+ for (int i = 0; i <= 191; i++) {
+ ministore.getBlockAt(i);
+ }
+
+ assertThrows(NoSuchElementException.class, () -> ministore.getBlockAt(192), "No block at 192");
+
+ // Now try writing through to 192, check that the SBAT and blocks are there
+ byte[] data = new byte[15 * 64];
+ POIFSStream stream = new POIFSStream(ministore, 178);
+ stream.updateContents(data);
+
+ // Check now
+ assertEquals(179, ministore.getNextBlock(178));
+ assertEquals(180, ministore.getNextBlock(179));
+ assertEquals(181, ministore.getNextBlock(180));
+ assertEquals(182, ministore.getNextBlock(181));
+ assertEquals(183, ministore.getNextBlock(182));
+ assertEquals(184, ministore.getNextBlock(183));
+ assertEquals(185, ministore.getNextBlock(184));
+ assertEquals(186, ministore.getNextBlock(185));
+ assertEquals(187, ministore.getNextBlock(186));
+ assertEquals(188, ministore.getNextBlock(187));
+ assertEquals(189, ministore.getNextBlock(188));
+ assertEquals(190, ministore.getNextBlock(189));
+ assertEquals(191, ministore.getNextBlock(190));
+ assertEquals(192, ministore.getNextBlock(191));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(192));
+ for (int i = 193; i < 256; i++) {
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(i));
+ }
+
+ fs.close();
+ }
+
+ @Test
+ public void testCreateMiniStoreFirst() throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem();
+ POIFSMiniStore ministore = fs.getMiniStore();
+ DocumentInputStream dis;
+ DocumentEntry entry;
+
+ // Initially has Properties + BAT but nothing else
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2));
+ // Ministore has no blocks, so can't iterate until used
+ try {
+ ministore.getNextBlock(0);
+ } catch (IndexOutOfBoundsException e) {
+ }
+
+ // Write a very small new document, will populate the ministore for us
+ byte[] data = new byte[8];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) (i + 42);
+ }
+ fs.getRoot().createDocument("mini", new ByteArrayInputStream(data));
+
+ // Should now have a mini-fat and a mini-stream
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
+ assertEquals(POIFSConstants.END_OF_CHAIN, ministore.getNextBlock(0));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, ministore.getNextBlock(1));
+
+ // Re-fetch the mini store, and add it a second time
+ ministore = fs.getMiniStore();
+ fs.getRoot().createDocument("mini2", new ByteArrayInputStream(data));
+
+ // Main unchanged, ministore has a second
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
+ 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);
+ assertArrayEquals(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);
+ assertArrayEquals(data, rdata);
+ dis.close();
+
+ // Done
+ fs.close();
+ }
+
+ @Test
+ public void testMultiBlockStream() throws Exception {
+ byte[] data1B = new byte[63];
+ byte[] data2B = new byte[64 + 14];
+ for (int i = 0; i < data1B.length; i++) {
+ data1B[i] = (byte) (i + 2);
+ }
+ for (int i = 0; i < data2B.length; i++) {
+ data2B[i] = (byte) (i + 4);
+ }
+
+ // New filesystem and store to use
+ POIFSFileSystem fs = new POIFSFileSystem();
+
+ // Initially has Properties + BAT but nothing else
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(2));
+
+ // Store the 2 block one, should use 2 mini blocks, and request
+ // the use of 2 big blocks
+ POIFSMiniStore ministore = fs.getMiniStore();
+ fs.getRoot().createDocument("mini2", new ByteArrayInputStream(data2B));
+
+ // Check
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); // SBAT
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); // Mini
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
+
+ // First 2 Mini blocks will be used
+ assertEquals(2, ministore.getFreeBlock());
+
+ // Add one more mini-stream, and check
+ fs.getRoot().createDocument("mini1", new ByteArrayInputStream(data1B));
+
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(0));
+ assertEquals(POIFSConstants.FAT_SECTOR_BLOCK, fs.getNextBlock(1));
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(2)); // SBAT
+ assertEquals(POIFSConstants.END_OF_CHAIN, fs.getNextBlock(3)); // Mini
+ assertEquals(POIFSConstants.UNUSED_BLOCK, fs.getNextBlock(4));
+
+ // One more mini-block will be used
+ assertEquals(3, ministore.getFreeBlock());
+
+ // Check the contents too
+ byte[] r1 = new byte[data1B.length];
+ DocumentInputStream dis = fs.createDocumentInputStream("mini1");
+ IOUtils.readFully(dis, r1);
+ dis.close();
+ assertArrayEquals(data1B, r1);
+
+ byte[] r2 = new byte[data2B.length];
+ dis = fs.createDocumentInputStream("mini2");
+ IOUtils.readFully(dis, r2);
+ dis.close();
+ assertArrayEquals(data2B, r2);
+ fs.close();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org