Author: fanningpj
Date: Thu Feb 3 18:42:39 2022
New Revision: 1897737
URL: http://svn.apache.org/viewvc?rev=1897737&view=rev
Log:
add regression test for opczip
Added:
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java
(with props)
Added:
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java?rev=1897737&view=auto
==============================================================================
---
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java
(added)
+++
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java
Thu Feb 3 18:42:39 2022
@@ -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;
+ }
+}
Propchange:
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/OpcZipTest.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]