[Libreoffice-commits] core.git: include/test sc/qa test/source

Markus Mohrhard markus.mohrhard at collabora.co.uk
Wed Mar 5 02:16:19 PST 2014


 include/test/bootstrapfixture.hxx |    8 ++++
 sc/qa/unit/helper/qahelper.cxx    |   68 ----------------------------------
 test/source/bootstrapfixture.cxx  |   74 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 67 deletions(-)

New commits:
commit 9a7ca779cdd3007df4e1425d296ba83091a4044d
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Wed Mar 5 11:11:41 2014 +0100

    move the export validation code to test
    
    Change-Id: Iaafe30a1095bd5b6dac3637c394818ba8bd848ce

diff --git a/include/test/bootstrapfixture.hxx b/include/test/bootstrapfixture.hxx
index 3896010..f7e40e6 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 7ab7a36..320ab5e 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 23ea391..137a284 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)
 {


More information about the Libreoffice-commits mailing list