aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi
diff options
context:
space:
mode:
Diffstat (limited to 'src/testcases/org/apache/poi')
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java116
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java20
-rw-r--r--src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java1
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestLeftRight.java4
-rw-r--r--src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java1
-rw-r--r--src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java3
6 files changed, 73 insertions, 72 deletions
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java b/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
index b44b5d5d53..73c0423859 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
@@ -18,61 +18,58 @@
package org.apache.poi.poifs.filesystem;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.stream.Stream;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
final class TestEmptyDocument {
private static final POILogger LOG = POILogFactory.getLogger(TestEmptyDocument.class);
- @Test
- void testSingleEmptyDocument() throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem();
- DirectoryEntry dir = fs.getRoot();
- dir.createDocument("Foo", new ByteArrayInputStream(new byte[] {}));
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- fs.writeFilesystem(out);
- new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())).close();
- fs.close();
+ private interface EmptyDoc {
+ void handle(DirectoryEntry dir) throws IOException;
}
- @Test
- void testSingleEmptyDocumentEvent() throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem();
- DirectoryEntry dir = fs.getRoot();
- dir.createDocument("Foo", 0, event -> LOG.log(POILogger.WARN, "written"));
+ public static Stream<Arguments> emptySupplier() {
+ return Stream.of(
+ Arguments.of("SingleEmptyDocument", (EmptyDoc)TestEmptyDocument::SingleEmptyDocument),
+ Arguments.of("SingleEmptyDocumentEvent", (EmptyDoc)TestEmptyDocument::SingleEmptyDocumentEvent),
+ Arguments.of("EmptyDocumentWithFriend", (EmptyDoc)TestEmptyDocument::EmptyDocumentWithFriend),
+ Arguments.of("EmptyDocumentEventWithFriend", (EmptyDoc)TestEmptyDocument::EmptyDocumentEventWithFriend)
+ );
+ }
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- fs.writeFilesystem(out);
- new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())).close();
- fs.close();
+ private static void SingleEmptyDocument(DirectoryEntry dir) throws IOException {
+ dir.createDocument("Foo", new ByteArrayInputStream(new byte[]{}));
}
- @Test
- void testEmptyDocumentWithFriend() throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem();
- DirectoryEntry dir = fs.getRoot();
- dir.createDocument("Bar", new ByteArrayInputStream(new byte[] { 0 }));
- dir.createDocument("Foo", new ByteArrayInputStream(new byte[] {}));
+ private static void SingleEmptyDocumentEvent(DirectoryEntry dir) throws IOException {
+ dir.createDocument("Foo", 0, event -> LOG.log(POILogger.WARN, "written"));
+ }
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- fs.writeFilesystem(out);
- new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())).close();
- fs.close();
+ private static void EmptyDocumentWithFriend(DirectoryEntry dir) throws IOException {
+ dir.createDocument("Bar", new ByteArrayInputStream(new byte[]{0}));
+ dir.createDocument("Foo", new ByteArrayInputStream(new byte[]{}));
}
- @Test
- void testEmptyDocumentEventWithFriend() throws IOException {
- POIFSFileSystem fs = new POIFSFileSystem();
- DirectoryEntry dir = fs.getRoot();
+ private static void EmptyDocumentEventWithFriend(DirectoryEntry dir) throws IOException {
dir.createDocument("Bar", 1, event -> {
try {
event.getStream().write(0);
@@ -81,38 +78,45 @@ final class TestEmptyDocument {
}
});
dir.createDocument("Foo", 0, event -> {});
+ }
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- fs.writeFilesystem(out);
- new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())).close();
- fs.close();
+
+ @ParameterizedTest(name = "{index} {0}")
+ @MethodSource("emptySupplier")
+ void testFoo(String testName, EmptyDoc emptyDoc) throws IOException {
+ try (POIFSFileSystem fs = new POIFSFileSystem()) {
+ DirectoryEntry dir = fs.getRoot();
+ emptyDoc.handle(dir);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fs.writeFilesystem(out);
+ assertDoesNotThrow(() -> new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())));
+ }
}
@Test
void testEmptyDocumentBug11744() throws Exception {
byte[] testData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- POIFSFileSystem fs = new POIFSFileSystem();
- fs.createDocument(new ByteArrayInputStream(new byte[0]), "Empty");
- fs.createDocument(new ByteArrayInputStream(testData), "NotEmpty");
ByteArrayOutputStream out = new ByteArrayOutputStream();
- fs.writeFilesystem(out);
- out.toByteArray();
- fs.close();
+ try (POIFSFileSystem fs = new POIFSFileSystem()) {
+ fs.createDocument(new ByteArrayInputStream(new byte[0]), "Empty");
+ fs.createDocument(new ByteArrayInputStream(testData), "NotEmpty");
+ fs.writeFilesystem(out);
+ }
// This line caused the error.
- fs = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
-
- DocumentEntry entry = (DocumentEntry) fs.getRoot().getEntry("Empty");
- assertEquals(0, entry.getSize(), "Expected zero size");
- byte[] actualReadbackData;
- actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
- assertEquals(0, actualReadbackData.length, "Expected zero read from stream");
-
- entry = (DocumentEntry) fs.getRoot().getEntry("NotEmpty");
- actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
- assertEquals(testData.length, entry.getSize(), "Expected size was wrong");
- assertArrayEquals(testData, actualReadbackData, "Expected same data read from stream");
- fs.close();
+ try (POIFSFileSystem fs = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()))) {
+ DocumentEntry entry = (DocumentEntry) fs.getRoot().getEntry("Empty");
+ assertEquals(0, entry.getSize(), "Expected zero size");
+ byte[] actualReadbackData;
+ actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
+ assertEquals(0, actualReadbackData.length, "Expected zero read from stream");
+
+ entry = (DocumentEntry) fs.getRoot().getEntry("NotEmpty");
+ actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
+ assertEquals(testData.length, entry.getSize(), "Expected size was wrong");
+ assertArrayEquals(testData, actualReadbackData, "Expected same data read from stream");
+ }
}
}
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
index 8682bad46b..c644fb1c60 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
@@ -42,6 +42,9 @@ import org.apache.poi.poifs.storage.BATBlock;
import org.apache.poi.poifs.storage.HeaderBlock;
import org.apache.poi.util.IOUtils;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.junit.jupiter.params.provider.ValueSource;
/**
* Tests for the older OPOIFS-based POIFSFileSystem
@@ -137,23 +140,18 @@ final class TestPOIFSFileSystem {
* The other is to fix the handling of the last block in
* POIFS, since it seems to be slight wrong
*/
- @Test
- void testShortLastBlock() throws Exception {
- String[] files = new String[] {
- "ShortLastBlock.qwp", "ShortLastBlock.wps"
- };
-
- for (String file : files) {
- // Open the file up
- POIFSFileSystem fs = new POIFSFileSystem(
- _samples.openResourceAsStream(file)
- );
+ @ParameterizedTest
+ @CsvSource({ "ShortLastBlock.qwp, 1303681", "ShortLastBlock.wps, 140787" })
+ void testShortLastBlock(String file, int size) throws Exception {
+ // Open the file up
+ try (POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream(file))) {
// Write it into a temp output array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
fs.writeFilesystem(baos);
// Check sizes
+ assertEquals(size, baos.size());
}
}
diff --git a/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java b/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java
index 4d0061673e..28849f77e9 100644
--- a/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java
+++ b/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java
@@ -51,7 +51,6 @@ class TestPresetGeometries {
}
@Disabled("problem solved? Turn back on if this debugging is still in process.")
- @Test
void testCheckXMLParser() throws Exception{
// Gump reports a strange error because of an unavailable XML Parser, let's try to find out where
// this comes from
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestLeftRight.java b/src/testcases/org/apache/poi/ss/formula/functions/TestLeftRight.java
index f6f0d1be19..4bf92c7196 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestLeftRight.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestLeftRight.java
@@ -50,8 +50,8 @@ class TestLeftRight {
@Test
void testLeftRight_bug49841() {
- invokeLeft(ANY_STRING_VALUE, NEGATIVE_OPERAND);
- invokeRight(ANY_STRING_VALUE, NEGATIVE_OPERAND);
+ assertEquals(ErrorEval.VALUE_INVALID, invokeLeft(ANY_STRING_VALUE, NEGATIVE_OPERAND));
+ assertEquals(ErrorEval.VALUE_INVALID, invokeRight(ANY_STRING_VALUE, NEGATIVE_OPERAND));
}
@Test
diff --git a/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java b/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java
index 70e83bd9af..9fb322f978 100644
--- a/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java
+++ b/src/testcases/org/apache/poi/ss/formula/functions/TestStatsLib.java
@@ -104,7 +104,6 @@ class TestStatsLib extends BaseTestNumeric {
assertDouble("kthLargest ", x, d);
}
- @Test
@Disabled("... implement ...")
void testKthSmallest() {
}
diff --git a/src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java b/src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java
index cc67d4304a..f4170286ca 100644
--- a/src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java
+++ b/src/testcases/org/apache/poi/ss/formula/ptg/TestReferencePtg.java
@@ -18,6 +18,7 @@
package org.apache.poi.ss.formula.ptg;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -71,7 +72,7 @@ final class TestReferencePtg {
@Test
void testBug44921() throws IOException {
try (HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex44921-21902.xls")) {
- HSSFTestDataSamples.writeOutAndReadBack(wb).close();
+ assertDoesNotThrow(() -> HSSFTestDataSamples.writeOutAndReadBack(wb));
}
}