summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2011-05-06 07:58:35 +0000
committerNick Burch <nick@apache.org>2011-05-06 07:58:35 +0000
commit888645dd3f8c50579d47dd9d7bb174b10c38cff8 (patch)
tree7559d6f5410a75990bdfed4954c6b23e6895fc2d
parent700e7fd5e2e6f163a596f373f13144f1f4cf4f3a (diff)
downloadpoi-888645dd3f8c50579d47dd9d7bb174b10c38cff8.tar.gz
poi-888645dd3f8c50579d47dd9d7bb174b10c38cff8.zip
More testing around bug #48877
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1100122 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
index 56e8cc0867..fca1643653 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
@@ -37,7 +37,6 @@ import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Name;
-import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@@ -804,22 +803,26 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
String text = "Use \n with word wrap on to create a new line.\n" +
"This line finishes with two trailing spaces. ";
- Workbook wb = new XSSFWorkbook();
- Sheet sheet = wb.createSheet();
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
Font font1 = wb.createFont();
font1.setColor((short) 20);
+ Font font2 = wb.createFont();
+ font2.setColor(Font.COLOR_RED);
+ Font font3 = wb.getFontAt((short)0);
- Row row = sheet.createRow(2);
- Cell cell = row.createCell(2);
+ XSSFRow row = sheet.createRow(2);
+ XSSFCell cell = row.createCell(2);
- RichTextString richTextString =
+ XSSFRichTextString richTextString =
wb.getCreationHelper().createRichTextString(text);
// Check the text has the newline
assertEquals(text, richTextString.getString());
// Apply the font
+ richTextString.applyFont(font3);
richTextString.applyFont(0, 3, font1);
cell.setCellValue(richTextString);
@@ -837,6 +840,28 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
row = sheet.getRow(2);
cell = row.getCell(2);
assertEquals(text, cell.getStringCellValue());
+
+ // Now add a 2nd, and check again
+ int fontAt = text.indexOf("\n", 6);
+ cell.getRichStringCellValue().applyFont(10, fontAt+1, font2);
+ assertEquals(text, cell.getStringCellValue());
+
+ assertEquals(4, cell.getRichStringCellValue().numFormattingRuns());
+ assertEquals("Use", cell.getRichStringCellValue().getCTRst().getRList().get(0).getT());
+
+ String r3 = cell.getRichStringCellValue().getCTRst().getRList().get(2).getT();
+ assertEquals("line.\n", r3.substring(r3.length()-6));
+
+ // Save and re-check
+ wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
+ sheet = wb.getSheetAt(0);
+ row = sheet.getRow(2);
+ cell = row.getCell(2);
+ assertEquals(text, cell.getStringCellValue());
+
+// FileOutputStream out = new FileOutputStream("/tmp/test48877.xlsx");
+// wb.write(out);
+// out.close();
}
/**