poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1691843 [24/30] - in /poi/branches/common_sl: ./ .settings/ legal/ osgi/ osgi/src/ src/examples/src/org/apache/poi/hpsf/examples/ src/examples/src/org/apache/poi/hssf/usermodel/examples/ src/examples/src/org/apache/poi/ss/examples/ src/exa...
Date Sun, 19 Jul 2015 19:00:38 GMT
Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java Sun Jul 19 19:00:32 2015
@@ -16,10 +16,12 @@
 ==================================================================== */
 package org.apache.poi.xwpf.usermodel;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.io.IOException;
 
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.xwpf.XWPFTestDataSamples;
 import org.apache.poi.xwpf.usermodel.XWPFRun.FontCharRange;
 import org.junit.Test;
@@ -28,14 +30,14 @@ public class TestXWPFBugs {
     @Test
     public void bug55802() throws Exception {
         String blabla =
-            "Bir, iki, \u00fc\u00e7, d\u00f6rt, be\u015f,\n"+
-            "\nalt\u0131, yedi, sekiz, dokuz, on.\n"+
-            "\nK\u0131rm\u0131z\u0131 don,\n"+
-            "\ngel bizim bah\u00e7eye kon,\n"+
-            "\nsar\u0131 limon";
+                "Bir, iki, \u00fc\u00e7, d\u00f6rt, be\u015f,\n" +
+                        "\nalt\u0131, yedi, sekiz, dokuz, on.\n" +
+                        "\nK\u0131rm\u0131z\u0131 don,\n" +
+                        "\ngel bizim bah\u00e7eye kon,\n" +
+                        "\nsar\u0131 limon";
         XWPFDocument doc = new XWPFDocument();
         XWPFRun run = doc.createParagraph().createRun();
-        
+
         for (String str : blabla.split("\n")) {
             run.setText(str);
             run.addBreak();
@@ -51,30 +53,52 @@ public class TestXWPFBugs {
         assertEquals(run.getFontFamily(FontCharRange.hAnsi), "Arial");
     }
 
-    
+
     @Test
     public void bug57312_NullPointException() throws IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("57312.docx");
         assertNotNull(doc);
-        
-        for( IBodyElement bodyElement : doc.getBodyElements()){
+
+        for (IBodyElement bodyElement : doc.getBodyElements()) {
             BodyElementType elementType = bodyElement.getElementType();
-            
-            if(elementType == BodyElementType.PARAGRAPH) {
+
+            if (elementType == BodyElementType.PARAGRAPH) {
                 XWPFParagraph paragraph = (XWPFParagraph) bodyElement;
-                
-                for (IRunElement iRunElem : paragraph.getIRuns()){
-                    
-                    if (iRunElem instanceof XWPFRun){   
+
+                for (IRunElement iRunElem : paragraph.getIRuns()) {
+
+                    if (iRunElem instanceof XWPFRun) {
                         XWPFRun runElement = (XWPFRun) iRunElem;
-                        
+
                         UnderlinePatterns underline = runElement.getUnderline();
                         assertNotNull(underline);
-                        
+
                         //System.out.println("Found: " + underline + ": " + runElement.getText(0));
                     }
                 }
-            } 
+            }
+        }
+    }
+
+
+    @Test
+    public void test56392() throws IOException, OpenXML4JException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("56392.docx");
+        assertNotNull(doc);
+    }
+
+    /**
+     * Removing a run needs to remove it from both Runs and IRuns
+     */
+    @Test
+    public void test57829() throws Exception {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
+        assertNotNull(doc);
+        assertEquals(3, doc.getParagraphs().size());
+
+        for (XWPFParagraph paragraph : doc.getParagraphs()) {
+            paragraph.removeRun(0);
+            assertNotNull(paragraph.getText());
         }
     }
 }

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java Sun Jul 19 19:00:32 2015
@@ -23,7 +23,6 @@ import java.util.Arrays;
 import java.util.List;
 
 import junit.framework.TestCase;
-
 import org.apache.poi.POIXMLDocumentPart;
 import org.apache.poi.POIXMLProperties;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -39,106 +38,105 @@ import org.openxmlformats.schemas.wordpr
 
 public final class TestXWPFDocument extends TestCase {
 
-	public void testContainsMainContentType() throws Exception {
-		XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
-		OPCPackage pack = doc.getPackage();
-
-		boolean found = false;
-		for(PackagePart part : pack.getParts()) {
-			if(part.getContentType().equals(XWPFRelation.DOCUMENT.getContentType())) {
-				found = true;
-			}
-			if (false) {
-				// successful tests should be silent
-				System.out.println(part);
-			}
-		}
-		assertTrue(found);
-	}
-
-	public void testOpen() throws Exception {
-		XWPFDocument xml;
-
-		// Simple file
-		xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
-		// Check it has key parts
-		assertNotNull(xml.getDocument());
-		assertNotNull(xml.getDocument().getBody());
-		assertNotNull(xml.getStyle());
-
-		// Complex file
-		xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
-		assertNotNull(xml.getDocument());
-		assertNotNull(xml.getDocument().getBody());
-		assertNotNull(xml.getStyle());
-	}
-
-	public void testMetadataBasics() throws IOException {
-		XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
-		assertNotNull(xml.getProperties().getCoreProperties());
-		assertNotNull(xml.getProperties().getExtendedProperties());
-
-		assertEquals("Microsoft Office Word", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
-		assertEquals(1315, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
-		assertEquals(10, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
-
-		assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
-		assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
-	}
-
-	public void testMetadataComplex() throws IOException {
-		XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
-		assertNotNull(xml.getProperties().getCoreProperties());
-		assertNotNull(xml.getProperties().getExtendedProperties());
-
-		assertEquals("Microsoft Office Outlook", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
-		assertEquals(5184, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
-		assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
-
-		assertEquals(" ", xml.getProperties().getCoreProperties().getTitle());
-		assertEquals(" ", xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
-	}
-
-	public void testWorkbookProperties() {
-		XWPFDocument doc = new XWPFDocument();
-		POIXMLProperties props = doc.getProperties();
-		assertNotNull(props);
-		assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
-	}
-	
-	public void testAddParagraph() throws IOException{
-	   XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
-	   assertEquals(3, doc.getParagraphs().size());
-
-	   XWPFParagraph p = doc.createParagraph();
-	   assertEquals(p, doc.getParagraphs().get(3));
-	   assertEquals(4, doc.getParagraphs().size());
-	   
-	   assertEquals(3, doc.getParagraphPos(3));
-      assertEquals(3, doc.getPosOfParagraph(p));
-
-	   CTP ctp = p.getCTP();
-	   XWPFParagraph newP = doc.getParagraph(ctp);
-	   assertSame(p, newP);
-	   XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor();
-	   XWPFParagraph cP = doc.insertNewParagraph(cursor);
-	   assertSame(cP, doc.getParagraphs().get(0));
-	   assertEquals(5, doc.getParagraphs().size());
-	}
+    public void testContainsMainContentType() throws Exception {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
+        OPCPackage pack = doc.getPackage();
+
+        boolean found = false;
+        for (PackagePart part : pack.getParts()) {
+            if (part.getContentType().equals(XWPFRelation.DOCUMENT.getContentType())) {
+                found = true;
+            }
+            if (false) {
+                // successful tests should be silent
+                System.out.println(part);
+            }
+        }
+        assertTrue(found);
+    }
+
+    public void testOpen() throws Exception {
+        XWPFDocument xml;
+
+        // Simple file
+        xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
+        // Check it has key parts
+        assertNotNull(xml.getDocument());
+        assertNotNull(xml.getDocument().getBody());
+        assertNotNull(xml.getStyle());
+
+        // Complex file
+        xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
+        assertNotNull(xml.getDocument());
+        assertNotNull(xml.getDocument().getBody());
+        assertNotNull(xml.getStyle());
+    }
+
+    public void testMetadataBasics() throws IOException {
+        XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("sample.docx");
+        assertNotNull(xml.getProperties().getCoreProperties());
+        assertNotNull(xml.getProperties().getExtendedProperties());
+
+        assertEquals("Microsoft Office Word", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
+        assertEquals(1315, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
+        assertEquals(10, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
+
+        assertEquals(null, xml.getProperties().getCoreProperties().getTitle());
+        assertEquals(null, xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
+    }
+
+    public void testMetadataComplex() throws IOException {
+        XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("IllustrativeCases.docx");
+        assertNotNull(xml.getProperties().getCoreProperties());
+        assertNotNull(xml.getProperties().getExtendedProperties());
+
+        assertEquals("Microsoft Office Outlook", xml.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication());
+        assertEquals(5184, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters());
+        assertEquals(0, xml.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
+
+        assertEquals(" ", xml.getProperties().getCoreProperties().getTitle());
+        assertEquals(" ", xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue());
+    }
 
-    public void testAddPicture() throws IOException, InvalidFormatException
-    {
+    public void testWorkbookProperties() {
+        XWPFDocument doc = new XWPFDocument();
+        POIXMLProperties props = doc.getProperties();
+        assertNotNull(props);
+        assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
+    }
+
+    public void testAddParagraph() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
+        assertEquals(3, doc.getParagraphs().size());
+
+        XWPFParagraph p = doc.createParagraph();
+        assertEquals(p, doc.getParagraphs().get(3));
+        assertEquals(4, doc.getParagraphs().size());
+
+        assertEquals(3, doc.getParagraphPos(3));
+        assertEquals(3, doc.getPosOfParagraph(p));
+
+        CTP ctp = p.getCTP();
+        XWPFParagraph newP = doc.getParagraph(ctp);
+        assertSame(p, newP);
+        XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor();
+        XWPFParagraph cP = doc.insertNewParagraph(cursor);
+        assertSame(cP, doc.getParagraphs().get(0));
+        assertEquals(5, doc.getParagraphs().size());
+    }
+
+    public void testAddPicture() throws IOException, InvalidFormatException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
         byte[] jpeg = XWPFTestDataSamples.getImage("nature1.jpg");
-        String relationId = doc.addPictureData(jpeg,XWPFDocument.PICTURE_TYPE_JPEG);
-        
+        String relationId = doc.addPictureData(jpeg, XWPFDocument.PICTURE_TYPE_JPEG);
+
         byte[] newJpeg = ((XWPFPictureData) doc.getRelationById(relationId)).getData();
-        assertEquals(newJpeg.length,jpeg.length);
-        for (int i = 0 ; i < jpeg.length ; i++)
-        {
-            assertEquals(newJpeg[i],jpeg[i]);
+        assertEquals(newJpeg.length, jpeg.length);
+        for (int i = 0; i < jpeg.length; i++) {
+            assertEquals(newJpeg[i], jpeg[i]);
         }
     }
+
     public void testAllPictureFormats() throws IOException, InvalidFormatException {
         XWPFDocument doc = new XWPFDocument();
 
@@ -161,184 +159,200 @@ public final class TestXWPFDocument exte
 
     }
 
-	public void testRemoveBodyElement() throws IOException {
-	   XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
-	   assertEquals(3, doc.getParagraphs().size());
-      assertEquals(3, doc.getBodyElements().size());
-      
-      XWPFParagraph p1 = doc.getParagraphs().get(0);
-      XWPFParagraph p2 = doc.getParagraphs().get(1);
-      XWPFParagraph p3 = doc.getParagraphs().get(2);
-      
-      assertEquals(p1, doc.getBodyElements().get(0));
-      assertEquals(p1, doc.getParagraphs().get(0));
-      assertEquals(p2, doc.getBodyElements().get(1));
-      assertEquals(p2, doc.getParagraphs().get(1));
-      assertEquals(p3, doc.getBodyElements().get(2));
-      assertEquals(p3, doc.getParagraphs().get(2));
-      
-      // Add another
-      XWPFParagraph p4 = doc.createParagraph();
-      
-      assertEquals(4, doc.getParagraphs().size());
-      assertEquals(4, doc.getBodyElements().size());
-      assertEquals(p1, doc.getBodyElements().get(0));
-      assertEquals(p1, doc.getParagraphs().get(0));
-      assertEquals(p2, doc.getBodyElements().get(1));
-      assertEquals(p2, doc.getParagraphs().get(1));
-      assertEquals(p3, doc.getBodyElements().get(2));
-      assertEquals(p3, doc.getParagraphs().get(2));
-      assertEquals(p4, doc.getBodyElements().get(3));
-      assertEquals(p4, doc.getParagraphs().get(3));
-      
-      // Remove the 2nd
-      assertEquals(true, doc.removeBodyElement(1));
-      assertEquals(3, doc.getParagraphs().size());
-      assertEquals(3, doc.getBodyElements().size());
-      
-      assertEquals(p1, doc.getBodyElements().get(0));
-      assertEquals(p1, doc.getParagraphs().get(0));
-      assertEquals(p3, doc.getBodyElements().get(1));
-      assertEquals(p3, doc.getParagraphs().get(1));
-      assertEquals(p4, doc.getBodyElements().get(2));
-      assertEquals(p4, doc.getParagraphs().get(2));
-      
-      // Remove the 1st
-      assertEquals(true, doc.removeBodyElement(0));
-      assertEquals(2, doc.getParagraphs().size());
-      assertEquals(2, doc.getBodyElements().size());
-      
-      assertEquals(p3, doc.getBodyElements().get(0));
-      assertEquals(p3, doc.getParagraphs().get(0));
-      assertEquals(p4, doc.getBodyElements().get(1));
-      assertEquals(p4, doc.getParagraphs().get(1));
-      
-      // Remove the last
-      assertEquals(true, doc.removeBodyElement(1));
-      assertEquals(1, doc.getParagraphs().size());
-      assertEquals(1, doc.getBodyElements().size());
-      
-      assertEquals(p3, doc.getBodyElements().get(0));
-      assertEquals(p3, doc.getParagraphs().get(0));
-	}
-	
-	public void testRegisterPackagePictureData() throws IOException, InvalidFormatException {
-	    XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
-	    
-	    /* manually assemble a new image package part*/
-	    OPCPackage opcPckg = doc.getPackage();
-	    XWPFRelation jpgRelation = XWPFRelation.IMAGE_JPEG;
-	    PackagePartName partName = PackagingURIHelper.createPartName(jpgRelation.getDefaultFileName().replace('#', '2'));
+    public void testRemoveBodyElement() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
+        assertEquals(3, doc.getParagraphs().size());
+        assertEquals(3, doc.getBodyElements().size());
+
+        XWPFParagraph p1 = doc.getParagraphs().get(0);
+        XWPFParagraph p2 = doc.getParagraphs().get(1);
+        XWPFParagraph p3 = doc.getParagraphs().get(2);
+
+        assertEquals(p1, doc.getBodyElements().get(0));
+        assertEquals(p1, doc.getParagraphs().get(0));
+        assertEquals(p2, doc.getBodyElements().get(1));
+        assertEquals(p2, doc.getParagraphs().get(1));
+        assertEquals(p3, doc.getBodyElements().get(2));
+        assertEquals(p3, doc.getParagraphs().get(2));
+
+        // Add another
+        XWPFParagraph p4 = doc.createParagraph();
+
+        assertEquals(4, doc.getParagraphs().size());
+        assertEquals(4, doc.getBodyElements().size());
+        assertEquals(p1, doc.getBodyElements().get(0));
+        assertEquals(p1, doc.getParagraphs().get(0));
+        assertEquals(p2, doc.getBodyElements().get(1));
+        assertEquals(p2, doc.getParagraphs().get(1));
+        assertEquals(p3, doc.getBodyElements().get(2));
+        assertEquals(p3, doc.getParagraphs().get(2));
+        assertEquals(p4, doc.getBodyElements().get(3));
+        assertEquals(p4, doc.getParagraphs().get(3));
+
+        // Remove the 2nd
+        assertEquals(true, doc.removeBodyElement(1));
+        assertEquals(3, doc.getParagraphs().size());
+        assertEquals(3, doc.getBodyElements().size());
+
+        assertEquals(p1, doc.getBodyElements().get(0));
+        assertEquals(p1, doc.getParagraphs().get(0));
+        assertEquals(p3, doc.getBodyElements().get(1));
+        assertEquals(p3, doc.getParagraphs().get(1));
+        assertEquals(p4, doc.getBodyElements().get(2));
+        assertEquals(p4, doc.getParagraphs().get(2));
+
+        // Remove the 1st
+        assertEquals(true, doc.removeBodyElement(0));
+        assertEquals(2, doc.getParagraphs().size());
+        assertEquals(2, doc.getBodyElements().size());
+
+        assertEquals(p3, doc.getBodyElements().get(0));
+        assertEquals(p3, doc.getParagraphs().get(0));
+        assertEquals(p4, doc.getBodyElements().get(1));
+        assertEquals(p4, doc.getParagraphs().get(1));
+
+        // Remove the last
+        assertEquals(true, doc.removeBodyElement(1));
+        assertEquals(1, doc.getParagraphs().size());
+        assertEquals(1, doc.getBodyElements().size());
+
+        assertEquals(p3, doc.getBodyElements().get(0));
+        assertEquals(p3, doc.getParagraphs().get(0));
+    }
+
+    public void testRegisterPackagePictureData() throws IOException, InvalidFormatException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
+
+        /* manually assemble a new image package part*/
+        OPCPackage opcPckg = doc.getPackage();
+        XWPFRelation jpgRelation = XWPFRelation.IMAGE_JPEG;
+        PackagePartName partName = PackagingURIHelper.createPartName(jpgRelation.getDefaultFileName().replace('#', '2'));
         PackagePart newImagePart = opcPckg.createPart(partName, jpgRelation.getContentType());
         byte[] nature1 = XWPFTestDataSamples.getImage("abstract4.jpg");
         OutputStream os = newImagePart.getOutputStream();
         os.write(nature1);
-	    os.close();
-	    XWPFHeader xwpfHeader = doc.getHeaderArray(0);
-	    PackageRelationship relationship = xwpfHeader.getPackagePart().addRelationship(partName, TargetMode.INTERNAL, jpgRelation.getRelation());
-	    XWPFPictureData newPicData = new XWPFPictureData(newImagePart,relationship);
-	    /* new part is now ready to rumble */
-	    
-	    assertFalse(xwpfHeader.getAllPictures().contains(newPicData));
-	    assertFalse(doc.getAllPictures().contains(newPicData));
-	    assertFalse(doc.getAllPackagePictures().contains(newPicData));
-
-	    doc.registerPackagePictureData(newPicData);
-	    
-	    assertFalse(xwpfHeader.getAllPictures().contains(newPicData));
-	    assertFalse(doc.getAllPictures().contains(newPicData));
-	    assertTrue(doc.getAllPackagePictures().contains(newPicData));
-	    
-	    doc.getPackage().revert();
-	}
-
-	public void testFindPackagePictureData() throws IOException {
-	    XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
-	    byte[] nature1 = XWPFTestDataSamples.getImage("nature1.gif");
-	    XWPFPictureData part = doc.findPackagePictureData(nature1, Document.PICTURE_TYPE_GIF);
-	    assertNotNull(part);
-	    assertTrue(doc.getAllPictures().contains(part));
-	    assertTrue(doc.getAllPackagePictures().contains(part));
-	    doc.getPackage().revert();
-	}
-	
-	public void testGetAllPictures() throws IOException {
-	    XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
-	    List<XWPFPictureData> allPictures = doc.getAllPictures();
-	    List<XWPFPictureData> allPackagePictures = doc.getAllPackagePictures();
-	    
-	    assertNotNull(allPictures);
-	    assertEquals(3,allPictures.size());
-	    for (XWPFPictureData xwpfPictureData : allPictures) {
-	        assertTrue(allPackagePictures.contains(xwpfPictureData));
+        os.close();
+        XWPFHeader xwpfHeader = doc.getHeaderArray(0);
+        PackageRelationship relationship = xwpfHeader.getPackagePart().addRelationship(partName, TargetMode.INTERNAL, jpgRelation.getRelation());
+        XWPFPictureData newPicData = new XWPFPictureData(newImagePart, relationship);
+        /* new part is now ready to rumble */
+
+        assertFalse(xwpfHeader.getAllPictures().contains(newPicData));
+        assertFalse(doc.getAllPictures().contains(newPicData));
+        assertFalse(doc.getAllPackagePictures().contains(newPicData));
+
+        doc.registerPackagePictureData(newPicData);
+
+        assertFalse(xwpfHeader.getAllPictures().contains(newPicData));
+        assertFalse(doc.getAllPictures().contains(newPicData));
+        assertTrue(doc.getAllPackagePictures().contains(newPicData));
+
+        doc.getPackage().revert();
+    }
+
+    public void testFindPackagePictureData() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
+        byte[] nature1 = XWPFTestDataSamples.getImage("nature1.gif");
+        XWPFPictureData part = doc.findPackagePictureData(nature1, Document.PICTURE_TYPE_GIF);
+        assertNotNull(part);
+        assertTrue(doc.getAllPictures().contains(part));
+        assertTrue(doc.getAllPackagePictures().contains(part));
+        doc.getPackage().revert();
+    }
+
+    public void testGetAllPictures() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
+        List<XWPFPictureData> allPictures = doc.getAllPictures();
+        List<XWPFPictureData> allPackagePictures = doc.getAllPackagePictures();
+
+        assertNotNull(allPictures);
+        assertEquals(3, allPictures.size());
+        for (XWPFPictureData xwpfPictureData : allPictures) {
+            assertTrue(allPackagePictures.contains(xwpfPictureData));
         }
 
-	    try {
+        try {
             allPictures.add(allPictures.get(0));
             fail("This list must be unmodifiable!");
         } catch (UnsupportedOperationException e) {
             // all ok
         }
-	    
-	    doc.getPackage().revert();
-	}
-
-	public void testGetAllPackagePictures() throws IOException {
-	       XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
-	        List<XWPFPictureData> allPackagePictures = doc.getAllPackagePictures();
-	        
-	        assertNotNull(allPackagePictures);
-	        assertEquals(5,allPackagePictures.size());
-
-	        try {
-	            allPackagePictures.add(allPackagePictures.get(0));
-	            fail("This list must be unmodifiable!");
-	        } catch (UnsupportedOperationException e) {
-	            // all ok
-	        }
-	        
-	        doc.getPackage().revert();
-	}
-	
-	public void testPictureHandlingSimpleFile() throws IOException, InvalidFormatException {
-	    XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
-	    assertEquals(1,doc.getAllPackagePictures().size());
-	    byte[] newPic = XWPFTestDataSamples.getImage("abstract4.jpg");
-	    String id1 = doc.addPictureData(newPic, Document.PICTURE_TYPE_JPEG);
-	    assertEquals(2,doc.getAllPackagePictures().size());
-	    /* copy data, to avoid instance-equality */
-	    byte[] newPicCopy = Arrays.copyOf(newPic, newPic.length);
-	    String id2 = doc.addPictureData(newPicCopy, Document.PICTURE_TYPE_JPEG);
-	    assertEquals(id1,id2);
-	    doc.getPackage().revert();
-	}
-	
-	public void testPictureHandlingHeaderDocumentImages() throws IOException {
-	    XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_2.docx");
-	    assertEquals(1,doc.getAllPictures().size());
-	    assertEquals(1,doc.getAllPackagePictures().size());
-	    assertEquals(1,doc.getHeaderArray(0).getAllPictures().size());
-	    doc.getPackage().revert();
-	}
-	
-	public void testPictureHandlingComplex() throws IOException, InvalidFormatException {
-	    XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
-	    XWPFHeader xwpfHeader = doc.getHeaderArray(0);
-
-	    assertEquals(3,doc.getAllPictures().size());
-        assertEquals(3,xwpfHeader.getAllPictures().size());
-	    assertEquals(5,doc.getAllPackagePictures().size());
-	    
-	    byte[] nature1 = XWPFTestDataSamples.getImage("nature1.jpg");
-	    String id = doc.addPictureData(nature1, Document.PICTURE_TYPE_JPEG);
-	    POIXMLDocumentPart part1 = xwpfHeader.getRelationById("rId1");
-	    XWPFPictureData part2 = (XWPFPictureData) doc.getRelationById(id);
-	    assertSame(part1,part2);
-	    
-	    doc.getPackage().revert();
-	}
 
-    public void testSettings(){
+        doc.getPackage().revert();
+    }
+
+    public void testGetAllPackagePictures() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
+        List<XWPFPictureData> allPackagePictures = doc.getAllPackagePictures();
+
+        assertNotNull(allPackagePictures);
+        assertEquals(5, allPackagePictures.size());
+
+        try {
+            allPackagePictures.add(allPackagePictures.get(0));
+            fail("This list must be unmodifiable!");
+        } catch (UnsupportedOperationException e) {
+            // all ok
+        }
+
+        doc.getPackage().revert();
+    }
+
+    public void testPictureHandlingSimpleFile() throws IOException, InvalidFormatException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_1.docx");
+        assertEquals(1, doc.getAllPackagePictures().size());
+        byte[] newPic = XWPFTestDataSamples.getImage("abstract4.jpg");
+        String id1 = doc.addPictureData(newPic, Document.PICTURE_TYPE_JPEG);
+        assertEquals(2, doc.getAllPackagePictures().size());
+        /* copy data, to avoid instance-equality */
+        byte[] newPicCopy = Arrays.copyOf(newPic, newPic.length);
+        String id2 = doc.addPictureData(newPicCopy, Document.PICTURE_TYPE_JPEG);
+        assertEquals(id1, id2);
+        doc.getPackage().revert();
+    }
+
+    public void testPictureHandlingHeaderDocumentImages() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_2.docx");
+        assertEquals(1, doc.getAllPictures().size());
+        assertEquals(1, doc.getAllPackagePictures().size());
+        assertEquals(1, doc.getHeaderArray(0).getAllPictures().size());
+        doc.getPackage().revert();
+    }
+
+    public void testPictureHandlingComplex() throws IOException, InvalidFormatException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("issue_51265_3.docx");
+        XWPFHeader xwpfHeader = doc.getHeaderArray(0);
+
+        assertEquals(3, doc.getAllPictures().size());
+        assertEquals(3, xwpfHeader.getAllPictures().size());
+        assertEquals(5, doc.getAllPackagePictures().size());
+
+        byte[] nature1 = XWPFTestDataSamples.getImage("nature1.jpg");
+        String id = doc.addPictureData(nature1, Document.PICTURE_TYPE_JPEG);
+        POIXMLDocumentPart part1 = xwpfHeader.getRelationById("rId1");
+        XWPFPictureData part2 = (XWPFPictureData) doc.getRelationById(id);
+        assertSame(part1, part2);
+
+        doc.getPackage().revert();
+    }
+
+    public void testZeroLengthLibreOfficeDocumentWithWaterMarkHeader() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("zero-length.docx");
+        POIXMLProperties properties = doc.getProperties();
+
+        assertNotNull(properties.getCoreProperties());
+
+        XWPFHeader headerArray = doc.getHeaderArray(0);
+        assertEquals(1, headerArray.getAllPictures().size());
+        assertEquals("image1.png", headerArray.pictures.get(0).getFileName());
+        assertEquals("", headerArray.getText());
+
+        POIXMLProperties.ExtendedProperties extendedProperties = properties.getExtendedProperties();
+        assertNotNull(extendedProperties);
+        assertEquals(0, extendedProperties.getUnderlyingProperties().getCharacters());
+    }
+
+    public void testSettings() {
         XWPFSettings settings = new XWPFSettings();
         settings.setZoomPercent(50);
         assertEquals(50, settings.getZoomPercent());

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFFootnotes.java Sun Jul 19 19:00:32 2015
@@ -19,52 +19,50 @@ package org.apache.poi.xwpf.usermodel;
 
 import java.io.IOException;
 import java.math.BigInteger;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.xwpf.XWPFTestDataSamples;
-
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFtnEdn;
-
-public class TestXWPFFootnotes extends TestCase {
-
-	public void testAddFootnotesToDocument() throws IOException{
-		XWPFDocument docOut = new XWPFDocument();
-
-		BigInteger noteId = BigInteger.valueOf(1);
-
-		XWPFFootnotes footnotes = docOut.createFootnotes();
-		CTFtnEdn ctNote = CTFtnEdn.Factory.newInstance();
-		ctNote.setId(noteId);
-		ctNote.setType(STFtnEdn.NORMAL);
-		footnotes.addFootnote(ctNote);
-
-		XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut);
-
-		XWPFFootnote note = docIn.getFootnoteByID(noteId.intValue());
-		assertEquals(note.getCTFtnEdn().getType(), STFtnEdn.NORMAL);
-	}
-
-   /**
-    * Bug 55066 - avoid double loading the footnotes
-    */
-	public void testLoadFootnotesOnce() throws IOException{
-		XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx");
-		List<XWPFFootnote> footnotes = doc.getFootnotes();
-		int hits = 0;
-		for (XWPFFootnote fn : footnotes){
-			for (IBodyElement e : fn.getBodyElements()){
-				if (e instanceof XWPFParagraph){
-					String txt = ((XWPFParagraph)e).getText();
-					if (txt.indexOf("Footnote_sdt") > -1){
-						hits++;
-					}
-				}
-			}
-		}
-		assertEquals("Load footnotes once", 1, hits);
-	}
-}
-
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STFtnEdn;
+
+public class TestXWPFFootnotes extends TestCase {
+
+    public void testAddFootnotesToDocument() throws IOException {
+        XWPFDocument docOut = new XWPFDocument();
+
+        BigInteger noteId = BigInteger.valueOf(1);
+
+        XWPFFootnotes footnotes = docOut.createFootnotes();
+        CTFtnEdn ctNote = CTFtnEdn.Factory.newInstance();
+        ctNote.setId(noteId);
+        ctNote.setType(STFtnEdn.NORMAL);
+        footnotes.addFootnote(ctNote);
+
+        XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut);
+
+        XWPFFootnote note = docIn.getFootnoteByID(noteId.intValue());
+        assertEquals(note.getCTFtnEdn().getType(), STFtnEdn.NORMAL);
+    }
+
+    /**
+     * Bug 55066 - avoid double loading the footnotes
+     */
+    public void testLoadFootnotesOnce() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx");
+        List<XWPFFootnote> footnotes = doc.getFootnotes();
+        int hits = 0;
+        for (XWPFFootnote fn : footnotes) {
+            for (IBodyElement e : fn.getBodyElements()) {
+                if (e instanceof XWPFParagraph) {
+                    String txt = ((XWPFParagraph) e).getText();
+                    if (txt.indexOf("Footnote_sdt") > -1) {
+                        hits++;
+                    }
+                }
+            }
+        }
+        assertEquals("Load footnotes once", 1, hits);
+    }
+}
+

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java Sun Jul 19 19:00:32 2015
@@ -17,13 +17,12 @@
 
 package org.apache.poi.xwpf.usermodel;
 
-import java.io.IOException;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.xwpf.XWPFTestDataSamples;
-import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
 
@@ -159,25 +158,25 @@ public final class TestXWPFHeader extend
         assertEquals("First paragraph for the footer", paras[0].getText());
         assertEquals("Second paragraph for the footer", paras[1].getText());
     }
-
-    public void testSetWatermark() throws IOException {
-        XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
-        
-        // No header is set (yet)
-        XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
-        assertNull(policy.getDefaultHeader());
+
+    public void testSetWatermark() throws IOException {
+        XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
+
+        // No header is set (yet)
+        XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
+        assertNull(policy.getDefaultHeader());
         assertNull(policy.getFirstPageHeader());
         assertNull(policy.getDefaultFooter());
 
         policy.createWatermark("DRAFT");
 
-        assertNotNull(policy.getDefaultHeader());
-        assertNotNull(policy.getFirstPageHeader());
-        assertNotNull(policy.getEvenPageHeader());
-        
-        // Re-open, and check
-        XWPFDocument reopened = XWPFTestDataSamples.writeOutAndReadBack(sampleDoc);
-        policy = reopened.getHeaderFooterPolicy();
+        assertNotNull(policy.getDefaultHeader());
+        assertNotNull(policy.getFirstPageHeader());
+        assertNotNull(policy.getEvenPageHeader());
+
+        // Re-open, and check
+        XWPFDocument reopened = XWPFTestDataSamples.writeOutAndReadBack(sampleDoc);
+        policy = reopened.getHeaderFooterPolicy();
 
         assertNotNull(policy.getDefaultHeader());
         assertNotNull(policy.getFirstPageHeader());

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java Sun Jul 19 19:00:32 2015
@@ -16,39 +16,38 @@
 ==================================================================== */
 package org.apache.poi.xwpf.usermodel;
 
-import java.io.IOException;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.xwpf.XWPFTestDataSamples;
-import org.apache.xmlbeans.XmlException;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
-
-/**
- * @author Paolo Mottadelli
- */
-public final class TestXWPFHeadings extends TestCase{
-	private static final String HEADING1 = "Heading1";
-
-	public void testSetParagraphStyle() throws IOException, XmlException {
-		//new clean instance of paragraph
-		XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("heading123.docx");
-		XWPFParagraph p = doc.createParagraph();
-		XWPFRun run = p.createRun();
-		run.setText("Heading 1");
-
-		CTSdtBlock block = doc.getDocument().getBody().addNewSdt();
-
-		assertNull(p.getStyle());
-		p.setStyle(HEADING1);
-		assertEquals(HEADING1, p.getCTP().getPPr().getPStyle().getVal());
-
-		doc.createTOC();
-        /*
-		// TODO - finish this test
-		if (false) {
-			CTStyles styles = doc.getStyle();
-			CTStyle style = styles.addNewStyle();
+import java.io.IOException;
+
+import junit.framework.TestCase;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.apache.xmlbeans.XmlException;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
+
+/**
+ * @author Paolo Mottadelli
+ */
+public final class TestXWPFHeadings extends TestCase {
+    private static final String HEADING1 = "Heading1";
+
+    public void testSetParagraphStyle() throws IOException, XmlException {
+        //new clean instance of paragraph
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("heading123.docx");
+        XWPFParagraph p = doc.createParagraph();
+        XWPFRun run = p.createRun();
+        run.setText("Heading 1");
+
+        CTSdtBlock block = doc.getDocument().getBody().addNewSdt();
+
+        assertNull(p.getStyle());
+        p.setStyle(HEADING1);
+        assertEquals(HEADING1, p.getCTP().getPPr().getPStyle().getVal());
+
+        doc.createTOC();
+        /*
+        // TODO - finish this test
+		if (false) {
+			CTStyles styles = doc.getStyle();
+			CTStyle style = styles.addNewStyle();
 			style.setType(STStyleType.PARAGRAPH);
 			style.setStyleId("Heading1");
 		}

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java Sun Jul 19 19:00:32 2015
@@ -18,60 +18,85 @@
 package org.apache.poi.xwpf.usermodel;
 
 import java.io.IOException;
-import java.math.BigInteger;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.xwpf.XWPFTestDataSamples;
-
-public class TestXWPFNumbering extends TestCase {
-	
-	public void testCompareAbstractNum() throws IOException{
-		XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx");
-		XWPFNumbering numbering = doc.getNumbering();
-		BigInteger numId = BigInteger.valueOf(1);
-		assertTrue(numbering.numExist(numId));
-		XWPFNum num = numbering.getNum(numId);
-		BigInteger abstrNumId = num.getCTNum().getAbstractNumId().getVal();
-		XWPFAbstractNum abstractNum = numbering.getAbstractNum(abstrNumId);
-		BigInteger compareAbstractNum = numbering.getIdOfAbstractNum(abstractNum);
-		assertEquals(abstrNumId, compareAbstractNum);
-	}
-
-	public void testAddNumberingToDoc() throws IOException{
-		BigInteger abstractNumId = BigInteger.valueOf(1);
-		BigInteger numId = BigInteger.valueOf(1);
-
-		XWPFDocument docOut = new XWPFDocument();
-		XWPFNumbering numbering = docOut.createNumbering();
-		numId = numbering.addNum(abstractNumId);
-		
-		XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut);
-
-		numbering = docIn.getNumbering();
-		assertTrue(numbering.numExist(numId));
-		XWPFNum num = numbering.getNum(numId);
-
-		BigInteger compareAbstractNum = num.getCTNum().getAbstractNumId().getVal();
-		assertEquals(abstractNumId, compareAbstractNum);
-	}
-
-	public void testGetNumIlvl() throws IOException{
-		XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx");
-		BigInteger numIlvl = BigInteger.valueOf(0);
-		assertEquals(numIlvl, doc.getParagraphs().get(0).getNumIlvl());
-		numIlvl = BigInteger.valueOf(1);
-      assertEquals(numIlvl, doc.getParagraphs().get(5).getNumIlvl());
-	}
-
-	public void testGetNumFmt() throws IOException{
-		XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx");
-		assertEquals("bullet", doc.getParagraphs().get(0).getNumFmt());
-		assertEquals("bullet", doc.getParagraphs().get(1).getNumFmt());
-		assertEquals("bullet", doc.getParagraphs().get(2).getNumFmt());
-		assertEquals("bullet", doc.getParagraphs().get(3).getNumFmt());
-		assertEquals("decimal", doc.getParagraphs().get(4).getNumFmt());
-		assertEquals("lowerLetter", doc.getParagraphs().get(5).getNumFmt());
-		assertEquals("lowerRoman", doc.getParagraphs().get(6).getNumFmt());
-  }
-}
+import java.math.BigInteger;
+
+import junit.framework.TestCase;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumLvl;
+
+public class TestXWPFNumbering extends TestCase {
+
+    public void testCompareAbstractNum() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx");
+        XWPFNumbering numbering = doc.getNumbering();
+        BigInteger numId = BigInteger.valueOf(1);
+        assertTrue(numbering.numExist(numId));
+        XWPFNum num = numbering.getNum(numId);
+        BigInteger abstrNumId = num.getCTNum().getAbstractNumId().getVal();
+        XWPFAbstractNum abstractNum = numbering.getAbstractNum(abstrNumId);
+        BigInteger compareAbstractNum = numbering.getIdOfAbstractNum(abstractNum);
+        assertEquals(abstrNumId, compareAbstractNum);
+    }
+
+    public void testAddNumberingToDoc() throws IOException {
+        BigInteger abstractNumId = BigInteger.valueOf(1);
+        BigInteger numId = BigInteger.valueOf(1);
+
+        XWPFDocument docOut = new XWPFDocument();
+        XWPFNumbering numbering = docOut.createNumbering();
+        numId = numbering.addNum(abstractNumId);
+
+        XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut);
+
+        numbering = docIn.getNumbering();
+        assertTrue(numbering.numExist(numId));
+        XWPFNum num = numbering.getNum(numId);
+
+        BigInteger compareAbstractNum = num.getCTNum().getAbstractNumId().getVal();
+        assertEquals(abstractNumId, compareAbstractNum);
+    }
+
+    public void testGetNumIlvl() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx");
+        BigInteger numIlvl = BigInteger.valueOf(0);
+        assertEquals(numIlvl, doc.getParagraphs().get(0).getNumIlvl());
+        numIlvl = BigInteger.valueOf(1);
+        assertEquals(numIlvl, doc.getParagraphs().get(5).getNumIlvl());
+    }
+
+    public void testGetNumFmt() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx");
+        assertEquals("bullet", doc.getParagraphs().get(0).getNumFmt());
+        assertEquals("bullet", doc.getParagraphs().get(1).getNumFmt());
+        assertEquals("bullet", doc.getParagraphs().get(2).getNumFmt());
+        assertEquals("bullet", doc.getParagraphs().get(3).getNumFmt());
+        assertEquals("decimal", doc.getParagraphs().get(4).getNumFmt());
+        assertEquals("lowerLetter", doc.getParagraphs().get(5).getNumFmt());
+        assertEquals("lowerRoman", doc.getParagraphs().get(6).getNumFmt());
+    }
+
+    public void testLvlText() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx");
+
+        assertEquals("%1.%2.%3.", doc.getParagraphs().get(12).getNumLevelText());
+
+        assertEquals("NEW-%1-FORMAT", doc.getParagraphs().get(14).getNumLevelText());
+
+        XWPFParagraph p = doc.getParagraphs().get(18);
+        assertEquals("%1.", p.getNumLevelText());
+        //test that null doesn't throw NPE
+        assertNull(p.getNumFmt());
+    }
+
+    public void testOverrideList() throws IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("NumberingWOverrides.docx");
+        XWPFParagraph p = doc.getParagraphs().get(4);
+        XWPFNumbering numbering = doc.getNumbering();
+        CTNum ctNum = numbering.getNum(p.getNumID()).getCTNum();
+        assertEquals(9, ctNum.sizeOfLvlOverrideArray());
+        CTNumLvl ctNumLvl = ctNum.getLvlOverrideArray(0);
+        assertEquals("upperLetter", ctNumLvl.getLvl().getNumFmt().getVal().toString());
+    }
+
+}

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java Sun Jul 19 19:00:32 2015
@@ -22,12 +22,26 @@ import java.math.BigInteger;
 import java.util.List;
 
 import junit.framework.TestCase;
-
 import org.apache.poi.xwpf.XWPFTestDataSamples;
 import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
 import org.openxmlformats.schemas.drawingml.x2006.picture.PicDocument;
 import org.openxmlformats.schemas.drawingml.x2006.picture.impl.PicDocumentImpl;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPBdr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextAlignment;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
 
 /**
  * Tests for XWPF Paragraphs
@@ -36,7 +50,8 @@ public final class TestXWPFParagraph ext
 
     /**
      * Check that we get the right paragraph from the header
-     * @throws IOException 
+     *
+     * @throws IOException
      */
     public void disabled_testHeaderParagraph() throws IOException {
         XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
@@ -44,7 +59,7 @@ public final class TestXWPFParagraph ext
         XWPFHeader hdr = xml.getHeaderFooterPolicy().getDefaultHeader();
         assertNotNull(hdr);
 
-       List<XWPFParagraph> ps =  hdr.getParagraphs();
+        List<XWPFParagraph> ps = hdr.getParagraphs();
         assertEquals(1, ps.size());
         XWPFParagraph p = ps.get(0);
 
@@ -55,7 +70,8 @@ public final class TestXWPFParagraph ext
 
     /**
      * Check that we get the right paragraphs from the document
-     * @throws IOException 
+     *
+     * @throws IOException
      */
     public void disabled_testDocumentParagraph() throws IOException {
         XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("ThreeColHead.docx");
@@ -88,7 +104,7 @@ public final class TestXWPFParagraph ext
         assertEquals(STBorder.NONE.intValue(), p.getBorderTop().getValue());
 
         CTP ctp = p.getCTP();
-        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
+        CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
 
         //bordi
         CTPBdr bdr = ppr.addNewPBdr();
@@ -109,7 +125,7 @@ public final class TestXWPFParagraph ext
         assertEquals(STJc.LEFT.intValue(), p.getAlignment().getValue());
 
         CTP ctp = p.getCTP();
-        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
+        CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
 
         CTJc align = ppr.addNewJc();
         align.setVal(STJc.CENTER);
@@ -125,7 +141,7 @@ public final class TestXWPFParagraph ext
         XWPFParagraph p = doc.createParagraph();
 
         CTP ctp = p.getCTP();
-        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
+        CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
 
         assertEquals(-1, p.getSpacingAfter());
 
@@ -142,7 +158,7 @@ public final class TestXWPFParagraph ext
         XWPFParagraph p = doc.createParagraph();
 
         CTP ctp = p.getCTP();
-        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
+        CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
 
         assertEquals(STLineSpacingRule.INT_AUTO, p.getSpacingLineRule().getValue());
 
@@ -161,7 +177,7 @@ public final class TestXWPFParagraph ext
         assertEquals(-1, p.getIndentationLeft());
 
         CTP ctp = p.getCTP();
-        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
+        CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
 
         assertEquals(-1, p.getIndentationLeft());
 
@@ -179,7 +195,7 @@ public final class TestXWPFParagraph ext
         XWPFParagraph p = doc.createParagraph();
 
         CTP ctp = p.getCTP();
-        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
+        CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
 
         CTTextAlignment txtAlign = ppr.addNewTextAlignment();
         txtAlign.setVal(STTextAlignment.CENTER);
@@ -194,7 +210,7 @@ public final class TestXWPFParagraph ext
         XWPFParagraph p = doc.createParagraph();
 
         CTP ctp = p.getCTP();
-        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
+        CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
 
         CTOnOff wordWrap = ppr.addNewWordWrap();
         wordWrap.setVal(STOnOff.FALSE);
@@ -210,7 +226,7 @@ public final class TestXWPFParagraph ext
         XWPFParagraph p = doc.createParagraph();
 
         CTP ctp = p.getCTP();
-        CTPPr ppr = ctp.getPPr()== null? ctp.addNewPPr() : ctp.getPPr();
+        CTPPr ppr = ctp.getPPr() == null ? ctp.addNewPPr() : ctp.getPPr();
 
         CTOnOff pageBreak = ppr.addNewPageBreakBefore();
         pageBreak.setVal(STOnOff.FALSE);
@@ -229,8 +245,8 @@ public final class TestXWPFParagraph ext
         assertEquals(0, paragraph.getCTP().sizeOfBookmarkEndArray());
         CTBookmark ctBookmark = paragraph.getCTP().getBookmarkStartArray(0);
         assertEquals("poi", ctBookmark.getName());
-        for(CTBookmark bookmark : paragraph.getCTP().getBookmarkStartArray()) {
-           assertEquals("poi", bookmark.getName());
+        for (CTBookmark bookmark : paragraph.getCTP().getBookmarkStartArray()) {
+            assertEquals("poi", bookmark.getName());
         }
     }
 
@@ -241,108 +257,108 @@ public final class TestXWPFParagraph ext
         p.setNumID(new BigInteger("10"));
         assertEquals("10", p.getNumID().toString());
     }
-    
+
     public void testAddingRuns() throws Exception {
-       XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
-     
-       XWPFParagraph p = doc.getParagraphs().get(0);
-       assertEquals(2, p.getRuns().size());
-       
-       XWPFRun r = p.createRun();
-       assertEquals(3, p.getRuns().size());
-       assertEquals(2, p.getRuns().indexOf(r));
-       
-       XWPFRun r2 = p.insertNewRun(1);
-       assertEquals(4, p.getRuns().size());
-       assertEquals(1, p.getRuns().indexOf(r2));
-       assertEquals(3, p.getRuns().indexOf(r));
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
+
+        XWPFParagraph p = doc.getParagraphs().get(0);
+        assertEquals(2, p.getRuns().size());
+
+        XWPFRun r = p.createRun();
+        assertEquals(3, p.getRuns().size());
+        assertEquals(2, p.getRuns().indexOf(r));
+
+        XWPFRun r2 = p.insertNewRun(1);
+        assertEquals(4, p.getRuns().size());
+        assertEquals(1, p.getRuns().indexOf(r2));
+        assertEquals(3, p.getRuns().indexOf(r));
     }
-    
+
     public void testPictures() throws Exception {
-       XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx");
-       assertEquals(7, doc.getParagraphs().size());
-       
-       XWPFParagraph p;
-       XWPFRun r;
-
-       // Text paragraphs
-       assertEquals("Sheet with various pictures", doc.getParagraphs().get(0).getText());
-       assertEquals("(jpeg, png, wmf, emf and pict) ", doc.getParagraphs().get(1).getText());
-       
-       // Spacer ones
-       assertEquals("", doc.getParagraphs().get(2).getText());
-       assertEquals("", doc.getParagraphs().get(3).getText());
-       assertEquals("", doc.getParagraphs().get(4).getText());
-       
-       // Image one
-       p = doc.getParagraphs().get(5);
-       assertEquals(6, p.getRuns().size());
-
-       r = p.getRuns().get(0);
-       assertEquals("", r.toString());
-       assertEquals(1, r.getEmbeddedPictures().size());
-       assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
-       assertEquals("image1.wmf", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
-
-       r = p.getRuns().get(1);
-       assertEquals("", r.toString());
-       assertEquals(1, r.getEmbeddedPictures().size());
-       assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
-       assertEquals("image2.png", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
-
-       r = p.getRuns().get(2);
-       assertEquals("", r.toString());
-       assertEquals(1, r.getEmbeddedPictures().size());
-       assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
-       assertEquals("image3.emf", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
-
-       r = p.getRuns().get(3);
-       assertEquals("", r.toString());
-       assertEquals(1, r.getEmbeddedPictures().size());
-       assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
-       assertEquals("image4.emf", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
-
-       r = p.getRuns().get(4);
-       assertEquals("", r.toString());
-       assertEquals(1, r.getEmbeddedPictures().size());
-       assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
-       assertEquals("image5.jpeg", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
-       
-       r = p.getRuns().get(5);
-       assertEquals(" ", r.toString());
-       assertEquals(0, r.getEmbeddedPictures().size());
-       
-       // Final spacer
-       assertEquals("", doc.getParagraphs().get(6).getText());
-       
-       
-       // Look in detail at one
-       r = p.getRuns().get(4);
-       XWPFPicture pict = r.getEmbeddedPictures().get(0);
-       CTPicture picture = pict.getCTPicture();
-       assertEquals("rId8", picture.getBlipFill().getBlip().getEmbed());
-       
-       // Ensure that the ooxml compiler finds everything we need
-       r.getCTR().getDrawingArray(0);
-       r.getCTR().getDrawingArray(0).getInlineArray(0);
-       r.getCTR().getDrawingArray(0).getInlineArray(0).getGraphic();
-       r.getCTR().getDrawingArray(0).getInlineArray(0).getGraphic().getGraphicData();
-       PicDocument pd = new PicDocumentImpl(null);
-       assertTrue(pd.isNil());
-    }
-    
-    public void testTika792() throws Exception{
-       //This test forces the loading of CTMoveBookmark and
-       //CTMoveBookmarkImpl into ooxml-lite.
-       XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Tika-792.docx");
-       XWPFParagraph paragraph = doc.getParagraphs().get(0);
-       assertEquals("s", paragraph.getText());
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx");
+        assertEquals(7, doc.getParagraphs().size());
+
+        XWPFParagraph p;
+        XWPFRun r;
+
+        // Text paragraphs
+        assertEquals("Sheet with various pictures", doc.getParagraphs().get(0).getText());
+        assertEquals("(jpeg, png, wmf, emf and pict) ", doc.getParagraphs().get(1).getText());
+
+        // Spacer ones
+        assertEquals("", doc.getParagraphs().get(2).getText());
+        assertEquals("", doc.getParagraphs().get(3).getText());
+        assertEquals("", doc.getParagraphs().get(4).getText());
+
+        // Image one
+        p = doc.getParagraphs().get(5);
+        assertEquals(6, p.getRuns().size());
+
+        r = p.getRuns().get(0);
+        assertEquals("", r.toString());
+        assertEquals(1, r.getEmbeddedPictures().size());
+        assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+        assertEquals("image1.wmf", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+        r = p.getRuns().get(1);
+        assertEquals("", r.toString());
+        assertEquals(1, r.getEmbeddedPictures().size());
+        assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+        assertEquals("image2.png", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+        r = p.getRuns().get(2);
+        assertEquals("", r.toString());
+        assertEquals(1, r.getEmbeddedPictures().size());
+        assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+        assertEquals("image3.emf", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+        r = p.getRuns().get(3);
+        assertEquals("", r.toString());
+        assertEquals(1, r.getEmbeddedPictures().size());
+        assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+        assertEquals("image4.emf", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+        r = p.getRuns().get(4);
+        assertEquals("", r.toString());
+        assertEquals(1, r.getEmbeddedPictures().size());
+        assertNotNull(r.getEmbeddedPictures().get(0).getPictureData());
+        assertEquals("image5.jpeg", r.getEmbeddedPictures().get(0).getPictureData().getFileName());
+
+        r = p.getRuns().get(5);
+        assertEquals(" ", r.toString());
+        assertEquals(0, r.getEmbeddedPictures().size());
+
+        // Final spacer
+        assertEquals("", doc.getParagraphs().get(6).getText());
+
+
+        // Look in detail at one
+        r = p.getRuns().get(4);
+        XWPFPicture pict = r.getEmbeddedPictures().get(0);
+        CTPicture picture = pict.getCTPicture();
+        assertEquals("rId8", picture.getBlipFill().getBlip().getEmbed());
+
+        // Ensure that the ooxml compiler finds everything we need
+        r.getCTR().getDrawingArray(0);
+        r.getCTR().getDrawingArray(0).getInlineArray(0);
+        r.getCTR().getDrawingArray(0).getInlineArray(0).getGraphic();
+        r.getCTR().getDrawingArray(0).getInlineArray(0).getGraphic().getGraphicData();
+        PicDocument pd = new PicDocumentImpl(null);
+        assertTrue(pd.isNil());
+    }
+
+    public void testTika792() throws Exception {
+        //This test forces the loading of CTMoveBookmark and
+        //CTMoveBookmarkImpl into ooxml-lite.
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Tika-792.docx");
+        XWPFParagraph paragraph = doc.getParagraphs().get(0);
+        assertEquals("s", paragraph.getText());
     }
 
     public void testSettersGetters() {
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
-        
+
         assertTrue(p.isEmpty());
         assertFalse(p.removeRun(0));
 
@@ -355,7 +371,7 @@ public final class TestXWPFParagraph ext
         assertFalse(p.isEmpty());
         assertNull(p.getStyleID());
         assertNull(p.getStyle());
-        
+
         assertNull(p.getNumID());
         p.setNumID(BigInteger.valueOf(12));
         assertEquals(BigInteger.valueOf(12), p.getNumID());
@@ -363,18 +379,18 @@ public final class TestXWPFParagraph ext
         assertEquals(BigInteger.valueOf(13), p.getNumID());
 
         assertNull(p.getNumFmt());
-        
+
         assertNull(p.getNumIlvl());
-        
+
         assertEquals("", p.getParagraphText());
         assertEquals("", p.getPictureText());
         assertEquals("", p.getFootnoteText());
-        
+
         p.setBorderBetween(Borders.NONE);
         assertEquals(Borders.NONE, p.getBorderBetween());
         p.setBorderBetween(Borders.BASIC_BLACK_DASHES);
         assertEquals(Borders.BASIC_BLACK_DASHES, p.getBorderBetween());
-        
+
         p.setBorderBottom(Borders.NONE);
         assertEquals(Borders.NONE, p.getBorderBottom());
         p.setBorderBottom(Borders.BABY_RATTLE);
@@ -394,37 +410,37 @@ public final class TestXWPFParagraph ext
         assertEquals(Borders.NONE, p.getBorderBottom());
         p.setBorderBottom(Borders.BASIC_WHITE_DOTS);
         assertEquals(Borders.BASIC_WHITE_DOTS, p.getBorderBottom());
-        
+
         assertFalse(p.isPageBreak());
         p.setPageBreak(true);
         assertTrue(p.isPageBreak());
         p.setPageBreak(false);
         assertFalse(p.isPageBreak());
-        
+
         assertEquals(-1, p.getSpacingAfter());
         p.setSpacingAfter(12);
         assertEquals(12, p.getSpacingAfter());
-        
+
         assertEquals(-1, p.getSpacingAfterLines());
         p.setSpacingAfterLines(14);
         assertEquals(14, p.getSpacingAfterLines());
-        
+
         assertEquals(-1, p.getSpacingBefore());
         p.setSpacingBefore(16);
         assertEquals(16, p.getSpacingBefore());
-        
+
         assertEquals(-1, p.getSpacingBeforeLines());
         p.setSpacingBeforeLines(18);
         assertEquals(18, p.getSpacingBeforeLines());
-        
+
         assertEquals(LineSpacingRule.AUTO, p.getSpacingLineRule());
         p.setSpacingLineRule(LineSpacingRule.EXACT);
         assertEquals(LineSpacingRule.EXACT, p.getSpacingLineRule());
-        
+
         assertEquals(-1, p.getIndentationLeft());
         p.setIndentationLeft(21);
         assertEquals(21, p.getIndentationLeft());
-        
+
         assertEquals(-1, p.getIndentationRight());
         p.setIndentationRight(25);
         assertEquals(25, p.getIndentationRight());
@@ -442,20 +458,20 @@ public final class TestXWPFParagraph ext
         assertTrue(p.isWordWrap());
         p.setWordWrap(false);
         assertFalse(p.isWordWrap());
-        
+
         assertNull(p.getStyle());
         p.setStyle("teststyle");
         assertEquals("teststyle", p.getStyle());
-        
+
         p.addRun(CTR.Factory.newInstance());
-        
+
         //assertTrue(p.removeRun(0));
-        
+
         assertNotNull(p.getBody());
         assertEquals(BodyElementType.PARAGRAPH, p.getElementType());
         assertEquals(BodyType.DOCUMENT, p.getPartType());
     }
-    
+
     public void testSearchTextNotFound() {
         XWPFDocument doc = new XWPFDocument();
         XWPFParagraph p = doc.createParagraph();
@@ -469,17 +485,17 @@ public final class TestXWPFParagraph ext
 
         List<XWPFParagraph> ps = xml.getParagraphs();
         assertEquals(10, ps.size());
-        
+
         XWPFParagraph p = ps.get(0);
 
         TextSegement segment = p.searchText("sample word document", new PositionInParagraph());
         assertNotNull(segment);
-        
+
         assertEquals("sample word document", p.getText(segment));
-        
+
         assertTrue(p.removeRun(0));
     }
-    
+
     @SuppressWarnings("deprecation")
     public void testRuns() {
         XWPFDocument doc = new XWPFDocument();
@@ -489,7 +505,7 @@ public final class TestXWPFParagraph ext
         XWPFRun r = new XWPFRun(run, doc.createParagraph());
         p.addRun(r);
         p.addRun(r);
-        
+
         assertNotNull(p.getRun(run));
         assertNull(p.getRun(null));
     }

Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java Sun Jul 19 19:00:32 2015
@@ -20,138 +20,129 @@ package org.apache.poi.xwpf.usermodel;
 import static org.junit.Assert.assertArrayEquals;
 
 import java.io.IOException;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
-import org.apache.poi.openxml4j.opc.PackageRelationship;
-import org.apache.poi.xssf.usermodel.XSSFRelation;
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.xssf.usermodel.XSSFRelation;
 import org.apache.poi.xwpf.XWPFTestDataSamples;
-import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
-
-public class TestXWPFPictureData extends TestCase {
-    
-    public void testRead() throws InvalidFormatException, IOException
-    {
-        XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx");
-        List<XWPFPictureData> pictures = sampleDoc.getAllPictures();
-
-        assertEquals(5,pictures.size());
-        String[] ext = {"wmf","png","emf","emf","jpeg"};
-        for (int i = 0 ; i < pictures.size() ; i++)
-        {
-            assertEquals(ext[i],pictures.get(i).suggestFileExtension());
-        }
-
-        int num = pictures.size();
-
-        byte[] pictureData = XWPFTestDataSamples.getImage("nature1.jpg");
-
-        String relationId = sampleDoc.addPictureData(pictureData,XWPFDocument.PICTURE_TYPE_JPEG);
-        // picture list was updated
-        assertEquals(num + 1,pictures.size());
-        XWPFPictureData pict = (XWPFPictureData) sampleDoc.getRelationById(relationId);
-        assertEquals("jpeg",pict.suggestFileExtension());
-        assertArrayEquals(pictureData,pict.getData());
-    }
-
-    public void testPictureInHeader() throws IOException
-    {
-        XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx");
-        verifyOneHeaderPicture(sampleDoc);
-        
-        XWPFDocument readBack = XWPFTestDataSamples.writeOutAndReadBack(sampleDoc);
-        verifyOneHeaderPicture(readBack);
-    }
+import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
+
+public class TestXWPFPictureData extends TestCase {
+
+    public void testRead() throws InvalidFormatException, IOException {
+        XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx");
+        List<XWPFPictureData> pictures = sampleDoc.getAllPictures();
+
+        assertEquals(5, pictures.size());
+        String[] ext = {"wmf", "png", "emf", "emf", "jpeg"};
+        for (int i = 0; i < pictures.size(); i++) {
+            assertEquals(ext[i], pictures.get(i).suggestFileExtension());
+        }
+
+        int num = pictures.size();
+
+        byte[] pictureData = XWPFTestDataSamples.getImage("nature1.jpg");
+
+        String relationId = sampleDoc.addPictureData(pictureData, XWPFDocument.PICTURE_TYPE_JPEG);
+        // picture list was updated
+        assertEquals(num + 1, pictures.size());
+        XWPFPictureData pict = (XWPFPictureData) sampleDoc.getRelationById(relationId);
+        assertEquals("jpeg", pict.suggestFileExtension());
+        assertArrayEquals(pictureData, pict.getData());
+    }
+
+    public void testPictureInHeader() throws IOException {
+        XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx");
+        verifyOneHeaderPicture(sampleDoc);
+
+        XWPFDocument readBack = XWPFTestDataSamples.writeOutAndReadBack(sampleDoc);
+        verifyOneHeaderPicture(readBack);
+    }
 
     private void verifyOneHeaderPicture(XWPFDocument sampleDoc) {
         XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
 
-        XWPFHeader header = policy.getDefaultHeader();
-
-        List<XWPFPictureData> pictures = header.getAllPictures();
-        assertEquals(1,pictures.size());
-    }
-
-    public void testNew() throws InvalidFormatException, IOException 
-    {
-        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("EmptyDocumentWithHeaderFooter.docx");
-        byte[] jpegData = XWPFTestDataSamples.getImage("nature1.jpg");
-        assertNotNull(jpegData);
+        XWPFHeader header = policy.getDefaultHeader();
+
+        List<XWPFPictureData> pictures = header.getAllPictures();
+        assertEquals(1, pictures.size());
+    }
+
+    public void testNew() throws InvalidFormatException, IOException {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("EmptyDocumentWithHeaderFooter.docx");
+        byte[] jpegData = XWPFTestDataSamples.getImage("nature1.jpg");
+        assertNotNull(jpegData);
         byte[] gifData = XWPFTestDataSamples.getImage("nature1.gif");
         assertNotNull(gifData);
         byte[] pngData = XWPFTestDataSamples.getImage("nature1.png");
-        assertNotNull(pngData);
-
-        List<XWPFPictureData> pictures = doc.getAllPictures();
-        assertEquals(0,pictures.size());
-
-        // Document shouldn't have any image relationships
-        assertEquals(13,doc.getPackagePart().getRelationships().size());
-        for (PackageRelationship rel : doc.getPackagePart().getRelationships())
-        {
-            if (rel.getRelationshipType().equals(XSSFRelation.IMAGE_JPEG.getRelation()))
-            {
-                fail("Shouldn't have JPEG yet");
-            }
-        }
-
-        // Add the image
-        String relationId = doc.addPictureData(jpegData,XWPFDocument.PICTURE_TYPE_JPEG);
-        assertEquals(1,pictures.size());
-        XWPFPictureData jpgPicData = (XWPFPictureData) doc.getRelationById(relationId);
-        assertEquals("jpeg",jpgPicData.suggestFileExtension());
-        assertArrayEquals(jpegData,jpgPicData.getData());
-
-        // Ensure it now has one
-        assertEquals(14,doc.getPackagePart().getRelationships().size());
-        PackageRelationship jpegRel = null;
-        for (PackageRelationship rel : doc.getPackagePart().getRelationships())
-        {
-            if (rel.getRelationshipType().equals(XWPFRelation.IMAGE_JPEG.getRelation()))
-            {
-                if (jpegRel != null)
-                    fail("Found 2 jpegs!");
-                jpegRel = rel;
-            }
-        }
-        assertNotNull("JPEG Relationship not found",jpegRel);
-
-        // Check the details
-        assertNotNull(jpegRel);
-        assertEquals(XWPFRelation.IMAGE_JPEG.getRelation(),jpegRel.getRelationshipType());
-        assertEquals("/word/document.xml",jpegRel.getSource().getPartName().toString());
-        assertEquals("/word/media/image1.jpeg",jpegRel.getTargetURI().getPath());
-
-        XWPFPictureData pictureDataByID = doc.getPictureDataByID(jpegRel.getId());
-        assertArrayEquals(jpegData, pictureDataByID.getData());
-
-        // Save an re-load, check it appears
-        doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
-        assertEquals(1,doc.getAllPictures().size());
-        assertEquals(1,doc.getAllPackagePictures().size());
-
-        // verify the picture that we read back in
-        pictureDataByID = doc.getPictureDataByID(jpegRel.getId());
-        assertArrayEquals(jpegData, pictureDataByID.getData());
-        
-    }
-
-    public void testBug51770() throws InvalidFormatException, IOException {
+        assertNotNull(pngData);
+
+        List<XWPFPictureData> pictures = doc.getAllPictures();
+        assertEquals(0, pictures.size());
+
+        // Document shouldn't have any image relationships
+        assertEquals(13, doc.getPackagePart().getRelationships().size());
+        for (PackageRelationship rel : doc.getPackagePart().getRelationships()) {
+            if (rel.getRelationshipType().equals(XSSFRelation.IMAGE_JPEG.getRelation())) {
+                fail("Shouldn't have JPEG yet");
+            }
+        }
+
+        // Add the image
+        String relationId = doc.addPictureData(jpegData, XWPFDocument.PICTURE_TYPE_JPEG);
+        assertEquals(1, pictures.size());
+        XWPFPictureData jpgPicData = (XWPFPictureData) doc.getRelationById(relationId);
+        assertEquals("jpeg", jpgPicData.suggestFileExtension());
+        assertArrayEquals(jpegData, jpgPicData.getData());
+
+        // Ensure it now has one
+        assertEquals(14, doc.getPackagePart().getRelationships().size());
+        PackageRelationship jpegRel = null;
+        for (PackageRelationship rel : doc.getPackagePart().getRelationships()) {
+            if (rel.getRelationshipType().equals(XWPFRelation.IMAGE_JPEG.getRelation())) {
+                if (jpegRel != null)
+                    fail("Found 2 jpegs!");
+                jpegRel = rel;
+            }
+        }
+        assertNotNull("JPEG Relationship not found", jpegRel);
+
+        // Check the details
+        assertNotNull(jpegRel);
+        assertEquals(XWPFRelation.IMAGE_JPEG.getRelation(), jpegRel.getRelationshipType());
+        assertEquals("/word/document.xml", jpegRel.getSource().getPartName().toString());
+        assertEquals("/word/media/image1.jpeg", jpegRel.getTargetURI().getPath());
+
+        XWPFPictureData pictureDataByID = doc.getPictureDataByID(jpegRel.getId());
+        assertArrayEquals(jpegData, pictureDataByID.getData());
+
+        // Save an re-load, check it appears
+        doc = XWPFTestDataSamples.writeOutAndReadBack(doc);
+        assertEquals(1, doc.getAllPictures().size());
+        assertEquals(1, doc.getAllPackagePictures().size());
+
+        // verify the picture that we read back in
+        pictureDataByID = doc.getPictureDataByID(jpegRel.getId());
+        assertArrayEquals(jpegData, pictureDataByID.getData());
+
+    }
+
+    public void testBug51770() throws InvalidFormatException, IOException {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug51170.docx");
         XWPFHeaderFooterPolicy policy = doc.getHeaderFooterPolicy();
         XWPFHeader header = policy.getDefaultHeader();
         for (XWPFParagraph paragraph : header.getParagraphs()) {
             for (XWPFRun run : paragraph.getRuns()) {
                 for (XWPFPicture picture : run.getEmbeddedPictures()) {
-                    if (paragraph.getDocument() != null) {
-                        //System.out.println(picture.getCTPicture());
-                        XWPFPictureData data = picture.getPictureData();
-                        if(data != null) System.out.println(data.getFileName());
-                    }
-                }
-            }
+                    if (paragraph.getDocument() != null) {
+                        //System.out.println(picture.getCTPicture());
+                        XWPFPictureData data = picture.getPictureData();
+                        if (data != null) System.out.println(data.getFileName());
+                    }
+                }
+            }
         }
 
     }



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


Mime
View raw message