You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/05/22 21:37:10 UTC

svn commit: r1890122 [16/16] - in /poi/trunk/poi-scratchpad/src: main/java/org/apache/poi/hdgf/ main/java/org/apache/poi/hdgf/chunks/ main/java/org/apache/poi/hdgf/dev/ main/java/org/apache/poi/hdgf/exceptions/ main/java/org/apache/poi/hdgf/extractor/ ...

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java Sat May 22 21:37:08 2021
@@ -60,54 +60,54 @@ public final class TestWordExtractor {
         assertContains(endnote, needle);
     }
 
-	private final String[] p_text1 = new String[] {
-			"This is a simple word document\r\n",
-			"\r\n",
-			"It has a number of paragraphs in it\r\n",
-			"\r\n",
-			"Some of them even feature bold, italic and underlined text\r\n",
-			"\r\n",
-			"\r\n",
-			"This bit is in a different font and size\r\n",
-			"\r\n",
-			"\r\n",
-			"This bit features some red text.\r\n",
-			"\r\n",
-			"\r\n",
-			"It is otherwise very very boring.\r\n"
-	};
+    private final String[] p_text1 = new String[] {
+            "This is a simple word document\r\n",
+            "\r\n",
+            "It has a number of paragraphs in it\r\n",
+            "\r\n",
+            "Some of them even feature bold, italic and underlined text\r\n",
+            "\r\n",
+            "\r\n",
+            "This bit is in a different font and size\r\n",
+            "\r\n",
+            "\r\n",
+            "This bit features some red text.\r\n",
+            "\r\n",
+            "\r\n",
+            "It is otherwise very very boring.\r\n"
+    };
 
     // Build splat'd out text version
-	private final String p_text1_block = StringUtil.join(p_text1, "");
+    private final String p_text1_block = StringUtil.join(p_text1, "");
 
-	/**
-	 * Test paragraph based extraction
-	 */
-	@Test
-	void testExtractFromParagraphs() throws IOException {
+    /**
+     * Test paragraph based extraction
+     */
+    @Test
+    void testExtractFromParagraphs() throws IOException {
         WordExtractor extractor = openExtractor("test2.doc");
-		String[] text = extractor.getParagraphText();
+        String[] text = extractor.getParagraphText();
 
-		assertEquals(p_text1.length, text.length);
-		for (int i = 0; i < p_text1.length; i++) {
-			assertEquals(p_text1[i], text[i]);
-		}
+        assertEquals(p_text1.length, text.length);
+        for (int i = 0; i < p_text1.length; i++) {
+            assertEquals(p_text1[i], text[i]);
+        }
         extractor.close();
 
-		// Lots of paragraphs with only a few lines in them
+        // Lots of paragraphs with only a few lines in them
         WordExtractor extractor2 = openExtractor("test.doc");
-		assertEquals(24, extractor2.getParagraphText().length);
-		assertEquals("as d\r\n", extractor2.getParagraphText()[16]);
-		assertEquals("as d\r\n", extractor2.getParagraphText()[17]);
-		assertEquals("as d\r\n", extractor2.getParagraphText()[18]);
-		extractor2.close();
-	}
-
-	/**
-	 * Test the paragraph -> flat extraction
-	 */
+        assertEquals(24, extractor2.getParagraphText().length);
+        assertEquals("as d\r\n", extractor2.getParagraphText()[16]);
+        assertEquals("as d\r\n", extractor2.getParagraphText()[17]);
+        assertEquals("as d\r\n", extractor2.getParagraphText()[18]);
+        extractor2.close();
+    }
+
+    /**
+     * Test the paragraph -> flat extraction
+     */
     @Test
