{ "three trailing spaces ", "*s2" }, { "one", "*t", "tab" }, { "two", "*t", "*t", "tabs" },
{ "*t", "leading tab" }, { "trailing tab", "*t" },
{ "mixed ", "*s2", "*t", " ", "*s2", "spaces and tabs" }, { "line", "*n", "break" } };
try {
// test append paragraph
TextDocument doc = TextDocument.newTextDocument();
Table table = Table.newTable(doc, 2, 2);
Cell cell = table.getCellByPosition(0, 0);
for (int i = 0; i < plainText.length; i++) {
Paragraph para = cell.addParagraph(plainText[i]);
compareResults(para.getOdfElement(), plainText[i], elementResult[i]);
}
// test set paragraph content
cell = table.getCellByPosition(0, 1);
for (int i = 0; i < plainText.length; i++) {
Paragraph para = cell.addParagraph(plainText[i]);
compareResults(para.getOdfElement(), plainText[i], elementResult[i]);
String content = para.getTextContent();
Assert.assertEquals(plainText[i], content);
}
// test remove paragraph content
cell = table.getCellByPosition(1, 0);
for (int i = 0; i < plainText.length; i++) {
Paragraph para = cell.addParagraph(plainText[i]);
String content = para.getTextContent();
Assert.assertEquals(plainText[i], content);
para.removeTextContent();
content = para.getTextContent();
Assert.assertEquals("", content);
}
// test get paragraph by index
cell = table.getCellByPosition(1, 1);
Paragraph paragraph1 = cell.addParagraph("paragraph1");
Paragraph paragraphE = cell.addParagraph(null);
Paragraph paragraph2 = cell.addParagraph("p2");
Paragraph t1 = cell.getParagraphByIndex(0, false);
Assert.assertEquals(t1, paragraph1);
t1 = cell.getParagraphByIndex(2, false);
Assert.assertEquals(t1, paragraph2);
t1 = cell.getParagraphByIndex(1, true);
Assert.assertEquals(t1, paragraph2);
t1 = cell.getParagraphByReverseIndex(0, false);
Assert.assertEquals(t1, paragraph2);
t1 = cell.getParagraphByReverseIndex(2, false);
Assert.assertEquals(t1, paragraph1);
t1 = cell.getParagraphByReverseIndex(1, true);
Assert.assertEquals(t1, paragraph1);
doc.save(ResourceUtilities.newTestOutputFile("testCellParagraph.odt"));
} catch (Exception e) {
Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, null, e);
Assert.fail(e.getMessage());
}
}