Skip to content

Commit

Permalink
More tests for reproducible outputs
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921981 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
centic9 committed Nov 20, 2024
1 parent c1f018f commit 7c881a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
==================================================================== */
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;
Expand All @@ -29,11 +30,13 @@ Licensed to the Apache Software Foundation (ASF) under one or more
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<
Expand Down Expand Up @@ -199,4 +202,29 @@ public static Color getColor(PaintStyle paintActual) {
: 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());
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,7 @@ protected void assertFormula(Workbook wb, Cell intF, String expectedFormula, Str
assertEquals(expectedResultOrNull, eval.evaluate(intF).formatAsString());
}

// ensure a simple workbook can be reproducibly written
@Test
void testWriteDocumentTwice() throws Exception {
try (Workbook wb = _testDataProvider.createWorkbook()) {
Expand Down

0 comments on commit 7c881a4

Please sign in to comment.