From 8daac21f87301870b0090a40fb0f617c25c8e500 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Thu, 25 Dec 2014 09:16:44 +0000 Subject: [PATCH] Add a test-suite which performs integration/stress tests which load and handle all stored test files in various ways. It works by using handlers for each type of file which perform various operations on the files, e.g. loading, iterating content, modify, ... This will trigger changes which break working with the available test-files and thus provides another layer of regression testing which hopefully prevents some failures from making it into releases. It is runnable via a new ant-target 'test-integration' and also added to the jenkins-target. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647885 13f79535-47bb-0310-9956-ffa450edef68 --- .classpath | 1 + build.xml | 79 ++++- .../org/apache/poi/TestAllFiles.java | 278 ++++++++++++++++++ .../poi/hssf/usermodel/RecordsStresser.java | 77 +++++ .../org/apache/poi/stress/FileHandler.java | 37 +++ .../apache/poi/stress/HDGFFileHandler.java | 58 ++++ .../apache/poi/stress/HMEFFileHandler.java | 60 ++++ .../apache/poi/stress/HPBFFileHandler.java | 49 +++ .../apache/poi/stress/HPSFFileHandler.java | 46 +++ .../apache/poi/stress/HSLFFileHandler.java | 56 ++++ .../apache/poi/stress/HSMFFileHandler.java | 69 +++++ .../apache/poi/stress/HSSFFileHandler.java | 52 ++++ .../apache/poi/stress/HWPFFileHandler.java | 48 +++ .../apache/poi/stress/POIFSFileHandler.java | 49 +++ .../poi/stress/POIXMLDocumentHandler.java | 31 ++ .../apache/poi/stress/SpreadsheetHandler.java | 86 ++++++ .../apache/poi/stress/XSLFFileHandler.java | 49 +++ .../apache/poi/stress/XSSFFileHandler.java | 71 +++++ .../apache/poi/stress/XWPFFileHandler.java | 44 +++ .../xssf/extractor/TestXSSFExportToXML.java | 13 + .../apache/poi/hssf/dev/TestEFBiffViewer.java | 5 + .../org/apache/poi/hssf/dev/TestReSave.java | 1 + .../poi/hssf/usermodel/TestUnfixedBugs.java | 48 +++ test-data/spreadsheet/44958_1.xls | Bin 0 -> 7168 bytes 24 files changed, 1306 insertions(+), 1 deletion(-) create mode 100644 src/integrationtest/org/apache/poi/TestAllFiles.java create mode 100644 src/integrationtest/org/apache/poi/hssf/usermodel/RecordsStresser.java create mode 100644 src/integrationtest/org/apache/poi/stress/FileHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/HSLFFileHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/HWPFFileHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/POIXMLDocumentHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/SpreadsheetHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java create mode 100644 src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java create mode 100644 test-data/spreadsheet/44958_1.xls diff --git a/.classpath b/.classpath index 58ae07b0f8..bc01351d8d 100644 --- a/.classpath +++ b/.classpath @@ -14,6 +14,7 @@ + diff --git a/build.xml b/build.xml index 00d7829805..ec4e65bb2a 100644 --- a/build.xml +++ b/build.xml @@ -122,6 +122,12 @@ under the License. + + + + + + @@ -285,6 +291,14 @@ under the License. + + + + + + + + @@ -369,6 +383,8 @@ under the License. + + @@ -788,6 +804,28 @@ under the License. + + + + + + + + + + + + + @@ -1036,6 +1074,45 @@ under the License. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1503,7 +1580,7 @@ under the License. - + diff --git a/src/integrationtest/org/apache/poi/TestAllFiles.java b/src/integrationtest/org/apache/poi/TestAllFiles.java new file mode 100644 index 0000000000..b2bc251f83 --- /dev/null +++ b/src/integrationtest/org/apache/poi/TestAllFiles.java @@ -0,0 +1,278 @@ +/* ==================================================================== + 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 HANDLERS = new HashMap(); + 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 EXPECTED_FAILURES = new HashSet(); + 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 files() { + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir(new File("test-data")); + + scanner.scan(); + + System.out.println("Handling " + scanner.getIncludedFiles().length + " files"); + + List files = new ArrayList(); + 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 { + } + } +} diff --git a/src/integrationtest/org/apache/poi/hssf/usermodel/RecordsStresser.java b/src/integrationtest/org/apache/poi/hssf/usermodel/RecordsStresser.java new file mode 100644 index 0000000000..acc8b97cd2 --- /dev/null +++ b/src/integrationtest/org/apache/poi/hssf/usermodel/RecordsStresser.java @@ -0,0 +1,77 @@ +/* ==================================================================== + 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 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(); + } + } +} diff --git a/src/integrationtest/org/apache/poi/stress/FileHandler.java b/src/integrationtest/org/apache/poi/stress/FileHandler.java new file mode 100644 index 0000000000..e6f3385f02 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/FileHandler.java @@ -0,0 +1,37 @@ +/* ==================================================================== + 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; +} diff --git a/src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java new file mode 100644 index 0000000000..7fac6647a3 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/HDGFFileHandler.java @@ -0,0 +1,58 @@ +/* ==================================================================== + 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(); + } + } +} diff --git a/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java new file mode 100644 index 0000000000..dfa8750058 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/HMEFFileHandler.java @@ -0,0 +1,60 @@ +/* ==================================================================== + 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(); + } + } +} diff --git a/src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java new file mode 100644 index 0000000000..31ad8bc123 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/HPBFFileHandler.java @@ -0,0 +1,49 @@ +/* ==================================================================== + 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(); + } + } +} diff --git a/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java new file mode 100644 index 0000000000..b7d846ae62 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/HPSFFileHandler.java @@ -0,0 +1,46 @@ +/* ==================================================================== + 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(); + } + } +} diff --git a/src/integrationtest/org/apache/poi/stress/HSLFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HSLFFileHandler.java new file mode 100644 index 0000000000..51e54f6eb2 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/HSLFFileHandler.java @@ -0,0 +1,56 @@ +/* ==================================================================== + 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(); + } + } +} diff --git a/src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java new file mode 100644 index 0000000000..9de8b798c5 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/HSMFFileHandler.java @@ -0,0 +1,69 @@ +/* ==================================================================== + 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 diff --git a/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java new file mode 100644 index 0000000000..19dbd97a0e --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java @@ -0,0 +1,52 @@ +/* ==================================================================== + 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 diff --git a/src/integrationtest/org/apache/poi/stress/HWPFFileHandler.java b/src/integrationtest/org/apache/poi/stress/HWPFFileHandler.java new file mode 100644 index 0000000000..1b6d4646c7 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/HWPFFileHandler.java @@ -0,0 +1,48 @@ +/* ==================================================================== + 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 diff --git a/src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java b/src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java new file mode 100644 index 0000000000..31deac7106 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/POIFSFileHandler.java @@ -0,0 +1,49 @@ +/* ==================================================================== + 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); + } +} diff --git a/src/integrationtest/org/apache/poi/stress/POIXMLDocumentHandler.java b/src/integrationtest/org/apache/poi/stress/POIXMLDocumentHandler.java new file mode 100644 index 0000000000..f28a85b529 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/POIXMLDocumentHandler.java @@ -0,0 +1,31 @@ +/* ==================================================================== + 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()); + } +} diff --git a/src/integrationtest/org/apache/poi/stress/SpreadsheetHandler.java b/src/integrationtest/org/apache/poi/stress/SpreadsheetHandler.java new file mode 100644 index 0000000000..aad703ce98 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/SpreadsheetHandler.java @@ -0,0 +1,86 @@ +/* ==================================================================== + 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 diff --git a/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java new file mode 100644 index 0000000000..bcdff84992 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/XSLFFileHandler.java @@ -0,0 +1,49 @@ +/* ==================================================================== + 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 diff --git a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java new file mode 100644 index 0000000000..701fdcdaaa --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java @@ -0,0 +1,71 @@ +/* ==================================================================== + 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 diff --git a/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java new file mode 100644 index 0000000000..358009a2f0 --- /dev/null +++ b/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java @@ -0,0 +1,44 @@ +/* ==================================================================== + 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 diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java index d0e118ae20..ccc883dd30 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java @@ -213,6 +213,19 @@ public final class TestXSSFExportToXML extends TestCase { 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 diff --git a/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java b/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java index a6fc85e4d4..c3730bc043 100644 --- a/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java +++ b/src/testcases/org/apache/poi/hssf/dev/TestEFBiffViewer.java @@ -32,8 +32,13 @@ public class TestEFBiffViewer extends BaseXLSIteratingTest { 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 diff --git a/src/testcases/org/apache/poi/hssf/dev/TestReSave.java b/src/testcases/org/apache/poi/hssf/dev/TestReSave.java index cc124f449a..d42af8858f 100644 --- a/src/testcases/org/apache/poi/hssf/dev/TestReSave.java +++ b/src/testcases/org/apache/poi/hssf/dev/TestReSave.java @@ -37,6 +37,7 @@ public class TestReSave extends BaseXLSIteratingTest { 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 diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java index 7b101affeb..b6a535347a 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java @@ -24,6 +24,10 @@ import junit.framework.TestCase; 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 @@ -74,4 +78,48 @@ public final class TestUnfixedBugs extends TestCase { // 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); + } + } + } + } + } } diff --git a/test-data/spreadsheet/44958_1.xls b/test-data/spreadsheet/44958_1.xls new file mode 100644 index 0000000000000000000000000000000000000000..c407c2f10b507372e070509918500e3bbe6def7d GIT binary patch literal 7168 zcmeHLdu&rx82@h9c6Vd2jW;pos)J|MHI+ACW}mA0RQtXrvflB*69eJNK4$rGtS)gV|}n^Z1?b zeCIpgd41=8@p<{#10Re$CplrJ6v$PpNW59NhJ3$txlF``Jh7{mWu;+c`@&shfh&%# zoI^Jz(F5X~7lL$95vUl%`VuF-i-y;y>P;-rED`)-Vn~yOkw#@JX1VuaC{|2%7rkkj zeO~m2|7JXW{bww2Gh4Af+x|Sid5#x=ZnXb-?sNb52Mqv~f^Y>$IcOkg5NI%H2xus1 z7-%?X1ZX6v0(1{(6sQt38f1XRfT}=aLE}Kxpz)v@P%WqqGyyabR1ca2nhd%Z#Boe@ zQs(bR{sGW52b9ZpTmkc>h4tQ;ykc5vYBgRejwCh z{99q3(jlO6Z6>iuXCtS{exL*7h(b@Oc(z)7VDgE<`KCwmsLQ8x->u>*6%RnH$%m@V zcM6$`b@?gyt?jQko4}*Z#rfAJ0SQS?E%@$a?QryHZ9l=mf$~evS6k^Wk%PROA8K0G z)I4`drF*m-;{IAQZfyP7u~XL8&3vM{$^T?k?YJrhtf{MXSIc2BuCYv>ay=I?G8W6* zy#J@5SbbLQ=7aLPg{Id+(jZQADg3u|#f@$oZ2{19BG^dWRl4wlDH%imLwX2@OZkU3;aR+EZ`DExr+j!5`WApc}jwk z!Cufvwd+EA%SuQBWh;TUkZW}%q# zkdRrkX308rzU{Ba-Dh$PZ(XcdTke`MIRz9eA_sI zE(?Q;?;QI+EbDe3mf(sK_cRd^goI#hFQ%1CVoYC7E$ zREvo!enIi3{iGKa_L7Rnqy2?n7=CE1$;#Iv|5eR4{4X@tW#tcGe-=S2PKO2w^;*5w z@Ax|W&o-u0O&&&#F58snCUU%jUYn>gTP-fhlndYip3yU9H)j3JpiJ3=Nvkf+l)dy6 zoU*v+5vIQlaN+4LPCu8;b6hP@vQ%Ljq!z+5*%)tuLYdGFqc*vGv}rD%Cl4R=x{j|f z4LDleVfP(6#A2(90}J#AkK)NZe<_V=MgZoL~f?aNuAQK%1l z=Zuu9ad>4mN*WB)-J&(($H0=6CF1o%deRRSlO8{&A~~;Mrh0rpM(UJ@;%Sn!`0tfC z)FEi{v#j7SQwveTmQPV_wN7C}sGpjGG89SGD!eFVFM1TRf=h~3JL=1GZw{vEIPE7s zMzU7LZ=re+T&q!(%Q<03+=H670mtVC_Ur@OE(9-KZ2*N7PknQ9TtYYPUic?q|p3Px&odOMBL<|+)q^Dj5h zf@gQW`Rk?S8_V8(RhNl1$G+usodBh$aUt^D4J#aMBT|0vii2p{T_C=D-vHqngZE>< ze~%(%k3U|q-?H56{=n0w5eT>9>S_xIY@Ex%A8Bt3w{0?3#saM&GpgRcY)f5ypmgx1 zGf3@xYR>XQoxDy(R{JA6qn~p~*M*+O&puqIKRdmDaz)wR*D?P3OYi%Ed2+Bdz<9}1 zIEgy5Eyvaqj_SVfKe51_{QjrbPtF;V&rCe`eYVRWkKpTLR5r4U zUb&Cc$KnkeIF+5;*a(`;N6+o}!m%7WJY|Eo5VL=dhkY~jrYZOSB8O2!zacSu(=0C! zT?V^nJI>3L1M;S&56a+?m9honZ^zS$-+mY2D{xTF36U7ShD3n$9BQ5ZdA0R+{CKqB pYPAD=AN0_obTHKy=v&ig#%+v$I=YTI{oje?R_&kt{q?`@|8J-vuW0}P literal 0 HcmV?d00001