Kaydet (Commit) 9a7ca779 authored tarafından Markus Mohrhard's avatar Markus Mohrhard Kaydeden (comit) Markus Mohrhard

move the export validation code to test

Change-Id: Iaafe30a1095bd5b6dac3637c394818ba8bd848ce
üst 7691532a
......@@ -27,6 +27,12 @@
namespace test {
enum ValidationFormat
{
OOXML,
ODF
};
// Class to do lots of heavy-lifting UNO & environment
// bootstrapping for unit tests, such that we can use
// almost an entire LibreOffice during compile - so
......@@ -47,6 +53,8 @@ public:
virtual void setUp();
virtual void tearDown();
static void validate(const OUString& rURL, ValidationFormat);
};
}
......
......@@ -587,70 +587,6 @@ 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);
if(nErrors)
{
SAL_WARN("sc", aContent);
}
CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsg.getStr(), sal_Int32(0), nErrors);
}
}
}
}
#endif
ScDocShellRef ScBootstrapFixture::saveAndReload(
ScDocShell* pShell, const OUString &rFilter,
const OUString &rUserData, const OUString& rTypeName, sal_uLong nFormatType)
......@@ -678,10 +614,8 @@ ScDocShellRef ScBootstrapFixture::saveAndReload(
nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS;
ScDocShellRef xDocSh = load(aTempFile.GetURL(), rFilter, rUserData, rTypeName, nFormatType, nFormat );
#if HAVE_EXPORT_VALIDATION
if(nFormatType == XLSX_FORMAT_TYPE)
validate(aTempFile, validation::OOXML);
#endif
validate(aTempFile.GetFileName(), test::OOXML);
return xDocSh;
}
......
......@@ -23,6 +23,11 @@
#include <tools/resmgr.hxx>
#include <vcl/graphicfilter.hxx>
#include <unotools/syslocaleoptions.hxx>
#include <osl/file.hxx>
#include <unotools/tempfile.hxx>
#include <boost/scoped_array.hpp>
#include <cstring>
using namespace ::com::sun::star;
......@@ -113,6 +118,75 @@ test::BootstrapFixture::~BootstrapFixture()
{
}
namespace {
OString loadFile(const OUString& rURL)
{
osl::File aFile(rURL);
osl::FileBase::RC eStatus = aFile.open(osl_File_OpenFlag_Read);
CPPUNIT_ASSERT_EQUAL(eStatus, osl::FileBase::E_None);
sal_uInt64 nSize;
aFile.getSize(nSize);
boost::scoped_array<char> aBytes(new char[nSize]);
sal_uInt64 nBytesRead;
aFile.read(aBytes.get(), nSize, nBytesRead);
CPPUNIT_ASSERT_EQUAL(nSize, nBytesRead);
OString aContent(aBytes.get());
return aContent;
}
}
void test::BootstrapFixture::validate(const OUString& rPath, test::ValidationFormat eFormat )
{
(void)rPath;
(void)eFormat;
#if HAVE_EXPORT_VALIDATION
OUString aValidator;
if( eFormat == test::OOXML )
{
aValidator = "officeotron ";
}
else
return;
utl::TempFile aOutput;
aOutput.EnableKillingFile();
OUString aOutputFile = aOutput.GetFileName();
OUString aCommand = aValidator + rPath + " > " + aOutputFile;
system(OUStringToOString(aCommand, RTL_TEXTENCODING_UTF8).getStr());
OString aContentString = loadFile(aOutput.GetURL());
OUString aContentOUString = OStringToOUString(aContentString, RTL_TEXTENCODING_UTF8);
if( eFormat == test::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("test", "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);
if(nErrors)
{
SAL_WARN("test", aContentOUString);
}
CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsg.getStr(), sal_Int32(0), nErrors);
}
}
#endif
}
IMPL_STATIC_LINK_NOINSTANCE(
test::BootstrapFixture, ImplInitFilterHdl, ConvertData*, pData)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment