You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2015/09/13 21:05:42 UTC

svn commit: r1702801 - in /poi/trunk/src/integrationtest/org/apache/poi: TestAllFiles.java stress/OPCFileHandler.java stress/XSSFFileHandler.java

Author: centic
Date: Sun Sep 13 19:05:40 2015
New Revision: 1702801

URL: http://svn.apache.org/r1702801
Log:
Enhance integration testing to apply OPCPackage tests to more file-types and also run XSSFReader in XSSFFileHandler

Modified:
    poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java
    poi/trunk/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java
    poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java

Modified: poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java?rev=1702801&r1=1702800&r2=1702801&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/TestAllFiles.java Sun Sep 13 19:05:40 2015
@@ -271,7 +271,16 @@ public class TestAllFiles {
         for(String file : scanner.getIncludedFiles()) {
             file = file.replace('\\', '/'); // ... failures/handlers lookup doesn't work on windows otherwise
             if (IGNORED.contains(file)) continue;
-            files.add(new Object[] { file, HANDLERS.get(getExtension(file)) });
+            FileHandler handler = HANDLERS.get(getExtension(file));
+            files.add(new Object[] { file, handler });
+            
+            // for some file-types also run OPCFileHandler
+            if(handler instanceof XSSFFileHandler ||
+                handler instanceof XWPFFileHandler ||
+                handler instanceof XSLFFileHandler ||
+                handler instanceof XDGFFileHandler) {
+                files.add(new Object[] { file, HANDLERS.get(".ooxml") });
+            }
         }
 
         return files;
@@ -301,8 +310,12 @@ public class TestAllFiles {
 
             handler.handleExtracting(inputFile);
 
+            // special cases where docx-handling breaks, but OPCPackage handling works
+            boolean ignoredOPC = (file.endsWith(".docx") || file.endsWith(".xlsx") || file.endsWith(".xlsb")) && 
+                    handler instanceof OPCFileHandler;
+
             assertFalse("Expected to fail for file " + file + " and handler " + handler + ", but did not fail!", 
-                    EXPECTED_FAILURES.contains(file));
+                EXPECTED_FAILURES.contains(file) && !ignoredOPC);
         } catch (OldWordFileFormatException e) {
             // for old word files we should still support extracting text
             if(OLD_FILES.contains(file)) {

Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java?rev=1702801&r1=1702800&r2=1702801&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/OPCFileHandler.java Sun Sep 13 19:05:40 2015
@@ -17,6 +17,7 @@
 package org.apache.poi.stress;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -36,19 +37,23 @@ public class OPCFileHandler extends Abst
         if (POIXMLDocumentHandler.isEncrypted(stream)) return;
 
         OPCPackage p = OPCPackage.open(stream);
-        
+
         for (PackagePart part : p.getParts()) {
             if (part.getPartName().toString().equals("/docProps/core.xml")) {
                 assertEquals(ContentTypes.CORE_PROPERTIES_PART, part.getContentType());
             }
             if (part.getPartName().toString().equals("/word/document.xml")) {
-                assertEquals(XWPFRelation.DOCUMENT.getContentType(), part.getContentType());
+                assertTrue("Expected one of " + XWPFRelation.MACRO_DOCUMENT + ", " + XWPFRelation.DOCUMENT + ", " + XWPFRelation.TEMPLATE + 
+                        ", but had " + part.getContentType(),
+                        XWPFRelation.DOCUMENT.getContentType().equals(part.getContentType()) ||
+                        XWPFRelation.MACRO_DOCUMENT.getContentType().equals(part.getContentType()) ||
+                        XWPFRelation.TEMPLATE.getContentType().equals(part.getContentType()));
             }
             if (part.getPartName().toString().equals("/word/theme/theme1.xml")) {
                 assertEquals(XWPFRelation.THEME.getContentType(), part.getContentType());
             }
         }
-	}
+    }
 	
     public void handleExtracting(File file) throws Exception {
         // text-extraction is not possible currenlty for these types of files
@@ -57,7 +62,7 @@ public class OPCFileHandler extends Abst
 	// a test-case to test this locally without executing the full TestAllFiles
 	@Test
 	public void test() throws Exception {
-		File file = new File("test-data/openxml4j/dcterms_bug_56479.zip");
+		File file = new File("test-data/diagram/test.vsdx");
 
 		InputStream stream = new PushbackInputStream(new FileInputStream(file), 100000);
 		try {
@@ -68,4 +73,4 @@ public class OPCFileHandler extends Abst
 		
 		handleExtracting(file);
 	}
-}
\ No newline at end of file
+}

