diff options
author | PJ Fanning <fanningpj@apache.org> | 2022-02-03 18:42:39 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2022-02-03 18:42:39 +0000 |
commit | 1bdd44fc88f9c3833d69bfdcd455c1d48f5f4a3f (patch) | |
tree | ffec9dccb6ba1ba6fa862c5088dda25ccbae234b /poi-ooxml | |
parent | fa8f94370e9158728bc92ccf2f9bad7a070077bd (diff) | |
download | poi-1bdd44fc88f9c3833d69bfdcd455c1d48f5f4a3f.tar.gz poi-1bdd44fc88f9c3833d69bfdcd455c1d48f5f4a3f.zip |
add regression test for opczip
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1897737 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java new file mode 100644 index 0000000000..8c7ecec01c --- /dev/null +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java @@ -0,0 +1,51 @@ +package org.apache.poi.xssf.streaming; + +import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; +import org.junit.jupiter.api.Test; + +import java.io.PrintStream; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.zip.ZipEntry; + +import static org.junit.jupiter.api.Assertions.assertArrayEquals; + +class OpcZipTest { + @Test + void compareOutput() throws Exception { + Map<String, String> contents = createContents(); + try ( + UnsynchronizedByteArrayOutputStream bos1 = new UnsynchronizedByteArrayOutputStream(); + UnsynchronizedByteArrayOutputStream bos2 = new UnsynchronizedByteArrayOutputStream() + ) { + try (OpcOutputStream zip = new OpcOutputStream(bos1)) { + for (Map.Entry<String, String> entry : contents.entrySet()) { + zip.putNextEntry(entry.getKey()); + PrintStream printer = new PrintStream(zip); + printer.print(entry.getValue()); + printer.flush(); + zip.closeEntry(); + } + } + try (com.github.rzymek.opczip.OpcOutputStream zip = new com.github.rzymek.opczip.OpcOutputStream(bos2)) { + for (Map.Entry<String, String> entry : contents.entrySet()) { + zip.putNextEntry(new ZipEntry(entry.getKey())); + PrintStream printer = new PrintStream(zip); + printer.print(entry.getValue()); + printer.flush(); + zip.closeEntry(); + } + } + assertArrayEquals(bos1.toByteArray(), bos2.toByteArray()); + } + } + + private static Map<String, String> createContents() { + Map<String, String> contents = new LinkedHashMap<>(); + for (int i = 0; i < 3; i++) { + String name = String.format("dir%s/file%s.txt", i % 3, i); + contents.put(name, "this is the contents"); + } + return contents; + } +} |