]> source.dussan.org Git - poi.git/commitdiff
More tests to show that the range based stuff is working properly
authorNick Burch <nick@apache.org>
Sat, 9 Aug 2008 17:23:42 +0000 (17:23 +0000)
committerNick Burch <nick@apache.org>
Sat, 9 Aug 2008 17:23:42 +0000 (17:23 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@684299 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/model/CPSplitCalculator.java
src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java [new file with mode: 0644]

index 774a07b119316b1c109855b677c349761911d2da..1e3a20731bc21b607f43e4d11fbb979328ca8f64 100644 (file)
@@ -55,9 +55,8 @@ public class CPSplitCalculator {
         * Length comes from FibRgLw97.ccpFtn
         */
        public int getFootnoteEnd() {
-               throw new IllegalStateException("Not yet finished!");
-//             return getFootnoteStart() +
-//                     ???;
+               return getFootnoteStart() +
+                       fib.getCcpFtn();
        }
        
        /**
@@ -72,8 +71,71 @@ public class CPSplitCalculator {
         * Length comes from FibRgLw97.ccpHdd
         */
        public int getHeaderStoryEnd() {
-               throw new IllegalStateException("Not yet finished!");
-//             return getHeaderStoryStart() +
-//                     ???;
+               return getHeaderStoryStart() +
+                       fib.getCcpHdd();
+       }
+       
+       /**
+        * Where the Comment (Atn) text starts.
+        * Follows straight on from the header stories.
+        */
+       public int getCommentsStart() {
+               return getHeaderStoryEnd();
+       }
+       /**
+        * Where the Comment (Atn) text ends.
+        * Length comes from FibRgLw97.ccpAtn
+        */
+       public int getCommentsEnd() {
+               return getCommentsStart() +
+                       fib.getCcpCommentAtn();
+       }
+       
+       /**
+        * Where the End Note text starts.
+        * Follows straight on from the comments.
+        */
+       public int getEndNoteStart() {
+               return getCommentsEnd();
+       }
+       /**
+        * Where the End Note text ends.
+        * Length comes from FibRgLw97.ccpEdn
+        */
+       public int getEndNoteEnd() {
+               return getEndNoteStart() +
+                       fib.getCcpEdn();
+       }
+       
+       /**
+        * Where the Main Textbox text starts.
+        * Follows straight on from the end note.
+        */
+       public int getMainTextboxStart() {
+               return getEndNoteEnd();
+       }
+       /**
+        * Where the Main textbox text ends.
+        * Length comes from FibRgLw97.ccpTxBx
+        */
+       public int getMainTextboxEnd() {
+               return getMainTextboxStart() +
+                       fib.getCcpTxtBx();
+       }
+       
+       /**
+        * Where the Header Textbox text starts.
+        * Follows straight on from the main textbox.
+        */
+       public int getHeaderTextboxStart() {
+               return getMainTextboxEnd();
+       }
+       /**
+        * Where the Header textbox text ends.
+        * Length comes from FibRgLw97.ccpHdrTxBx
+        */
+       public int getHeaderTextboxEnd() {
+               return getHeaderTextboxStart() +
+                       fib.getCcpHdrTxtBx();
        }
 }
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java b/src/scratchpad/testcases/org/apache/poi/hwpf/TestHWPFRangeParts.java
new file mode 100644 (file)
index 0000000..9a19344
--- /dev/null
@@ -0,0 +1,145 @@
+
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+        
+package org.apache.poi.hwpf;
+
+import java.io.FileInputStream;
+
+import org.apache.poi.hwpf.usermodel.Range;
+
+import junit.framework.TestCase;
+
+/**
+ * Test that we pull out the right bits of a file into
+ *  the different ranges
+ */
+public class TestHWPFRangeParts extends TestCase {
+       private static final String page_1 =
+               "This is a sample word document. It has two pages. It has a three column heading, and a three column footer\r" +
+               "\r" +
+               "HEADING TEXT\r" + 
+               "\r" +
+               "More on page one\r" +
+               "\r\r" +
+               "End of page 1\r"
+       ;
+       private static final char page_break = (char)12;
+       private static final String page_2 =
+               "This is page two. It also has a three column heading, and a three column footer.\r"
+       ;
+       
+       private static final String headerDef = 
+               "\u0003\r\r" +
+               "\u0004\r\r" +
+               "\u0003\r\r" +
+               "\u0004\r\r"
+       ;
+       private static final String header =
+               "First header column!\tMid header Right header!\r"
+       ;
+       private static final String footerDef = 
+               "\r"
+       ;
+       private static final String footer =
+               "Footer Left\tFooter Middle Footer Right\r"
+       ;
+       private static final String endHeaderFooter =
+               "\r\r"
+       ;
+       
+       private HWPFDocument doc;
+       
+       public void setUp() throws Exception {
+               String filename = System.getProperty("HWPF.testdata.path");
+               filename = filename + "/ThreeColHeadFoot.doc";
+               
+               doc = new HWPFDocument(
+                               new FileInputStream(filename)
+               );
+       }
+       
+       public void testBasics() throws Exception {
+               // First check the start and end bits
+               assertEquals(
+                               0,
+                               doc._cpSplit.getMainDocumentStart()
+               );
+               assertEquals(
+                               page_1.length() +
+                               2 + // page break
+                               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() + header.length() +
+                               footerDef.length() + footer.length() + endHeaderFooter.length(),
+                               doc._cpSplit.getHeaderStoryEnd()
+               );
+       }
+       
+       public void testContents() throws Exception {
+               Range r;
+               
+               // Now check the real ranges
+               r = doc.getRange();
+               assertEquals(
+                               page_1 +
+                               page_break + "\r" +
+                               page_2,
+                               r.text()
+               );
+               
+               r = doc.getHeaderStoryRange();
+               assertEquals(
+                               headerDef +
+                               header +
+                               footerDef +
+                               footer + 
+                               endHeaderFooter,
+                               r.text()
+               );
+               
+               r = doc.getOverallRange();
+               assertEquals(
+                               page_1 +
+                               page_break + "\r" +
+                               page_2 + 
+                               headerDef +
+                               header +
+                               footerDef +
+                               footer + 
+                               endHeaderFooter +
+                               "\r",
+                               r.text()
+               );
+       }
+}