diff options
author | Yegor Kozlov <yegor@apache.org> | 2009-07-24 07:29:22 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2009-07-24 07:29:22 +0000 |
commit | 51baaaafbd9a9c8a0042b3f244c146dee7cf2e3d (patch) | |
tree | 318a1f5249cd98c685c75d8b0450cb2a259761ea /src/ooxml/testcases | |
parent | b7ba153dcb41f534516cb411553cfa1bf6bd6c4e (diff) | |
download | poi-51baaaafbd9a9c8a0042b3f244c146dee7cf2e3d.tar.gz poi-51baaaafbd9a9c8a0042b3f244c146dee7cf2e3d.zip |
fixed compatibility issues with OpenOffice 3.0 and Excel 2008 Mac sp2, see Bugzilla #46419 and #47559
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@797350 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases')
4 files changed, 49 insertions, 22 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java index 46597b7828..90e7d54458 100755 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java @@ -27,6 +27,7 @@ import java.io.OutputStream; import java.lang.reflect.Field; import java.net.URI; import java.util.TreeMap; +import java.util.Iterator; import junit.framework.TestCase; @@ -36,11 +37,14 @@ 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.IOUtils; +import org.apache.poi.util.POILogger; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.Namespace; import org.dom4j.QName; +import org.dom4j.io.SAXReader; public final class TestPackage extends TestCase { private static Logger logger = Logger.getLogger("org.apache.poi.openxml4j.test"); @@ -185,16 +189,17 @@ public final class TestPackage extends TestCase { // Save and re-load pkg.close(); File tmp = TempFile.createTempFile("testCreatePackageWithCoreDocument", ".zip"); - FileOutputStream fout = new FileOutputStream(tmp); + FileOutputStream fout = new FileOutputStream(tmp); fout.write(baos.toByteArray()); fout.close(); pkg = OPCPackage.open(tmp.getPath()); //tmp.delete(); - + // Check still right coreRels = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT); assertEquals(1, coreRels.size()); coreRel = coreRels.getRelationship(0); + assertEquals("/", coreRel.getSourceURI().toString()); assertEquals("/xl/workbook.xml", coreRel.getTargetURI().toString()); corePart = pkg.getPart(coreRel); @@ -205,10 +210,30 @@ public final class TestPackage extends TestCase { rel = rels.getRelationship(0); assertEquals("Sheet1!A1", rel.getTargetURI().getRawFragment()); + assertMSCompatibility(pkg); + } + + private void assertMSCompatibility(OPCPackage pkg) throws Exception { + PackagePartName relName = PackagingURIHelper.createPartName(PackageRelationship.getContainerPartRelationship()); + PackagePart relPart = pkg.getPart(relName); + SAXReader reader = new SAXReader(); + Document xmlRelationshipsDoc = reader + .read(relPart.getInputStream()); + + Element root = xmlRelationshipsDoc.getRootElement(); + for (Iterator i = root + .elementIterator(PackageRelationship.RELATIONSHIP_TAG_NAME); i + .hasNext();) { + Element element = (Element) i.next(); + String value = element.attribute( + PackageRelationship.TARGET_ATTRIBUTE_NAME) + .getValue(); + assertTrue("Root target must not start with a leadng slash ('/'): " + value, value.charAt(0) != '/'); + } } - /** + /** * Test package opening. */ public void testOpenPackage() throws Exception { diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java index 48a4b4ecc1..7064fc48d8 100755 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackagingURIHelper.java @@ -31,8 +31,6 @@ public class TestPackagingURIHelper extends TestCase { /** * Test relativizePartName() method. - * - * TODO: fix and unable */ public void testRelativizeURI() throws Exception { URI uri1 = new URI("/word/document.xml"); @@ -54,23 +52,15 @@ public class TestPackagingURIHelper extends TestCase { URI retURI2 = PackagingURIHelper.relativizeURI(uri1, uri1); assertEquals("", retURI2.getPath()); - // Document and root totally different - URI uri4 = new URI("/"); - try { - PackagingURIHelper.relativizeURI(uri1, uri4); - //TODO: figure oout why the assertion fails - //fail("Must throw an exception ! Can't relativize with an empty URI"); - } catch (Exception e) { - // Do nothing - } - try { - PackagingURIHelper.relativizeURI(uri4, uri1); - //TODO: figure oout why the assertion fails - //fail("Must throw an exception ! Can't relativize with an empty URI"); - } catch (Exception e) { - // Do nothing - } - } + // relativization against root + URI root = new URI("/"); + uriRes = PackagingURIHelper.relativizeURI(root, uri1); + assertEquals("/word/document.xml", uriRes.toString()); + + //URI compatible with MS Office and OpenOffice: leading slash is removed + uriRes = PackagingURIHelper.relativizeURI(root, uri1, true); + assertEquals("word/document.xml", uriRes.toString()); + } /** * Test createPartName(String, y) diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java index 6c48e2fb16..2df9d8beef 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java @@ -260,6 +260,8 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { XSSFWorkbook workbook = new XSSFWorkbook(); POIXMLProperties props = workbook.getProperties(); assertNotNull(props); + //the Application property must be set for new workbooks, see Bugzilla #47559 + assertEquals("Microsoft Excel", props.getExtendedProperties().getUnderlyingProperties().getApplication()); PackagePropertiesPart opcProps = props.getCoreProperties().getUnderlyingProperties(); assertNotNull(opcProps); @@ -269,6 +271,7 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { opcProps.setCreatorProperty("poi-dev@poi.apache.org"); workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook); + assertEquals("Microsoft Excel", workbook.getProperties().getExtendedProperties().getUnderlyingProperties().getApplication()); opcProps = workbook.getProperties().getCoreProperties().getUnderlyingProperties(); assertEquals("Testing Bugzilla #47460", opcProps.getTitleProperty().getValue()); assertEquals("poi-dev@poi.apache.org", opcProps.getCreatorProperty().getValue()); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java b/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java index 68df95786c..881adf34b2 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java @@ -21,6 +21,7 @@ import java.io.File; import junit.framework.TestCase; import org.apache.poi.POIXMLDocument; +import org.apache.poi.POIXMLProperties; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.xwpf.usermodel.XWPFDocument; @@ -119,4 +120,12 @@ public class TestXWPFDocument extends TestCase { assertEquals(" ", xml.getProperties().getCoreProperties().getTitle()); assertEquals(" ", xml.getProperties().getCoreProperties().getUnderlyingProperties().getSubjectProperty().getValue()); } + + public void testWorkbookProperties() throws Exception { + XWPFDocument doc = new XWPFDocument(); + POIXMLProperties props = doc.getProperties(); + assertNotNull(props); + assertEquals("Microsoft Office Word", props.getExtendedProperties().getUnderlyingProperties().getApplication()); + } + } |