poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1734718 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/model/TextPieceTable.java testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java
Date Sat, 12 Mar 2016 16:56:26 GMT
Author: centic
Date: Sat Mar 12 16:56:26 2016
New Revision: 1734718

URL: http://svn.apache.org/viewvc?rev=1734718&view=rev
Log:
Fix bug 56549: correctly calculate char index ranges for HWPF in the TextPieceTable

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java?rev=1734718&r1=1734717&r2=1734718&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java Sat Mar 12
16:56:26 2016
@@ -259,6 +259,7 @@ public class TextPieceTable implements C
         return charCount;
     }
 
+    @Override
     public int[][] getCharIndexRanges( int startBytePosInclusive,
             int endBytePosExclusive )
     {
@@ -271,7 +272,7 @@ public class TextPieceTable implements C
                     + textPiece.bytesLength();
             if ( startBytePosInclusive > tpEnd )
                 continue;
-            if ( endBytePosExclusive < tpStart )
+            if ( endBytePosExclusive <= tpStart )
                 break;
 
             final int rangeStartBytes = Math.max( tpStart,

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java?rev=1734718&r1=1734717&r2=1734718&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestTextPieceTable.java Sat
Mar 12 16:56:26 2016
@@ -26,13 +26,38 @@ import org.apache.poi.hwpf.HWPFDocFixtur
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.HWPFTestDataSamples;
 import org.apache.poi.hwpf.model.io.HWPFFileSystem;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 @SuppressWarnings("deprecation")
-public final class TestTextPieceTable extends TestCase {
+public final class TestTextPieceTable {
     private HWPFDocFixture _hWPFDocFixture;
 
-    // private String dirname;
+    @Before
+    public void setUp() throws Exception {
+        System.setProperty("org.apache.poi.hwpf.preserveTextTable",
+                Boolean.TRUE.toString());
+
+        _hWPFDocFixture = new HWPFDocFixture(this,
+                HWPFDocFixture.DEFAULT_TEST_FILE);
+        _hWPFDocFixture.setUp();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        _hWPFDocFixture.tearDown();
+        _hWPFDocFixture = null;
 
+        System.setProperty("org.apache.poi.hwpf.preserveTextTable",
+                Boolean.FALSE.toString());
+    }
+
+    @Test
     public void testReadWrite() throws Exception {
         FileInformationBlock fib = _hWPFDocFixture._fib;
         byte[] mainStream = _hWPFDocFixture._mainStream;
@@ -63,6 +88,7 @@ public final class TestTextPieceTable ex
     /**
      * Check that we do the positions correctly when working with pure-ascii
      */
+    @Test
     public void testAsciiParts() throws Exception {
         HWPFDocument doc = HWPFTestDataSamples
                 .openSampleFile("ThreeColHeadFoot.doc");
@@ -98,6 +124,7 @@ public final class TestTextPieceTable ex
      * Check that we do the positions correctly when working with a mix ascii,
      * unicode file
      */
+    @Test
     public void testUnicodeParts() throws Exception {
         HWPFDocument doc = HWPFTestDataSamples
                 .openSampleFile("HeaderFooterUnicode.doc");
@@ -164,25 +191,61 @@ public final class TestTextPieceTable ex
         return new HWPFDocument(new ByteArrayInputStream(baos.toByteArray()));
     }
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        System.setProperty("org.apache.poi.hwpf.preserveTextTable",
-                Boolean.TRUE.toString());
+    @Test
+    public void test56549_CharIndexRange() {
+        HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
 
-        _hWPFDocFixture = new HWPFDocFixture(this,
-                HWPFDocFixture.DEFAULT_TEST_FILE);
-        _hWPFDocFixture.setUp();
-    }
+        // there is one range from 2048 - 2387
 
-    @Override
-    protected void tearDown() throws Exception {
-        _hWPFDocFixture.tearDown();
-        _hWPFDocFixture = null;
+        TextPieceTable tbl = doc.getTextTable();
+        int[][] range = tbl.getCharIndexRanges(0, 0);
+        assertEquals(0, range.length);
 
-        System.setProperty("org.apache.poi.hwpf.preserveTextTable",
-                Boolean.FALSE.toString());
-        super.tearDown();
-    }
+        range = tbl.getCharIndexRanges(0, 1);
+        assertEquals(0, range.length);
+
+        range = tbl.getCharIndexRanges(0, 338);
+        assertEquals(0, range.length);
+
+        range = tbl.getCharIndexRanges(0, 339);
+        assertEquals(0, range.length);
+
+        range = tbl.getCharIndexRanges(0, 340);
+        assertEquals(0, range.length);
 
+        range = tbl.getCharIndexRanges(2030, 2048);
+        assertEquals(0, range.length);
+
+        range = tbl.getCharIndexRanges(2030, 2049);
+        assertEquals(1, range.length);
+        assertArrayEquals(new int[] {0,1}, range[0]);
+
+        range = tbl.getCharIndexRanges(2048, 2049);
+        assertEquals(1, range.length);
+        assertArrayEquals(new int[] {0,1}, range[0]);
+
+        range = tbl.getCharIndexRanges(2048, 2300);
+        assertEquals(1, range.length);
+        assertArrayEquals(new int[] {0,252}, range[0]);
+
+        range = tbl.getCharIndexRanges(2049, 2300);
+        assertEquals(1, range.length);
+        assertArrayEquals(new int[] {1,252}, range[0]);
+
+        range = tbl.getCharIndexRanges(2049, 2300);
+        assertEquals(1, range.length);
+        assertArrayEquals(new int[] {1,252}, range[0]);
+
+        range = tbl.getCharIndexRanges(2049, 2387);
+        assertEquals(1, range.length);
+        assertArrayEquals(new int[] {1,339}, range[0]);
+
+        range = tbl.getCharIndexRanges(2049, 2388);
+        assertEquals(1, range.length);
+        assertArrayEquals(new int[] {1,339}, range[0]);
+
+        range = tbl.getCharIndexRanges(2387, 2388);
+        assertEquals(1, range.length);
+        assertArrayEquals(new int[] {339,339}, range[0]);
+    }
 }



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


Mime
View raw message