aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2024-11-20 20:29:45 +0000
committerDominik Stadler <centic@apache.org>2024-11-20 20:29:45 +0000
commit7c881a408f9ae99de59b8ee5f8a459e09304d066 (patch)
tree1a6cb615aa3415c9516d4911be4a5a3a80aaf608
parentc1f018f79c6193e4f989e51dfcb41f7653b8478f (diff)
downloadpoi-7c881a408f9ae99de59b8ee5f8a459e09304d066.tar.gz
poi-7c881a408f9ae99de59b8ee5f8a459e09304d066.zip
More tests for reproducible outputs
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921981 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShow.java28
-rw-r--r--poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java1
2 files changed, 29 insertions, 0 deletions
diff --git a/poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShow.java b/poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShow.java
index 0654012411..b4ac148215 100644
--- a/poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShow.java
+++ b/poi/src/test/java/org/apache/poi/sl/usermodel/BaseTestSlideShow.java
@@ -16,6 +16,7 @@
==================================================================== */
package org.apache.poi.sl.usermodel;
+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.assertNotNull;
@@ -29,11 +30,13 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.List;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.POIDataSamples;
import org.apache.poi.common.usermodel.fonts.FontInfo;
import org.apache.poi.sl.draw.DrawPaint;
import org.apache.poi.sl.usermodel.PictureData.PictureType;
import org.apache.poi.sl.usermodel.TabStop.TabStopType;
+import org.apache.poi.util.Reproducibility;
import org.junit.jupiter.api.Test;
public abstract class BaseTestSlideShow<
@@ -199,4 +202,29 @@ public abstract class BaseTestSlideShow<
: null;
}
+ // ensure a simple slide-show can be reproducibly written
+ @Test
+ void testWriteDocumentTwice() throws Exception {
+ try (SlideShow<S,P> ppt = createSlideShow()) {
+ ppt.createSlide();
+
+ Reproducibility.runWithSourceDateEpoch(
+ () -> {
+ try (UnsynchronizedByteArrayOutputStream out1 = UnsynchronizedByteArrayOutputStream.builder().get();
+ UnsynchronizedByteArrayOutputStream out2 = UnsynchronizedByteArrayOutputStream.builder().get()) {
+ ppt.write(out1);
+ ppt.write(out2);
+
+ out1.flush();
+ out2.flush();
+
+ // to avoid flaky tests if the documents are written at slightly different timestamps
+ // we clear some bytes which contain timestamps
+ assertArrayEquals(
+ out1.toByteArray(),
+ out2.toByteArray());
+ }
+ });
+ }
+ }
}
diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
index 3b5a1e24f0..9039293b5b 100644
--- a/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
+++ b/poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
@@ -1800,6 +1800,7 @@ public abstract class BaseTestBugzillaIssues {
assertEquals(expectedResultOrNull, eval.evaluate(intF).formatAsString());
}
+ // ensure a simple workbook can be reproducibly written
@Test
void testWriteDocumentTwice() throws Exception {
try (Workbook wb = _testDataProvider.createWorkbook()) {