-	void testGetText() throws IOException {
+    void testGetText() throws IOException {
         WordExtractor extractor = openExtractor("test2.doc");
         assertEqualsTrim(p_text1_block, extractor.getText());
 
@@ -118,148 +118,148 @@ public final class TestWordExtractor {
         // assertEquals(
         // extractor2.getTextFromPieces().replaceAll("[\\r\\n]", ""),
         // extractor2.getText().replaceAll("[\\r\\n]", ""));
-		extractor.close();
+        extractor.close();
     }
 
-	/**
-	 * Test textPieces based extraction
-	 */
+    /**
+     * Test textPieces based extraction
+     */
     @Test
-	void testExtractFromTextPieces() throws IOException {
+    void testExtractFromTextPieces() throws IOException {
         WordExtractor extractor = openExtractor("test2.doc");
-		String text = extractor.getTextFromPieces();
-		assertEquals(p_text1_block, text);
-		extractor.close();
-	}
-
-
-	/**
-	 * Test that we can get data from two different embedded word documents
-	 */
-    @Test
-	void testExtractFromEmbeded() throws IOException {
-	    InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("excel_with_embeded.xls");
-		POIFSFileSystem fs = new POIFSFileSystem(is);
-		is.close();
+        String text = extractor.getTextFromPieces();
+        assertEquals(p_text1_block, text);
+        extractor.close();
+    }
 
-		DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B7");
-		DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B2");
 
-		// Should have WordDocument and 1Table
-		assertNotNull(dirA.getEntry("1Table"));
-		assertNotNull(dirA.getEntry("WordDocument"));
+    /**
+     * Test that we can get data from two different embedded word documents
+     */
+    @Test
+    void testExtractFromEmbeded() throws IOException {
+        InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("excel_with_embeded.xls");
+        POIFSFileSystem fs = new POIFSFileSystem(is);
+        is.close();
+
+        DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B7");
+        DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B2");
+
+        // Should have WordDocument and 1Table
+        assertNotNull(dirA.getEntry("1Table"));
+        assertNotNull(dirA.getEntry("WordDocument"));
 
-		assertNotNull(dirB.getEntry("1Table"));
-		assertNotNull(dirB.getEntry("WordDocument"));
+        assertNotNull(dirB.getEntry("1Table"));
+        assertNotNull(dirB.getEntry("WordDocument"));
 
-		// Check each in turn
+        // Check each in turn
         HWPFDocument docA = new HWPFDocument(dirA);
-		WordExtractor extractorA = new WordExtractor(docA);
-
-		assertNotNull(extractorA.getText());
-		assertTrue(extractorA.getText().length() > 20);
-		assertEqualsTrim("I am a sample document\r\nNot much on me\r\nI am document 1\r\n", extractorA.getText());
-		assertEquals("Sample Doc 1", extractorA.getSummaryInformation().getTitle());
-		assertEquals("Sample Test", extractorA.getSummaryInformation().getSubject());
-
-		HWPFDocument docB = new HWPFDocument(dirB);
-		WordExtractor extractorB = new WordExtractor(docB);
+        WordExtractor extractorA = new WordExtractor(docA);
 
-		assertNotNull(extractorB.getText());
-		assertTrue(extractorB.getText().length() > 20);
-		assertEqualsTrim("I am another sample document\r\nNot much on me\r\nI am document 2\r\n", extractorB.getText());
-		assertEquals("Sample Doc 2", extractorB.getSummaryInformation().getTitle());
-		assertEquals("Another Sample Test", extractorB.getSummaryInformation().getSubject());
+        assertNotNull(extractorA.getText());
+        assertTrue(extractorA.getText().length() > 20);
+        assertEqualsTrim("I am a sample document\r\nNot much on me\r\nI am document 1\r\n", extractorA.getText());
+        assertEquals("Sample Doc 1", extractorA.getSummaryInformation().getTitle());
+        assertEquals("Sample Test", extractorA.getSummaryInformation().getSubject());
+
+        HWPFDocument docB = new HWPFDocument(dirB);
+        WordExtractor extractorB = new WordExtractor(docB);
+
+        assertNotNull(extractorB.getText());
+        assertTrue(extractorB.getText().length() > 20);
+        assertEqualsTrim("I am another sample document\r\nNot much on me\r\nI am document 2\r\n", extractorB.getText());
+        assertEquals("Sample Doc 2", extractorB.getSummaryInformation().getTitle());
+        assertEquals("Another Sample Test", extractorB.getSummaryInformation().getSubject());
 
-		extractorA.close();
-		docA.close();
+        extractorA.close();
+        docA.close();
 
-		extractorB.close();
-		docB.close();
+        extractorB.close();
+        docB.close();
 
-		fs.close();
-	}
+        fs.close();
+    }
 
     @Test
-	void testWithHeader() throws IOException {
-		// Non-unicode
-		HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
-		WordExtractor extractor1 = new WordExtractor(doc1);
+    void testWithHeader() throws IOException {
+        // Non-unicode
+        HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
+        WordExtractor extractor1 = new WordExtractor(doc1);
 
         //noinspection deprecation
         assertEquals("First header column!\tMid header Right header!\n", extractor1.getHeaderText());
-		assertContains(extractor1.getText(), "First header column!");
-		extractor1.close();
-		doc1.close();
-
-		// Unicode
-		HWPFDocument doc2 = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
-		WordExtractor extractor2 = new WordExtractor(doc2);
+        assertContains(extractor1.getText(), "First header column!");
+        extractor1.close();
+        doc1.close();
+
+        // Unicode
+        HWPFDocument doc2 = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
+        WordExtractor extractor2 = new WordExtractor(doc2);
 
         //noinspection deprecation
         assertEquals("This is a simple header, with a \u20ac euro symbol in it.\n\n", extractor2.getHeaderText());
-		assertContains(extractor2.getText(), "This is a simple header");
-		extractor2.close();
-		doc2.close();
-	}
+        assertContains(extractor2.getText(), "This is a simple header");
+        extractor2.close();
+        doc2.close();
+    }
 
     @Test
-	void testWithFooter() throws IOException {
-		// Non-unicode
-		HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
-		WordExtractor extractor1 = new WordExtractor(doc1);
+    void testWithFooter() throws IOException {
+        // Non-unicode
+        HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
+        WordExtractor extractor1 = new WordExtractor(doc1);
 
         //noinspection deprecation
         assertEquals("Footer Left\tFooter Middle Footer Right\n", extractor1.getFooterText());
-		assertContains(extractor1.getText(), "Footer Left");
+        assertContains(extractor1.getText(), "Footer Left");
         extractor1.close();
         doc1.close();
 
-		// Unicode
-		HWPFDocument doc2 = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
-		WordExtractor extractor2 = new WordExtractor(doc2);
+        // Unicode
+        HWPFDocument doc2 = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
+        WordExtractor extractor2 = new WordExtractor(doc2);
 
         //noinspection deprecation
         assertEquals("The footer, with Moli\u00e8re, has Unicode in it.\n", extractor2.getFooterText());
-		assertContains(extractor2.getText(), "The footer, with");
+        assertContains(extractor2.getText(), "The footer, with");
         extractor2.close();
         doc2.close();
-	}
+    }
 
     @Test
-	void testFootnote() throws IOException {
-		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("footnote.doc");
-		WordExtractor extractor = new WordExtractor(doc);
-
-		assertExtractedContains(extractor.getFootnoteText(), "TestFootnote");
-		assertEquals(0x00, doc.getRange().getSection(0).getFootnoteNumberingFormat()); // msonfcArabic
-		assertEquals(0x00, doc.getRange().getSection(0).getFootnoteRestartQualifier()); // rncCont
-		assertEquals(0, doc.getRange().getSection(0).getFootnoteNumberingOffset());
-		assertEquals(1, doc.getFootnotes().getNotesCount());
-		extractor.close();
-		doc.close();
-	}
-
-    @Test
-	void testEndnote() throws IOException {
-		HWPFDocument doc = HWPFTestDataSamples.openSampleFile("footnote.doc");
-		WordExtractor extractor = new WordExtractor(doc);
-
-		assertExtractedContains(extractor.getEndnoteText(), "TestEndnote");
-		assertEquals(0x02, doc.getRange().getSection(0).getEndnoteNumberingFormat()); // msonfcLCRoman
-		assertEquals(0x00, doc.getRange().getSection(0).getEndnoteRestartQualifier()); // rncCont
-		assertEquals(0, doc.getRange().getSection(0).getEndnoteNumberingOffset());
-		assertEquals(1, doc.getEndnotes().getNotesCount());
-		extractor.close();
-		doc.close();
-	}
-
-    @Test
-	void testComments() throws IOException {
-		WordExtractor extractor = openExtractor("footnote.doc");
-		assertExtractedContains(extractor.getCommentsText(), "TestComment");
-		extractor.close();
-	}
+    void testFootnote() throws IOException {
+        HWPFDocument doc = HWPFTestDataSamples.openSampleFile("footnote.doc");
+        WordExtractor extractor = new WordExtractor(doc);
+
+        assertExtractedContains(extractor.getFootnoteText(), "TestFootnote");
+        assertEquals(0x00, doc.getRange().getSection(0).getFootnoteNumberingFormat()); // msonfcArabic
+        assertEquals(0x00, doc.getRange().getSection(0).getFootnoteRestartQualifier()); // rncCont
+        assertEquals(0, doc.getRange().getSection(0).getFootnoteNumberingOffset());
+        assertEquals(1, doc.getFootnotes().getNotesCount());
+        extractor.close();
+        doc.close();
+    }
+
+    @Test
+    void testEndnote() throws IOException {
+        HWPFDocument doc = HWPFTestDataSamples.openSampleFile("footnote.doc");
+        WordExtractor extractor = new WordExtractor(doc);
+
+        assertExtractedContains(extractor.getEndnoteText(), "TestEndnote");
+        assertEquals(0x02, doc.getRange().getSection(0).getEndnoteNumberingFormat()); // msonfcLCRoman
+        assertEquals(0x00, doc.getRange().getSection(0).getEndnoteRestartQualifier()); // rncCont
+        assertEquals(0, doc.getRange().getSection(0).getEndnoteNumberingOffset());
+        assertEquals(1, doc.getEndnotes().getNotesCount());
+        extractor.close();
+        doc.close();
+    }
+
+    @Test
+    void testComments() throws IOException {
+        WordExtractor extractor = openExtractor("footnote.doc");
+        assertExtractedContains(extractor.getCommentsText(), "TestComment");
+        extractor.close();
+    }
 
     @Test
     void testWord95_WordExtractor() {

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractorBugs.java Sat May 22 21:37:08 2021
@@ -56,5 +56,5 @@ public final class TestWordExtractorBugs
                 assertNotNull(extractor.getParagraphText());
             }
         }
-	}
+    }
 }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestSectionTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestSectionTable.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestSectionTable.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestSectionTable.java Sat May 22 21:37:08 2021
@@ -55,8 +55,8 @@ public final class TestSectionTable {
     byte[] newMainStream = mainOut.toByteArray();
 
     SectionTable newSectionTable = new SectionTable(
-    		newMainStream, newTableStream, 0,
-    		newTableStream.length, 0, tpt, fib.getSubdocumentTextStreamLength( SubdocumentType.MAIN ));
+            newMainStream, newTableStream, 0,
+            newTableStream.length, 0, tpt, fib.getSubdocumentTextStreamLength( SubdocumentType.MAIN ));
 
     List<SEPX> oldSections = sectionTable.getSections();
     List<SEPX> newSections = newSectionTable.getSections();
@@ -79,8 +79,8 @@ public final class TestSectionTable {
     int size = oldSections.size();
     for (int x = 0; x < size; x++)
     {
-	  SEPX oldNode = oldSections.get(x);
-	  SEPX newNode = newSections.get(x);
+      SEPX oldNode = oldSections.get(x);
+      SEPX newNode = newSections.get(x);
       assertEquals(oldNode, newNode);
     }
   }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestBug46610.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestBug46610.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestBug46610.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestBug46610.java Sat May 22 21:37:08 2021
