]> source.dussan.org Git - poi.git/commitdiff
Move some tests from "unfixed" to "normal" test classes as the underlying bug is...
authorDominik Stadler <centic@apache.org>
Tue, 20 May 2014 14:12:19 +0000 (14:12 +0000)
committerDominik Stadler <centic@apache.org>
Tue, 20 May 2014 14:12:19 +0000 (14:12 +0000)
Also make on of the unfixed bugs cause an actual failure so it is justified to stay in "unfixed"

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1596261 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestUnfixedBugs.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

index cdeeaec3124c7ce9f6f9374f21eb960fafb11fba..2d91e8400dd5e67c74f4fd973d3555c412cfa3a7 100644 (file)
 \r
 package org.apache.poi.xssf.usermodel;\r
 \r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
 import java.io.IOException;\r
 import java.io.UnsupportedEncodingException;\r
+import java.util.Date;\r
 \r
 import junit.framework.TestCase;\r
 \r
 import org.apache.poi.hssf.HSSFTestDataSamples;\r
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
 import org.apache.poi.ss.usermodel.Cell;\r
-import org.apache.poi.ss.usermodel.Font;\r
 import org.apache.poi.ss.usermodel.Row;\r
 import org.apache.poi.ss.usermodel.Sheet;\r
 import org.apache.poi.ss.usermodel.Workbook;\r
