poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1736742 - in /poi/trunk/src: ooxml/testcases/org/apache/poi/xssf/streaming/ ooxml/testcases/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/hssf/usermodel/ testcases/org/apache/poi/ss/usermodel/
Date Sun, 27 Mar 2016 13:04:38 GMT
Author: onealj
Date: Sun Mar 27 13:04:37 2016
New Revision: 1736742

URL: http://svn.apache.org/viewvc?rev=1736742&view=rev
Log:
add more commented-out tests for bug 58779: closing an XML Workbook that was not opened as
read-only will modify the file on disk

Modified:
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java?rev=1736742&r1=1736741&r2=1736742&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java Sun
Mar 27 13:04:37 2016
@@ -26,10 +26,14 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 
+import org.apache.poi.POIDataSamples;
 import org.apache.poi.POITestCase;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.usermodel.BaseTestWorkbook;
 import org.apache.poi.ss.usermodel.Cell;
@@ -444,4 +448,30 @@ public final class TestSXSSFWorkbook ext
     public void getSpreadsheetVersion() throws IOException {
         verifySpreadsheetVersion(SpreadsheetVersion.EXCEL2007);
     }
+    
+    @Test
+    public void closeDoesNotModifyWorkbook() throws IOException, InvalidFormatException {
+        final String filename = "SampleSS.xlsx";
+        final File file = POIDataSamples.getSpreadSheetInstance().getFile(filename);
+        SXSSFWorkbook wb;
+        
+        // Some tests commented out because close() modifies the file
+        // See bug 58779
+        
+        // String
+        //wb = new SXSSFWorkbook(new XSSFWorkbook(file.getPath()));
+        //assertCloseDoesNotModifyFile(filename, wb);
+        
+        // File
+        //wb = new SXSSFWorkbook(new XSSFWorkbook(file));
+        //assertCloseDoesNotModifyFile(filename, wb);
+        
+        // InputStream
+        wb = new SXSSFWorkbook(new XSSFWorkbook(new FileInputStream(file)));
+        assertCloseDoesNotModifyFile(filename, wb);
+        
+        // OPCPackage
+        //wb = new SXSSFWorkbook(new XSSFWorkbook(OPCPackage.open(file)));
+        //assertCloseDoesNotModifyFile(filename, wb);
+    }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=1736742&r1=1736741&r2=1736742&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Sun
Mar 27 13:04:37 2016
@@ -29,6 +29,7 @@ import static org.junit.Assert.fail;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -37,6 +38,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.zip.CRC32;
 
+import org.apache.poi.POIDataSamples;
 import org.apache.poi.POIXMLProperties;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -1085,4 +1087,30 @@ public final class TestXSSFWorkbook exte
     public void getSpreadsheetVersion() throws IOException {
         verifySpreadsheetVersion(SpreadsheetVersion.EXCEL2007);
     }
+    
+    @Test
+    public void closeDoesNotModifyWorkbook() throws IOException, InvalidFormatException {
+        final String filename = "SampleSS.xlsx";
+        final File file = POIDataSamples.getSpreadSheetInstance().getFile(filename);
+        Workbook wb;
+        
+        // Some tests commented out because close() modifies the file
+        // See bug 58779
+        
+        // String
+        //wb = new XSSFWorkbook(file.getPath());
+        //assertCloseDoesNotModifyFile(filename, wb);
+        
+        // File
+        //wb = new XSSFWorkbook(file);
+        //assertCloseDoesNotModifyFile(filename, wb);
+        
+        // InputStream
+        wb = new XSSFWorkbook(new FileInputStream(file));
+        assertCloseDoesNotModifyFile(filename, wb);
+        
+        // OPCPackage
+        //wb = new XSSFWorkbook(OPCPackage.open(file));
+        //assertCloseDoesNotModifyFile(filename, wb);
+    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java?rev=1736742&r1=1736741&r2=1736742&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java Sun Mar 27
13:04:37 2016
@@ -28,6 +28,7 @@ import static org.junit.Assert.fail;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -1262,4 +1263,23 @@ public final class TestHSSFWorkbook exte
     public void getSpreadsheetVersion() throws IOException {
         verifySpreadsheetVersion(SpreadsheetVersion.EXCEL97);
     }
+    
+    @Test
+    public void closeDoesNotModifyWorkbook() throws IOException {
+        final String filename = "SampleSS.xls";
+        final File file = POIDataSamples.getSpreadSheetInstance().getFile(filename);
+        Workbook wb;
+        
+        // File via POIFileStream (java.io)
+        wb = new HSSFWorkbook(new POIFSFileSystem(file));
+        assertCloseDoesNotModifyFile(filename, wb);
+        
+        // File via NPOIFileStream (java.nio)
+        wb = new HSSFWorkbook(new NPOIFSFileSystem(file));
+        assertCloseDoesNotModifyFile(filename, wb);
+        
+        // InputStream
+        wb = new HSSFWorkbook(new FileInputStream(file));
+        assertCloseDoesNotModifyFile(filename, wb);
+    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java?rev=1736742&r1=1736741&r2=1736742&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java Sun Mar 27 13:04:37
2016
@@ -17,6 +17,7 @@
 
 package org.apache.poi.ss.usermodel;
 
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -30,6 +31,7 @@ import java.io.OutputStream;
 import java.util.ConcurrentModificationException;
 import java.util.Iterator;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.ss.ITestDataProvider;
 import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.util.CellRangeAddress;
@@ -832,4 +834,12 @@ public abstract class BaseTestWorkbook {
         assertEquals(expected, wb.getSpreadsheetVersion());
         wb.close();
     }
+    
+    protected static void assertCloseDoesNotModifyFile(String filename, Workbook wb) throws
IOException {
+        final byte[] before = HSSFTestDataSamples.getTestDataFileContent(filename);
+        wb.close();
+        final byte[] after = HSSFTestDataSamples.getTestDataFileContent(filename);
+        assertArrayEquals(filename + " sample file was modified as a result of closing the
workbook",
+                before, after);
+    }
 }



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


Mime
View raw message