Modified: poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java?rev=1702801&r1=1702800&r2=1702801&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java (original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java Sun Sep 13 19:05:40 2015
@@ -16,14 +16,25 @@
 ==================================================================== */
 package org.apache.poi.stress;
 
+import static org.junit.Assert.assertNotNull;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.io.InputStream;
+import java.util.Iterator;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.TransformerException;
 
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.xssf.eventusermodel.XSSFReader;
 import org.apache.poi.xssf.extractor.XSSFExportToXml;
 import org.apache.poi.xssf.usermodel.XSSFMap;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -31,27 +42,64 @@ import org.junit.Test;
 import org.xml.sax.SAXException;
 
 public class XSSFFileHandler extends SpreadsheetHandler {
-	@Override
+    @Override
     public void handleFile(InputStream stream) throws Exception {
-	    // ignore password protected files
-	    if (POIXMLDocumentHandler.isEncrypted(stream)) return;
-	    
-		XSSFWorkbook wb = new XSSFWorkbook(stream);
-		
-		// use the combined handler for HSSF/XSSF
-		handleWorkbook(wb, ".xlsx");
-		
+        // ignore password protected files
+        if (POIXMLDocumentHandler.isEncrypted(stream)) return;
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        IOUtils.copy(stream, out);
+
+        XSSFWorkbook wb = new XSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+        
+        // 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);
-	}
+        // also verify general POIFS-stuff
+        new POIXMLDocumentHandler().handlePOIXMLDocument(wb);
+        
+        // and finally ensure that exporting to XML works
+        exportToXML(wb);
+        
+        checkXSSFReader(OPCPackage.open(new ByteArrayInputStream(out.toByteArray())));
+    }
+
 
+    private void checkXSSFReader(OPCPackage p)
+            throws IOException, OpenXML4JException, InvalidFormatException {
+        XSSFReader reader = new XSSFReader(p);
+        
+        // these can be null...
+        InputStream sharedStringsData = reader.getSharedStringsData();
+        if(sharedStringsData != null) {
+            sharedStringsData.close();
+        }
+        reader.getSharedStringsTable();
+
+        InputStream stylesData = reader.getStylesData();
+        if(stylesData != null) {
+            stylesData.close();
+        }
+        reader.getStylesTable();
+        
+        InputStream themesData = reader.getThemesData();
+        if(themesData != null) {
+            themesData.close();
+        }
+
+        assertNotNull(reader.getWorkbookData());
+        
+        Iterator<InputStream> sheetsData = reader.getSheetsData();
+        while(sheetsData.hasNext()) {
+            InputStream str = sheetsData.next();
+            str.close();
+        }
+    }
+    
     private void exportToXML(XSSFWorkbook wb) throws SAXException,
             ParserConfigurationException, TransformerException {
         for (XSSFMap map : wb.getCustomXMLMappings()) {
@@ -62,16 +110,16 @@ public class XSSFFileHandler extends Spr
         }
     }
     
-	// 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();
-		}
-	}
+    // a test-case to test this locally without executing the full TestAllFiles
+    @Test
+    public void test() throws Exception {
+        InputStream stream = new BufferedInputStream(new FileInputStream("test-data/openxml4j/50154.xlsx"));
+        try {
+            handleFile(stream);
+        } finally {
+            stream.close();
+        }
+    }
 
     // a test-case to test this locally without executing the full TestAllFiles
     @Test



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org