]> source.dussan.org Git - poi.git/commitdiff
Add a unit test for bug #50833
authorNick Burch <nick@apache.org>
Fri, 4 Mar 2011 21:09:02 +0000 (21:09 +0000)
committerNick Burch <nick@apache.org>
Fri, 4 Mar 2011 21:09:02 +0000 (21:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1078135 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/50833.xls [new file with mode: 0644]

index ae54b4aaac1396a8961dd6905614372d16f57a58..2725528e86bf0d132fc7639b7df0612c7e523fd3 100644 (file)
@@ -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 (file)
index 0000000..0022778
Binary files /dev/null and b/test-data/spreadsheet/50833.xls differ