]> source.dussan.org Git - poi.git/commitdiff
#45088 - POI-HSLF changeTextInRichTextRun corrupts presentation
authorAndreas Beeker <kiwiwings@apache.org>
Sun, 1 Nov 2015 19:37:24 +0000 (19:37 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sun, 1 Nov 2015 19:37:24 +0000 (19:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1711845 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
test-data/slideshow/bug45088.ppt [new file with mode: 0644]

index d18e8a26d3b12b2136d7de67f12fac19e6702f54..820f099eefa14a65e6ae940418913ad4676774b0 100644 (file)
@@ -689,4 +689,34 @@ public final class TestBugs {
         
         ppt2.close();
     }
+    
+    @Test
+    public void bug45088() throws IOException {
+        String template = "[SYSDATE]";
+        String textExp = "REPLACED_DATE_WITH_A_LONG_ONE";
+        
+        HSLFSlideShow ppt1 = (HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("bug45088.ppt"));
+        for (HSLFSlide slide : ppt1.getSlides()) {
+            for (List<HSLFTextParagraph> paraList : slide.getTextParagraphs()) {
+                for (HSLFTextParagraph para : paraList) {
+                    for (HSLFTextRun run : para.getTextRuns()) {
+                        String text = run.getRawText();
+                        if (text != null && text.contains(template)) {
+                            String replacedText = text.replace(template, textExp);
+                            run.setText(replacedText);
+                            para.setDirty();
+                        }
+                    }
+                }
+            }
+        }
+
+        HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
+        ppt1.close();
+        
+        HSLFTextBox tb = (HSLFTextBox)ppt2.getSlides().get(0).getShapes().get(1);
+        String textAct = tb.getTextParagraphs().get(0).getTextRuns().get(0).getRawText().trim();
+        assertEquals(textExp, textAct);
+        ppt2.close();
+    }
 }
diff --git a/test-data/slideshow/bug45088.ppt b/test-data/slideshow/bug45088.ppt
new file mode 100644 (file)
index 0000000..e4be0f3
Binary files /dev/null and b/test-data/slideshow/bug45088.ppt differ