summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-03-03 10:49:37 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2014-03-03 10:56:28 +0100
commit69e14b0fee1c474168d8159b874d7c2fd9dea64f (patch)
tree36413d0601e7c38e223a80a8585d26d930259930 /sc
parent1c3c83e6a35ee4258c9d658494297d1453a70806 (diff)
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
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/helper/qahelper.cxx67
1 files changed, 66 insertions, 1 deletions
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index b875265e16c8..35f5bc92f369 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 )