poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r880799 - in /poi/trunk/src/ooxml: java/org/apache/poi/openxml4j/opc/ java/org/apache/poi/xssf/usermodel/ java/org/apache/poi/xwpf/usermodel/ testcases/org/apache/poi/openxml4j/opc/ testcases/org/apache/poi/xssf/usermodel/ testcases/org/apa...
Date Mon, 16 Nov 2009 15:33:46 GMT
Author: yegor
Date: Mon Nov 16 15:33:45 2009
New Revision: 880799

URL: http://svn.apache.org/viewvc?rev=880799&view=rev
Log:
removed log4j calls from ooxml tests, also fixed misc bugs discovered when imlementing OOXMLLite

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java?rev=880799&r1=880798&r2=880799&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java Mon Nov 16 15:33:45
2009
@@ -246,8 +246,7 @@
 			return new MemoryPackagePart(this, partName, contentType,
 					loadRelationships);
 		} catch (InvalidFormatException e) {
-			// TODO - don't use system.err.  Is it valid to return null when this exception occurs?
-			System.err.println(e);
+			logger.log(POILogger.WARN, e);
 			return null;
 		}
 	}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java?rev=880799&r1=880798&r2=880799&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java Mon Nov 16
15:33:45 2009
@@ -171,6 +171,7 @@
             for (int i = 0; i < str.getCTRst().sizeOfRArray(); i++) {
                 CTRElt lt = str.getCTRst().getRArray(i);
                 CTRPrElt ltPr = lt.getRPr();
+                if(ltPr == null) ltPr = lt.addNewRPr();
 
                 CTRegularTextRun r = p.addNewR();
                 CTTextCharacterProperties rPr = r.addNewRPr();

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java?rev=880799&r1=880798&r2=880799&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java Mon Nov 16 15:33:45
2009
@@ -62,9 +62,8 @@
      */
     public void setHeight(int height) {
         CTTrPr properties = getTrPr();
-        CTHeight h = properties.getTrHeightArray(0) == null ? properties.addNewTrHeight()
: properties.getTrHeightArray(0);
+        CTHeight h = properties.sizeOfTrHeightArray() == 0 ? properties.addNewTrHeight()
: properties.getTrHeightArray(0);
         h.setVal(new BigInteger("" + height));
-        //properties.setTrHeightArray(0,height);
     }
 
     /**
@@ -79,7 +78,7 @@
      */
     public int getHeight() {
         CTTrPr properties = getTrPr();
-        return properties.getTrHeightArray(0) == null ? 0 : properties.getTrHeightArray(0).getVal().intValue();
+        return properties.sizeOfTrHeightArray() == 0 ? 0 : properties.getTrHeightArray(0).getVal().intValue();
     }
 
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java?rev=880799&r1=880798&r2=880799&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestListParts.java Mon Nov
16 15:33:45 2009
@@ -23,12 +23,13 @@
 
 import junit.framework.TestCase;
 
-import org.apache.log4j.Logger;
 import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.POILogFactory;
 
 public final class TestListParts extends TestCase {
-	private static Logger logger = Logger.getLogger("org.apache.poi.openxml4j.test");
+    private static final POILogger logger = POILogFactory.getLogger(TestListParts.class);
 
 	private TreeMap<PackagePartName, String> expectedValues;
 
@@ -91,7 +92,7 @@
 		}
 		for (PackagePart part : p.getParts()) {
 			values.put(part.getPartName(), part.getContentType());
-			logger.debug(part.getPartName());
+			logger.log(POILogger.DEBUG, part.getPartName());
 		}
 
 		// Compare expected values with values return by the package

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java?rev=880799&r1=880798&r2=880799&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java Mon Nov 16
15:33:45 2009
@@ -30,12 +30,13 @@
 
 import junit.framework.TestCase;
 
-import org.apache.log4j.Logger;
 import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.opc.internal.ContentTypeManager;
 import org.apache.poi.openxml4j.opc.internal.FileHelper;
 import org.apache.poi.util.TempFile;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.POILogFactory;
 import org.dom4j.Document;
 import org.dom4j.DocumentHelper;
 import org.dom4j.Element;
@@ -44,7 +45,7 @@
 import org.dom4j.io.SAXReader;
 
 public final class TestPackage extends TestCase {
-	private static Logger logger = Logger.getLogger("org.apache.poi.openxml4j.test");
+    private static final POILogger logger = POILogFactory.getLogger(TestPackage.class);
 
 	/**
 	 * Test that just opening and closing the file doesn't alter the document.
@@ -393,7 +394,7 @@
 
 		for (PackagePart part : p.getParts()) {
 			values.put(part.getPartName(), part.getContentType());
-			logger.debug(part.getPartName());
+			logger.log(POILogger.DEBUG, part.getPartName());
 		}
 
 		// Compare expected values with values return by the package
@@ -431,7 +432,7 @@
 
 		for (PackagePart part : p.getParts()) {
 			values.put(part.getPartName(), part.getContentType());
-			logger.debug(part.getPartName());
+			logger.log(POILogger.DEBUG, part.getPartName());
 		}
 
 		// Compare expected values with values return by the package

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java?rev=880799&r1=880798&r2=880799&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackageCoreProperties.java
Mon Nov 16 15:33:45 2009
@@ -25,13 +25,15 @@
 
 import junit.framework.TestCase;
 
-import org.apache.log4j.Logger;
 import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.util.Nullable;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.POILogFactory;
 
 public final class TestPackageCoreProperties extends TestCase {
+    private static final POILogger logger = POILogFactory.getLogger(TestPackageCoreProperties.class);
 
 	/**
 	 * Test package core properties getters.
@@ -43,7 +45,7 @@
 			compareProperties(p);
 			p.revert();
 		} catch (OpenXML4JException e) {
-			Logger.getLogger("org.apache.poi.openxml4j.demo").debug(e.getMessage());
+			logger.log(POILogger.DEBUG, e.getMessage());
 			throw new RuntimeException(e);
 		} catch (IOException e) {
 			throw new RuntimeException(e);

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java?rev=880799&r1=880798&r2=880799&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java Mon
Nov 16 15:33:45 2009
@@ -21,8 +21,9 @@
 
 import junit.framework.TestCase;
 
-import org.apache.log4j.Logger;
 import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
+import org.apache.poi.util.POILogger;
+import org.apache.poi.util.POILogFactory;
 
 
 public class TestRelationships extends TestCase {
@@ -33,7 +34,7 @@
 	private static final String SHEET_WITH_COMMENTS =
 		"/xl/worksheets/sheet1.xml";
 
-	private static Logger logger = Logger.getLogger("org.apache.poi.openxml4j.test");
+    private static final POILogger logger = POILogFactory.getLogger(TestPackageCoreProperties.class);
 
     /**
      * Test relationships are correctly loaded. This at the moment fails (as of r499)
@@ -44,7 +45,7 @@
     public void testLoadRelationships() throws Exception {
         InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.xlsx");
         OPCPackage pkg = OPCPackage.open(is);
-        logger.debug("1: " + pkg);
+        logger.log(POILogger.DEBUG, "1: " + pkg);
         PackageRelationshipCollection rels = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
         PackageRelationship coreDocRelationship = rels.getRelationship(0);
         PackagePart corePart = pkg.getPart(coreDocRelationship);

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java?rev=880799&r1=880798&r2=880799&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java Mon Nov
16 15:33:45 2009
@@ -66,6 +66,25 @@
         assertTrue(sheet.getCTWorksheet().isSetDrawing());
         assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId());
 
+        XSSFClientAnchor anchor = new XSSFClientAnchor();
+
+        XSSFConnector c1= drawing.createConnector(anchor);
+        c1.setLineWidth(2.5);
+        c1.setLineStyle(1);
+
+        XSSFShapeGroup c2 = drawing.createGroup(anchor);
+
+        XSSFSimpleShape c3 = drawing.createSimpleShape(anchor);
+        c3.setText(new XSSFRichTextString("Test String"));
+        c3.setFillColor(128, 128, 128);
+
+        XSSFTextBox c4 = drawing.createTextbox(anchor);
+        XSSFRichTextString rt = new XSSFRichTextString("Test String");
+        rt.applyFont(0, 5, wb.createFont());
+        rt.applyFont(5, 6, wb.createFont());
+        c4.setText(rt);
+
+        c4.setNoFill(true);
     }
     public void testMultipleDrawings(){
         XSSFWorkbook wb = new XSSFWorkbook();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java?rev=880799&r1=880798&r2=880799&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java Mon Nov
16 15:33:45 2009
@@ -82,7 +82,7 @@
     }
 
     public void testShouldEnforceForFillingForms() throws Exception {
-        XWPFDocument document = createDocumentFromSampleFile("test-data/document/documentProtection_no_protection.docx");
+        XWPFDocument document = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection.docx");
         assertFalse(document.isEnforcedFillingFormsProtection());
 
         document.enforceFillingFormsProtection();
@@ -91,7 +91,7 @@
     }
 
     public void testShouldEnforceForComments() throws Exception {
-        XWPFDocument document = createDocumentFromSampleFile("test-data/document/documentProtection_no_protection.docx");
+        XWPFDocument document = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection.docx");
         assertFalse(document.isEnforcedCommentsProtection());
 
         document.enforceCommentsProtection();
@@ -100,7 +100,7 @@
     }
 
     public void testShouldEnforceForTrackedChanges() throws Exception {
-        XWPFDocument document = createDocumentFromSampleFile("test-data/document/documentProtection_no_protection.docx");
+        XWPFDocument document = XWPFTestDataSamples.openSampleDocument("documentProtection_no_protection.docx");
         assertFalse(document.isEnforcedTrackedChangesProtection());
 
         document.enforceTrackedChangesProtection();
@@ -109,7 +109,7 @@
     }
 
     public void testShouldUnsetEnforcement() throws Exception {
-        XWPFDocument document = createDocumentFromSampleFile("test-data/document/documentProtection_readonly_no_password.docx");
+        XWPFDocument document = XWPFTestDataSamples.openSampleDocument("documentProtection_readonly_no_password.docx");
         assertTrue(document.isEnforcedReadonlyProtection());
 
         document.removeProtectionEnforcement();
@@ -139,15 +139,4 @@
         assertTrue(document.isEnforcedCommentsProtection());
     }
 
-    private XWPFDocument createDocumentFromSampleFile(String fileName) throws FileNotFoundException,
IOException {
-        File file = new File(fileName);
-        FileInputStream in = new FileInputStream(file);
-        byte[] bytes = new byte[(int) file.length()];
-        in.read(bytes);
-
-        ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
-        XWPFDocument document = new XWPFDocument(inputStream);
-        return document;
-    }
-
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java?rev=880799&r1=880798&r2=880799&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeadings.java Mon
Nov 16 15:33:45 2009
@@ -1,19 +1,12 @@
 package org.apache.poi.xwpf.usermodel;
 
-import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.OutputStream;
 
 import junit.framework.TestCase;
 
-import org.apache.poi.util.TempFile;
 import org.apache.poi.xwpf.XWPFTestDataSamples;
 import org.apache.xmlbeans.XmlException;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STStyleType;
 
 /**
  * @author Paolo Mottadelli
@@ -35,7 +28,7 @@
 		assertEquals(HEADING1, p.getCTP().getPPr().getPStyle().getVal());
 
 		doc.createTOC();
-
+        /*
 		// TODO - finish this test
 		if (false) {
 			CTStyles styles = doc.getStyle();
@@ -50,5 +43,6 @@
 			doc.write(out);
 			out.close();
 		}
-	}
+        */
+    }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java?rev=880799&r1=880798&r2=880799&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java Mon Nov 16
15:33:45 2009
@@ -187,7 +187,7 @@
         run.setText("TEXT1");
         run.addBreak();
         run.setText("TEXT2");
-        run.addBreak();
+        run.addBreak(BreakType.TEXT_WRAPPING);
         assertEquals(2, run.getCTR().sizeOfBrArray());
     }
     

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java?rev=880799&r1=880798&r2=880799&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java Mon Nov
16 15:33:45 2009
@@ -33,85 +33,92 @@
 public class TestXWPFTable extends TestCase {
 
     protected void setUp() {
-	/*
-        XWPFDocument doc = new XWPFDocument();
-        p = doc.createParagraph();
+        /*
+          XWPFDocument doc = new XWPFDocument();
+          p = doc.createParagraph();
 
-        this.ctRun = CTR.Factory.newInstance();
-	 */
+          this.ctRun = CTR.Factory.newInstance();
+       */
     }
 
     public void testConstructor() {
-	CTTbl ctTable=CTTbl.Factory.newInstance();
-	XWPFTable xtab=new XWPFTable(null, ctTable);
-	assertNotNull(xtab);
-	assertEquals(1,ctTable.sizeOfTrArray());
-	assertEquals(1,ctTable.getTrArray(0).sizeOfTcArray());
-	assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
-	
-	ctTable=CTTbl.Factory.newInstance();
-	xtab=new XWPFTable(null, ctTable, 3,2);
-	assertNotNull(xtab);
-	assertEquals(3,ctTable.sizeOfTrArray());
-	assertEquals(2,ctTable.getTrArray(0).sizeOfTcArray());
-	assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
-    }        
-    
-    
-    public void testGetText(){
-	CTTbl table = CTTbl.Factory.newInstance();
-	CTRow row=table.addNewTr();
-	CTTc cell=row.addNewTc();
-	CTP paragraph=cell.addNewP();
-	CTR run=paragraph.addNewR();
-	CTText text=run.addNewT();
-	text.setStringValue("finally I can write!");
-	
-	XWPFTable xtab=new XWPFTable(null, table);
-    	assertEquals("finally I can write!\n",xtab.getText());
-    }
-    
-    
-    public void testCreateRow(){
-	CTTbl table = CTTbl.Factory.newInstance();
-	CTRow r1=table.addNewTr();
-	r1.addNewTc().addNewP();
-	r1.addNewTc().addNewP();
-	CTRow r2=table.addNewTr();
-	r2.addNewTc().addNewP();
-	r2.addNewTc().addNewP();
-	CTRow r3=table.addNewTr();
-	r3.addNewTc().addNewP();
-	r3.addNewTc().addNewP();
-	
-	XWPFTable xtab=new XWPFTable(null, table);
-    	assertEquals(3,xtab.getNumberOfRows());
-    	assertNotNull(xtab.getRow(2));
-    	
-    	//add a new row
-    	xtab.createRow();
-    	
-    	//check number of cols
-    	assertEquals(2,table.getTrArray(0).sizeOfTcArray());
-    	    	
-    	//check creation of first row
-	xtab=new XWPFTable(null, CTTbl.Factory.newInstance());
-    	assertEquals(1,xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
-    }
-    
-    
-    public void testSetGetWidth(){
-	CTTbl table = CTTbl.Factory.newInstance();
-	table.addNewTblPr().addNewTblW().setW(new BigInteger("1000"));
-	
-	XWPFTable xtab=new XWPFTable(null, table);
-	
-	assertEquals(1000,xtab.getWidth());
-	
-	xtab.setWidth(100);
-	assertEquals(100,table.getTblPr().getTblW().getW().intValue());
+        CTTbl ctTable = CTTbl.Factory.newInstance();
+        XWPFTable xtab = new XWPFTable(null, ctTable);
+        assertNotNull(xtab);
+        assertEquals(1, ctTable.sizeOfTrArray());
+        assertEquals(1, ctTable.getTrArray(0).sizeOfTcArray());
+        assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
+
+        ctTable = CTTbl.Factory.newInstance();
+        xtab = new XWPFTable(null, ctTable, 3, 2);
+        assertNotNull(xtab);
+        assertEquals(3, ctTable.sizeOfTrArray());
+        assertEquals(2, ctTable.getTrArray(0).sizeOfTcArray());
+        assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
+    }
+
+
+    public void testGetText() {
+        CTTbl table = CTTbl.Factory.newInstance();
+        CTRow row = table.addNewTr();
+        CTTc cell = row.addNewTc();
+        CTP paragraph = cell.addNewP();
+        CTR run = paragraph.addNewR();
+        CTText text = run.addNewT();
+        text.setStringValue("finally I can write!");
+
+        XWPFTable xtab = new XWPFTable(null, table);
+        assertEquals("finally I can write!\n", xtab.getText());
+    }
+
+
+    public void testCreateRow() {
+        CTTbl table = CTTbl.Factory.newInstance();
+        CTRow r1 = table.addNewTr();
+        r1.addNewTc().addNewP();
+        r1.addNewTc().addNewP();
+        CTRow r2 = table.addNewTr();
+        r2.addNewTc().addNewP();
+        r2.addNewTc().addNewP();
+        CTRow r3 = table.addNewTr();
+        r3.addNewTc().addNewP();
+        r3.addNewTc().addNewP();
+
+        XWPFTable xtab = new XWPFTable(null, table);
+        assertEquals(3, xtab.getNumberOfRows());
+        assertNotNull(xtab.getRow(2));
+
+        //add a new row
+        xtab.createRow();
+
+        //check number of cols
+        assertEquals(2, table.getTrArray(0).sizeOfTcArray());
+
+        //check creation of first row
+        xtab = new XWPFTable(null, CTTbl.Factory.newInstance());
+        assertEquals(1, xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
+    }
+
+
+    public void testSetGetWidth() {
+        CTTbl table = CTTbl.Factory.newInstance();
+        table.addNewTblPr().addNewTblW().setW(new BigInteger("1000"));
+
+        XWPFTable xtab = new XWPFTable(null, table);
+
+        assertEquals(1000, xtab.getWidth());
+
+        xtab.setWidth(100);
+        assertEquals(100, table.getTblPr().getTblW().getW().intValue());
+    }
+
+    public void testSetGetHeight() {
+        CTTbl table = CTTbl.Factory.newInstance();
+
+        XWPFTable xtab = new XWPFTable(null, table);
+        XWPFTableRow row = xtab.createRow();
+        row.setHeight(20);
+        assertEquals(20, row.getHeight());
     }
-    
-    
 
 }
\ No newline at end of file



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


Mime
View raw message