From d9697de075e6ff1554455fc8c5d62b3ab22a02ba Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 13 Aug 2015 19:20:58 +0000 Subject: [PATCH] Fix inconsistent line endings and some eclipse warnings git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1695757 13f79535-47bb-0310-9956-ffa450edef68 --- .../xwpf/usermodel/TestChangeTracking.java | 139 +++--- .../poi/xwpf/usermodel/TestXWPFBugs.java | 208 ++++---- .../poi/xwpf/usermodel/TestXWPFFootnotes.java | 94 ++-- .../poi/xwpf/usermodel/TestXWPFHeader.java | 40 +- .../poi/xwpf/usermodel/TestXWPFHeadings.java | 64 +-- .../poi/xwpf/usermodel/TestXWPFNumbering.java | 164 +++--- .../xwpf/usermodel/TestXWPFPictureData.java | 218 ++++---- .../poi/xwpf/usermodel/TestXWPFRun.java | 470 +++++++++--------- .../poi/xwpf/usermodel/TestXWPFSDT.java | 292 +++++------ .../poi/xwpf/usermodel/TestXWPFSmartTag.java | 76 +-- .../poi/xwpf/usermodel/TestXWPFStyles.java | 279 +++++------ .../poi/xwpf/usermodel/TestXWPFTable.java | 169 ++++--- .../poi/xwpf/usermodel/TestXWPFTableCell.java | 133 ++--- .../poi/xwpf/usermodel/TestXWPFTableRow.java | 101 ++-- 14 files changed, 1219 insertions(+), 1228 deletions(-) diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java index 0a309a8306..47ec765245 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestChangeTracking.java @@ -1,71 +1,68 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ -package org.apache.poi.xwpf.usermodel; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; - -import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.junit.Test; - -public class TestChangeTracking { - - @Test - public void detection() throws Exception { - - XWPFDocument documentWithoutChangeTracking = XWPFTestDataSamples.openSampleDocument("bug56075-changeTracking_off.docx"); - assertFalse(documentWithoutChangeTracking.isTrackRevisions()); - - XWPFDocument documentWithChangeTracking = XWPFTestDataSamples.openSampleDocument("bug56075-changeTracking_on.docx"); - assertTrue(documentWithChangeTracking.isTrackRevisions()); - - } - - @Test - public void activateChangeTracking() throws Exception { - XWPFDocument document = XWPFTestDataSamples.openSampleDocument("bug56075-changeTracking_off.docx"); - assertFalse(document.isTrackRevisions()); - - document.setTrackRevisions(true); - - assertTrue(document.isTrackRevisions()); - } - - @Test - public void integration() throws Exception { - XWPFDocument doc = new XWPFDocument(); - - XWPFParagraph p1 = doc.createParagraph(); - - XWPFRun r1 = p1.createRun(); - r1.setText("Lorem ipsum dolor sit amet."); - doc.setTrackRevisions(true); - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - doc.write(out); - - ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray()); - XWPFDocument document = new XWPFDocument(inputStream); - inputStream.close(); - - assertTrue(document.isTrackRevisions()); - } - -} +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.xwpf.usermodel; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.junit.Test; + +public class TestChangeTracking { + @Test + public void detection() throws Exception { + XWPFDocument documentWithoutChangeTracking = XWPFTestDataSamples.openSampleDocument("bug56075-changeTracking_off.docx"); + assertFalse(documentWithoutChangeTracking.isTrackRevisions()); + + XWPFDocument documentWithChangeTracking = XWPFTestDataSamples.openSampleDocument("bug56075-changeTracking_on.docx"); + assertTrue(documentWithChangeTracking.isTrackRevisions()); + } + + @Test + public void activateChangeTracking() throws Exception { + XWPFDocument document = XWPFTestDataSamples.openSampleDocument("bug56075-changeTracking_off.docx"); + assertFalse(document.isTrackRevisions()); + + document.setTrackRevisions(true); + + assertTrue(document.isTrackRevisions()); + } + + @Test + @SuppressWarnings("resource") + public void integration() throws Exception { + XWPFDocument doc = new XWPFDocument(); + + XWPFParagraph p1 = doc.createParagraph(); + + XWPFRun r1 = p1.createRun(); + r1.setText("Lorem ipsum dolor sit amet."); + doc.setTrackRevisions(true); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + doc.write(out); + + ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray()); + XWPFDocument document = new XWPFDocument(inputStream); + inputStream.close(); + + assertTrue(document.isTrackRevisions()); + } +} diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java index 78df19c009..cc7b7c0650 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java @@ -1,104 +1,104 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ -package org.apache.poi.xwpf.usermodel; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; - -import org.apache.poi.openxml4j.exceptions.OpenXML4JException; -import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.apache.poi.xwpf.usermodel.XWPFRun.FontCharRange; -import org.junit.Test; - -public class TestXWPFBugs { - @Test - public void bug55802() throws Exception { - String blabla = - "Bir, iki, \u00fc\u00e7, d\u00f6rt, be\u015f,\n" + - "\nalt\u0131, yedi, sekiz, dokuz, on.\n" + - "\nK\u0131rm\u0131z\u0131 don,\n" + - "\ngel bizim bah\u00e7eye kon,\n" + - "\nsar\u0131 limon"; - XWPFDocument doc = new XWPFDocument(); - XWPFRun run = doc.createParagraph().createRun(); - - for (String str : blabla.split("\n")) { - run.setText(str); - run.addBreak(); - } - - run.setFontFamily("Times New Roman"); - run.setFontSize(20); - assertEquals(run.getFontFamily(), "Times New Roman"); - assertEquals(run.getFontFamily(FontCharRange.cs), "Times New Roman"); - assertEquals(run.getFontFamily(FontCharRange.eastAsia), "Times New Roman"); - assertEquals(run.getFontFamily(FontCharRange.hAnsi), "Times New Roman"); - run.setFontFamily("Arial", FontCharRange.hAnsi); - assertEquals(run.getFontFamily(FontCharRange.hAnsi), "Arial"); - } - - - @Test - public void bug57312_NullPointException() throws IOException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("57312.docx"); - assertNotNull(doc); - - for (IBodyElement bodyElement : doc.getBodyElements()) { - BodyElementType elementType = bodyElement.getElementType(); - - if (elementType == BodyElementType.PARAGRAPH) { - XWPFParagraph paragraph = (XWPFParagraph) bodyElement; - - for (IRunElement iRunElem : paragraph.getIRuns()) { - - if (iRunElem instanceof XWPFRun) { - XWPFRun runElement = (XWPFRun) iRunElem; - - UnderlinePatterns underline = runElement.getUnderline(); - assertNotNull(underline); - - //System.out.println("Found: " + underline + ": " + runElement.getText(0)); - } - } - } - } - } - - - @Test - public void test56392() throws IOException, OpenXML4JException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("56392.docx"); - assertNotNull(doc); - } - - /** - * Removing a run needs to remove it from both Runs and IRuns - */ - @Test - public void test57829() throws Exception { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); - assertNotNull(doc); - assertEquals(3, doc.getParagraphs().size()); - - for (XWPFParagraph paragraph : doc.getParagraphs()) { - paragraph.removeRun(0); - assertNotNull(paragraph.getText()); - } - } -} +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.xwpf.usermodel; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import org.apache.poi.openxml4j.exceptions.OpenXML4JException; +import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.apache.poi.xwpf.usermodel.XWPFRun.FontCharRange; +import org.junit.Test; + +public class TestXWPFBugs { + @Test + public void bug55802() throws Exception { + String blabla = + "Bir, iki, \u00fc\u00e7, d\u00f6rt, be\u015f,\n" + + "\nalt\u0131, yedi, sekiz, dokuz, on.\n" + + "\nK\u0131rm\u0131z\u0131 don,\n" + + "\ngel bizim bah\u00e7eye kon,\n" + + "\nsar\u0131 limon"; + XWPFDocument doc = new XWPFDocument(); + XWPFRun run = doc.createParagraph().createRun(); + + for (String str : blabla.split("\n")) { + run.setText(str); + run.addBreak(); + } + + run.setFontFamily("Times New Roman"); + run.setFontSize(20); + assertEquals(run.getFontFamily(), "Times New Roman"); + assertEquals(run.getFontFamily(FontCharRange.cs), "Times New Roman"); + assertEquals(run.getFontFamily(FontCharRange.eastAsia), "Times New Roman"); + assertEquals(run.getFontFamily(FontCharRange.hAnsi), "Times New Roman"); + run.setFontFamily("Arial", FontCharRange.hAnsi); + assertEquals(run.getFontFamily(FontCharRange.hAnsi), "Arial"); + } + + + @Test + public void bug57312_NullPointException() throws IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("57312.docx"); + assertNotNull(doc); + + for (IBodyElement bodyElement : doc.getBodyElements()) { + BodyElementType elementType = bodyElement.getElementType(); + + if (elementType == BodyElementType.PARAGRAPH) { + XWPFParagraph paragraph = (XWPFParagraph) bodyElement; + + for (IRunElement iRunElem : paragraph.getIRuns()) { + + if (iRunElem instanceof XWPFRun) { + XWPFRun runElement = (XWPFRun) iRunElem; + + UnderlinePatterns underline = runElement.getUnderline(); + assertNotNull(underline); + + //System.out.println("Found: " + underline + ": " + runElement.getText(0)); + } + } + } + } + } + + + @Test + public void test56392() throws IOException, OpenXML4JException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("56392.docx"); + assertNotNull(doc); + } + + /** + * Removing a run needs to remove it from both Runs and IRuns + */ + @Test + public void test57829() throws Exception { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); + assertNotNull(doc); + assertEquals(3, doc.getParagraphs().size()); + + for (XWPFParagraph paragraph : doc.getParagraphs()) { + paragraph.removeRun(0); + assertNotNull(paragraph.getText()); + } + } +} diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java index 0915de0fef..7025a266c7 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java @@ -19,50 +19,50 @@ package org.apache.poi.xwpf.usermodel; import java.io.IOException; import java.math.BigInteger; -import java.util.List; - -import junit.framework.TestCase; -import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFtnEdn; - -public class TestXWPFFootnotes extends TestCase { - - public void testAddFootnotesToDocument() throws IOException { - XWPFDocument docOut = new XWPFDocument(); - - BigInteger noteId = BigInteger.valueOf(1); - - XWPFFootnotes footnotes = docOut.createFootnotes(); - CTFtnEdn ctNote = CTFtnEdn.Factory.newInstance(); - ctNote.setId(noteId); - ctNote.setType(STFtnEdn.NORMAL); - footnotes.addFootnote(ctNote); - - XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); - - XWPFFootnote note = docIn.getFootnoteByID(noteId.intValue()); - assertEquals(note.getCTFtnEdn().getType(), STFtnEdn.NORMAL); - } - - /** - * Bug 55066 - avoid double loading the footnotes - */ - public void testLoadFootnotesOnce() throws IOException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx"); - List footnotes = doc.getFootnotes(); - int hits = 0; - for (XWPFFootnote fn : footnotes) { - for (IBodyElement e : fn.getBodyElements()) { - if (e instanceof XWPFParagraph) { - String txt = ((XWPFParagraph) e).getText(); - if (txt.indexOf("Footnote_sdt") > -1) { - hits++; - } - } - } - } - assertEquals("Load footnotes once", 1, hits); - } -} - +import java.util.List; + +import junit.framework.TestCase; +import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFtnEdn; + +public class TestXWPFFootnotes extends TestCase { + + public void testAddFootnotesToDocument() throws IOException { + XWPFDocument docOut = new XWPFDocument(); + + BigInteger noteId = BigInteger.valueOf(1); + + XWPFFootnotes footnotes = docOut.createFootnotes(); + CTFtnEdn ctNote = CTFtnEdn.Factory.newInstance(); + ctNote.setId(noteId); + ctNote.setType(STFtnEdn.NORMAL); + footnotes.addFootnote(ctNote); + + XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); + + XWPFFootnote note = docIn.getFootnoteByID(noteId.intValue()); + assertEquals(note.getCTFtnEdn().getType(), STFtnEdn.NORMAL); + } + + /** + * Bug 55066 - avoid double loading the footnotes + */ + public void testLoadFootnotesOnce() throws IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx"); + List footnotes = doc.getFootnotes(); + int hits = 0; + for (XWPFFootnote fn : footnotes) { + for (IBodyElement e : fn.getBodyElements()) { + if (e instanceof XWPFParagraph) { + String txt = ((XWPFParagraph) e).getText(); + if (txt.indexOf("Footnote_sdt") > -1) { + hits++; + } + } + } + } + assertEquals("Load footnotes once", 1, hits); + } +} + diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java index 172c0eb16d..0efb679fac 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java @@ -17,12 +17,12 @@ package org.apache.poi.xwpf.usermodel; -import java.io.IOException; - -import junit.framework.TestCase; -import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; +import java.io.IOException; + +import junit.framework.TestCase; +import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; @@ -158,25 +158,25 @@ public final class TestXWPFHeader extends TestCase { assertEquals("First paragraph for the footer", paras[0].getText()); assertEquals("Second paragraph for the footer", paras[1].getText()); } - - public void testSetWatermark() throws IOException { - XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx"); - - // No header is set (yet) - XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy(); - assertNull(policy.getDefaultHeader()); + + public void testSetWatermark() throws IOException { + XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx"); + + // No header is set (yet) + XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy(); + assertNull(policy.getDefaultHeader()); assertNull(policy.getFirstPageHeader()); assertNull(policy.getDefaultFooter()); policy.createWatermark("DRAFT"); - assertNotNull(policy.getDefaultHeader()); - assertNotNull(policy.getFirstPageHeader()); - assertNotNull(policy.getEvenPageHeader()); - - // Re-open, and check - XWPFDocument reopened = XWPFTestDataSamples.writeOutAndReadBack(sampleDoc); - policy = reopened.getHeaderFooterPolicy(); + assertNotNull(policy.getDefaultHeader()); + assertNotNull(policy.getFirstPageHeader()); + assertNotNull(policy.getEvenPageHeader()); + + // Re-open, and check + XWPFDocument reopened = XWPFTestDataSamples.writeOutAndReadBack(sampleDoc); + policy = reopened.getHeaderFooterPolicy(); assertNotNull(policy.getDefaultHeader()); assertNotNull(policy.getFirstPageHeader()); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java index b084634829..ef7620eee7 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java @@ -16,38 +16,38 @@ ==================================================================== */ package org.apache.poi.xwpf.usermodel; -import java.io.IOException; - -import junit.framework.TestCase; -import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.apache.xmlbeans.XmlException; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock; - -/** - * @author Paolo Mottadelli - */ -public final class TestXWPFHeadings extends TestCase { - private static final String HEADING1 = "Heading1"; - - public void testSetParagraphStyle() throws IOException, XmlException { - //new clean instance of paragraph - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("heading123.docx"); - XWPFParagraph p = doc.createParagraph(); - XWPFRun run = p.createRun(); - run.setText("Heading 1"); - - CTSdtBlock block = doc.getDocument().getBody().addNewSdt(); - - assertNull(p.getStyle()); - p.setStyle(HEADING1); - assertEquals(HEADING1, p.getCTP().getPPr().getPStyle().getVal()); - - doc.createTOC(); - /* - // TODO - finish this test - if (false) { - CTStyles styles = doc.getStyle(); - CTStyle style = styles.addNewStyle(); +import java.io.IOException; + +import junit.framework.TestCase; +import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.apache.xmlbeans.XmlException; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock; + +/** + * @author Paolo Mottadelli + */ +public final class TestXWPFHeadings extends TestCase { + private static final String HEADING1 = "Heading1"; + + public void testSetParagraphStyle() throws IOException, XmlException { + //new clean instance of paragraph + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("heading123.docx"); + XWPFParagraph p = doc.createParagraph(); + XWPFRun run = p.createRun(); + run.setText("Heading 1"); + + CTSdtBlock block = doc.getDocument().getBody().addNewSdt(); + + assertNull(p.getStyle()); + p.setStyle(HEADING1); + assertEquals(HEADING1, p.getCTP().getPPr().getPStyle().getVal()); + + doc.createTOC(); + /* + // TODO - finish this test + if (false) { + CTStyles styles = doc.getStyle(); + CTStyle style = styles.addNewStyle(); style.setType(STStyleType.PARAGRAPH); style.setStyleId("Heading1"); } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java index dfdecc9f38..5a5ce78f5c 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java @@ -18,85 +18,85 @@ package org.apache.poi.xwpf.usermodel; import java.io.IOException; -import java.math.BigInteger; - -import junit.framework.TestCase; -import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumLvl; - -public class TestXWPFNumbering extends TestCase { - - public void testCompareAbstractNum() throws IOException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx"); - XWPFNumbering numbering = doc.getNumbering(); - BigInteger numId = BigInteger.valueOf(1); - assertTrue(numbering.numExist(numId)); - XWPFNum num = numbering.getNum(numId); - BigInteger abstrNumId = num.getCTNum().getAbstractNumId().getVal(); - XWPFAbstractNum abstractNum = numbering.getAbstractNum(abstrNumId); - BigInteger compareAbstractNum = numbering.getIdOfAbstractNum(abstractNum); - assertEquals(abstrNumId, compareAbstractNum); - } - - public void testAddNumberingToDoc() throws IOException { - BigInteger abstractNumId = BigInteger.valueOf(1); - BigInteger numId = BigInteger.valueOf(1); - - XWPFDocument docOut = new XWPFDocument(); - XWPFNumbering numbering = docOut.createNumbering(); - numId = numbering.addNum(abstractNumId); - - XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); - - numbering = docIn.getNumbering(); - assertTrue(numbering.numExist(numId)); - XWPFNum num = numbering.getNum(numId); - - BigInteger compareAbstractNum = num.getCTNum().getAbstractNumId().getVal(); - assertEquals(abstractNumId, compareAbstractNum); - } - - public void testGetNumIlvl() throws IOException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx"); - BigInteger numIlvl = BigInteger.valueOf(0); - assertEquals(numIlvl, doc.getParagraphs().get(0).getNumIlvl()); - numIlvl = BigInteger.valueOf(1); - assertEquals(numIlvl, doc.getParagraphs().get(5).getNumIlvl()); - } - - public void testGetNumFmt() throws IOException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx"); - assertEquals("bullet", doc.getParagraphs().get(0).getNumFmt()); - assertEquals("bullet", doc.getParagraphs().get(1).getNumFmt()); - assertEquals("bullet", doc.getParagraphs().get(2).getNumFmt()); - assertEquals("bullet", doc.getParagraphs().get(3).getNumFmt()); - assertEquals("decimal", doc.getParagraphs().get(4).getNumFmt()); - assertEquals("lowerLetter", doc.getParagraphs().get(5).getNumFmt()); - assertEquals("lowerRoman", doc.getParagraphs().get(6).getNumFmt()); - } - - public void testLvlText() throws IOException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx"); - - assertEquals("%1.%2.%3.", doc.getParagraphs().get(12).getNumLevelText()); - - assertEquals("NEW-%1-FORMAT", doc.getParagraphs().get(14).getNumLevelText()); - - XWPFParagraph p = doc.getParagraphs().get(18); - assertEquals("%1.", p.getNumLevelText()); - //test that null doesn't throw NPE - assertNull(p.getNumFmt()); - } - - public void testOverrideList() throws IOException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("NumberingWOverrides.docx"); - XWPFParagraph p = doc.getParagraphs().get(4); - XWPFNumbering numbering = doc.getNumbering(); - CTNum ctNum = numbering.getNum(p.getNumID()).getCTNum(); - assertEquals(9, ctNum.sizeOfLvlOverrideArray()); - CTNumLvl ctNumLvl = ctNum.getLvlOverrideArray(0); - assertEquals("upperLetter", ctNumLvl.getLvl().getNumFmt().getVal().toString()); - } - -} +import java.math.BigInteger; + +import junit.framework.TestCase; +import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumLvl; + +public class TestXWPFNumbering extends TestCase { + + public void testCompareAbstractNum() throws IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx"); + XWPFNumbering numbering = doc.getNumbering(); + BigInteger numId = BigInteger.valueOf(1); + assertTrue(numbering.numExist(numId)); + XWPFNum num = numbering.getNum(numId); + BigInteger abstrNumId = num.getCTNum().getAbstractNumId().getVal(); + XWPFAbstractNum abstractNum = numbering.getAbstractNum(abstrNumId); + BigInteger compareAbstractNum = numbering.getIdOfAbstractNum(abstractNum); + assertEquals(abstrNumId, compareAbstractNum); + } + + public void testAddNumberingToDoc() throws IOException { + BigInteger abstractNumId = BigInteger.valueOf(1); + BigInteger numId = BigInteger.valueOf(1); + + XWPFDocument docOut = new XWPFDocument(); + XWPFNumbering numbering = docOut.createNumbering(); + numId = numbering.addNum(abstractNumId); + + XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); + + numbering = docIn.getNumbering(); + assertTrue(numbering.numExist(numId)); + XWPFNum num = numbering.getNum(numId); + + BigInteger compareAbstractNum = num.getCTNum().getAbstractNumId().getVal(); + assertEquals(abstractNumId, compareAbstractNum); + } + + public void testGetNumIlvl() throws IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx"); + BigInteger numIlvl = BigInteger.valueOf(0); + assertEquals(numIlvl, doc.getParagraphs().get(0).getNumIlvl()); + numIlvl = BigInteger.valueOf(1); + assertEquals(numIlvl, doc.getParagraphs().get(5).getNumIlvl()); + } + + public void testGetNumFmt() throws IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx"); + assertEquals("bullet", doc.getParagraphs().get(0).getNumFmt()); + assertEquals("bullet", doc.getParagraphs().get(1).getNumFmt()); + assertEquals("bullet", doc.getParagraphs().get(2).getNumFmt()); + assertEquals("bullet", doc.getParagraphs().get(3).getNumFmt()); + assertEquals("decimal", doc.getParagraphs().get(4).getNumFmt()); + assertEquals("lowerLetter", doc.getParagraphs().get(5).getNumFmt()); + assertEquals("lowerRoman", doc.getParagraphs().get(6).getNumFmt()); + } + + public void testLvlText() throws IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx"); + + assertEquals("%1.%2.%3.", doc.getParagraphs().get(12).getNumLevelText()); + + assertEquals("NEW-%1-FORMAT", doc.getParagraphs().get(14).getNumLevelText()); + + XWPFParagraph p = doc.getParagraphs().get(18); + assertEquals("%1.", p.getNumLevelText()); + //test that null doesn't throw NPE + assertNull(p.getNumFmt()); + } + + public void testOverrideList() throws IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("NumberingWOverrides.docx"); + XWPFParagraph p = doc.getParagraphs().get(4); + XWPFNumbering numbering = doc.getNumbering(); + CTNum ctNum = numbering.getNum(p.getNumID()).getCTNum(); + assertEquals(9, ctNum.sizeOfLvlOverrideArray()); + CTNumLvl ctNumLvl = ctNum.getLvlOverrideArray(0); + assertEquals("upperLetter", ctNumLvl.getLvl().getNumFmt().getVal().toString()); + } + +} diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java index c9123a3a14..0d3cea64cb 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java @@ -20,129 +20,129 @@ package org.apache.poi.xwpf.usermodel; import static org.junit.Assert.assertArrayEquals; import java.io.IOException; -import java.util.List; - -import junit.framework.TestCase; -import org.apache.poi.openxml4j.exceptions.InvalidFormatException; -import org.apache.poi.openxml4j.opc.PackageRelationship; -import org.apache.poi.xssf.usermodel.XSSFRelation; +import java.util.List; + +import junit.framework.TestCase; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.openxml4j.opc.PackageRelationship; +import org.apache.poi.xssf.usermodel.XSSFRelation; import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; - -public class TestXWPFPictureData extends TestCase { - - public void testRead() throws InvalidFormatException, IOException { - XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx"); - List pictures = sampleDoc.getAllPictures(); - - assertEquals(5, pictures.size()); - String[] ext = {"wmf", "png", "emf", "emf", "jpeg"}; - for (int i = 0; i < pictures.size(); i++) { - assertEquals(ext[i], pictures.get(i).suggestFileExtension()); - } - - int num = pictures.size(); - - byte[] pictureData = XWPFTestDataSamples.getImage("nature1.jpg"); - - String relationId = sampleDoc.addPictureData(pictureData, XWPFDocument.PICTURE_TYPE_JPEG); - // picture list was updated - assertEquals(num + 1, pictures.size()); - XWPFPictureData pict = (XWPFPictureData) sampleDoc.getRelationById(relationId); - assertEquals("jpeg", pict.suggestFileExtension()); - assertArrayEquals(pictureData, pict.getData()); - } - - public void testPictureInHeader() throws IOException { - XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx"); - verifyOneHeaderPicture(sampleDoc); - - XWPFDocument readBack = XWPFTestDataSamples.writeOutAndReadBack(sampleDoc); - verifyOneHeaderPicture(readBack); - } +import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; + +public class TestXWPFPictureData extends TestCase { + + public void testRead() throws InvalidFormatException, IOException { + XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx"); + List pictures = sampleDoc.getAllPictures(); + + assertEquals(5, pictures.size()); + String[] ext = {"wmf", "png", "emf", "emf", "jpeg"}; + for (int i = 0; i < pictures.size(); i++) { + assertEquals(ext[i], pictures.get(i).suggestFileExtension()); + } + + int num = pictures.size(); + + byte[] pictureData = XWPFTestDataSamples.getImage("nature1.jpg"); + + String relationId = sampleDoc.addPictureData(pictureData, XWPFDocument.PICTURE_TYPE_JPEG); + // picture list was updated + assertEquals(num + 1, pictures.size()); + XWPFPictureData pict = (XWPFPictureData) sampleDoc.getRelationById(relationId); + assertEquals("jpeg", pict.suggestFileExtension()); + assertArrayEquals(pictureData, pict.getData()); + } + + public void testPictureInHeader() throws IOException { + XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx"); + verifyOneHeaderPicture(sampleDoc); + + XWPFDocument readBack = XWPFTestDataSamples.writeOutAndReadBack(sampleDoc); + verifyOneHeaderPicture(readBack); + } private void verifyOneHeaderPicture(XWPFDocument sampleDoc) { XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy(); - XWPFHeader header = policy.getDefaultHeader(); - - List pictures = header.getAllPictures(); - assertEquals(1, pictures.size()); - } - - public void testNew() throws InvalidFormatException, IOException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("EmptyDocumentWithHeaderFooter.docx"); - byte[] jpegData = XWPFTestDataSamples.getImage("nature1.jpg"); - assertNotNull(jpegData); + XWPFHeader header = policy.getDefaultHeader(); + + List pictures = header.getAllPictures(); + assertEquals(1, pictures.size()); + } + + public void testNew() throws InvalidFormatException, IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("EmptyDocumentWithHeaderFooter.docx"); + byte[] jpegData = XWPFTestDataSamples.getImage("nature1.jpg"); + assertNotNull(jpegData); byte[] gifData = XWPFTestDataSamples.getImage("nature1.gif"); assertNotNull(gifData); byte[] pngData = XWPFTestDataSamples.getImage("nature1.png"); - assertNotNull(pngData); - - List pictures = doc.getAllPictures(); - assertEquals(0, pictures.size()); - - // Document shouldn't have any image relationships - assertEquals(13, doc.getPackagePart().getRelationships().size()); - for (PackageRelationship rel : doc.getPackagePart().getRelationships()) { - if (rel.getRelationshipType().equals(XSSFRelation.IMAGE_JPEG.getRelation())) { - fail("Shouldn't have JPEG yet"); - } - } - - // Add the image - String relationId = doc.addPictureData(jpegData, XWPFDocument.PICTURE_TYPE_JPEG); - assertEquals(1, pictures.size()); - XWPFPictureData jpgPicData = (XWPFPictureData) doc.getRelationById(relationId); - assertEquals("jpeg", jpgPicData.suggestFileExtension()); - assertArrayEquals(jpegData, jpgPicData.getData()); - - // Ensure it now has one - assertEquals(14, doc.getPackagePart().getRelationships().size()); - PackageRelationship jpegRel = null; - for (PackageRelationship rel : doc.getPackagePart().getRelationships()) { - if (rel.getRelationshipType().equals(XWPFRelation.IMAGE_JPEG.getRelation())) { - if (jpegRel != null) - fail("Found 2 jpegs!"); - jpegRel = rel; - } - } - assertNotNull("JPEG Relationship not found", jpegRel); - - // Check the details - assertNotNull(jpegRel); - assertEquals(XWPFRelation.IMAGE_JPEG.getRelation(), jpegRel.getRelationshipType()); - assertEquals("/word/document.xml", jpegRel.getSource().getPartName().toString()); - assertEquals("/word/media/image1.jpeg", jpegRel.getTargetURI().getPath()); - - XWPFPictureData pictureDataByID = doc.getPictureDataByID(jpegRel.getId()); - assertArrayEquals(jpegData, pictureDataByID.getData()); - - // Save an re-load, check it appears - doc = XWPFTestDataSamples.writeOutAndReadBack(doc); - assertEquals(1, doc.getAllPictures().size()); - assertEquals(1, doc.getAllPackagePictures().size()); - - // verify the picture that we read back in - pictureDataByID = doc.getPictureDataByID(jpegRel.getId()); - assertArrayEquals(jpegData, pictureDataByID.getData()); - - } - - public void testBug51770() throws InvalidFormatException, IOException { + assertNotNull(pngData); + + List pictures = doc.getAllPictures(); + assertEquals(0, pictures.size()); + + // Document shouldn't have any image relationships + assertEquals(13, doc.getPackagePart().getRelationships().size()); + for (PackageRelationship rel : doc.getPackagePart().getRelationships()) { + if (rel.getRelationshipType().equals(XSSFRelation.IMAGE_JPEG.getRelation())) { + fail("Shouldn't have JPEG yet"); + } + } + + // Add the image + String relationId = doc.addPictureData(jpegData, XWPFDocument.PICTURE_TYPE_JPEG); + assertEquals(1, pictures.size()); + XWPFPictureData jpgPicData = (XWPFPictureData) doc.getRelationById(relationId); + assertEquals("jpeg", jpgPicData.suggestFileExtension()); + assertArrayEquals(jpegData, jpgPicData.getData()); + + // Ensure it now has one + assertEquals(14, doc.getPackagePart().getRelationships().size()); + PackageRelationship jpegRel = null; + for (PackageRelationship rel : doc.getPackagePart().getRelationships()) { + if (rel.getRelationshipType().equals(XWPFRelation.IMAGE_JPEG.getRelation())) { + if (jpegRel != null) + fail("Found 2 jpegs!"); + jpegRel = rel; + } + } + assertNotNull("JPEG Relationship not found", jpegRel); + + // Check the details + assertNotNull(jpegRel); + assertEquals(XWPFRelation.IMAGE_JPEG.getRelation(), jpegRel.getRelationshipType()); + assertEquals("/word/document.xml", jpegRel.getSource().getPartName().toString()); + assertEquals("/word/media/image1.jpeg", jpegRel.getTargetURI().getPath()); + + XWPFPictureData pictureDataByID = doc.getPictureDataByID(jpegRel.getId()); + assertArrayEquals(jpegData, pictureDataByID.getData()); + + // Save an re-load, check it appears + doc = XWPFTestDataSamples.writeOutAndReadBack(doc); + assertEquals(1, doc.getAllPictures().size()); + assertEquals(1, doc.getAllPackagePictures().size()); + + // verify the picture that we read back in + pictureDataByID = doc.getPictureDataByID(jpegRel.getId()); + assertArrayEquals(jpegData, pictureDataByID.getData()); + + } + + public void testBug51770() throws InvalidFormatException, IOException { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug51170.docx"); XWPFHeaderFooterPolicy policy = doc.getHeaderFooterPolicy(); XWPFHeader header = policy.getDefaultHeader(); for (XWPFParagraph paragraph : header.getParagraphs()) { for (XWPFRun run : paragraph.getRuns()) { for (XWPFPicture picture : run.getEmbeddedPictures()) { - if (paragraph.getDocument() != null) { - //System.out.println(picture.getCTPicture()); - XWPFPictureData data = picture.getPictureData(); - if (data != null) System.out.println(data.getFileName()); - } - } - } + if (paragraph.getDocument() != null) { + //System.out.println(picture.getCTPicture()); + XWPFPictureData data = picture.getPictureData(); + if (data != null) System.out.println(data.getFileName()); + } + } + } } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java index d9af8c91fd..a447098ef8 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java @@ -20,12 +20,12 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.math.BigInteger; import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; -import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr; +import java.util.List; + +import junit.framework.TestCase; +import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear; @@ -45,28 +45,28 @@ public class TestXWPFRun extends TestCase { p = doc.createParagraph(); this.ctRun = CTR.Factory.newInstance(); - } - - public void testSetGetText() { - ctRun.addNewT().setStringValue("TEST STRING"); - ctRun.addNewT().setStringValue("TEST2 STRING"); - ctRun.addNewT().setStringValue("TEST3 STRING"); - - assertEquals(3, ctRun.sizeOfTArray()); - XWPFRun run = new XWPFRun(ctRun, p); - - assertEquals("TEST2 STRING", run.getText(1)); - - run.setText("NEW STRING", 0); - assertEquals("NEW STRING", run.getText(0)); - - //run.setText("xxx",14); - //fail("Position wrong"); - } - - public void testSetGetBold() { - CTRPr rpr = ctRun.addNewRPr(); - rpr.addNewB().setVal(STOnOff.TRUE); + } + + public void testSetGetText() { + ctRun.addNewT().setStringValue("TEST STRING"); + ctRun.addNewT().setStringValue("TEST2 STRING"); + ctRun.addNewT().setStringValue("TEST3 STRING"); + + assertEquals(3, ctRun.sizeOfTArray()); + XWPFRun run = new XWPFRun(ctRun, p); + + assertEquals("TEST2 STRING", run.getText(1)); + + run.setText("NEW STRING", 0); + assertEquals("NEW STRING", run.getText(0)); + + //run.setText("xxx",14); + //fail("Position wrong"); + } + + public void testSetGetBold() { + CTRPr rpr = ctRun.addNewRPr(); + rpr.addNewB().setVal(STOnOff.TRUE); XWPFRun run = new XWPFRun(ctRun, p); assertEquals(true, run.isBold()); @@ -177,16 +177,16 @@ public class TestXWPFRun extends TestCase { run.setText("T1"); run.addCarriageReturn(); run.addCarriageReturn(); - run.setText("T2"); - run.addCarriageReturn(); - assertEquals(3, run.getCTR().sizeOfCrArray()); - - assertEquals("T1\n\nT2\n", run.toString()); - } - - public void testAddTabsAndLineBreaks() { - ctRun.addNewT().setStringValue("TEST STRING"); - ctRun.addNewCr(); + run.setText("T2"); + run.addCarriageReturn(); + assertEquals(3, run.getCTR().sizeOfCrArray()); + + assertEquals("T1\n\nT2\n", run.toString()); + } + + public void testAddTabsAndLineBreaks() { + ctRun.addNewT().setStringValue("TEST STRING"); + ctRun.addNewCr(); ctRun.addNewT().setStringValue("TEST2 STRING"); ctRun.addNewTab(); ctRun.addNewT().setStringValue("TEST3 STRING"); @@ -198,21 +198,21 @@ public class TestXWPFRun extends TestCase { run.addCarriageReturn(); run.setText("T2"); run.addTab(); - run.setText("T3"); - assertEquals(1, run.getCTR().sizeOfCrArray()); - assertEquals(1, run.getCTR().sizeOfTabArray()); - - assertEquals("T1\nT2\tT3", run.toString()); - } - + run.setText("T3"); + assertEquals(1, run.getCTR().sizeOfCrArray()); + assertEquals(1, run.getCTR().sizeOfTabArray()); + + assertEquals("T1\nT2\tT3", run.toString()); + } + public void testAddPageBreak() { - ctRun.addNewT().setStringValue("TEST STRING"); - ctRun.addNewBr(); - ctRun.addNewT().setStringValue("TEST2 STRING"); - CTBr breac = ctRun.addNewBr(); - breac.setClear(STBrClear.LEFT); - ctRun.addNewT().setStringValue("TEST3 STRING"); - assertEquals(2, ctRun.sizeOfBrArray()); + ctRun.addNewT().setStringValue("TEST STRING"); + ctRun.addNewBr(); + ctRun.addNewT().setStringValue("TEST2 STRING"); + CTBr breac = ctRun.addNewBr(); + breac.setClear(STBrClear.LEFT); + ctRun.addNewT().setStringValue("TEST3 STRING"); + assertEquals(2, ctRun.sizeOfBrArray()); XWPFRun run = new XWPFRun(CTR.Factory.newInstance(), p); run.setText("TEXT1"); @@ -221,145 +221,145 @@ public class TestXWPFRun extends TestCase { run.addBreak(BreakType.TEXT_WRAPPING); assertEquals(2, run.getCTR().sizeOfBrArray()); } - - /** - * Test that on an existing document, we do the - * right thing with it - * - * @throws IOException - */ - public void testExisting() throws IOException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx"); - XWPFParagraph p; - XWPFRun run; - - - // First paragraph is simple - p = doc.getParagraphArray(0); - assertEquals("This is a test document.", p.getText()); - assertEquals(2, p.getRuns().size()); - - run = p.getRuns().get(0); - assertEquals("This is a test document", run.toString()); - assertEquals(false, run.isBold()); - assertEquals(false, run.isItalic()); - assertEquals(false, run.isStrike()); - assertEquals(null, run.getCTR().getRPr()); - - run = p.getRuns().get(1); - assertEquals(".", run.toString()); - assertEquals(false, run.isBold()); - assertEquals(false, run.isItalic()); - assertEquals(false, run.isStrike()); - assertEquals(null, run.getCTR().getRPr()); - - - // Next paragraph is all in one style, but a different one - p = doc.getParagraphArray(1); - assertEquals("This bit is in bold and italic", p.getText()); - assertEquals(1, p.getRuns().size()); - - run = p.getRuns().get(0); - assertEquals("This bit is in bold and italic", run.toString()); - assertEquals(true, run.isBold()); - assertEquals(true, run.isItalic()); - assertEquals(false, run.isStrike()); - assertEquals(true, run.getCTR().getRPr().isSetB()); - assertEquals(false, run.getCTR().getRPr().getB().isSetVal()); - - - // Back to normal - p = doc.getParagraphArray(2); - assertEquals("Back to normal", p.getText()); - assertEquals(1, p.getRuns().size()); - - run = p.getRuns().get(0); - assertEquals("Back to normal", run.toString()); - assertEquals(false, run.isBold()); - assertEquals(false, run.isItalic()); - assertEquals(false, run.isStrike()); - assertEquals(null, run.getCTR().getRPr()); - - - // Different styles in one paragraph - p = doc.getParagraphArray(3); - assertEquals("This contains BOLD, ITALIC and BOTH, as well as RED and YELLOW text.", p.getText()); - assertEquals(11, p.getRuns().size()); - - run = p.getRuns().get(0); - assertEquals("This contains ", run.toString()); - assertEquals(false, run.isBold()); - assertEquals(false, run.isItalic()); - assertEquals(false, run.isStrike()); - assertEquals(null, run.getCTR().getRPr()); - - run = p.getRuns().get(1); - assertEquals("BOLD", run.toString()); - assertEquals(true, run.isBold()); - assertEquals(false, run.isItalic()); - assertEquals(false, run.isStrike()); - - run = p.getRuns().get(2); - assertEquals(", ", run.toString()); - assertEquals(false, run.isBold()); - assertEquals(false, run.isItalic()); - assertEquals(false, run.isStrike()); - assertEquals(null, run.getCTR().getRPr()); - - run = p.getRuns().get(3); - assertEquals("ITALIC", run.toString()); - assertEquals(false, run.isBold()); - assertEquals(true, run.isItalic()); - assertEquals(false, run.isStrike()); - - run = p.getRuns().get(4); - assertEquals(" and ", run.toString()); - assertEquals(false, run.isBold()); - assertEquals(false, run.isItalic()); - assertEquals(false, run.isStrike()); - assertEquals(null, run.getCTR().getRPr()); - - run = p.getRuns().get(5); - assertEquals("BOTH", run.toString()); - assertEquals(true, run.isBold()); - assertEquals(true, run.isItalic()); - assertEquals(false, run.isStrike()); - - run = p.getRuns().get(6); - assertEquals(", as well as ", run.toString()); - assertEquals(false, run.isBold()); - assertEquals(false, run.isItalic()); - assertEquals(false, run.isStrike()); - assertEquals(null, run.getCTR().getRPr()); - - run = p.getRuns().get(7); - assertEquals("RED", run.toString()); - assertEquals(false, run.isBold()); - assertEquals(false, run.isItalic()); - assertEquals(false, run.isStrike()); - - run = p.getRuns().get(8); - assertEquals(" and ", run.toString()); - assertEquals(false, run.isBold()); - assertEquals(false, run.isItalic()); - assertEquals(false, run.isStrike()); - assertEquals(null, run.getCTR().getRPr()); - - run = p.getRuns().get(9); - assertEquals("YELLOW", run.toString()); - assertEquals(false, run.isBold()); - assertEquals(false, run.isItalic()); - assertEquals(false, run.isStrike()); - - run = p.getRuns().get(10); - assertEquals(" text.", run.toString()); - assertEquals(false, run.isBold()); - assertEquals(false, run.isItalic()); - assertEquals(false, run.isStrike()); - assertEquals(null, run.getCTR().getRPr()); - } - - public void testPictureInHeader() throws IOException { + + /** + * Test that on an existing document, we do the + * right thing with it + * + * @throws IOException + */ + public void testExisting() throws IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx"); + XWPFParagraph p; + XWPFRun run; + + + // First paragraph is simple + p = doc.getParagraphArray(0); + assertEquals("This is a test document.", p.getText()); + assertEquals(2, p.getRuns().size()); + + run = p.getRuns().get(0); + assertEquals("This is a test document", run.toString()); + assertEquals(false, run.isBold()); + assertEquals(false, run.isItalic()); + assertEquals(false, run.isStrike()); + assertEquals(null, run.getCTR().getRPr()); + + run = p.getRuns().get(1); + assertEquals(".", run.toString()); + assertEquals(false, run.isBold()); + assertEquals(false, run.isItalic()); + assertEquals(false, run.isStrike()); + assertEquals(null, run.getCTR().getRPr()); + + + // Next paragraph is all in one style, but a different one + p = doc.getParagraphArray(1); + assertEquals("This bit is in bold and italic", p.getText()); + assertEquals(1, p.getRuns().size()); + + run = p.getRuns().get(0); + assertEquals("This bit is in bold and italic", run.toString()); + assertEquals(true, run.isBold()); + assertEquals(true, run.isItalic()); + assertEquals(false, run.isStrike()); + assertEquals(true, run.getCTR().getRPr().isSetB()); + assertEquals(false, run.getCTR().getRPr().getB().isSetVal()); + + + // Back to normal + p = doc.getParagraphArray(2); + assertEquals("Back to normal", p.getText()); + assertEquals(1, p.getRuns().size()); + + run = p.getRuns().get(0); + assertEquals("Back to normal", run.toString()); + assertEquals(false, run.isBold()); + assertEquals(false, run.isItalic()); + assertEquals(false, run.isStrike()); + assertEquals(null, run.getCTR().getRPr()); + + + // Different styles in one paragraph + p = doc.getParagraphArray(3); + assertEquals("This contains BOLD, ITALIC and BOTH, as well as RED and YELLOW text.", p.getText()); + assertEquals(11, p.getRuns().size()); + + run = p.getRuns().get(0); + assertEquals("This contains ", run.toString()); + assertEquals(false, run.isBold()); + assertEquals(false, run.isItalic()); + assertEquals(false, run.isStrike()); + assertEquals(null, run.getCTR().getRPr()); + + run = p.getRuns().get(1); + assertEquals("BOLD", run.toString()); + assertEquals(true, run.isBold()); + assertEquals(false, run.isItalic()); + assertEquals(false, run.isStrike()); + + run = p.getRuns().get(2); + assertEquals(", ", run.toString()); + assertEquals(false, run.isBold()); + assertEquals(false, run.isItalic()); + assertEquals(false, run.isStrike()); + assertEquals(null, run.getCTR().getRPr()); + + run = p.getRuns().get(3); + assertEquals("ITALIC", run.toString()); + assertEquals(false, run.isBold()); + assertEquals(true, run.isItalic()); + assertEquals(false, run.isStrike()); + + run = p.getRuns().get(4); + assertEquals(" and ", run.toString()); + assertEquals(false, run.isBold()); + assertEquals(false, run.isItalic()); + assertEquals(false, run.isStrike()); + assertEquals(null, run.getCTR().getRPr()); + + run = p.getRuns().get(5); + assertEquals("BOTH", run.toString()); + assertEquals(true, run.isBold()); + assertEquals(true, run.isItalic()); + assertEquals(false, run.isStrike()); + + run = p.getRuns().get(6); + assertEquals(", as well as ", run.toString()); + assertEquals(false, run.isBold()); + assertEquals(false, run.isItalic()); + assertEquals(false, run.isStrike()); + assertEquals(null, run.getCTR().getRPr()); + + run = p.getRuns().get(7); + assertEquals("RED", run.toString()); + assertEquals(false, run.isBold()); + assertEquals(false, run.isItalic()); + assertEquals(false, run.isStrike()); + + run = p.getRuns().get(8); + assertEquals(" and ", run.toString()); + assertEquals(false, run.isBold()); + assertEquals(false, run.isItalic()); + assertEquals(false, run.isStrike()); + assertEquals(null, run.getCTR().getRPr()); + + run = p.getRuns().get(9); + assertEquals("YELLOW", run.toString()); + assertEquals(false, run.isBold()); + assertEquals(false, run.isItalic()); + assertEquals(false, run.isStrike()); + + run = p.getRuns().get(10); + assertEquals(" text.", run.toString()); + assertEquals(false, run.isBold()); + assertEquals(false, run.isItalic()); + assertEquals(false, run.isStrike()); + assertEquals(null, run.getCTR().getRPr()); + } + + public void testPictureInHeader() throws IOException { XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx"); XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy(); @@ -373,47 +373,47 @@ public class TestXWPFRun extends TestCase { for (XWPFPicture pic : pictures) { assertNotNull(pic.getPictureData()); - assertEquals("DOZOR", pic.getDescription()); - } - - count += pictures.size(); - } - } - - assertEquals(1, count); - } - - public void testAddPicture() throws Exception { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx"); - XWPFParagraph p = doc.getParagraphArray(2); - XWPFRun r = p.getRuns().get(0); - - assertEquals(0, doc.getAllPictures().size()); - assertEquals(0, r.getEmbeddedPictures().size()); - - r.addPicture(new ByteArrayInputStream(new byte[0]), Document.PICTURE_TYPE_JPEG, "test.jpg", 21, 32); - - assertEquals(1, doc.getAllPictures().size()); - assertEquals(1, r.getEmbeddedPictures().size()); - } - - /** - * Bugzilla #52288 - setting the font family on the - * run mustn't NPE - */ - public void testSetFontFamily_52288() throws Exception { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52288.docx"); - final Iterator paragraphs = doc.getParagraphsIterator(); - while (paragraphs.hasNext()) { - final XWPFParagraph paragraph = paragraphs.next(); - for (final XWPFRun run : paragraph.getRuns()) { - if (run != null) { - final String text = run.getText(0); - if (text != null) { - run.setFontFamily("Times New Roman"); - } - } - } - } - } -} + assertEquals("DOZOR", pic.getDescription()); + } + + count += pictures.size(); + } + } + + assertEquals(1, count); + } + + public void testAddPicture() throws Exception { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx"); + XWPFParagraph p = doc.getParagraphArray(2); + XWPFRun r = p.getRuns().get(0); + + assertEquals(0, doc.getAllPictures().size()); + assertEquals(0, r.getEmbeddedPictures().size()); + + r.addPicture(new ByteArrayInputStream(new byte[0]), Document.PICTURE_TYPE_JPEG, "test.jpg", 21, 32); + + assertEquals(1, doc.getAllPictures().size()); + assertEquals(1, r.getEmbeddedPictures().size()); + } + + /** + * Bugzilla #52288 - setting the font family on the + * run mustn't NPE + */ + public void testSetFontFamily_52288() throws Exception { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52288.docx"); + final Iterator paragraphs = doc.getParagraphsIterator(); + while (paragraphs.hasNext()) { + final XWPFParagraph paragraph = paragraphs.next(); + for (final XWPFRun run : paragraph.getRuns()) { + if (run != null) { + final String text = run.getText(0); + if (text != null) { + run.setFontFamily("Times New Roman"); + } + } + } + } + } +} 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 92c94052e0..b008763ca6 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java @@ -15,46 +15,46 @@ limitations under the License. ==================================================================== */ -package org.apache.poi.xwpf.usermodel; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import junit.framework.TestCase; -import org.apache.poi.xwpf.XWPFTestDataSamples; - -public final class TestXWPFSDT extends TestCase { - - /** - * Test simple tag and title extraction from SDT - * - * @throws Exception - */ - public void testTagTitle() throws Exception { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx"); - String tag = null; - String title = null; - List sdts = extractAllSDTs(doc); - for (AbstractXWPFSDT sdt : sdts) { - if (sdt.getContent().toString().equals("Rich_text")) { - tag = "MyTag"; - title = "MyTitle"; - break; - } - - } - assertEquals("controls size", 13, sdts.size()); - +package org.apache.poi.xwpf.usermodel; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import junit.framework.TestCase; +import org.apache.poi.xwpf.XWPFTestDataSamples; + +public final class TestXWPFSDT extends TestCase { + + /** + * Test simple tag and title extraction from SDT + * + * @throws Exception + */ + public void testTagTitle() throws Exception { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx"); + String tag = null; + String title = null; + List sdts = extractAllSDTs(doc); + for (AbstractXWPFSDT sdt : sdts) { + if (sdt.getContent().toString().equals("Rich_text")) { + tag = "MyTag"; + title = "MyTitle"; + break; + } + + } + assertEquals("controls size", 13, sdts.size()); + assertEquals("tag", "MyTag", tag); assertEquals("title", "MyTitle", title); - } - - - public void testGetSDTs() throws Exception { - String[] contents = new String[]{ - "header_rich_text", - "Rich_text", + } + + + public void testGetSDTs() throws Exception { + String[] contents = new String[]{ + "header_rich_text", + "Rich_text", "Rich_text_pre_table\nRich_text_cell1\t\t\t\n\t\t\t\n\t\t\t\n\nRich_text_post_table", "Plain_text_no_newlines", "Plain_text_with_newlines1\nplain_text_with_newlines2", @@ -70,126 +70,126 @@ public final class TestXWPFSDT extends TestCase { }; XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx"); List sdts = extractAllSDTs(doc); - - assertEquals("number of sdts", contents.length, sdts.size()); - - for (int i = 0; i < contents.length; i++) { - AbstractXWPFSDT sdt = sdts.get(i); - assertEquals(i + ": " + contents[i], contents[i], sdt.getContent().toString()); - } - } - - /** - * POI-54771 and TIKA-1317 - */ + + assertEquals("number of sdts", contents.length, sdts.size()); + + for (int i = 0; i < contents.length; i++) { + AbstractXWPFSDT sdt = sdts.get(i); + assertEquals(i + ": " + contents[i], contents[i], sdt.getContent().toString()); + } + } + + /** + * POI-54771 and TIKA-1317 + */ public void testSDTAsCell() throws Exception { //Bug54771a.docx and Bug54771b.docx test slightly //different recursion patterns. Keep both! - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx"); - List sdts = extractAllSDTs(doc); - String text = sdts.get(0).getContent().getText(); - assertEquals(2, sdts.size()); - assertTrue(text.indexOf("Test") > -1); - - text = sdts.get(1).getContent().getText(); + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx"); + List sdts = extractAllSDTs(doc); + String text = sdts.get(0).getContent().getText(); + assertEquals(2, sdts.size()); + assertTrue(text.indexOf("Test") > -1); + + text = sdts.get(1).getContent().getText(); assertTrue(text.indexOf("Test Subtitle") > -1); assertTrue(text.indexOf("Test User") > -1); assertTrue(text.indexOf("Test") < text.indexOf("Test Subtitle")); - - doc = XWPFTestDataSamples.openSampleDocument("Bug54771b.docx"); - sdts = extractAllSDTs(doc); - assertEquals(3, sdts.size()); - assertTrue(sdts.get(0).getContent().getText().indexOf("Test") > -1); - - assertTrue(sdts.get(1).getContent().getText().indexOf("Test Subtitle") > -1); - assertTrue(sdts.get(2).getContent().getText().indexOf("Test User") > -1); - - } - - /** - * POI-55142 and Tika 1130 - */ - public void testNewLinesBetweenRuns() throws Exception { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug55142.docx"); - List sdts = extractAllSDTs(doc); - List targs = new ArrayList(); - //these test newlines and tabs in paragraphs/body elements - targs.add("Rich-text1 abcdefghi"); - targs.add("Rich-text2 abcd\t\tefgh"); - targs.add("Rich-text3 abcd\nefg"); - targs.add("Rich-text4 abcdefg"); - targs.add("Rich-text5 abcdefg\nhijk"); - targs.add("Plain-text1 abcdefg"); - targs.add("Plain-text2 abcdefg\nhijk\nlmnop"); - //this tests consecutive runs within a cell (not a paragraph) - //this test case was triggered by Tika-1130 - targs.add("sdt_incell2 abcdefg"); - - for (int i = 0; i < sdts.size(); i++) { - AbstractXWPFSDT sdt = sdts.get(i); - assertEquals(targs.get(i), targs.get(i), sdt.getContent().getText()); - } - } - - private List extractAllSDTs(XWPFDocument doc) { - - List sdts = new ArrayList(); - - List headers = doc.getHeaderList(); - for (XWPFHeader header : headers) { - sdts.addAll(extractSDTsFromBodyElements(header.getBodyElements())); - } - sdts.addAll(extractSDTsFromBodyElements(doc.getBodyElements())); - - List footers = doc.getFooterList(); - for (XWPFFooter footer : footers) { - sdts.addAll(extractSDTsFromBodyElements(footer.getBodyElements())); - } - - for (XWPFFootnote footnote : doc.getFootnotes()) { - sdts.addAll(extractSDTsFromBodyElements(footnote.getBodyElements())); - } - for (Map.Entry e : doc.endnotes.entrySet()) { - sdts.addAll(extractSDTsFromBodyElements(e.getValue().getBodyElements())); - } - return sdts; - } - - private List extractSDTsFromBodyElements(List elements) { - List sdts = new ArrayList(); - for (IBodyElement e : elements) { - if (e instanceof XWPFSDT) { - XWPFSDT sdt = (XWPFSDT) e; - sdts.add(sdt); - } else if (e instanceof XWPFParagraph) { - - XWPFParagraph p = (XWPFParagraph) e; - for (IRunElement e2 : p.getIRuns()) { - if (e2 instanceof XWPFSDT) { - XWPFSDT sdt = (XWPFSDT) e2; - sdts.add(sdt); - } - } - } else if (e instanceof XWPFTable) { - XWPFTable table = (XWPFTable) e; - sdts.addAll(extractSDTsFromTable(table)); - } - } + + doc = XWPFTestDataSamples.openSampleDocument("Bug54771b.docx"); + sdts = extractAllSDTs(doc); + assertEquals(3, sdts.size()); + assertTrue(sdts.get(0).getContent().getText().indexOf("Test") > -1); + + assertTrue(sdts.get(1).getContent().getText().indexOf("Test Subtitle") > -1); + assertTrue(sdts.get(2).getContent().getText().indexOf("Test User") > -1); + + } + + /** + * POI-55142 and Tika 1130 + */ + public void testNewLinesBetweenRuns() throws Exception { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug55142.docx"); + List sdts = extractAllSDTs(doc); + List targs = new ArrayList(); + //these test newlines and tabs in paragraphs/body elements + targs.add("Rich-text1 abcdefghi"); + targs.add("Rich-text2 abcd\t\tefgh"); + targs.add("Rich-text3 abcd\nefg"); + targs.add("Rich-text4 abcdefg"); + targs.add("Rich-text5 abcdefg\nhijk"); + targs.add("Plain-text1 abcdefg"); + targs.add("Plain-text2 abcdefg\nhijk\nlmnop"); + //this tests consecutive runs within a cell (not a paragraph) + //this test case was triggered by Tika-1130 + targs.add("sdt_incell2 abcdefg"); + + for (int i = 0; i < sdts.size(); i++) { + AbstractXWPFSDT sdt = sdts.get(i); + assertEquals(targs.get(i), targs.get(i), sdt.getContent().getText()); + } + } + + private List extractAllSDTs(XWPFDocument doc) { + + List sdts = new ArrayList(); + + List headers = doc.getHeaderList(); + for (XWPFHeader header : headers) { + sdts.addAll(extractSDTsFromBodyElements(header.getBodyElements())); + } + sdts.addAll(extractSDTsFromBodyElements(doc.getBodyElements())); + + List footers = doc.getFooterList(); + for (XWPFFooter footer : footers) { + sdts.addAll(extractSDTsFromBodyElements(footer.getBodyElements())); + } + + for (XWPFFootnote footnote : doc.getFootnotes()) { + sdts.addAll(extractSDTsFromBodyElements(footnote.getBodyElements())); + } + for (Map.Entry e : doc.endnotes.entrySet()) { + sdts.addAll(extractSDTsFromBodyElements(e.getValue().getBodyElements())); + } + return sdts; + } + + private List extractSDTsFromBodyElements(List elements) { + List sdts = new ArrayList(); + for (IBodyElement e : elements) { + if (e instanceof XWPFSDT) { + XWPFSDT sdt = (XWPFSDT) e; + sdts.add(sdt); + } else if (e instanceof XWPFParagraph) { + + XWPFParagraph p = (XWPFParagraph) e; + for (IRunElement e2 : p.getIRuns()) { + if (e2 instanceof XWPFSDT) { + XWPFSDT sdt = (XWPFSDT) e2; + sdts.add(sdt); + } + } + } else if (e instanceof XWPFTable) { + XWPFTable table = (XWPFTable) e; + sdts.addAll(extractSDTsFromTable(table)); + } + } return sdts; } private List extractSDTsFromTable(XWPFTable table) { List sdts = new ArrayList(); - for (XWPFTableRow r : table.getRows()) { - for (ICell c : r.getTableICells()) { - if (c instanceof XWPFSDTCell) { - sdts.add((XWPFSDTCell) c); - } else if (c instanceof XWPFTableCell) { - sdts.addAll(extractSDTsFromBodyElements(((XWPFTableCell) c).getBodyElements())); - } - } - } + for (XWPFTableRow r : table.getRows()) { + for (ICell c : r.getTableICells()) { + if (c instanceof XWPFSDTCell) { + sdts.add((XWPFSDTCell) c); + } else if (c instanceof XWPFTableCell) { + sdts.addAll(extractSDTsFromBodyElements(((XWPFTableCell) c).getBodyElements())); + } + } + } return sdts; } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java index 011092729a..7adc0d0f34 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java @@ -1,38 +1,38 @@ -/* ==================================================================== - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==================================================================== */ -package org.apache.poi.xwpf.usermodel; - -import java.io.IOException; - -import junit.framework.TestCase; -import org.apache.poi.xwpf.XWPFTestDataSamples; - -/** - * Tests for reading SmartTags from Word docx. - * - * @author Fabian Lange - */ -public final class TestXWPFSmartTag extends TestCase { - - public void testSmartTags() throws IOException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("smarttag-snippet.docx"); - XWPFParagraph p = doc.getParagraphArray(0); - assertTrue(p.getText().contains("Carnegie Mellon University School of Computer Science")); - p = doc.getParagraphArray(2); - assertTrue(p.getText().contains("Alice's Adventures")); - } -} +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.xwpf.usermodel; + +import java.io.IOException; + +import junit.framework.TestCase; +import org.apache.poi.xwpf.XWPFTestDataSamples; + +/** + * Tests for reading SmartTags from Word docx. + * + * @author Fabian Lange + */ +public final class TestXWPFSmartTag extends TestCase { + + public void testSmartTags() throws IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("smarttag-snippet.docx"); + XWPFParagraph p = doc.getParagraphArray(0); + assertTrue(p.getText().contains("Carnegie Mellon University School of Computer Science")); + p = doc.getParagraphArray(2); + assertTrue(p.getText().contains("Alice's Adventures")); + } +} diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java index bef00de159..3773b2998d 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java @@ -19,82 +19,77 @@ package org.apache.poi.xwpf.usermodel; import java.io.IOException; import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; -import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLatentStyles; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLatentStyles; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLsdException; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STStyleType; public class TestXWPFStyles extends TestCase { + public void testGetUsedStyles() throws IOException { + XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("Styles.docx"); + List testUsedStyleList = new ArrayList(); + XWPFStyles styles = sampleDoc.getStyles(); + XWPFStyle style = styles.getStyle("berschrift1"); + testUsedStyleList.add(style); + testUsedStyleList.add(styles.getStyle("Standard")); + testUsedStyleList.add(styles.getStyle("berschrift1Zchn")); + testUsedStyleList.add(styles.getStyle("Absatz-Standardschriftart")); + style.hasSameName(style); + + List usedStyleList = styles.getUsedStyleList(style); + assertEquals(usedStyleList, testUsedStyleList); + } + + public void testAddStylesToDocument() throws IOException { + XWPFDocument docOut = new XWPFDocument(); + XWPFStyles styles = docOut.createStyles(); + + String strStyleId = "headline1"; + CTStyle ctStyle = CTStyle.Factory.newInstance(); + + ctStyle.setStyleId(strStyleId); + XWPFStyle s = new XWPFStyle(ctStyle); + styles.addStyle(s); -// protected void setUp() throws Exception { -// super.setUp(); -// } - - public void testGetUsedStyles() throws IOException { - XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("Styles.docx"); - List testUsedStyleList = new ArrayList(); - XWPFStyles styles = sampleDoc.getStyles(); - XWPFStyle style = styles.getStyle("berschrift1"); - testUsedStyleList.add(style); - testUsedStyleList.add(styles.getStyle("Standard")); - testUsedStyleList.add(styles.getStyle("berschrift1Zchn")); - testUsedStyleList.add(styles.getStyle("Absatz-Standardschriftart")); - style.hasSameName(style); - - List usedStyleList = styles.getUsedStyleList(style); - assertEquals(usedStyleList, testUsedStyleList); - - - } - - public void testAddStylesToDocument() throws IOException { - XWPFDocument docOut = new XWPFDocument(); - XWPFStyles styles = docOut.createStyles(); - - String strStyleId = "headline1"; - CTStyle ctStyle = CTStyle.Factory.newInstance(); - - ctStyle.setStyleId(strStyleId); - XWPFStyle s = new XWPFStyle(ctStyle); - styles.addStyle(s); - - assertTrue(styles.styleExist(strStyleId)); - - XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); - - styles = docIn.getStyles(); - assertTrue(styles.styleExist(strStyleId)); - } - - /** - * Bug #52449 - We should be able to write a file containing - * both regular and glossary styles without error - */ - public void test52449() throws Exception { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52449.docx"); - XWPFStyles styles = doc.getStyles(); - assertNotNull(styles); - - XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(doc); - styles = docIn.getStyles(); - assertNotNull(styles); - } - - - /** - * YK: tests below don't make much sense, - * they exist only to copy xml beans to pi-ooxml-schemas.jar - */ - public void testLanguages() { - XWPFDocument docOut = new XWPFDocument(); - XWPFStyles styles = docOut.createStyles(); - styles.setEastAsia("Chinese"); + assertTrue(styles.styleExist(strStyleId)); + + XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); + + styles = docIn.getStyles(); + assertTrue(styles.styleExist(strStyleId)); + } + + /** + * Bug #52449 - We should be able to write a file containing + * both regular and glossary styles without error + */ + public void test52449() throws Exception { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52449.docx"); + XWPFStyles styles = doc.getStyles(); + assertNotNull(styles); + + XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(doc); + styles = docIn.getStyles(); + assertNotNull(styles); + } + + + /** + * YK: tests below don't make much sense, + * they exist only to copy xml beans to pi-ooxml-schemas.jar + */ + @SuppressWarnings("resource") + public void testLanguages() { + XWPFDocument docOut = new XWPFDocument(); + XWPFStyles styles = docOut.createStyles(); + styles.setEastAsia("Chinese"); styles.setSpellingLanguage("English"); @@ -115,82 +110,82 @@ public class TestXWPFStyles extends TestCase { CTLsdException ex = latentStyles.addNewLsdException(); ex.setName("ex1"); XWPFLatentStyles ls = new XWPFLatentStyles(latentStyles); - assertEquals(true, ls.isLatentStyle("ex1")); - assertEquals(false, ls.isLatentStyle("notex1")); - } - - public void testSetStyles_Bug57254() throws IOException { - XWPFDocument docOut = new XWPFDocument(); - XWPFStyles styles = docOut.createStyles(); + assertEquals(true, ls.isLatentStyle("ex1")); + assertEquals(false, ls.isLatentStyle("notex1")); + } + + public void testSetStyles_Bug57254() throws IOException { + XWPFDocument docOut = new XWPFDocument(); + XWPFStyles styles = docOut.createStyles(); CTStyles ctStyles = CTStyles.Factory.newInstance(); String strStyleId = "headline1"; CTStyle ctStyle = ctStyles.addNewStyle(); - - ctStyle.setStyleId(strStyleId); - styles.setStyles(ctStyles); - - assertTrue(styles.styleExist(strStyleId)); - - XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); - - styles = docIn.getStyles(); - assertTrue(styles.styleExist(strStyleId)); - } - - public void testEasyAccessToStyles() throws IOException { - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx"); - XWPFStyles styles = doc.getStyles(); - assertNotNull(styles); - - // Has 3 paragraphs on page one, a break, and 3 on page 2 - assertEquals(7, doc.getParagraphs().size()); - - // Check the first three have no run styles, just default paragraph style - for (int i = 0; i < 3; i++) { - XWPFParagraph p = doc.getParagraphs().get(i); - assertEquals(null, p.getStyle()); - assertEquals(null, p.getStyleID()); - assertEquals(1, p.getRuns().size()); - - XWPFRun r = p.getRuns().get(0); - assertEquals(null, r.getColor()); - assertEquals(null, r.getFontFamily()); - assertEquals(null, r.getFontName()); - assertEquals(-1, r.getFontSize()); - } - - // On page two, has explicit styles, but on runs not on - // the paragraph itself - for (int i = 4; i < 7; i++) { - XWPFParagraph p = doc.getParagraphs().get(i); - assertEquals(null, p.getStyle()); - assertEquals(null, p.getStyleID()); - assertEquals(1, p.getRuns().size()); - - XWPFRun r = p.getRuns().get(0); - assertEquals("Arial Black", r.getFontFamily()); - assertEquals("Arial Black", r.getFontName()); - assertEquals(16, r.getFontSize()); - assertEquals("548DD4", r.getColor()); - } - - // Check the document styles - // Should have a style defined for each type - assertEquals(4, styles.getNumberOfStyles()); + + ctStyle.setStyleId(strStyleId); + styles.setStyles(ctStyles); + + assertTrue(styles.styleExist(strStyleId)); + + XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut); + + styles = docIn.getStyles(); + assertTrue(styles.styleExist(strStyleId)); + } + + public void testEasyAccessToStyles() throws IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx"); + XWPFStyles styles = doc.getStyles(); + assertNotNull(styles); + + // Has 3 paragraphs on page one, a break, and 3 on page 2 + assertEquals(7, doc.getParagraphs().size()); + + // Check the first three have no run styles, just default paragraph style + for (int i = 0; i < 3; i++) { + XWPFParagraph p = doc.getParagraphs().get(i); + assertEquals(null, p.getStyle()); + assertEquals(null, p.getStyleID()); + assertEquals(1, p.getRuns().size()); + + XWPFRun r = p.getRuns().get(0); + assertEquals(null, r.getColor()); + assertEquals(null, r.getFontFamily()); + assertEquals(null, r.getFontName()); + assertEquals(-1, r.getFontSize()); + } + + // On page two, has explicit styles, but on runs not on + // the paragraph itself + for (int i = 4; i < 7; i++) { + XWPFParagraph p = doc.getParagraphs().get(i); + assertEquals(null, p.getStyle()); + assertEquals(null, p.getStyleID()); + assertEquals(1, p.getRuns().size()); + + XWPFRun r = p.getRuns().get(0); + assertEquals("Arial Black", r.getFontFamily()); + assertEquals("Arial Black", r.getFontName()); + assertEquals(16, r.getFontSize()); + assertEquals("548DD4", r.getColor()); + } + + // Check the document styles + // Should have a style defined for each type + assertEquals(4, styles.getNumberOfStyles()); assertNotNull(styles.getStyle("Normal")); - assertNotNull(styles.getStyle("DefaultParagraphFont")); - assertNotNull(styles.getStyle("TableNormal")); - assertNotNull(styles.getStyle("NoList")); - - // We can't do much yet with latent styles - assertEquals(137, styles.getLatentStyles().getNumberOfStyles()); - - // Check the default styles - assertNotNull(styles.getDefaultRunStyle()); - assertNotNull(styles.getDefaultParagraphStyle()); - - assertEquals(11, styles.getDefaultRunStyle().getFontSize()); - assertEquals(200, styles.getDefaultParagraphStyle().getSpacingAfter()); - } + assertNotNull(styles.getStyle("DefaultParagraphFont")); + assertNotNull(styles.getStyle("TableNormal")); + assertNotNull(styles.getStyle("NoList")); + + // We can't do much yet with latent styles + assertEquals(137, styles.getLatentStyles().getNumberOfStyles()); + + // Check the default styles + assertNotNull(styles.getDefaultRunStyle()); + assertNotNull(styles.getDefaultParagraphStyle()); + + assertEquals(11, styles.getDefaultRunStyle().getFontSize()); + assertEquals(200, styles.getDefaultParagraphStyle().getSpacingAfter()); + } } diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java index 6f85a05cf0..b4687b36fb 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java @@ -17,12 +17,12 @@ package org.apache.poi.xwpf.usermodel; import java.math.BigInteger; -import java.util.List; - -import junit.framework.TestCase; -import org.apache.poi.xwpf.XWPFTestDataSamples; -import org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; +import java.util.List; + +import junit.framework.TestCase; +import org.apache.poi.xwpf.XWPFTestDataSamples; +import org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl; @@ -34,10 +34,9 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder; /** - * Tests for XWPF Run + * Tests for XWPF Tables */ public class TestXWPFTable extends TestCase { - protected void setUp() { /* XWPFDocument doc = new XWPFDocument(); @@ -121,13 +120,13 @@ public class TestXWPFTable extends TestCase { assertEquals(1, xtab.getCTTbl().getTrArray(0).sizeOfTcArray()); } - - public void testSetGetWidth() { - XWPFDocument doc = new XWPFDocument(); - - CTTbl table = CTTbl.Factory.newInstance(); - table.addNewTblPr().addNewTblW().setW(new BigInteger("1000")); - + + public void testSetGetWidth() { + XWPFDocument doc = new XWPFDocument(); + + CTTbl table = CTTbl.Factory.newInstance(); + table.addNewTblPr().addNewTblW().setW(new BigInteger("1000")); + XWPFTable xtab = new XWPFTable(table, doc); assertEquals(1000, xtab.getWidth()); @@ -145,20 +144,20 @@ public class TestXWPFTable extends TestCase { XWPFTableRow row = xtab.createRow(); row.setHeight(20); assertEquals(20, row.getHeight()); - } - - public void testSetGetMargins() { - // instantiate the following class so it'll get picked up by - // the XmlBean process and added to the jar file. it's required - // for the following XWPFTable methods. - CTTblCellMar ctm = CTTblCellMar.Factory.newInstance(); - assertNotNull(ctm); - // create a table - XWPFDocument doc = new XWPFDocument(); - CTTbl ctTable = CTTbl.Factory.newInstance(); - XWPFTable table = new XWPFTable(ctTable, doc); - // set margins - table.setCellMargins(50, 50, 250, 450); + } + + public void testSetGetMargins() { + // instantiate the following class so it'll get picked up by + // the XmlBean process and added to the jar file. it's required + // for the following XWPFTable methods. + CTTblCellMar ctm = CTTblCellMar.Factory.newInstance(); + assertNotNull(ctm); + // create a table + XWPFDocument doc = new XWPFDocument(); + CTTbl ctTable = CTTbl.Factory.newInstance(); + XWPFTable table = new XWPFTable(ctTable, doc); + // set margins + table.setCellMargins(50, 50, 250, 450); // get margin components int t = table.getCellMarginTop(); assertEquals(50, t); @@ -168,22 +167,22 @@ public class TestXWPFTable extends TestCase { assertEquals(250, b); int r = table.getCellMarginRight(); assertEquals(450, r); - } - - public void testSetGetHBorders() { - // instantiate the following classes so they'll get picked up by - // the XmlBean process and added to the jar file. they are required - // for the following XWPFTable methods. - CTTblBorders cttb = CTTblBorders.Factory.newInstance(); - assertNotNull(cttb); - STBorder stb = STBorder.Factory.newInstance(); - assertNotNull(stb); - // create a table - XWPFDocument doc = new XWPFDocument(); - CTTbl ctTable = CTTbl.Factory.newInstance(); - XWPFTable table = new XWPFTable(ctTable, doc); - // set inside horizontal border - table.setInsideHBorder(XWPFBorderType.SINGLE, 4, 0, "FF0000"); + } + + public void testSetGetHBorders() { + // instantiate the following classes so they'll get picked up by + // the XmlBean process and added to the jar file. they are required + // for the following XWPFTable methods. + CTTblBorders cttb = CTTblBorders.Factory.newInstance(); + assertNotNull(cttb); + STBorder stb = STBorder.Factory.newInstance(); + assertNotNull(stb); + // create a table + XWPFDocument doc = new XWPFDocument(); + CTTbl ctTable = CTTbl.Factory.newInstance(); + XWPFTable table = new XWPFTable(ctTable, doc); + // set inside horizontal border + table.setInsideHBorder(XWPFBorderType.SINGLE, 4, 0, "FF0000"); // get inside horizontal border components int s = table.getInsideHBorderSize(); assertEquals(4, s); @@ -193,26 +192,26 @@ public class TestXWPFTable extends TestCase { assertEquals("FF0000", clr); XWPFBorderType bt = table.getInsideHBorderType(); assertEquals(XWPFBorderType.SINGLE, bt); - } - - public void testSetGetVBorders() { - // create a table - XWPFDocument doc = new XWPFDocument(); - CTTbl ctTable = CTTbl.Factory.newInstance(); - XWPFTable table = new XWPFTable(ctTable, doc); + } + + public void testSetGetVBorders() { + // create a table + XWPFDocument doc = new XWPFDocument(); + CTTbl ctTable = CTTbl.Factory.newInstance(); + XWPFTable table = new XWPFTable(ctTable, doc); // set inside vertical border table.setInsideVBorder(XWPFBorderType.DOUBLE, 4, 0, "00FF00"); // get inside vertical border components XWPFBorderType bt = table.getInsideVBorderType(); assertEquals(XWPFBorderType.DOUBLE, bt); int sz = table.getInsideVBorderSize(); - assertEquals(4, sz); - int sp = table.getInsideVBorderSpace(); - assertEquals(0, sp); - String clr = table.getInsideVBorderColor(); - assertEquals("00FF00", clr); - } - + assertEquals(4, sz); + int sp = table.getInsideVBorderSpace(); + assertEquals(0, sp); + String clr = table.getInsideVBorderColor(); + assertEquals("00FF00", clr); + } + public void testSetGetRowBandSize() { XWPFDocument doc = new XWPFDocument(); CTTbl ctTable = CTTbl.Factory.newInstance(); @@ -229,30 +228,30 @@ public class TestXWPFTable extends TestCase { table.setColBandSize(16); int sz = table.getColBandSize(); assertEquals(16, sz); - } - - public void testCreateTable() throws Exception { - // open an empty document - XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); - - // create a table with 5 rows and 7 columns - int noRows = 5; - int noCols = 7; - XWPFTable table = doc.createTable(noRows, noCols); - - // assert the table is empty - List rows = table.getRows(); - assertEquals("Table has less rows than requested.", noRows, rows.size()); - for (XWPFTableRow xwpfRow : rows) { - assertNotNull(xwpfRow); - for (int i = 0; i < 7; i++) { - XWPFTableCell xwpfCell = xwpfRow.getCell(i); - assertNotNull(xwpfCell); - assertEquals("Empty cells should not have one paragraph.", 1, xwpfCell.getParagraphs().size()); - xwpfCell = xwpfRow.getCell(i); - assertEquals("Calling 'getCell' must not modify cells content.", 1, xwpfCell.getParagraphs().size()); - } - } - doc.getPackage().revert(); - } + } + + public void testCreateTable() throws Exception { + // open an empty document + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); + + // create a table with 5 rows and 7 columns + int noRows = 5; + int noCols = 7; + XWPFTable table = doc.createTable(noRows, noCols); + + // assert the table is empty + List rows = table.getRows(); + assertEquals("Table has less rows than requested.", noRows, rows.size()); + for (XWPFTableRow xwpfRow : rows) { + assertNotNull(xwpfRow); + for (int i = 0; i < 7; i++) { + XWPFTableCell xwpfCell = xwpfRow.getCell(i); + assertNotNull(xwpfCell); + assertEquals("Empty cells should not have one paragraph.", 1, xwpfCell.getParagraphs().size()); + xwpfCell = xwpfRow.getCell(i); + assertEquals("Calling 'getCell' must not modify cells content.", 1, xwpfCell.getParagraphs().size()); + } + } + doc.getPackage().revert(); + } } \ No newline at end of file diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java index 34d54c0410..f793742c3f 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java @@ -17,80 +17,81 @@ * ==================================================================== */ -package org.apache.poi.xwpf.usermodel; - -import junit.framework.TestCase; -import org.apache.poi.xwpf.usermodel.XWPFTableCell.XWPFVertAlign; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHMerge; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcBorders; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVMerge; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc; - -public class TestXWPFTableCell extends TestCase { - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testSetGetVertAlignment() throws Exception { - // instantiate the following classes so they'll get picked up by - // the XmlBean process and added to the jar file. they are required - // for the following XWPFTableCell methods. - CTShd ctShd = CTShd.Factory.newInstance(); - assertNotNull(ctShd); - CTVerticalJc ctVjc = CTVerticalJc.Factory.newInstance(); - assertNotNull(ctVjc); - STShd stShd = STShd.Factory.newInstance(); - assertNotNull(stShd); - STVerticalJc stVjc = STVerticalJc.Factory.newInstance(); - assertNotNull(stVjc); - - // create a table - XWPFDocument doc = new XWPFDocument(); - CTTbl ctTable = CTTbl.Factory.newInstance(); - XWPFTable table = new XWPFTable(ctTable, doc); - // table has a single row by default; grab it - XWPFTableRow tr = table.getRow(0); +package org.apache.poi.xwpf.usermodel; + +import junit.framework.TestCase; + +import org.apache.poi.xwpf.usermodel.XWPFTableCell.XWPFVertAlign; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHMerge; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcBorders; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVMerge; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc; + +public class TestXWPFTableCell extends TestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + public void testSetGetVertAlignment() throws Exception { + // instantiate the following classes so they'll get picked up by + // the XmlBean process and added to the jar file. they are required + // for the following XWPFTableCell methods. + CTShd ctShd = CTShd.Factory.newInstance(); + assertNotNull(ctShd); + CTVerticalJc ctVjc = CTVerticalJc.Factory.newInstance(); + assertNotNull(ctVjc); + STShd stShd = STShd.Factory.newInstance(); + assertNotNull(stShd); + STVerticalJc stVjc = STVerticalJc.Factory.newInstance(); + assertNotNull(stVjc); + + // create a table + XWPFDocument doc = new XWPFDocument(); + CTTbl ctTable = CTTbl.Factory.newInstance(); + XWPFTable table = new XWPFTable(ctTable, doc); + // table has a single row by default; grab it + XWPFTableRow tr = table.getRow(0); assertNotNull(tr); // row has a single cell by default; grab it XWPFTableCell cell = tr.getCell(0); - cell.setVerticalAlignment(XWPFVertAlign.BOTH); - XWPFVertAlign al = cell.getVerticalAlignment(); - assertEquals(XWPFVertAlign.BOTH, al); - } - - public void testSetGetColor() throws Exception { - // create a table - XWPFDocument doc = new XWPFDocument(); - CTTbl ctTable = CTTbl.Factory.newInstance(); - XWPFTable table = new XWPFTable(ctTable, doc); - // table has a single row by default; grab it - XWPFTableRow tr = table.getRow(0); + cell.setVerticalAlignment(XWPFVertAlign.BOTH); + XWPFVertAlign al = cell.getVerticalAlignment(); + assertEquals(XWPFVertAlign.BOTH, al); + } + + public void testSetGetColor() throws Exception { + // create a table + XWPFDocument doc = new XWPFDocument(); + CTTbl ctTable = CTTbl.Factory.newInstance(); + XWPFTable table = new XWPFTable(ctTable, doc); + // table has a single row by default; grab it + XWPFTableRow tr = table.getRow(0); assertNotNull(tr); // row has a single cell by default; grab it XWPFTableCell cell = tr.getCell(0); - cell.setColor("F0000F"); - String clr = cell.getColor(); - assertEquals("F0000F", clr); - } - - /** - * ensure that CTHMerge & CTTcBorders go in poi-ooxml.jar - */ - public void test54099() { - XWPFDocument doc = new XWPFDocument(); - CTTbl ctTable = CTTbl.Factory.newInstance(); - XWPFTable table = new XWPFTable(ctTable, doc); + cell.setColor("F0000F"); + String clr = cell.getColor(); + assertEquals("F0000F", clr); + } + + /** + * ensure that CTHMerge & CTTcBorders go in poi-ooxml.jar + */ + @SuppressWarnings("unused") + public void test54099() { + XWPFDocument doc = new XWPFDocument(); + CTTbl ctTable = CTTbl.Factory.newInstance(); + XWPFTable table = new XWPFTable(ctTable, doc); XWPFTableRow tr = table.getRow(0); XWPFTableCell cell = tr.getCell(0); 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 b01f8e9dc4..b22f1a0cb7 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java @@ -15,54 +15,53 @@ limitations under the License. ==================================================================== */ -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; - -public class TestXWPFTableRow extends TestCase { - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testCreateRow() throws Exception { - CTRow ctRow = CTRow.Factory.newInstance(); - assertNotNull(ctRow); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void testSetGetCantSplitRow() { - // create a table - XWPFDocument doc = new XWPFDocument(); - CTTbl ctTable = CTTbl.Factory.newInstance(); - XWPFTable table = new XWPFTable(ctTable, doc); - // table has a single row by default; grab it - XWPFTableRow tr = table.getRow(0); - assertNotNull(tr); - - tr.setCantSplitRow(true); - boolean isCant = tr.isCantSplitRow(); - assert (isCant); - } - - public void testSetGetRepeatHeader() { - // create a table - XWPFDocument doc = new XWPFDocument(); - CTTbl ctTable = CTTbl.Factory.newInstance(); - XWPFTable table = new XWPFTable(ctTable, doc); - // table has a single row by default; grab it - XWPFTableRow tr = table.getRow(0); - assertNotNull(tr); - - tr.setRepeatHeader(true); - boolean isRpt = tr.isRepeatHeader(); - assert (isRpt); - } -} +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; + +public class TestXWPFTableRow extends TestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + public void testCreateRow() throws Exception { + CTRow ctRow = CTRow.Factory.newInstance(); + assertNotNull(ctRow); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testSetGetCantSplitRow() { + // create a table + XWPFDocument doc = new XWPFDocument(); + CTTbl ctTable = CTTbl.Factory.newInstance(); + XWPFTable table = new XWPFTable(ctTable, doc); + // table has a single row by default; grab it + XWPFTableRow tr = table.getRow(0); + assertNotNull(tr); + + tr.setCantSplitRow(true); + boolean isCant = tr.isCantSplitRow(); + assert (isCant); + } + + public void testSetGetRepeatHeader() { + // create a table + XWPFDocument doc = new XWPFDocument(); + CTTbl ctTable = CTTbl.Factory.newInstance(); + XWPFTable table = new XWPFTable(ctTable, doc); + // table has a single row by default; grab it + XWPFTableRow tr = table.getRow(0); + assertNotNull(tr); + + tr.setRepeatHeader(true); + boolean isRpt = tr.isRepeatHeader(); + assert (isRpt); + } +} -- 2.39.5