Modified: 
poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java?rev=1895248&r1=1895247&r2=1895248&view=diff
==============================================================================
--- 
poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java
 (original)
+++ 
poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/usermodel/TestTextRun.java
 Mon Nov 22 00:01:31 2021
@@ -17,8 +17,10 @@
 
 package org.apache.poi.hslf.usermodel;
 
-import static org.apache.poi.sl.usermodel.BaseTestSlideShow.getColor;
+import static org.apache.poi.hslf.HSLFTestDataSamples.getSlideShow;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
@@ -27,15 +29,22 @@ import static org.junit.jupiter.api.Asse
 
 import java.awt.Color;
 import java.io.IOException;
+import java.time.LocalDateTime;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.apache.poi.hslf.HSLFTestDataSamples;
 import org.apache.poi.hslf.model.textproperties.TextPropCollection;
+import org.apache.poi.hslf.record.DateTimeMCAtom;
 import org.apache.poi.hslf.record.TextBytesAtom;
 import org.apache.poi.hslf.record.TextCharsAtom;
-import org.apache.poi.hslf.record.TextHeaderAtom;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
+import org.apache.poi.sl.usermodel.BaseTestSlideShow;
+import org.apache.poi.sl.usermodel.PlaceholderDetails;
+import org.apache.poi.util.LocaleUtil;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -43,76 +52,62 @@ import org.junit.jupiter.api.Test;
  */
 @SuppressWarnings("UnusedAssignment")
 public final class TestTextRun {
-    // SlideShow primed on the test data
-    private HSLFSlideShow ss;
-    private HSLFSlideShow ssRich;
-
-    @BeforeEach
-    void setUp() throws IOException {
-        // Basic (non rich) test file
-        ss = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
-
-        // Rich test file
-        ssRich = HSLFTestDataSamples.getSlideShow("Single_Coloured_Page.ppt");
-    }
-
-    @AfterEach
-    void tearDown() throws IOException {
-        ssRich.close();
-        ss.close();
-    }
-
     /**
      * Test to ensure that getting the text works correctly
      */
     @Test
-    void testGetText() {
-        HSLFSlide slideOne = ss.getSlides().get(0);
-        List<List<HSLFTextParagraph>> textParas = slideOne.getTextParagraphs();
-
-        assertEquals(2, textParas.size());
-
-        // Get text works with \n
-        assertEquals("This is a test title", 
HSLFTextParagraph.getText(textParas.get(0)));
-        assertEquals("This is a test subtitle\nThis is on page 1", 
HSLFTextParagraph.getText(textParas.get(1)));
-
-        // Raw text has \r instead
-        assertEquals("This is a test title", 
HSLFTextParagraph.getRawText(textParas.get(0)));
-        assertEquals("This is a test subtitle\rThis is on page 1", 
HSLFTextParagraph.getRawText(textParas.get(1)));
-
+    void testGetText() throws IOException {
+        try (HSLFSlideShow ppt = getSlideShow("basic_test_ppt_file.ppt")) {
+            HSLFSlide slideOne = ppt.getSlides().get(0);
+            List<List<HSLFTextParagraph>> textParas = 
slideOne.getTextParagraphs();
+
+            // Get text works with \n
+            String[] exp1 = { "This is a test title", "This is a test 
subtitle\nThis is on page 1" };
+            String[] act1 = 
textParas.stream().map(HSLFTextParagraph::getText).toArray(String[]::new);
+            assertArrayEquals(exp1, act1);
+
+            // Raw text has \r instead
+            String[] exp2 = { "This is a test title", "This is a test 
subtitle\rThis is on page 1" };
+            String[] act2 = 
textParas.stream().map(HSLFTextParagraph::getRawText).toArray(String[]::new);
+            assertArrayEquals(exp2, act2);
+        }
 
         // Now check on a rich text run
-        HSLFSlide slideOneR = ssRich.getSlides().get(0);
-        textParas = slideOneR.getTextParagraphs();
+        try (HSLFSlideShow ppt = getSlideShow("Single_Coloured_Page.ppt")) {
+            List<List<HSLFTextParagraph>> textParas = 
ppt.getSlides().get(0).getTextParagraphs();
 
-        assertEquals(2, textParas.size());
-        assertEquals("This is a title, it\u2019s in black", 
HSLFTextParagraph.getText(textParas.get(0)));
-        assertEquals("This is the subtitle, in bold\nThis bit is blue and 
italic\nThis bit is red (normal)", HSLFTextParagraph.getText(textParas.get(1)));
-        assertEquals("This is a title, it\u2019s in black", 
HSLFTextParagraph.getRawText(textParas.get(0)));
-        assertEquals("This is the subtitle, in bold\rThis bit is blue and 
italic\rThis bit is red (normal)", 
HSLFTextParagraph.getRawText(textParas.get(1)));
+            String[] exp1 = { "This is a title, it\u2019s in black", "This is 
the subtitle, in bold\nThis bit is blue and italic\nThis bit is red (normal)" };
+            String[] act1 = 
textParas.stream().map(HSLFTextParagraph::getText).toArray(String[]::new);
+            assertArrayEquals(exp1, act1);
+
+            String[] exp2 = { "This is a title, it\u2019s in black", "This is 
the subtitle, in bold\rThis bit is blue and italic\rThis bit is red (normal)" };
+            String[] act2 = 
textParas.stream().map(HSLFTextParagraph::getRawText).toArray(String[]::new);
+            assertArrayEquals(exp2, act2);
+        }
     }
 
     /**
      * Test to ensure changing non rich text bytes->bytes works correctly
      */
     @Test
-    void testSetText() {
-        HSLFSlide slideOne = ss.getSlides().get(0);
-        List<List<HSLFTextParagraph>> textRuns = slideOne.getTextParagraphs();
-        HSLFTextParagraph run = textRuns.get(0).get(0);
-        HSLFTextRun tr =  run.getTextRuns().get(0);
-
-        // Check current text
-        assertEquals("This is a test title", tr.getRawText());
-
-        // Change
-        String changeTo = "New test title";
-        tr.setText(changeTo);
-        assertEquals(changeTo, tr.getRawText());
-
-        // Ensure trailing \n's are NOT stripped, it is legal to set a text 
with a trailing '\r'
-        tr.setText(changeTo + "\n");
-        assertEquals(changeTo + "\r", tr.getRawText());
+    void testSetText() throws IOException {
+        try (HSLFSlideShow ppt = getSlideShow("basic_test_ppt_file.ppt")) {
+            List<List<HSLFTextParagraph>> textRuns = 
ppt.getSlides().get(0).getTextParagraphs();
+            HSLFTextParagraph run = textRuns.get(0).get(0);
+            HSLFTextRun tr = run.getTextRuns().get(0);
+
+            // Check current text
+            assertEquals("This is a test title", tr.getRawText());
+
+            // Change
+            String changeTo = "New test title";
+            tr.setText(changeTo);
+            assertEquals(changeTo, tr.getRawText());
+
+            // Ensure trailing \n's are NOT stripped, it is legal to set a 
text with a trailing '\r'
+            tr.setText(changeTo + "\n");
+            assertEquals(changeTo + "\r", tr.getRawText());
+        }
     }
 
     /**
@@ -121,74 +116,53 @@ public final class TestTextRun {
      */
     @SuppressWarnings("unused")
     @Test
-    void testAdvancedSetText() {
-        HSLFSlide slideOne = ss.getSlides().get(0);
-        List<HSLFTextParagraph> paras = slideOne.getTextParagraphs().get(0);
-        HSLFTextParagraph para = paras.get(0);
-
-        TextHeaderAtom tha = null;
-        TextBytesAtom tba = null;
-        TextCharsAtom tca = null;
-        for ( org.apache.poi.hslf.record.Record r : para.getRecords()) {
-            if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r;
-            else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
-            else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
-        }
-
-        // Bytes -> Bytes
-        assertNull(tca);
-        assertNotNull(tba);
-        // assertFalse(run._isUnicode);
-        assertEquals("This is a test title", 
para.getTextRuns().get(0).getRawText());
-
-        String changeBytesOnly = "New Test Title";
-        HSLFTextParagraph.setText(paras, changeBytesOnly);
-        para = paras.get(0);
-        tha = null; tba = null; tca = null;
-        for ( org.apache.poi.hslf.record.Record r : para.getRecords()) {
-            if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r;
-            else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
-            else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
-        }
-
-        assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras));
-        assertNull(tca);
-        assertNotNull(tba);
-
-        // Bytes -> Chars
-        assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras));
-
-        String changeByteChar = "This is a test title with a '\u0121' g with a 
dot";
-        HSLFTextParagraph.setText(paras, changeByteChar);
-        para = paras.get(0);
-        tha = null; tba = null; tca = null;
-        for ( org.apache.poi.hslf.record.Record r : para.getRecords()) {
-            if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r;
-            else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
-            else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
-        }
-
-        assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras));
-        assertNotNull(tca);
-        assertNull(tba);
-
-        // Chars -> Chars
-        assertNotNull(tca);
-        assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras));
-
-        String changeCharChar = "This is a test title with a '\u0147' N with a 
hat";
-        HSLFTextParagraph.setText(paras, changeCharChar);
-        para = paras.get(0);
-        tha = null; tba = null; tca = null;
-        for ( org.apache.poi.hslf.record.Record r : para.getRecords()) {
-            if (r instanceof TextHeaderAtom) tha = (TextHeaderAtom)r;
-            else if (r instanceof TextBytesAtom) tba = (TextBytesAtom)r;
-            else if (r instanceof TextCharsAtom) tca = (TextCharsAtom)r;
-        }
-
-        assertEquals(changeCharChar, HSLFTextParagraph.getRawText(paras));
-        assertNotNull(tca);
-        assertNull(tba);
+    void testAdvancedSetText() throws IOException {
+        try (HSLFSlideShow ppt = getSlideShow("basic_test_ppt_file.ppt")) {
+            List<HSLFTextParagraph> paras = 
ppt.getSlides().get(0).getTextParagraphs().get(0);
+            final HSLFTextParagraph para = paras.get(0);
+
+            final TextBytesAtom[] tba = { null };
+            final TextCharsAtom[] tca = { null };
+            Runnable extract = () -> {
+                tba[0] = null;
+                tca[0] = null;
+                Stream.of(para.getRecords()).forEach(r -> {
+                    if (r instanceof TextBytesAtom) tba[0] = (TextBytesAtom) r;
+                    else if (r instanceof TextCharsAtom) tca[0] = 
(TextCharsAtom) r;
+                });
+            };
+
+            // Bytes -> Bytes
+            extract.run();
+            assertNull(tca[0]);
+            assertNotNull(tba);
+            // assertFalse(run._isUnicode);
+            assertEquals("This is a test title", 
para.getTextRuns().get(0).getRawText());
+
+            String changeBytesOnly = "New Test Title";
+            HSLFTextParagraph.setText(paras, changeBytesOnly);
+            extract.run();
+            assertEquals(changeBytesOnly, HSLFTextParagraph.getRawText(paras));
+            assertNull(tca[0]);
+            assertNotNull(tba);
+
+            // Bytes -> Chars
+            String changeByteChar = "This is a test title with a '\u0121' g 
with a dot";
+            HSLFTextParagraph.setText(paras, changeByteChar);
+            extract.run();
+            assertEquals(changeByteChar, HSLFTextParagraph.getRawText(paras));
+            assertNotNull(tca[0]);
+            assertNull(tba[0]);
+
+            // Chars -> Chars
+            String changeCharChar = "This is a test title with a '\u0147' N 
with a hat";
+            HSLFTextParagraph.setText(paras, changeCharChar);
+            extract.run();
+
+            assertEquals(changeCharChar, HSLFTextParagraph.getRawText(paras));
+            assertNotNull(tca[0]);
+            assertNull(tba[0]);
+        }
     }
 
     /**
@@ -196,61 +170,63 @@ public final class TestTextRun {
      *  set up for it
      */
     @Test
-    void testGetRichTextNonRich() {
-        HSLFSlide slideOne = ss.getSlides().get(0);
-        List<List<HSLFTextParagraph>> textParass = 
slideOne.getTextParagraphs();
+    void testGetRichTextNonRich() throws IOException {
+        try (HSLFSlideShow ppt = getSlideShow("basic_test_ppt_file.ppt")) {
+            List<List<HSLFTextParagraph>> textParass = 
ppt.getSlides().get(0).getTextParagraphs();
 
-        assertEquals(2, textParass.size());
+            assertEquals(2, textParass.size());
 
-        List<HSLFTextParagraph> trA = textParass.get(0);
-        List<HSLFTextParagraph> trB = textParass.get(1);
+            List<HSLFTextParagraph> trA = textParass.get(0);
+            List<HSLFTextParagraph> trB = textParass.get(1);
 
-        assertEquals(1, trA.size());
-        assertEquals(2, trB.size());
+            assertEquals(1, trA.size());
+            assertEquals(2, trB.size());
 
-        HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0);
-        HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+            HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0);
+            HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
 
-        assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText());
-        assertEquals(HSLFTextParagraph.getRawText(trB.subList(0, 1)), 
rtrB.getRawText());
+            assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText());
+            assertEquals(HSLFTextParagraph.getRawText(trB.subList(0, 1)), 
rtrB.getRawText());
+        }
     }
 
     /**
      * Tests to ensure that the rich text runs are built up correctly
      */
     @Test
