mirror of https://github.com/apache/poi.git
Sonar fixes
add asserts to tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1885537 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ac19545a66
commit
ca71e9dacf
|
@ -27,19 +27,12 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
|||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
@ -56,8 +49,6 @@ import java.util.function.Function;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
||||
|
@ -66,6 +57,7 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||
import org.apache.poi.openxml4j.opc.PackagePartName;
|
||||
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
|
||||
import org.apache.poi.sl.draw.DrawFactory;
|
||||
import org.apache.poi.sl.draw.DrawPaint;
|
||||
import org.apache.poi.sl.extractor.SlideShowExtractor;
|
||||
import org.apache.poi.sl.usermodel.Hyperlink;
|
||||
|
@ -1051,4 +1043,41 @@ class TestXSLFBugs {
|
|||
assertEquals("Open Jakarta POI HSSF module test ", strings.get(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void bug59056() throws IOException {
|
||||
assumeFalse(xslfOnly);
|
||||
|
||||
final double[][] clips = {
|
||||
{ 50.999999999999986, 51.0, 298.0, 98.0 },
|
||||
{ 51.00000000000003, 51.0, 298.0, 98.0 },
|
||||
{ 51.0, 51.0, 298.0, 98.0 },
|
||||
{ 250.02000796164992, 93.10370370370373, 78.61839367617523, 55.89629629629627 },
|
||||
{ 79.58198774450841, 53.20887318960063, 109.13118501448272, 9.40935058567127 },
|
||||
};
|
||||
|
||||
DummyGraphics2d dgfx = new DummyGraphics2d(new NullPrintStream()) {
|
||||
int idx = 0;
|
||||
@Override
|
||||
public void clip(java.awt.Shape s) {
|
||||
assertTrue(s instanceof Rectangle2D);
|
||||
Rectangle2D r = (Rectangle2D)s;
|
||||
|
||||
double[] clip = clips[idx++];
|
||||
assertEquals(clip[0], r.getX(), 0.5);
|
||||
assertEquals(clip[1], r.getY(), 0.5);
|
||||
assertEquals(clip[2], r.getWidth(), 0.5);
|
||||
assertEquals(clip[3], r.getHeight(), 0.5);
|
||||
}
|
||||
};
|
||||
|
||||
Rectangle2D box = new Rectangle2D.Double(51, 51, 298, 98);
|
||||
DrawFactory df = DrawFactory.getInstance(dgfx);
|
||||
|
||||
try (SlideShow<?,?> ppt = SlideShowFactory.create(slTests.getFile("54541_cropped_bitmap.ppt"))) {
|
||||
ppt.getSlides().get(0).getShapes().forEach(shape -> df.drawShape(dgfx, shape, box));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,10 +17,17 @@
|
|||
|
||||
package org.apache.poi.hslf.model;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.poi.hslf.HSLFTestDataSamples;
|
||||
import org.apache.poi.hslf.usermodel.HSLFLine;
|
||||
import org.apache.poi.hslf.usermodel.HSLFShape;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlide;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||
import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound;
|
||||
|
@ -32,101 +39,73 @@ import org.junit.jupiter.api.Test;
|
|||
*/
|
||||
public final class TestLine {
|
||||
|
||||
private static final Object[][] lines = {
|
||||
// line styles
|
||||
{ 75, 200, LineCompound.SINGLE, Color.blue },
|
||||
{ 75, 230, LineCompound.DOUBLE, 3.5 },
|
||||
{ 75, 260, LineCompound.TRIPLE, 6d },
|
||||
{ 75, 290, LineCompound.THICK_THIN, 4.5d },
|
||||
{ 75, 320, LineCompound.THIN_THICK, 5.5d },
|
||||
// line dashing
|
||||
{ 450, 200, LineDash.SOLID },
|
||||
{ 450, 230, LineDash.DASH },
|
||||
{ 450, 260, LineDash.DOT },
|
||||
{ 450, 290, LineDash.DASH_DOT },
|
||||
{ 450, 320, LineDash.LG_DASH_DOT_DOT },
|
||||
// Combinations
|
||||
{ 75, 400, LineDash.DASH_DOT, LineCompound.TRIPLE, 5d },
|
||||
{ 75, 430, LineDash.DASH, LineCompound.THICK_THIN, 4d },
|
||||
{ 75, 460, LineDash.DOT, LineCompound.DOUBLE, 8d }
|
||||
};
|
||||
|
||||
|
||||
@Test
|
||||
void testCreateLines() throws IOException {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow();
|
||||
|
||||
HSLFSlide slide = ppt.createSlide();
|
||||
try (HSLFSlideShow ppt1 = new HSLFSlideShow()) {
|
||||
HSLFSlide slide1 = ppt1.createSlide();
|
||||
slide1.addTitle().setText("Lines tester");
|
||||
|
||||
slide.addTitle().setText("Lines tester");
|
||||
for (Object[] line : lines) {
|
||||
HSLFLine hslfLine = new HSLFLine();
|
||||
hslfLine.setAnchor(new Rectangle((Integer)line[0], (Integer)line[1], 300, 0));
|
||||
for (Object attr : Arrays.copyOfRange(line, 2, line.length)) {
|
||||
if (attr instanceof LineCompound) {
|
||||
hslfLine.setLineCompound((LineCompound)attr);
|
||||
} else if (attr instanceof Double) {
|
||||
hslfLine.setLineWidth((Double)attr);
|
||||
} else if (attr instanceof Color) {
|
||||
hslfLine.setLineColor((Color)attr);
|
||||
} else if (attr instanceof LineDash) {
|
||||
hslfLine.setLineDash((LineDash)attr);
|
||||
}
|
||||
}
|
||||
slide1.addShape(hslfLine);
|
||||
}
|
||||
|
||||
HSLFLine line;
|
||||
try (HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1)) {
|
||||
HSLFSlide slide2 = ppt2.getSlides().get(0);
|
||||
|
||||
/**
|
||||
* line styles
|
||||
*/
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(75, 200, 300, 0));
|
||||
line.setLineCompound(LineCompound.SINGLE);
|
||||
line.setLineColor(Color.blue);
|
||||
slide.addShape(line);
|
||||
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(75, 230, 300, 0));
|
||||
line.setLineCompound(LineCompound.DOUBLE);
|
||||
line.setLineWidth(3.5);
|
||||
slide.addShape(line);
|
||||
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(75, 260, 300, 0));
|
||||
line.setLineCompound(LineCompound.TRIPLE);
|
||||
line.setLineWidth(6);
|
||||
slide.addShape(line);
|
||||
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(75, 290, 300, 0));
|
||||
line.setLineCompound(LineCompound.THICK_THIN);
|
||||
line.setLineWidth(4.5);
|
||||
slide.addShape(line);
|
||||
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(75, 320, 300, 0));
|
||||
line.setLineCompound(LineCompound.THIN_THICK);
|
||||
line.setLineWidth(5.5);
|
||||
slide.addShape(line);
|
||||
|
||||
/**
|
||||
* line dashing
|
||||
*/
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(450, 200, 300, 0));
|
||||
line.setLineDash(LineDash.SOLID);
|
||||
slide.addShape(line);
|
||||
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(450, 230, 300, 0));
|
||||
line.setLineDash(LineDash.DASH);
|
||||
slide.addShape(line);
|
||||
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(450, 260, 300, 0));
|
||||
line.setLineDash(LineDash.DOT);
|
||||
slide.addShape(line);
|
||||
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(450, 290, 300, 0));
|
||||
line.setLineDash(LineDash.DASH_DOT);
|
||||
slide.addShape(line);
|
||||
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(450, 320, 300, 0));
|
||||
line.setLineDash(LineDash.LG_DASH_DOT_DOT);
|
||||
slide.addShape(line);
|
||||
|
||||
/**
|
||||
* Combinations
|
||||
*/
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(75, 400, 300, 0));
|
||||
line.setLineDash(LineDash.DASH_DOT);
|
||||
line.setLineCompound(LineCompound.TRIPLE);
|
||||
line.setLineWidth(5.0);
|
||||
slide.addShape(line);
|
||||
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(75, 430, 300, 0));
|
||||
line.setLineDash(LineDash.DASH);
|
||||
line.setLineCompound(LineCompound.THICK_THIN);
|
||||
line.setLineWidth(4.0);
|
||||
slide.addShape(line);
|
||||
|
||||
line = new HSLFLine();
|
||||
line.setAnchor(new java.awt.Rectangle(75, 460, 300, 0));
|
||||
line.setLineDash(LineDash.DOT);
|
||||
line.setLineCompound(LineCompound.DOUBLE);
|
||||
line.setLineWidth(8.0);
|
||||
slide.addShape(line);
|
||||
|
||||
ppt.close();
|
||||
int idx = 0;
|
||||
for (HSLFShape shape : slide2.getShapes().subList(1,14)) {
|
||||
HSLFLine hslfLine = (HSLFLine)shape;
|
||||
Object[] line = lines[idx++];
|
||||
Rectangle2D anchor = hslfLine.getAnchor();
|
||||
assertEquals(line[0], (int)anchor.getX());
|
||||
assertEquals(line[1], (int)anchor.getY());
|
||||
for (Object attr : Arrays.copyOfRange(line, 2, line.length)) {
|
||||
if (attr instanceof LineCompound) {
|
||||
assertEquals(attr, hslfLine.getLineCompound());
|
||||
} else if (attr instanceof Double) {
|
||||
assertEquals(attr, hslfLine.getLineWidth());
|
||||
} else if (attr instanceof Color) {
|
||||
assertEquals(attr, hslfLine.getLineColor());
|
||||
} else if (attr instanceof LineDash) {
|
||||
assertEquals(attr, hslfLine.getLineDash());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,14 +17,23 @@
|
|||
|
||||
package org.apache.poi.hslf.record;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.hslf.exceptions.HSLFException;
|
||||
import org.apache.poi.hslf.model.textproperties.*;
|
||||
import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
|
||||
import org.apache.poi.hslf.model.textproperties.TextProp;
|
||||
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -702,7 +711,7 @@ public final class TestStyleTextPropAtom {
|
|||
// all the properties the mask says we have
|
||||
// Make sure we just do the best we can
|
||||
StyleTextPropAtom stpc = new StyleTextPropAtom(data_c,0,data_c.length);
|
||||
stpc.setParentTextSize(data_c_text_len);
|
||||
assertDoesNotThrow(() -> stpc.setParentTextSize(data_c_text_len));
|
||||
|
||||
// If we get here, we didn't break
|
||||
}
|
||||
|
|
|
@ -28,11 +28,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Path2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -67,7 +65,6 @@ import org.apache.poi.hslf.record.VBAInfoAtom;
|
|||
import org.apache.poi.hslf.record.VBAInfoContainer;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
import org.apache.poi.poifs.macros.VBAMacroReader;
|
||||
import org.apache.poi.sl.draw.DrawFactory;
|
||||
import org.apache.poi.sl.draw.DrawPaint;
|
||||
import org.apache.poi.sl.extractor.SlideShowExtractor;
|
||||
import org.apache.poi.sl.usermodel.ColorStyle;
|
||||
|
@ -87,6 +84,9 @@ import org.apache.poi.util.LittleEndian;
|
|||
import org.apache.poi.util.StringUtil;
|
||||
import org.apache.poi.util.Units;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
/**
|
||||
* Testcases for bugs entered in bugzilla
|
||||
|
@ -220,19 +220,6 @@ public final class TestBugs {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 42486: Failure parsing a seemingly valid PPT
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
void bug42486 () throws IOException {
|
||||
try (HSLFSlideShow ppt = open("42486.ppt")) {
|
||||
for (HSLFSlide slide : ppt.getSlides()) {
|
||||
List<HSLFShape> shape = slide.getShapes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 42524: NPE in Shape.getShapeType()
|
||||
*/
|
||||
|
@ -259,7 +246,7 @@ public final class TestBugs {
|
|||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
void bug42520 () throws IOException {
|
||||
void bug42520() throws IOException {
|
||||
try (HSLFSlideShow ppt = open("42520.ppt")) {
|
||||
|
||||
//test case from the bug report
|
||||
|
@ -267,6 +254,8 @@ public final class TestBugs {
|
|||
HSLFPictureShape picture = (HSLFPictureShape) shapeGroup.getShapes().get(0);
|
||||
picture.getPictureData();
|
||||
|
||||
boolean found = false;
|
||||
|
||||
//walk down the tree and see if there were no errors while reading
|
||||
for (HSLFSlide slide : ppt.getSlides()) {
|
||||
for (HSLFShape shape : slide.getShapes()) {
|
||||
|
@ -275,11 +264,15 @@ public final class TestBugs {
|
|||
for (HSLFShape comp : group.getShapes()) {
|
||||
if (comp instanceof HSLFPictureShape) {
|
||||
HSLFPictureData pict = ((HSLFPictureShape) comp).getPictureData();
|
||||
assertEquals("Rectangle 35893", comp.getShapeName());
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(found);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,17 +356,6 @@ public final class TestBugs {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 44770: java.lang.RuntimeException: Couldn't instantiate the class for
|
||||
* type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing
|
||||
*/
|
||||
@Test
|
||||
void bug44770() throws IOException {
|
||||
try (HSLFSlideShow ppt = open("44770.ppt")) {
|
||||
assertNotNull(ppt.getSlides().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 41071: Will not extract text from Powerpoint TextBoxes
|
||||
*/
|
||||
|
@ -413,33 +395,16 @@ public final class TestBugs {
|
|||
try (HSLFSlideShow ppt = open("49648.ppt")) {
|
||||
for (HSLFSlide slide : ppt.getSlides()) {
|
||||
for (List<HSLFTextParagraph> run : slide.getTextParagraphs()) {
|
||||
String repl = "With \u0123\u1234\u5678 unicode";
|
||||
String text = HSLFTextParagraph.getRawText(run);
|
||||
text = text.replace("{txtTot}", "With \u0123\u1234\u5678 unicode");
|
||||
text = text.replace("{txtTot}", repl);
|
||||
HSLFTextParagraph.setText(run, text);
|
||||
if (text.contains(repl)) {
|
||||
assertTrue(HSLFTextParagraph.getText(run).contains(repl));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 41246: AIOOB with illegal note references
|
||||
*/
|
||||
@Test
|
||||
void bug41246a() throws IOException {
|
||||
try (HSLFSlideShow ppt = open("41246-1.ppt")) {
|
||||
try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt)) {
|
||||
assertNotNull(ppt2.getSlides().get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug41246b() throws IOException {
|
||||
try (HSLFSlideShow ppt = open("41246-2.ppt")) {
|
||||
try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt)) {
|
||||
assertNotNull(ppt2.getSlides().get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -523,26 +488,6 @@ public final class TestBugs {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug37625() throws IOException {
|
||||
try (HSLFSlideShow ppt1 = open("37625.ppt");
|
||||
HSLFSlideShow ppt2 = writeOutAndReadBack(ppt1)) {
|
||||
assertEquals(29, ppt1.getSlides().size());
|
||||
assertNotNull(ppt2);
|
||||
assertEquals(29, ppt2.getSlides().size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug57272() throws IOException {
|
||||
try (HSLFSlideShow ppt1 = open("57272_corrupted_usereditatom.ppt");
|
||||
HSLFSlideShow ppt2 = writeOutAndReadBack(ppt1)) {
|
||||
assertEquals(6, ppt1.getSlides().size());
|
||||
assertNotNull(ppt2);
|
||||
assertEquals(6, ppt2.getSlides().size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug49541() throws IOException {
|
||||
try (HSLFSlideShow ppt = open("49541_symbol_map.ppt")) {
|
||||
|
@ -554,21 +499,36 @@ public final class TestBugs {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug47261() throws IOException {
|
||||
try (HSLFSlideShow ppt = open("bug47261.ppt")) {
|
||||
ppt.removeSlide(0);
|
||||
ppt.createSlide();
|
||||
writeOutAndReadBack(ppt).close();
|
||||
}
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
// bug47261.ppt has actually 16 slides, but also non-conforming multiple document records
|
||||
"bug47261.ppt, 1",
|
||||
"bug56240.ppt, 105",
|
||||
"bug58516.ppt, 5",
|
||||
"57272_corrupted_usereditatom.ppt, 6",
|
||||
"37625.ppt, 29",
|
||||
// Bug 41246: AIOOB with illegal note references
|
||||
"41246-1.ppt, 36",
|
||||
"41246-2.ppt, 16",
|
||||
// Bug 44770: java.lang.RuntimeException: Couldn't instantiate the class for
|
||||
// type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing
|
||||
"44770.ppt, 19",
|
||||
// Bug 42486: Failure parsing a seemingly valid PPT
|
||||
"42486.ppt, 33"
|
||||
})
|
||||
void testFile(String file, int slideCnt) throws IOException {
|
||||
try (HSLFSlideShow ppt = open(file)) {
|
||||
for (HSLFSlide slide : ppt.getSlides()) {
|
||||
List<HSLFShape> shape = slide.getShapes();
|
||||
assertFalse(shape.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug56240() throws IOException {
|
||||
try (HSLFSlideShow ppt = open("bug56240.ppt")) {
|
||||
int slideCnt = ppt.getSlides().size();
|
||||
assertEquals(105, slideCnt);
|
||||
writeOutAndReadBack(ppt).close();
|
||||
assertNotNull(ppt.getSlides().get(0));
|
||||
ppt.removeSlide(0);
|
||||
ppt.createSlide();
|
||||
try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt)) {
|
||||
assertEquals(slideCnt, ppt2.getSlides().size());
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -600,11 +560,6 @@ public final class TestBugs {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug58516() throws IOException {
|
||||
open("bug58516.ppt").close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug45124() throws IOException {
|
||||
try (HSLFSlideShow ppt = open("bug45124.ppt")) {
|
||||
|
@ -771,20 +726,13 @@ public final class TestBugs {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug58718() throws IOException {
|
||||
String[] files = {"bug58718_008524.ppt", "bug58718_008558.ppt", "bug58718_349008.ppt", "bug58718_008495.ppt",};
|
||||
for (String f : files) {
|
||||
File sample = HSLFTestDataSamples.getSampleFile(f);
|
||||
try (SlideShowExtractor<?,?> ex = new SlideShowExtractor<>(SlideShowFactory.create(sample))) {
|
||||
assertNotNull(ex.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug58733() throws IOException {
|
||||
File sample = HSLFTestDataSamples.getSampleFile("bug58733_671884.ppt");
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"bug58718_008524.ppt", "bug58718_008558.ppt", "bug58718_349008.ppt", "bug58718_008495.ppt",
|
||||
"bug58733_671884.ppt"
|
||||
})
|
||||
void bug58718(String file) throws IOException {
|
||||
File sample = HSLFTestDataSamples.getSampleFile(file);
|
||||
try (SlideShowExtractor<?,?> ex = new SlideShowExtractor<>(SlideShowFactory.create(sample))) {
|
||||
assertNotNull(ex.getText());
|
||||
}
|
||||
|
@ -832,23 +780,6 @@ public final class TestBugs {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void bug59056() throws IOException {
|
||||
try (HSLFSlideShow ppt = open("54541_cropped_bitmap.ppt")) {
|
||||
for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
|
||||
BufferedImage img = new BufferedImage(500, 300, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D graphics = img.createGraphics();
|
||||
Rectangle2D box = new Rectangle2D.Double(50, 50, 300, 100);
|
||||
graphics.setPaint(Color.red);
|
||||
graphics.fill(box);
|
||||
box = new Rectangle2D.Double(box.getX() + 1, box.getY() + 1, box.getWidth() - 2, box.getHeight() - 2);
|
||||
DrawFactory.getInstance(graphics).drawShape(graphics, shape, box);
|
||||
graphics.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static HSLFSlideShow open(String fileName) throws IOException {
|
||||
File sample = HSLFTestDataSamples.getSampleFile(fileName);
|
||||
// Note: don't change the code here, it is required for Eclipse to compile the code
|
||||
|
|
|
@ -574,12 +574,13 @@ public final class TestTextRun {
|
|||
|
||||
@Test
|
||||
void testAppendEmpty() throws IOException {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow();
|
||||
try (HSLFSlideShow ppt = new HSLFSlideShow()) {
|
||||
HSLFSlide s = ppt.createSlide();
|
||||
HSLFTextBox title = s.addTitle();
|
||||
title.setText("");
|
||||
title.appendText("\n", true);
|
||||
title.appendText("para", true);
|
||||
ppt.close();
|
||||
assertEquals("\npara", title.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,13 @@
|
|||
package org.apache.poi.hsmf;
|
||||
|
||||
import static org.apache.poi.POITestCase.assertContains;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashSet;
|
||||
|
@ -45,6 +44,7 @@ import org.apache.poi.hsmf.dev.HSMFDump;
|
|||
import org.apache.poi.hsmf.extractor.OutlookTextExtractor;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
import org.apache.poi.util.LocaleUtil;
|
||||
import org.apache.poi.util.NullPrintStream;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -168,19 +168,17 @@ public final class TestFixedSizedProperties {
|
|||
*/
|
||||
@Test
|
||||
void testReadMessageDateSucceedsWithHSMFDump() throws IOException {
|
||||
PrintStream stream = new PrintStream(new ByteArrayOutputStream(), true, "ISO-8859-1");
|
||||
HSMFDump dump = new HSMFDump(fsMessageSucceeds);
|
||||
dump.dump(stream);
|
||||
assertDoesNotThrow(() -> dump.dump(new NullPrintStream()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if we can read the Date Chunk with HSMFDump.
|
||||
*/
|
||||
@Test
|
||||
void testReadMessageDateFailsWithHSMFDump() throws Exception {
|
||||
PrintStream stream = new PrintStream(new ByteArrayOutputStream(), true, "ISO-8859-1");
|
||||
void testReadMessageDateFailsWithHSMFDump() {
|
||||
HSMFDump dump = new HSMFDump(fsMessageFails);
|
||||
dump.dump(stream);
|
||||
assertDoesNotThrow(() -> dump.dump(new NullPrintStream()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
|
@ -87,51 +86,6 @@ public class HWPFTestDataSamples {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a remote sample from URL. opening is performd in two phases:
|
||||
* (1) download content into a byte array
|
||||
* (2) construct HWPFDocument
|
||||
*
|
||||
* @param sampleFileUrl the url to open
|
||||
*/
|
||||
public static HWPFDocument openRemoteFile( String sampleFileUrl )
|
||||
{
|
||||
final long start = System.currentTimeMillis();
|
||||
try
|
||||
{
|
||||
logger.log(POILogger.DEBUG, "Downloading ", sampleFileUrl, " ...");
|
||||
|
||||
try (InputStream is = new URL(sampleFileUrl).openStream()) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
IOUtils.copy(is, baos);
|
||||
} finally {
|
||||
baos.close();
|
||||
}
|
||||
|
||||
final long endDownload = System.currentTimeMillis();
|
||||
byte[] byteArray = baos.toByteArray();
|
||||
|
||||
logger.log(POILogger.DEBUG, "Downloaded in ",
|
||||
Long.valueOf(endDownload - start), " ms -- ",
|
||||
Long.valueOf(byteArray.length), " byte(s)");
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(byteArray);
|
||||
HWPFDocument doc = new HWPFDocument(bais);
|
||||
final long endParse = System.currentTimeMillis();
|
||||
|
||||
logger.log(POILogger.DEBUG, "Parsed in ",
|
||||
Long.valueOf(endParse - start), " ms");
|
||||
|
||||
return doc;
|
||||
}
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
|
||||
public static HWPFOldDocument openOldSampleFile(String sampleFileName) {
|
||||
try {
|
||||
InputStream is = POIDataSamples.getDocumentInstance().openResourceAsStream(sampleFileName);
|
||||
|
|
|
@ -32,56 +32,27 @@ import javax.imageio.ImageIO;
|
|||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hwpf.model.PicturesTable;
|
||||
import org.apache.poi.hwpf.usermodel.Picture;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test picture support in HWPF
|
||||
*/
|
||||
public final class TestHWPFPictures {
|
||||
private String docAFile;
|
||||
private String docBFile;
|
||||
private String docCFile;
|
||||
private String docDFile;
|
||||
|
||||
private String imgAFile;
|
||||
private String imgBFile;
|
||||
private String imgCFile;
|
||||
private String imgDFile;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
docAFile = "testPictures.doc";
|
||||
docBFile = "two_images.doc";
|
||||
docCFile = "vector_image.doc";
|
||||
docDFile = "GaiaTest.doc";
|
||||
|
||||
imgAFile = "simple_image.jpg";
|
||||
imgBFile = "simple_image.png";
|
||||
imgCFile = "vector_image.emf";
|
||||
imgDFile = "GaiaTestImg.png";
|
||||
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
// we use ImageIO in one of the tests here so we should ensure that the temporary directory is created correctly
|
||||
File tempDir = new File(System.getProperty("java.io.tmpdir"));
|
||||
assertTrue( tempDir.exists() || tempDir.mkdirs(), "Could not create temporary directory " + tempDir.getAbsolutePath() + ": " + tempDir.exists() + "/" + tempDir.isDirectory() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test just opening the files
|
||||
*/
|
||||
@Test
|
||||
void testOpen() {
|
||||
HWPFTestDataSamples.openSampleFile(docAFile);
|
||||
HWPFTestDataSamples.openSampleFile(docBFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that we have the right numbers of images in each file
|
||||
*/
|
||||
@Test
|
||||
void testImageCount() {
|
||||
HWPFDocument docA = HWPFTestDataSamples.openSampleFile(docAFile);
|
||||
HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
|
||||
HWPFDocument docA = HWPFTestDataSamples.openSampleFile("testPictures.doc");
|
||||
HWPFDocument docB = HWPFTestDataSamples.openSampleFile("two_images.doc");
|
||||
|
||||
assertNotNull(docA.getPicturesTable());
|
||||
assertNotNull(docB.getPicturesTable());
|
||||
|
@ -101,7 +72,7 @@ public final class TestHWPFPictures {
|
|||
*/
|
||||
@Test
|
||||
void testImageData() {
|
||||
HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);
|
||||
HWPFDocument docB = HWPFTestDataSamples.openSampleFile("two_images.doc");
|
||||
PicturesTable picB = docB.getPicturesTable();
|
||||
List<Picture> picturesB = picB.getAllPictures();
|
||||
|
||||
|
@ -114,8 +85,8 @@ public final class TestHWPFPictures {
|
|||
assertNotNull(pic2);
|
||||
|
||||
// Check the same
|
||||
byte[] pic1B = readFile(imgAFile);
|
||||
byte[] pic2B = readFile(imgBFile);
|
||||
byte[] pic1B = readFile("simple_image.jpg");
|
||||
byte[] pic2B = readFile("simple_image.png");
|
||||
|
||||
assertArrayEquals(pic1B, pic1.getContent());
|
||||
assertArrayEquals(pic2B, pic2.getContent());
|
||||
|
@ -126,7 +97,7 @@ public final class TestHWPFPictures {
|
|||
*/
|
||||
@Test
|
||||
void testCompressedImageData() {
|
||||
HWPFDocument docC = HWPFTestDataSamples.openSampleFile(docCFile);
|
||||
HWPFDocument docC = HWPFTestDataSamples.openSampleFile("vector_image.doc");
|
||||
PicturesTable picC = docC.getPicturesTable();
|
||||
List<Picture> picturesC = picC.getAllPictures();
|
||||
|
||||
|
@ -136,7 +107,7 @@ public final class TestHWPFPictures {
|
|||
assertNotNull(pic);
|
||||
|
||||
// Check the same
|
||||
byte[] picBytes = readFile(imgCFile);
|
||||
byte[] picBytes = readFile("vector_image.emf");
|
||||
assertArrayEquals(picBytes, pic.getContent());
|
||||
}
|
||||
|
||||
|
@ -171,14 +142,14 @@ public final class TestHWPFPictures {
|
|||
*/
|
||||
@Test
|
||||
void testEscherDrawing() {
|
||||
HWPFDocument docD = HWPFTestDataSamples.openSampleFile(docDFile);
|
||||
HWPFDocument docD = HWPFTestDataSamples.openSampleFile("GaiaTest.doc");
|
||||
List<Picture> allPictures = docD.getPicturesTable().getAllPictures();
|
||||
|
||||
assertEquals(1, allPictures.size());
|
||||
|
||||
Picture pic = allPictures.get(0);
|
||||
assertNotNull(pic);
|
||||
byte[] picD = readFile(imgDFile);
|
||||
byte[] picD = readFile("GaiaTestImg.png");
|
||||
|
||||
assertEquals(picD.length, pic.getContent().length);
|
||||
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
package org.apache.poi.hwpf.converter;
|
||||
|
||||
import static org.apache.poi.POITestCase.assertContains;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.apache.poi.POITestCase.assertNotContained;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
|
@ -29,28 +30,98 @@ import javax.xml.transform.stream.StreamResult;
|
|||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.hwpf.HWPFDocument;
|
||||
import org.apache.poi.util.XMLHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
/**
|
||||
* Test cases for {@link WordToHtmlConverter}
|
||||
*/
|
||||
public class TestWordToHtmlConverter {
|
||||
private static String getHtmlText(final String sampleFileName) throws Exception {
|
||||
return getHtmlText(sampleFileName, false);
|
||||
private static final POIDataSamples SAMPLES = POIDataSamples.getDocumentInstance();
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"AIOOB-Tap.doc, <table class=\"t1\">",
|
||||
"Bug33519.doc, " +
|
||||
"\u041F\u043B\u0430\u043D\u0438\u043D\u0441\u043A\u0438 \u0442\u0443\u0440\u043E\u0432\u0435|" +
|
||||
"\u042F\u0432\u043E\u0440 \u0410\u0441\u0435\u043D\u043E\u0432",
|
||||
"Bug46610_2.doc, 012345678911234567892123456789312345678941234567890123456789112345678921234567893123456789412345678",
|
||||
"Bug46817.doc, <table class=\"t1\">",
|
||||
"Bug47286.doc, " +
|
||||
"!FORMTEXT|" +
|
||||
"color:#4f6228;|" +
|
||||
"Passport No and the date of expire|" +
|
||||
"mfa.gov.cy",
|
||||
"Bug48075.doc, \u041F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435 \u21162",
|
||||
"innertable.doc, <span>A</span>",
|
||||
"o_kurs.doc, \u0412\u0441\u0435 \u0441\u0442\u0440\u0430\u043D\u0438\u0446\u044B \u043D\u0443\u043C\u0435\u0440\u0443\u044E\u0442\u0441\u044F",
|
||||
"Bug52583.doc, <select><option selected>riri</option><option>fifi</option><option>loulou</option></select>",
|
||||
"Bug53182.doc, !italic",
|
||||
"documentProperties.doc, " +
|
||||
"<title>This is document title</title>|" +
|
||||
"<meta content=\"This is document keywords\" name=\"keywords\">",
|
||||
// email hyperlink
|
||||
"Bug47286.doc, provisastpet@mfa.gov.cy",
|
||||
"endingnote.doc, " +
|
||||
"<a class=\"a1 endnoteanchor\" href=\"#endnote_1\" name=\"endnote_back_1\">1</a>|" +
|
||||
"<a class=\"a1 endnoteindex\" href=\"#endnote_back_1\" name=\"endnote_1\">1</a><span|" +
|
||||
"Ending note text",
|
||||
"equation.doc, <!--Image link to '0.emf' can be here-->",
|
||||
"hyperlink.doc, " +
|
||||
"<span>Before text; </span><a |" +
|
||||
"<a href=\"http://testuri.org/\"><span class=\"s1\">Hyperlink text</span></a>|" +
|
||||
"</a><span>; after text</span>",
|
||||
"lists-margins.doc, " +
|
||||
".s1{display: inline-block; text-indent: 0; min-width: 0.4861111in;}|" +
|
||||
".s2{display: inline-block; text-indent: 0; min-width: 0.23055555in;}|" +
|
||||
".s3{display: inline-block; text-indent: 0; min-width: 0.28541666in;}|" +
|
||||
".s4{display: inline-block; text-indent: 0; min-width: 0.28333333in;}|" +
|
||||
".p4{text-indent:-0.59652776in;margin-left:-0.70069444in;",
|
||||
"pageref.doc, " +
|
||||
"<a href=\"#userref\">|" +
|
||||
"<a name=\"userref\">|" +
|
||||
"1",
|
||||
"table-merges.doc, " +
|
||||
"<td class=\"td1\" colspan=\"3\">|" +
|
||||
"<td class=\"td2\" colspan=\"2\">",
|
||||
"52420.doc, " +
|
||||
"!FORMTEXT|" +
|
||||
"\u0417\u0410\u0414\u0410\u041d\u0418\u0415|" +
|
||||
"\u041f\u0440\u0435\u043f\u043e\u0434\u0430\u0432\u0430\u0442\u0435\u043b\u044c",
|
||||
"picture.doc, " +
|
||||
"src=\"0.emf\"|" +
|
||||
"width:3.1293333in;height:1.7247736in;|" +
|
||||
"left:-0.09433333;top:-0.2573611;|" +
|
||||
"width:3.4125in;height:2.3253334in;",
|
||||
"pictures_escher.doc, " +
|
||||
"<img src=\"s0.PNG\">|" +
|
||||
"<img src=\"s808.PNG\">"
|
||||
|
||||
})
|
||||
void testFile(String file, String contains) throws Exception {
|
||||
boolean emulatePictureStorage = file.contains("picture");
|
||||
|
||||
String result = getHtmlText(file, emulatePictureStorage);
|
||||
assertNotNull(result);
|
||||
// starting with JDK 9 such unimportant whitespaces may be trimmed
|
||||
result = result.replace("</a> <span", "</a><span");
|
||||
|
||||
for (String match : contains.split("\\|")) {
|
||||
if (match.startsWith("!")) {
|
||||
assertNotContained(result, match.substring(1));
|
||||
} else {
|
||||
assertContains(result, match);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getHtmlText(final String sampleFileName,
|
||||
boolean emulatePictureStorage) throws Exception {
|
||||
HWPFDocument hwpfDocument = new HWPFDocument(POIDataSamples
|
||||
.getDocumentInstance().openResourceAsStream(sampleFileName));
|
||||
|
||||
private static String getHtmlText(final String sampleFileName, boolean emulatePictureStorage) throws Exception {
|
||||
Document newDocument = XMLHelper.newDocumentBuilder().newDocument();
|
||||
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(
|
||||
newDocument);
|
||||
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(newDocument);
|
||||
|
||||
if (emulatePictureStorage)
|
||||
{
|
||||
try (HWPFDocument hwpfDocument = new HWPFDocument(SAMPLES.openResourceAsStream(sampleFileName))) {
|
||||
if (emulatePictureStorage) {
|
||||
wordToHtmlConverter.setPicturesManager((content, pictureType, suggestedName, widthInches, heightInches) -> suggestedName);
|
||||
}
|
||||
|
||||
|
@ -66,186 +137,7 @@ public class TestWordToHtmlConverter {
|
|||
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAIOOBTap() throws Exception {
|
||||
String result = getHtmlText("AIOOB-Tap.doc");
|
||||
assertContains(result, "<table class=\"t1\">");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBug33519() throws Exception {
|
||||
String result = getHtmlText("Bug33519.doc");
|
||||
assertContains(
|
||||
result,
|
||||
"\u041F\u043B\u0430\u043D\u0438\u043D\u0441\u043A\u0438 \u0442\u0443\u0440\u043E\u0432\u0435");
|
||||
assertContains(result,
|
||||
"\u042F\u0432\u043E\u0440 \u0410\u0441\u0435\u043D\u043E\u0432");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBug46610_2() throws Exception {
|
||||
String result = getHtmlText("Bug46610_2.doc");
|
||||
assertContains(
|
||||
result,
|
||||
"012345678911234567892123456789312345678941234567890123456789112345678921234567893123456789412345678");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBug46817() throws Exception {
|
||||
String result = getHtmlText("Bug46817.doc");
|
||||
final String substring = "<table class=\"t1\">";
|
||||
assertContains(result, substring);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBug47286() throws Exception {
|
||||
String result = getHtmlText("Bug47286.doc");
|
||||
|
||||
assertFalse(result.contains("FORMTEXT"));
|
||||
|
||||
assertContains(result, "color:#4f6228;");
|
||||
assertContains(result, "Passport No and the date of expire");
|
||||
assertContains(result, "mfa.gov.cy");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBug48075() throws Exception {
|
||||
getHtmlText("Bug48075.doc");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBug52583() throws Exception {
|
||||
String result = getHtmlText("Bug52583.doc");
|
||||
assertContains(
|
||||
result,
|
||||
"<select><option selected>riri</option><option>fifi</option><option>loulou</option></select>");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBug53182() throws Exception {
|
||||
String result = getHtmlText("Bug53182.doc");
|
||||
assertFalse(result.contains("italic"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDocumentProperties() throws Exception {
|
||||
String result = getHtmlText("documentProperties.doc");
|
||||
|
||||
assertContains(result, "<title>This is document title</title>");
|
||||
assertContains(result,
|
||||
"<meta content=\"This is document keywords\" name=\"keywords\">");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmailhyperlink() throws Exception {
|
||||
String result = getHtmlText("Bug47286.doc");
|
||||
final String substring = "provisastpet@mfa.gov.cy";
|
||||
assertContains(result, substring);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEndnote() throws Exception {
|
||||
String result = getHtmlText("endingnote.doc");
|
||||
|
||||
assertContains(
|
||||
result,
|
||||
"<a class=\"a1 endnoteanchor\" href=\"#endnote_1\" name=\"endnote_back_1\">1</a>");
|
||||
assertContains(
|
||||
// starting with JDK 9 such unimportant whitespaces may be trimmed
|
||||
result.replace("</a> <span", "</a><span"),
|
||||
"<a class=\"a1 endnoteindex\" href=\"#endnote_back_1\" name=\"endnote_1\">1</a><span");
|
||||
assertContains(result, "Ending note text");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquation() throws Exception {
|
||||
String result = getHtmlText("equation.doc");
|
||||
|
||||
assertContains(result, "<!--Image link to '0.emf' can be here-->");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHyperlink() throws Exception {
|
||||
String result = getHtmlText("hyperlink.doc");
|
||||
|
||||
assertContains(result, "<span>Before text; </span><a ");
|
||||
assertContains(result,
|
||||
"<a href=\"http://testuri.org/\"><span class=\"s1\">Hyperlink text</span></a>");
|
||||
assertContains(result, "</a><span>; after text</span>");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInnerTable() throws Exception {
|
||||
getHtmlText("innertable.doc");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testListsMargins() throws Exception {
|
||||
String result = getHtmlText("lists-margins.doc");
|
||||
|
||||
assertContains(result,
|
||||
".s1{display: inline-block; text-indent: 0; min-width: 0.4861111in;}");
|
||||
assertContains(result,
|
||||
".s2{display: inline-block; text-indent: 0; min-width: 0.23055555in;}");
|
||||
assertContains(result,
|
||||
".s3{display: inline-block; text-indent: 0; min-width: 0.28541666in;}");
|
||||
assertContains(result,
|
||||
".s4{display: inline-block; text-indent: 0; min-width: 0.28333333in;}");
|
||||
assertContains(result,
|
||||
".p4{text-indent:-0.59652776in;margin-left:-0.70069444in;");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testO_kurs_doc() throws Exception {
|
||||
getHtmlText("o_kurs.doc");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPageref() throws Exception {
|
||||
String result = getHtmlText("pageref.doc");
|
||||
|
||||
assertContains(result, "<a href=\"#userref\">");
|
||||
assertContains(result, "<a name=\"userref\">");
|
||||
assertContains(result, "1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPicture() throws Exception {
|
||||
String result = getHtmlText("picture.doc", true);
|
||||
|
||||
// picture
|
||||
assertContains(result, "src=\"0.emf\"");
|
||||
// visible size
|
||||
assertContains(result, "width:3.1293333in;height:1.7247736in;");
|
||||
// shift due to crop
|
||||
assertContains(result, "left:-0.09433333;top:-0.2573611;");
|
||||
// size without crop
|
||||
assertContains(result, "width:3.4125in;height:2.3253334in;");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPicturesEscher() throws Exception {
|
||||
String result = getHtmlText("pictures_escher.doc", true);
|
||||
assertContains(result, "<img src=\"s0.PNG\">");
|
||||
assertContains(result, "<img src=\"s808.PNG\">");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTableMerges() throws Exception {
|
||||
String result = getHtmlText("table-merges.doc");
|
||||
|
||||
assertContains(result, "<td class=\"td1\" colspan=\"3\">");
|
||||
assertContains(result, "<td class=\"td2\" colspan=\"2\">");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBug52420() throws Exception {
|
||||
String result = getHtmlText("52420.doc");
|
||||
|
||||
assertFalse(result.contains("FORMTEXT"));
|
||||
|
||||
assertContains(result, "\u0417\u0410\u0414\u0410\u041d\u0418\u0415");
|
||||
assertContains(result, "\u041f\u0440\u0435\u043f\u043e\u0434\u0430\u0432\u0430\u0442\u0435\u043b\u044c");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.poi.hwpf.converter;
|
||||
|
||||
import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.apache.poi.hwpf.HWPFDocument;
|
||||
|
@ -56,7 +57,7 @@ public class TestWordToTextConverter {
|
|||
@Test
|
||||
void testBug53380_3() throws Exception {
|
||||
try (HWPFDocument doc = openSampleFile( "Bug53380_3.doc" )) {
|
||||
WordToTextConverter.getText(doc);
|
||||
assertNotNull(WordToTextConverter.getText(doc));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,56 +16,42 @@
|
|||
==================================================================== */
|
||||
package org.apache.poi.hwpf.dev;
|
||||
|
||||
import java.io.File;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.util.NullPrintStream;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
public class TestHWPFLister {
|
||||
private static PrintStream oldStdOut;
|
||||
private static final POIDataSamples SAMPLES = POIDataSamples.getDocumentInstance();
|
||||
private static final String[] CLEAR_PROPS = {
|
||||
"org.apache.poi.hwpf.preserveBinTables",
|
||||
"org.apache.poi.hwpf.preserveTextTable"
|
||||
};
|
||||
|
||||
@BeforeAll
|
||||
public static void muteStdout() {
|
||||
oldStdOut = System.out;
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"",
|
||||
" --dop --textPieces --textPiecesText --chpx --chpxProperties --chpxSprms --papx --papxProperties --papxSprms --paragraphs --paragraphsText --bookmarks --escher --fields --pictures --officeDrawings --styles --writereadback"
|
||||
})
|
||||
void main(String args) throws Exception {
|
||||
String fileArgs = SAMPLES.getFile("SampleDoc.doc").getAbsolutePath() + args;
|
||||
|
||||
PrintStream oldStdOut = System.out;
|
||||
System.setOut(new NullPrintStream());
|
||||
}
|
||||
try {
|
||||
|
||||
@AfterAll
|
||||
public static void restoreStdout() {
|
||||
assertDoesNotThrow(() -> HWPFLister.main(fileArgs.split(" ")));
|
||||
|
||||
} finally {
|
||||
System.setOut(oldStdOut);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
// the main-method sets these properties, we need to revert them here to not affect other tests
|
||||
System.clearProperty("org.apache.poi.hwpf.preserveBinTables");
|
||||
System.clearProperty("org.apache.poi.hwpf.preserveTextTable");
|
||||
Arrays.stream(CLEAR_PROPS).forEach(System::clearProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
void main() throws Exception {
|
||||
File file = POIDataSamples.getDocumentInstance().getFile("SampleDoc.doc");
|
||||
HWPFLister.main(new String[] { file.getAbsolutePath() });
|
||||
}
|
||||
|
||||
@Test
|
||||
void mainAll() throws Exception {
|
||||
File file = POIDataSamples.getDocumentInstance().getFile("SampleDoc.doc");
|
||||
HWPFLister.main(new String[] {
|
||||
file.getAbsolutePath(),
|
||||
"--dop", "--textPieces", "--textPiecesText",
|
||||
"--chpx", "--chpxProperties", "--chpxSprms",
|
||||
"--papx", "--papxProperties", "--papxSprms",
|
||||
"--paragraphs", "--paragraphsText",
|
||||
"--bookmarks", "--escher",
|
||||
"--fields", "--pictures",
|
||||
"--officeDrawings", "--styles",
|
||||
"--writereadback"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ import java.io.InputStream;
|
|||
import org.apache.poi.POIDataSamples;
|
||||
import org.apache.poi.extractor.ExtractorFactory;
|
||||
import org.apache.poi.extractor.POITextExtractor;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
/**
|
||||
* Tests for bugs with the WordExtractor
|
||||
|
@ -34,38 +34,27 @@ import org.junit.jupiter.api.Test;
|
|||
public final class TestWordExtractorBugs {
|
||||
private static final POIDataSamples SAMPLES = POIDataSamples.getDocumentInstance();
|
||||
|
||||
@Test
|
||||
void testProblemMetadata() throws IOException {
|
||||
InputStream is = SAMPLES.openResourceAsStream("ProblemExtracting.doc");
|
||||
WordExtractor extractor = new WordExtractor(is);
|
||||
is.close();
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"ProblemExtracting.doc",
|
||||
// bug 50688
|
||||
"parentinvguid.doc",
|
||||
// Bug60374
|
||||
"cn.orthodox.www_divenbog_APRIL_30-APRIL.DOC"
|
||||
})
|
||||
void testFile(String file) throws IOException {
|
||||
try (InputStream is = SAMPLES.openResourceAsStream(file);
|
||||
POITextExtractor ex = ExtractorFactory.createExtractor(is)) {
|
||||
// Check it gives text without error
|
||||
extractor.getText();
|
||||
extractor.getParagraphText();
|
||||
extractor.getTextFromPieces();
|
||||
extractor.close();
|
||||
assertNotNull(ex.getText());
|
||||
if (ex instanceof WordExtractor) {
|
||||
WordExtractor extractor = (WordExtractor)ex;
|
||||
assertNotNull(extractor.getParagraphText());
|
||||
assertNotNull(extractor.getTextFromPieces());
|
||||
} else {
|
||||
Word6Extractor extractor = (Word6Extractor)ex;
|
||||
assertNotNull(extractor.getParagraphText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBug50688() throws Exception {
|
||||
InputStream is = SAMPLES.openResourceAsStream("parentinvguid.doc");
|
||||
WordExtractor extractor = new WordExtractor(is);
|
||||
is.close();
|
||||
|
||||
// Check it gives text without error
|
||||
extractor.getText();
|
||||
extractor.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBug60374() throws Exception {
|
||||
POIFSFileSystem fs = new POIFSFileSystem(SAMPLES.openResourceAsStream("cn.orthodox.www_divenbog_APRIL_30-APRIL.DOC"));
|
||||
final POITextExtractor extractor = ExtractorFactory.createExtractor(fs);
|
||||
|
||||
// Check it gives text without error
|
||||
assertNotNull(extractor.getText());
|
||||
|
||||
extractor.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,29 +17,33 @@
|
|||
|
||||
package org.apache.poi.hwpf.model;
|
||||
|
||||
import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.hwpf.HWPFDocFixture;
|
||||
import org.apache.poi.hwpf.HWPFTestDataSamples;
|
||||
import org.apache.poi.hwpf.HWPFDocument;
|
||||
import org.apache.poi.hwpf.converter.WordToTextConverter;
|
||||
import org.apache.poi.hwpf.model.io.HWPFFileSystem;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public final class TestPAPBinTable {
|
||||
|
||||
@Test
|
||||
void testObIs() throws IOException {
|
||||
void testObIs() throws Exception {
|
||||
// shall not fail with assertions on
|
||||
HWPFTestDataSamples.openSampleFile( "ob_is.doc" ).close();
|
||||
try (HWPFDocument doc = openSampleFile("ob_is.doc")) {
|
||||
assertNotNull(WordToTextConverter.getText(doc));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReadWrite() throws IOException {
|
||||
/** @todo verify the constructors */
|
||||
// @todo verify the constructors
|
||||
HWPFDocFixture _hWPFDocFixture = new HWPFDocFixture( this, HWPFDocFixture.DEFAULT_TEST_FILE );
|
||||
|
||||
_hWPFDocFixture.setUp();
|
||||
|
|
|
@ -20,6 +20,7 @@ import static org.apache.poi.POIDataSamples.getDocumentInstance;
|
|||
import static org.apache.poi.POITestCase.assertContains;
|
||||
import static org.apache.poi.POITestCase.assertNotContained;
|
||||
import static org.apache.poi.hwpf.HWPFTestDataSamples.openSampleFile;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
@ -402,8 +403,8 @@ class TestBugs {
|
|||
try (InputStream is = getDocumentInstance()
|
||||
.openResourceAsStream("Bug47742-text.txt")) {
|
||||
byte[] expectedBytes = IOUtils.toByteArray(is);
|
||||
String expectedText = new String(expectedBytes, StandardCharsets.UTF_8)
|
||||
.substring(1); // strip-off the unicode marker
|
||||
// strip-off the unicode marker
|
||||
String expectedText = new String(expectedBytes, StandardCharsets.UTF_8).substring(1);
|
||||
|
||||
assertEqualsIgnoreNewline(expectedText, foundText);
|
||||
}
|
||||
|
@ -413,9 +414,10 @@ class TestBugs {
|
|||
* Bug 47958 - Exception during Escher walk of pictures
|
||||
*/
|
||||
@Test
|
||||
void test47958() {
|
||||
HWPFDocument doc = openSampleFile("Bug47958.doc");
|
||||
doc.getPicturesTable().getAllPictures();
|
||||
void test47958() throws IOException {
|
||||
try (HWPFDocument doc = openSampleFile("Bug47958.doc")) {
|
||||
assertDoesNotThrow(doc.getPicturesTable()::getAllPictures);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -555,42 +557,6 @@ class TestBugs {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [RESOLVED FIXED] Bug 51671 - HWPFDocument.write based on POIFSFileSystem
|
||||
* throws a NullPointerException
|
||||
*/
|
||||
@Test
|
||||
void test51671() throws Exception {
|
||||
InputStream is = getDocumentInstance()
|
||||
.openResourceAsStream("empty.doc");
|
||||
try (POIFSFileSystem poifsFileSystem = new POIFSFileSystem(is)) {
|
||||
HWPFDocument hwpfDocument = new HWPFDocument(
|
||||
poifsFileSystem.getRoot());
|
||||
hwpfDocument.write(new ByteArrayOutputStream());
|
||||
hwpfDocument.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 51678 - Extracting text from Bug51524.zip is slow Bug 51524 -
|
||||
* PapBinTable constructor is slow
|
||||
*/
|
||||
@Test
|
||||
void test51678And51524() throws IOException {
|
||||
// YK: the test will run only if the poi.test.remote system property is
|
||||
// set.
|
||||
// TODO: refactor into something nicer!
|
||||
if (System.getProperty("poi.test.remote") != null) {
|
||||
String href = "http://domex.nps.edu/corp/files/govdocs1/007/007488.doc";
|
||||
HWPFDocument hwpfDocument = HWPFTestDataSamples
|
||||
.openRemoteFile(href);
|
||||
|
||||
try (WordExtractor wordExtractor = new WordExtractor(hwpfDocument)) {
|
||||
wordExtractor.getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [FIXED] Bug 51902 - Picture.fillRawImageContent -
|
||||
* ArrayIndexOutOfBoundsException
|
||||
|
@ -648,7 +614,9 @@ class TestBugs {
|
|||
"cap.stanford.edu_profiles_viewbiosketch_facultyid=4009&name=m_maciver.doc, true",
|
||||
"ca.kwsymphony.www_education_School_Concert_Seat_Booking_Form_2011-12.doc, true",
|
||||
// Bug 33519 - HWPF fails to read a file
|
||||
"Bug33519.doc, false"
|
||||
"Bug33519.doc, false",
|
||||
// Bug 51671 - HWPFDocument.write based on POIFSFileSystem throws a NullPointerException
|
||||
"empty.doc, true"
|
||||
})
|
||||
void testBug51834(String file, boolean doReadBack) throws Exception {
|
||||
try (HWPFDocument doc = openSampleFile(file)) {
|
||||
|
@ -786,7 +754,6 @@ class TestBugs {
|
|||
try (HWPFDocument doc = openSampleFile("61490.doc")) {
|
||||
Range range = doc.getRange();
|
||||
|
||||
System.out.println("print table");
|
||||
TableIterator tableIter = new TableIterator(range);
|
||||
assertTrue(tableIter.hasNext());
|
||||
Table table = tableIter.next();
|
||||
|
|
Loading…
Reference in New Issue