diff options
author | Nick Burch <nick@apache.org> | 2012-01-30 12:59:54 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2012-01-30 12:59:54 +0000 |
commit | bcb898e9778d4b2078f59474a4ee34c9cf82d293 (patch) | |
tree | f98e44dbe0c0ea532353d3fdf010b4bec0b634c6 /src/ooxml/testcases/org/apache/poi/openxml4j/opc | |
parent | 91f163c97a2c5683c77967e8998d018887348b8f (diff) | |
download | poi-bcb898e9778d4b2078f59474a4ee34c9cf82d293.tar.gz poi-bcb898e9778d4b2078f59474a4ee34c9cf82d293.zip |
Fix bug #52540 - Relax the M4.1 constraint on reading OOXML files, as some Office produced ones do have 2 Core Properties, despite the specification explicitly forbidding this
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1237631 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases/org/apache/poi/openxml4j/opc')
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java index b3a4a6320f..0cf5200092 100644 --- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java +++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java @@ -25,6 +25,7 @@ import java.net.URISyntaxException; import junit.framework.AssertionFailedError; import junit.framework.TestCase; +import org.apache.poi.POIDataSamples; import org.apache.poi.openxml4j.OpenXML4JTestDataSamples; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidOperationException; @@ -33,7 +34,6 @@ import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.TargetMode; -import org.apache.poi.POIDataSamples; /** * Test core properties Open Packaging Convention compliance. @@ -42,6 +42,7 @@ import org.apache.poi.POIDataSamples; * at most one core properties relationship for a package. A format consumer * shall consider more than one core properties relationship for a package to be * an error. If present, the relationship shall target the Core Properties part. + * (POI relaxes this on reading, as Office sometimes breaks this) * * M4.2: The format designer shall not specify and the format producer shall not * create Core Properties that use the Markup Compatibility namespace as defined @@ -82,28 +83,43 @@ public final class TestOPCComplianceCoreProperties extends TestCase { } private static String extractInvalidFormatMessage(String sampleNameSuffix) { - InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix); OPCPackage pkg; try { pkg = OPCPackage.open(is); } catch (InvalidFormatException e) { - // expected during successful test + // no longer required for successful test return e.getMessage(); } catch (IOException e) { throw new RuntimeException(e); } pkg.revert(); - // Normally must thrown an InvalidFormatException exception. throw new AssertionFailedError("expected OPC compliance exception was not thrown"); } /** * Test M4.1 rule. */ - public void testOnlyOneCorePropertiesPart() { - String msg = extractInvalidFormatMessage("OnlyOneCorePropertiesPartFAIL.docx"); - assertEquals("OPC Compliance error [M4.1]: there is more than one core properties relationship in the package !", msg); + public void testOnlyOneCorePropertiesPart() throws Exception { + // We have relaxed this check, so we can read the file anyway + try { + extractInvalidFormatMessage("OnlyOneCorePropertiesPartFAIL.docx"); + fail("M4.1 should be being relaxed"); + } catch (AssertionFailedError e) {} + + // We will use the first core properties, and ignore the others + InputStream is = OpenXML4JTestDataSamples.openSampleStream("MultipleCoreProperties.docx"); + OPCPackage pkg = OPCPackage.open(is); + + // We can see 2 by type + assertEquals(2, pkg.getPartsByContentType(ContentTypes.CORE_PROPERTIES_PART).size()); + // But only the first one by relationship + assertEquals(1, pkg.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES).size()); + // It should be core.xml not the older core1.xml + assertEquals( + "/docProps/core.xml", + pkg.getPartsByRelationshipType(PackageRelationshipTypes.CORE_PROPERTIES).get(0).getPartName().toString() + ); } private static URI createURI(String text) { @@ -131,7 +147,8 @@ public final class TestOPCComplianceCoreProperties extends TestCase { try { pkg.addRelationship(PackagingURIHelper.createPartName(partUri), TargetMode.INTERNAL, PackageRelationshipTypes.CORE_PROPERTIES); - fail("expected OPC compliance exception was not thrown"); + // no longer fail on compliance error + //fail("expected OPC compliance exception was not thrown"); } catch (InvalidFormatException e) { throw new RuntimeException(e); } catch (InvalidOperationException e) { @@ -157,7 +174,8 @@ public final class TestOPCComplianceCoreProperties extends TestCase { try { pkg.createPart(PackagingURIHelper.createPartName(partUri), ContentTypes.CORE_PROPERTIES_PART); - fail("expected OPC compliance exception was not thrown"); + // no longer fail on compliance error + //fail("expected OPC compliance exception was not thrown"); } catch (InvalidFormatException e) { throw new RuntimeException(e); } catch (InvalidOperationException e) { |