poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject svn commit: r1156662 [3/3] - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/ src/org/apache/poi/hwpf/dev/ src/org/apache/poi/hwpf/model/ src/org/apache/poi/hwpf/model/types/ testcases/org/apache/poi/hwpf/model/ testcases/org/apache/poi/hwpf/user...
Date Thu, 11 Aug 2011 16:37:32 GMT
Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java?rev=1156662&r1=1156661&r2=1156662&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestDocumentProperties.java
Thu Aug 11 16:37:31 2011
@@ -39,7 +39,7 @@ public final class TestDocumentPropertie
     _documentProperties.serialize(buf, 0);
 
     DocumentProperties newDocProperties =
-      new DocumentProperties(buf, 0);
+      new DocumentProperties(buf, 0, size);
 
     Field[] fields = DocumentProperties.class.getSuperclass().getDeclaredFields();
     AccessibleObject.setAccessible(fields, true);
@@ -71,7 +71,7 @@ public final class TestDocumentPropertie
 
     _hWPFDocFixture.setUp();
 
-    _documentProperties = new DocumentProperties(_hWPFDocFixture._tableStream, _hWPFDocFixture._fib.getFcDop());
+    _documentProperties = new DocumentProperties(_hWPFDocFixture._tableStream, _hWPFDocFixture._fib.getFcDop(),
_hWPFDocFixture._fib.getLcbDop());
   }
 
   protected void tearDown()

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java?rev=1156662&r1=1156661&r2=1156662&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java Thu Aug
11 16:37:31 2011
@@ -16,21 +16,15 @@
 ==================================================================== */
 package org.apache.poi.hwpf.usermodel;
 
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
-import org.apache.poi.util.LittleEndian;
-
-import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
-import org.apache.poi.hwpf.model.SubdocumentType;
-
-import org.apache.poi.hwpf.model.FileInformationBlock;
-
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hwpf.HWPFDocument;
@@ -39,8 +33,12 @@ import org.apache.poi.hwpf.HWPFTestDataS
 import org.apache.poi.hwpf.extractor.Word6Extractor;
 import org.apache.poi.hwpf.extractor.WordExtractor;
 import org.apache.poi.hwpf.model.FieldsDocumentPart;
+import org.apache.poi.hwpf.model.FileInformationBlock;
 import org.apache.poi.hwpf.model.PlexOfField;
+import org.apache.poi.hwpf.model.SubdocumentType;
+import org.apache.poi.hwpf.model.io.HWPFOutputStream;
 import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.LittleEndian;
 
 /**
  * Test different problems reported in Apache Bugzilla
@@ -549,11 +547,13 @@ public class TestBugs extends TestCase
     /**
      * [RESOLVED FIXED] Bug 51604 - replace text fails for doc ( poi 3.8 beta
      * release from download site )
+     * 
+     * @throws IOException
+     * @throws FileNotFoundException
      */
-    public void test51604p2()
+    public void test51604p2() throws FileNotFoundException, IOException
     {
-        HWPFDocument doc = HWPFTestDataSamples
-                .openSampleFile( "Bug51604.doc" );
+        HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug51604.doc" );
 
         Range range = doc.getRange();
         int numParagraph = range.numParagraphs();
@@ -583,7 +583,49 @@ public class TestBugs extends TestCase
 
             totalLength += partLength;
         }
+    }
+
+    /**
+     * [RESOLVED FIXED] Bug 51604 - replace text fails for doc ( poi 3.8 beta
+     * release from download site )
+     */
+    public void test51604p3() throws IOException
+    {
+        HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "Bug51604.doc" );
+
+        byte[] originalData = new byte[doc.getFileInformationBlock()
+                .getLcbDop()];
+        System.arraycopy( doc.getTableStream(), doc.getFileInformationBlock()
+                .getFcDop(), originalData, 0, originalData.length );
+
+        HWPFOutputStream outputStream = new HWPFOutputStream();
+        doc.getDocProperties().writeTo( outputStream );
+        final byte[] oldData = outputStream.toByteArray();
+
+        assertEquals( Arrays.toString( originalData ),
+                Arrays.toString( oldData ) );
+
+        Range range = doc.getRange();
+        int numParagraph = range.numParagraphs();
+        for ( int i = 0; i < numParagraph; i++ )
+        {
+            Paragraph paragraph = range.getParagraph( i );
+            int numCharRuns = paragraph.numCharacterRuns();
+            for ( int j = 0; j < numCharRuns; j++ )
+            {
+                CharacterRun charRun = paragraph.getCharacterRun( j );
+                String text = charRun.text();
+                if ( text.contains( "Header" ) )
+                    charRun.replaceText( text, "added" );
+            }
+        }
+
+        doc = HWPFTestDataSamples.writeOutAndReadBack( doc );
+
+        outputStream = new HWPFOutputStream();
+        doc.getDocProperties().writeTo( outputStream );
+        final byte[] newData = outputStream.toByteArray();
 
-        assertEquals( doc.getText().length(), totalLength );
+        assertEquals( Arrays.toString( oldData ), Arrays.toString( newData ) );
     }
 }



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


Mime
View raw message