@@ -26,39 +26,39 @@ import org.junit.jupiter.api.Test;
 
 public final class TestBug46610 {
 
-	@Test
-	void testUtf() throws Exception {
-		String text = runExtract("Bug46610_1.doc");
-		assertNotNull(text);
-	}
-
-	@Test
-	void testUtf2() throws Exception {
-		String text = runExtract("Bug46610_2.doc");
-		assertNotNull(text);
-	}
-
-	@Test
-	void testExtraction() throws Exception {
-		String text = runExtract("Bug46610_3.doc");
-		assertContains(text, "\u0421\u0412\u041e\u042e");
-	}
-
-	private static String runExtract(String sampleName) throws Exception {
-		HWPFDocument doc = HWPFTestDataSamples.openSampleFile(sampleName);
-		StringBuilder out = new StringBuilder();
-
-		Range globalRange = doc.getRange();
-		for (int i = 0; i < globalRange.numParagraphs(); i++) {
-			Paragraph p = globalRange.getParagraph(i);
-			out.append(p.text());
-			out.append("\n");
-			for (int j = 0; j < p.numCharacterRuns(); j++) {
-				CharacterRun characterRun = p.getCharacterRun(j);
-				characterRun.text();
-			}
-		doc.close();
-		}
-		return out.toString();
-	}
+    @Test
+    void testUtf() throws Exception {
+        String text = runExtract("Bug46610_1.doc");
+        assertNotNull(text);
+    }
+
+    @Test
+    void testUtf2() throws Exception {
+        String text = runExtract("Bug46610_2.doc");
+        assertNotNull(text);
+    }
+
+    @Test
+    void testExtraction() throws Exception {
+        String text = runExtract("Bug46610_3.doc");
+        assertContains(text, "\u0421\u0412\u041e\u042e");
+    }
+
+    private static String runExtract(String sampleName) throws Exception {
+        HWPFDocument doc = HWPFTestDataSamples.openSampleFile(sampleName);
+        StringBuilder out = new StringBuilder();
+
+        Range globalRange = doc.getRange();
+        for (int i = 0; i < globalRange.numParagraphs(); i++) {
+            Paragraph p = globalRange.getParagraph(i);
+            out.append(p.text());
+            out.append("\n");
+            for (int j = 0; j < p.numCharacterRuns(); j++) {
+                CharacterRun characterRun = p.getCharacterRun(j);
+                characterRun.text();
+            }
+        doc.close();
+        }
+        return out.toString();
+    }
 }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestBug47563.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestBug47563.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestBug47563.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestBug47563.java Sat May 22 21:37:08 2021
@@ -36,62 +36,62 @@ import org.junit.jupiter.params.provider
 public class TestBug47563 {
 
 
-	public static Stream<Arguments> data() {
-		List<Arguments> data = new ArrayList<>();
+    public static Stream<Arguments> data() {
+        List<Arguments> data = new ArrayList<>();
 
-		data.add(Arguments.of( 1, 5 ));
-		data.add(Arguments.of( 1, 6 ));
-		data.add(Arguments.of( 5, 1 ));
-		data.add(Arguments.of( 6, 1 ));
-		data.add(Arguments.of( 2, 2 ));
-		data.add(Arguments.of( 3, 2 ));
-		data.add(Arguments.of( 2, 3 ));
-		data.add(Arguments.of( 3, 3 ));
-
-		return data.stream();
-	}
-
-	@ParameterizedTest
-	@MethodSource("data")
-	void test(int rows, int columns) throws Exception {
-		// POI apparently can't create a document from scratch,
-		// so we need an existing empty dummy document
-		try (HWPFDocument doc = HWPFTestDataSamples.openSampleFile("empty.doc")) {
-			Range range = doc.getRange();
-			range.sanityCheck();
-
-			Table table = range.insertTableBefore((short) columns, rows);
-			table.sanityCheck();
-
-			for (int rowIdx = 0; rowIdx < table.numRows(); rowIdx++) {
-				TableRow row = table.getRow(rowIdx);
-				row.sanityCheck();
-
-				for (int colIdx = 0; colIdx < row.numCells(); colIdx++) {
-					TableCell cell = row.getCell(colIdx);
-					cell.sanityCheck();
-
-					Paragraph par = cell.getParagraph(0);
-					par.sanityCheck();
-
-					par.insertBefore("" + (rowIdx * row.numCells() + colIdx));
-					par.sanityCheck();
-
-					row.sanityCheck();
-					table.sanityCheck();
-					range.sanityCheck();
-				}
-			}
-
-			String text = range.text();
-			String textBytes = HexDump.toHex(text.getBytes(StandardCharsets.UTF_8));
-			int mustBeAfter = 0;
-			for (int i = 0; i < rows * columns; i++) {
-				int next = text.indexOf(Integer.toString(i), mustBeAfter);
-				assertTrue( next != -1, "Test with " + rows + "/" + columns + ": Should find " + i +
-					" but did not find it (" + next + ") with " + mustBeAfter + " in " + textBytes + "\n" + next);
-				mustBeAfter = next;
-			}
-		}
-	}
+        data.add(Arguments.of( 1, 5 ));
+        data.add(Arguments.of( 1, 6 ));
+        data.add(Arguments.of( 5, 1 ));
+        data.add(Arguments.of( 6, 1 ));
+        data.add(Arguments.of( 2, 2 ));
+        data.add(Arguments.of( 3, 2 ));
+        data.add(Arguments.of( 2, 3 ));
+        data.add(Arguments.of( 3, 3 ));
+
+        return data.stream();
+    }
+
+    @ParameterizedTest
+    @MethodSource("data")
+    void test(int rows, int columns) throws Exception {
+        // POI apparently can't create a document from scratch,
+        // so we need an existing empty dummy document
+        try (HWPFDocument doc = HWPFTestDataSamples.openSampleFile("empty.doc")) {
+            Range range = doc.getRange();
+            range.sanityCheck();
+
+            Table table = range.insertTableBefore((short) columns, rows);
+            table.sanityCheck();
+
+            for (int rowIdx = 0; rowIdx < table.numRows(); rowIdx++) {
+                TableRow row = table.getRow(rowIdx);
+                row.sanityCheck();
+
+                for (int colIdx = 0; colIdx < row.numCells(); colIdx++) {
+                    TableCell cell = row.getCell(colIdx);
+                    cell.sanityCheck();
+
+                    Paragraph par = cell.getParagraph(0);
+                    par.sanityCheck();
+
+                    par.insertBefore("" + (rowIdx * row.numCells() + colIdx));
+                    par.sanityCheck();
+
+                    row.sanityCheck();
+                    table.sanityCheck();
+                    range.sanityCheck();
+                }
+            }
+
+            String text = range.text();
+            String textBytes = HexDump.toHex(text.getBytes(StandardCharsets.UTF_8));
+            int mustBeAfter = 0;
+            for (int i = 0; i < rows * columns; i++) {
+                int next = text.indexOf(Integer.toString(i), mustBeAfter);
+                assertTrue( next != -1, "Test with " + rows + "/" + columns + ": Should find " + i +
+                    " but did not find it (" + next + ") with " + mustBeAfter + " in " + textBytes + "\n" + next);
+                mustBeAfter = next;
+            }
+        }
+    }
 }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHeaderStories.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHeaderStories.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHeaderStories.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestHeaderStories.java Sat May 22 21:37:08 2021
