diff options
Diffstat (limited to 'src/ooxml/testcases/org')
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java | 14 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java | 121 |
2 files changed, 108 insertions, 27 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java index 0f625fbd90..c9d12bddce 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java @@ -17,21 +17,26 @@ package org.apache.poi.xwpf.usermodel; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; -import junit.framework.TestCase; import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.junit.Ignore; +import org.junit.Test; -public final class TestXWPFSDT extends TestCase { +public final class TestXWPFSDT { /** * Test simple tag and title extraction from SDT * * @throws Exception */ + @Test public void testTagTitle() throws Exception { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx"); String tag = null; @@ -51,7 +56,7 @@ public final class TestXWPFSDT extends TestCase { assertEquals("title", "MyTitle", title); } - + @Test public void testGetSDTs() throws Exception { String[] contents = new String[]{ "header_rich_text", @@ -83,6 +88,7 @@ public final class TestXWPFSDT extends TestCase { /** * POI-54771 and TIKA-1317 */ + @Test public void testSDTAsCell() throws Exception { //Bug54771a.docx and Bug54771b.docx test slightly //different recursion patterns. Keep both! @@ -110,6 +116,7 @@ public final class TestXWPFSDT extends TestCase { /** * POI-55142 and Tika 1130 */ + @Test public void testNewLinesBetweenRuns() throws Exception { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug55142.docx"); List<AbstractXWPFSDT> sdts = extractAllSDTs(doc); @@ -132,6 +139,7 @@ public final class TestXWPFSDT extends TestCase { } } + @Ignore public void test60341() throws IOException { //handle sdtbody without an sdtpr XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug60341.docx"); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java index b22f1a0cb7..57ed435320 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java @@ -17,51 +17,124 @@ package org.apache.poi.xwpf.usermodel; -import junit.framework.TestCase; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; -public class TestXWPFTableRow extends TestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - } +import java.io.IOException; - public void testCreateRow() throws Exception { - CTRow ctRow = CTRow.Factory.newInstance(); - assertNotNull(ctRow); - } +import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.junit.Test; - @Override - protected void tearDown() throws Exception { - super.tearDown(); +public class TestXWPFTableRow { + + @Test + public void testCreateRow() throws IOException { + XWPFDocument doc = new XWPFDocument(); + XWPFTable table = doc.createTable(1, 1); + XWPFTableRow tr = table.createRow(); + assertNotNull(tr); + doc.close(); } - public void testSetGetCantSplitRow() { + @Test + public void testSetGetCantSplitRow() throws IOException { // create a table XWPFDocument doc = new XWPFDocument(); - CTTbl ctTable = CTTbl.Factory.newInstance(); - XWPFTable table = new XWPFTable(ctTable, doc); + XWPFTable table = doc.createTable(1, 1); // table has a single row by default; grab it XWPFTableRow tr = table.getRow(0); assertNotNull(tr); + // Assert the repeat header is false by default + boolean isCantSplit = tr.isCantSplitRow(); + assertFalse(isCantSplit); + + // Repeat the header tr.setCantSplitRow(true); - boolean isCant = tr.isCantSplitRow(); - assert (isCant); + isCantSplit = tr.isCantSplitRow(); + assertTrue(isCantSplit); + + // Make the header no longer repeating + tr.setCantSplitRow(false); + isCantSplit = tr.isCantSplitRow(); + assertFalse(isCantSplit); + + doc.close(); } - public void testSetGetRepeatHeader() { + @Test + public void testSetGetRepeatHeader() throws IOException { // create a table XWPFDocument doc = new XWPFDocument(); - CTTbl ctTable = CTTbl.Factory.newInstance(); - XWPFTable table = new XWPFTable(ctTable, doc); + XWPFTable table = doc.createTable(3, 1); // table has a single row by default; grab it XWPFTableRow tr = table.getRow(0); assertNotNull(tr); + + // Assert the repeat header is false by default + boolean isRpt = tr.isRepeatHeader(); + assertFalse(isRpt); + + // Repeat the header + tr.setRepeatHeader(true); + isRpt = tr.isRepeatHeader(); + assertTrue(isRpt); + // Make the header no longer repeating + tr.setRepeatHeader(false); + isRpt = tr.isRepeatHeader(); + assertFalse(isRpt); + + // If the third row is set to repeat, but not the second, + // isRepeatHeader should report false because Word will + // ignore it. + tr = table.getRow(2); tr.setRepeatHeader(true); + isRpt = tr.isRepeatHeader(); + assertFalse(isRpt); + + doc.close(); + } + + // Test that validates the table header value can be parsed from a document + // generated in Word + @Test + public void testIsRepeatHeader() throws Exception { + XWPFDocument doc = XWPFTestDataSamples + .openSampleDocument("Bug60337.docx"); + XWPFTable table = doc.getTables().get(0); + XWPFTableRow tr = table.getRow(0); boolean isRpt = tr.isRepeatHeader(); - assert (isRpt); + assertTrue(isRpt); + + tr = table.getRow(1); + isRpt = tr.isRepeatHeader(); + assertFalse(isRpt); + + tr = table.getRow(2); + isRpt = tr.isRepeatHeader(); + assertFalse(isRpt); + } + + + // Test that validates the table header value can be parsed from a document + // generated in Word + @Test + public void testIsCantSplit() throws Exception { + XWPFDocument doc = XWPFTestDataSamples + .openSampleDocument("Bug60337.docx"); + XWPFTable table = doc.getTables().get(0); + XWPFTableRow tr = table.getRow(0); + boolean isCantSplit = tr.isCantSplitRow(); + assertFalse(isCantSplit); + + tr = table.getRow(1); + isCantSplit = tr.isCantSplitRow(); + assertFalse(isCantSplit); + + tr = table.getRow(2); + isCantSplit = tr.isCantSplitRow(); + assertTrue(isCantSplit); } } |