<classpathentry kind="src" path="src/excelant/java"/>
<classpathentry kind="src" path="src/excelant/testcases"/>
<classpathentry kind="src" path="src/excelant/resources"/>
+ <classpathentry kind="src" path="src/integrationtest"/>
<classpathentry kind="lib" path="lib/ant-1.9.4.jar"/>
<classpathentry kind="lib" path="lib/ant-launcher-1.9.4.jar"/>
<classpathentry kind="lib" path="lib/commons-codec-1.9.jar"/>
<property name="ooxml.testokfile" location="build/ooxml-testokfile.txt"/>
<property name="ooxml.lite.output.dir" location="build/ooxml-lite-classes"/>
+ <!-- Integration testing -->
+ <property name="integration.src.test" location="src/integrationtest"/>
+ <property name="integration.reports.test" location="build/integration-test-results"/>
+ <property name="integration.output.test.dir" location="build/integration-test-classes"/>
+ <property name="integration.testokfile" location="build/integration-testokfile.txt"/>
+
<!-- Excelant: -->
<property name="excelant.resource.dir" value="src/excelant/resources"/>
<property name="excelant.src" location="src/excelant/java"/>
<pathelement location="${additionaljar}"/>
</path>
+ <path id="test.integration.classpath">
+ <path refid="scratchpad.classpath"/>
+ <path refid="ooxml.classpath"/>
+ <pathelement location="${main.output.test.dir}"/>
+ <pathelement location="${ooxml.output.dir}"/>
+ <pathelement location="${integration.output.test.dir}"/>
+ </path>
+
<path id="ooxml-lite.classpath">
<pathelement location="${ooxml.xmlbeans26.jar}"/>
<pathelement location="${ooxml.lite.output.dir}"/> <!-- instead of ooxml-xsds.jar use the filtered classes-->
<mkdir dir="${excelant.output.test.dir}"/>
<mkdir dir="${excelant.reports.test}"/>
<mkdir dir="${examples.output.dir}"/>
+ <mkdir dir="${integration.output.test.dir}"/>
+ <mkdir dir="${integration.reports.test}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="${build.site}"/>
</copy>
</target>
+ <target name="compile-integration" depends="compile-scratchpad, compile-main, compile-ooxml">
+ <javac target="${jdk.version.class}"
+ source="${jdk.version.source}"
+ destdir="${integration.output.test.dir}"
+ srcdir="${integration.src.test}"
+ debug="${compile.debug}"
+ encoding="${java.source.encoding}"
+ fork="yes"
+ includeantruntime="false">
+ <classpath>
+ <path refid="scratchpad.classpath"/>
+ <path refid="ooxml.classpath"/>
+ <pathelement location="${ooxml.output.dir}"/>
+ <pathelement location="${main.output.test.dir}"/>
+ <pathelement location="${main.ant.jar}"/>
+ </classpath>
+ </javac>
+ <!--copy todir="${integration.output.dir}">
+ <fileset dir="${integration.resource1.dir}"/>
+ </copy-->
+ </target>
+
<target name="compile-version" depends="init"
description="Compiles the version class">
<!-- Generate the .java file -->
<echo file="${ooxml.testokfile}" append="false" message="testok"/>
</target>
+ <target name="-test-integration-check">
+ <uptodate property="integration.test.notRequired" targetfile="${integration.testokfile}">
+ <srcfiles dir="${integration.src.test}"/>
+ </uptodate>
+ </target>
+
+ <target name="test-integration" depends="compile-integration,-test-integration-check,jacocotask"
+ unless="integration.test.notRequired" xmlns:jacoco="antlib:org.jacoco.ant">
+ <jacoco:coverage enabled="${coverage.enabled}" excludes="${coverage.excludes}" destfile="build/jacoco-integration.exec">
+ <junit printsummary="withOutAndErr" fork="yes" forkmode="once" haltonfailure="${halt.on.test.failure}"
+ failureproperty="integration.test.failed" showoutput="true">
+ <classpath refid="test.integration.classpath"/>
+ <syspropertyset refid="junit.properties"/>
+ <jvmarg value="${poi.test.locale}"/>
+ <jvmarg value="-ea"/>
+ <!--
+ YK: ensure that JUnit has enough memory to run tests.
+ Without the line below tests fail on Mac OS X with jdk-1.6.26
+ and on Windows with jdk-1.5.22
+ -->
+ <jvmarg value="-Xmx1512M"/>
+ <jvmarg value="-Dadditionaljar=${additionaljar}"/>
+ <formatter type="plain"/>
+ <formatter type="xml"/>
+ <batchtest todir="${integration.reports.test}">
+ <fileset dir="${integration.src.test}">
+ <include name="**/${testpattern}.java"/>
+ </fileset>
+ </batchtest>
+ </junit>
+ </jacoco:coverage>
+ <delete file="${integration.testokfile}"/>
+ <antcall target="-test-integration-write-testfile"/>
+ </target>
+
+ <target name="-test-integration-write-testfile" unless="integration.test.failed">
+ <echo file="${integration.testokfile}" append="false" message="testok"/>
+ </target>
+
<target name="compile-ooxml-lite" depends="compile-ooxml">
<property name="ooxml.lite-merged.dir" location="build/ooxml-lite-merged"/>
<mkdir dir="${ooxml.lite-merged.dir}"/>
</target>
<target name="gump" depends="compile-all, test-all, jar"/>
- <target name="jenkins" depends="compile-all, test-all, jar, javadocs, assemble, findbugs, release-notes, rat-check"/>
+ <target name="jenkins" depends="compile-all, test-all, test-integration, jar, javadocs, assemble, findbugs, release-notes, rat-check"/>
<available property="maven.ant.tasks.present" classname="org.apache.maven.artifact.ant.Pom"/>
<target name="maven.ant.tasks-check">
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.poi.stress.*;
+import org.apache.tools.ant.DirectoryScanner;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * This is an integration test which performs various actions on all stored test-files and tries
+ * to reveal problems which are introduced, but not covered (yet) by unit tests.
+ *
+ * This test looks for any file under the test-data directory and tries to do some useful
+ * processing with it based on it's type.
+ *
+ * The test is implemented as a junit {@link Parameterized} test, which leads
+ * to one test-method call for each file (currently around 950 files are handled).
+ *
+ * There is a a mapping of extension to implementations of the interface
+ * {@link FileHandler} which defines how the file is loaded and which actions are
+ * tried with the file.
+ *
+ * The test can be expanded by adding more actions to the FileHandlers, this automatically
+ * applies the action to any such file in our test-data repository.
+ *
+ * There is also a list of files that should actually fail.
+ *
+ * Note: It is also a test-failure if a file that is expected to fail now actually works,
+ * i.e. if a bug was fixed in POI itself, the file should be removed from the expected-failures
+ * here as well! This is to ensure that files that should not work really do not work, e.g.
+ * that we do not remove expected sanity checks.
+ */
+@RunWith(Parameterized.class)
+public class TestAllFiles {
+ // map file extensions to the actual mappers
+ private static final Map<String, FileHandler> HANDLERS = new HashMap<String, FileHandler>();
+ static {
+ // Excel
+ HANDLERS.put(".xls", new HSSFFileHandler());
+ HANDLERS.put(".xlsx", new XSSFFileHandler());
+ HANDLERS.put(".xlsm", new XSSFFileHandler());
+ HANDLERS.put(".xltx", new XSSFFileHandler());
+ HANDLERS.put(".xlsb", new XSSFFileHandler());
+
+ // Word
+ HANDLERS.put(".doc", new HWPFFileHandler());
+ HANDLERS.put(".docx", new XWPFFileHandler());
+ HANDLERS.put(".dotx", new XWPFFileHandler());
+ HANDLERS.put(".docm", new XWPFFileHandler());
+ HANDLERS.put(".ooxml", new XWPFFileHandler()); // OPCPackage
+
+ // Powerpoint
+ HANDLERS.put(".ppt", new HSLFFileHandler());
+ HANDLERS.put(".pptx", new XSLFFileHandler());
+ HANDLERS.put(".pptm", new XSLFFileHandler());
+ HANDLERS.put(".ppsm", new XSLFFileHandler());
+ HANDLERS.put(".ppsx", new XSLFFileHandler());
+ HANDLERS.put(".thmx", new XSLFFileHandler());
+
+ // Outlook
+ HANDLERS.put(".msg", new HSMFFileHandler());
+
+ // Publisher
+ HANDLERS.put(".pub", new HPBFFileHandler());
+
+ // Visio
+ HANDLERS.put(".vsd", new HDGFFileHandler());
+
+ // POIFS
+ HANDLERS.put(".ole2", new POIFSFileHandler());
+
+ // Microsoft Admin Template?
+ HANDLERS.put(".adm", new HPSFFileHandler());
+
+ // Microsoft TNEF
+ HANDLERS.put(".dat", new HMEFFileHandler());
+
+ // TODO: are these readable by some of the formats?
+ HANDLERS.put(".shw", new NullFileHandler());
+ HANDLERS.put(".zvi", new NullFileHandler());
+ HANDLERS.put(".mpp", new NullFileHandler());
+ HANDLERS.put(".qwp", new NullFileHandler());
+ HANDLERS.put(".wps", new NullFileHandler());
+ HANDLERS.put(".bin", new NullFileHandler());
+ HANDLERS.put(".xps", new NullFileHandler());
+ HANDLERS.put(".sldprt", new NullFileHandler());
+ HANDLERS.put(".mdb", new NullFileHandler());
+ HANDLERS.put(".vml", new NullFileHandler());
+
+ // ignore some file types, images, other formats, ...
+ HANDLERS.put(".txt", new NullFileHandler());
+ HANDLERS.put(".pdf", new NullFileHandler());
+ HANDLERS.put(".rtf", new NullFileHandler());
+ HANDLERS.put(".gif", new NullFileHandler());
+ HANDLERS.put(".html", new NullFileHandler());
+ HANDLERS.put(".png", new NullFileHandler());
+ HANDLERS.put(".wmf", new NullFileHandler());
+ HANDLERS.put(".emf", new NullFileHandler());
+ HANDLERS.put(".dib", new NullFileHandler());
+ HANDLERS.put(".svg", new NullFileHandler());
+ HANDLERS.put(".pict", new NullFileHandler());
+ HANDLERS.put(".jpg", new NullFileHandler());
+ HANDLERS.put(".wav", new NullFileHandler());
+ HANDLERS.put(".pfx", new NullFileHandler());
+ HANDLERS.put(".xml", new NullFileHandler());
+
+ // map some files without extension
+ HANDLERS.put("spreadsheet/BigSSTRecord", new NullFileHandler());
+ HANDLERS.put("spreadsheet/BigSSTRecord2", new NullFileHandler());
+ HANDLERS.put("spreadsheet/BigSSTRecord2CR1", new NullFileHandler());
+ HANDLERS.put("spreadsheet/BigSSTRecord2CR2", new NullFileHandler());
+ HANDLERS.put("spreadsheet/BigSSTRecord2CR3", new NullFileHandler());
+ HANDLERS.put("spreadsheet/BigSSTRecord2CR4", new NullFileHandler());
+ HANDLERS.put("spreadsheet/BigSSTRecord2CR5", new NullFileHandler());
+ HANDLERS.put("spreadsheet/BigSSTRecord2CR6", new NullFileHandler());
+ HANDLERS.put("spreadsheet/BigSSTRecord2CR7", new NullFileHandler());
+ HANDLERS.put("spreadsheet/BigSSTRecordCR", new NullFileHandler());
+ HANDLERS.put("spreadsheet/test_properties1", new NullFileHandler());
+ }
+
+ private static final Set<String> EXPECTED_FAILURES = new HashSet<String>();
+ static {
+ // password protected files
+ EXPECTED_FAILURES.add("poifs/protect.xlsx");
+ EXPECTED_FAILURES.add("spreadsheet/password.xls");
+ EXPECTED_FAILURES.add("spreadsheet/51832.xls");
+ EXPECTED_FAILURES.add("document/PasswordProtected.doc");
+ EXPECTED_FAILURES.add("slideshow/Password_Protected-hello.ppt");
+ EXPECTED_FAILURES.add("slideshow/Password_Protected-56-hello.ppt");
+ EXPECTED_FAILURES.add("slideshow/Password_Protected-np-hello.ppt");
+ EXPECTED_FAILURES.add("slideshow/cryptoapi-proc2356.ppt");
+ EXPECTED_FAILURES.add("document/bug53475-password-is-pass.docx");
+ EXPECTED_FAILURES.add("document/bug53475-password-is-solrcell.docx");
+ EXPECTED_FAILURES.add("spreadsheet/xor-encryption-abc.xls");
+ EXPECTED_FAILURES.add("spreadsheet/35897-type4.xls");
+
+ // TODO: fails XMLExportTest, is this ok?
+ EXPECTED_FAILURES.add("spreadsheet/CustomXMLMapping-singleattributenamespace.xlsx");
+ EXPECTED_FAILURES.add("spreadsheet/55864.xlsx");
+
+ // TODO: these fail now with some NPE/file read error because we now try to compute every value via Cell.toString()!
+ EXPECTED_FAILURES.add("spreadsheet/44958.xls");
+ EXPECTED_FAILURES.add("spreadsheet/44958_1.xls");
+ EXPECTED_FAILURES.add("spreadsheet/testArraysAndTables.xls");
+
+ // TODO: good to ignore?
+ EXPECTED_FAILURES.add("spreadsheet/sample-beta.xlsx");
+ EXPECTED_FAILURES.add("spreadsheet/49931.xls");
+ EXPECTED_FAILURES.add("poifs/protected_sha512.xlsx");
+ EXPECTED_FAILURES.add("poifs/extenxls_pwd123.xlsx");
+ EXPECTED_FAILURES.add("openxml4j/ContentTypeHasParameters.ooxml");
+
+ // This is actually a spreadsheet!
+ EXPECTED_FAILURES.add("hpsf/TestRobert_Flaherty.doc");
+
+ // some files that are broken, Excel 5.0/95, Word 95, ...
+ EXPECTED_FAILURES.add("poifs/protected_agile.docx");
+ EXPECTED_FAILURES.add("spreadsheet/43493.xls");
+ EXPECTED_FAILURES.add("spreadsheet/46904.xls");
+ EXPECTED_FAILURES.add("document/56880.doc");
+ EXPECTED_FAILURES.add("document/Bug49933.doc");
+ EXPECTED_FAILURES.add("document/Bug50955.doc");
+ EXPECTED_FAILURES.add("document/Bug51944.doc");
+ EXPECTED_FAILURES.add("document/Word6.doc");
+ EXPECTED_FAILURES.add("document/Word6_sections.doc");
+ EXPECTED_FAILURES.add("document/Word6_sections2.doc");
+ EXPECTED_FAILURES.add("document/Word95.doc");
+ EXPECTED_FAILURES.add("document/word95err.doc");
+ EXPECTED_FAILURES.add("hpsf/TestMickey.doc");
+ EXPECTED_FAILURES.add("slideshow/PPT95.ppt");
+ EXPECTED_FAILURES.add("openxml4j/OPCCompliance_CoreProperties_DCTermsNamespaceLimitedUseFAIL.docx");
+ EXPECTED_FAILURES.add("openxml4j/OPCCompliance_CoreProperties_DoNotUseCompatibilityMarkupFAIL.docx");
+ EXPECTED_FAILURES.add("openxml4j/OPCCompliance_CoreProperties_LimitedXSITypeAttribute_NotPresentFAIL.docx");
+ EXPECTED_FAILURES.add("openxml4j/OPCCompliance_CoreProperties_LimitedXSITypeAttribute_PresentWithUnauthorizedValueFAIL.docx");
+ EXPECTED_FAILURES.add("openxml4j/OPCCompliance_CoreProperties_OnlyOneCorePropertiesPartFAIL.docx");
+ EXPECTED_FAILURES.add("openxml4j/OPCCompliance_CoreProperties_UnauthorizedXMLLangAttributeFAIL.docx");
+ EXPECTED_FAILURES.add("openxml4j/OPCCompliance_DerivedPartNameFAIL.docx");
+ EXPECTED_FAILURES.add("spreadsheet/54764-2.xlsx"); // see TestXSSFBugs.bug54764()
+ EXPECTED_FAILURES.add("spreadsheet/54764.xlsx"); // see TestXSSFBugs.bug54764()
+ EXPECTED_FAILURES.add("spreadsheet/Simple.xlsb");
+ EXPECTED_FAILURES.add("spreadsheet/testEXCEL_4.xls");
+ EXPECTED_FAILURES.add("spreadsheet/testEXCEL_5.xls");
+ EXPECTED_FAILURES.add("spreadsheet/testEXCEL_95.xls");
+
+ // non-TNEF files
+ EXPECTED_FAILURES.add("ddf/Container.dat");
+ EXPECTED_FAILURES.add("ddf/47143.dat");
+ }
+
+ @Parameters(name="{index}: {0} using {1}")
+ public static Iterable<Object[]> files() {
+ DirectoryScanner scanner = new DirectoryScanner();
+ scanner.setBasedir(new File("test-data"));
+
+ scanner.scan();
+
+ System.out.println("Handling " + scanner.getIncludedFiles().length + " files");
+
+ List<Object[]> files = new ArrayList<Object[]>();
+ for(String file : scanner.getIncludedFiles()) {
+ files.add(new Object[] { file, HANDLERS.get(getExtension(file)) });
+ }
+
+ return files;
+ }
+
+ @Parameter(value=0)
+ public String file;
+
+ @Parameter(value=1)
+ public FileHandler handler;
+
+ @Test
+ public void testAllFiles() throws Exception {
+ assertNotNull("Unknown file extension for file: " + file + ": " + getExtension(file), handler);
+ InputStream stream = new FileInputStream(new File("test-data", file));
+ try {
+ handler.handleFile(stream);
+
+ assertFalse("Expected to fail for file " + file + " and handler " + handler + ", but did not fail!",
+ EXPECTED_FAILURES.contains(file));
+ } catch (Exception e) {
+ // check if we expect failure for this file
+ if(!EXPECTED_FAILURES.contains(file)) {
+ throw new Exception("While handling " + file, e);
+ }
+ } finally {
+ stream.close();
+ }
+ }
+
+ private static String getExtension(String file) {
+ int pos = file.lastIndexOf('.');
+ if(pos == -1 || pos == file.length()-1) {
+ return file;
+ }
+
+ return file.substring(pos);
+ }
+
+ private static class NullFileHandler implements FileHandler {
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ }
+ }
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.hssf.usermodel;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.poi.hssf.record.Record;
+import org.junit.Test;
+
+/**
+ * Needs to be implemented in this package to have access to
+ * HSSFWorkbook.getWorkbook()
+ */
+public class RecordsStresser {
+ public static void handleWorkbook(HSSFWorkbook wb) {
+ List<Record> records = wb.getWorkbook().getRecords();
+ for(Record record : records) {
+ // some Records do not implement clone ?!
+ // equals instead of instanceof is on purpose here to only skip exactly this class and not any derived ones
+// if(record.getClass().equals(InterfaceHdrRecord.class) ||
+// record.getClass().equals(MMSRecord.class) ||
+// record.getClass().equals(InterfaceEndRecord.class) ||
+// record.getClass().equals(WriteAccessRecord.class) ||
+// record.getClass().equals(CodepageRecord.class) ||
+// record.getClass().equals(DSFRecord.class)) {
+// continue;
+// }
+ try {
+ Record newRecord = (Record) record.clone();
+
+ assertEquals("Expecting the same class back from clone(), but had Record of type " + record.getClass() + " and got back a " + newRecord.getClass() + " from clone()",
+ record.getClass(), newRecord.getClass());
+
+ byte[] origBytes = record.serialize();
+ byte[] newBytes = newRecord.serialize();
+
+ assertArrayEquals("Record of type " + record.getClass() + " should return the same byte array via the clone() method, but did return a different array",
+ origBytes, newBytes);
+ } catch (RuntimeException e) {
+ // some Records do not implement clone, ignore those for now
+ assertTrue(e.getMessage().contains("needs to define a clone method"));
+ }
+ }
+ }
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void test() throws Exception {
+ InputStream stream = new FileInputStream("test-data/spreadsheet/15556.xls");
+ try {
+ HSSFWorkbook wb = new HSSFWorkbook(stream);
+ handleWorkbook(wb);
+ } finally {
+ stream.close();
+ }
+ }
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import java.io.InputStream;
+
+/**
+ * Base interface for the various file types that are
+ * used in the stress testing.
+ */
+public interface FileHandler {
+ /**
+ * The FileHandler receives a stream ready for reading the
+ * file and should handle the content that is provided and
+ * try to read and interpret the data.
+ *
+ * Closing is handled by the framework outside this call.
+ *
+ * @param stream
+ * @throws Exception
+ */
+ void handleFile(InputStream stream) throws Exception;
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.poi.hdgf.HDGFDiagram;
+import org.apache.poi.hdgf.streams.Stream;
+import org.apache.poi.hdgf.streams.TrailerStream;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.junit.Test;
+
+public class HDGFFileHandler extends POIFSFileHandler {
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ HDGFDiagram diagram = new HDGFDiagram(new POIFSFileSystem(stream));
+ Stream[] topLevelStreams = diagram.getTopLevelStreams();
+ assertNotNull(topLevelStreams);
+ for(Stream str : topLevelStreams) {
+ assertTrue(str.getPointer().getLength() >= 0);
+ }
+
+ TrailerStream trailerStream = diagram.getTrailerStream();
+ assertNotNull(trailerStream);
+ assertTrue(trailerStream.getPointer().getLength() >= 0);
+
+ // writing is not yet implemented... handlePOIDocument(diagram);
+ }
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void test() throws Exception {
+ InputStream stream = new FileInputStream("test-data/diagram/44501.vsd");
+ try {
+ handleFile(stream);
+ } finally {
+ stream.close();
+ }
+ }
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.poi.hmef.HMEFMessage;
+import org.apache.poi.hmef.attribute.MAPIAttribute;
+import org.apache.poi.hmef.attribute.MAPIStringAttribute;
+import org.junit.Test;
+
+public class HMEFFileHandler implements FileHandler {
+
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ HMEFMessage msg = new HMEFMessage(stream);
+
+ // list all properties
+ StringBuilder props = new StringBuilder();
+ for(MAPIAttribute att : msg.getMessageMAPIAttributes()) {
+ props.append(att.getType()).append(": ").append(MAPIStringAttribute.getAsString( att)).append("\n");
+ }
+
+ // there are two test-files that have no body...
+ if(!msg.getSubject().equals("Testing TNEF Message") && !msg.getSubject().equals("TNEF test message with attachments")) {
+ assertNotNull("Had: " + msg.getBody() + ", " + msg.getSubject() + ", " + msg.getAttachments() + ": " + props.toString(),
+ msg.getBody());
+ }
+ assertNotNull("Had: " + msg.getBody() + ", " + msg.getSubject() + ", " + msg.getAttachments() + ": " + props.toString(),
+ msg.getSubject());
+ }
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void test() throws Exception {
+ InputStream stream = new FileInputStream("test-data/hmef/quick-winmail.dat");
+ try {
+ handleFile(stream);
+ } finally {
+ stream.close();
+ }
+ }
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.poi.hpbf.HPBFDocument;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.junit.Test;
+
+public class HPBFFileHandler extends POIFSFileHandler {
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ HPBFDocument pub = new HPBFDocument(new POIFSFileSystem(stream));
+ assertNotNull(pub.getEscherDelayStm());
+ assertNotNull(pub.getMainContents());
+ assertNotNull(pub.getQuillContents());
+
+ // writing is not yet implemented... handlePOIDocument(pub);
+ }
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void test() throws Exception {
+ InputStream stream = new FileInputStream("test-data/publisher/SampleBrochure.pub");
+ try {
+ handleFile(stream);
+ } finally {
+ stream.close();
+ }
+ }
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.poi.hpsf.HPSFPropertiesOnlyDocument;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.junit.Test;
+
+public class HPSFFileHandler implements FileHandler {
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ HPSFPropertiesOnlyDocument hpsf = new HPSFPropertiesOnlyDocument(new POIFSFileSystem(stream));
+ assertNotNull(hpsf.getDocumentSummaryInformation());
+ assertNotNull(hpsf.getSummaryInformation());
+ }
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void test() throws Exception {
+ InputStream stream = new FileInputStream("test-data/hpsf/Test0313rur.adm");
+ try {
+ handleFile(stream);
+ } finally {
+ stream.close();
+ }
+ }
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.poi.hslf.HSLFSlideShow;
+import org.apache.poi.hslf.record.Record;
+import org.junit.Test;
+
+public class HSLFFileHandler extends POIFSFileHandler {
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ HSLFSlideShow slide = new HSLFSlideShow(stream);
+ assertNotNull(slide.getCurrentUserAtom());
+ assertNotNull(slide.getEmbeddedObjects());
+ assertNotNull(slide.getUnderlyingBytes());
+ assertNotNull(slide.getPictures());
+ Record[] records = slide.getRecords();
+ assertNotNull(records);
+ for(Record record : records) {
+ assertTrue(record.getRecordType() >= 0);
+ }
+
+ handlePOIDocument(slide);
+ }
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void test() throws Exception {
+ InputStream stream = new FileInputStream("test-data/hpsf/Test_Humor-Generation.ppt");
+ try {
+ handleFile(stream);
+ } finally {
+ stream.close();
+ }
+ }
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.poi.hsmf.MAPIMessage;
+import org.junit.Test;
+
+public class HSMFFileHandler extends POIFSFileHandler {
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ MAPIMessage mapi = new MAPIMessage(stream);
+ assertNotNull(mapi.getAttachmentFiles());
+ assertNotNull(mapi.getDisplayBCC());
+ assertNotNull(mapi.getMessageDate());
+
+ /* => Writing isn't yet supported...
+ // write out the file
+ File file = TempFile.createTempFile("StressTest", ".msg");
+ writeToFile(mapi, file);
+
+ MAPIMessage read = new MAPIMessage(file.getAbsolutePath());
+ assertNotNull(read.getAttachmentFiles());
+ assertNotNull(read.getDisplayBCC());
+ assertNotNull(read.getMessageDate());
+ */
+
+ // writing is not yet supported... handlePOIDocument(mapi);
+ }
+
+// private void writeToFile(MAPIMessage mapi, File file)
+// throws FileNotFoundException, IOException {
+// OutputStream stream = new FileOutputStream(file);
+// try {
+// mapi.write(stream);
+// } finally {
+// stream.close();
+// }
+// }
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void test() throws Exception {
+ InputStream stream = new FileInputStream("test-data/hsmf/example_received_regular.msg");
+ try {
+ handleFile(stream);
+ } finally {
+ stream.close();
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.junit.Test;
+
+public class HSSFFileHandler extends SpreadsheetHandler {
+ private POIFSFileHandler delegate = new POIFSFileHandler();
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ HSSFWorkbook wb = new HSSFWorkbook(stream);
+ handleWorkbook(wb, ".xls");
+
+ // TODO: some documents fail currently...
+ //HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);
+ //evaluator.evaluateAll();
+
+ delegate.handlePOIDocument(wb);
+
+ // also try to see if some of the Records behave incorrectly
+ // TODO: still fails on some records... RecordsStresser.handleWorkbook(wb);
+ }
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void test() throws Exception {
+ InputStream stream = new FileInputStream("test-data/spreadsheet/49219.xls");
+ try {
+ handleFile(stream);
+ } finally {
+ stream.close();
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.poi.hwpf.HWPFDocument;
+import org.junit.Test;
+
+public class HWPFFileHandler extends POIFSFileHandler {
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ HWPFDocument doc = new HWPFDocument(stream);
+ assertNotNull(doc.getBookmarks());
+ assertNotNull(doc.getCharacterTable());
+ assertNotNull(doc.getEndnotes());
+
+ handlePOIDocument(doc);
+ }
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void test() throws Exception {
+ InputStream stream = new FileInputStream("test-data/document/HeaderFooterUnicode.doc");
+ try {
+ handleFile(stream);
+ } finally {
+ stream.close();
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import org.apache.poi.POIDocument;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+
+public class POIFSFileHandler implements FileHandler {
+
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ POIFSFileSystem fs = new POIFSFileSystem(stream);
+ handlePOIFSFileSystem(fs);
+ }
+
+ private void handlePOIFSFileSystem(POIFSFileSystem fs) {
+ assertNotNull(fs);
+ assertNotNull(fs.getRoot());
+ }
+
+ protected void handlePOIDocument(POIDocument doc) throws Exception {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ doc.write(out);
+
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ POIFSFileSystem fs = new POIFSFileSystem(in);
+ handlePOIFSFileSystem(fs);
+ }
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.poi.POIXMLDocument;
+
+public final class POIXMLDocumentHandler {
+ protected void handlePOIXMLDocument(POIXMLDocument doc) throws Exception {
+ assertNotNull(doc.getAllEmbedds());
+ assertNotNull(doc.getPackage());
+ assertNotNull(doc.getPackagePart());
+ assertNotNull(doc.getProperties());
+ assertNotNull(doc.getRelations());
+ }
+}
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
+
+public abstract class SpreadsheetHandler implements FileHandler {
+ public void handleWorkbook(Workbook wb, String extension) throws IOException {
+ // try to access some of the content
+ readContent(wb);
+
+ // write out the file
+ ByteArrayOutputStream out = writeToArray(wb);
+
+ // access some more content (we had cases where writing corrupts the data in memory)
+ readContent(wb);
+
+ // write once more
+ out = writeToArray(wb);
+
+ // read in the writen file
+ Workbook read;
+ try {
+ read = WorkbookFactory.create(new ByteArrayInputStream(out.toByteArray()));
+ } catch (InvalidFormatException e) {
+ throw new IllegalStateException(e);
+ }
+ assertNotNull(read);
+
+ readContent(read);
+ }
+
+ private ByteArrayOutputStream writeToArray(Workbook wb)
+ throws FileNotFoundException, IOException {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ try {
+ wb.write(stream);
+ } finally {
+ stream.close();
+ }
+
+ return stream;
+ }
+
+ private void readContent(Workbook wb) {
+ for(int i = 0;i < wb.getNumberOfSheets();i++) {
+ Sheet sheet = wb.getSheetAt(i);
+ assertNotNull(wb.getSheet(sheet.getSheetName()));
+ sheet.groupColumn((short) 4, (short) 5);
+ sheet.setColumnGroupCollapsed(4, true);
+ sheet.setColumnGroupCollapsed(4, false);
+
+ for(Row row : sheet) {
+ for(Cell cell : row) {
+ cell.toString();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.xslf.XSLFSlideShow;
+import org.junit.Test;
+
+public class XSLFFileHandler implements FileHandler {
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ XSLFSlideShow slide = new XSLFSlideShow(OPCPackage.open(stream));
+ assertNotNull(slide.getPresentation());
+ assertNotNull(slide.getSlideMasterReferences());
+ assertNotNull(slide.getSlideReferences());
+
+ new POIXMLDocumentHandler().handlePOIXMLDocument(slide);
+ }
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void test() throws Exception {
+ InputStream stream = new FileInputStream("test-data/slideshow/testPPT.pptx");
+ try {
+ handleFile(stream);
+ } finally {
+ stream.close();
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import org.apache.poi.xssf.extractor.XSSFExportToXml;
+import org.apache.poi.xssf.usermodel.XSSFMap;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+public class XSSFFileHandler extends SpreadsheetHandler {
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ XSSFWorkbook wb = new XSSFWorkbook(stream);
+
+ // use the combined handler for HSSF/XSSF
+ handleWorkbook(wb, ".xlsx");
+
+ // TODO: some documents fail currently...
+ //XSSFFormulaEvaluator evaluator = new XSSFFormulaEvaluator(wb);
+ //evaluator.evaluateAll();
+
+ // also verify general POIFS-stuff
+ new POIXMLDocumentHandler().handlePOIXMLDocument(wb);
+
+ // and finally ensure that exporting to XML works
+ exportToXML(wb);
+ }
+
+ private void exportToXML(XSSFWorkbook wb) throws SAXException,
+ ParserConfigurationException, TransformerException {
+ for (XSSFMap map : wb.getCustomXMLMappings()) {
+ XSSFExportToXml exporter = new XSSFExportToXml(map);
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ exporter.exportToXML(os, true);
+ }
+ }
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void test() throws Exception {
+ InputStream stream = new FileInputStream("test-data/spreadsheet/WithConditionalFormatting.xlsx");
+ try {
+ handleFile(stream);
+ } finally {
+ stream.close();
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+package org.apache.poi.stress;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.junit.Test;
+
+public class XWPFFileHandler implements FileHandler {
+ @Override
+ public void handleFile(InputStream stream) throws Exception {
+ XWPFDocument doc = new XWPFDocument(stream);
+
+ new POIXMLDocumentHandler().handlePOIXMLDocument(doc);
+ }
+
+ // a test-case to test this locally without executing the full TestAllFiles
+ @Test
+ public void test() throws Exception {
+ InputStream stream = new FileInputStream("test-data/document/footnotes.docx");
+ try {
+ handleFile(stream);
+ } finally {
+ stream.close();
+ }
+ }
+
+}
\ No newline at end of file
assertTrue(found);
}
+ public void testExportToXMLSingleAttributeNamespace() throws Exception {
+ // TODO: Fails, but I don't know if it is ok or not...
+
+// XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("CustomXMLMapping-singleattributenamespace.xlsx");
+//
+// for (XSSFMap map : wb.getCustomXMLMappings()) {
+// XSSFExportToXml exporter = new XSSFExportToXml(map);
+//
+// ByteArrayOutputStream os = new ByteArrayOutputStream();
+// exporter.exportToXML(os, true);
+// }
+ }
+
public void test55850ComplexXmlExport() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples
SILENT_EXCLUDED.add("51832.xls"); // password
SILENT_EXCLUDED.add("xor-encryption-abc.xls"); // password, ty again later!
SILENT_EXCLUDED.add("43493.xls"); // HSSFWorkbook cannot open it as well
+ SILENT_EXCLUDED.add("44958_1.xls"); // known bad file
SILENT_EXCLUDED.add("46904.xls"); // Exception, too old
SILENT_EXCLUDED.add("47251_1.xls"); // Broken test file
+ SILENT_EXCLUDED.add("testEXCEL_4.xls"); // old unsupported format
+ SILENT_EXCLUDED.add("testEXCEL_5.xls"); // old unsupported format
+ SILENT_EXCLUDED.add("testEXCEL_95.xls"); // old unsupported format
+ SILENT_EXCLUDED.add("35897-type4.xls"); // unsupported encryption
}
@Override
SILENT_EXCLUDED.add("43493.xls"); // HSSFWorkbook cannot open it as well
SILENT_EXCLUDED.add("46904.xls");
SILENT_EXCLUDED.add("51832.xls"); // password
+ SILENT_EXCLUDED.add("44958_1.xls"); // known bad file
}
@Override
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.RecordFormatException;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
/**
* @author aviks
// Problem 3 - fixed and transfered
}
+
+ public void testFormulaRecordAggregate_1() throws Exception {
+ // fails at formula "=MEHRFACH.OPERATIONEN(E$3;$B$5;$D4)"
+ Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958_1.xls");
+ for(int i = 0;i < wb.getNumberOfSheets();i++) {
+ Sheet sheet = wb.getSheetAt(i);
+ assertNotNull(wb.getSheet(sheet.getSheetName()));
+ sheet.groupColumn((short) 4, (short) 5);
+ sheet.setColumnGroupCollapsed(4, true);
+ sheet.setColumnGroupCollapsed(4, false);
+
+ for(Row row : sheet) {
+ for(Cell cell : row) {
+ try {
+ cell.toString();
+ } catch (Exception e) {
+ throw new Exception("While handling: " + sheet.getSheetName() + "/" + row.getRowNum() + "/" + cell.getColumnIndex(), e);
+ }
+ }
+ }
+ }
+ }
+
+ public void testFormulaRecordAggregate() throws Exception {
+ // fails at formula "=MEHRFACH.OPERATIONEN(E$3;$B$5;$D4)"
+ Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958.xls");
+ for(int i = 0;i < wb.getNumberOfSheets();i++) {
+ Sheet sheet = wb.getSheetAt(i);
+ assertNotNull(wb.getSheet(sheet.getSheetName()));
+ sheet.groupColumn((short) 4, (short) 5);
+ sheet.setColumnGroupCollapsed(4, true);
+ sheet.setColumnGroupCollapsed(4, false);
+
+ for(Row row : sheet) {
+ for(Cell cell : row) {
+ try {
+ cell.toString();
+ } catch (Exception e) {
+ throw new Exception("While handling: " + sheet.getSheetName() + "/" + row.getRowNum() + "/" + cell.getColumnIndex(), e);
+ }
+ }
+ }
+ }
+ }
}