@@ -31,173 +31,173 @@ import org.junit.jupiter.api.Test;
  */
 @SuppressWarnings("deprecation")
 public final class TestHeaderStories {
-	private HWPFDocument none;
-	private HWPFDocument header;
-	private HWPFDocument footer;
-	private HWPFDocument headerFooter;
-	private HWPFDocument oddEven;
-	private HWPFDocument diffFirst;
-	private HWPFDocument unicode;
-	private HWPFDocument withFields;
+    private HWPFDocument none;
+    private HWPFDocument header;
+    private HWPFDocument footer;
+    private HWPFDocument headerFooter;
+    private HWPFDocument oddEven;
+    private HWPFDocument diffFirst;
+    private HWPFDocument unicode;
+    private HWPFDocument withFields;
 
-	@BeforeEach
+    @BeforeEach
     void setUp() {
 
-		none = openSampleFile("NoHeadFoot.doc");
-		header = openSampleFile("ThreeColHead.doc");
-		footer = openSampleFile("ThreeColFoot.doc");
-		headerFooter = openSampleFile("SimpleHeadThreeColFoot.doc");
-		oddEven = openSampleFile("PageSpecificHeadFoot.doc");
-		diffFirst = openSampleFile("DiffFirstPageHeadFoot.doc");
-		unicode = openSampleFile("HeaderFooterUnicode.doc");
-		withFields = openSampleFile("HeaderWithMacros.doc");
-	}
-
-	@Test
-	void testNone() {
-		HeaderStories hs = new HeaderStories(none);
-
-		assertNull(hs.getPlcfHdd());
-		assertEquals(0, hs.getRange().text().length());
-	}
-
-	@Test
-	void testHeader() {
-		HeaderStories hs = new HeaderStories(header);
-
-		assertEquals(60, hs.getRange().text().length());
-
-		// Should have the usual 6 separaters
-		// Then all 6 of the different header/footer kinds
-		// Finally a terminater
-		assertEquals(13, hs.getPlcfHdd().length());
-
-		assertEquals(215, hs.getRange().getStartOffset());
-
-		assertEquals(0, hs.getPlcfHdd().getProperty(0).getStart());
-		assertEquals(3, hs.getPlcfHdd().getProperty(1).getStart());
-		assertEquals(6, hs.getPlcfHdd().getProperty(2).getStart());
-		assertEquals(6, hs.getPlcfHdd().getProperty(3).getStart());
-		assertEquals(9, hs.getPlcfHdd().getProperty(4).getStart());
-		assertEquals(12, hs.getPlcfHdd().getProperty(5).getStart());
-
-		assertEquals(12, hs.getPlcfHdd().getProperty(6).getStart());
-		assertEquals(12, hs.getPlcfHdd().getProperty(7).getStart());
-		assertEquals(59, hs.getPlcfHdd().getProperty(8).getStart());
-		assertEquals(59, hs.getPlcfHdd().getProperty(9).getStart());
-		assertEquals(59, hs.getPlcfHdd().getProperty(10).getStart());
-		assertEquals(59, hs.getPlcfHdd().getProperty(11).getStart());
-
-		assertEquals(59, hs.getPlcfHdd().getProperty(12).getStart());
-
-		assertEquals("\u0003\r\r", hs.getFootnoteSeparator());
-		assertEquals("\u0004\r\r", hs.getFootnoteContSeparator());
-		assertEquals("", hs.getFootnoteContNote());
-		assertEquals("\u0003\r\r", hs.getEndnoteSeparator());
-		assertEquals("\u0004\r\r", hs.getEndnoteContSeparator());
-		assertEquals("", hs.getEndnoteContNote());
-
-		assertEquals("", hs.getFirstHeader());
-		assertEquals("", hs.getEvenHeader());
-		assertEquals("First header column!\tMid header Right header!\r\r", hs.getOddHeader());
-
-		assertEquals("", hs.getFirstFooter());
-		assertEquals("", hs.getEvenFooter());
-		assertEquals("", hs.getOddFooter());
-	}
-
-	@Test
-	void testFooter() {
-		HeaderStories hs = new HeaderStories(footer);
-
-		assertEquals("", hs.getFirstHeader());
-		assertEquals("", hs.getEvenHeader());
-		assertEquals("", hs.getOddHeader()); // Was \r\r but gets emptied
-
-		assertEquals("", hs.getFirstFooter());
-		assertEquals("", hs.getEvenFooter());
-		assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
-	}
-
-	@Test
-	void testHeaderFooter() {
-		HeaderStories hs = new HeaderStories(headerFooter);
-
-		assertEquals("", hs.getFirstHeader());
-		assertEquals("", hs.getEvenHeader());
-		assertEquals("I am some simple header text here\r\r\r", hs.getOddHeader());
-
-		assertEquals("", hs.getFirstFooter());
-		assertEquals("", hs.getEvenFooter());
-		assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
-	}
-
-	@Test
-	void testOddEven() {
-		HeaderStories hs = new HeaderStories(oddEven);
-
-		assertEquals("", hs.getFirstHeader());
-		assertEquals("[This is an Even Page, with a Header]\u0007August 20, 2008\u0007\u0007\r\r",
-				hs.getEvenHeader());
-		assertEquals("August 20, 2008\u0007[ODD Page Header text]\u0007\u0007\r\r", hs
-				.getOddHeader());
-
-		assertEquals("", hs.getFirstFooter());
-		assertEquals(
-				"\u0007Page \u0013 PAGE  \\* MERGEFORMAT \u00142\u0015\u0007\u0007\u0007\u0007\u0007\u0007\u0007This is a simple footer on the second page\r\r",
-				hs.getEvenFooter());
-		assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
-
-		assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(1));
-		assertEquals(
-				"\u0007Page \u0013 PAGE  \\* MERGEFORMAT \u00142\u0015\u0007\u0007\u0007\u0007\u0007\u0007\u0007This is a simple footer on the second page\r\r",
-				hs.getFooter(2));
-		assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(3));
-	}
-
-	@Test
-	void testFirst() {
-		HeaderStories hs = new HeaderStories(diffFirst);
-
-		assertEquals("I am the header on the first page, and I\u2019m nice and simple\r\r", hs
-				.getFirstHeader());
-		assertEquals("", hs.getEvenHeader());
-		assertEquals("First header column!\tMid header Right header!\r\r", hs.getOddHeader());
-
-		assertEquals("The footer of the first page\r\r", hs.getFirstFooter());
-		assertEquals("", hs.getEvenFooter());
-		assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
-
-		assertEquals("The footer of the first page\r\r", hs.getFooter(1));
-		assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(2));
-		assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(3));
-	}
-
-	@Test
-	void testUnicode() {
-		HeaderStories hs = new HeaderStories(unicode);
-
-		assertEquals("", hs.getFirstHeader());
-		assertEquals("", hs.getEvenHeader());
-		assertEquals("This is a simple header, with a \u20ac euro symbol in it.\r\r\r", hs
-				.getOddHeader());
-
-		assertEquals("", hs.getFirstFooter());
-		assertEquals("", hs.getEvenFooter());
-		assertEquals("The footer, with Moli\u00e8re, has Unicode in it.\r\r", hs.getOddFooter());
-	}
-
-	@Test
-	void testWithFields() {
-		HeaderStories hs = new HeaderStories(withFields);
-		assertFalse(hs.areFieldsStripped());
-
-		assertEquals(
-				"HEADER GOES HERE. 8/12/2008 \u0013 AUTHOR   \\* MERGEFORMAT \u0014Eric Roch\u0015\r\r\r",
-				hs.getOddHeader());
-
-		// Now turn on stripping
-		hs.setAreFieldsStripped(true);
-		assertEquals("HEADER GOES HERE. 8/12/2008 Eric Roch\r\r\r", hs.getOddHeader());
-	}
+        none = openSampleFile("NoHeadFoot.doc");
+        header = openSampleFile("ThreeColHead.doc");
+        footer = openSampleFile("ThreeColFoot.doc");
+        headerFooter = openSampleFile("SimpleHeadThreeColFoot.doc");
+        oddEven = openSampleFile("PageSpecificHeadFoot.doc");
+        diffFirst = openSampleFile("DiffFirstPageHeadFoot.doc");
+        unicode = openSampleFile("HeaderFooterUnicode.doc");
+        withFields = openSampleFile("HeaderWithMacros.doc");
+    }
+
+    @Test
+    void testNone() {
+        HeaderStories hs = new HeaderStories(none);
+
+        assertNull(hs.getPlcfHdd());
+        assertEquals(0, hs.getRange().text().length());
+    }
+
+    @Test
+    void testHeader() {
+        HeaderStories hs = new HeaderStories(header);
+
+        assertEquals(60, hs.getRange().text().length());
+
+        // Should have the usual 6 separaters
+        // Then all 6 of the different header/footer kinds
+        // Finally a terminater
+        assertEquals(13, hs.getPlcfHdd().length());
+
+        assertEquals(215, hs.getRange().getStartOffset());
+
+        assertEquals(0, hs.getPlcfHdd().getProperty(0).getStart());
+        assertEquals(3, hs.getPlcfHdd().getProperty(1).getStart());
+        assertEquals(6, hs.getPlcfHdd().getProperty(2).getStart());
+        assertEquals(6, hs.getPlcfHdd().getProperty(3).getStart());
+        assertEquals(9, hs.getPlcfHdd().getProperty(4).getStart());
+        assertEquals(12, hs.getPlcfHdd().getProperty(5).getStart());
+
+        assertEquals(12, hs.getPlcfHdd().getProperty(6).getStart());
+        assertEquals(12, hs.getPlcfHdd().getProperty(7).getStart());
+        assertEquals(59, hs.getPlcfHdd().getProperty(8).getStart());
+        assertEquals(59, hs.getPlcfHdd().getProperty(9).getStart());
+        assertEquals(59, hs.getPlcfHdd().getProperty(10).getStart());
+        assertEquals(59, hs.getPlcfHdd().getProperty(11).getStart());
+
+        assertEquals(59, hs.getPlcfHdd().getProperty(12).getStart());
+
+        assertEquals("\u0003\r\r", hs.getFootnoteSeparator());
+        assertEquals("\u0004\r\r", hs.getFootnoteContSeparator());
+        assertEquals("", hs.getFootnoteContNote());
+        assertEquals("\u0003\r\r", hs.getEndnoteSeparator());
+        assertEquals("\u0004\r\r", hs.getEndnoteContSeparator());
+        assertEquals("", hs.getEndnoteContNote());
+
+        assertEquals("", hs.getFirstHeader());
+        assertEquals("", hs.getEvenHeader());
+        assertEquals("First header column!\tMid header Right header!\r\r", hs.getOddHeader());
+
+        assertEquals("", hs.getFirstFooter());
+        assertEquals("", hs.getEvenFooter());
+        assertEquals("", hs.getOddFooter());
+    }
+
+    @Test
+    void testFooter() {
+        HeaderStories hs = new HeaderStories(footer);
+
+        assertEquals("", hs.getFirstHeader());
+        assertEquals("", hs.getEvenHeader());
+        assertEquals("", hs.getOddHeader()); // Was \r\r but gets emptied
+
+        assertEquals("", hs.getFirstFooter());
+        assertEquals("", hs.getEvenFooter());
+        assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
+    }
+
+    @Test
+    void testHeaderFooter() {
+        HeaderStories hs = new HeaderStories(headerFooter);
+
+        assertEquals("", hs.getFirstHeader());
+        assertEquals("", hs.getEvenHeader());
+        assertEquals("I am some simple header text here\r\r\r", hs.getOddHeader());
+
+        assertEquals("", hs.getFirstFooter());
+        assertEquals("", hs.getEvenFooter());
+        assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
+    }
+
+    @Test
+    void testOddEven() {
+        HeaderStories hs = new HeaderStories(oddEven);
+
+        assertEquals("", hs.getFirstHeader());
+        assertEquals("[This is an Even Page, with a Header]\u0007August 20, 2008\u0007\u0007\r\r",
+                hs.getEvenHeader());
+        assertEquals("August 20, 2008\u0007[ODD Page Header text]\u0007\u0007\r\r", hs
+                .getOddHeader());
+
+        assertEquals("", hs.getFirstFooter());
+        assertEquals(
+                "\u0007Page \u0013 PAGE  \\* MERGEFORMAT \u00142\u0015\u0007\u0007\u0007\u0007\u0007\u0007\u0007This is a simple footer on the second page\r\r",
+                hs.getEvenFooter());
+        assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
+
+        assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(1));
+        assertEquals(
+                "\u0007Page \u0013 PAGE  \\* MERGEFORMAT \u00142\u0015\u0007\u0007\u0007\u0007\u0007\u0007\u0007This is a simple footer on the second page\r\r",
+                hs.getFooter(2));
+        assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(3));
+    }
+
+    @Test
+    void testFirst() {
+        HeaderStories hs = new HeaderStories(diffFirst);
+
+        assertEquals("I am the header on the first page, and I\u2019m nice and simple\r\r", hs
+                .getFirstHeader());
+        assertEquals("", hs.getEvenHeader());
+        assertEquals("First header column!\tMid header Right header!\r\r", hs.getOddHeader());
+
+        assertEquals("The footer of the first page\r\r", hs.getFirstFooter());
+        assertEquals("", hs.getEvenFooter());
+        assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getOddFooter());
+
+        assertEquals("The footer of the first page\r\r", hs.getFooter(1));
+        assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(2));
+        assertEquals("Footer Left\tFooter Middle Footer Right\r\r", hs.getFooter(3));
+    }
+
+    @Test
+    void testUnicode() {
+        HeaderStories hs = new HeaderStories(unicode);
+
+        assertEquals("", hs.getFirstHeader());
+        assertEquals("", hs.getEvenHeader());
+        assertEquals("This is a simple header, with a \u20ac euro symbol in it.\r\r\r", hs
+                .getOddHeader());
+
+        assertEquals("", hs.getFirstFooter());
+        assertEquals("", hs.getEvenFooter());
+        assertEquals("The footer, with Moli\u00e8re, has Unicode in it.\r\r", hs.getOddFooter());
+    }
+
+    @Test
+    void testWithFields() {
+        HeaderStories hs = new HeaderStories(withFields);
+        assertFalse(hs.areFieldsStripped());
+
+        assertEquals(
+                "HEADER GOES HERE. 8/12/2008 \u0013 AUTHOR   \\* MERGEFORMAT \u0014Eric Roch\u0015\r\r\r",
+                hs.getOddHeader());
+
+        // Now turn on stripping
+        hs.setAreFieldsStripped(true);
+        assertEquals("HEADER GOES HERE. 8/12/2008 Eric Roch\r\r\r", hs.getOddHeader());
+    }
 }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeDelete.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeDelete.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeDelete.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeDelete.java Sat May 22 21:37:08 2021
