diff options
author | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-03-05 11:11:41 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-03-05 11:14:55 +0100 |
commit | 9a7ca779cdd3007df4e1425d296ba83091a4044d (patch) | |
tree | 7ddf34f70998b6cc1c3c97dbfc87c9f5b3cfd999 | |
parent | 7691532a89a94120c220f77e8cc6c42615e3d7c4 (diff) |
move the export validation code to test
Change-Id: Iaafe30a1095bd5b6dac3637c394818ba8bd848ce
-rw-r--r-- | include/test/bootstrapfixture.hxx | 8 | ||||
-rw-r--r-- | sc/qa/unit/helper/qahelper.cxx | 68 | ||||
-rw-r--r-- | test/source/bootstrapfixture.cxx | 74 |
3 files changed, 83 insertions, 67 deletions
diff --git a/include/test/bootstrapfixture.hxx b/include/test/bootstrapfixture.hxx index 3896010eec1e..f7e40e6af101 100644 --- a/include/test/bootstrapfixture.hxx +++ b/include/test/bootstrapfixture.hxx @@ -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); }; } diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx index 7ab7a36e3c88..320ab5ee1516 100644 --- a/sc/qa/unit/helper/qahelper.cxx +++ b/sc/qa/unit/helper/qahelper.cxx @@ -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; } diff --git a/test/source/bootstrapfixture.cxx b/test/source/bootstrapfixture.cxx index 23ea391983de..137a284c53f3 100644 --- a/test/source/bootstrapfixture.cxx +++ b/test/source/bootstrapfixture.cxx @@ -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) { |