Browse Source

Add unit tests for XSSFTextRun and TextPainter, slightly more tests for XSSFSheet and enhance unit tests for XWPFParagraph and ExcelAntTest

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1649309 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_12_BETA1
Dominik Stadler 9 years ago
parent
commit
e8317cea56

+ 37
- 0
src/excelant/testcases/org/apache/poi/ss/excelant/MockExcelAntWorkbookHandler.java View File

@@ -0,0 +1,37 @@
/*
* 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);
}
}

+ 38
- 0
src/excelant/testcases/org/apache/poi/ss/excelant/TestBuildFile.java View File

@@ -48,6 +48,12 @@ public class TestBuildFile extends BuildFileTest {
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
}
public void testEvaluateNoDetails() {
executeTarget("test-evaluate-nodetails");
assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
assertLogNotContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
}
public void testPrecision() {
executeTarget("test-precision");
@@ -61,12 +67,25 @@ public class TestBuildFile extends BuildFileTest {
assertLogContaining("2/3 tests passed");
}
public void testPrecisionFail() {
expectSpecificBuildException("test-precision-fails", "precision not matched",
"\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.");
}
public void testPassOnError() {
executeTarget("test-passonerror");
}
public void testFailOnError() {
expectBuildException("test-failonerror", "fail on error");
assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3");
}
public void testFailOnErrorNoDetails() {
expectBuildException("test-failonerror-nodetails", "fail on error");
assertLogNotContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
assertLogNotContaining("failed because 1 of 0 evaluations failed to evaluate correctly. Failed to evaluate cell 'MortageCalculatorFunction'!$D$3");
}
public void testUdf() {
@@ -78,4 +97,23 @@ public class TestBuildFile extends BuildFileTest {
executeTarget("test-settext");
assertLogContaining("1/1 tests passed");
}
public void testAddHandler() {
executeTarget("test-addhandler");
assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
assertNotNull("The workbook should have been passed to the handler", MockExcelAntWorkbookHandler.workbook);
assertTrue("The handler should have been executed", MockExcelAntWorkbookHandler.executed);
}
public void testAddHandlerWrongClass() {
executeTarget("test-addhandler-wrongclass");
assertLogContaining("Using input file: " + BuildFileTest.getDataDir() + "/spreadsheet/excelant.xls");
assertLogContaining("Succeeded when evaluating 'MortgageCalculator'!$B$4.");
}
public void testAddHandlerFails() {
expectSpecificBuildException("test-addhandler-fails", "NullPointException", null);
}
}

+ 79
- 1
src/excelant/testcases/org/apache/poi/ss/excelant/tests.xml View File

@@ -57,6 +57,18 @@ under the License.
</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"/>
@@ -85,7 +97,22 @@ under the License.
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>

<!--
@@ -120,6 +147,19 @@ under the License.
</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">
@@ -145,4 +185,42 @@ under the License.
</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>

+ 39
- 18
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java View File

@@ -21,12 +21,7 @@ import static junit.framework.TestCase.assertNotNull;
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;
@@ -34,6 +29,7 @@ import java.util.HashSet;
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;
@@ -58,18 +54,7 @@ import org.apache.poi.xssf.streaming.SXSSFSheet;
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")
@@ -370,6 +355,7 @@ public final class TestXSSFSheet extends BaseTestSheet {
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);
@@ -1167,6 +1153,8 @@ public final class TestXSSFSheet extends BaseTestSheet {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sheet 1");

assertFalse(sheet.getForceFormulaRecalculation());
// Set
sheet.setForceFormulaRecalculation(true);
assertEquals(true, sheet.getForceFormulaRecalculation());
@@ -1463,4 +1451,37 @@ public final class TestXSSFSheet extends BaseTestSheet {
}
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());
}
}

+ 142
- 0
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTextRun.java View File

@@ -0,0 +1,142 @@
/* ====================================================================
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();
}
}
}

+ 158
- 16
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java View File

@@ -27,21 +27,7 @@ import org.apache.poi.xwpf.XWPFTestDataSamples;
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
@@ -342,6 +328,7 @@ public final class TestXWPFParagraph extends TestCase {
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{
@@ -351,4 +338,159 @@ public final class TestXWPFParagraph extends TestCase {
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));
}
}

+ 52
- 0
src/scratchpad/testcases/org/apache/poi/hslf/model/TextPainterTest.java View File

@@ -0,0 +1,52 @@
/* ====================================================================
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);
}
}

Loading…
Cancel
Save