diff options
author | Josh Micich <josh@apache.org> | 2009-02-05 07:39:57 +0000 |
---|---|---|
committer | Josh Micich <josh@apache.org> | 2009-02-05 07:39:57 +0000 |
commit | 8a2b5147e325171f855b264747d3d087f46d749b (patch) | |
tree | 6fd5055b8366cef8f34fe0854f8525741692c100 /src/testcases | |
parent | da884af7df68a2da8b9ec8f3dd6ee960870e9e45 (diff) | |
download | poi-8a2b5147e325171f855b264747d3d087f46d749b.tar.gz poi-8a2b5147e325171f855b264747d3d087f46d749b.zip |
Fix for bug 46654 - HSSFRow/RowRecord needs to properly update cell boundary indexes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@741036 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java | 32 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java | 50 |
2 files changed, 58 insertions, 24 deletions
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java index 9525a181a1..7014cb5149 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFComment.java @@ -16,9 +16,11 @@ ==================================================================== */ package org.apache.poi.hssf.usermodel; -import junit.framework.TestCase; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; -import java.io.*; +import junit.framework.TestCase; import org.apache.poi.hssf.HSSFTestDataSamples; @@ -37,7 +39,7 @@ public final class TestHSSFComment extends TestCase { String commentText = "We can set comments in POI"; String commentAuthor = "Apache Software Foundation"; int cellRow = 3; - short cellColumn = 1; + int cellColumn = 1; HSSFWorkbook wb = new HSSFWorkbook(); @@ -55,6 +57,10 @@ public final class TestHSSFComment extends TestCase { comment.setString(string1); comment.setAuthor(commentAuthor); cell.setCellComment(comment); + if (false) { + // TODO - the following line should break this test, but it doesn't + cell.removeCellComment(); + } //verify our settings assertEquals(HSSFSimpleShape.OBJECT_TYPE_COMMENT, comment.getShapeType()); @@ -79,11 +85,11 @@ public final class TestHSSFComment extends TestCase { assertEquals(commentText, comment.getString().getString()); assertEquals(cellRow, comment.getRow()); assertEquals(cellColumn, comment.getColumn()); - - + + // Change slightly, and re-test comment.setString(new HSSFRichTextString("New Comment Text")); - + out = new ByteArrayOutputStream(); wb.write(out); out.close(); @@ -131,7 +137,7 @@ public final class TestHSSFComment extends TestCase { assertEquals(HSSFSimpleShape.OBJECT_TYPE_COMMENT, comment.getShapeType()); assertEquals("Yegor Kozlov", comment.getAuthor()); - assertFalse("cells in the second column have not empyy notes", + assertFalse("cells in the second column have not empyy notes", "".equals(comment.getString().getString())); assertEquals(rownum, comment.getRow()); assertEquals(cell.getColumnIndex(), comment.getColumn()); @@ -176,24 +182,24 @@ public final class TestHSSFComment extends TestCase { } } - + public void testDeleteComments() throws Exception { HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("SimpleWithComments.xls"); HSSFSheet sheet = wb.getSheetAt(0); - + // Zap from rows 1 and 3 assertNotNull(sheet.getRow(0).getCell(1).getCellComment()); assertNotNull(sheet.getRow(1).getCell(1).getCellComment()); assertNotNull(sheet.getRow(2).getCell(1).getCellComment()); - + sheet.getRow(0).getCell(1).removeCellComment(); sheet.getRow(2).getCell(1).setCellComment(null); - + // Check gone so far assertNull(sheet.getRow(0).getCell(1).getCellComment()); assertNotNull(sheet.getRow(1).getCell(1).getCellComment()); assertNull(sheet.getRow(2).getCell(1).getCellComment()); - + // Save and re-load ByteArrayOutputStream out = new ByteArrayOutputStream(); wb.write(out); @@ -204,7 +210,7 @@ public final class TestHSSFComment extends TestCase { assertNull(sheet.getRow(0).getCell(1).getCellComment()); assertNotNull(sheet.getRow(1).getCell(1).getCellComment()); assertNull(sheet.getRow(2).getCell(1).getCellComment()); - + // FileOutputStream fout = new FileOutputStream("/tmp/c.xls"); // wb.write(fout); // fout.close(); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java index 8e7864fad2..444eef108e 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFRow.java @@ -17,9 +17,12 @@ package org.apache.poi.hssf.usermodel; +import junit.framework.AssertionFailedError; import junit.framework.TestCase; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.hssf.record.BlankRecord; +import org.apache.poi.hssf.record.RowRecord; /** * Test HSSFRow is okay. @@ -48,6 +51,32 @@ public final class TestHSSFRow extends TestCase { assertEquals(1, row.getFirstCellNum()); assertEquals(4, row.getLastCellNum()); } + public void testLastAndFirstColumns_bug46654() { + int ROW_IX = 10; + int COL_IX = 3; + HSSFWorkbook workbook = new HSSFWorkbook(); + HSSFSheet sheet = workbook.createSheet("Sheet1"); + RowRecord rowRec = new RowRecord(ROW_IX); + rowRec.setFirstCol((short)2); + rowRec.setLastCol((short)5); + + BlankRecord br = new BlankRecord(); + br.setRow(ROW_IX); + br.setColumn((short)COL_IX); + + sheet.getSheet().addValueRecord(ROW_IX, br); + HSSFRow row = new HSSFRow(workbook, sheet, rowRec); + HSSFCell cell = row.createCellFromRecord(br); + + if (row.getFirstCellNum() == 2 && row.getLastCellNum() == 5) { + throw new AssertionFailedError("Identified bug 46654a"); + } + assertEquals(COL_IX, row.getFirstCellNum()); + assertEquals(COL_IX + 1, row.getLastCellNum()); + row.removeCell(cell); + assertEquals(-1, row.getFirstCellNum()); + assertEquals(-1, row.getLastCellNum()); + } /** * Make sure that there is no cross-talk between rows especially with getFirstCellNum and getLastCellNum @@ -204,11 +233,11 @@ public final class TestHSSFRow extends TestCase { row.createCell(255); assertEquals(256, row.getLastCellNum()); } - + /** * Tests for the missing/blank cell policy stuff */ - public void testGetCellPolicy() throws Exception { + public void testGetCellPolicy() { HSSFWorkbook book = new HSSFWorkbook(); HSSFSheet sheet = book.createSheet("test"); HSSFRow row = sheet.createRow(0); @@ -223,7 +252,7 @@ public final class TestHSSFRow extends TestCase { row.createCell(1).setCellValue(3.2); row.createCell(4, HSSFCell.CELL_TYPE_BLANK); row.createCell(5).setCellValue(4); - + // First up, no policy given, uses default assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0).getCellType()); assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType()); @@ -231,7 +260,7 @@ public final class TestHSSFRow extends TestCase { assertEquals(null, row.getCell(3)); assertEquals(HSSFCell.CELL_TYPE_BLANK, row.getCell(4).getCellType()); assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5).getCellType()); - + // RETURN_NULL_AND_BLANK - same as default assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0, HSSFRow.RETURN_NULL_AND_BLANK).getCellType()); assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1, HSSFRow.RETURN_NULL_AND_BLANK).getCellType()); @@ -239,7 +268,7 @@ public final class TestHSSFRow extends TestCase { assertEquals(null, row.getCell(3, HSSFRow.RETURN_NULL_AND_BLANK)); assertEquals(HSSFCell.CELL_TYPE_BLANK, row.getCell(4, HSSFRow.RETURN_NULL_AND_BLANK).getCellType()); assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5, HSSFRow.RETURN_NULL_AND_BLANK).getCellType()); - + // RETURN_BLANK_AS_NULL - nearly the same assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0, HSSFRow.RETURN_BLANK_AS_NULL).getCellType()); assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1, HSSFRow.RETURN_BLANK_AS_NULL).getCellType()); @@ -247,7 +276,7 @@ public final class TestHSSFRow extends TestCase { assertEquals(null, row.getCell(3, HSSFRow.RETURN_BLANK_AS_NULL)); assertEquals(null, row.getCell(4, HSSFRow.RETURN_BLANK_AS_NULL)); assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5, HSSFRow.RETURN_BLANK_AS_NULL).getCellType()); - + // CREATE_NULL_AS_BLANK - creates as needed assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0, HSSFRow.CREATE_NULL_AS_BLANK).getCellType()); assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1, HSSFRow.CREATE_NULL_AS_BLANK).getCellType()); @@ -255,7 +284,7 @@ public final class TestHSSFRow extends TestCase { assertEquals(HSSFCell.CELL_TYPE_BLANK, row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getCellType()); assertEquals(HSSFCell.CELL_TYPE_BLANK, row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getCellType()); assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getCellType()); - + // Check created ones get the right column assertEquals(0, row.getCell(0, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex()); assertEquals(1, row.getCell(1, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex()); @@ -263,12 +292,12 @@ public final class TestHSSFRow extends TestCase { assertEquals(3, row.getCell(3, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex()); assertEquals(4, row.getCell(4, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex()); assertEquals(5, row.getCell(5, HSSFRow.CREATE_NULL_AS_BLANK).getColumnIndex()); - - + + // Now change the cell policy on the workbook, check // that that is now used if no policy given book.setMissingCellPolicy(HSSFRow.RETURN_BLANK_AS_NULL); - + assertEquals(HSSFCell.CELL_TYPE_STRING, row.getCell(0).getCellType()); assertEquals(HSSFCell.CELL_TYPE_NUMERIC, row.getCell(1).getCellType()); assertEquals(null, row.getCell(2)); @@ -300,5 +329,4 @@ public final class TestHSSFRow extends TestCase { row2 = sheet.getRow(1); assertEquals(400, row2.getHeight()); } - } |