poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fannin...@apache.org
Subject svn commit: r1846489 - in /poi/trunk/src: examples/src/org/apache/poi/xssf/usermodel/examples/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/xssf/usermodel/
Date Tue, 13 Nov 2018 08:20:48 GMT
Author: fanningpj
Date: Tue Nov 13 08:20:47 2018
New Revision: 1846489

URL: http://svn.apache.org/viewvc?rev=1846489&view=rev
Log:
add testcase for https://bz.apache.org/bugzilla/show_bug.cgi?id=62906

Modified:
    poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateTable.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java

Modified: poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateTable.java?rev=1846489&r1=1846488&r2=1846489&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateTable.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateTable.java Tue
Nov 13 08:20:47 2018
@@ -36,8 +36,8 @@ public class CreateTable {
 
     public static void main(String[] args) throws IOException {
 
-        try (Workbook wb = new XSSFWorkbook()) {
-            XSSFSheet sheet = (XSSFSheet) wb.createSheet();
+        try (XSSFWorkbook wb = new XSSFWorkbook()) {
+            XSSFSheet sheet = wb.createSheet();
 
             // Set which area the table should be placed in
             AreaReference reference = wb.getCreationHelper().createAreaReference(

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1846489&r1=1846488&r2=1846489&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Tue Nov 13 08:20:47
2018
@@ -4109,18 +4109,17 @@ public class XSSFSheet extends POIXMLDoc
         int tableNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.TABLE.getContentType()).size()
+ 1;
 
         // the id could already be taken after insertion/deletion of different tables
-        outerloop:
-        while(true) {
+        boolean loop = true;
+        while(loop) {
+            loop = false;
             for (PackagePart packagePart : getPackagePart().getPackage().getPartsByContentType(XSSFRelation.TABLE.getContentType()))
{
                 String fileName = XSSFRelation.TABLE.getFileName(tableNumber);
                 if(fileName.equals(packagePart.getPartName().getName())) {
                     // duplicate found, increase the number and start iterating again
                     tableNumber++;
-                    continue outerloop;
+                    loop = true;
                 }
             }
-
-            break;
         }
 
         RelationPart rp = createRelationship(XSSFRelation.TABLE, XSSFFactory.getInstance(),
tableNumber, false);

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=1846489&r1=1846488&r2=1846489&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Tue Nov
13 08:20:47 2018
@@ -55,10 +55,7 @@ import org.apache.poi.ss.usermodel.Index
 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.util.CellAddress;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.ss.util.CellUtil;
+import org.apache.poi.ss.util.*;
 import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
@@ -1993,12 +1990,11 @@ public final class TestXSSFSheet extends
 
     @Test
     public void testGetHeaderFooterProperties() throws IOException {
-         XSSFWorkbook wb = new XSSFWorkbook();
-         XSSFSheet sh = wb.createSheet();
-
-         XSSFHeaderFooterProperties hfProp = sh.getHeaderFooterProperties();
-         assertNotNull(hfProp);
+        try (XSSFWorkbook wb = new XSSFWorkbook()) {
+            XSSFSheet sh = wb.createSheet();
 
-         wb.close();
+            XSSFHeaderFooterProperties hfProp = sh.getHeaderFooterProperties();
+            assertNotNull(hfProp);
+        }
     }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java?rev=1846489&r1=1846488&r2=1846489&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java Tue Nov
13 08:20:47 2018
@@ -348,15 +348,45 @@ public final class TestXSSFTable {
         
         IOUtils.closeQuietly(wb);
     }
-    
+
+    @Test
+    public void testCreateTableIds() throws IOException {
+        try (XSSFWorkbook wb = new XSSFWorkbook()) {
+            XSSFSheet sheet = wb.createSheet();
+
+            AreaReference reference1 = wb.getCreationHelper().createAreaReference(
+                    new CellReference(0, 0), new CellReference(2, 2));
+
+            XSSFTable table1 = sheet.createTable(reference1);
+
+            assertEquals(1, table1.getCTTable().getTableColumns().getTableColumnArray(0).getId());
+            assertEquals(2, table1.getCTTable().getTableColumns().getTableColumnArray(1).getId());
+            assertEquals(3, table1.getCTTable().getTableColumns().getTableColumnArray(2).getId());
+
+            assertEquals(1, table1.getCTTable().getId());
+
+            AreaReference reference2 = wb.getCreationHelper().createAreaReference(
+                    new CellReference(10, 10), new CellReference(12, 12));
+
+            XSSFTable table2 = sheet.createTable(reference2);
+
+            // these IDs dupplicate those from table1 and may be cause of https://bz.apache.org/bugzilla/show_bug.cgi?id=62906
+            assertEquals(1, table2.getCTTable().getTableColumns().getTableColumnArray(0).getId());
+            assertEquals(2, table2.getCTTable().getTableColumns().getTableColumnArray(1).getId());
+            assertEquals(3, table2.getCTTable().getTableColumns().getTableColumnArray(2).getId());
+
+            assertEquals(2, table2.getCTTable().getId());
+        }
+    }
+
     @Test
     public void testSetArea() throws IOException {
-        XSSFWorkbook wb = new XSSFWorkbook();
+        try (XSSFWorkbook wb = new XSSFWorkbook()) {
             XSSFSheet sh = wb.createSheet();
-            
+
             AreaReference tableArea = new AreaReference("B10:D12", wb.getSpreadsheetVersion());
             XSSFTable table = sh.createTable(tableArea);
-            
+
             assertEquals(3, table.getColumnCount());
             assertEquals(3, table.getRowCount());
 
@@ -366,11 +396,11 @@ public final class TestXSSFTable {
 
             assertEquals(3, table.getColumnCount());
             assertEquals(3, table.getRowCount());
- 
+
             // increase size by 1 row and 1 column
             AreaReference tableArea3 = new AreaReference("B11:E14", wb.getSpreadsheetVersion());
             table.setArea(tableArea3);
-            
+
             assertEquals(4, table.getColumnCount());
             assertEquals(4, table.getRowCount());
 
@@ -380,43 +410,41 @@ public final class TestXSSFTable {
 
             assertEquals(2, table.getColumnCount());
             assertEquals(2, table.getRowCount());
-            
-            IOUtils.closeQuietly(wb);
+        }
     }
     
     @Test
-    public void testCreateColumn() {
-        XSSFWorkbook wb = new XSSFWorkbook();
-        XSSFSheet sh = wb.createSheet();
-        
-        AreaReference tableArea = new AreaReference("A2:A3", wb.getSpreadsheetVersion());
-        XSSFTable table = sh.createTable(tableArea);
+    public void testCreateColumn() throws IOException {
+        try (XSSFWorkbook wb = new XSSFWorkbook()) {
+            XSSFSheet sh = wb.createSheet();
 
-        assertEquals(1, table.getColumnCount());
-        assertEquals(2, table.getRowCount());
+            AreaReference tableArea = new AreaReference("A2:A3", wb.getSpreadsheetVersion());
+            XSSFTable table = sh.createTable(tableArea);
 
-        // add columns
-        XSSFTableColumn c1 = table.getColumns().get(0);
-        XSSFTableColumn cB = table.createColumn("Column B");
-        XSSFTableColumn cD = table.createColumn("Column D");
-        XSSFTableColumn cC = table.createColumn("Column C", 2); // add between B and D
-        table.updateReferences();
-        table.updateHeaders();
-
-        assertEquals(4, table.getColumnCount());
-        assertEquals(2, table.getRowCount());
-
-        // column IDs start at 1, and increase in the order columns are added (see bug #62740)
-        assertEquals("Column c ID", 1, c1.getId());
-        assertTrue("Column B ID", c1.getId() < cB.getId());
-        assertTrue("Column D ID", cB.getId() < cD.getId());
-        assertTrue("Column C ID", cD.getId() < cC.getId());
-        assertEquals("Column 1", table.getColumns().get(0).getName()); // generated name
-        assertEquals("Column B", table.getColumns().get(1).getName());
-        assertEquals("Column C", table.getColumns().get(2).getName());
-        assertEquals("Column D", table.getColumns().get(3).getName());
+            assertEquals(1, table.getColumnCount());
+            assertEquals(2, table.getRowCount());
 
-        IOUtils.closeQuietly(wb);
+            // add columns
+            XSSFTableColumn c1 = table.getColumns().get(0);
+            XSSFTableColumn cB = table.createColumn("Column B");
+            XSSFTableColumn cD = table.createColumn("Column D");
+            XSSFTableColumn cC = table.createColumn("Column C", 2); // add between B and
D
+            table.updateReferences();
+            table.updateHeaders();
+
+            assertEquals(4, table.getColumnCount());
+            assertEquals(2, table.getRowCount());
+
+            // column IDs start at 1, and increase in the order columns are added (see bug
#62740)
+            assertEquals("Column c ID", 1, c1.getId());
+            assertTrue("Column B ID", c1.getId() < cB.getId());
+            assertTrue("Column D ID", cB.getId() < cD.getId());
+            assertTrue("Column C ID", cD.getId() < cC.getId());
+            assertEquals("Column 1", table.getColumns().get(0).getName()); // generated name
+            assertEquals("Column B", table.getColumns().get(1).getName());
+            assertEquals("Column C", table.getColumns().get(2).getName());
+            assertEquals("Column D", table.getColumns().get(3).getName());
+        }
     }
 
     @Test(expected = IllegalArgumentException.class)



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


Mime
View raw message