From: Nick Burch Date: Fri, 4 Mar 2011 21:09:02 +0000 (+0000) Subject: Add a unit test for bug #50833 X-Git-Tag: REL_3_8_BETA2~35 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5805f3b66001219a382427f995b323fcba40d700;p=poi.git Add a unit test for bug #50833 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1078135 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index ae54b4aaac..2725528e86 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -22,7 +22,10 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; import junit.framework.AssertionFailedError; @@ -43,7 +46,6 @@ import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.DataFormatter; import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; @@ -1983,4 +1985,38 @@ if(1==2) { assertEquals("35", df.formatCellValue(r18.getCell(2))); assertEquals("123", df.formatCellValue(r18.getCell(3))); } + + /** + * A protected sheet with comments, when written out by + * POI, ends up upsetting excel. + * TODO Identify the cause and add extra asserts for + * the bit excel cares about + */ + public void test50833() throws Exception { + HSSFWorkbook wb = openSample("50833.xls"); + HSSFSheet s = wb.getSheetAt(0); + assertEquals("Sheet1", s.getSheetName()); + assertEquals(false, s.getProtect()); + + HSSFCell c = s.getRow(0).getCell(0); + assertEquals("test cell value", c.getRichStringCellValue().getString()); + + HSSFComment cmt = c.getCellComment(); + assertNotNull(cmt); + assertEquals("Robert Lawrence", cmt.getAuthor()); + assertEquals("Robert Lawrence:\ntest comment", cmt.getString().getString()); + + // Reload + wb = writeOutAndReadBack(wb); + s = wb.getSheetAt(0); + c = s.getRow(0).getCell(0); + + // Re-check the comment + cmt = c.getCellComment(); + assertNotNull(cmt); + assertEquals("Robert Lawrence", cmt.getAuthor()); + assertEquals("Robert Lawrence:\ntest comment", cmt.getString().getString()); + + // TODO Identify what excel doesn't like, and check for that + } } diff --git a/test-data/spreadsheet/50833.xls b/test-data/spreadsheet/50833.xls new file mode 100644 index 0000000000..00227789e7 Binary files /dev/null and b/test-data/spreadsheet/50833.xls differ