-    void testGetRichText() {
-        HSLFSlide slideOne = ssRich.getSlides().get(0);
-        List<List<HSLFTextParagraph>> textParass = 
slideOne.getTextParagraphs();
-
-        assertEquals(2, textParass.size());
-
-        List<HSLFTextParagraph> trA = textParass.get(0);
-        List<HSLFTextParagraph> trB = textParass.get(1);
-
-        assertEquals(1, trA.size());
-        assertEquals(3, trB.size());
-
-        HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0);
-        HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
-        HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
-        HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
-
-        assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText());
-
-        String trBstr = HSLFTextParagraph.getRawText(trB);
-        assertEquals(trBstr.substring(0, 30), rtrB.getRawText());
-        assertEquals(trBstr.substring(30,58), rtrC.getRawText());
-        assertEquals(trBstr.substring(58,82), rtrD.getRawText());
-
-        // Same paragraph styles
-        assertEquals(trB.get(0).getParagraphStyle(), 
trB.get(1).getParagraphStyle());
-        assertEquals(trB.get(0).getParagraphStyle(), 
trB.get(2).getParagraphStyle());
-
-        // Different char styles
-        assertNotEquals(rtrB.getCharacterStyle(), rtrC.getCharacterStyle());
-        assertNotEquals(rtrB.getCharacterStyle(), rtrD.getCharacterStyle());
-        assertNotEquals(rtrC.getCharacterStyle(), rtrD.getCharacterStyle());
+    void testGetRichText() throws IOException {
+        try (HSLFSlideShow ppt = getSlideShow("Single_Coloured_Page.ppt")) {
+            List<List<HSLFTextParagraph>> textParass = 
ppt.getSlides().get(0).getTextParagraphs();
+
+            assertEquals(2, textParass.size());
+
+            List<HSLFTextParagraph> trA = textParass.get(0);
+            List<HSLFTextParagraph> trB = textParass.get(1);
+
+            assertEquals(1, trA.size());
+            assertEquals(3, trB.size());
+
+            HSLFTextRun rtrA = trA.get(0).getTextRuns().get(0);
+            HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+            HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
+            HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
+
+            assertEquals(HSLFTextParagraph.getRawText(trA), rtrA.getRawText());
+
+            String trBstr = HSLFTextParagraph.getRawText(trB);
+            assertEquals(trBstr.substring(0, 30), rtrB.getRawText());
+            assertEquals(trBstr.substring(30, 58), rtrC.getRawText());
+            assertEquals(trBstr.substring(58, 82), rtrD.getRawText());
+
+            // Same paragraph styles
+            assertEquals(trB.get(0).getParagraphStyle(), 
trB.get(1).getParagraphStyle());
+            assertEquals(trB.get(0).getParagraphStyle(), 
trB.get(2).getParagraphStyle());
+
+            // Different char styles
+            assertNotEquals(rtrB.getCharacterStyle(), 
rtrC.getCharacterStyle());
+            assertNotEquals(rtrB.getCharacterStyle(), 
rtrD.getCharacterStyle());
+            assertNotEquals(rtrC.getCharacterStyle(), 
rtrD.getCharacterStyle());
+        }
     }
 
     /**
@@ -258,20 +234,20 @@ public final class TestTextRun {
      *  ensuring that everything stays with the same default styling
      */
     @Test
