config_host/config_features.h.in | 5 + configure.ac | 20 +++++ sc/qa/unit/data/xlsx/universal-content-strict.xlsx |binary sc/qa/unit/filters-test.cxx | 84 ++------------------- sc/qa/unit/helper/qahelper.cxx | 67 ++++++++++++++++ writerfilter/source/ooxml/OOXMLDocumentImpl.cxx | 36 ++++++--- writerfilter/source/ooxml/OOXMLStreamImpl.cxx | 39 +++++++++ 7 files changed, 165 insertions(+), 86 deletions(-)
New commits: commit 13a30b3a109c39ce346ea5bc1f35889209bb375b Author: Markus Mohrhard <[email protected]> Date: Mon Mar 3 10:52:05 2014 +0100 remove remaining parts of the old crash testing Change-Id: I2282d2ee8304bdc9dbdf24c5a22c16d0e742deb7 diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx index 74a68ae..4de62d1 100644 --- a/sc/qa/unit/filters-test.cxx +++ b/sc/qa/unit/filters-test.cxx @@ -20,8 +20,6 @@ #include <sfx2/sfxmodelfactory.hxx> #include <svl/stritem.hxx> -#define TEST_BUG_FILES 0 - #include "helper/qahelper.hxx" #include "docsh.hxx" @@ -70,14 +68,6 @@ public: void testContentXLS_XML(); void testSharedFormulaXLS(); void testSharedFormulaXLSX(); -#if TEST_BUG_FILES - //goes recursively through all files in this dir and tries to open them - void testDir(osl::Directory& rDir, sal_Int32 nType); - //test Bug Files and search for files that crash LibO - void testBugFiles(); - void testBugFilesXLS(); - void testBugFilesXLSX(); -#endif void testLegacyCellAnchoredRotatedShape(); CPPUNIT_TEST_SUITE(ScFiltersTest); @@ -93,11 +83,6 @@ public: CPPUNIT_TEST(testSharedFormulaXLSX); CPPUNIT_TEST(testLegacyCellAnchoredRotatedShape); -#if TEST_BUG_FILES - CPPUNIT_TEST(testBugFiles); - CPPUNIT_TEST(testBugFilesXLS); - CPPUNIT_TEST(testBugFilesXLSX); -#endif CPPUNIT_TEST_SUITE_END(); private: @@ -134,64 +119,6 @@ void ScFiltersTest::testCVEs() #endif } -#if TEST_BUG_FILES - -void ScFiltersTest::testDir(osl::Directory& rDir, sal_uInt32 nType) -{ - OUString aFilterName(getFileFormats()[nType].pFilterName, strlen(getFileFormats()[nType].pFilterName), RTL_TEXTENCODING_UTF8) ; - OUString aFilterType(getFileFormats()[nType].pTypeName, strlen(getFileFormats()[nType].pTypeName), RTL_TEXTENCODING_UTF8); - - osl::DirectoryItem aItem; - osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL|osl_FileStatus_Mask_Type); - while (rDir.getNextItem(aItem) == osl::FileBase::E_None) - { - aItem.getFileStatus(aFileStatus); - OUString sURL = aFileStatus.getFileURL(); - std::cout << "File: " << OUStringToOString(sURL, RTL_TEXTENCODING_UTF8).getStr() << std::endl; - //OStringBuffer aMessage("Failed loading: "); - //aMessage.append(OUStringToOString(sURL, RTL_TEXTENCODING_UTF8)); - - unsigned int nFormatType = getFileFormats()[nType].nFormatType; - unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0; - ScDocShellRef xDocSh = load(sURL, aFilterName, OUString(), - aFilterType, nFormatType, nClipboardId ); - // use this only if you're sure that all files can be loaded - // pay attention to lock files - //CPPUNIT_ASSERT_MESSAGE(aMessage.getStr(), xDocSh.Is()); - if (xDocSh.Is()) - xDocSh->DoClose(); - } -} - -void ScFiltersTest::testBugFiles() -{ - OUString aDirName = getURLFromSrc("/sc/qa/unit/data/bugODS/"); - osl::Directory aDir(aDirName); - - CPPUNIT_ASSERT(osl::FileBase::E_None == aDir.open()); - testDir(aDir, 0); -} - -void ScFiltersTest::testBugFilesXLS() -{ - OUString aDirName = getURLFromSrc("/sc/qa/unit/data/bugXLS/"); - osl::Directory aDir(aDirName); - - CPPUNIT_ASSERT(osl::FileBase::E_None == aDir.open()); - testDir(aDir, 1); -} - -void ScFiltersTest::testBugFilesXLSX() -{ - OUString aDirName = getURLFromSrc("/sc/qa/unit/data/bugXLSX/"); - osl::Directory aDir(aDirName); - - CPPUNIT_ASSERT(osl::FileBase::E_None == aDir.open()); - testDir(aDir, 2); -} - -#endif - namespace { void testRangeNameImpl(ScDocument* pDoc) commit 69e14b0fee1c474168d8159b874d7c2fd9dea64f Author: Markus Mohrhard <[email protected]> Date: Mon Mar 3 10:49:37 2014 +0100 add experimental export file validation In calc unit tests we validate the exported OOXML files now with officeotron. For this there must be a script called officeotron that takes the file path. Currently the generated files are still invalid but I'm going to fix it. Change-Id: I1809b9457a535dbbe6a72f3778dfb53db168bbda diff --git a/config_host/config_features.h.in b/config_host/config_features.h.in index 0f63f26..6a46e1c 100644 --- a/config_host/config_features.h.in +++ b/config_host/config_features.h.in @@ -120,4 +120,9 @@ */ #define HAVE_FT_FACE_GETCHARVARIANTINDEX 0 +/* + * Whether to use validation on files. + */ +#define HAVE_EXPORT_VALIDATION 0 + #endif diff --git a/configure.ac b/configure.ac index 4d98071..bf2d03c 100644 --- a/configure.ac +++ b/configure.ac @@ -1835,6 +1835,15 @@ AC_ARG_WITH(ant-home, ], ,) +AC_ARG_WITH(export-validation, + AS_HELP_STRING([--with-export-validation], + [If you want the exported files to be validated. Right now limited to OOXML files in calc export tests. + Note: You need an executable script officeotron that takes the path to the file.]) + [ + Usage: --with-export-validation + ], +,) + AC_ARG_WITH(junit, AS_HELP_STRING([--with-junit], [Specifies the JUnit 4 jar file to use for JUnit-based tests. @@ -2558,6 +2567,17 @@ dnl ENABLE_JAVA="TRUE" if we want there to be *run-time* (and build-time) suppor dnl ENABLE_JAVA="" indicate no Java support at all dnl =================================================================== +dnl Export file validation +dnl =================================================================== +AC_MSG_CHECKING([whether to enable export file validation]) +if test "with_export_validation" != "no"; then + AC_MSG_RESULT([yes]) + AC_DEFINE(HAVE_EXPORT_VALIDATION) +else + AC_MSG_RESULT([no]) +fi + +dnl =================================================================== dnl Test the Solaris compiler version dnl =================================================================== if test "$_os" = "SunOS"; then diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx index b875265..35f5bc9 100644 --- a/sc/qa/unit/helper/qahelper.cxx +++ b/sc/qa/unit/helper/qahelper.cxx @@ -587,6 +587,66 @@ void ScBootstrapFixture::createCSVPath(const OUString& aFileBase, OUString& rCSV rCSVPath = aBuffer.makeStringAndClear(); } +namespace validation { + +enum ScValidationFormat +{ + OOXML +}; + +} + +#if HAVE_EXPORT_VALIDATION + +namespace { + +void validate(const utl::TempFile& rTempFile, validation::ScValidationFormat eFormat) +{ + OUString aValidator; + if( eFormat == validation::OOXML ) + { + aValidator = "officeotron "; + } + else + return; + + utl::TempFile aOutput; + aOutput.EnableKillingFile(); + OUString aOutputFile = aOutput.GetFileName(); + OUString aInputFile = rTempFile.GetFileName(); + OUString aCommand = aValidator + aInputFile + " > " + aOutputFile; + + system(OUStringToOString(aCommand, RTL_TEXTENCODING_UTF8).getStr()); + + std::string aContent; + loadFile(aOutputFile, aContent); + OString aContentString(aContent.c_str()); + OUString aContentOUString = OStringToOUString(aContentString, RTL_TEXTENCODING_UTF8); + + if( eFormat == validation::OOXML && !aContentOUString.isEmpty() ) + { + // check for validation errors here + sal_Int32 nIndex = aContentOUString.lastIndexOf("Grand total of errors in submitted package: "); + if(nIndex == -1) + { + SAL_WARN("sc", "no summery line"); + } + else + { + sal_Int32 nStartOfNumber = nIndex + std::strlen("Grand total of errors in submitted package: "); + OUString aNumber = aContentOUString.copy(nStartOfNumber); + sal_Int32 nErrors = aNumber.toInt32(); + OString aMsg("validation error in OOXML export: Errors: "); + aMsg = aMsg + OString::number(nErrors); + CPPUNIT_ASSERT_MESSAGE(aMsg.getStr(), nErrors == 0); + } + } +} + +} + +#endif + ScDocShellRef ScBootstrapFixture::saveAndReload( ScDocShell* pShell, const OUString &rFilter, const OUString &rUserData, const OUString& rTypeName, sal_uLong nFormatType) @@ -613,7 +673,12 @@ ScDocShellRef ScBootstrapFixture::saveAndReload( if (nFormatType == ODS_FORMAT_TYPE) nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS; - return load(aTempFile.GetURL(), rFilter, rUserData, rTypeName, nFormatType, nFormat ); + ScDocShellRef xDocSh = load(aTempFile.GetURL(), rFilter, rUserData, rTypeName, nFormatType, nFormat ); +#if HAVE_EXPORT_VALIDATION + if(nFormatType == XLSX_FORMAT_TYPE) + validate(aTempFile, validation::OOXML); +#endif + return xDocSh; } ScDocShellRef ScBootstrapFixture::saveAndReload( ScDocShell* pShell, sal_Int32 nFormat ) commit 1c3c83e6a35ee4258c9d658494297d1453a70806 Author: Markus Mohrhard <[email protected]> Date: Mon Mar 3 07:50:05 2014 +0100 add import test for strict OOXML import in calc Change-Id: I4dc0fb84cc9e2601e7ae8b82a467787388ac4d99 diff --git a/sc/qa/unit/data/xlsx/universal-content-strict.xlsx b/sc/qa/unit/data/xlsx/universal-content-strict.xlsx new file mode 100644 index 0000000..32beb4d Binary files /dev/null and b/sc/qa/unit/data/xlsx/universal-content-strict.xlsx differ diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx index 53f8c76..74a68ae 100644 --- a/sc/qa/unit/filters-test.cxx +++ b/sc/qa/unit/filters-test.cxx @@ -64,6 +64,7 @@ public: void testContentODS(); void testContentXLS(); void testContentXLSX(); + void testContentXLSXStrict(); // strict OOXML void testContentLotus123(); void testContentDIF(); void testContentXLS_XML(); @@ -315,6 +316,16 @@ void ScFiltersTest::testContentXLSX() xDocSh->DoClose(); } +void ScFiltersTest::testContentXLSXStrict() +{ + ScDocShellRef xDocSh = loadDoc("universal-content-strict.", XLSX); + xDocSh->DoHardRecalc(true); + + ScDocument* pDoc = xDocSh->GetDocument(); + testContentImpl(pDoc, XLSX); + xDocSh->DoClose(); +} + void ScFiltersTest::testContentLotus123() { ScDocShellRef xDocSh = loadDoc("universal-content.", LOTUS123); commit 46e25170b901211f9e9bed117e25428505d8536c Author: Markus Mohrhard <[email protected]> Date: Sun Mar 2 19:13:18 2014 +0100 allow OOXML strict relationships in writer Change-Id: I1c09280f68467748faedee19c4a66be3bc7d7aa3 diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx index 5f67fd2..09dbbb1 100644 --- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx @@ -494,7 +494,8 @@ void OOXMLDocumentImpl::resolveCustomXmlStream(Stream & rStream) mxRelationshipAccess.set((*dynamic_cast<OOXMLStreamImpl *>(mpStream.get())).accessDocumentStream(), uno::UNO_QUERY_THROW); if (mxRelationshipAccess.is()) { - OUString sCustomType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml"); + static const OUString sCustomType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml"); + static const OUString sCustomTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/customXml"); OUString sTarget("Target"); bool bFound = false; sal_Int32 counter = 0; @@ -510,7 +511,8 @@ void OOXMLDocumentImpl::resolveCustomXmlStream(Stream & rStream) beans::StringPair aPair = aSeq[i]; // Need to resolve only customxml files from document relationships. // Skipping other files. - if (aPair.Second.compareTo(sCustomType) == 0) + if (aPair.Second.compareTo(sCustomType) == 0 || + aPair.Second.compareTo(sCustomTypeStrict) == 0) bFound = true; else if(aPair.First.compareTo(sTarget) == 0 && bFound) { @@ -548,6 +550,10 @@ void OOXMLDocumentImpl::resolveGlossaryStream(Stream & /*rStream*/) static OUString sStylesType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"); static OUString sFonttableType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"); static OUString sWebSettings("http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"); + static OUString sSettingsTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/settings"); + static OUString sStylesTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/styles"); + static OUString sFonttableTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/fontTable"); + static OUString sWebSettingsStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/webSettings"); OOXMLStream::Pointer_t pStream; try @@ -581,25 +587,29 @@ void OOXMLDocumentImpl::resolveGlossaryStream(Stream & /*rStream*/) OOXMLStream::StreamType_t nType(OOXMLStream::UNKNOWN); bool bFound = true; - if(gType.compareTo(sSettingsType) == 0) + if(gType.compareTo(sSettingsType) == 0 || + gType.compareTo(sSettingsTypeStrict) == 0) { nType = OOXMLStream::SETTINGS; contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"; } - else if(gType.compareTo(sStylesType) == 0) + else if(gType.compareTo(sStylesType) == 0 || + gType.compareTo(sStylesTypeStrict) == 0) { nType = OOXMLStream::STYLES; contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"; } - else if(gType.compareTo(sWebSettings) == 0) + else if(gType.compareTo(sWebSettings) == 0 || + gType.compareTo(sWebSettingsStrict) == 0) { nType = OOXMLStream::WEBSETTINGS; contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"; } - else if(gType.compareTo(sFonttableType) == 0) + else if(gType.compareTo(sFonttableType) == 0 || + gType.compareTo(sFonttableTypeStrict) == 0) { - nType = OOXMLStream::FONTTABLE; - contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"; + nType = OOXMLStream::FONTTABLE; + contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"; } else { @@ -650,6 +660,7 @@ void OOXMLDocumentImpl::resolveEmbeddingsStream(Stream & /*rStream*/) if (mxRelationshipAccess.is()) { OUString sChartType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"); + OUString sChartTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/chart"); OUString sTarget("Target"); bool bFound = false; sal_Int32 counter = 0; @@ -662,7 +673,8 @@ void OOXMLDocumentImpl::resolveEmbeddingsStream(Stream & /*rStream*/) for (sal_Int32 i = 0; i < aSeq.getLength(); i++) { beans::StringPair aPair = aSeq[i]; - if (aPair.Second.compareTo(sChartType) == 0) + if (aPair.Second.compareTo(sChartType) == 0 || + aPair.Second.compareTo(sChartTypeStrict) == 0) bFound = true; else if(aPair.First.compareTo(sTarget) == 0 && bFound) { @@ -701,7 +713,8 @@ void OOXMLDocumentImpl::resolveActiveXStream(Stream & rStream) mxRelationshipAccess.set((*dynamic_cast<OOXMLStreamImpl *>(mpStream.get())).accessDocumentStream(), uno::UNO_QUERY_THROW); if (mxRelationshipAccess.is()) { - OUString sCustomType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/control"); + static const OUString sCustomType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/control"); + static const OUString sCustomTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/control"); OUString sTarget("Target"); bool bFound = false; sal_Int32 counter = 0; @@ -717,7 +730,8 @@ void OOXMLDocumentImpl::resolveActiveXStream(Stream & rStream) beans::StringPair aPair = aSeq[i]; // Need to resolve only ActiveX files from document relationships. // Skipping other files. - if (aPair.Second.compareTo(sCustomType) == 0) + if (aPair.Second.compareTo(sCustomType) == 0 || + aPair.Second.compareTo(sCustomTypeStrict) == 0) bFound = true; else if(aPair.First.compareTo(sTarget) == 0 && bFound) { diff --git a/writerfilter/source/ooxml/OOXMLStreamImpl.cxx b/writerfilter/source/ooxml/OOXMLStreamImpl.cxx index d278805..1495b17 100644 --- a/writerfilter/source/ooxml/OOXMLStreamImpl.cxx +++ b/writerfilter/source/ooxml/OOXMLStreamImpl.cxx @@ -119,68 +119,104 @@ bool OOXMLStreamImpl::lcl_getTarget(uno::Reference<embed::XRelationshipAccess> static OUString sSettingsType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"); static OUString sChartType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"); static OUString sEmbeddingsType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"); + // OOXML strict + static OUString sDocumentTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument"); + static OUString sStylesTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/styles"); + static OUString sNumberingTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/numbering"); + static OUString sFonttableTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/fontTable"); + static OUString sFootnotesTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/footnotes"); + static OUString sEndnotesTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/endnotes"); + static OUString sCommentsTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/comments"); + static OUString sThemeTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/theme"); + static OUString sCustomTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/customXml"); + static OUString sCustomPropsTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/customXmlProps"); + static OUString sActiveXTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/control"); + static OUString sGlossaryTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/glossaryDocument"); + static OUString sWebSettingsStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/webSettings"); + static OUString sSettingsTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/settings"); + static OUString sChartTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/chart"); + static OUString sEmbeddingsTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/package"); static OUString sTarget("Target"); static OUString sTargetMode("TargetMode"); static OUString sExternal("External"); static OUString sVBAProjectType("http://schemas.microsoft.com/office/2006/relationships/vbaProject"); OUString sStreamType; + OUString sStreamTypeStrict; switch (nStreamType) { case VBAPROJECT: sStreamType = sVBAProjectType; + sStreamTypeStrict = sVBAProjectType; break; case DOCUMENT: sStreamType = sDocumentType; + sStreamTypeStrict = sDocumentTypeStrict; break; case STYLES: sStreamType = sStylesType; + sStreamTypeStrict = sStylesTypeStrict; break; case NUMBERING: sStreamType = sNumberingType; + sStreamTypeStrict = sNumberingTypeStrict; break; case FONTTABLE: sStreamType = sFonttableType; + sStreamTypeStrict = sFonttableTypeStrict; break; case FOOTNOTES: sStreamType = sFootnotesType; + sStreamTypeStrict = sFootnotesTypeStrict; break; case ENDNOTES: sStreamType = sEndnotesType; + sStreamTypeStrict = sEndnotesTypeStrict; break; case COMMENTS: sStreamType = sCommentsType; + sStreamTypeStrict = sCommentsTypeStrict; break; case THEME: sStreamType = sThemeType; + sStreamTypeStrict = sThemeTypeStrict; break; case CUSTOMXML: sStreamType = sCustomType; + sStreamTypeStrict = sCustomTypeStrict; break; case CUSTOMXMLPROPS: sStreamType = sCustomPropsType; + sStreamTypeStrict = sCustomPropsTypeStrict; break; case ACTIVEX: sStreamType = sActiveXType; + sStreamTypeStrict = sActiveXTypeStrict; break; case ACTIVEXBIN: sStreamType = sActiveXBinType; + sStreamTypeStrict = sActiveXBinType; break; case SETTINGS: sStreamType = sSettingsType; + sStreamTypeStrict = sSettingsTypeStrict; break; case GLOSSARY: sStreamType = sGlossaryType; + sStreamTypeStrict = sGlossaryTypeStrict; break; case WEBSETTINGS: sStreamType = sWebSettings; + sStreamTypeStrict = sWebSettingsStrict; break; case CHARTS: sStreamType = sChartType; + sStreamTypeStrict = sChartTypeStrict; break; case EMBEDDINGS: sStreamType = sEmbeddingsType; + sStreamTypeStrict = sEmbeddingsTypeStrict; break; default: break; @@ -202,7 +238,8 @@ bool OOXMLStreamImpl::lcl_getTarget(uno::Reference<embed::XRelationshipAccess> beans::StringPair aPair = aSeq[i]; if (aPair.First.compareTo(sType) == 0 && - aPair.Second.compareTo(sStreamType) == 0) + ( aPair.Second.compareTo(sStreamType) == 0 || + aPair.Second.compareTo(sStreamTypeStrict) == 0)) bFound = true; else if (aPair.First.compareTo(sId) == 0 && aPair.Second.compareTo(rId) == 0) _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