-import org.apache.poi.util.TempFile;\r
 import org.apache.poi.xssf.SXSSFITestDataProvider;\r
 import org.apache.poi.xssf.XSSFTestDataSamples;\r
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;\r
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontImpl;\r
 \r
 /**\r
  * @author centic\r
@@ -84,123 +78,30 @@ public final class TestUnfixedBugs extends TestCase {
         assertEquals("The data in the text-file should exactly match the data that we read from the workbook", testData, value);\r
     }\r
 \r
-       public void test54071() {\r
-               Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("54071.xlsx");\r
-               Sheet sheet = workbook.getSheetAt(0);\r
-               int rows = sheet.getPhysicalNumberOfRows();\r
-               System.out.println(">> file rows is:"+(rows-1)+" <<");\r
-               Row title = sheet.getRow(0);\r
-\r
-               for (int row = 1; row < rows; row++) {\r
-                       Row rowObj = sheet.getRow(row);\r
-                       for (int col = 0; col < 1; col++) {\r
-                               String titleName = title.getCell(col).toString();\r
-                               Cell cell = rowObj.getCell(col);\r
-                               if (titleName.startsWith("time")) {\r
-                                       // here the output will produce ...59 or ...58 for the rows, probably POI is\r
-                                       // doing some different rounding or some other small difference...\r
-                                       System.out.println("==Time:"+cell.getDateCellValue());\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       public void testBug53798XLSX() throws IOException {\r
-       XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("53798_shiftNegative_TMPL.xlsx");\r
-        File xlsOutput = TempFile.createTempFile("testBug53798", ".xlsx");\r
-        bug53798Work(wb, xlsOutput);\r
-       }\r
-\r
-       // Disabled because shift rows is not yet implemented for SXSSFWorkbook\r
-       public void disabled_testBug53798XLSXStream() throws IOException {\r
-       XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("53798_shiftNegative_TMPL.xlsx");\r
-        File xlsOutput = TempFile.createTempFile("testBug53798", ".xlsx");\r
-        bug53798Work(new SXSSFWorkbook(wb), xlsOutput);\r
-       }\r
-\r
-       public void testBug53798XLS() throws IOException {\r
-       Workbook wb = HSSFTestDataSamples.openSampleWorkbook("53798_shiftNegative_TMPL.xls");\r
-        File xlsOutput = TempFile.createTempFile("testBug53798", ".xls");\r
-        bug53798Work(wb, xlsOutput);\r
-       }\r
-\r
-       private void bug53798Work(Workbook wb, File xlsOutput) throws IOException {\r
-               Sheet testSheet = wb.getSheetAt(0);\r
-\r
-               testSheet.shiftRows(2, 2, 1);\r
-\r
-               saveAndReloadReport(wb, xlsOutput);\r
-\r
-               // 1) corrupted xlsx (unreadable data in the first row of a shifted group) already comes about\r
-               // when shifted by less than -1 negative amount (try -2)\r
-               testSheet.shiftRows(3, 3, -1);\r
-\r
-               saveAndReloadReport(wb, xlsOutput);\r
-\r
-               testSheet.shiftRows(2, 2, 1);\r
-\r
-               saveAndReloadReport(wb, xlsOutput);\r
-\r
-               Row newRow = null;\r
-               Cell newCell = null;\r
-               // 2) attempt to create a new row IN PLACE of a removed row by a negative shift causes corrupted\r
-               // xlsx file with  unreadable data in the negative shifted row.\r
-               // NOTE it's ok to create any other row.\r
-               newRow = testSheet.createRow(3);\r
-\r
-               saveAndReloadReport(wb, xlsOutput);\r
-\r
-               newCell = newRow.createCell(0);\r
-\r
-               saveAndReloadReport(wb, xlsOutput);\r
-\r
-               newCell.setCellValue("new Cell in row "+newRow.getRowNum());\r
-\r
-               saveAndReloadReport(wb, xlsOutput);\r
-\r
-               // 3) once a negative shift has been made any attempt to shift another group of rows\r
-               // (note: outside of previously negative shifted rows) by a POSITIVE amount causes POI exception:\r
-               // org.apache.xmlbeans.impl.values.XmlValueDisconnectedException.\r
-               // NOTE: another negative shift on another group of rows is successful, provided no new rows in\r
-               // place of previously shifted rows were attempted to be created as explained above.\r
-               testSheet.shiftRows(6, 7, 1);   // -- CHANGE the shift to positive once the behaviour of\r
-                                                                               // the above has been tested\r
-\r
-               saveAndReloadReport(wb, xlsOutput);\r
-       }\r
-\r
-       private void saveAndReloadReport(Workbook wb, File outFile) throws IOException {\r
-               // run some method on the font to verify if it is "disconnected" already\r
-               //for(short i = 0;i < 256;i++)\r
-               {\r
-                       Font font = wb.getFontAt((short)0);\r
-                       if(font instanceof XSSFFont) {\r
-                               XSSFFont xfont = (XSSFFont) wb.getFontAt((short)0);\r
-                               CTFontImpl ctFont = (CTFontImpl) xfont.getCTFont();\r
-                               assertEquals(0, ctFont.sizeOfBArray());\r
-                       }\r
-               }\r
-\r
-               FileOutputStream fileOutStream = new FileOutputStream(outFile);\r
-               wb.write(fileOutStream);\r
-               fileOutStream.close();\r
-               //System.out.println("File \""+outFile.getName()+"\" has been saved successfully");\r
-\r
-               FileInputStream is = new FileInputStream(outFile);\r
-               try {\r
-                       final Workbook newWB;\r
-                       if(wb instanceof XSSFWorkbook) {\r
-                               newWB = new XSSFWorkbook(is);\r
-                       } else if(wb instanceof HSSFWorkbook) {\r
-                               newWB = new HSSFWorkbook(is);\r
-                       } else if(wb instanceof SXSSFWorkbook) {\r
-                               newWB = new SXSSFWorkbook(new XSSFWorkbook(is));\r
-                       } else {\r
-                               throw new IllegalStateException("Unknown workbook: " + wb);\r
-                       }\r
-                       assertNotNull(newWB.getSheet("test"));\r
-               } finally {\r
-                       is.close();\r
-               }\r
-       }\r
+    public void test54071() {\r
+        Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("54071.xlsx");\r
+        Sheet sheet = workbook.getSheetAt(0);\r
+        int rows = sheet.getPhysicalNumberOfRows();\r
+        System.out.println(">> file rows is:"+(rows-1)+" <<");\r
+        Row title = sheet.getRow(0);\r
+\r
+        Date prev = null;\r
+        for (int row = 1; row < rows; row++) {\r
+            Row rowObj = sheet.getRow(row);\r
+            for (int col = 0; col < 1; col++) {\r
+                String titleName = title.getCell(col).toString();\r
+                Cell cell = rowObj.getCell(col);\r
+                if (titleName.startsWith("time")) {\r
+                    // here the output will produce ...59 or ...58 for the rows, probably POI is\r
+                    // doing some different rounding or some other small difference...\r
+                    System.out.println("==Time:"+cell.getDateCellValue());\r
+                    if(prev != null) {\r
+                        assertEquals(prev, cell.getDateCellValue());\r
+                    }\r
+                    \r
+                    prev = cell.getDateCellValue();\r
+                }\r
+            }\r
+        }\r
+    }\r
 }\r
index 9af149bf56ba2f864092618c9cfe9bc23ef4c8ab..aa8395e02d22d6247f042b05f3c4195ec150c30c 100644 (file)
@@ -22,11 +22,16 @@ import static org.junit.Assert.*;
 
 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.util.List;
 
 import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackagePart;
@@ -41,14 +46,17 @@ import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.AreaReference;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.util.TempFile;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.model.CalculationChain;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTFontImpl;
 
 public final class TestXSSFBugs extends BaseTestBugzillaIssues {
 
@@ -1493,4 +1501,107 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
         
         assertThat(firstSave, equalTo(secondSave));
     }
+
+
+    @Test
+    public void testBug53798XLSX() throws IOException {
+        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("53798_shiftNegative_TMPL.xlsx");
+        File xlsOutput = TempFile.createTempFile("testBug53798", ".xlsx");
+        bug53798Work(wb, xlsOutput);
+    }
+
+    @Ignore("Shifting rows is not yet implemented in XSSFSheet")
+    @Test
+    public void testBug53798XLSXStream() throws IOException {
+        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("53798_shiftNegative_TMPL.xlsx");
+        File xlsOutput = TempFile.createTempFile("testBug53798", ".xlsx");
+        bug53798Work(new SXSSFWorkbook(wb), xlsOutput);
+    }
+
+    @Test
+    public void testBug53798XLS() throws IOException {
+        Workbook wb = HSSFTestDataSamples.openSampleWorkbook("53798_shiftNegative_TMPL.xls");
+        File xlsOutput = TempFile.createTempFile("testBug53798", ".xls");
+        bug53798Work(wb, xlsOutput);
+    }
+
+    private void bug53798Work(Workbook wb, File xlsOutput) throws IOException {
+        Sheet testSheet = wb.getSheetAt(0);
+
+        testSheet.shiftRows(2, 2, 1);
+
+        saveAndReloadReport(wb, xlsOutput);
+
+        // 1) corrupted xlsx (unreadable data in the first row of a shifted group) already comes about
+        // when shifted by less than -1 negative amount (try -2)
+        testSheet.shiftRows(3, 3, -1);
+
+        saveAndReloadReport(wb, xlsOutput);
+
+        testSheet.shiftRows(2, 2, 1);
+
+        saveAndReloadReport(wb, xlsOutput);
+
+        Row newRow = null;
+        Cell newCell = null;
+        // 2) attempt to create a new row IN PLACE of a removed row by a negative shift causes corrupted
+        // xlsx file with  unreadable data in the negative shifted row.
+        // NOTE it's ok to create any other row.
+        newRow = testSheet.createRow(3);
+
+        saveAndReloadReport(wb, xlsOutput);
+
+        newCell = newRow.createCell(0);
+
+        saveAndReloadReport(wb, xlsOutput);
+
+        newCell.setCellValue("new Cell in row "+newRow.getRowNum());
+
+        saveAndReloadReport(wb, xlsOutput);
+
+        // 3) once a negative shift has been made any attempt to shift another group of rows
+        // (note: outside of previously negative shifted rows) by a POSITIVE amount causes POI exception:
+        // org.apache.xmlbeans.impl.values.XmlValueDisconnectedException.
+        // NOTE: another negative shift on another group of rows is successful, provided no new rows in
+        // place of previously shifted rows were attempted to be created as explained above.
+        testSheet.shiftRows(6, 7, 1);   // -- CHANGE the shift to positive once the behaviour of
+                                        // the above has been tested
+
+        saveAndReloadReport(wb, xlsOutput);
+    }
+
+    private void saveAndReloadReport(Workbook wb, File outFile) throws IOException {
+        // run some method on the font to verify if it is "disconnected" already
+        //for(short i = 0;i < 256;i++)
+        {
+            Font font = wb.getFontAt((short)0);
+            if(font instanceof XSSFFont) {
+                XSSFFont xfont = (XSSFFont) wb.getFontAt((short)0);
+                CTFontImpl ctFont = (CTFontImpl) xfont.getCTFont();
+                assertEquals(0, ctFont.sizeOfBArray());
+            }
+        }
+
+        FileOutputStream fileOutStream = new FileOutputStream(outFile);
+        wb.write(fileOutStream);
+        fileOutStream.close();
+        //System.out.println("File \""+outFile.getName()+"\" has been saved successfully");
+
+        FileInputStream is = new FileInputStream(outFile);
+        try {
+            final Workbook newWB;
+            if(wb instanceof XSSFWorkbook) {
+                newWB = new XSSFWorkbook(is);
+            } else if(wb instanceof HSSFWorkbook) {
+                newWB = new HSSFWorkbook(is);
+            } else if(wb instanceof SXSSFWorkbook) {
+                newWB = new SXSSFWorkbook(new XSSFWorkbook(is));
+            } else {
+                throw new IllegalStateException("Unknown workbook: " + wb);
+            }
+            assertNotNull(newWB.getSheet("test"));
+        } finally {
+            is.close();
+        }
+    }
 }