[bug-66040] add apparently working test cases

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903437 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2022-08-15 13:08:03 +00:00
parent 7425aa0af3
commit 0f45464494
1 changed files with 96 additions and 0 deletions

View File

@ -158,6 +158,102 @@ class TestXSLFShape {
try (XMLSlideShow ppt2 = new XMLSlideShow(bos.toInputStream())) {
assertEquals(6, ppt2.getSlides().size());
XSLFSlide updatedSlide = ppt2.getSlides().get(0);
for (XSLFShape shape : updatedSlide.getShapes()) {
if (shape instanceof XSLFTextShape) {
XSLFTextShape textShape = (XSLFTextShape) shape;
List<XSLFTextParagraph> textBoxParagraphs = textShape.getTextParagraphs();
List<XSLFTextRun> textBoxParagraphTextRuns = textBoxParagraphs.stream()
.map(XSLFTextParagraph::getTextRuns)
.flatMap(List::stream)
.collect(Collectors.toList());
int pos = 0;
for (XSLFTextRun r : textBoxParagraphTextRuns) {
assertEquals("Replaced" + pos++, r.getRawText());
}
}
}
}
}
}
@Test
void testCloneSlideAndReplaceText() throws IOException {
try (
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
) {
assertEquals(6, ppt.getSlides().size());
XSLFSlide slide0 = ppt.getSlides().get(0);
XSLFSlide newSlide = ppt.createSlide(slide0.getSlideLayout());
newSlide = newSlide.importContent(slide0);
for (XSLFShape shape : newSlide.getShapes()) {
if (shape instanceof XSLFTextShape) {
XSLFTextShape textShape = (XSLFTextShape) shape;
List<XDDFTextParagraph> textBoxParagraphs = textShape.getTextBody().getParagraphs();
List<XDDFTextRun> textBoxParagraphTextRuns = textBoxParagraphs.stream()
.map(XDDFTextParagraph::getTextRuns)
.flatMap(List::stream)
.collect(Collectors.toList());
int pos = 0;
for (XDDFTextRun r : textBoxParagraphTextRuns) {
r.setText("Replaced" + pos++);
}
}
}
ppt.write(bos);
try (XMLSlideShow ppt2 = new XMLSlideShow(bos.toInputStream())) {
assertEquals(7, ppt2.getSlides().size());
XSLFSlide updatedSlide = ppt2.getSlides().get(6);
assertEquals(newSlide.getSlideName(), updatedSlide.getSlideName());
for (XSLFShape shape : updatedSlide.getShapes()) {
if (shape instanceof XSLFTextShape) {
XSLFTextShape textShape = (XSLFTextShape) shape;
List<XSLFTextParagraph> textBoxParagraphs = textShape.getTextParagraphs();
List<XSLFTextRun> textBoxParagraphTextRuns = textBoxParagraphs.stream()
.map(XSLFTextParagraph::getTextRuns)
.flatMap(List::stream)
.collect(Collectors.toList());
int pos = 0;
for (XSLFTextRun r : textBoxParagraphTextRuns) {
assertEquals("Replaced" + pos++, r.getRawText());
}
}
}
}
}
}
@Test
void testCloneSlideAndReplaceTextXDDF() throws IOException {
try (
XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
) {
assertEquals(6, ppt.getSlides().size());
XSLFSlide slide0 = ppt.getSlides().get(0);
XSLFSlide newSlide = ppt.createSlide(slide0.getSlideLayout());
newSlide = newSlide.importContent(slide0);
for (XSLFShape shape : newSlide.getShapes()) {
if (shape instanceof XSLFTextShape) {
XSLFTextShape textShape = (XSLFTextShape) shape;
List<XDDFTextParagraph> textBoxParagraphs = textShape.getTextBody().getParagraphs();
List<XDDFTextRun> textBoxParagraphTextRuns = textBoxParagraphs.stream()
.map(XDDFTextParagraph::getTextRuns)
.flatMap(List::stream)
.collect(Collectors.toList());
int pos = 0;
for (XDDFTextRun r : textBoxParagraphTextRuns) {
r.setText("Replaced" + pos++);
}
}
}
ppt.write(bos);
try (XMLSlideShow ppt2 = new XMLSlideShow(bos.toInputStream())) {
assertEquals(7, ppt2.getSlides().size());
XSLFSlide updatedSlide = ppt2.getSlides().get(6);
assertEquals(newSlide.getSlideName(), updatedSlide.getSlideName());
for (XSLFShape shape : updatedSlide.getShapes()) {
if (shape instanceof XSLFTextShape) {
XSLFTextShape textShape = (XSLFTextShape) shape;