@@ -27,217 +27,217 @@ import org.apache.poi.hwpf.model.PAPX;
 import org.junit.jupiter.api.Test;
 
 /**
- *	Test to see if Range.delete() works even if the Range contains a
- *	CharacterRun that uses Unicode characters.
+ *  Test to see if Range.delete() works even if the Range contains a
+ *  CharacterRun that uses Unicode characters.
  */
 public final class TestRangeDelete {
 
-	// u201c and u201d are "smart-quotes"
-	private static final String introText =
-		"Introduction\r";
-	private static final String fillerText =
-		"${delete} This is an MS-Word 97 formatted document created using NeoOffice v. 2.2.4 Patch 0 (OpenOffice.org v. 2.2.1).\r";
-	private static final String originalText =
-		"It is used to confirm that text delete works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.  Everybody should be thankful to the ${organization} ${delete} and all the POI contributors for their assistance in this matter.\r";
-	private static final String lastText =
-		"Thank you, ${organization} ${delete}!\r";
-	private static final String searchText = "${delete}";
-	private static final String expectedText1 = " This is an MS-Word 97 formatted document created using NeoOffice v. 2.2.4 Patch 0 (OpenOffice.org v. 2.2.1).\r";
-	private static final String expectedText2 =
-		"It is used to confirm that text delete works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.  Everybody should be thankful to the ${organization}  and all the POI contributors for their assistance in this matter.\r";
-	private static final String expectedText3 = "Thank you, ${organization} !\r";
-
-	private static final String illustrativeDocFile = "testRangeDelete.doc";
-
-	/**
-	 * Test just opening the files
-	 */
-	@Test
-	void testOpen() throws IOException {
-		try (HWPFDocument doc = openSampleFile(illustrativeDocFile)) {
-			assertEquals(5, doc.getParagraphTable().getParagraphs().size());
-		}
-	}
-
-	/**
-	 * Test (more "confirm" than test) that we have the general structure that we expect to have.
-	 */
-	@Test
-	void testDocStructure() throws IOException {
-
-		try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
-			Range range;
-			Section section;
-			Paragraph para;
-			PAPX paraDef;
-
-			// First, check overall
-			range = daDoc.getOverallRange();
-			assertEquals(1, range.numSections());
-			assertEquals(5, range.numParagraphs());
-
-
-			// Now, onto just the doc bit
-			range = daDoc.getRange();
-
-			assertEquals(1, range.numSections());
-			assertEquals(1, daDoc.getSectionTable().getSections().size());
-			section = range.getSection(0);
-
-			assertEquals(5, section.numParagraphs());
-
-			para = section.getParagraph(0);
-			assertEquals(1, para.numCharacterRuns());
-			assertEquals(introText, para.text());
-
-			para = section.getParagraph(1);
-			assertEquals(5, para.numCharacterRuns());
-			assertEquals(fillerText, para.text());
-
-
-			paraDef = daDoc.getParagraphTable().getParagraphs().get(2);
-			assertEquals(132, paraDef.getStart());
-			assertEquals(400, paraDef.getEnd());
-
-			para = section.getParagraph(2);
-			assertEquals(5, para.numCharacterRuns());
-			assertEquals(originalText, para.text());
-
-
-			paraDef = daDoc.getParagraphTable().getParagraphs().get(3);
-			assertEquals(400, paraDef.getStart());
-			assertEquals(438, paraDef.getEnd());
-
-			para = section.getParagraph(3);
-			assertEquals(1, para.numCharacterRuns());
-			assertEquals(lastText, para.text());
-
-
-			// Check things match on text length
-			assertEquals(439, range.text().length());
-			assertEquals(439, section.text().length());
-			assertEquals(439,
-						 section.getParagraph(0).text().length() +
-								 section.getParagraph(1).text().length() +
-								 section.getParagraph(2).text().length() +
-								 section.getParagraph(3).text().length() +
-								 section.getParagraph(4).text().length()
-			);
-		}
-	}
-
-	/**
-	 * Test that we can delete text (one instance) from our Range with Unicode text.
-	 */
-	@Test
-	void testRangeDeleteOne() throws IOException {
-		try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
-
-			Range range = daDoc.getOverallRange();
-			assertEquals(1, range.numSections());
-
-			Section section = range.getSection(0);
-			assertEquals(5, section.numParagraphs());
-
-			Paragraph para = section.getParagraph(2);
-
-			String text = para.text();
-			assertEquals(originalText, text);
-
-			int offset = text.indexOf(searchText);
-			assertEquals(192, offset);
-
-			int absOffset = para.getStartOffset() + offset;
-			Range subRange = new Range(absOffset, (absOffset + searchText.length()), para.getDocument());
-
-			assertEquals(searchText, subRange.text());
-
-			subRange.delete();
-			daDoc.getOverallRange().sanityCheck();
-			daDoc.getRange().sanityCheck();
-
-			// we need to let the model re-calculate the Range before we evaluate it
-			range = daDoc.getRange();
-
-			assertEquals(1, range.numSections());
-			section = range.getSection(0);
-
-			assertEquals(5, section.numParagraphs());
-			para = section.getParagraph(2);
-
-			text = para.text();
-			assertEquals(expectedText2, text);
-
-			// this can lead to a StringBufferOutOfBoundsException, so we will add it
-			// even though we don't have an assertion for it
-			Range daRange = daDoc.getRange();
-			daRange.sanityCheck();
-			daRange.text();
-		}
-	}
-
-	/**
-	 * Test that we can delete text (all instances of) from our Range with Unicode text.
-	 */
-	@Test
-	void testRangeDeleteAll() throws IOException {
-		try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
-
-			Range range = daDoc.getRange();
-			assertEquals(1, range.numSections());
-
-			Section section = range.getSection(0);
-			assertEquals(5, section.numParagraphs());
-
-			Paragraph para = section.getParagraph(2);
-
-			String text = para.text();
-			assertEquals(originalText, text);
-
-			boolean keepLooking = true;
-			while (keepLooking) {
-				// Reload the range every time
-				range = daDoc.getRange();
-				int offset = range.text().indexOf(searchText);
-				if (offset >= 0) {
-
-					int absOffset = range.getStartOffset() + offset;
-
-					Range subRange = new Range(
-							absOffset, (absOffset + searchText.length()), range.getDocument());
-
-					assertEquals(searchText, subRange.text());
-
-					subRange.delete();
-
-				} else {
-					keepLooking = false;
-				}
-			}
-
-			// we need to let the model re-calculate the Range before we use it
-			range = daDoc.getRange();
-
-			assertEquals(1, range.numSections());
-			section = range.getSection(0);
-
-			assertEquals(5, section.numParagraphs());
-
-			para = section.getParagraph(0);
-			text = para.text();
-			assertEquals(introText, text);
-
-			para = section.getParagraph(1);
-			text = para.text();
-			assertEquals(expectedText1, text);
-
-			para = section.getParagraph(2);
-			text = para.text();
-			assertEquals(expectedText2, text);
-
-			para = section.getParagraph(3);
-			text = para.text();
-			assertEquals(expectedText3, text);
-		}
-	}
+    // u201c and u201d are "smart-quotes"
+    private static final String introText =
+        "Introduction\r";
+    private static final String fillerText =
+        "${delete} This is an MS-Word 97 formatted document created using NeoOffice v. 2.2.4 Patch 0 (OpenOffice.org v. 2.2.1).\r";
+    private static final String originalText =
+        "It is used to confirm that text delete works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.  Everybody should be thankful to the ${organization} ${delete} and all the POI contributors for their assistance in this matter.\r";
+    private static final String lastText =
+        "Thank you, ${organization} ${delete}!\r";
+    private static final String searchText = "${delete}";
+    private static final String expectedText1 = " This is an MS-Word 97 formatted document created using NeoOffice v. 2.2.4 Patch 0 (OpenOffice.org v. 2.2.1).\r";
+    private static final String expectedText2 =
+        "It is used to confirm that text delete works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.  Everybody should be thankful to the ${organization}  and all the POI contributors for their assistance in this matter.\r";
+    private static final String expectedText3 = "Thank you, ${organization} !\r";
+
+    private static final String illustrativeDocFile = "testRangeDelete.doc";
+
+    /**
+     * Test just opening the files
+     */
+    @Test
+    void testOpen() throws IOException {
+        try (HWPFDocument doc = openSampleFile(illustrativeDocFile)) {
+            assertEquals(5, doc.getParagraphTable().getParagraphs().size());
+        }
+    }
+
+    /**
+     * Test (more "confirm" than test) that we have the general structure that we expect to have.
+     */
+    @Test
+    void testDocStructure() throws IOException {
+
+        try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
+            Range range;
+            Section section;
+            Paragraph para;
+            PAPX paraDef;
+
+            // First, check overall
+            range = daDoc.getOverallRange();
+            assertEquals(1, range.numSections());
+            assertEquals(5, range.numParagraphs());
+
+
+            // Now, onto just the doc bit
+            range = daDoc.getRange();
+
+            assertEquals(1, range.numSections());
+            assertEquals(1, daDoc.getSectionTable().getSections().size());
+            section = range.getSection(0);
+
+            assertEquals(5, section.numParagraphs());
+
+            para = section.getParagraph(0);
+            assertEquals(1, para.numCharacterRuns());
+            assertEquals(introText, para.text());
+
+            para = section.getParagraph(1);
+            assertEquals(5, para.numCharacterRuns());
+            assertEquals(fillerText, para.text());
+
+
+            paraDef = daDoc.getParagraphTable().getParagraphs().get(2);
+            assertEquals(132, paraDef.getStart());
+            assertEquals(400, paraDef.getEnd());
+
+            para = section.getParagraph(2);
+            assertEquals(5, para.numCharacterRuns());
+            assertEquals(originalText, para.text());
+
+
+            paraDef = daDoc.getParagraphTable().getParagraphs().get(3);
+            assertEquals(400, paraDef.getStart());
+            assertEquals(438, paraDef.getEnd());
+
+            para = section.getParagraph(3);
+            assertEquals(1, para.numCharacterRuns());
+            assertEquals(lastText, para.text());
+
+
+            // Check things match on text length
+            assertEquals(439, range.text().length());
+            assertEquals(439, section.text().length());
+            assertEquals(439,
+                         section.getParagraph(0).text().length() +
+                                 section.getParagraph(1).text().length() +
+                                 section.getParagraph(2).text().length() +
+                                 section.getParagraph(3).text().length() +
+                                 section.getParagraph(4).text().length()
+            );
+        }
+    }
+
+    /**
+     * Test that we can delete text (one instance) from our Range with Unicode text.
+     */
+    @Test
+    void testRangeDeleteOne() throws IOException {
+        try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
+
+            Range range = daDoc.getOverallRange();
+            assertEquals(1, range.numSections());
+
+            Section section = range.getSection(0);
+            assertEquals(5, section.numParagraphs());
+
+            Paragraph para = section.getParagraph(2);
+
+            String text = para.text();
+            assertEquals(originalText, text);
+
+            int offset = text.indexOf(searchText);
+            assertEquals(192, offset);
+
+            int absOffset = para.getStartOffset() + offset;
+            Range subRange = new Range(absOffset, (absOffset + searchText.length()), para.getDocument());
+
+            assertEquals(searchText, subRange.text());
+
+            subRange.delete();
+            daDoc.getOverallRange().sanityCheck();
+            daDoc.getRange().sanityCheck();
+
+            // we need to let the model re-calculate the Range before we evaluate it
+            range = daDoc.getRange();
+
+            assertEquals(1, range.numSections());
+            section = range.getSection(0);
+
+            assertEquals(5, section.numParagraphs());
+            para = section.getParagraph(2);
+
+            text = para.text();
+            assertEquals(expectedText2, text);
+
+            // this can lead to a StringBufferOutOfBoundsException, so we will add it
+            // even though we don't have an assertion for it
+            Range daRange = daDoc.getRange();
+            daRange.sanityCheck();
+            daRange.text();
+        }
+    }
+
+    /**
+     * Test that we can delete text (all instances of) from our Range with Unicode text.
+     */
+    @Test
+    void testRangeDeleteAll() throws IOException {
+        try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
+
+            Range range = daDoc.getRange();
+            assertEquals(1, range.numSections());
+
+            Section section = range.getSection(0);
+            assertEquals(5, section.numParagraphs());
+
+            Paragraph para = section.getParagraph(2);
+
+            String text = para.text();
+            assertEquals(originalText, text);
+
+            boolean keepLooking = true;
+            while (keepLooking) {
+                // Reload the range every time
+                range = daDoc.getRange();
+                int offset = range.text().indexOf(searchText);
+                if (offset >= 0) {
+
+                    int absOffset = range.getStartOffset() + offset;
+
+                    Range subRange = new Range(
+                            absOffset, (absOffset + searchText.length()), range.getDocument());
+
+                    assertEquals(searchText, subRange.text());
+
+                    subRange.delete();
+
+                } else {
+                    keepLooking = false;
+                }
+            }
+
+            // we need to let the model re-calculate the Range before we use it
+            range = daDoc.getRange();
+
+            assertEquals(1, range.numSections());
+            section = range.getSection(0);
+
+            assertEquals(5, section.numParagraphs());
+
+            para = section.getParagraph(0);
+            text = para.text();
+            assertEquals(introText, text);
+
+            para = section.getParagraph(1);
+            text = para.text();
+            assertEquals(expectedText1, text);
+
+            para = section.getParagraph(2);
+            text = para.text();
+            assertEquals(expectedText2, text);
+
+            para = section.getParagraph(3);
+            text = para.text();
+            assertEquals(expectedText3, text);
+        }
+    }
 }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeInsertion.java Sat May 22 21:37:08 2021
