]> source.dussan.org Git - poi.git/commitdiff
Bug 58333: Apply patch to verify behavior on row-index before and after the limits...
authorDominik Stadler <centic@apache.org>
Sun, 20 Sep 2015 20:16:17 +0000 (20:16 +0000)
committerDominik Stadler <centic@apache.org>
Sun, 20 Sep 2015 20:16:17 +0000 (20:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1704186 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java

index ad3c4438305749541a646b4437857c2d116c51f8..53c9cff792b19536d6839f28ffca574d76ab0c7e 100644 (file)
@@ -24,6 +24,7 @@ import static org.junit.Assert.fail;
 
 import java.io.IOException;
 
+import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.usermodel.BaseTestSheet;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
@@ -146,6 +147,10 @@ public class TestSXSSFSheet extends BaseTestSheet {
         } finally {
             wb.close();
         }
+    }
 
+    @Test
+    public void createRowAfterLastRow() {
+        createRowAfterLastRow(SpreadsheetVersion.EXCEL2007);
     }
 }
index 785af694d1b39b7433546aa7c285275e8f511a70..8e77b2c4996e3936986dc2b690075ca040980371 100644 (file)
@@ -33,6 +33,7 @@ import org.apache.poi.POIXMLException;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.poifs.crypt.CryptoFunctions;
 import org.apache.poi.poifs.crypt.HashAlgorithm;
+import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.usermodel.AutoFilter;
 import org.apache.poi.ss.usermodel.BaseTestSheet;
 import org.apache.poi.ss.usermodel.Cell;
@@ -994,6 +995,11 @@ public final class TestXSSFSheet extends BaseTestSheet {
         assertEquals(3, xrow[2].getR());
 
     }
+    
+    @Test
+    public void createRowAfterLastRow() {
+        createRowAfterLastRow(SpreadsheetVersion.EXCEL2007);
+    }
 
     @Test
     public void setAutoFilter() {
index f47a11efdcca5172b39fc8adc217aed20081f068..4b7d8491bed2fbbcd00d54ace321dd17187750d7 100644 (file)
@@ -57,6 +57,7 @@ import org.apache.poi.hssf.record.WSBoolRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
 import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
 import org.apache.poi.hssf.usermodel.RecordInspector.RecordCollector;
+import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.formula.ptg.Area3DPtg;
 import org.apache.poi.ss.formula.ptg.Ptg;
 import org.apache.poi.ss.usermodel.AutoFilter;
@@ -84,7 +85,11 @@ public final class TestHSSFSheet extends BaseTestSheet {
     public TestHSSFSheet() {
         super(HSSFITestDataProvider.instance);
     }
-
+    
+    @Test
+    public void createRowAfterLastRow() {
+        createRowAfterLastRow(SpreadsheetVersion.EXCEL97);
+    }
 
     /**
      * Test for Bugzilla #29747.
index 55f9795e311950d60a59aa2bbe2c50c668d9ec54..16080068524f54a495a30a5a9b9d9c0f4528a7ce 100644 (file)
@@ -87,6 +87,31 @@ public abstract class BaseTestSheet {
         assertSame(row2_ovrewritten, row2_ovrewritten_ref);
         assertEquals(100.0, row2_ovrewritten_ref.getCell(0).getNumericCellValue(), 0.0);
     }
+    
+    @Test
+    public void createRowBeforeFirstRow() {
+        final Workbook workbook = _testDataProvider.createWorkbook();
+        final Sheet sh = workbook.createSheet();
+        sh.createRow(0);
+        try {
+            sh.createRow(-1);
+            fail("Negative rows not allowed");
+        } catch (final IllegalArgumentException e) {
+            // expected
+        }
+    }
+    
+    protected void createRowAfterLastRow(SpreadsheetVersion version) {
+        final Workbook workbook = _testDataProvider.createWorkbook();
+        final Sheet sh = workbook.createSheet();
+        sh.createRow(version.getLastRowIndex());
+        try {
+            sh.createRow(version.getLastRowIndex() + 1);
+            fail("Row number must be between 0 and " + version.getLastColumnIndex());
+        } catch (final IllegalArgumentException e) {
+            // expected
+        }
+    }
 
 
     @Test