removed log4j calls from ooxml tests, also fixed misc bugs discovered when imlementing OOXMLLite

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@880799 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2009-11-16 15:33:45 +00:00
parent aead99342f
commit a584c030ff
12 changed files with 128 additions and 115 deletions

View File

@ -246,8 +246,7 @@ public final class ZipPackage extends Package {
return new MemoryPackagePart(this, partName, contentType, return new MemoryPackagePart(this, partName, contentType,
loadRelationships); loadRelationships);
} catch (InvalidFormatException e) { } catch (InvalidFormatException e) {
// TODO - don't use system.err. Is it valid to return null when this exception occurs? logger.log(POILogger.WARN, e);
System.err.println(e);
return null; return null;
} }
} }

View File

@ -171,6 +171,7 @@ public class XSSFSimpleShape extends XSSFShape { // TODO - instantiable supercla
for (int i = 0; i < str.getCTRst().sizeOfRArray(); i++) { for (int i = 0; i < str.getCTRst().sizeOfRArray(); i++) {
CTRElt lt = str.getCTRst().getRArray(i); CTRElt lt = str.getCTRst().getRArray(i);
CTRPrElt ltPr = lt.getRPr(); CTRPrElt ltPr = lt.getRPr();
if(ltPr == null) ltPr = lt.addNewRPr();
CTRegularTextRun r = p.addNewR(); CTRegularTextRun r = p.addNewR();
CTTextCharacterProperties rPr = r.addNewRPr(); CTTextCharacterProperties rPr = r.addNewRPr();

View File

@ -62,9 +62,8 @@ public class XWPFTableRow {
*/ */
public void setHeight(int height) { public void setHeight(int height) {
CTTrPr properties = getTrPr(); 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)); h.setVal(new BigInteger("" + height));
//properties.setTrHeightArray(0,height);
} }
/** /**
@ -79,7 +78,7 @@ public class XWPFTableRow {
*/ */
public int getHeight() { public int getHeight() {
CTTrPr properties = getTrPr(); CTTrPr properties = getTrPr();
return properties.getTrHeightArray(0) == null ? 0 : properties.getTrHeightArray(0).getVal().intValue(); return properties.sizeOfTrHeightArray() == 0 ? 0 : properties.getTrHeightArray(0).getVal().intValue();
} }

View File

@ -23,12 +23,13 @@ import java.util.TreeMap;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.log4j.Logger;
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; 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 { 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; private TreeMap<PackagePartName, String> expectedValues;
@ -91,7 +92,7 @@ public final class TestListParts extends TestCase {
} }
for (PackagePart part : p.getParts()) { for (PackagePart part : p.getParts()) {
values.put(part.getPartName(), part.getContentType()); 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 // Compare expected values with values return by the package

View File

@ -30,12 +30,13 @@ import java.util.Iterator;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.log4j.Logger;
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.internal.ContentTypeManager; import org.apache.poi.openxml4j.opc.internal.ContentTypeManager;
import org.apache.poi.openxml4j.opc.internal.FileHelper; import org.apache.poi.openxml4j.opc.internal.FileHelper;
import org.apache.poi.util.TempFile; 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.Document;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
@ -44,7 +45,7 @@ import org.dom4j.QName;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
public final class TestPackage extends TestCase { 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. * Test that just opening and closing the file doesn't alter the document.
@ -393,7 +394,7 @@ public final class TestPackage extends TestCase {
for (PackagePart part : p.getParts()) { for (PackagePart part : p.getParts()) {
values.put(part.getPartName(), part.getContentType()); 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 // Compare expected values with values return by the package
@ -431,7 +432,7 @@ public final class TestPackage extends TestCase {
for (PackagePart part : p.getParts()) { for (PackagePart part : p.getParts()) {
values.put(part.getPartName(), part.getContentType()); 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 // Compare expected values with values return by the package

View File

@ -25,13 +25,15 @@ import java.util.Date;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.log4j.Logger;
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.util.Nullable; 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 { public final class TestPackageCoreProperties extends TestCase {
private static final POILogger logger = POILogFactory.getLogger(TestPackageCoreProperties.class);
/** /**
* Test package core properties getters. * Test package core properties getters.
@ -43,7 +45,7 @@ public final class TestPackageCoreProperties extends TestCase {
compareProperties(p); compareProperties(p);
p.revert(); p.revert();
} catch (OpenXML4JException e) { } catch (OpenXML4JException e) {
Logger.getLogger("org.apache.poi.openxml4j.demo").debug(e.getMessage()); logger.log(POILogger.DEBUG, e.getMessage());
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);

View File

@ -21,8 +21,9 @@ import java.io.*;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.log4j.Logger;
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.POILogFactory;
public class TestRelationships extends TestCase { public class TestRelationships extends TestCase {
@ -33,7 +34,7 @@ public class TestRelationships extends TestCase {
private static final String SHEET_WITH_COMMENTS = private static final String SHEET_WITH_COMMENTS =
"/xl/worksheets/sheet1.xml"; "/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) * Test relationships are correctly loaded. This at the moment fails (as of r499)
@ -44,7 +45,7 @@ public class TestRelationships extends TestCase {
public void testLoadRelationships() throws Exception { public void testLoadRelationships() throws Exception {
InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.xlsx"); InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.xlsx");
OPCPackage pkg = OPCPackage.open(is); OPCPackage pkg = OPCPackage.open(is);
logger.debug("1: " + pkg); logger.log(POILogger.DEBUG, "1: " + pkg);
PackageRelationshipCollection rels = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT); PackageRelationshipCollection rels = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
PackageRelationship coreDocRelationship = rels.getRelationship(0); PackageRelationship coreDocRelationship = rels.getRelationship(0);
PackagePart corePart = pkg.getPart(coreDocRelationship); PackagePart corePart = pkg.getPart(coreDocRelationship);

View File

@ -66,6 +66,25 @@ public class TestXSSFDrawing extends TestCase {
assertTrue(sheet.getCTWorksheet().isSetDrawing()); assertTrue(sheet.getCTWorksheet().isSetDrawing());
assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId()); 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(){ public void testMultipleDrawings(){
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();

View File

@ -82,7 +82,7 @@ public class TestDocumentProtection extends TestCase {
} }
public void testShouldEnforceForFillingForms() throws Exception { 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()); assertFalse(document.isEnforcedFillingFormsProtection());
document.enforceFillingFormsProtection(); document.enforceFillingFormsProtection();
@ -91,7 +91,7 @@ public class TestDocumentProtection extends TestCase {
} }
public void testShouldEnforceForComments() throws Exception { 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()); assertFalse(document.isEnforcedCommentsProtection());
document.enforceCommentsProtection(); document.enforceCommentsProtection();
@ -100,7 +100,7 @@ public class TestDocumentProtection extends TestCase {
} }
public void testShouldEnforceForTrackedChanges() throws Exception { 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()); assertFalse(document.isEnforcedTrackedChangesProtection());
document.enforceTrackedChangesProtection(); document.enforceTrackedChangesProtection();
@ -109,7 +109,7 @@ public class TestDocumentProtection extends TestCase {
} }
public void testShouldUnsetEnforcement() throws Exception { 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()); assertTrue(document.isEnforcedReadonlyProtection());
document.removeProtectionEnforcement(); document.removeProtectionEnforcement();
@ -139,15 +139,4 @@ public class TestDocumentProtection extends TestCase {
assertTrue(document.isEnforcedCommentsProtection()); 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;
}
} }

View File

@ -1,19 +1,12 @@
package org.apache.poi.xwpf.usermodel; package org.apache.poi.xwpf.usermodel;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.util.TempFile;
import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock; 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 * @author Paolo Mottadelli
@ -35,7 +28,7 @@ public final class TestXWPFHeadings extends TestCase{
assertEquals(HEADING1, p.getCTP().getPPr().getPStyle().getVal()); assertEquals(HEADING1, p.getCTP().getPPr().getPStyle().getVal());
doc.createTOC(); doc.createTOC();
/*
// TODO - finish this test // TODO - finish this test
if (false) { if (false) {
CTStyles styles = doc.getStyle(); CTStyles styles = doc.getStyle();
@ -50,5 +43,6 @@ public final class TestXWPFHeadings extends TestCase{
doc.write(out); doc.write(out);
out.close(); out.close();
} }
*/
} }
} }

View File

@ -187,7 +187,7 @@ public class TestXWPFRun extends TestCase {
run.setText("TEXT1"); run.setText("TEXT1");
run.addBreak(); run.addBreak();
run.setText("TEXT2"); run.setText("TEXT2");
run.addBreak(); run.addBreak(BreakType.TEXT_WRAPPING);
assertEquals(2, run.getCTR().sizeOfBrArray()); assertEquals(2, run.getCTR().sizeOfBrArray());
} }

View File

@ -112,6 +112,13 @@ public class TestXWPFTable extends TestCase {
assertEquals(100, table.getTblPr().getTblW().getW().intValue()); 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());
}
} }