]> source.dussan.org Git - poi.git/commitdiff
More unit testing for XWPF list numbering complex cases, and some TODOs on improving...
authorNick Burch <nick@apache.org>
Fri, 4 Nov 2016 10:55:31 +0000 (10:55 +0000)
committerNick Burch <nick@apache.org>
Fri, 4 Nov 2016 10:55:31 +0000 (10:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1768005 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNum.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
test-data/document/ComplexNumberedLists.docx [new file with mode: 0644]

index b1ae7ed8cf337ff992db8c0eb355348df71129d9..7674510c1ffc0e7021543144dc5b3aff81960ee0 100644 (file)
@@ -19,8 +19,8 @@ package org.apache.poi.xwpf.usermodel;
 
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum;
 \r
-/**\r
- * @author Philipp Epp\r
+/**
+ * TODO Bring more of the logic over from XWPFParagraph\r
  */\r
 public class XWPFNum {\r
     protected XWPFNumbering numbering;\r
index 6cd3171f3c2dbaf726234bd8fcaca10d42e8d128..756aeef5548eeeb108c1812d0f20f262791a7994 100644 (file)
@@ -592,4 +592,88 @@ public final class TestXWPFParagraph {
         }
         assertEquals("This is a test.\n\n\n\n3\n4\n5\n\n\n\nThis is a whole paragraph where one word is deleted.\n", str.toString());
     }
+    
+    @Test
+    public void testNumberedLists() throws Exception {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("ComplexNumberedLists.docx");
+        XWPFParagraph p;
+        
+        p = doc.getParagraphArray(0);
+        assertEquals("This is a document with numbered lists", p.getText());
+        assertEquals(null, p.getNumID());
+        assertEquals(null, p.getNumIlvl());
+        assertEquals(null, p.getNumStartOverride());
+        
+        p = doc.getParagraphArray(1);
+        assertEquals("Entry #1", p.getText());
+        assertEquals(BigInteger.valueOf(1), p.getNumID());
+        assertEquals(BigInteger.valueOf(0), p.getNumIlvl());
+        assertEquals(null, p.getNumStartOverride());
+        
+        p = doc.getParagraphArray(2);
+        assertEquals("Entry #2, with children", p.getText());
+        assertEquals(BigInteger.valueOf(1), p.getNumID());
+        assertEquals(BigInteger.valueOf(0), p.getNumIlvl());
+        assertEquals(null, p.getNumStartOverride());
+        
+        p = doc.getParagraphArray(3);
+        assertEquals("2-a", p.getText());
+        assertEquals(BigInteger.valueOf(1), p.getNumID());
+        assertEquals(BigInteger.valueOf(1), p.getNumIlvl());
+        assertEquals(null, p.getNumStartOverride());
+        
+        p = doc.getParagraphArray(4);
+        assertEquals("2-b", p.getText());
+        assertEquals(BigInteger.valueOf(1), p.getNumID());
+        assertEquals(BigInteger.valueOf(1), p.getNumIlvl());
+        assertEquals(null, p.getNumStartOverride());
+        
+        p = doc.getParagraphArray(5);
+        assertEquals("2-c", p.getText());
+        assertEquals(BigInteger.valueOf(1), p.getNumID());
+        assertEquals(BigInteger.valueOf(1), p.getNumIlvl());
+        assertEquals(null, p.getNumStartOverride());
+        
+        p = doc.getParagraphArray(6);
+        assertEquals("Entry #3", p.getText());
+        assertEquals(BigInteger.valueOf(1), p.getNumID());
+        assertEquals(BigInteger.valueOf(0), p.getNumIlvl());
+        assertEquals(null, p.getNumStartOverride());
+        
+        p = doc.getParagraphArray(7);
+        assertEquals("Entry #4", p.getText());
+        assertEquals(BigInteger.valueOf(1), p.getNumID());
+        assertEquals(BigInteger.valueOf(0), p.getNumIlvl());
+        assertEquals(null, p.getNumStartOverride());
+        
+        // New list
+        p = doc.getParagraphArray(8);
+        assertEquals("Restarted to 1 from 5", p.getText());
+        assertEquals(BigInteger.valueOf(2), p.getNumID());
+        assertEquals(BigInteger.valueOf(0), p.getNumIlvl());
+        assertEquals(null, p.getNumStartOverride());
+        
+        p = doc.getParagraphArray(9);
+        assertEquals("Restarted @ 2", p.getText());
+        assertEquals(BigInteger.valueOf(2), p.getNumID());
+        assertEquals(BigInteger.valueOf(0), p.getNumIlvl());
+        assertEquals(null, p.getNumStartOverride());
+        
+        p = doc.getParagraphArray(10);
+        assertEquals("Restarted @ 3", p.getText());
+        assertEquals(BigInteger.valueOf(2), p.getNumID());
+        assertEquals(BigInteger.valueOf(0), p.getNumIlvl());
+        assertEquals(null, p.getNumStartOverride());
+        
+        // New list starting at 10
+        p = doc.getParagraphArray(11);
+        assertEquals("Jump to new list at 10", p.getText());
+        assertEquals(BigInteger.valueOf(6), p.getNumID());
+        assertEquals(BigInteger.valueOf(0), p.getNumIlvl());
+        // TODO Why isn't this seen as 10?
+        assertEquals(null, p.getNumStartOverride());
+        
+        // TODO Shouldn't we use XWPFNumbering or similar here?
+        // TODO Make it easier to change
+    }
 }
diff --git a/test-data/document/ComplexNumberedLists.docx b/test-data/document/ComplexNumberedLists.docx
new file mode 100644 (file)
index 0000000..b4409c9
Binary files /dev/null and b/test-data/document/ComplexNumberedLists.docx differ