-    void testSetTextWhereNotRich() {
-        HSLFSlide slideOne = ss.getSlides().get(0);
-        List<List<HSLFTextParagraph>> textParass = 
slideOne.getTextParagraphs();
-        List<HSLFTextParagraph> trB = textParass.get(0);
-        assertEquals(1, trB.size());
-
-        HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
-        assertEquals(HSLFTextParagraph.getText(trB), rtrB.getRawText());
-
-        // Change text via normal
-        HSLFTextParagraph.setText(trB, "Test Foo Test");
-        rtrB = trB.get(0).getTextRuns().get(0);
-        assertEquals("Test Foo Test", HSLFTextParagraph.getRawText(trB));
-        assertEquals("Test Foo Test", rtrB.getRawText());
+    void testSetTextWhereNotRich() throws IOException {
+        try (HSLFSlideShow ppt = getSlideShow("basic_test_ppt_file.ppt")) {
+            List<HSLFTextParagraph> trB = 
ppt.getSlides().get(0).getTextParagraphs().get(0);
+            assertEquals(1, trB.size());
+
+            HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+            assertEquals(HSLFTextParagraph.getText(trB), rtrB.getRawText());
+
+            // Change text via normal
+            HSLFTextParagraph.setText(trB, "Test Foo Test");
+            rtrB = trB.get(0).getTextRuns().get(0);
+            assertEquals("Test Foo Test", HSLFTextParagraph.getRawText(trB));
+            assertEquals("Test Foo Test", rtrB.getRawText());
+        }
     }
 
     /**
@@ -279,48 +255,48 @@ public final class TestTextRun {
      *  sets everything to the same styling
      */
     @Test
-    void testSetTextWhereRich() {
-        HSLFSlide slideOne = ssRich.getSlides().get(0);
-        List<List<HSLFTextParagraph>> textParass = 
slideOne.getTextParagraphs();
-        List<HSLFTextParagraph> trB = textParass.get(1);
-        assertEquals(3, trB.size());
-
-        HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
-        HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
-        HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
-        TextPropCollection tpBP = rtrB.getTextParagraph().getParagraphStyle();
-        TextPropCollection tpBC = rtrB.getCharacterStyle();
-        TextPropCollection tpCP = rtrC.getTextParagraph().getParagraphStyle();
-        TextPropCollection tpCC = rtrC.getCharacterStyle();
-        TextPropCollection tpDP = rtrD.getTextParagraph().getParagraphStyle();
-        TextPropCollection tpDC = rtrD.getCharacterStyle();
+    void testSetTextWhereRich() throws IOException {
+        try (HSLFSlideShow ppt = getSlideShow("Single_Coloured_Page.ppt")) {
+            List<HSLFTextParagraph> trB = 
ppt.getSlides().get(0).getTextParagraphs().get(1);
+            assertEquals(3, trB.size());
+
+            HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+            HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
+            HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
+            TextPropCollection tpBP = 
rtrB.getTextParagraph().getParagraphStyle();
+            TextPropCollection tpBC = rtrB.getCharacterStyle();
+            TextPropCollection tpCP = 
rtrC.getTextParagraph().getParagraphStyle();
+            TextPropCollection tpCC = rtrC.getCharacterStyle();
+            TextPropCollection tpDP = 
rtrD.getTextParagraph().getParagraphStyle();
+            TextPropCollection tpDC = rtrD.getCharacterStyle();
 
 //      assertEquals(trB.getRawText().substring(0, 30), rtrB.getRawText());
-        assertNotNull(tpBP);
-        assertNotNull(tpBC);
-        assertNotNull(tpCP);
-        assertNotNull(tpCC);
-        assertNotNull(tpDP);
-        assertNotNull(tpDC);
-        assertEquals(tpBP,tpCP);
-        assertEquals(tpBP,tpDP);
-        assertEquals(tpCP,tpDP);
-        assertNotEquals(tpBC,tpCC);
-        assertNotEquals(tpBC,tpDC);
-        assertNotEquals(tpCC,tpDC);
-
-        // Change text via normal
-        HSLFTextParagraph.setText(trB, "Test Foo Test");
-
-        // Ensure now have first style
-        assertEquals(1, trB.get(0).getTextRuns().size());
-        rtrB = trB.get(0).getTextRuns().get(0);
-        assertEquals("Test Foo Test", HSLFTextParagraph.getRawText(trB));
-        assertEquals("Test Foo Test", rtrB.getRawText());
-        assertNotNull(rtrB.getCharacterStyle());
-        assertNotNull(rtrB.getTextParagraph().getParagraphStyle());
-        assertEquals( tpBP, rtrB.getTextParagraph().getParagraphStyle() );
-        assertEquals( tpBC, rtrB.getCharacterStyle() );
+            assertNotNull(tpBP);
+            assertNotNull(tpBC);
+            assertNotNull(tpCP);
+            assertNotNull(tpCC);
+            assertNotNull(tpDP);
+            assertNotNull(tpDC);
+            assertEquals(tpBP, tpCP);
+            assertEquals(tpBP, tpDP);
+            assertEquals(tpCP, tpDP);
+            assertNotEquals(tpBC, tpCC);
+            assertNotEquals(tpBC, tpDC);
+            assertNotEquals(tpCC, tpDC);
+
+            // Change text via normal
+            HSLFTextParagraph.setText(trB, "Test Foo Test");
+
+            // Ensure now have first style
+            assertEquals(1, trB.get(0).getTextRuns().size());
+            rtrB = trB.get(0).getTextRuns().get(0);
+            assertEquals("Test Foo Test", HSLFTextParagraph.getRawText(trB));
+            assertEquals("Test Foo Test", rtrB.getRawText());
+            assertNotNull(rtrB.getCharacterStyle());
+            assertNotNull(rtrB.getTextParagraph().getParagraphStyle());
+            assertEquals(tpBP, rtrB.getTextParagraph().getParagraphStyle());
+            assertEquals(tpBC, rtrB.getCharacterStyle());
+        }
     }
 
     /**
@@ -328,25 +304,26 @@ public final class TestTextRun {
      *  in a rich text run, that doesn't happen to actually be rich
      */
     @Test
-    void testChangeTextInRichTextRunNonRich() {
-        HSLFSlide slideOne = ss.getSlides().get(0);
-        List<List<HSLFTextParagraph>> textRuns = slideOne.getTextParagraphs();
-        List<HSLFTextParagraph> trB = textRuns.get(1);
-        assertEquals(1, trB.get(0).getTextRuns().size());
-
-        HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
-        assertEquals(HSLFTextParagraph.getRawText(trB.subList(0, 1)), 
rtrB.getRawText());
-        assertNotNull(rtrB.getCharacterStyle());
-        assertNotNull(rtrB.getTextParagraph().getParagraphStyle());
-
-        // Change text via rich
-        rtrB.setText("Test Test Test");
-        assertEquals("Test Test Test", 
HSLFTextParagraph.getRawText(trB.subList(0, 1)));
-        assertEquals("Test Test Test", rtrB.getRawText());
-
-        // Will now have dummy props
-        assertNotNull(rtrB.getCharacterStyle());
-        assertNotNull(rtrB.getTextParagraph().getParagraphStyle());
+    void testChangeTextInRichTextRunNonRich() throws IOException {
+        try (HSLFSlideShow ppt = getSlideShow("basic_test_ppt_file.ppt")) {
+            List<List<HSLFTextParagraph>> textRuns = 
ppt.getSlides().get(0).getTextParagraphs();
+            List<HSLFTextParagraph> trB = textRuns.get(1);
+            assertEquals(1, trB.get(0).getTextRuns().size());
+
+            HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+            assertEquals(HSLFTextParagraph.getRawText(trB.subList(0, 1)), 
rtrB.getRawText());
+            assertNotNull(rtrB.getCharacterStyle());
+            assertNotNull(rtrB.getTextParagraph().getParagraphStyle());
+
+            // Change text via rich
+            rtrB.setText("Test Test Test");
+            assertEquals("Test Test Test", 
HSLFTextParagraph.getRawText(trB.subList(0, 1)));
+            assertEquals("Test Test Test", rtrB.getRawText());
+
+            // Will now have dummy props
+            assertNotNull(rtrB.getCharacterStyle());
+            assertNotNull(rtrB.getTextParagraph().getParagraphStyle());
+        }
     }
 
     /**
@@ -354,76 +331,78 @@ public final class TestTextRun {
      *  correctly
      */
     @Test
-    void testChangeTextInRichTextRun() {
-        HSLFSlide slideOne = ssRich.getSlides().get(0);
-        List<List<HSLFTextParagraph>> textParass = 
slideOne.getTextParagraphs();
-        List<HSLFTextParagraph> trB = textParass.get(1);
-        assertEquals(3, trB.size());
-
-        // We start with 3 text runs, each with their own set of styles,
-        // but all sharing the same paragraph styles
-        HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
-        HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
-        HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
-        TextPropCollection tpBP = rtrB.getTextParagraph().getParagraphStyle();
-        TextPropCollection tpBC = rtrB.getCharacterStyle();
-        TextPropCollection tpCP = rtrC.getTextParagraph().getParagraphStyle();
-        TextPropCollection tpCC = rtrC.getCharacterStyle();
-        TextPropCollection tpDP = rtrD.getTextParagraph().getParagraphStyle();
-        TextPropCollection tpDC = rtrD.getCharacterStyle();
-
-        // Check text and stylings
-        assertEquals(HSLFTextParagraph.getRawText(trB).substring(0, 30), 
rtrB.getRawText());
-        assertNotNull(tpBP);
-        assertNotNull(tpBC);
-        assertNotNull(tpCP);
-        assertNotNull(tpCC);
-        assertNotNull(tpDP);
-        assertNotNull(tpDC);
-        assertEquals(tpBP, tpCP);
-        assertEquals(tpBP, tpDP);
-        assertEquals(tpCP, tpDP);
-        assertNotEquals(tpBC, tpCC);
-        assertNotEquals(tpBC, tpDC);
-        assertNotEquals(tpCC, tpDC);
-
-        // Check text in the rich runs
-        assertEquals("This is the subtitle, in bold\r", rtrB.getRawText());
-        assertEquals("This bit is blue and italic\r", rtrC.getRawText());
-        assertEquals("This bit is red (normal)", rtrD.getRawText());
-
-        String newBText = "New Subtitle, will still be bold\n";
-        String newCText = "New blue and italic text\n";
-        String newDText = "Funky new normal red text";
-        rtrB.setText(newBText);
-        rtrC.setText(newCText);
-        rtrD.setText(newDText);
-        HSLFTextParagraph.storeText(trB);
-
-        assertEquals(newBText.replace('\n','\r'), rtrB.getRawText());
-        assertEquals(newCText.replace('\n','\r'), rtrC.getRawText());
-        assertEquals(newDText.replace('\n','\r'), rtrD.getRawText());
-
-        assertEquals(newBText.replace('\n','\r') + newCText.replace('\n','\r') 
+ newDText.replace('\n','\r'), HSLFTextParagraph.getRawText(trB));
-
-        // The styles should have been updated for the new sizes
-        assertEquals(newBText.length(), tpBC.getCharactersCovered());
-        assertEquals(newCText.length(), tpCC.getCharactersCovered());
-        assertEquals(newDText.length()+1, tpDC.getCharactersCovered()); // 
Last one is always one larger
-
-        // Paragraph style should be sum of text length
-        assertEquals(
-            newBText.length() + newCText.length() + newDText.length() +1,
-            tpBP.getCharactersCovered() + tpCP.getCharactersCovered() + 
tpDP.getCharactersCovered()
-        );
-
-        // Check stylings still as expected
-        TextPropCollection ntpBC = rtrB.getCharacterStyle();
-        TextPropCollection ntpCC = rtrC.getCharacterStyle();
-        TextPropCollection ntpDC = rtrD.getCharacterStyle();
-        assertEquals(tpBC.getTextPropList(), ntpBC.getTextPropList());
-        assertEquals(tpCC.getTextPropList(), ntpCC.getTextPropList());
-        assertEquals(tpDC.getTextPropList(), ntpDC.getTextPropList());
+    void testChangeTextInRichTextRun() throws IOException {
+        try (HSLFSlideShow ppt = getSlideShow("Single_Coloured_Page.ppt")) {
+            HSLFSlide slideOne = ppt.getSlides().get(0);
+            List<List<HSLFTextParagraph>> textParass = 
slideOne.getTextParagraphs();
+            List<HSLFTextParagraph> trB = textParass.get(1);
+            assertEquals(3, trB.size());
+
+            // We start with 3 text runs, each with their own set of styles,
+            // but all sharing the same paragraph styles
+            HSLFTextRun rtrB = trB.get(0).getTextRuns().get(0);
+            HSLFTextRun rtrC = trB.get(1).getTextRuns().get(0);
+            HSLFTextRun rtrD = trB.get(2).getTextRuns().get(0);
+            TextPropCollection tpBP = 
rtrB.getTextParagraph().getParagraphStyle();
+            TextPropCollection tpBC = rtrB.getCharacterStyle();
+            TextPropCollection tpCP = 
rtrC.getTextParagraph().getParagraphStyle();
+            TextPropCollection tpCC = rtrC.getCharacterStyle();
+            TextPropCollection tpDP = 
rtrD.getTextParagraph().getParagraphStyle();
+            TextPropCollection tpDC = rtrD.getCharacterStyle();
+
+            // Check text and stylings
+            assertEquals(HSLFTextParagraph.getRawText(trB).substring(0, 30), 
rtrB.getRawText());
+            assertNotNull(tpBP);
+            assertNotNull(tpBC);
+            assertNotNull(tpCP);
+            assertNotNull(tpCC);
+            assertNotNull(tpDP);
+            assertNotNull(tpDC);
+            assertEquals(tpBP, tpCP);
+            assertEquals(tpBP, tpDP);
+            assertEquals(tpCP, tpDP);
+            assertNotEquals(tpBC, tpCC);
+            assertNotEquals(tpBC, tpDC);
+            assertNotEquals(tpCC, tpDC);
+
+            // Check text in the rich runs
+            assertEquals("This is the subtitle, in bold\r", rtrB.getRawText());
+            assertEquals("This bit is blue and italic\r", rtrC.getRawText());
+            assertEquals("This bit is red (normal)", rtrD.getRawText());
+
+            String newBText = "New Subtitle, will still be bold\n";
+            String newCText = "New blue and italic text\n";
+            String newDText = "Funky new normal red text";
+            rtrB.setText(newBText);
+            rtrC.setText(newCText);
+            rtrD.setText(newDText);
+            HSLFTextParagraph.storeText(trB);
+
+            assertEquals(newBText.replace('\n', '\r'), rtrB.getRawText());
+            assertEquals(newCText.replace('\n', '\r'), rtrC.getRawText());
+            assertEquals(newDText.replace('\n', '\r'), rtrD.getRawText());
+
+            assertEquals(newBText.replace('\n', '\r') + newCText.replace('\n', 
'\r') + newDText.replace('\n', '\r'), HSLFTextParagraph.getRawText(trB));
+
+            // The styles should have been updated for the new sizes
+            assertEquals(newBText.length(), tpBC.getCharactersCovered());
+            assertEquals(newCText.length(), tpCC.getCharactersCovered());
+            assertEquals(newDText.length() + 1, tpDC.getCharactersCovered()); 
// Last one is always one larger
+
+            // Paragraph style should be sum of text length
+            assertEquals(
+                newBText.length() + newCText.length() + newDText.length() + 1,
+                tpBP.getCharactersCovered() + tpCP.getCharactersCovered() + 
tpDP.getCharactersCovered()
+            );
+
+            // Check stylings still as expected
+            TextPropCollection ntpBC = rtrB.getCharacterStyle();
+            TextPropCollection ntpCC = rtrC.getCharacterStyle();
+            TextPropCollection ntpDC = rtrD.getCharacterStyle();
+            assertEquals(tpBC.getTextPropList(), ntpBC.getTextPropList());
+            assertEquals(tpCC.getTextPropList(), ntpCC.getTextPropList());
+            assertEquals(tpDC.getTextPropList(), ntpDC.getTextPropList());
+        }
     }
 
 
@@ -436,29 +415,27 @@ public final class TestTextRun {
      */
     @Test
     void testBug41015() throws IOException {
-        List<HSLFTextRun> rt;
-
-        HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("bug-41015.ppt");
-        HSLFSlide sl = ppt.getSlides().get(0);
-        List<List<HSLFTextParagraph>> textParass = sl.getTextParagraphs();
-        assertEquals(2, textParass.size());
-
-        List<HSLFTextParagraph> textParas = textParass.get(0);
-        rt = textParass.get(0).get(0).getTextRuns();
-        assertEquals(1, rt.size());
-        assertEquals(0, textParass.get(0).get(0).getIndentLevel());
-        assertEquals("sdfsdfsdf", rt.get(0).getRawText());
-
-        textParas = textParass.get(1);
-        String[] texts = {"Sdfsdfsdf\r", "Dfgdfg\r", "Dfgdfgdfg\r", 
"Sdfsdfs\r", "Sdfsdf\r"};
-        int[] indents = {0, 0, 0, 1, 1};
-        int i=0;
-        for (HSLFTextParagraph p : textParas) {
-            assertEquals(texts[i], p.getTextRuns().get(0).getRawText());
-            assertEquals(indents[i], p.getIndentLevel());
-            i++;
+        try (HSLFSlideShow ppt = getSlideShow("bug-41015.ppt")) {
+            HSLFSlide sl = ppt.getSlides().get(0);
+            List<List<HSLFTextParagraph>> textParass = sl.getTextParagraphs();
+            assertEquals(2, textParass.size());
+
+            List<HSLFTextParagraph> textParas = textParass.get(0);
+            List<HSLFTextRun> rt = textParass.get(0).get(0).getTextRuns();
+            assertEquals(1, rt.size());
+            assertEquals(0, textParass.get(0).get(0).getIndentLevel());
+            assertEquals("sdfsdfsdf", rt.get(0).getRawText());
+
+            textParas = textParass.get(1);
+            String[] texts = {"Sdfsdfsdf\r", "Dfgdfg\r", "Dfgdfgdfg\r", 
"Sdfsdfs\r", "Sdfsdf\r"};
+            int[] indents = {0, 0, 0, 1, 1};
+            int i = 0;
+            for (HSLFTextParagraph p : textParas) {
+                assertEquals(texts[i], p.getTextRuns().get(0).getRawText());
+                assertEquals(indents[i], p.getIndentLevel());
+                i++;
+            }
         }
-        ppt.close();
     }
 
     /**
@@ -466,110 +443,106 @@ public final class TestTextRun {
      */
     @Test
     void testAddTextRun() throws IOException {
-        HSLFSlideShow ppt = new HSLFSlideShow();
-        HSLFSlide slide = ppt.createSlide();
+        try (HSLFSlideShow ppt = new HSLFSlideShow()) {
+            HSLFSlide slide = ppt.createSlide();
 
-        assertEquals(0, slide.getTextParagraphs().size());
+            assertEquals(0, slide.getTextParagraphs().size());
 
-        HSLFTextBox shape1 = new HSLFTextBox();
-        List<HSLFTextParagraph> run1 = shape1.getTextParagraphs();
-        shape1.setText("Text 1");
-        slide.addShape(shape1);
-
-        //The array of Slide's text runs must be updated when new text shapes 
are added.
-        List<List<HSLFTextParagraph>> runs = slide.getTextParagraphs();
-        assertNotNull(runs);
-        assertSame(run1, runs.get(0));
-
-        HSLFTextBox shape2 = new HSLFTextBox();
-        List<HSLFTextParagraph> run2 = shape2.getTextParagraphs();
-        shape2.setText("Text 2");
-        slide.addShape(shape2);
-
-        runs = slide.getTextParagraphs();
-        assertEquals(2, runs.size());
-
-        assertSame(run1, runs.get(0));
-        assertSame(run2, runs.get(1));
-
-        // as getShapes()
-        List<HSLFShape> sh = slide.getShapes();
-        assertEquals(2, sh.size());
-        assertTrue(sh.get(0) instanceof HSLFTextBox);
-        HSLFTextBox box1 = (HSLFTextBox)sh.get(0);
-        assertSame(run1, box1.getTextParagraphs());
-        HSLFTextBox box2 = (HSLFTextBox)sh.get(1);
-        assertSame(run2, box2.getTextParagraphs());
-
-        // test Table - a complex group of shapes containing text objects
-        HSLFSlide slide2 = ppt.createSlide();
-        assertTrue(slide2.getTextParagraphs().isEmpty());
-        HSLFTable table = new HSLFTable(2, 2);
-        slide2.addShape(table);
-        runs = slide2.getTextParagraphs();
-        assertNotNull(runs);
-        assertEquals(4, runs.size());
-        ppt.close();
+            HSLFTextBox shape1 = new HSLFTextBox();
+            List<HSLFTextParagraph> run1 = shape1.getTextParagraphs();
+            shape1.setText("Text 1");
+            slide.addShape(shape1);
+
+            //The array of Slide's text runs must be updated when new text 
shapes are added.
+            List<List<HSLFTextParagraph>> runs = slide.getTextParagraphs();
+            assertNotNull(runs);
+            assertSame(run1, runs.get(0));
+
+            HSLFTextBox shape2 = new HSLFTextBox();
+            List<HSLFTextParagraph> run2 = shape2.getTextParagraphs();
+            shape2.setText("Text 2");
+            slide.addShape(shape2);
+
+            runs = slide.getTextParagraphs();
+            assertEquals(2, runs.size());
+
+            assertSame(run1, runs.get(0));
+            assertSame(run2, runs.get(1));
+
+            // as getShapes()
+            List<HSLFShape> sh = slide.getShapes();
+            assertEquals(2, sh.size());
+            assertTrue(sh.get(0) instanceof HSLFTextBox);
+            HSLFTextBox box1 = (HSLFTextBox) sh.get(0);
+            assertSame(run1, box1.getTextParagraphs());
+            HSLFTextBox box2 = (HSLFTextBox) sh.get(1);
+            assertSame(run2, box2.getTextParagraphs());
+
+            // test Table - a complex group of shapes containing text objects
+            HSLFSlide slide2 = ppt.createSlide();
+            assertTrue(slide2.getTextParagraphs().isEmpty());
+            HSLFTable table = new HSLFTable(2, 2);
+            slide2.addShape(table);
+            runs = slide2.getTextParagraphs();
+            assertNotNull(runs);
+            assertEquals(4, runs.size());
+        }
     }
 
     @Test
     void test48916() throws IOException {
-        HSLFSlideShow ppt1 = 
HSLFTestDataSamples.getSlideShow("SampleShow.ppt");
-        List<HSLFSlide> slides = ppt1.getSlides();
-        for(HSLFSlide slide : slides){
-            for(HSLFShape sh : slide.getShapes()){
-                if (!(sh instanceof HSLFTextShape)) continue;
-                HSLFTextShape tx = (HSLFTextShape)sh;
-                List<HSLFTextParagraph> paras = tx.getTextParagraphs();
-                //verify that records cached in  TextRun and 
EscherTextboxWrapper are the same
-                 org.apache.poi.hslf.record.Record[] runChildren = 
paras.get(0).getRecords();
-                 org.apache.poi.hslf.record.Record[] txboxChildren = 
tx.getEscherTextboxWrapper().getChildRecords();
-                assertEquals(runChildren.length, txboxChildren.length);
-                for(int i=0; i < txboxChildren.length; i++){
-                    assertSame(txboxChildren[i], runChildren[i]);
-                }
-                // caused NPE prior to fix of Bugzilla #48916
-                for (HSLFTextParagraph p : paras) {
-                    for (HSLFTextRun rt : p.getTextRuns()) {
-                        rt.setBold(true);
-                        rt.setFontColor(Color.RED);
+        try (HSLFSlideShow ppt1 = getSlideShow("SampleShow.ppt")) {
+            List<HSLFSlide> slides = ppt1.getSlides();
+            for (HSLFSlide slide : slides) {
+                for (HSLFShape sh : slide.getShapes()) {
+                    if (!(sh instanceof HSLFTextShape)) continue;
+                    HSLFTextShape tx = (HSLFTextShape) sh;
+                    List<HSLFTextParagraph> paras = tx.getTextParagraphs();
+                    //verify that records cached in  TextRun and 
EscherTextboxWrapper are the same
+                    org.apache.poi.hslf.record.Record[] runChildren = 
paras.get(0).getRecords();
+                    org.apache.poi.hslf.record.Record[] txboxChildren = 
tx.getEscherTextboxWrapper().getChildRecords();
+                    assertEquals(runChildren.length, txboxChildren.length);
+                    for (int i = 0; i < txboxChildren.length; i++) {
+                        assertSame(txboxChildren[i], runChildren[i]);
+                    }
+                    // caused NPE prior to fix of Bugzilla #48916
+                    for (HSLFTextParagraph p : paras) {
+                        for (HSLFTextRun rt : p.getTextRuns()) {
+                            rt.setBold(true);
+                            rt.setFontColor(Color.RED);
+                        }
                     }
+                    // tx.storeText();
                 }
-                // tx.storeText();
             }
-        }
 
-        HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
-        for(HSLFSlide slide : ppt2.getSlides()){
-            for(HSLFShape sh : slide.getShapes()){
-                if(sh instanceof HSLFTextShape){
-                    HSLFTextShape tx = (HSLFTextShape)sh;
-                    List<HSLFTextParagraph> run = tx.getTextParagraphs();
-                    HSLFTextRun rt = run.get(0).getTextRuns().get(0);
-                    assertTrue(rt.isBold());
-                    assertEquals(Color.RED, getColor(rt.getFontColor()));
-                }
+            try (HSLFSlideShow ppt2 = 
HSLFTestDataSamples.writeOutAndReadBack(ppt1)) {
+                List<HSLFTextRun> runs = ppt2.getSlides().stream()
+                    .flatMap(s -> s.getShapes().stream())
+                    .filter(s -> s instanceof HSLFTextShape)
+                    .map(s -> ((HSLFTextShape) 
s).getTextParagraphs().get(0).getTextRuns().get(0))
+                    .collect(Collectors.toList());
+
+                assertFalse(runs.isEmpty());
+                assertTrue(runs.stream().allMatch(HSLFTextRun::isBold));
+                assertTrue(runs.stream().map(HSLFTextRun::getFontColor)
+                    
.map(BaseTestSlideShow::getColor).allMatch(Color.RED::equals));
             }
         }
-        ppt2.close();
-        ppt1.close();
     }
 
     @Test
     void test52244() throws IOException {
-        HSLFSlideShow ppt = HSLFTestDataSamples.getSlideShow("52244.ppt");
-        HSLFSlide slide = ppt.getSlides().get(0);
+        try (HSLFSlideShow ppt = getSlideShow("52244.ppt")) {
+            HSLFSlide slide = ppt.getSlides().get(0);
 
-        int[] sizes = {36, 24, 12, 32, 12, 12};
+            List<HSLFTextRun> runs = slide.getTextParagraphs().stream().map(tp 
-> tp.get(0).getTextRuns().get(0)).collect(Collectors.toList());
+            
assertTrue(runs.stream().map(HSLFTextRun::getFontFamily).allMatch("Arial"::equals));
 
-        int i=0;
-        for (List<HSLFTextParagraph> textParas : slide.getTextParagraphs()) {
-            HSLFTextRun first = textParas.get(0).getTextRuns().get(0);
-            assertEquals("Arial", first.getFontFamily());
-            assertNotNull(first.getFontSize());
-            assertEquals(sizes[i++], first.getFontSize().intValue());
+            int[] exp = {36, 24, 12, 32, 12, 12};
+            int[] act = 
runs.stream().map(HSLFTextRun::getFontSize).mapToInt(Double::intValue).toArray();
+            assertArrayEquals(exp, act);
         }
-        ppt.close();
     }
 
     @Test
@@ -583,4 +556,66 @@ public final class TestTextRun {
             assertEquals("\npara", title.getText());
         }
     }
+
+    @Test
+    void datetimeFormats() throws IOException {
+        LocalDateTime ldt = LocalDateTime.of(2012, 3, 4, 23, 45, 26);
+        final Map<Locale, String[]> formats = new HashMap<>();
+        formats.put(Locale.GERMANY, new String[]{
+            "04.03.2012",
+            "Sonntag, 4. M\u00e4rz 2012",
+            "04/03/12",
+            "4. M\u00e4rz 2012",
+            "12-03-04",
+            "M\u00e4rz 12",
+            "M\u00e4r-12",
+            "04.03.12  23:45",
+            "04.03.12  23:45:26",
+            "23:45",
+            "23:45:26",
+            "11:45",
+            "11:45:26"
+        });
+        formats.put(Locale.US, new String[]{
+            "03/04/2012",
+            "Sunday, March 4, 2012",
+            "4 March 2012",
+            "March 04, 2012",
+            "4-Mar-12",
+            "March 12",
+            "Mar-12",
+            "3/4/12  11:45 PM",
+            "3/4/12  11:45:26 PM",
+            "23:45",
+            "23:45:26",
+            "11:45 PM",
+            "11:45:26 PM"
+        });
+
+
+        try (HSLFSlideShow ppt = getSlideShow("datetime.ppt")) {
+            List<HSLFTextShape> shapes = ppt.getSlides().get(0).getShapes()
+                
.stream().map(HSLFTextShape.class::cast).collect(Collectors.toList());
+
+            int[] expFormatId = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
+            int[] actFormatId = shapes.stream().flatMap(tp -> 
Stream.of(tp.getTextParagraphs().get(0).getRecords()))
+                .filter(r -> r instanceof DateTimeMCAtom)
+                .mapToInt(r -> ((DateTimeMCAtom)r).getIndex()).toArray();
+            assertArrayEquals(expFormatId, actFormatId);
+
+            List<HSLFShapePlaceholderDetails> phs = 
shapes.stream().map(HSLFSimpleShape::getPlaceholderDetails).collect(Collectors.toList());
+
+            for (Map.Entry<Locale,String[]> me : formats.entrySet()) {
+                LocaleUtil.setUserLocale(me.getKey());
+
+                // refresh internal members
+                phs.forEach(PlaceholderDetails::getPlaceholder);
+
+                String[] actDate = 
phs.stream().map(PlaceholderDetails::getDateFormat).map(ldt::format).toArray(String[]::new);
+                assertArrayEquals(me.getValue(), actDate);
+            }
+        } finally {
+            LocaleUtil.resetUserLocale();
+        }
+    }
 }

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/sl/draw/DrawMasterSheet.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/sl/draw/DrawMasterSheet.java?rev=1895248&r1=1895247&r2=1895248&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/sl/draw/DrawMasterSheet.java 
(original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/sl/draw/DrawMasterSheet.java Mon 
Nov 22 00:01:31 2021
@@ -45,7 +45,7 @@ public class DrawMasterSheet extends Dra
             // in XSLF, slidenumber and date shapes aren't marked as 
placeholders opposed to HSLF
             Placeholder ph = ((SimpleShape<?,?>)shape).getPlaceholder();
             if (ph != null) {
-                return slide.getDisplayPlaceholder(ph);
+                return slide.getDisplayPlaceholder((SimpleShape<?, ?>)shape);
             }
         }
         return slide.getFollowMasterGraphics();

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/sl/draw/DrawTextParagraph.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/sl/draw/DrawTextParagraph.java?rev=1895248&r1=1895247&r2=1895248&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/sl/draw/DrawTextParagraph.java 
(original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/sl/draw/DrawTextParagraph.java 
Mon Nov 22 00:01:31 2021
@@ -17,6 +17,8 @@
 
 package org.apache.poi.sl.draw;
 
+import static org.apache.logging.log4j.util.Unbox.box;
+
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.Graphics2D;
@@ -30,8 +32,10 @@ import java.io.InvalidObjectException;
 import java.text.AttributedCharacterIterator;
 import java.text.AttributedCharacterIterator.Attribute;
 import java.text.AttributedString;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Calendar;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -47,8 +51,8 @@ import org.apache.poi.sl.usermodel.Hyper
 import org.apache.poi.sl.usermodel.Insets2D;
 import org.apache.poi.sl.usermodel.PaintStyle;
 import org.apache.poi.sl.usermodel.PlaceableShape;
-import org.apache.poi.sl.usermodel.ShapeContainer;
-import org.apache.poi.sl.usermodel.Sheet;
+import org.apache.poi.sl.usermodel.PlaceholderDetails;
+import org.apache.poi.sl.usermodel.SimpleShape;
 import org.apache.poi.sl.usermodel.Slide;
 import org.apache.poi.sl.usermodel.TextParagraph;
 import org.apache.poi.sl.usermodel.TextParagraph.BulletStyle;
@@ -61,8 +65,6 @@ import org.apache.poi.util.Internal;
 import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.util.Units;
 
-import static org.apache.logging.log4j.util.Unbox.box;
-
 public class DrawTextParagraph implements Drawable {
     private static final Logger LOG = 
LogManager.getLogger(DrawTextParagraph.class);
 
@@ -397,11 +399,31 @@ public class DrawTextParagraph implement
     }
 
     protected String getRenderableText(Graphics2D graphics, TextRun tr) {
-        if (tr.getFieldType() == FieldType.SLIDE_NUMBER) {
-            Slide<?,?> slide = 
(Slide<?,?>)graphics.getRenderingHint(Drawable.CURRENT_SLIDE);
-            return (slide == null) ? "" : 
Integer.toString(slide.getSlideNumber());
+        FieldType ft = tr.getFieldType();
+        if (ft == null) {
+            return getRenderableText(tr);
+        }
+        if (!tr.getRawText().isEmpty()) {
+            switch (ft) {
+                case SLIDE_NUMBER: {
+                    Slide<?, ?> slide = (Slide<?, ?>) 
graphics.getRenderingHint(Drawable.CURRENT_SLIDE);
+                    return (slide == null) ? "" : 
Integer.toString(slide.getSlideNumber());
+                }
+                case DATE_TIME: {
+                    PlaceholderDetails pd = ((SimpleShape<?, ?>) 
this.getParagraphShape()).getPlaceholderDetails();
+                    // refresh internal members
+                    pd.getPlaceholder();
+                    String uda = pd.getUserDate();
+                    if (uda != null) {
+                        return uda;
+                    }
+                    Calendar cal = LocaleUtil.getLocaleCalendar();
+                    LocalDateTime now = 
LocalDateTime.ofInstant(cal.toInstant(), cal.getTimeZone().toZoneId());
+                    return now.format(pd.getDateFormat());
+                }
+            }
         }
-        return getRenderableText(tr);
+        return "";
     }
 
     @Internal
@@ -550,30 +572,8 @@ public class DrawTextParagraph implement
     /**
      * Helper method for paint style relative to bounds, e.g. gradient paint
      */
-    @SuppressWarnings("rawtypes")
     private PlaceableShape<?,?> getParagraphShape() {
-        return new PlaceableShape(){
-            @Override
-            public ShapeContainer<?,?> getParent() { return null; }
-            @Override
-            public Rectangle2D getAnchor() { return 
paragraph.getParentShape().getAnchor(); }
-            @Override
-            public void setAnchor(Rectangle2D anchor) {}
-            @Override
-            public double getRotation() { return 0; }
-            @Override
-            public void setRotation(double theta) {}
-            @Override
-            public void setFlipHorizontal(boolean flip) {}
-            @Override
-            public void setFlipVertical(boolean flip) {}
-            @Override
-            public boolean getFlipHorizontal() { return false; }
-            @Override
-            public boolean getFlipVertical() { return false; }
-            @Override
-            public Sheet<?,?> getSheet() { return 
paragraph.getParentShape().getSheet(); }
-        };
+        return paragraph.getParentShape();
     }
 
     protected List<AttributedStringData> getAttributedString(Graphics2D 
graphics, StringBuilder text) {
@@ -671,9 +671,11 @@ public class DrawTextParagraph implement
     }
 
     /**
-     * Processing the glyphs is done in two steps.
-     * <li>determine the font group - a text run can have different font 
groups. Depending on the chars,
-     * the correct font group needs to be used
+     * Processing the glyphs is done in two steps:
+     * <ul>
+     * <li>1. determine the font group - a text run can have different font 
groups.
+     * <li>2. Depending on the chars, the correct font group needs to be used
+     * </ul>
      *
      * @see <a 
href="https://blogs.msdn.microsoft.com/officeinteroperability/2013/04/22/office-open-xml-themes-schemes-and-fonts/";>Office
 Open XML Themes, Schemes, and Fonts</a>
      */

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/sl/usermodel/PlaceholderDetails.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/sl/usermodel/PlaceholderDetails.java?rev=1895248&r1=1895247&r2=1895248&view=diff
==============================================================================
--- 
poi/trunk/poi/src/main/java/org/apache/poi/sl/usermodel/PlaceholderDetails.java 
(original)
+++ 
poi/trunk/poi/src/main/java/org/apache/poi/sl/usermodel/PlaceholderDetails.java 
Mon Nov 22 00:01:31 2021
@@ -18,6 +18,8 @@
 package org.apache.poi.sl.usermodel;
 
 
+import java.time.format.DateTimeFormatter;
+
 /**
  * Extended details about placholders
  *
@@ -27,7 +29,7 @@ public interface PlaceholderDetails {
     enum PlaceholderSize {
         quarter, half, full
     }
-    
+
     Placeholder getPlaceholder();
 
     /**
@@ -40,13 +42,13 @@ public interface PlaceholderDetails {
      * @param placeholder The shape to use as placeholder or null if no 
placeholder should be set.
      */
     void setPlaceholder(Placeholder placeholder);
-    
+
     boolean isVisible();
-    
+
     void setVisible(boolean isVisible);
-    
+
     PlaceholderSize getSize();
-    
+
     void setSize(PlaceholderSize size);
 
     /**
@@ -66,4 +68,23 @@ public interface PlaceholderDetails {
      * @since POI 4.0.0
      */
     void setText(String text);
+
+
+    /**
+     * @return the stored / fixed user specified date
+     *
+     * @since POI 5.2.0
+     */
+    default String getUserDate() {
+        return null;
+    }
+
+    /**
+     * @return Get the date format for the datetime placeholder
+     *
+     * @since POI 5.2.0
+     */
+    default DateTimeFormatter getDateFormat() {
+        return DateTimeFormatter.ISO_LOCAL_DATE;
+    }
 }

Modified: poi/trunk/poi/src/main/java/org/apache/poi/sl/usermodel/Slide.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/sl/usermodel/Slide.java?rev=1895248&r1=1895247&r2=1895248&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/sl/usermodel/Slide.java 
(original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/sl/usermodel/Slide.java Mon Nov 
22 00:01:31 2021
@@ -19,6 +19,8 @@ package org.apache.poi.sl.usermodel;
 
 import java.util.List;
 
+import org.apache.poi.util.Removal;
+
 @SuppressWarnings("unused")
 public interface Slide<
     S extends Shape<S,P>,
@@ -54,8 +56,29 @@ public interface Slide<
      * @param placeholder the placeholder type
      * @return {@code true} if the placeholder should be displayed/rendered
      * @since POI 3.16-beta2
+     *
+     * @deprecated in POI 5.2.0 - use {@link 
#getDisplayPlaceholder(SimpleShape)}
+     *
+     */
+    @Deprecated
+    @Removal(version = "6.0.0")
+    default boolean getDisplayPlaceholder(Placeholder placeholder) {
+        return false;
+    }
+
+
+    /**
+     * In XSLF, slidenumber and date shapes aren't marked as placeholders
+     * whereas in HSLF they are activated via a HeadersFooter configuration.
+     * This method is used to generalize that handling.
+     *
+     * @param placeholderRefShape the shape which references to the placeholder
+     * @return {@code true} if the placeholder should be displayed/rendered
+     * @since POI 5.2.0
      */
-    boolean getDisplayPlaceholder(Placeholder placeholder);
+    default boolean getDisplayPlaceholder(SimpleShape<?,?> 
placeholderRefShape) {
+        return false;
+    }
 
     /**
      * Sets the slide visibility

Modified: poi/trunk/poi/src/main/java9/module-info.class
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java9/module-info.class?rev=1895248&r1=1895247&r2=1895248&view=diff
==============================================================================
Binary files - no diff available.

Added: poi/trunk/test-data/slideshow/datetime.ppt
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/datetime.ppt?rev=1895248&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/slideshow/datetime.ppt
------------------------------------------------------------------------------
    svn:executable = *

Propchange: poi/trunk/test-data/slideshow/datetime.ppt
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-powerpoint



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to