mirror of https://github.com/apache/poi.git
sonar fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894365 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
646fb8c690
commit
3c3154ea8c
|
@ -106,7 +106,7 @@ public class TestXLSX2CSV {
|
||||||
}
|
}
|
||||||
|
|
||||||
String errorOutput = errorBytes.toString(StandardCharsets.UTF_8);
|
String errorOutput = errorBytes.toString(StandardCharsets.UTF_8);
|
||||||
assertEquals(errorOutput.length(), 0);
|
assertEquals(0, errorOutput.length());
|
||||||
|
|
||||||
String output = outputBytes.toString(StandardCharsets.UTF_8);
|
String output = outputBytes.toString(StandardCharsets.UTF_8);
|
||||||
assertTrue(output.contains("\"Lorem\",111,,,"), "Had: " + output);
|
assertTrue(output.contains("\"Lorem\",111,,,"), "Had: " + output);
|
||||||
|
|
|
@ -274,7 +274,7 @@ class TestExcelAntWorkbookUtil {
|
||||||
List<String> sheets = fixture.getSheets();
|
List<String> sheets = fixture.getSheets();
|
||||||
|
|
||||||
assertNotNull(sheets);
|
assertNotNull(sheets);
|
||||||
assertEquals(sheets.size(), 3);
|
assertEquals(3, sheets.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -23,11 +23,9 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
|
||||||
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
|
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.openxml4j.opc.PackageAccess;
|
import org.apache.poi.openxml4j.opc.PackageAccess;
|
||||||
|
@ -40,7 +38,6 @@ import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
import org.apache.poi.ss.usermodel.ClientAnchor;
|
||||||
import org.apache.poi.ss.usermodel.CreationHelper;
|
import org.apache.poi.ss.usermodel.CreationHelper;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
|
||||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFDrawing;
|
import org.apache.poi.xssf.usermodel.XSSFDrawing;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFPicture;
|
import org.apache.poi.xssf.usermodel.XSSFPicture;
|
||||||
|
@ -88,10 +85,10 @@ public final class TestContentTypeManager {
|
||||||
ctm.addContentType(name3, "text/xml+rel");
|
ctm.addContentType(name3, "text/xml+rel");
|
||||||
ctm.addContentType(name4, "text/xml+rel");
|
ctm.addContentType(name4, "text/xml+rel");
|
||||||
|
|
||||||
assertEquals(ctm.getContentType(name1), "foo-type1");
|
assertEquals("foo-type1", ctm.getContentType(name1));
|
||||||
assertEquals(ctm.getContentType(name2), "foo-type2");
|
assertEquals("foo-type2", ctm.getContentType(name2));
|
||||||
assertEquals(ctm.getContentType(name3), "text/xml+rel");
|
assertEquals("text/xml+rel", ctm.getContentType(name3));
|
||||||
assertEquals(ctm.getContentType(name3), "text/xml+rel");
|
assertEquals("text/xml+rel", ctm.getContentType(name3));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,8 +111,8 @@ public final class TestContentTypeManager {
|
||||||
ctm.removeContentType(name2);
|
ctm.removeContentType(name2);
|
||||||
ctm.removeContentType(name3);
|
ctm.removeContentType(name3);
|
||||||
|
|
||||||
assertEquals(ctm.getContentType(name1), "foo-type1");
|
assertEquals("foo-type1", ctm.getContentType(name1));
|
||||||
assertEquals(ctm.getContentType(name2), "foo-type1");
|
assertEquals("foo-type1", ctm.getContentType(name2));
|
||||||
assertNull(ctm.getContentType(name3));
|
assertNull(ctm.getContentType(name3));
|
||||||
|
|
||||||
ctm.removeContentType(name1);
|
ctm.removeContentType(name1);
|
||||||
|
@ -131,15 +128,6 @@ public final class TestContentTypeManager {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
protected byte[] toByteArray(Workbook wb) {
|
|
||||||
try (UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream()) {
|
|
||||||
wb.write(os);
|
|
||||||
return os.toByteArray();
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException("failed to write excel file.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void bug62629CombinePictures() throws Exception {
|
void bug62629CombinePictures() throws Exception {
|
||||||
// this file has incorrect default content-types which caused problems in Apache POI
|
// this file has incorrect default content-types which caused problems in Apache POI
|
||||||
|
|
|
@ -608,14 +608,14 @@ class TestSignatureInfo {
|
||||||
String certDigestXQuery = declareNS +
|
String certDigestXQuery = declareNS +
|
||||||
"$this//xades:SigningCertificate/xades:Cert/xades:CertDigest";
|
"$this//xades:SigningCertificate/xades:Cert/xades:CertDigest";
|
||||||
XmlObject[] xoList = sigDoc.selectPath(certDigestXQuery);
|
XmlObject[] xoList = sigDoc.selectPath(certDigestXQuery);
|
||||||
assertEquals(xoList.length, 1);
|
assertEquals(1, xoList.length);
|
||||||
DigestAlgAndValueType certDigest = (DigestAlgAndValueType) xoList[0];
|
DigestAlgAndValueType certDigest = (DigestAlgAndValueType) xoList[0];
|
||||||
assertNotNull(certDigest.getDigestValue());
|
assertNotNull(certDigest.getDigestValue());
|
||||||
|
|
||||||
String qualPropXQuery = declareNS +
|
String qualPropXQuery = declareNS +
|
||||||
"$this/ds:Signature/ds:Object/xades:QualifyingProperties";
|
"$this/ds:Signature/ds:Object/xades:QualifyingProperties";
|
||||||
xoList = sigDoc.selectPath(qualPropXQuery);
|
xoList = sigDoc.selectPath(qualPropXQuery);
|
||||||
assertEquals(xoList.length, 1);
|
assertEquals(1, xoList.length);
|
||||||
QualifyingPropertiesType qualProp = (QualifyingPropertiesType) xoList[0];
|
QualifyingPropertiesType qualProp = (QualifyingPropertiesType) xoList[0];
|
||||||
boolean qualPropXsdOk = qualProp.validate();
|
boolean qualPropXsdOk = qualProp.validate();
|
||||||
assertTrue(qualPropXsdOk);
|
assertTrue(qualPropXsdOk);
|
||||||
|
|
|
@ -50,7 +50,8 @@ import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
import org.apache.commons.io.output.NullPrintStream;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||||
import org.apache.poi.extractor.ExtractorFactory;
|
import org.apache.poi.extractor.ExtractorFactory;
|
||||||
|
@ -79,11 +80,9 @@ import org.apache.poi.sl.usermodel.TextParagraph;
|
||||||
import org.apache.poi.sl.usermodel.TextRun;
|
import org.apache.poi.sl.usermodel.TextRun;
|
||||||
import org.apache.poi.sl.usermodel.TextShape;
|
import org.apache.poi.sl.usermodel.TextShape;
|
||||||
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
import org.apache.poi.sl.usermodel.VerticalAlignment;
|
||||||
import org.apache.commons.io.output.NullPrintStream;
|
|
||||||
import org.apache.poi.xslf.usermodel.*;
|
import org.apache.poi.xslf.usermodel.*;
|
||||||
import org.apache.poi.xslf.util.DummyGraphics2d;
|
import org.apache.poi.xslf.util.DummyGraphics2d;
|
||||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -114,11 +113,11 @@ class TestXSLFBugs {
|
||||||
|
|
||||||
XSLFSlide slide = ss1.getSlides().get(0);
|
XSLFSlide slide = ss1.getSlides().get(0);
|
||||||
|
|
||||||
assertEquals(slide.getShapes().size(), 1);
|
assertEquals(1,slide.getShapes().size());
|
||||||
|
|
||||||
XSLFPictureShape picture = (XSLFPictureShape) slide.getShapes().get(0);
|
XSLFPictureShape picture = (XSLFPictureShape) slide.getShapes().get(0);
|
||||||
|
|
||||||
assertEquals(picture.getShapeId(), 662);
|
assertEquals(662, picture.getShapeId());
|
||||||
assertFalse(picture.isExternalLinkedPicture());
|
assertFalse(picture.isExternalLinkedPicture());
|
||||||
assertNull(picture.getPictureData());
|
assertNull(picture.getPictureData());
|
||||||
assertNull(picture.getPictureLink());
|
assertNull(picture.getPictureLink());
|
||||||
|
@ -133,12 +132,12 @@ class TestXSLFBugs {
|
||||||
|
|
||||||
XSLFSlide slide0 = ss1.getSlides().get(0);
|
XSLFSlide slide0 = ss1.getSlides().get(0);
|
||||||
|
|
||||||
assertEquals(slide0.getShapes().size(), 4);
|
assertEquals(4, slide0.getShapes().size());
|
||||||
|
|
||||||
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
||||||
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
||||||
assertRelation(slide0, "/ppt/media/image1.png", "rId2");
|
assertRelation(slide0, "/ppt/media/image1.png", "rId2");
|
||||||
assertEquals(slide0.getRelations().size(), 2);
|
assertEquals(2, slide0.getRelations().size());
|
||||||
|
|
||||||
List<XSLFPictureShape> pictures = new ArrayList<>();
|
List<XSLFPictureShape> pictures = new ArrayList<>();
|
||||||
for (XSLFShape shape : slide0.getShapes()) {
|
for (XSLFShape shape : slide0.getShapes()) {
|
||||||
|
@ -147,21 +146,21 @@ class TestXSLFBugs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(pictures.size(), 2);
|
assertEquals(2, pictures.size());
|
||||||
assertEquals(pictures.get(0).getPictureData().getFileName(), "image1.png");
|
assertEquals("image1.png", pictures.get(0).getPictureData().getFileName());
|
||||||
assertEquals(pictures.get(1).getPictureData().getFileName(), "image1.png");
|
assertEquals("image1.png", pictures.get(1).getPictureData().getFileName());
|
||||||
// blipId is rId2 of both pictures
|
// blipId is rId2 of both pictures
|
||||||
|
|
||||||
// remove just the first picture
|
// remove just the first picture
|
||||||
slide0.removeShape(pictures.get(0));
|
slide0.removeShape(pictures.get(0));
|
||||||
|
|
||||||
assertEquals(slide0.getShapes().size(), 3);
|
assertEquals(3, slide0.getShapes().size());
|
||||||
|
|
||||||
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
||||||
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
||||||
// the bug is that the following relation is gone
|
// the bug is that the following relation is gone
|
||||||
assertRelation(slide0, "/ppt/media/image1.png", "rId2");
|
assertRelation(slide0, "/ppt/media/image1.png", "rId2");
|
||||||
assertEquals(slide0.getRelations().size(), 2);
|
assertEquals(2, slide0.getRelations().size());
|
||||||
|
|
||||||
// Save and re-load
|
// Save and re-load
|
||||||
try (XMLSlideShow ss2 = writeOutAndReadBack(ss1)) {
|
try (XMLSlideShow ss2 = writeOutAndReadBack(ss1)) {
|
||||||
|
@ -172,7 +171,7 @@ class TestXSLFBugs {
|
||||||
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
||||||
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
||||||
assertRelation(slide0, "/ppt/media/image1.png", "rId2");
|
assertRelation(slide0, "/ppt/media/image1.png", "rId2");
|
||||||
assertEquals(slide0.getRelations().size(), 2);
|
assertEquals(2, slide0.getRelations().size());
|
||||||
|
|
||||||
pictures.clear();
|
pictures.clear();
|
||||||
for (XSLFShape shape : slide0.getShapes()) {
|
for (XSLFShape shape : slide0.getShapes()) {
|
||||||
|
@ -181,17 +180,17 @@ class TestXSLFBugs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(pictures.size(), 1);
|
assertEquals(1, pictures.size());
|
||||||
assertEquals(pictures.get(0).getPictureData().getFileName(), "image1.png");
|
assertEquals("image1.png", pictures.get(0).getPictureData().getFileName());
|
||||||
|
|
||||||
slide0.removeShape(pictures.get(0));
|
slide0.removeShape(pictures.get(0));
|
||||||
|
|
||||||
assertEquals(slide0.getShapes().size(), 2);
|
assertEquals(2, slide0.getShapes().size());
|
||||||
|
|
||||||
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
||||||
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
||||||
assertNull(slide0.getRelationById("rId2"));
|
assertNull(slide0.getRelationById("rId2"));
|
||||||
assertEquals(slide0.getRelations().size(), 1);
|
assertEquals(1, slide0.getRelations().size());
|
||||||
|
|
||||||
// Save and re-load
|
// Save and re-load
|
||||||
try (XMLSlideShow ss3 = writeOutAndReadBack(ss2)) {
|
try (XMLSlideShow ss3 = writeOutAndReadBack(ss2)) {
|
||||||
|
@ -201,7 +200,7 @@ class TestXSLFBugs {
|
||||||
|
|
||||||
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
assertRelation(slide0, "/ppt/slides/slide1.xml", null);
|
||||||
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
|
||||||
assertEquals(slide0.getShapes().size(), 2);
|
assertEquals(2, slide0.getShapes().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -919,9 +918,9 @@ class TestXSLFBugs {
|
||||||
|
|
||||||
XSLFSlide slide = ss1.getSlides().get(0);
|
XSLFSlide slide = ss1.getSlides().get(0);
|
||||||
|
|
||||||
assertEquals(slide.getShapes().size(), 1);
|
assertEquals(1, slide.getShapes().size());
|
||||||
XSLFGroupShape group = (XSLFGroupShape) slide.getShapes().get(0);
|
XSLFGroupShape group = (XSLFGroupShape) slide.getShapes().get(0);
|
||||||
assertEquals(group.getShapes().size(), 2);
|
assertEquals(2, group.getShapes().size());
|
||||||
XSLFAutoShape oval = (XSLFAutoShape) group.getShapes().get(0);
|
XSLFAutoShape oval = (XSLFAutoShape) group.getShapes().get(0);
|
||||||
XSLFAutoShape arrow = (XSLFAutoShape) group.getShapes().get(1);
|
XSLFAutoShape arrow = (XSLFAutoShape) group.getShapes().get(1);
|
||||||
assertNull(oval.getFillColor());
|
assertNull(oval.getFillColor());
|
||||||
|
@ -1067,7 +1066,7 @@ class TestXSLFBugs {
|
||||||
XSLFSlide targetSlide = targetPresentation.getSlides().get(0);
|
XSLFSlide targetSlide = targetPresentation.getSlides().get(0);
|
||||||
assertEquals(2, targetPresentation.getPictureData().size());
|
assertEquals(2, targetPresentation.getPictureData().size());
|
||||||
|
|
||||||
targetPresentation.write(new UnsynchronizedByteArrayOutputStream());
|
targetPresentation.write(NullOutputStream.NULL_OUTPUT_STREAM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class TestXSSFSheetXMLHandler {
|
||||||
public void cell(final String cellReference, final String formattedValue,
|
public void cell(final String cellReference, final String formattedValue,
|
||||||
final XSSFComment comment) {
|
final XSSFComment comment) {
|
||||||
assertEquals("\uD83D\uDE1Cmore text", formattedValue);
|
assertEquals("\uD83D\uDE1Cmore text", formattedValue);
|
||||||
assertEquals(cellCount++, 0);
|
assertEquals(0, cellCount++);
|
||||||
}
|
}
|
||||||
}, false));
|
}, false));
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,9 @@ package org.apache.poi.xssf.usermodel;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -66,19 +68,16 @@ public abstract class BaseTestXSSFPivotTable {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void testAddRowLabelToPivotTable() {
|
void testAddRowLabelToPivotTable() {
|
||||||
int columnIndex = 0;
|
|
||||||
|
|
||||||
assertEquals(0, pivotTable.getRowLabelColumns().size());
|
assertEquals(0, pivotTable.getRowLabelColumns().size());
|
||||||
|
|
||||||
pivotTable.addRowLabel(columnIndex);
|
pivotTable.addRowLabel(0);
|
||||||
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();
|
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();
|
||||||
|
|
||||||
assertEquals(defintion.getRowFields().getFieldArray(0).getX(), columnIndex);
|
assertEquals(0, defintion.getRowFields().getFieldArray(0).getX());
|
||||||
assertEquals(defintion.getRowFields().getCount(), 1);
|
assertEquals(1, defintion.getRowFields().getCount());
|
||||||
assertEquals(1, pivotTable.getRowLabelColumns().size());
|
assertEquals(1, pivotTable.getRowLabelColumns().size());
|
||||||
|
|
||||||
columnIndex = 1;
|
pivotTable.addRowLabel(1);
|
||||||
pivotTable.addRowLabel(columnIndex);
|
|
||||||
assertEquals(2, pivotTable.getRowLabelColumns().size());
|
assertEquals(2, pivotTable.getRowLabelColumns().size());
|
||||||
|
|
||||||
assertEquals(0, (int)pivotTable.getRowLabelColumns().get(0));
|
assertEquals(0, (int)pivotTable.getRowLabelColumns().get(0));
|
||||||
|
@ -120,7 +119,7 @@ public abstract class BaseTestXSSFPivotTable {
|
||||||
pivotTable.addColumnLabel(DataConsolidateFunction.MIN, columnThree);
|
pivotTable.addColumnLabel(DataConsolidateFunction.MIN, columnThree);
|
||||||
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();
|
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();
|
||||||
|
|
||||||
assertEquals(defintion.getDataFields().getDataFieldList().size(), 3);
|
assertEquals(3, defintion.getDataFields().getDataFieldList().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,7 +137,7 @@ public abstract class BaseTestXSSFPivotTable {
|
||||||
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, columnThree);
|
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, columnThree);
|
||||||
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();
|
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();
|
||||||
|
|
||||||
assertEquals(defintion.getDataFields().getDataFieldList().size(), 3);
|
assertEquals(3, defintion.getDataFields().getDataFieldList().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,15 +160,13 @@ public abstract class BaseTestXSSFPivotTable {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void testColumnLabelCreatesDataField() {
|
void testColumnLabelCreatesDataField() {
|
||||||
int columnIndex = 0;
|
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 0);
|
||||||
|
|
||||||
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, columnIndex);
|
|
||||||
|
|
||||||
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();
|
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();
|
||||||
|
|
||||||
assertEquals(defintion.getDataFields().getDataFieldArray(0).getFld(), columnIndex);
|
assertEquals(0, defintion.getDataFields().getDataFieldArray(0).getFld());
|
||||||
assertEquals(defintion.getDataFields().getDataFieldArray(0).getSubtotal(),
|
assertSame(STDataConsolidateFunction.Enum.forInt(DataConsolidateFunction.SUM.getValue()),
|
||||||
STDataConsolidateFunction.Enum.forInt(DataConsolidateFunction.SUM.getValue()));
|
defintion.getDataFields().getDataFieldArray(0).getSubtotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -220,12 +217,9 @@ public abstract class BaseTestXSSFPivotTable {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void testAddDataColumn() {
|
void testAddDataColumn() {
|
||||||
int columnIndex = 0;
|
pivotTable.addDataColumn(0, true);
|
||||||
boolean isDataField = true;
|
|
||||||
|
|
||||||
pivotTable.addDataColumn(columnIndex, isDataField);
|
|
||||||
CTPivotFields pivotFields = pivotTable.getCTPivotTableDefinition().getPivotFields();
|
CTPivotFields pivotFields = pivotTable.getCTPivotTableDefinition().getPivotFields();
|
||||||
assertEquals(pivotFields.getPivotFieldArray(columnIndex).getDataField(), isDataField);
|
assertTrue(pivotFields.getPivotFieldArray(0).getDataField());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -247,8 +241,8 @@ public abstract class BaseTestXSSFPivotTable {
|
||||||
CTPageFields fields = pivotTable.getCTPivotTableDefinition().getPageFields();
|
CTPageFields fields = pivotTable.getCTPivotTableDefinition().getPageFields();
|
||||||
CTPageField field = fields.getPageFieldArray(0);
|
CTPageField field = fields.getPageFieldArray(0);
|
||||||
assertEquals(field.getFld(), columnIndex);
|
assertEquals(field.getFld(), columnIndex);
|
||||||
assertEquals(field.getHier(), -1);
|
assertEquals(-1, field.getHier());
|
||||||
assertEquals(fields.getCount(), 1);
|
assertEquals(1, fields.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -295,19 +289,16 @@ public abstract class BaseTestXSSFPivotTable {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
void testAddColLabelToPivotTable() {
|
void testAddColLabelToPivotTable() {
|
||||||
int columnIndex = 0;
|
|
||||||
|
|
||||||
assertEquals(0, pivotTable.getColLabelColumns().size());
|
assertEquals(0, pivotTable.getColLabelColumns().size());
|
||||||
|
|
||||||
pivotTable.addColLabel(columnIndex);
|
pivotTable.addColLabel(0);
|
||||||
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();
|
CTPivotTableDefinition defintion = pivotTable.getCTPivotTableDefinition();
|
||||||
|
|
||||||
assertEquals(defintion.getColFields().getFieldArray(0).getX(), columnIndex);
|
assertEquals(0, defintion.getColFields().getFieldArray(0).getX());
|
||||||
assertEquals(defintion.getColFields().getCount(), 1);
|
assertEquals(1, defintion.getColFields().getCount());
|
||||||
assertEquals(1, pivotTable.getColLabelColumns().size());
|
assertEquals(1, pivotTable.getColLabelColumns().size());
|
||||||
|
|
||||||
columnIndex = 1;
|
pivotTable.addColLabel(1);
|
||||||
pivotTable.addColLabel(columnIndex);
|
|
||||||
assertEquals(2, pivotTable.getColLabelColumns().size());
|
assertEquals(2, pivotTable.getColLabelColumns().size());
|
||||||
|
|
||||||
assertEquals(0, (int)pivotTable.getColLabelColumns().get(0));
|
assertEquals(0, (int)pivotTable.getColLabelColumns().get(0));
|
||||||
|
|
|
@ -121,7 +121,7 @@ class TestXSSFCellStyle {
|
||||||
assertTrue(borderId > 0);
|
assertTrue(borderId > 0);
|
||||||
//check changes in the underlying xml bean
|
//check changes in the underlying xml bean
|
||||||
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
|
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
|
||||||
assertEquals(STBorderStyle.MEDIUM, ctBorder.getBottom().getStyle());
|
assertSame(STBorderStyle.MEDIUM, ctBorder.getBottom().getStyle());
|
||||||
|
|
||||||
num = stylesTable.getBorders().size();
|
num = stylesTable.getBorders().size();
|
||||||
//setting the same border multiple times should not change borderId
|
//setting the same border multiple times should not change borderId
|
||||||
|
@ -141,7 +141,7 @@ class TestXSSFCellStyle {
|
||||||
//none is not the same as "not set", therefore the following doesn't work any more
|
//none is not the same as "not set", therefore the following doesn't work any more
|
||||||
//assertFalse(ctBorder.isSetBottom());
|
//assertFalse(ctBorder.isSetBottom());
|
||||||
//replacement:
|
//replacement:
|
||||||
assertEquals(ctBorder.getBottom().getStyle(), STBorderStyle.NONE);
|
assertSame(STBorderStyle.NONE, ctBorder.getBottom().getStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -159,7 +159,7 @@ class TestXSSFCellStyle {
|
||||||
assertTrue(borderId > 0);
|
assertTrue(borderId > 0);
|
||||||
//check changes in the underlying xml bean
|
//check changes in the underlying xml bean
|
||||||
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
|
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
|
||||||
assertEquals(STBorderStyle.MEDIUM, ctBorder.getRight().getStyle());
|
assertSame(STBorderStyle.MEDIUM, ctBorder.getRight().getStyle());
|
||||||
|
|
||||||
num = stylesTable.getBorders().size();
|
num = stylesTable.getBorders().size();
|
||||||
//setting the same border multiple times should not change borderId
|
//setting the same border multiple times should not change borderId
|
||||||
|
@ -179,7 +179,7 @@ class TestXSSFCellStyle {
|
||||||
//none is not the same as "not set", therefore the following doesn't work any more
|
//none is not the same as "not set", therefore the following doesn't work any more
|
||||||
//assertFalse(ctBorder.isSetRight());
|
//assertFalse(ctBorder.isSetRight());
|
||||||
//replacement:
|
//replacement:
|
||||||
assertEquals(ctBorder.getRight().getStyle(), STBorderStyle.NONE);
|
assertSame(STBorderStyle.NONE, ctBorder.getRight().getStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -197,7 +197,7 @@ class TestXSSFCellStyle {
|
||||||
assertTrue(borderId > 0);
|
assertTrue(borderId > 0);
|
||||||
//check changes in the underlying xml bean
|
//check changes in the underlying xml bean
|
||||||
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
|
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
|
||||||
assertEquals(STBorderStyle.MEDIUM, ctBorder.getLeft().getStyle());
|
assertSame(STBorderStyle.MEDIUM, ctBorder.getLeft().getStyle());
|
||||||
|
|
||||||
num = stylesTable.getBorders().size();
|
num = stylesTable.getBorders().size();
|
||||||
//setting the same border multiple times should not change borderId
|
//setting the same border multiple times should not change borderId
|
||||||
|
@ -217,7 +217,7 @@ class TestXSSFCellStyle {
|
||||||
//none is not the same as "not set", therefore the following doesn't work any more
|
//none is not the same as "not set", therefore the following doesn't work any more
|
||||||
//assertFalse(ctBorder.isSetLeft());
|
//assertFalse(ctBorder.isSetLeft());
|
||||||
//replacement:
|
//replacement:
|
||||||
assertEquals(ctBorder.getLeft().getStyle(), STBorderStyle.NONE);
|
assertSame(STBorderStyle.NONE, ctBorder.getLeft().getStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -235,7 +235,7 @@ class TestXSSFCellStyle {
|
||||||
assertTrue(borderId > 0);
|
assertTrue(borderId > 0);
|
||||||
//check changes in the underlying xml bean
|
//check changes in the underlying xml bean
|
||||||
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
|
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
|
||||||
assertEquals(STBorderStyle.MEDIUM, ctBorder.getTop().getStyle());
|
assertSame(STBorderStyle.MEDIUM, ctBorder.getTop().getStyle());
|
||||||
|
|
||||||
num = stylesTable.getBorders().size();
|
num = stylesTable.getBorders().size();
|
||||||
//setting the same border multiple times should not change borderId
|
//setting the same border multiple times should not change borderId
|
||||||
|
@ -255,7 +255,7 @@ class TestXSSFCellStyle {
|
||||||
//none is not the same as "not set", therefore the following doesn't work any more
|
//none is not the same as "not set", therefore the following doesn't work any more
|
||||||
//assertFalse(ctBorder.isSetTop());
|
//assertFalse(ctBorder.isSetTop());
|
||||||
//replacement:
|
//replacement:
|
||||||
assertEquals(ctBorder.getTop().getStyle(), STBorderStyle.NONE);
|
assertSame(STBorderStyle.NONE, ctBorder.getTop().getStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testGetSetBorderXMLBean(BorderStyle border, STBorderStyle.Enum expected) {
|
private void testGetSetBorderXMLBean(BorderStyle border, STBorderStyle.Enum expected) {
|
||||||
|
@ -265,7 +265,7 @@ class TestXSSFCellStyle {
|
||||||
assertTrue(borderId > 0);
|
assertTrue(borderId > 0);
|
||||||
//check changes in the underlying xml bean
|
//check changes in the underlying xml bean
|
||||||
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
|
CTBorder ctBorder = stylesTable.getBorderAt(borderId).getCTBorder();
|
||||||
assertEquals(expected, ctBorder.getTop().getStyle());
|
assertSame(expected, ctBorder.getTop().getStyle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -641,7 +641,7 @@ class TestXSSFCellStyle {
|
||||||
assertTrue(fillId > 0);
|
assertTrue(fillId > 0);
|
||||||
//check changes in the underlying xml bean
|
//check changes in the underlying xml bean
|
||||||
CTFill ctFill2 = stylesTable.getFillAt(fillId).getCTFill();
|
CTFill ctFill2 = stylesTable.getFillAt(fillId).getCTFill();
|
||||||
assertEquals(STPatternType.SOLID, ctFill2.getPatternFill().getPatternType());
|
assertSame(STPatternType.SOLID, ctFill2.getPatternFill().getPatternType());
|
||||||
|
|
||||||
//setting the same fill multiple time does not update the styles table
|
//setting the same fill multiple time does not update the styles table
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
@ -695,15 +695,15 @@ class TestXSSFCellStyle {
|
||||||
|
|
||||||
cellStyle.setAlignment(HorizontalAlignment.LEFT);
|
cellStyle.setAlignment(HorizontalAlignment.LEFT);
|
||||||
assertEquals(HorizontalAlignment.LEFT, cellStyle.getAlignment());
|
assertEquals(HorizontalAlignment.LEFT, cellStyle.getAlignment());
|
||||||
assertEquals(STHorizontalAlignment.LEFT, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
|
assertSame(STHorizontalAlignment.LEFT, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
|
||||||
|
|
||||||
cellStyle.setAlignment(HorizontalAlignment.JUSTIFY);
|
cellStyle.setAlignment(HorizontalAlignment.JUSTIFY);
|
||||||
assertEquals(HorizontalAlignment.JUSTIFY, cellStyle.getAlignment());
|
assertEquals(HorizontalAlignment.JUSTIFY, cellStyle.getAlignment());
|
||||||
assertEquals(STHorizontalAlignment.JUSTIFY, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
|
assertSame(STHorizontalAlignment.JUSTIFY, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
|
||||||
|
|
||||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
assertEquals(HorizontalAlignment.CENTER, cellStyle.getAlignment());
|
assertEquals(HorizontalAlignment.CENTER, cellStyle.getAlignment());
|
||||||
assertEquals(STHorizontalAlignment.CENTER, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
|
assertSame(STHorizontalAlignment.CENTER, cellStyle.getCellAlignment().getCTCellAlignment().getHorizontal());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -728,15 +728,15 @@ class TestXSSFCellStyle {
|
||||||
void testGetSetVerticalAlignment() {
|
void testGetSetVerticalAlignment() {
|
||||||
assertEquals(VerticalAlignment.BOTTOM, cellStyle.getVerticalAlignment());
|
assertEquals(VerticalAlignment.BOTTOM, cellStyle.getVerticalAlignment());
|
||||||
assertFalse(cellStyle.getCellAlignment().getCTCellAlignment().isSetVertical());
|
assertFalse(cellStyle.getCellAlignment().getCTCellAlignment().isSetVertical());
|
||||||
assertEquals(STVerticalAlignment.BOTTOM, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
|
assertSame(STVerticalAlignment.BOTTOM, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
|
||||||
|
|
||||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
assertEquals(VerticalAlignment.CENTER, cellStyle.getVerticalAlignment());
|
assertEquals(VerticalAlignment.CENTER, cellStyle.getVerticalAlignment());
|
||||||
assertEquals(STVerticalAlignment.CENTER, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
|
assertSame(STVerticalAlignment.CENTER, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
|
||||||
|
|
||||||
cellStyle.setVerticalAlignment(VerticalAlignment.JUSTIFY);
|
cellStyle.setVerticalAlignment(VerticalAlignment.JUSTIFY);
|
||||||
assertEquals(VerticalAlignment.JUSTIFY, cellStyle.getVerticalAlignment());
|
assertEquals(VerticalAlignment.JUSTIFY, cellStyle.getVerticalAlignment());
|
||||||
assertEquals(STVerticalAlignment.JUSTIFY, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
|
assertSame(STVerticalAlignment.JUSTIFY, cellStyle.getCellAlignment().getCTCellAlignment().getVertical());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -848,8 +848,8 @@ class TestXSSFCellStyle {
|
||||||
assertEquals("TestingFont", clone.getFont().getFontName());
|
assertEquals("TestingFont", clone.getFont().getFontName());
|
||||||
assertEquals(fmtClone.getFormat("Test##"), clone.getDataFormat());
|
assertEquals(fmtClone.getFormat("Test##"), clone.getDataFormat());
|
||||||
assertNotEquals(fmtClone.getFormat("Test##"), fmt.getFormat("Test##"));
|
assertNotEquals(fmtClone.getFormat("Test##"), fmt.getFormat("Test##"));
|
||||||
assertEquals(clone.getFillPattern(), FillPatternType.SOLID_FOREGROUND);
|
assertEquals(FillPatternType.SOLID_FOREGROUND, clone.getFillPattern());
|
||||||
assertEquals(clone.getFillForegroundColor(), IndexedColors.BRIGHT_GREEN.getIndex());
|
assertEquals(IndexedColors.BRIGHT_GREEN.getIndex(), clone.getFillForegroundColor());
|
||||||
|
|
||||||
// Save it and re-check
|
// Save it and re-check
|
||||||
XSSFWorkbook wbReload = XSSFTestDataSamples.writeOutAndReadBack(wbClone);
|
XSSFWorkbook wbReload = XSSFTestDataSamples.writeOutAndReadBack(wbClone);
|
||||||
|
@ -862,8 +862,8 @@ class TestXSSFCellStyle {
|
||||||
assertEquals("TestingFont", reload.getFont().getFontName());
|
assertEquals("TestingFont", reload.getFont().getFontName());
|
||||||
assertEquals(fmtClone.getFormat("Test##"), reload.getDataFormat());
|
assertEquals(fmtClone.getFormat("Test##"), reload.getDataFormat());
|
||||||
assertNotEquals(fmtClone.getFormat("Test##"), fmt.getFormat("Test##"));
|
assertNotEquals(fmtClone.getFormat("Test##"), fmt.getFormat("Test##"));
|
||||||
assertEquals(clone.getFillPattern(), FillPatternType.SOLID_FOREGROUND);
|
assertEquals(FillPatternType.SOLID_FOREGROUND, clone.getFillPattern());
|
||||||
assertEquals(clone.getFillForegroundColor(), IndexedColors.BRIGHT_GREEN.getIndex());
|
assertEquals(IndexedColors.BRIGHT_GREEN.getIndex(), clone.getFillForegroundColor());
|
||||||
|
|
||||||
XSSFWorkbook wbOrig2 = XSSFTestDataSamples.writeOutAndReadBack(wbOrig);
|
XSSFWorkbook wbOrig2 = XSSFTestDataSamples.writeOutAndReadBack(wbOrig);
|
||||||
assertNotNull(wbOrig2);
|
assertNotNull(wbOrig2);
|
||||||
|
@ -1006,8 +1006,6 @@ class TestXSSFCellStyle {
|
||||||
final CellStyle targetStyle = target.createCellStyle();
|
final CellStyle targetStyle = target.createCellStyle();
|
||||||
targetStyle.cloneStyleFrom(referenceStyle);
|
targetStyle.cloneStyleFrom(referenceStyle);
|
||||||
}
|
}
|
||||||
/*System.out.println("Reference : "+reference.getNumCellStyles());
|
|
||||||
System.out.println("Target : "+target.getNumCellStyles());*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1025,9 +1023,6 @@ class TestXSSFCellStyle {
|
||||||
cell.setCellValue("Coucou"+i);
|
cell.setCellValue("Coucou"+i);
|
||||||
cell.setCellStyle(target.getCellStyleAt(i));
|
cell.setCellStyle(target.getCellStyleAt(i));
|
||||||
}
|
}
|
||||||
/*OutputStream out = new FileOutputStream("C:\\temp\\58084.xlsx");
|
|
||||||
target.write(out);
|
|
||||||
out.close();*/
|
|
||||||
|
|
||||||
Workbook copy = XSSFTestDataSamples.writeOutAndReadBack(target);
|
Workbook copy = XSSFTestDataSamples.writeOutAndReadBack(target);
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
|
import static org.apache.poi.ss.usermodel.FontCharset.*;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -79,7 +80,7 @@ public final class TestXSSFFont extends BaseTestFont{
|
||||||
|
|
||||||
|
|
||||||
xssfFont.setBold(true);
|
xssfFont.setBold(true);
|
||||||
assertEquals(ctFont.sizeOfBArray(),1);
|
assertEquals(1,ctFont.sizeOfBArray());
|
||||||
assertTrue(ctFont.getBArray(0).getVal());
|
assertTrue(ctFont.getBArray(0).getVal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,27 +89,27 @@ public final class TestXSSFFont extends BaseTestFont{
|
||||||
void testCharSetWithDeprecatedFontCharset() throws IOException {
|
void testCharSetWithDeprecatedFontCharset() throws IOException {
|
||||||
CTFont ctFont=CTFont.Factory.newInstance();
|
CTFont ctFont=CTFont.Factory.newInstance();
|
||||||
CTIntProperty prop=ctFont.addNewCharset();
|
CTIntProperty prop=ctFont.addNewCharset();
|
||||||
prop.setVal(org.apache.poi.ss.usermodel.FontCharset.ANSI.getValue());
|
prop.setVal(ANSI.getValue());
|
||||||
|
|
||||||
ctFont.setCharsetArray(0,prop);
|
ctFont.setCharsetArray(0,prop);
|
||||||
XSSFFont xssfFont=new XSSFFont(ctFont);
|
XSSFFont xssfFont=new XSSFFont(ctFont);
|
||||||
assertEquals(Font.ANSI_CHARSET,xssfFont.getCharSet());
|
assertEquals(Font.ANSI_CHARSET,xssfFont.getCharSet());
|
||||||
|
|
||||||
xssfFont.setCharSet(org.apache.poi.ss.usermodel.FontCharset.DEFAULT);
|
xssfFont.setCharSet(DEFAULT);
|
||||||
assertEquals(org.apache.poi.ss.usermodel.FontCharset.DEFAULT.getValue(),ctFont.getCharsetArray(0).getVal());
|
assertEquals(DEFAULT.getValue(),ctFont.getCharsetArray(0).getVal());
|
||||||
|
|
||||||
// Try with a few less usual ones:
|
// Try with a few less usual ones:
|
||||||
// Set with the Charset itself
|
// Set with the Charset itself
|
||||||
xssfFont.setCharSet(org.apache.poi.ss.usermodel.FontCharset.RUSSIAN);
|
xssfFont.setCharSet(RUSSIAN);
|
||||||
assertEquals(org.apache.poi.ss.usermodel.FontCharset.RUSSIAN.getValue(), xssfFont.getCharSet());
|
assertEquals(RUSSIAN.getValue(), xssfFont.getCharSet());
|
||||||
// And set with the Charset index
|
// And set with the Charset index
|
||||||
xssfFont.setCharSet(org.apache.poi.ss.usermodel.FontCharset.ARABIC.getValue());
|
xssfFont.setCharSet(ARABIC.getValue());
|
||||||
assertEquals(org.apache.poi.ss.usermodel.FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
|
assertEquals(ARABIC.getValue(), xssfFont.getCharSet());
|
||||||
xssfFont.setCharSet((byte)(org.apache.poi.ss.usermodel.FontCharset.ARABIC.getValue()));
|
xssfFont.setCharSet((byte)(ARABIC.getValue()));
|
||||||
assertEquals(org.apache.poi.ss.usermodel.FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
|
assertEquals(ARABIC.getValue(), xssfFont.getCharSet());
|
||||||
|
|
||||||
// This one isn't allowed
|
// This one isn't allowed
|
||||||
assertNull(org.apache.poi.ss.usermodel.FontCharset.valueOf(9999));
|
assertNull(valueOf(9999));
|
||||||
assertThrows(POIXMLException.class, () -> xssfFont.setCharSet(9999),
|
assertThrows(POIXMLException.class, () -> xssfFont.setCharSet(9999),
|
||||||
"Shouldn't be able to set an invalid charset");
|
"Shouldn't be able to set an invalid charset");
|
||||||
|
|
||||||
|
@ -198,7 +199,7 @@ public final class TestXSSFFont extends BaseTestFont{
|
||||||
assertFalse(xssfFont.getItalic());
|
assertFalse(xssfFont.getItalic());
|
||||||
|
|
||||||
xssfFont.setItalic(true);
|
xssfFont.setItalic(true);
|
||||||
assertEquals(ctFont.sizeOfIArray(),1);
|
assertEquals(1,ctFont.sizeOfIArray());
|
||||||
assertTrue(ctFont.getIArray(0).getVal());
|
assertTrue(ctFont.getIArray(0).getVal());
|
||||||
assertTrue(ctFont.getIArray(0).getVal());
|
assertTrue(ctFont.getIArray(0).getVal());
|
||||||
}
|
}
|
||||||
|
@ -214,7 +215,7 @@ public final class TestXSSFFont extends BaseTestFont{
|
||||||
assertFalse(xssfFont.getStrikeout());
|
assertFalse(xssfFont.getStrikeout());
|
||||||
|
|
||||||
xssfFont.setStrikeout(true);
|
xssfFont.setStrikeout(true);
|
||||||
assertEquals(ctFont.sizeOfStrikeArray(),1);
|
assertEquals(1,ctFont.sizeOfStrikeArray());
|
||||||
assertTrue(ctFont.getStrikeArray(0).getVal());
|
assertTrue(ctFont.getStrikeArray(0).getVal());
|
||||||
assertTrue(ctFont.getStrikeArray(0).getVal());
|
assertTrue(ctFont.getStrikeArray(0).getVal());
|
||||||
}
|
}
|
||||||
|
@ -258,11 +259,11 @@ public final class TestXSSFFont extends BaseTestFont{
|
||||||
assertEquals(Font.U_SINGLE, xssfFont.getUnderline());
|
assertEquals(Font.U_SINGLE, xssfFont.getUnderline());
|
||||||
|
|
||||||
xssfFont.setUnderline(Font.U_DOUBLE);
|
xssfFont.setUnderline(Font.U_DOUBLE);
|
||||||
assertEquals(ctFont.sizeOfUArray(),1);
|
assertEquals(1, ctFont.sizeOfUArray());
|
||||||
assertSame(STUnderlineValues.DOUBLE,ctFont.getUArray(0).getVal());
|
assertSame(STUnderlineValues.DOUBLE,ctFont.getUArray(0).getVal());
|
||||||
|
|
||||||
xssfFont.setUnderline(FontUnderline.DOUBLE_ACCOUNTING);
|
xssfFont.setUnderline(FontUnderline.DOUBLE_ACCOUNTING);
|
||||||
assertEquals(ctFont.sizeOfUArray(),1);
|
assertEquals(1, ctFont.sizeOfUArray());
|
||||||
assertSame(STUnderlineValues.DOUBLE_ACCOUNTING,ctFont.getUArray(0).getVal());
|
assertSame(STUnderlineValues.DOUBLE_ACCOUNTING,ctFont.getUArray(0).getVal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -17,18 +17,11 @@
|
||||||
|
|
||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
import org.apache.poi.ss.SpreadsheetVersion;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import org.apache.poi.ss.util.AreaReference;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import org.apache.poi.ss.util.CellReference;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import org.apache.poi.util.IOUtils;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import org.apache.poi.util.TempFile;
|
|
||||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
|
||||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -38,11 +31,17 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import org.apache.poi.ss.SpreadsheetVersion;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import org.apache.poi.ss.util.AreaReference;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import org.apache.poi.ss.util.CellReference;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import org.apache.poi.util.TempFile;
|
||||||
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn;
|
||||||
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo;
|
||||||
|
|
||||||
public final class TestXSSFTable {
|
public final class TestXSSFTable {
|
||||||
|
|
||||||
|
@ -86,34 +85,33 @@ public final class TestXSSFTable {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCTTableStyleInfo() throws IOException {
|
void testCTTableStyleInfo() throws IOException {
|
||||||
XSSFWorkbook outputWorkbook = new XSSFWorkbook();
|
try (XSSFWorkbook outputWorkbook = new XSSFWorkbook()) {
|
||||||
XSSFSheet sheet = outputWorkbook.createSheet();
|
XSSFSheet sheet = outputWorkbook.createSheet();
|
||||||
|
|
||||||
//Create
|
//Create
|
||||||
XSSFTable outputTable = sheet.createTable(null);
|
XSSFTable outputTable = sheet.createTable(null);
|
||||||
outputTable.setDisplayName("Test");
|
outputTable.setDisplayName("Test");
|
||||||
CTTable outputCTTable = outputTable.getCTTable();
|
CTTable outputCTTable = outputTable.getCTTable();
|
||||||
|
|
||||||
//Style configurations
|
//Style configurations
|
||||||
CTTableStyleInfo outputStyleInfo = outputCTTable.addNewTableStyleInfo();
|
CTTableStyleInfo outputStyleInfo = outputCTTable.addNewTableStyleInfo();
|
||||||
outputStyleInfo.setName("TableStyleLight1");
|
outputStyleInfo.setName("TableStyleLight1");
|
||||||
outputStyleInfo.setShowColumnStripes(false);
|
outputStyleInfo.setShowColumnStripes(false);
|
||||||
outputStyleInfo.setShowRowStripes(true);
|
outputStyleInfo.setShowRowStripes(true);
|
||||||
|
|
||||||
XSSFWorkbook inputWorkbook = XSSFTestDataSamples.writeOutAndReadBack(outputWorkbook);
|
try (XSSFWorkbook inputWorkbook = XSSFTestDataSamples.writeOutAndReadBack(outputWorkbook)) {
|
||||||
List<XSSFTable> tables = inputWorkbook.getSheetAt(0).getTables();
|
List<XSSFTable> tables = inputWorkbook.getSheetAt(0).getTables();
|
||||||
assertEquals(1, tables.size(), "Tables number");
|
assertEquals(1, tables.size(), "Tables number");
|
||||||
|
|
||||||
XSSFTable inputTable = tables.get(0);
|
XSSFTable inputTable = tables.get(0);
|
||||||
assertEquals(outputTable.getDisplayName(), inputTable.getDisplayName(), "Table display name");
|
assertEquals(outputTable.getDisplayName(), inputTable.getDisplayName(), "Table display name");
|
||||||
|
|
||||||
CTTableStyleInfo inputStyleInfo = inputTable.getCTTable().getTableStyleInfo();
|
CTTableStyleInfo inputStyleInfo = inputTable.getCTTable().getTableStyleInfo();
|
||||||
assertEquals(outputStyleInfo.getName(), inputStyleInfo.getName(), "Style name");
|
assertEquals(outputStyleInfo.getName(), inputStyleInfo.getName(), "Style name");
|
||||||
assertEquals(outputStyleInfo.getShowColumnStripes(), inputStyleInfo.getShowColumnStripes(), "Show column stripes");
|
assertEquals(outputStyleInfo.getShowColumnStripes(), inputStyleInfo.getShowColumnStripes(), "Show column stripes");
|
||||||
assertEquals(outputStyleInfo.getShowRowStripes(), inputStyleInfo.getShowRowStripes(), "Show row stripes");
|
assertEquals(outputStyleInfo.getShowRowStripes(), inputStyleInfo.getShowRowStripes(), "Show row stripes");
|
||||||
|
}
|
||||||
inputWorkbook.close();
|
}
|
||||||
outputWorkbook.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -269,8 +267,6 @@ public final class TestXSSFTable {
|
||||||
|
|
||||||
assertEquals(new CellReference("C1"), table.getStartCellReference());
|
assertEquals(new CellReference("C1"), table.getStartCellReference());
|
||||||
assertEquals(new CellReference("M3"), table.getEndCellReference());
|
assertEquals(new CellReference("M3"), table.getEndCellReference());
|
||||||
|
|
||||||
IOUtils.closeQuietly(wb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,8 +288,6 @@ public final class TestXSSFTable {
|
||||||
// update cell references to clear the cache
|
// update cell references to clear the cache
|
||||||
table.updateReferences();
|
table.updateReferences();
|
||||||
assertEquals(11, table.getRowCount());
|
assertEquals(11, table.getRowCount());
|
||||||
|
|
||||||
IOUtils.closeQuietly(wb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,8 +305,6 @@ public final class TestXSSFTable {
|
||||||
|
|
||||||
assertEquals(6, table.getRowCount());
|
assertEquals(6, table.getRowCount());
|
||||||
assertEquals(5, table.getDataRowCount());
|
assertEquals(5, table.getDataRowCount());
|
||||||
|
|
||||||
IOUtils.closeQuietly(wb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,8 +332,6 @@ public final class TestXSSFTable {
|
||||||
assertEquals(0, table.getTotalsRowCount());
|
assertEquals(0, table.getTotalsRowCount());
|
||||||
|
|
||||||
assertEquals("C10:C15", table.getArea().formatAsString());
|
assertEquals("C10:C15", table.getArea().formatAsString());
|
||||||
|
|
||||||
IOUtils.closeQuietly(wb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,10 +431,10 @@ public final class TestXSSFTable {
|
||||||
assertTrue (cB.getId() < cD.getId(), "Column D ID");
|
assertTrue (cB.getId() < cD.getId(), "Column D ID");
|
||||||
assertTrue (cD.getId() < cC.getId(), "Column C ID");
|
assertTrue (cD.getId() < cC.getId(), "Column C ID");
|
||||||
// generated name
|
// generated name
|
||||||
assertEquals(table.getColumns().get(0).getName(), "Column 1");
|
assertEquals("Column 1", table.getColumns().get(0).getName());
|
||||||
assertEquals(table.getColumns().get(1).getName(), "Column B");
|
assertEquals("Column B", table.getColumns().get(1).getName());
|
||||||
assertEquals(table.getColumns().get(2).getName(), "Column C");
|
assertEquals("Column C", table.getColumns().get(2).getName());
|
||||||
assertEquals(table.getColumns().get(3).getName(), "Column D");
|
assertEquals("Column D", table.getColumns().get(3).getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,23 +518,20 @@ public final class TestXSSFTable {
|
||||||
));
|
));
|
||||||
|
|
||||||
// Save and re-load
|
// Save and re-load
|
||||||
XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
try (XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb)) {
|
||||||
IOUtils.closeQuietly(wb);
|
s = wb2.getSheetAt(0);
|
||||||
s = wb2.getSheetAt(0);
|
|
||||||
|
|
||||||
// Check
|
// Check
|
||||||
assertEquals(1, s.getTables().size());
|
assertEquals(1, s.getTables().size());
|
||||||
t = s.getTables().get(0);
|
t = s.getTables().get(0);
|
||||||
assertEquals("A1", t.getStartCellReference().formatAsString());
|
assertEquals("A1", t.getStartCellReference().formatAsString());
|
||||||
assertEquals("C2", t.getEndCellReference().formatAsString());
|
assertEquals("C2", t.getEndCellReference().formatAsString());
|
||||||
|
|
||||||
// TODO Nicer column fetching
|
// TODO Nicer column fetching
|
||||||
assertEquals("12", t.getCTTable().getTableColumns().getTableColumnArray(0).getName());
|
assertEquals("12", t.getCTTable().getTableColumns().getTableColumnArray(0).getName());
|
||||||
assertEquals("34.56", t.getCTTable().getTableColumns().getTableColumnArray(1).getName());
|
assertEquals("34.56", t.getCTTable().getTableColumns().getTableColumnArray(1).getName());
|
||||||
assertEquals("ABCD", t.getCTTable().getTableColumns().getTableColumnArray(2).getName());
|
assertEquals("ABCD", t.getCTTable().getTableColumns().getTableColumnArray(2).getName());
|
||||||
|
}
|
||||||
// Done
|
|
||||||
IOUtils.closeQuietly(wb2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,9 @@ public final class TestXSSFCategoryAxis {
|
||||||
XDDFCategoryAxis axis = chart.createCategoryAxis(AxisPosition.BOTTOM);
|
XDDFCategoryAxis axis = chart.createCategoryAxis(AxisPosition.BOTTOM);
|
||||||
|
|
||||||
axis.setCrosses(AxisCrosses.AUTO_ZERO);
|
axis.setCrosses(AxisCrosses.AUTO_ZERO);
|
||||||
assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO);
|
assertEquals(AxisCrosses.AUTO_ZERO, axis.getCrosses());
|
||||||
|
|
||||||
assertEquals(chart.getAxes().size(), 1);
|
assertEquals(1, chart.getAxes().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,9 +41,9 @@ public final class TestXSSFDateAxis {
|
||||||
XDDFDateAxis axis = chart.createDateAxis(AxisPosition.BOTTOM);
|
XDDFDateAxis axis = chart.createDateAxis(AxisPosition.BOTTOM);
|
||||||
|
|
||||||
axis.setCrosses(AxisCrosses.AUTO_ZERO);
|
axis.setCrosses(AxisCrosses.AUTO_ZERO);
|
||||||
assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO);
|
assertEquals(AxisCrosses.AUTO_ZERO, axis.getCrosses());
|
||||||
|
|
||||||
assertEquals(chart.getAxes().size(), 1);
|
assertEquals(1, chart.getAxes().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,12 +42,12 @@ public final class TestXSSFValueAxis {
|
||||||
XDDFValueAxis axis = chart.createValueAxis(AxisPosition.BOTTOM);
|
XDDFValueAxis axis = chart.createValueAxis(AxisPosition.BOTTOM);
|
||||||
|
|
||||||
axis.setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
|
axis.setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
|
||||||
assertEquals(axis.getCrossBetween(), AxisCrossBetween.MIDPOINT_CATEGORY);
|
assertEquals(AxisCrossBetween.MIDPOINT_CATEGORY, axis.getCrossBetween());
|
||||||
|
|
||||||
axis.setCrosses(AxisCrosses.AUTO_ZERO);
|
axis.setCrosses(AxisCrosses.AUTO_ZERO);
|
||||||
assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO);
|
assertEquals(AxisCrosses.AUTO_ZERO, axis.getCrosses());
|
||||||
|
|
||||||
assertEquals(chart.getAxes().size(), 1);
|
assertEquals(1, chart.getAxes().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
package org.apache.poi.xssf.usermodel.extensions;
|
package org.apache.poi.xssf.usermodel.extensions;
|
||||||
|
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
@ -89,19 +90,13 @@ class TestXSSFCellFill {
|
||||||
XSSFCell cellWithThemeColor = wb.getSheetAt(0).getRow(10).getCell(0);
|
XSSFCell cellWithThemeColor = wb.getSheetAt(0).getRow(10).getCell(0);
|
||||||
//color RGB will be extracted from theme
|
//color RGB will be extracted from theme
|
||||||
XSSFColor foregroundColor = cellWithThemeColor.getCellStyle().getFillForegroundXSSFColor();
|
XSSFColor foregroundColor = cellWithThemeColor.getCellStyle().getFillForegroundXSSFColor();
|
||||||
byte[] rgb = foregroundColor.getRGB();
|
|
||||||
byte[] rgbWithTint = foregroundColor.getRGBWithTint();
|
|
||||||
// Dk2
|
// Dk2
|
||||||
assertEquals(rgb[0], 31);
|
assertArrayEquals(new byte[]{31, 73, 125}, foregroundColor.getRGB());
|
||||||
assertEquals(rgb[1], 73);
|
|
||||||
assertEquals(rgb[2], 125);
|
|
||||||
// Dk2, lighter 40% (tint is about 0.39998)
|
// Dk2, lighter 40% (tint is about 0.39998)
|
||||||
// 31 * (1.0 - 0.39998) + (255 - 255 * (1.0 - 0.39998)) = 120.59552 => 120 (byte)
|
// 31 * (1.0 - 0.39998) + (255 - 255 * (1.0 - 0.39998)) = 120.59552 => 120 (byte)
|
||||||
// 73 * (1.0 - 0.39998) + (255 - 255 * (1.0 - 0.39998)) = 145.79636 => -111 (byte)
|
// 73 * (1.0 - 0.39998) + (255 - 255 * (1.0 - 0.39998)) = 145.79636 => -111 (byte)
|
||||||
// 125 * (1.0 - 0.39998) + (255 - 255 * (1.0 - 0.39998)) = 176.99740 => -80 (byte)
|
// 125 * (1.0 - 0.39998) + (255 - 255 * (1.0 - 0.39998)) = 176.99740 => -80 (byte)
|
||||||
assertEquals(rgbWithTint[0], 120);
|
assertArrayEquals(new byte[]{120, -111, -80}, foregroundColor.getRGBWithTint());
|
||||||
assertEquals(rgbWithTint[1], -111);
|
|
||||||
assertEquals(rgbWithTint[2], -80);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,12 +53,12 @@ class TestXWPFBugs {
|
||||||
|
|
||||||
run.setFontFamily("Times New Roman");
|
run.setFontFamily("Times New Roman");
|
||||||
run.setFontSize(20);
|
run.setFontSize(20);
|
||||||
assertEquals(run.getFontFamily(), "Times New Roman");
|
assertEquals("Times New Roman", run.getFontFamily());
|
||||||
assertEquals(run.getFontFamily(FontCharRange.cs), "Times New Roman");
|
assertEquals("Times New Roman", run.getFontFamily(FontCharRange.cs));
|
||||||
assertEquals(run.getFontFamily(FontCharRange.eastAsia), "Times New Roman");
|
assertEquals("Times New Roman", run.getFontFamily(FontCharRange.eastAsia));
|
||||||
assertEquals(run.getFontFamily(FontCharRange.hAnsi), "Times New Roman");
|
assertEquals("Times New Roman", run.getFontFamily(FontCharRange.hAnsi));
|
||||||
run.setFontFamily("Arial", FontCharRange.hAnsi);
|
run.setFontFamily("Arial", FontCharRange.hAnsi);
|
||||||
assertEquals(run.getFontFamily(FontCharRange.hAnsi), "Arial");
|
assertEquals("Arial", run.getFontFamily(FontCharRange.hAnsi));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,29 +45,19 @@ import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
|
||||||
import org.apache.xmlbeans.XmlCursor;
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.CTProperties;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
|
||||||
|
|
||||||
public final class TestXWPFDocument {
|
public final class TestXWPFDocument {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testContainsMainContentType() throws Exception {
|
void testContainsMainContentType() throws Exception {
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
||||||
OPCPackage pack = doc.getPackage();
|
OPCPackage pack = doc.getPackage()) {
|
||||||
|
String ct = XWPFRelation.DOCUMENT.getContentType();
|
||||||
boolean found = false;
|
boolean found = pack.getParts().stream().anyMatch(p -> ct.equals(p.getContentType()));
|
||||||
for (PackagePart part : pack.getParts()) {
|
assertTrue(found);
|
||||||
if (part.getContentType().equals(XWPFRelation.DOCUMENT.getContentType())) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
// if (false) {
|
|
||||||
// // successful tests should be silent
|
|
||||||
// System.out.println(part);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
assertTrue(found);
|
|
||||||
|
|
||||||
pack.close();
|
|
||||||
doc.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -105,90 +95,92 @@ public final class TestXWPFDocument {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMetadataComplex() throws IOException {
|
void testMetadataComplex() throws IOException {
|
||||||
XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
|
try (XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx")) {
|
||||||
assertNotNull(xml.getProperties().getCoreProperties());
|
assertNotNull(xml.getProperties().getCoreProperties());
|
||||||
assertNotNull(xml.getProperties().getExtendedProperties());
|
assertNotNull(xml.getProperties().getExtendedProperties());
|
||||||
|
|
||||||
assertEquals("Microsoft Office Outlook", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
|
CTProperties up = xml.getProperties().getExtendedProperties().getUnderlyingProperties();
|
||||||
assertEquals(5184, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
|
assertEquals("Microsoft Office Outlook", up.getApplication());
|
||||||
assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
|
assertEquals(5184, up.getCharacters());
|
||||||
|
assertEquals(0, up.getLines());
|
||||||
|
|
||||||
assertEquals(" ", xml.getProperties().getCoreProperties().getTitle());
|
POIXMLProperties.CoreProperties cp = xml.getProperties().getCoreProperties();
|
||||||
Optional<String> subjectProperty = xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty();
|
assertEquals(" ", cp.getTitle());
|
||||||
assertTrue(subjectProperty.isPresent());
|
Optional<String> subjectProperty = cp.getUnderlyingProperties().getSubjectProperty();
|
||||||
assertEquals(" ", subjectProperty.get());
|
assertTrue(subjectProperty.isPresent());
|
||||||
xml.close();
|
assertEquals(" ", subjectProperty.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWorkbookProperties() throws Exception {
|
void testWorkbookProperties() throws Exception {
|
||||||
XWPFDocument doc = new XWPFDocument();
|
try (XWPFDocument doc = new XWPFDocument()) {
|
||||||
POIXMLProperties props = doc.getProperties();
|
POIXMLProperties props = doc.getProperties();
|
||||||
assertNotNull(props);
|
assertNotNull(props);
|
||||||
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
|
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
|
||||||
doc.close();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAddParagraph() throws IOException {
|
void testAddParagraph() throws IOException {
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx")) {
|
||||||
assertEquals(3, doc.getParagraphs().size());
|
assertEquals(3, doc.getParagraphs().size());
|
||||||
|
|
||||||
XWPFParagraph p = doc.createParagraph();
|
XWPFParagraph p = doc.createParagraph();
|
||||||
assertEquals(p, doc.getParagraphs().get(3));
|
assertEquals(p, doc.getParagraphs().get(3));
|
||||||
assertEquals(4, doc.getParagraphs().size());
|
assertEquals(4, doc.getParagraphs().size());
|
||||||
|
|
||||||
assertEquals(3, doc.getParagraphPos(3));
|
assertEquals(3, doc.getParagraphPos(3));
|
||||||
assertEquals(3, doc.getPosOfParagraph(p));
|
assertEquals(3, doc.getPosOfParagraph(p));
|
||||||
|
|
||||||
CTP ctp = p.getCTP();
|
CTP ctp = p.getCTP();
|
||||||
XWPFParagraph newP = doc.getParagraph(ctp);
|
XWPFParagraph newP = doc.getParagraph(ctp);
|
||||||
assertSame(p, newP);
|
assertSame(p, newP);
|
||||||
XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor();
|
XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor();
|
||||||
XWPFParagraph cP = doc.insertNewParagraph(cursor);
|
XWPFParagraph cP = doc.insertNewParagraph(cursor);
|
||||||
assertSame(cP, doc.getParagraphs().get(0));
|
assertSame(cP, doc.getParagraphs().get(0));
|
||||||
assertEquals(5, doc.getParagraphs().size());
|
assertEquals(5, doc.getParagraphs().size());
|
||||||
doc.close();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAddPicture() throws IOException, InvalidFormatException {
|
void testAddPicture() throws IOException, InvalidFormatException {
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx")) {
|
||||||
byte[] jpeg = XWPFTestDataSamples.getImage("nature1.jpg");
|
byte[] jpeg = XWPFTestDataSamples.getImage("nature1.jpg");
|
||||||
String relationId = doc.addPictureData(jpeg, Document.PICTURE_TYPE_JPEG);
|
String relationId = doc.addPictureData(jpeg, Document.PICTURE_TYPE_JPEG);
|
||||||
|
|
||||||
XWPFPictureData relationById = (XWPFPictureData) doc.getRelationById(relationId);
|
XWPFPictureData relationById = (XWPFPictureData) doc.getRelationById(relationId);
|
||||||
assertNotNull(relationById);
|
assertNotNull(relationById);
|
||||||
byte[] newJpeg = relationById.getData();
|
byte[] newJpeg = relationById.getData();
|
||||||
assertEquals(newJpeg.length, jpeg.length);
|
assertEquals(newJpeg.length, jpeg.length);
|
||||||
for (int i = 0; i < jpeg.length; i++) {
|
for (int i = 0; i < jpeg.length; i++) {
|
||||||
assertEquals(newJpeg[i], jpeg[i]);
|
assertEquals(newJpeg[i], jpeg[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
doc.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAllPictureFormats() throws IOException, InvalidFormatException {
|
void testAllPictureFormats() throws IOException, InvalidFormatException {
|
||||||
XWPFDocument doc = new XWPFDocument();
|
try (XWPFDocument doc = new XWPFDocument()) {
|
||||||
|
|
||||||
doc.addPictureData(new byte[10], Document.PICTURE_TYPE_EMF);
|
doc.addPictureData(new byte[10], Document.PICTURE_TYPE_EMF);
|
||||||
doc.addPictureData(new byte[11], Document.PICTURE_TYPE_WMF);
|
doc.addPictureData(new byte[11], Document.PICTURE_TYPE_WMF);
|
||||||
doc.addPictureData(new byte[12], Document.PICTURE_TYPE_PICT);
|
doc.addPictureData(new byte[12], Document.PICTURE_TYPE_PICT);
|
||||||
doc.addPictureData(new byte[13], Document.PICTURE_TYPE_JPEG);
|
doc.addPictureData(new byte[13], Document.PICTURE_TYPE_JPEG);
|
||||||
doc.addPictureData(new byte[14], Document.PICTURE_TYPE_PNG);
|
doc.addPictureData(new byte[14], Document.PICTURE_TYPE_PNG);
|
||||||
doc.addPictureData(new byte[15], Document.PICTURE_TYPE_DIB);
|
doc.addPictureData(new byte[15], Document.PICTURE_TYPE_DIB);
|
||||||
doc.addPictureData(new byte[16], Document.PICTURE_TYPE_GIF);
|
doc.addPictureData(new byte[16], Document.PICTURE_TYPE_GIF);
|
||||||
doc.addPictureData(new byte[17], Document.PICTURE_TYPE_TIFF);
|
doc.addPictureData(new byte[17], Document.PICTURE_TYPE_TIFF);
|
||||||
doc.addPictureData(new byte[18], Document.PICTURE_TYPE_EPS);
|
doc.addPictureData(new byte[18], Document.PICTURE_TYPE_EPS);
|
||||||
doc.addPictureData(new byte[19], Document.PICTURE_TYPE_BMP);
|
doc.addPictureData(new byte[19], Document.PICTURE_TYPE_BMP);
|
||||||
doc.addPictureData(new byte[20], Document.PICTURE_TYPE_WPG);
|
doc.addPictureData(new byte[20], Document.PICTURE_TYPE_WPG);
|
||||||
|
|
||||||
assertEquals(11, doc.getAllPictures().size());
|
assertEquals(11, doc.getAllPictures().size());
|
||||||
|
|
||||||
XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc);
|
try (XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc)) {
|
||||||
assertEquals(11, doc2.getAllPictures().size());
|
assertEquals(11, doc2.getAllPictures().size());
|
||||||
doc2.close();
|
}
|
||||||
doc.close();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -201,8 +193,8 @@ public final class TestXWPFDocument {
|
||||||
assertEquals("rId7", h.getHyperlinkId());
|
assertEquals("rId7", h.getHyperlinkId());
|
||||||
|
|
||||||
assertEquals("https://poi.apache.org/", h.getHyperlink(doc).getURL());
|
assertEquals("https://poi.apache.org/", h.getHyperlink(doc).getURL());
|
||||||
assertEquals(p.getRuns().size(), 1);
|
assertEquals(1, p.getRuns().size());
|
||||||
assertEquals(p.getRuns().get(0), h);
|
assertEquals(h, p.getRuns().get(0));
|
||||||
|
|
||||||
h = p.createHyperlinkRun("https://poi.apache.org/");
|
h = p.createHyperlinkRun("https://poi.apache.org/");
|
||||||
h.setText("Apache POI");
|
h.setText("Apache POI");
|
||||||
|
@ -426,32 +418,27 @@ public final class TestXWPFDocument {
|
||||||
settings.setMirrorMargins(true);
|
settings.setMirrorMargins(true);
|
||||||
assertTrue(settings.getMirrorMargins());
|
assertTrue(settings.getMirrorMargins());
|
||||||
|
|
||||||
XWPFDocument doc = new XWPFDocument();
|
try (XWPFDocument doc = new XWPFDocument()) {
|
||||||
assertEquals(100, doc.getZoomPercent());
|
assertEquals(100, doc.getZoomPercent());
|
||||||
|
|
||||||
doc.setZoomPercent(50);
|
doc.setZoomPercent(50);
|
||||||
assertEquals(50, doc.getZoomPercent());
|
assertEquals(50, doc.getZoomPercent());
|
||||||
|
|
||||||
doc.setZoomPercent(200);
|
doc.setZoomPercent(200);
|
||||||
assertEquals(200, doc.getZoomPercent());
|
assertEquals(200, doc.getZoomPercent());
|
||||||
|
|
||||||
assertFalse(doc.getEvenAndOddHeadings());
|
assertFalse(doc.getEvenAndOddHeadings());
|
||||||
doc.setEvenAndOddHeadings(true);
|
doc.setEvenAndOddHeadings(true);
|
||||||
assertTrue(doc.getEvenAndOddHeadings());
|
assertTrue(doc.getEvenAndOddHeadings());
|
||||||
|
|
||||||
assertFalse(doc.getMirrorMargins());
|
assertFalse(doc.getMirrorMargins());
|
||||||
doc.setMirrorMargins(true);
|
doc.setMirrorMargins(true);
|
||||||
assertTrue(doc.getMirrorMargins());
|
assertTrue(doc.getMirrorMargins());
|
||||||
|
|
||||||
XWPFDocument back = XWPFTestDataSamples.writeOutAndReadBack(doc);
|
try (XWPFDocument back = XWPFTestDataSamples.writeOutAndReadBack(doc)) {
|
||||||
assertEquals(200, back.getZoomPercent());
|
assertEquals(200, back.getZoomPercent());
|
||||||
back.close();
|
}
|
||||||
|
}
|
||||||
// OutputStream out = new FileOutputStream("/tmp/testZoom.docx");
|
|
||||||
// doc.write(out);
|
|
||||||
// out.close();
|
|
||||||
|
|
||||||
doc.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -464,20 +451,19 @@ public final class TestXWPFDocument {
|
||||||
@Test
|
@Test
|
||||||
@Disabled("XWPF should be able to write to a new Stream when opened Read-Only")
|
@Disabled("XWPF should be able to write to a new Stream when opened Read-Only")
|
||||||
void testWriteFromReadOnlyOPC() throws Exception {
|
void testWriteFromReadOnlyOPC() throws Exception {
|
||||||
OPCPackage opc = OPCPackage.open(
|
try (OPCPackage opc = OPCPackage.open(
|
||||||
POIDataSamples.getDocumentInstance().getFile("SampleDoc.docx"),
|
POIDataSamples.getDocumentInstance().getFile("SampleDoc.docx"),
|
||||||
PackageAccess.READ
|
PackageAccess.READ
|
||||||
);
|
);
|
||||||
XWPFDocument doc = new XWPFDocument(opc);
|
XWPFDocument doc = new XWPFDocument(opc);
|
||||||
|
XWPFWordExtractor ext = new XWPFWordExtractor(doc)
|
||||||
|
) {
|
||||||
|
final String origText = ext.getText();
|
||||||
|
|
||||||
final String origText;
|
try (XWPFDocument doc2 = XWPFTestDataSamples.writeOutAndReadBack(doc);
|
||||||
try (XWPFWordExtractor ext = new XWPFWordExtractor(doc)) {
|
XWPFWordExtractor ext2 = new XWPFWordExtractor(doc2)) {
|
||||||
origText = ext.getText();
|
assertEquals(origText, ext2.getText());
|
||||||
|
}
|
||||||
doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
|
|
||||||
}
|
|
||||||
try (XWPFWordExtractor ext = new XWPFWordExtractor(doc)) {
|
|
||||||
assertEquals(origText, ext.getText());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@ public final class TestExtractor {
|
||||||
assertNotNull(nText);
|
assertNotNull(nText);
|
||||||
|
|
||||||
// Notes record were corrupt, so don't expect any
|
// Notes record were corrupt, so don't expect any
|
||||||
assertEquals(nText.length(), 0);
|
assertEquals(0, nText.length());
|
||||||
|
|
||||||
// Slide records were fine
|
// Slide records were fine
|
||||||
assertContains(text, "Using Disease Surveillance and Response");
|
assertContains(text, "Using Disease Surveillance and Response");
|
||||||
|
|
|
@ -116,7 +116,7 @@ public final class TestShapes {
|
||||||
String text = txtbox.getText();
|
String text = txtbox.getText();
|
||||||
assertNotNull(text);
|
assertNotNull(text);
|
||||||
|
|
||||||
assertEquals(txtbox.getTextParagraphs().get(0).getTextRuns().size(), 1);
|
assertEquals(1, txtbox.getTextParagraphs().get(0).getTextRuns().size());
|
||||||
HSLFTextRun rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
|
HSLFTextRun rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||||
|
|
||||||
switch (text) {
|
switch (text) {
|
||||||
|
|
|
@ -80,9 +80,9 @@ public final class TestExControl {
|
||||||
|
|
||||||
ExOleObjAtom oleObj = record.getExOleObjAtom();
|
ExOleObjAtom oleObj = record.getExOleObjAtom();
|
||||||
assertNotNull(oleObj);
|
assertNotNull(oleObj);
|
||||||
assertEquals(oleObj.getDrawAspect(), ExOleObjAtom.DRAW_ASPECT_VISIBLE);
|
assertEquals(ExOleObjAtom.DRAW_ASPECT_VISIBLE, oleObj.getDrawAspect());
|
||||||
assertEquals(oleObj.getType(), ExOleObjAtom.TYPE_CONTROL);
|
assertEquals(ExOleObjAtom.TYPE_CONTROL, oleObj.getType());
|
||||||
assertEquals(oleObj.getSubType(), ExOleObjAtom.SUBTYPE_DEFAULT);
|
assertEquals(ExOleObjAtom.SUBTYPE_DEFAULT, oleObj.getSubType());
|
||||||
|
|
||||||
assertEquals("Shockwave Flash Object", record.getMenuName());
|
assertEquals("Shockwave Flash Object", record.getMenuName());
|
||||||
assertEquals("ShockwaveFlash.ShockwaveFlash.9", record.getProgId());
|
assertEquals("ShockwaveFlash.ShockwaveFlash.9", record.getProgId());
|
||||||
|
|
|
@ -38,12 +38,13 @@ public final class TestExOleObjAtom {
|
||||||
ExOleObjAtom record = new ExOleObjAtom(data, 0, data.length);
|
ExOleObjAtom record = new ExOleObjAtom(data, 0, data.length);
|
||||||
assertEquals(RecordTypes.ExOleObjAtom.typeID, record.getRecordType());
|
assertEquals(RecordTypes.ExOleObjAtom.typeID, record.getRecordType());
|
||||||
|
|
||||||
assertEquals(record.getDrawAspect(), ExOleObjAtom.DRAW_ASPECT_VISIBLE);
|
assertEquals(ExOleObjAtom.DRAW_ASPECT_VISIBLE, record.getDrawAspect());
|
||||||
assertEquals(record.getType(), ExOleObjAtom.TYPE_CONTROL);
|
assertEquals(ExOleObjAtom.TYPE_CONTROL, record.getType());
|
||||||
assertEquals(record.getObjID(), 1);
|
assertEquals(1, record.getObjID());
|
||||||
assertEquals(record.getSubType(), ExOleObjAtom.SUBTYPE_DEFAULT);
|
assertEquals(ExOleObjAtom.SUBTYPE_DEFAULT, record.getSubType());
|
||||||
assertEquals(record.getObjStgDataRef(), 2);
|
assertEquals(2, record.getObjStgDataRef());
|
||||||
assertEquals(record.getOptions(), 1283584); //ther meaning is unknown
|
// the meaning is unknown
|
||||||
|
assertEquals(1283584, record.getOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -55,28 +55,28 @@ public final class TestFontCollection {
|
||||||
void testFonts() {
|
void testFonts() {
|
||||||
FontCollection fonts = new FontCollection(data, 0, data.length);
|
FontCollection fonts = new FontCollection(data, 0, data.length);
|
||||||
Record[] child = fonts.getChildRecords();
|
Record[] child = fonts.getChildRecords();
|
||||||
assertEquals(child.length, 1);
|
assertEquals(1, child.length);
|
||||||
|
|
||||||
FontEntityAtom fnt = (FontEntityAtom)child[0];
|
FontEntityAtom fnt = (FontEntityAtom)child[0];
|
||||||
assertEquals(fnt.getFontName(), "Times New Roman");
|
assertEquals("Times New Roman", fnt.getFontName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testAddFont() {
|
void testAddFont() {
|
||||||
FontCollection fonts = new FontCollection(data, 0, data.length);
|
FontCollection fonts = new FontCollection(data, 0, data.length);
|
||||||
HSLFFontInfo fi = fonts.addFont(HSLFFontInfoPredefined.TIMES_NEW_ROMAN);
|
HSLFFontInfo fi = fonts.addFont(HSLFFontInfoPredefined.TIMES_NEW_ROMAN);
|
||||||
assertEquals((int)fi.getIndex(), 0);
|
assertEquals(0, (int)fi.getIndex());
|
||||||
fi = fonts.addFont(new HSLFFontInfo("Helvetica"));
|
fi = fonts.addFont(new HSLFFontInfo("Helvetica"));
|
||||||
assertEquals((int)fi.getIndex(), 1);
|
assertEquals(1, (int)fi.getIndex());
|
||||||
fi = fonts.addFont(HSLFFontInfoPredefined.ARIAL);
|
fi = fonts.addFont(HSLFFontInfoPredefined.ARIAL);
|
||||||
assertEquals((int)fi.getIndex(), 2);
|
assertEquals(2, (int)fi.getIndex());
|
||||||
//the font being added twice
|
//the font being added twice
|
||||||
fi = fonts.addFont(HSLFFontInfoPredefined.ARIAL);
|
fi = fonts.addFont(HSLFFontInfoPredefined.ARIAL);
|
||||||
assertEquals((int)fi.getIndex(), 2);
|
assertEquals(2, (int)fi.getIndex());
|
||||||
|
|
||||||
// Font collection should contain 3 fonts
|
// Font collection should contain 3 fonts
|
||||||
Record[] child = fonts.getChildRecords();
|
Record[] child = fonts.getChildRecords();
|
||||||
assertEquals(child.length, 3);
|
assertEquals(3, child.length);
|
||||||
|
|
||||||
// Check we get the right font name for the indicies
|
// Check we get the right font name for the indicies
|
||||||
fi = fonts.getFontInfo(0);
|
fi = fonts.getFontInfo(0);
|
||||||
|
|
|
@ -45,8 +45,8 @@ public final class TestTextRulerAtom {
|
||||||
@Test
|
@Test
|
||||||
void testReadRuler() {
|
void testReadRuler() {
|
||||||
TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length);
|
TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length);
|
||||||
assertEquals(ruler.getNumberOfLevels(), 0);
|
assertEquals(0, ruler.getNumberOfLevels());
|
||||||
assertEquals(ruler.getDefaultTabSize(), 0);
|
assertEquals(0, ruler.getDefaultTabSize());
|
||||||
|
|
||||||
List<HSLFTabStop> tabStops = ruler.getTabStops();
|
List<HSLFTabStop> tabStops = ruler.getTabStops();
|
||||||
assertNotNull(tabStops);
|
assertNotNull(tabStops);
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class TestExtractEmbeddedMSG {
|
||||||
expectedMessageDate.set(Calendar.MILLISECOND, 0);
|
expectedMessageDate.set(Calendar.MILLISECOND, 0);
|
||||||
assertEquals(expectedMessageDate.getTimeInMillis(), messageDate.getTimeInMillis());
|
assertEquals(expectedMessageDate.getTimeInMillis(), messageDate.getTimeInMillis());
|
||||||
// test variable length property
|
// test variable length property
|
||||||
assertEquals(msg.getSubject(), "Test Attachment");
|
assertEquals("Test Attachment", msg.getSubject());
|
||||||
}
|
}
|
||||||
|
|
||||||
private POIFSFileSystem rebuildFromAttached(MAPIMessage attachedMsg) throws IOException {
|
private POIFSFileSystem rebuildFromAttached(MAPIMessage attachedMsg) throws IOException {
|
||||||
|
|
|
@ -26,53 +26,51 @@ import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public final class TestPlexOfCps {
|
public final class TestPlexOfCps {
|
||||||
private PlexOfCps _plexOfCps;
|
private PlexOfCps _plexOfCps;
|
||||||
private HWPFDocFixture _hWPFDocFixture;
|
private HWPFDocFixture _hWPFDocFixture;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testWriteRead() {
|
void testWriteRead() {
|
||||||
_plexOfCps = new PlexOfCps(4);
|
_plexOfCps = new PlexOfCps(4);
|
||||||
|
|
||||||
int last = 0;
|
int last = 0;
|
||||||
for (int x = 0; x < 110; x++)
|
for (int x = 0; x < 110; x++) {
|
||||||
{
|
byte[] intHolder = new byte[4];
|
||||||
byte[] intHolder = new byte[4];
|
int span = (int) (110.0f * Math.random());
|
||||||
int span = (int)(110.0f * Math.random());
|
LittleEndian.putInt(intHolder, 0, span);
|
||||||
LittleEndian.putInt(intHolder, 0, span);
|
_plexOfCps.addProperty(new GenericPropertyNode(last, last + span, intHolder));
|
||||||
_plexOfCps.addProperty(new GenericPropertyNode(last, last + span, intHolder));
|
last += span;
|
||||||
last += span;
|
}
|
||||||
|
|
||||||
|
byte[] output = _plexOfCps.toByteArray();
|
||||||
|
_plexOfCps = new PlexOfCps(output, 0, output.length, 4);
|
||||||
|
int len = _plexOfCps.length();
|
||||||
|
assertEquals(110, len);
|
||||||
|
|
||||||
|
last = 0;
|
||||||
|
for (int x = 0; x < len; x++) {
|
||||||
|
GenericPropertyNode node = _plexOfCps.getProperty(x);
|
||||||
|
assertEquals(node.getStart(), last);
|
||||||
|
last = node.getEnd();
|
||||||
|
int span = LittleEndian.getInt(node.getBytes());
|
||||||
|
assertEquals(node.getEnd() - node.getStart(), span);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] output = _plexOfCps.toByteArray();
|
@BeforeEach
|
||||||
_plexOfCps = new PlexOfCps(output, 0, output.length, 4);
|
void setUp() throws Exception {
|
||||||
int len = _plexOfCps.length();
|
/* @todo verify the constructors*/
|
||||||
assertEquals(len, 110);
|
_hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
|
||||||
|
|
||||||
last = 0;
|
_hWPFDocFixture.setUp();
|
||||||
for (int x = 0; x < len; x++)
|
|
||||||
{
|
|
||||||
GenericPropertyNode node = _plexOfCps.getProperty(x);
|
|
||||||
assertEquals(node.getStart(), last);
|
|
||||||
last = node.getEnd();
|
|
||||||
int span = LittleEndian.getInt(node.getBytes());
|
|
||||||
assertEquals(node.getEnd()-node.getStart(), span);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
@AfterEach
|
||||||
void setUp() throws Exception {
|
void tearDown() {
|
||||||
/**@todo verify the constructors*/
|
_plexOfCps = null;
|
||||||
_hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE);
|
_hWPFDocFixture.tearDown();
|
||||||
|
|
||||||
_hWPFDocFixture.setUp();
|
_hWPFDocFixture = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
void tearDown() throws Exception {
|
|
||||||
_plexOfCps = null;
|
|
||||||
_hWPFDocFixture.tearDown();
|
|
||||||
|
|
||||||
_hWPFDocFixture = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,9 +52,8 @@ public final class TestPictures {
|
||||||
List<Picture> pics = doc.getPicturesTable().getAllPictures();
|
List<Picture> pics = doc.getPicturesTable().getAllPictures();
|
||||||
|
|
||||||
assertNotNull(pics);
|
assertNotNull(pics);
|
||||||
assertEquals(pics.size(), 2);
|
assertEquals(2, pics.size());
|
||||||
for (int i = 0; i < pics.size(); i++) {
|
for (Picture pic : pics) {
|
||||||
Picture pic = pics.get(i);
|
|
||||||
assertNotNull(pic.suggestFileExtension());
|
assertNotNull(pic.suggestFileExtension());
|
||||||
assertNotNull(pic.suggestFullFileName());
|
assertNotNull(pic.suggestFullFileName());
|
||||||
}
|
}
|
||||||
|
@ -289,7 +288,6 @@ public final class TestPictures {
|
||||||
assertEquals(0, plain8s);
|
assertEquals(0, plain8s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test
|
@Test
|
||||||
void testCroppedPictures() {
|
void testCroppedPictures() {
|
||||||
HWPFDocument doc = openSampleFile("testCroppedPictures.doc");
|
HWPFDocument doc = openSampleFile("testCroppedPictures.doc");
|
||||||
|
@ -334,40 +332,40 @@ public final class TestPictures {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPictureWithAlternativeText() {
|
void testPictureWithAlternativeText() throws IOException {
|
||||||
HWPFDocument document = openSampleFile("Picture_Alternative_Text.doc");
|
try (HWPFDocument document = openSampleFile("Picture_Alternative_Text.doc")) {
|
||||||
PicturesTable pictureTable = document.getPicturesTable();
|
PicturesTable pictureTable = document.getPicturesTable();
|
||||||
Picture picture = pictureTable.getAllPictures().get(0);
|
Picture picture = pictureTable.getAllPictures().get(0);
|
||||||
|
|
||||||
assertEquals("This is the alternative text for the picture.", picture.getDescription());
|
assertEquals("This is the alternative text for the picture.", picture.getDescription());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled("This bug is not fixed yet")
|
@Disabled("This bug is not fixed yet")
|
||||||
@Test
|
@Test
|
||||||
void test58804_1() throws Exception {
|
void test58804_1() throws Exception {
|
||||||
HWPFDocument docA = openSampleFile("58804_1.doc");
|
try (HWPFDocument docA = openSampleFile("58804_1.doc")) {
|
||||||
|
expectImages(docA, 1);
|
||||||
|
|
||||||
expectImages(docA, 1);
|
try (HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA);
|
||||||
|
OutputStream out = new FileOutputStream("/tmp/58804_1_out.doc")) {
|
||||||
HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA);
|
docB.write(out);
|
||||||
|
expectImages(docB, 1);
|
||||||
try (OutputStream out = new FileOutputStream("/tmp/58804_1_out.doc")) {
|
}
|
||||||
docB.write(out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expectImages(docB, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled("This bug is not fixed yet")
|
@Disabled("This bug is not fixed yet")
|
||||||
@Test
|
@Test
|
||||||
void test58804() throws Exception {
|
void test58804() throws IOException {
|
||||||
HWPFDocument docA = openSampleFile("58804.doc");
|
try (HWPFDocument docA = openSampleFile("58804.doc")) {
|
||||||
|
expectImages(docA, 7);
|
||||||
|
|
||||||
expectImages(docA, 7);
|
try (HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA)) {
|
||||||
|
expectImages(docB, 7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA);
|
|
||||||
|
|
||||||
expectImages(docB, 7);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void expectImages(HWPFDocument docA, int expectedCount) {
|
private void expectImages(HWPFDocument docA, int expectedCount) {
|
||||||
|
|
|
@ -64,33 +64,31 @@ public final class TestRange {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBug46817() throws IOException {
|
void testBug46817() throws IOException {
|
||||||
InputStream is = SAMPLES.openResourceAsStream( "Bug46817.doc" );
|
try (InputStream is = SAMPLES.openResourceAsStream("Bug46817.doc");
|
||||||
HWPFDocument hwpfDocument = new HWPFDocument( is );
|
HWPFDocument hwpfDocument = new HWPFDocument(is)) {
|
||||||
is.close();
|
|
||||||
|
|
||||||
final List<SEPX> sections = hwpfDocument.getSectionTable()
|
final List<SEPX> sections = hwpfDocument.getSectionTable().getSections();
|
||||||
.getSections();
|
assertEquals( 1, sections.size() );
|
||||||
assertEquals( sections.size(), 1 );
|
|
||||||
|
|
||||||
// whole document, including additional text from shape
|
// whole document, including additional text from shape
|
||||||
SEPX sepx = sections.get( 0 );
|
SEPX sepx = sections.get( 0 );
|
||||||
assertEquals( sepx.getStart(), 0 );
|
assertEquals( 0, sepx.getStart() );
|
||||||
assertEquals( sepx.getEnd(), 1428 );
|
assertEquals( 1428, sepx.getEnd() );
|
||||||
|
|
||||||
// only main range
|
// only main range
|
||||||
Range range = hwpfDocument.getRange();
|
Range range = hwpfDocument.getRange();
|
||||||
assertEquals( range.getStartOffset(), 0 );
|
assertEquals( 0, range.getStartOffset() );
|
||||||
assertEquals( range.getEndOffset(), 766 );
|
assertEquals( 766, range.getEndOffset() );
|
||||||
|
|
||||||
Paragraph lastInMainRange = range.getParagraph( range.numParagraphs() - 1);
|
Paragraph lastInMainRange = range.getParagraph( range.numParagraphs() - 1);
|
||||||
assertTrue( lastInMainRange.getEndOffset() <= 766 );
|
assertTrue( lastInMainRange.getEndOffset() <= 766 );
|
||||||
|
|
||||||
Section section = range.getSection( 0 );
|
Section section = range.getSection( 0 );
|
||||||
assertTrue( section.getEndOffset() <= 766 );
|
assertTrue( section.getEndOffset() <= 766 );
|
||||||
|
|
||||||
Paragraph lastInMainSection = section.getParagraph( section
|
Paragraph lastInMainSection = section.getParagraph( section
|
||||||
.numParagraphs() - 1);
|
.numParagraphs() - 1);
|
||||||
assertTrue( lastInMainSection.getEndOffset() <= 766 );
|
assertTrue( lastInMainSection.getEndOffset() <= 766 );
|
||||||
hwpfDocument.close();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ final class TestBasic {
|
||||||
final SummaryInformation si = (SummaryInformation)PropertySetFactory.create(is);
|
final SummaryInformation si = (SummaryInformation)PropertySetFactory.create(is);
|
||||||
final List<Section> sections = si.getSections();
|
final List<Section> sections = si.getSections();
|
||||||
final Section s = sections.get(0);
|
final Section s = sections.get(0);
|
||||||
assertEquals(s.getFormatID(), SummaryInformation.FORMAT_ID);
|
assertEquals(SummaryInformation.FORMAT_ID, s.getFormatID());
|
||||||
assertNotNull(s.getProperties());
|
assertNotNull(s.getProperties());
|
||||||
assertEquals(17, s.getPropertyCount());
|
assertEquals(17, s.getPropertyCount());
|
||||||
assertEquals("Titel", s.getProperty(PropertyIDMap.PID_TITLE));
|
assertEquals("Titel", s.getProperty(PropertyIDMap.PID_TITLE));
|
||||||
|
|
|
@ -141,13 +141,13 @@ final class TestEmptyProperties {
|
||||||
assertNotNull(s.getTemplate());
|
assertNotNull(s.getTemplate());
|
||||||
assertNotNull(s.getLastAuthor());
|
assertNotNull(s.getLastAuthor());
|
||||||
assertNotNull(s.getRevNumber());
|
assertNotNull(s.getRevNumber());
|
||||||
assertEquals(s.getEditTime(), 0);
|
assertEquals(0, s.getEditTime());
|
||||||
assertNull(s.getLastPrinted());
|
assertNull(s.getLastPrinted());
|
||||||
assertNull(s.getCreateDateTime());
|
assertNull(s.getCreateDateTime());
|
||||||
assertNull(s.getLastSaveDateTime());
|
assertNull(s.getLastSaveDateTime());
|
||||||
assertEquals(s.getPageCount(), 0);
|
assertEquals(0, s.getPageCount());
|
||||||
assertEquals(s.getWordCount(), 0);
|
assertEquals(0, s.getWordCount());
|
||||||
assertEquals(s.getCharCount(), 0);
|
assertEquals(0, s.getCharCount());
|
||||||
assertNull(s.getThumbnail());
|
assertNull(s.getThumbnail());
|
||||||
assertNull(s.getApplicationName());
|
assertNull(s.getApplicationName());
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue