diff --git a/odfdom/src/test/java/org/odftoolkit/odfdom/changes/RoundtripTest.java b/odfdom/src/test/java/org/odftoolkit/odfdom/changes/RoundtripTest.java index 6de794542..98d385b5c 100644 --- a/odfdom/src/test/java/org/odftoolkit/odfdom/changes/RoundtripTest.java +++ b/odfdom/src/test/java/org/odftoolkit/odfdom/changes/RoundtripTest.java @@ -88,6 +88,10 @@ private static void addFilesFromFolder(final File folder, Collection t && !filePath.contains("textTestTemplate.ott") && !filePath.contains("indentTest.odt") && !filePath.contains("testInvalidPkg") + && !filePath.contains("duplicate-files.odt") + && !filePath.contains("unicode-path.odt") + && !filePath.contains("slash.odt") + && !filePath.contains("two-zips.odt") && !filePath.contains("BigTable.odt") // too slow 4 now && !filePath.endsWith("PasswordProtected.odt")) { // !filePath.contains("Text1.odt") diff --git a/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/PackageTest.java b/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/PackageTest.java index 3cc2e2002..a6186cf4f 100644 --- a/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/PackageTest.java +++ b/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/PackageTest.java @@ -397,6 +397,112 @@ public void validationTest() { handler4.validate(); } + @Test + public void validationTest5() { + // TESTDOC5: duplicate ZIP entries + Map expectedFatalErrors = + new HashMap(); + expectedFatalErrors.put(OdfPackageConstraint.PACKAGE_ENTRY_DUPLICATE, 1); + ErrorHandlerStub handler = new ErrorHandlerStub(null, null, expectedFatalErrors); + handler.setTestFilePath("duplicate-files.odt"); + + try { + try { + OdfPackage.loadPackage( + new File(ResourceUtilities.getAbsoluteInputPath(handler.getTestFilePath())), + null, + handler); + Assert.fail(); + } catch (Exception e) { + String errorMsg = OdfPackageConstraint.PACKAGE_ENTRY_DUPLICATE.getMessage(); + if (e.getMessage().indexOf(errorMsg.substring(0, errorMsg.indexOf("%2$s"))) == -1) { + Assert.fail(); + } + } + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + Assert.fail(ex.toString()); + } + handler.validate(); + } + + @Test + public void validationTest6() { + // TESTDOC6: Info-ZIP Unicode Path Extra Field with different name + Map expectedErrors = + new HashMap(); + // depending on setUseUnicodeExtraFields this would be reported as + // MANIFEST_DOES_NOT_LIST_FILE or as PACKAGE_ENTRY_DUPLICATE + expectedErrors.put(OdfPackageConstraint.MANIFEST_DOES_NOT_LIST_FILE, 1); + ErrorHandlerStub handler = new ErrorHandlerStub(null, expectedErrors, null); + handler.setTestFilePath("unicode-path.odt"); + + try { + OdfPackage pkg = + OdfPackage.loadPackage( + new File(ResourceUtilities.getAbsoluteInputPath(handler.getTestFilePath())), + null, + handler); + Assert.assertNotNull(pkg); + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + Assert.fail(ex.toString()); + } + handler.validate(); + } + + @Test + public void validationTest7() { + // TESTDOC7: invalid file name + Map expectedFatalErrors = + new HashMap(); + expectedFatalErrors.put(OdfPackageConstraint.PACKAGE_ENTRY_INVALID_FILE_NAME, 1); + ErrorHandlerStub handler = new ErrorHandlerStub(null, null, expectedFatalErrors); + handler.setTestFilePath("slash.odt"); + + try { + try { + OdfPackage.loadPackage( + new File(ResourceUtilities.getAbsoluteInputPath(handler.getTestFilePath())), + null, + handler); + Assert.fail(); + } catch (Exception e) { + String errorMsg = OdfPackageConstraint.PACKAGE_ENTRY_INVALID_FILE_NAME.getMessage(); + if (e.getMessage().indexOf(errorMsg.substring(0, errorMsg.indexOf("%2$s"))) == -1) { + Assert.fail(); + } + } + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + Assert.fail(ex.toString()); + } + handler.validate(); + } + + @Test + public void validationTest8() { + // TESTDOC8: 2 concatenated zips + Map expectedErrors = + new HashMap(); + expectedErrors.put(OdfPackageConstraint.MIMETYPE_NOT_FIRST_IN_PACKAGE, 1); + ErrorHandlerStub handler = new ErrorHandlerStub(null, expectedErrors, null); + handler.setTestFilePath("two-zips.odt"); + + try { + OdfPackage pkg = + OdfPackage.loadPackage( + new File(ResourceUtilities.getAbsoluteInputPath(handler.getTestFilePath())), + null, + handler); + Assert.assertNotNull(pkg); + } catch (Exception ex) { + LOG.log(Level.SEVERE, null, ex); + Assert.fail(ex.toString()); + } + handler.validate(); + } + @Test public void testPackagePassword() { File tmpFile = ResourceUtilities.getTestOutputFile("PackagePassword.ods"); diff --git a/odfdom/src/test/resources/test-input/duplicate-files.odt b/odfdom/src/test/resources/test-input/duplicate-files.odt new file mode 100644 index 000000000..cc24f7024 Binary files /dev/null and b/odfdom/src/test/resources/test-input/duplicate-files.odt differ diff --git a/odfdom/src/test/resources/test-input/slash.odt b/odfdom/src/test/resources/test-input/slash.odt new file mode 100644 index 000000000..22c644349 Binary files /dev/null and b/odfdom/src/test/resources/test-input/slash.odt differ diff --git a/odfdom/src/test/resources/test-input/two-zips.odt b/odfdom/src/test/resources/test-input/two-zips.odt new file mode 100644 index 000000000..36d90cb9d Binary files /dev/null and b/odfdom/src/test/resources/test-input/two-zips.odt differ diff --git a/odfdom/src/test/resources/test-input/unicode-path.odt b/odfdom/src/test/resources/test-input/unicode-path.odt new file mode 100644 index 000000000..9edaaeb68 Binary files /dev/null and b/odfdom/src/test/resources/test-input/unicode-path.odt differ