From b45b8f99f8bcd92bbeeea14ff83bae3a4ab2ae22 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 10 Jul 2008 22:43:01 +0000 Subject: [PATCH] Add a test to show that the behaviour around bug #30635 is exactly as you would expect, and the bug report is invalid git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@675793 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/usermodel/TestBugs.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index fde53ba6a..643dfb3b5 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -1272,4 +1272,53 @@ public final class TestBugs extends TestCase { assertEquals("{=sin(B1:B9){9,1)[1][0]", nc2.getCellFormula()); assertEquals("{=sin(B1:B9){9,1)[2][0]", nc3.getCellFormula()); } + + /** + * People are all getting confused about the last + * row and cell number + */ + public void test30635() throws Exception { + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet s = wb.createSheet(); + + // No rows, everything is 0 + assertEquals(0, s.getFirstRowNum()); + assertEquals(0, s.getLastRowNum()); + assertEquals(0, s.getPhysicalNumberOfRows()); + + // One row, most things are 0, physical is 1 + s.createRow(0); + assertEquals(0, s.getFirstRowNum()); + assertEquals(0, s.getLastRowNum()); + assertEquals(1, s.getPhysicalNumberOfRows()); + + // And another, things change + s.createRow(4); + assertEquals(0, s.getFirstRowNum()); + assertEquals(4, s.getLastRowNum()); + assertEquals(2, s.getPhysicalNumberOfRows()); + + + // Now start on cells + HSSFRow r = s.getRow(0); + assertEquals(-1, r.getFirstCellNum()); + assertEquals(-1, r.getLastCellNum()); + assertEquals(0, r.getPhysicalNumberOfCells()); + + // Add a cell, things move off -1 + r.createCell((short)0); + assertEquals(0, r.getFirstCellNum()); + assertEquals(1, r.getLastCellNum()); // last cell # + 1 + assertEquals(1, r.getPhysicalNumberOfCells()); + + r.createCell((short)1); + assertEquals(0, r.getFirstCellNum()); + assertEquals(2, r.getLastCellNum()); // last cell # + 1 + assertEquals(2, r.getPhysicalNumberOfCells()); + + r.createCell((short)4); + assertEquals(0, r.getFirstCellNum()); + assertEquals(5, r.getLastCellNum()); // last cell # + 1 + assertEquals(3, r.getPhysicalNumberOfCells()); + } }