@@ -26,97 +26,97 @@ import org.apache.poi.hwpf.HWPFDocument;
 import org.junit.jupiter.api.Test;
 
 /**
- *	Test to see if Range.insertBefore() works even if the Range contains a
- *	CharacterRun that uses Unicode characters.
+ *  Test to see if Range.insertBefore() works even if the Range contains a
+ *  CharacterRun that uses Unicode characters.
  *
  * TODO - re-enable me when unicode paragraph stuff is fixed!
  */
 public final class TestRangeInsertion {
 
-	// u201c and u201d are "smart-quotes"
-	private static final String originalText =
-		"It is used to confirm that text insertion works even if Unicode characters (such as \u201c\u2014\u201d " +
-		"(U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.\r";
-	private static final String textToInsert = "Look at me!  I'm cool!  ";
-	private static final int insertionPoint = 122;
-
-	private static final String illustrativeDocFile = "testRangeInsertion.doc";
-
-	/**
-	 * Test just opening the files
-	 */
-	@Test
-	void testOpen() throws IOException {
-		try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
-			assertEquals(3, daDoc.getParagraphTable().getParagraphs().size());
-		}
-	}
-
-	/**
-	 * Test (more "confirm" than test) that we have the general structure that we expect to have.
-	 */
-	@Test
-	void testDocStructure() throws IOException {
-		try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
-
-			Range range = daDoc.getRange();
-
-			assertEquals(1, range.numSections());
-			Section section = range.getSection(0);
-
-			assertEquals(3, section.numParagraphs());
-			Paragraph para = section.getParagraph(2);
-			assertEquals(originalText, para.text());
-
-			assertEquals(3, para.numCharacterRuns());
-			String text =
-					para.getCharacterRun(0).text() +
-							para.getCharacterRun(1).text() +
-							para.getCharacterRun(2).text();
-
-			assertEquals(originalText, text);
-
-			assertEquals(insertionPoint, para.getStartOffset());
-		}
-	}
-
-	/**
-	 * Test that we can insert text in our CharacterRun with Unicode text.
-	 */
-	@Test
-	void testRangeInsertion() throws IOException {
-		try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
-
-//		if (false) { // TODO - delete or resurrect this code
-//			Range range = daDoc.getRange();
-//			Section section = range.getSection(0);
-//			Paragraph para = section.getParagraph(2);
-//			String text = para.getCharacterRun(0).text() + para.getCharacterRun(1).text() +
-//			para.getCharacterRun(2).text();
+    // u201c and u201d are "smart-quotes"
+    private static final String originalText =
+        "It is used to confirm that text insertion works even if Unicode characters (such as \u201c\u2014\u201d " +
+        "(U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.\r";
+    private static final String textToInsert = "Look at me!  I'm cool!  ";
+    private static final int insertionPoint = 122;
+
+    private static final String illustrativeDocFile = "testRangeInsertion.doc";
+
+    /**
+     * Test just opening the files
+     */
+    @Test
+    void testOpen() throws IOException {
+        try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
+            assertEquals(3, daDoc.getParagraphTable().getParagraphs().size());
+        }
+    }
+
+    /**
+     * Test (more "confirm" than test) that we have the general structure that we expect to have.
+     */
+    @Test
+    void testDocStructure() throws IOException {
+        try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
+
+            Range range = daDoc.getRange();
+
+            assertEquals(1, range.numSections());
+            Section section = range.getSection(0);
+
+            assertEquals(3, section.numParagraphs());
+            Paragraph para = section.getParagraph(2);
+            assertEquals(originalText, para.text());
+
+            assertEquals(3, para.numCharacterRuns());
+            String text =
+                    para.getCharacterRun(0).text() +
+                            para.getCharacterRun(1).text() +
+                            para.getCharacterRun(2).text();
+
+            assertEquals(originalText, text);
+
+            assertEquals(insertionPoint, para.getStartOffset());
+        }
+    }
+
+    /**
+     * Test that we can insert text in our CharacterRun with Unicode text.
+     */
+    @Test
+    void testRangeInsertion() throws IOException {
+        try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
+
+//      if (false) { // TODO - delete or resurrect this code
+//          Range range = daDoc.getRange();
+//          Section section = range.getSection(0);
+//          Paragraph para = section.getParagraph(2);
+//          String text = para.getCharacterRun(0).text() + para.getCharacterRun(1).text() +
+//          para.getCharacterRun(2).text();
 //
-//			System.out.println(text);
-//		}
+//          System.out.println(text);
+//      }
 
-			Range range = new Range(insertionPoint, (insertionPoint + 2), daDoc);
-			range.insertBefore(textToInsert);
+            Range range = new Range(insertionPoint, (insertionPoint + 2), daDoc);
+            range.insertBefore(textToInsert);
 
-			// we need to let the model re-calculate the Range before we evaluate it
-			range = daDoc.getRange();
+            // we need to let the model re-calculate the Range before we evaluate it
+            range = daDoc.getRange();
 
-			assertEquals(1, range.numSections());
-			Section section = range.getSection(0);
-
-			assertEquals(3, section.numParagraphs());
-			Paragraph para = section.getParagraph(2);
-			assertEquals((textToInsert + originalText), para.text());
-
-			assertEquals(3, para.numCharacterRuns());
-			String text =
-				para.getCharacterRun(0).text() +
-				para.getCharacterRun(1).text() +
-				para.getCharacterRun(2).text();
-
-			assertEquals((textToInsert + originalText), text);
-		}
-	}
+            assertEquals(1, range.numSections());
+            Section section = range.getSection(0);
+
+            assertEquals(3, section.numParagraphs());
+            Paragraph para = section.getParagraph(2);
+            assertEquals((textToInsert + originalText), para.text());
+
+            assertEquals(3, para.numCharacterRuns());
+            String text =
+                para.getCharacterRun(0).text() +
+                para.getCharacterRun(1).text() +
+                para.getCharacterRun(2).text();
+
+            assertEquals((textToInsert + originalText), text);
+        }
+    }
 }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeProperties.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeProperties.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeProperties.java Sat May 22 21:37:08 2021
