--- /dev/null
+/*
+ * 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.ss.excelant;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.poi.ss.usermodel.Workbook;
+
+public class MockExcelAntWorkbookHandler implements IExcelAntWorkbookHandler {
+ public static boolean executed = false;
+ public static Workbook workbook = null;
+
+
+ public void setWorkbook(Workbook workbook) {
+ MockExcelAntWorkbookHandler.workbook = workbook;
+ }
+
+ public void execute() {
+ executed = true;
+ assertNotNull(workbook);
+ }
+}
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");\r
}\r
\r
+ public void testEvaluateNoDetails() {\r
+ executeTarget("test-evaluate-nodetails");\r
+ assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");\r
+ assertLogNotContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");\r
+ }\r
+\r
public void testPrecision() {\r
executeTarget("test-precision");\r
\r
assertLogContaining("2/3 tests passed");\r
}\r
\r
+ public void testPrecisionFail() {\r
+ expectSpecificBuildException("test-precision-fails", "precision not matched",\r
+ "\tFailed to evaluate cell 'MortgageCalculator'!$B$4. It evaluated to 2285.5761494145563 when the value of 2285.576149 with precision of 1.0E-10 was expected.");\r
+ }\r
+\r
public void testPassOnError() {\r
executeTarget("test-passonerror");\r
}\r
\r
public void testFailOnError() {\r
expectBuildException("test-failonerror", "fail on error");\r
+ assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");\r
+ assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3");\r
+ }\r
+\r
+ public void testFailOnErrorNoDetails() {\r
+ expectBuildException("test-failonerror-nodetails", "fail on error");\r
+ assertLogNotContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");\r
+ assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3");\r
}\r
\r
public void testUdf() {\r
executeTarget("test-settext");\r
assertLogContaining("1/1 tests passed");\r
}\r
+ \r
+ public void testAddHandler() {\r
+ executeTarget("test-addhandler");\r
+ assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");\r
+ assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");\r
+ \r
+ assertNotNull("The workbook should have been passed to the handler", MockExcelAntWorkbookHandler.workbook);\r
+ assertTrue("The handler should have been executed", MockExcelAntWorkbookHandler.executed);\r
+ }\r
+ \r
+ public void testAddHandlerWrongClass() {\r
+ executeTarget("test-addhandler-wrongclass");\r
+ assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");\r
+ assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");\r
+ }\r
+ \r
+ public void testAddHandlerFails() {\r
+ expectSpecificBuildException("test-addhandler-fails", "NullPointException", null);\r
+ }\r
}\r
</poi:excelant>
</target>
+ <target name="test-evaluate-nodetails">
+ <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls">
+ <poi:test showSuccessDetails="false">
+ <poi:setDouble cell="'MortgageCalculator'!$B$1" value="240000"/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$2" value ="0.11"/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$3" value ="30"/>
+ <poi:evaluate showDelta="true" cell="'MortgageCalculator'!$B$4"
+ expectedValue="2285.576149" precision="1.0E-4" />
+ </poi:test>
+ </poi:excelant>
+ </target>
+
<target name="test-precision">
<poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls">
<poi:precision value="1.0E-4"/>
expectedValue="2285.576149" precision="1.0E-10"/>
</poi:test>
- </poi:excelant>
+ </poi:excelant>
+ </target>
+
+ <target name="test-precision-fails">
+ <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls">
+ <poi:precision value="1.0E-4"/>
+
+ <poi:test name="tiny-precision" showFailureDetail="true" showSuccessDetails="true">
+ <poi:setDouble cell="'MortgageCalculator'!$B$1" value="240000"/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$2" value ="0.11"/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$3" value ="30"/>
+ <poi:evaluate showDelta="true" cell="'MortgageCalculator'!$B$4"
+ expectedValue="2285.576149" precision="1.0E-10" requiredToPass="true"/>
+ </poi:test>
+
+ </poi:excelant>
</target>
<!--
</poi:excelant>
</target>
+ <target name="test-failonerror-notdetails">
+ <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls" failOnError="true">
+
+ <poi:test name="failonerror" showFailureDetail="false" showSuccessDetails="false">
+ <poi:setDouble cell="'MortageCalculatorFunction'!$D$1" value="1"/>
+ <poi:setDouble cell="'MortageCalculatorFunction'!$D$2" value="2"/>
+ <poi:setFormula cell="'MortageCalculatorFunction'!$D$3" value ="SUM(D1:D2)"/>
+ <poi:evaluate showDelta="true" cell="'MortageCalculatorFunction'!$D$3" expectedValue="2"/>
+ </poi:test>
+
+ </poi:excelant>
+ </target>
+
<!-- Evaluation of user-defined functions -->
<target name="test-udf">
<poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls">
</poi:excelant>
</target>
+ <target name="test-addhandler">
+ <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls">
+ <poi:test showSuccessDetails="true">
+ <poi:handler className="org.apache.poi.ss.excelant.MockExcelAntWorkbookHandler"/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$1" value="240000"/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$2" value ="0.11"/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$3" value ="30"/>
+ <poi:evaluate showDelta="true" cell="'MortgageCalculator'!$B$4"
+ expectedValue="2285.576149" precision="1.0E-4" />
+ </poi:test>
+ </poi:excelant>
+ </target>
+
+ <target name="test-addhandler-wrongclass">
+ <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls">
+ <poi:test showSuccessDetails="true">
+ <poi:handler className="java.lang.String"/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$1" value="240000"/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$2" value ="0.11"/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$3" value ="30"/>
+ <poi:evaluate showDelta="true" cell="'MortgageCalculator'!$B$4"
+ expectedValue="2285.576149" precision="1.0E-4" />
+ </poi:test>
+ </poi:excelant>
+ </target>
+
+ <target name="test-addhandler-fails">
+ <poi:excelant fileName="${data.dir.name}/spreadsheet/excelant.xls">
+ <poi:test showSuccessDetails="true">
+ <poi:handler/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$1" value="240000"/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$2" value ="0.11"/>
+ <poi:setDouble cell="'MortgageCalculator'!$B$3" value ="30"/>
+ <poi:evaluate showDelta="true" cell="'MortgageCalculator'!$B$4"
+ expectedValue="2285.576149" precision="1.0E-4" />
+ </poi:test>
+ </poi:excelant>
+ </target>
</project>
import static junit.framework.TestCase.assertTrue;
import static org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook;
import static org.apache.poi.xssf.XSSFTestDataSamples.writeOutAndReadBack;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
+import org.apache.poi.POIXMLException;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.crypt.CryptoFunctions;
import org.apache.poi.poifs.crypt.HashAlgorithm;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
import org.junit.Test;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetData;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCalcMode;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
@SuppressWarnings("resource")
assertEquals(2 + 1, colArray[0].getMin()); // 1 based
assertEquals(7 + 1, colArray[0].getMax()); // 1 based
assertEquals(1, colArray[0].getOutlineLevel());
+ assertEquals(0, sheet.getColumnOutlineLevel(0));
//two level
sheet.groupColumn(1, 2);
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sheet 1");
+ assertFalse(sheet.getForceFormulaRecalculation());
+
// Set
sheet.setForceFormulaRecalculation(true);
assertEquals(true, sheet.getForceFormulaRecalculation());
}
fail();
}
+
+ @Test
+ public void testReadFails() {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
+
+ try {
+ sheet.onDocumentRead();
+ fail("Throws exception because we cannot read here");
+ } catch (POIXMLException e) {
+ // expected here
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void testCreateComment() {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
+ assertNotNull(sheet.createComment());
+ }
+
+ @Test
+ public void testRightToLeft() {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
+
+ assertFalse(sheet.isRightToLeft());
+ sheet.setRightToLeft(true);
+ assertTrue(sheet.isRightToLeft());
+ sheet.setRightToLeft(false);
+ assertFalse(sheet.isRightToLeft());
+ }
}
\ No newline at end of file
--- /dev/null
+/* ====================================================================
+ 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.xssf.usermodel;
+
+import static org.junit.Assert.*;
+
+import java.awt.Color;
+import java.io.IOException;
+import java.util.List;
+
+import org.junit.Test;
+
+public class TestXSSFTextRun {
+ @Test
+ public void testXSSFTextParagraph() throws IOException {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ try {
+ XSSFSheet sheet = wb.createSheet();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+
+ XSSFTextBox shape = drawing.createTextbox(new XSSFClientAnchor(0, 0, 0, 0, 2, 2, 3, 4));
+
+ XSSFTextParagraph para = shape.addNewTextParagraph();
+ para.addNewTextRun().setText("Line 1");
+
+ List<XSSFTextRun> runs = para.getTextRuns();
+ assertEquals(1, runs.size());
+ XSSFTextRun run = runs.get(0);
+ assertEquals("Line 1", run.getText());
+
+ assertNotNull(run.getParentParagraph());
+ assertNotNull(run.getXmlObject());
+ assertNotNull(run.getRPr());
+
+ assertEquals(new Color(0,0,0), run.getFontColor());
+
+ Color color = new Color(0, 255, 255);
+ run.setFontColor(color);
+ assertEquals(color, run.getFontColor());
+
+ assertEquals(11.0, run.getFontSize(), 0.01);
+ run.setFontSize(12.32);
+ assertEquals(12.32, run.getFontSize(), 0.01);
+ run.setFontSize(-1.0);
+ assertEquals(11.0, run.getFontSize(), 0.01);
+ run.setFontSize(-1.0);
+ assertEquals(11.0, run.getFontSize(), 0.01);
+ try {
+ run.setFontSize(0.9);
+ fail("Should fail");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("0.9"));
+ }
+ assertEquals(11.0, run.getFontSize(), 0.01);
+
+ assertEquals(0.0, run.getCharacterSpacing(), 0.01);
+ run.setCharacterSpacing(12.31);
+ assertEquals(12.31, run.getCharacterSpacing(), 0.01);
+ run.setCharacterSpacing(0.0);
+ assertEquals(0.0, run.getCharacterSpacing(), 0.01);
+ run.setCharacterSpacing(0.0);
+ assertEquals(0.0, run.getCharacterSpacing(), 0.01);
+
+ assertEquals("Calibri", run.getFontFamily());
+ run.setFontFamily("Arial", (byte)1, (byte)1, false);
+ assertEquals("Arial", run.getFontFamily());
+ run.setFontFamily("Arial", (byte)-1, (byte)1, false);
+ assertEquals("Arial", run.getFontFamily());
+ run.setFontFamily("Arial", (byte)1, (byte)-1, false);
+ assertEquals("Arial", run.getFontFamily());
+ run.setFontFamily("Arial", (byte)1, (byte)1, true);
+ assertEquals("Arial", run.getFontFamily());
+ run.setFontFamily(null, (byte)1, (byte)1, false);
+ assertEquals("Calibri", run.getFontFamily());
+ run.setFontFamily(null, (byte)1, (byte)1, false);
+ assertEquals("Calibri", run.getFontFamily());
+
+ run.setFont("Arial");
+ assertEquals("Arial", run.getFontFamily());
+
+ assertEquals((byte)0, run.getPitchAndFamily());
+ run.setFont(null);
+ assertEquals((byte)0, run.getPitchAndFamily());
+
+ assertFalse(run.isStrikethrough());
+ run.setStrikethrough(true);
+ assertTrue(run.isStrikethrough());
+ run.setStrikethrough(false);
+ assertFalse(run.isStrikethrough());
+
+ assertFalse(run.isSuperscript());
+ run.setSuperscript(true);
+ assertTrue(run.isSuperscript());
+ run.setSuperscript(false);
+ assertFalse(run.isSuperscript());
+
+ assertFalse(run.isSubscript());
+ run.setSubscript(true);
+ assertTrue(run.isSubscript());
+ run.setSubscript(false);
+ assertFalse(run.isSubscript());
+
+ assertEquals(TextCap.NONE, run.getTextCap());
+
+ assertFalse(run.isBold());
+ run.setBold(true);
+ assertTrue(run.isBold());
+ run.setBold(false);
+ assertFalse(run.isBold());
+
+ assertFalse(run.isItalic());
+ run.setItalic(true);
+ assertTrue(run.isItalic());
+ run.setItalic(false);
+ assertFalse(run.isItalic());
+
+ assertFalse(run.isUnderline());
+ run.setUnderline(true);
+ assertTrue(run.isUnderline());
+ run.setUnderline(false);
+ assertFalse(run.isUnderline());
+
+ assertNotNull(run.toString());
+ } finally {
+ wb.close();
+ }
+ }
+}
import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
import org.openxmlformats.schemas.drawingml.x2006.picture.PicDocument;
import org.openxmlformats.schemas.drawingml.x2006.picture.impl.PicDocumentImpl;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPBdr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextAlignment;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
/**
* Tests for XWPF Paragraphs
r.getCTR().getDrawingArray(0).getInlineArray(0).getGraphic();
r.getCTR().getDrawingArray(0).getInlineArray(0).getGraphic().getGraphicData();
PicDocument pd = new PicDocumentImpl(null);
+ assertTrue(pd.isNil());
}
public void testTika792() throws Exception{
XWPFParagraph paragraph = doc.getParagraphs().get(0);
assertEquals("s", paragraph.getText());
}
- }
+
+ public void testSettersGetters() {
+ XWPFDocument doc = new XWPFDocument();
+ XWPFParagraph p = doc.createParagraph();
+
+ assertTrue(p.isEmpty());
+ assertFalse(p.removeRun(0));
+
+ p.setBorderTop(Borders.BABY_PACIFIER);
+ p.setBorderBetween(Borders.BABY_PACIFIER);
+ p.setBorderBottom(Borders.BABY_RATTLE);
+
+ assertNotNull(p.getIRuns());
+ assertEquals(0, p.getIRuns().size());
+ assertFalse(p.isEmpty());
+ assertNull(p.getStyleID());
+ assertNull(p.getStyle());
+
+ assertNull(p.getNumID());
+ p.setNumID(BigInteger.valueOf(12));
+ assertEquals(BigInteger.valueOf(12), p.getNumID());
+ p.setNumID(BigInteger.valueOf(13));
+ assertEquals(BigInteger.valueOf(13), p.getNumID());
+
+ assertNull(p.getNumFmt());
+
+ assertNull(p.getNumIlvl());
+
+ assertEquals("", p.getParagraphText());
+ assertEquals("", p.getPictureText());
+ assertEquals("", p.getFootnoteText());
+
+ p.setBorderBetween(Borders.NONE);
+ assertEquals(Borders.NONE, p.getBorderBetween());
+ p.setBorderBetween(Borders.BASIC_BLACK_DASHES);
+ assertEquals(Borders.BASIC_BLACK_DASHES, p.getBorderBetween());
+
+ p.setBorderBottom(Borders.NONE);
+ assertEquals(Borders.NONE, p.getBorderBottom());
+ p.setBorderBottom(Borders.BABY_RATTLE);
+ assertEquals(Borders.BABY_RATTLE, p.getBorderBottom());
+
+ p.setBorderLeft(Borders.NONE);
+ assertEquals(Borders.NONE, p.getBorderLeft());
+ p.setBorderLeft(Borders.BASIC_WHITE_SQUARES);
+ assertEquals(Borders.BASIC_WHITE_SQUARES, p.getBorderLeft());
+
+ p.setBorderRight(Borders.NONE);
+ assertEquals(Borders.NONE, p.getBorderRight());
+ p.setBorderRight(Borders.BASIC_WHITE_DASHES);
+ assertEquals(Borders.BASIC_WHITE_DASHES, p.getBorderRight());
+
+ p.setBorderBottom(Borders.NONE);
+ assertEquals(Borders.NONE, p.getBorderBottom());
+ p.setBorderBottom(Borders.BASIC_WHITE_DOTS);
+ assertEquals(Borders.BASIC_WHITE_DOTS, p.getBorderBottom());
+
+ assertFalse(p.isPageBreak());
+ p.setPageBreak(true);
+ assertTrue(p.isPageBreak());
+ p.setPageBreak(false);
+ assertFalse(p.isPageBreak());
+
+ assertEquals(-1, p.getSpacingAfter());
+ p.setSpacingAfter(12);
+ assertEquals(12, p.getSpacingAfter());
+
+ assertEquals(-1, p.getSpacingAfterLines());
+ p.setSpacingAfterLines(14);
+ assertEquals(14, p.getSpacingAfterLines());
+
+ assertEquals(-1, p.getSpacingBefore());
+ p.setSpacingBefore(16);
+ assertEquals(16, p.getSpacingBefore());
+
+ assertEquals(-1, p.getSpacingBeforeLines());
+ p.setSpacingBeforeLines(18);
+ assertEquals(18, p.getSpacingBeforeLines());
+
+ assertEquals(LineSpacingRule.AUTO, p.getSpacingLineRule());
+ p.setSpacingLineRule(LineSpacingRule.EXACT);
+ assertEquals(LineSpacingRule.EXACT, p.getSpacingLineRule());
+
+ assertEquals(-1, p.getIndentationLeft());
+ p.setIndentationLeft(21);
+ assertEquals(21, p.getIndentationLeft());
+
+ assertEquals(-1, p.getIndentationRight());
+ p.setIndentationRight(25);
+ assertEquals(25, p.getIndentationRight());
+
+ assertEquals(-1, p.getIndentationHanging());
+ p.setIndentationHanging(25);
+ assertEquals(25, p.getIndentationHanging());
+
+ assertEquals(-1, p.getIndentationFirstLine());
+ p.setIndentationFirstLine(25);
+ assertEquals(25, p.getIndentationFirstLine());
+
+ assertFalse(p.isWordWrap());
+ p.setWordWrap(true);
+ assertTrue(p.isWordWrap());
+ p.setWordWrap(false);
+ assertFalse(p.isWordWrap());
+
+ assertNull(p.getStyle());
+ p.setStyle("teststyle");
+ assertEquals("teststyle", p.getStyle());
+
+ p.addRun(CTR.Factory.newInstance());
+
+ //assertTrue(p.removeRun(0));
+
+ assertNotNull(p.getBody());
+ assertEquals(BodyElementType.PARAGRAPH, p.getElementType());
+ assertEquals(BodyType.DOCUMENT, p.getPartType());
+ }
+
+ public void testSearchTextNotFound() {
+ XWPFDocument doc = new XWPFDocument();
+ XWPFParagraph p = doc.createParagraph();
+
+ assertNull(p.searchText("test", new PositionInParagraph()));
+ assertEquals("", p.getText());
+ }
+
+ public void testSearchTextFound() throws IOException {
+ XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
+
+ List<XWPFParagraph> ps = xml.getParagraphs();
+ assertEquals(10, ps.size());
+
+ XWPFParagraph p = ps.get(0);
+
+ TextSegement segment = p.searchText("sample word document", new PositionInParagraph());
+ assertNotNull(segment);
+
+ assertEquals("sample word document", p.getText(segment));
+
+ assertTrue(p.removeRun(0));
+ }
+
+ @SuppressWarnings("deprecation")
+ public void testRuns() {
+ XWPFDocument doc = new XWPFDocument();
+ XWPFParagraph p = doc.createParagraph();
+
+ CTR run = CTR.Factory.newInstance();
+ XWPFRun r = new XWPFRun(run, doc.createParagraph());
+ p.addRun(r);
+ p.addRun(r);
+
+ assertNotNull(p.getRun(run));
+ assertNull(p.getRun(null));
+ }
+}
--- /dev/null
+/* ====================================================================
+ 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.hslf.model;
+
+import org.apache.poi.hslf.record.StyleTextPropAtom;
+import org.apache.poi.hslf.record.TextCharsAtom;
+import org.apache.poi.hslf.record.TextHeaderAtom;
+import org.apache.poi.hslf.usermodel.SlideShow;
+import org.apache.poi.hssf.usermodel.DummyGraphics2d;
+import org.junit.Test;
+
+
+public class TextPainterTest {
+ @Test
+ public void testTextPainter() {
+ TextShape shape = new Polygon();
+ TextPainter painter = new TextPainter(shape);
+ painter.getAttributedString(new TextRun(null, new TextCharsAtom(), null));
+ painter.paint(new DummyGraphics2d());
+ painter.getTextElements((float)1.0, null);
+ }
+
+ @Test
+ public void testTextPainterWithText() {
+ TextShape shape = new Polygon();
+ TextPainter painter = new TextPainter(shape);
+ TextCharsAtom tca = new TextCharsAtom();
+ tca.setText("some text to read");
+ TextRun txrun = new TextRun(new TextHeaderAtom(), tca, new StyleTextPropAtom(10));
+ Slide sheet = new Slide(1, 1, 1);
+ sheet.setSlideShow(new SlideShow());
+ txrun.setSheet(sheet);
+
+ painter.getAttributedString(txrun, new DummyGraphics2d());
+ painter.paint(new DummyGraphics2d());
+ painter.getTextElements((float)1.0, null);
+ }
+}