]> source.dussan.org Git - poi.git/commitdiff
Slightly expand tests, inspired by bug #50060, but ultimately show there is a deeper...
authorNick Burch <nick@apache.org>
Fri, 22 Oct 2010 16:41:02 +0000 (16:41 +0000)
committerNick Burch <nick@apache.org>
Fri, 22 Oct 2010 16:41:02 +0000 (16:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1026399 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java
src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java

index 4dd20d69dd4e08a9cbc2e36384ef85bb0045381d..72f37b4182f62b9b49589541b6973d9cd0496613 100644 (file)
@@ -199,7 +199,8 @@ public class CHPBinTable
     int pageNum = docOffset/POIFSConstants.SMALLER_BIG_BLOCK_SIZE;
 
     // get the ending fc
-    int endingFc = ((PropertyNode)_textRuns.get(_textRuns.size() - 1)).getEnd();
+    PropertyNode lastRun = (PropertyNode)_textRuns.get(_textRuns.size() - 1); 
+    int endingFc = lastRun.getEnd();
     endingFc += fcMin;
 
 
index 43eb9b4870a4655ed0b276addb37c49601a09266..ebb4614c19d172bed8db106edde3570d6720199f 100644 (file)
@@ -98,108 +98,149 @@ public final class TestHWPFRangeParts extends TestCase {
                docAscii = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
        }
 
+       /**
+        * Note - this test runs several times, to ensure that things
+        *  don't get broken as we write out and read back in again
+        * TODO - Make this work with 3+ runs
+        */
        public void testBasics() {
-               // First check the start and end bits
-               assertEquals(
-                               0,
-                               docAscii._cpSplit.getMainDocumentStart()
-               );
-               assertEquals(
-                               a_page_1.length() +
-                               2 + // page break
-                               a_page_2.length(),
-                               docAscii._cpSplit.getMainDocumentEnd()
-               );
-
-               assertEquals(
-                               238,
-                               docAscii._cpSplit.getFootnoteStart()
-               );
-               assertEquals(
-                               238,
-                               docAscii._cpSplit.getFootnoteEnd()
-               );
-
-               assertEquals(
-                               238,
-                               docAscii._cpSplit.getHeaderStoryStart()
-               );
-               assertEquals(
-                               238 + headerDef.length() + a_header.length() +
-                               footerDef.length() + a_footer.length() + endHeaderFooter.length(),
-                               docAscii._cpSplit.getHeaderStoryEnd()
-               );
+          HWPFDocument doc = docAscii;
+          for(int run=0; run<3; run++) {
+               // First check the start and end bits
+               assertEquals(
+                               0,
+                               doc._cpSplit.getMainDocumentStart()
+               );
+               assertEquals(
+                               a_page_1.length() +
+                               2 + // page break
+                               a_page_2.length(),
+                               doc._cpSplit.getMainDocumentEnd()
+               );
+   
+               assertEquals(
+                               238,
+                               doc._cpSplit.getFootnoteStart()
+               );
+               assertEquals(
+                               238,
+                               doc._cpSplit.getFootnoteEnd()
+               );
+   
+               assertEquals(
+                               238,
+                               doc._cpSplit.getHeaderStoryStart()
+               );
+               assertEquals(
+                               238 + headerDef.length() + a_header.length() +
+                               footerDef.length() + a_footer.length() + endHeaderFooter.length(),
+                               doc._cpSplit.getHeaderStoryEnd()
+               );
+               
+               // Write out and read back in again, ready for
+               //  the next run of the test
+               // TODO run more than once
+               if(run < 1)
+                  doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
+          }
        }
 
+   /**
+    * Note - this test runs several times, to ensure that things
+    *  don't get broken as we write out and read back in again
+    * TODO - Make this work with 3+ runs
+    */
        public void testContents() {
-               Range r;
-
-               // Now check the real ranges
-               r = docAscii.getRange();
-               assertEquals(
-                               a_page_1 +
-                               page_break + "\r" +
-                               a_page_2,
-                               r.text()
-               );
-
-               r = docAscii.getHeaderStoryRange();
-               assertEquals(
-                               headerDef +
-                               a_header +
-                               footerDef +
-                               a_footer +
-                               endHeaderFooter,
-                               r.text()
-               );
-
-               r = docAscii.getOverallRange();
-               assertEquals(
-                               a_page_1 +
-                               page_break + "\r" +
-                               a_page_2 +
-                               headerDef +
-                               a_header +
-                               footerDef +
-                               a_footer +
-                               endHeaderFooter +
-                               "\r",
-                               r.text()
-               );
+      HWPFDocument doc = docAscii;
+      for(int run=0; run<3; run++) {
+               Range r;
+   
+               // Now check the real ranges
+               r = doc.getRange();
+               assertEquals(
+                               a_page_1 +
+                               page_break + "\r" +
+                               a_page_2,
+                               r.text()
+               );
+   
+               r = doc.getHeaderStoryRange();
+               assertEquals(
+                               headerDef +
+                               a_header +
+                               footerDef +
+                               a_footer +
+                               endHeaderFooter,
+                               r.text()
+               );
+   
+               r = doc.getOverallRange();
+               assertEquals(
+                               a_page_1 +
+                               page_break + "\r" +
+                               a_page_2 +
+                               headerDef +
+                               a_header +
+                               footerDef +
+                               a_footer +
+                               endHeaderFooter +
+                               "\r",
+                               r.text()
+               );
+         
+         // Write out and read back in again, ready for
+         //  the next run of the test
+         // TODO run more than once
+         if(run < 1)
+            doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
+      }
        }
 
+   /**
+    * Note - this test runs several times, to ensure that things
+    *  don't get broken as we write out and read back in again
+    */
        public void testBasicsUnicode() {
-               // First check the start and end bits
-               assertEquals(
-                               0,
-                               docUnicode._cpSplit.getMainDocumentStart()
-               );
-               assertEquals(
-                               u_page_1.length() +
-                               2 + // page break
-                               u_page_2.length(),
-                               docUnicode._cpSplit.getMainDocumentEnd()
-               );
-
-               assertEquals(
-                               408,
-                               docUnicode._cpSplit.getFootnoteStart()
-               );
-               assertEquals(
-                               408,
-                               docUnicode._cpSplit.getFootnoteEnd()
-               );
-
-               assertEquals(
-                               408,
-                               docUnicode._cpSplit.getHeaderStoryStart()
-               );
-               // TODO - fix this one
-               assertEquals(
-                               408 + headerDef.length() + u_header.length() +
-                               footerDef.length() + u_footer.length() + endHeaderFooter.length(),
-                               docUnicode._cpSplit.getHeaderStoryEnd()
-               );
+      HWPFDocument doc = docUnicode;
+      for(int run=0; run<3; run++) {
+               // First check the start and end bits
+               assertEquals(
+                               0,
+                               doc._cpSplit.getMainDocumentStart()
+               );
+               assertEquals(
+                               u_page_1.length() +
+                               2 + // page break
+                               u_page_2.length(),
+                               doc._cpSplit.getMainDocumentEnd()
+               );
+   
+               assertEquals(
+                               408,
+                               doc._cpSplit.getFootnoteStart()
+               );
+               assertEquals(
+                               408,
+                               doc._cpSplit.getFootnoteEnd()
+               );
+   
+               assertEquals(
+                               408,
+                               doc._cpSplit.getHeaderStoryStart()
+               );
+               // TODO - fix this one
+               assertEquals(
+                               408 + headerDef.length() + u_header.length() +
+                               footerDef.length() + u_footer.length() + endHeaderFooter.length(),
+                               doc._cpSplit.getHeaderStoryEnd()
+               );
+               
+         // Write out and read back in again, ready for
+         //  the next run of the test
+         // TODO run more than once
+         if(run < 1)
+            doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
+      }
        }
 
        public void testContentsUnicode() {