@@ -261,7 +261,7 @@ public final class TestRangeProperties {
                 p1_parts[2].length() + 1,
                 p2.getEnd()
         );
-	}
+    }
 
     /**
      * Tests the paragraph text of a unicode document

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java?rev=1890122&r1=1890121&r2=1890122&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRangeReplacement.java Sat May 22 21:37:08 2021
@@ -26,131 +26,131 @@ import org.apache.poi.hwpf.HWPFDocument;
 import org.junit.jupiter.api.Test;
 
 /**
- *	Test to see if Range.replaceText() works even if the Range contains a
- *	CharacterRun that uses Unicode characters.
+ *  Test to see if Range.replaceText() works even if the Range contains a
+ *  CharacterRun that uses Unicode characters.
  *
  * TODO - re-enable me when unicode paragraph stuff is fixed!
  */
 public final class TestRangeReplacement {
 
-	// u201c and u201d are "smart-quotes"
-	private static final String originalText =
-		"It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.  Everybody should be thankful to the ${organization} and all the POI contributors for their assistance in this matter.\r";
-	private static final String searchText = "${organization}";
-	private static final String replacementText = "Apache Software Foundation";
-	private static final String expectedText2 =
-		"It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.  Everybody should be thankful to the Apache Software Foundation and all the POI contributors for their assistance in this matter.\r";
-	private static final String expectedText3 = "Thank you, Apache Software Foundation!\r";
-
-	private static final String illustrativeDocFile = "testRangeReplacement.doc";
-
-	/**
-	 * Test just opening the files
-	 */
-	void testOpen() {
-		openSampleFile(illustrativeDocFile);
-	}
-
-	/**
-	 * Test (more "confirm" than test) that we have the general structure that we expect to have.
-	 */
-	@Test
-	void testDocStructure() throws IOException {
-		try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
-
-			Range range = daDoc.getRange();
-			assertEquals(414, range.text().length());
-
-			assertEquals(1, range.numSections());
-			Section section = range.getSection(0);
-			assertEquals(414, section.text().length());
-
-			assertEquals(5, section.numParagraphs());
-			Paragraph para = section.getParagraph(2);
-
-			assertEquals(5, para.numCharacterRuns());
-			String text =
-					para.getCharacterRun(0).text() +
-							para.getCharacterRun(1).text() +
-							para.getCharacterRun(2).text() +
-							para.getCharacterRun(3).text() +
-							para.getCharacterRun(4).text();
-
-			assertEquals(originalText, text);
-		}
-	}
-
-	/**
-	 * Test that we can replace text in our Range with Unicode text.
-	 */
-	@Test
-	void testRangeReplacementOne() throws IOException {
-		try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
-
-			// Has one section
-			Range range = daDoc.getRange();
-			assertEquals(1, range.numSections());
-
-			// The first section has 5 paragraphs
-			Section section = range.getSection(0);
-			assertEquals(5, section.numParagraphs());
-
-
-			// Change some text
-			Paragraph para = section.getParagraph(2);
-
-			String text = para.text();
-			assertEquals(originalText, text);
-
-			int offset = text.indexOf(searchText);
-			assertEquals(181, offset);
-
-			para.replaceText(searchText, replacementText, offset);
-
-			// Ensure we still have one section, 5 paragraphs
-			assertEquals(1, range.numSections());
-			section = range.getSection(0);
-
-			assertEquals(5, section.numParagraphs());
-			para = section.getParagraph(2);
-
-			// Ensure the text is what we should now have
-			text = para.text();
-			assertEquals(expectedText2, text);
-		}
-	}
-
-	/**
-	 * Test that we can replace text in our Range with Unicode text.
-	 */
-	@Test
-	void testRangeReplacementAll() throws IOException {
-		try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
-
-			Range range = daDoc.getRange();
-			assertEquals(1, range.numSections());
-
-			Section section = range.getSection(0);
-			assertEquals(5, section.numParagraphs());
-
-			Paragraph para = section.getParagraph(2);
-
-			String text = para.text();
-			assertEquals(originalText, text);
-
-			range.replaceText(searchText, replacementText);
-
-			assertEquals(1, range.numSections());
-			section = range.getSection(0);
-			assertEquals(5, section.numParagraphs());
-
-			para = section.getParagraph(2);
-			text = para.text();
-			assertEquals(expectedText2, text);
-
-			para = section.getParagraph(3);
-			text = para.text();
-			assertEquals(expectedText3, text);
-		}
-	}
+    // u201c and u201d are "smart-quotes"
+    private static final String originalText =
+        "It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.  Everybody should be thankful to the ${organization} and all the POI contributors for their assistance in this matter.\r";
+    private static final String searchText = "${organization}";
+    private static final String replacementText = "Apache Software Foundation";
+    private static final String expectedText2 =
+        "It is used to confirm that text replacement works even if Unicode characters (such as \u201c\u2014\u201d (U+2014), \u201c\u2e8e\u201d (U+2E8E), or \u201c\u2714\u201d (U+2714)) are present.  Everybody should be thankful to the Apache Software Foundation and all the POI contributors for their assistance in this matter.\r";
+    private static final String expectedText3 = "Thank you, Apache Software Foundation!\r";
+
+    private static final String illustrativeDocFile = "testRangeReplacement.doc";
+
+    /**
+     * Test just opening the files
+     */
+    void testOpen() {
+        openSampleFile(illustrativeDocFile);
+    }
+
+    /**
+     * Test (more "confirm" than test) that we have the general structure that we expect to have.
+     */
+    @Test
+    void testDocStructure() throws IOException {
+        try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
+
+            Range range = daDoc.getRange();
+            assertEquals(414, range.text().length());
+
+            assertEquals(1, range.numSections());
+            Section section = range.getSection(0);
+            assertEquals(414, section.text().length());
+
+            assertEquals(5, section.numParagraphs());
+            Paragraph para = section.getParagraph(2);
+
+            assertEquals(5, para.numCharacterRuns());
+            String text =
+                    para.getCharacterRun(0).text() +
+                            para.getCharacterRun(1).text() +
+                            para.getCharacterRun(2).text() +
+                            para.getCharacterRun(3).text() +
+                            para.getCharacterRun(4).text();
+
+            assertEquals(originalText, text);
+        }
+    }
+
+    /**
+     * Test that we can replace text in our Range with Unicode text.
+     */
+    @Test
+    void testRangeReplacementOne() throws IOException {
+        try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
+
+            // Has one section
+            Range range = daDoc.getRange();
+            assertEquals(1, range.numSections());
+
+            // The first section has 5 paragraphs
+            Section section = range.getSection(0);
+            assertEquals(5, section.numParagraphs());
+
+
+            // Change some text
+            Paragraph para = section.getParagraph(2);
+
+            String text = para.text();
+            assertEquals(originalText, text);
+
+            int offset = text.indexOf(searchText);
+            assertEquals(181, offset);
+
+            para.replaceText(searchText, replacementText, offset);
+
+            // Ensure we still have one section, 5 paragraphs
+            assertEquals(1, range.numSections());
+            section = range.getSection(0);
+
+            assertEquals(5, section.numParagraphs());
+            para = section.getParagraph(2);
+
+            // Ensure the text is what we should now have
+            text = para.text();
+            assertEquals(expectedText2, text);
+        }
+    }
+
+    /**
+     * Test that we can replace text in our Range with Unicode text.
+     */
+    @Test
+    void testRangeReplacementAll() throws IOException {
+        try (HWPFDocument daDoc = openSampleFile(illustrativeDocFile)) {
+
+            Range range = daDoc.getRange();
+            assertEquals(1, range.numSections());
+
+            Section section = range.getSection(0);
+            assertEquals(5, section.numParagraphs());
+
+            Paragraph para = section.getParagraph(2);
+
+            String text = para.text();
+            assertEquals(originalText, text);
+
+            range.replaceText(searchText, replacementText);
+
+            assertEquals(1, range.numSections());
+            section = range.getSection(0);
+            assertEquals(5, section.numParagraphs());
+
+            para = section.getParagraph(2);
+            text = para.text();
+            assertEquals(expectedText2, text);
+
+            para = section.getParagraph(3);
+            text = para.text();
+            assertEquals(expectedText3, text);
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org