]> source.dussan.org Git - poi.git/commitdiff
added test case for reported bug 44987
authorJosh Micich <josh@apache.org>
Tue, 13 May 2008 15:25:51 +0000 (15:25 +0000)
committerJosh Micich <josh@apache.org>
Tue, 13 May 2008 15:25:51 +0000 (15:25 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@655912 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java

index f0c4139d2ed664d438d7686a4cfb1f383d2e7b0b..7611abb51ce8bc3e8ec0f93449af87e0fb715a17 100644 (file)
 
 package org.apache.poi.hssf.usermodel;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
+
 /**
  * Test HSSFRow is okay.
  *
@@ -32,7 +31,7 @@ public final class TestHSSFRow extends TestCase {
     public void testLastAndFirstColumns() {
         HSSFWorkbook workbook = new HSSFWorkbook();
         HSSFSheet sheet = workbook.createSheet();
-        HSSFRow row = sheet.createRow((short) 0);
+        HSSFRow row = sheet.createRow(0);
         assertEquals(-1, row.getFirstCellNum());
         assertEquals(-1, row.getLastCellNum());
 
@@ -50,7 +49,35 @@ public final class TestHSSFRow extends TestCase {
         assertEquals(4, row.getLastCellNum());
     }
 
-    public void testRemoveCell() throws Exception {
+    /**
+     * Make sure that there is no cross-talk between rows especially with getFirstCellNum and getLastCellNum
+     * This test was added in response to bug report 44987.
+     */
+    public void testBoundsInMultipleRows() {
+        HSSFWorkbook workbook = new HSSFWorkbook();
+        HSSFSheet sheet = workbook.createSheet();
+        HSSFRow rowA = sheet.createRow(0);
+
+        rowA.createCell((short) 10);
+        rowA.createCell((short) 5);
+        assertEquals(5, rowA.getFirstCellNum());
+        assertEquals(11, rowA.getLastCellNum());
+
+        HSSFRow rowB = sheet.createRow(1);
+        rowB.createCell((short) 15);
+        rowB.createCell((short) 30);
+        assertEquals(15, rowB.getFirstCellNum());
+        assertEquals(31, rowB.getLastCellNum());
+
+        assertEquals(5, rowA.getFirstCellNum());
+        assertEquals(11, rowA.getLastCellNum());
+        rowA.createCell((short) 50);
+        assertEquals(51, rowA.getLastCellNum());
+
+        assertEquals(31, rowB.getLastCellNum());
+    }
+
+    public void testRemoveCell() {
         HSSFWorkbook workbook = new HSSFWorkbook();
         HSSFSheet sheet = workbook.createSheet();
         HSSFRow row = sheet.createRow((short) 0);
@@ -76,16 +103,11 @@ public final class TestHSSFRow extends TestCase {
         assertEquals(0, data[6]);
         assertEquals(0, data[8]);
 
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        workbook.write(baos);
-        baos.close();
-        ByteArrayInputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
-        workbook = new HSSFWorkbook(inputStream);
+        workbook = HSSFTestDataSamples.writeOutAndReadBack(workbook);
         sheet = workbook.getSheetAt(0);
-        inputStream.close();
 
-        assertEquals(-1, sheet.getRow((short) 0).getLastCellNum());
-        assertEquals(-1, sheet.getRow((short) 0).getFirstCellNum());
+        assertEquals(-1, sheet.getRow(0).getLastCellNum());
+        assertEquals(-1, sheet.getRow(0).getFirstCellNum());
     }
 
     public void testMoveCell() {