[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - sw/qa

Michael Stahl mstahl at redhat.com
Mon Feb 15 10:35:05 UTC 2016


 sw/qa/extras/htmlexport/htmlexport.cxx   |   18 ++++++++--------
 sw/qa/extras/inc/swmodeltestbase.hxx     |   34 +++++++++++++++++++++++++++----
 sw/qa/extras/odfexport/odfexport.cxx     |   22 ++++++++++----------
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx |   15 ++++++++-----
 sw/qa/extras/rtfimport/rtfimport.cxx     |   19 ++++++++++-------
 5 files changed, 71 insertions(+), 37 deletions(-)

New commits:
commit 938ddc33ed55579ea40d25bd9cd5704d31b0034e
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Feb 12 15:47:05 2016 +0100

    sw: ensure that configuration change in odfexporttest.cxx ...
    
    ... is reverted in case the test function throws an exception, so that
    subsequent^Wfollowing tests don't inherit the changed configuration.
    
    (cherry picked from commit e2bfae9006e6adc4de17d0167dac6661b002f126)
    
    Change-Id: I748f9edf15a7f860607ae4cce891450db254c73e
    Reviewed-on: https://gerrit.libreoffice.org/22336
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 2ce1040..4f24c35 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -41,7 +41,7 @@ private:
         return OString(filename) != "fdo62336.docx";
     }
 
-    void preTest(const char* filename) SAL_OVERRIDE
+    virtual std::unique_ptr<Resetter> preTest(const char* filename) SAL_OVERRIDE
     {
         if (getTestName().indexOf("SkipImage") != -1)
             setFilterOptions("SkipImages");
@@ -50,22 +50,22 @@ private:
 
         if (OString(filename) == "charborder.odt")
         {
+
             // FIXME if padding-top gets exported as inches, not cms, we get rounding errors.
             SwGlobals::ensure(); // make sure that SW_MOD() is not 0
+            std::unique_ptr<Resetter> pResetter(new Resetter(
+                [this] () {
+                    SwMasterUsrPref* pPref = const_cast<SwMasterUsrPref*>(SW_MOD()->GetUsrPref(false));
+                    pPref->SetMetric(this->m_eUnit);
+                }));
             SwMasterUsrPref* pPref = const_cast<SwMasterUsrPref*>(SW_MOD()->GetUsrPref(false));
             m_eUnit = pPref->GetMetric();
             pPref->SetMetric(FUNIT_CM);
+            return pResetter;
         }
+        return nullptr;
     }
 
-    void postTest(const char* filename) SAL_OVERRIDE
-    {
-        if (OString(filename) == "charborder.odt")
-        {
-            SwMasterUsrPref* pPref = const_cast<SwMasterUsrPref*>(SW_MOD()->GetUsrPref(false));
-            pPref->SetMetric(m_eUnit);
-        }
-    }
 };
 
 #define DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(TestName, filename) DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, HtmlExportTest)
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index 879c4f9..e34d76f 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -145,6 +145,31 @@ protected:
     bool mbExported; ///< Does maTempFile already contain something useful?
 
 protected:
+
+    class Resetter
+    {
+    private:
+        std::function<void ()> m_Func;
+
+    public:
+        Resetter(std::function<void ()> const& rFunc)
+            : m_Func(rFunc)
+        {
+        }
+        ~Resetter()
+        {
+            try
+            {
+                m_Func();
+            }
+            catch (...) // has to be reliable
+            {
+                fprintf(stderr, "resetter failed with exception\n");
+                abort();
+            }
+        }
+    };
+
     virtual OUString getTestName() { return OUString(); }
 
 public:
@@ -197,7 +222,7 @@ protected:
         {
             maTempFile.EnableKillingFile(false);
             header();
-            preTest(filename);
+            std::unique_ptr<Resetter> const pChanges(preTest(filename));
             load(mpTestDocumentPath, filename);
             postTest(filename);
             verify();
@@ -215,7 +240,7 @@ protected:
     {
         maTempFile.EnableKillingFile(false);
         header();
-        preTest(filename);
+        std::unique_ptr<Resetter> const pChanges(preTest(filename));
         load(mpTestDocumentPath, filename);
         postLoad(filename);
         reload(mpFilter, filename);
@@ -235,7 +260,7 @@ protected:
     {
         maTempFile.EnableKillingFile(false);
         header();
-        preTest(filename);
+        std::unique_ptr<Resetter> const pChanges(preTest(filename));
         load(mpTestDocumentPath, filename);
         save(OUString::createFromAscii(mpFilter), maTempFile);
         maTempFile.EnableKillingFile(false);
@@ -263,8 +288,9 @@ protected:
     /**
      * Override this function if some special filename-specific setup is needed
      */
-    virtual void preTest(const char* /*filename*/)
+    virtual std::unique_ptr<Resetter> preTest(const char* /*filename*/)
     {
+        return nullptr;
     }
 
     /// Override this function if some special file-specific setup is needed during export test: after load, but before save.
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index 0e106fa..2506ec3 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -51,24 +51,24 @@ public:
         return std::find(aBlacklist.begin(), aBlacklist.end(), filename) == aBlacklist.end();
     }
 
-    virtual void preTest(const char* pFilename) SAL_OVERRIDE
+    virtual std::unique_ptr<Resetter> preTest(const char* pFilename) SAL_OVERRIDE
     {
         if (OString(pFilename) == "fdo58949.docx")
         {
-            std::shared_ptr<comphelper::ConfigurationChanges> pBatch(comphelper::ConfigurationChanges::create());
-            officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::set(false, pBatch);
-            pBatch->commit();
-        }
-    }
+            std::unique_ptr<Resetter> pResetter(new Resetter(
+                [] () {
+                    std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
+                            comphelper::ConfigurationChanges::create());
+                    officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::set(true, pBatch);
+                    return pBatch->commit();
+                }));
 
-    virtual void postTest(const char* pFilename) SAL_OVERRIDE
-    {
-        if (OString(pFilename) == "fdo58949.docx")
-        {
             std::shared_ptr<comphelper::ConfigurationChanges> pBatch(comphelper::ConfigurationChanges::create());
-            officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::set(true, pBatch);
+            officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::set(false, pBatch);
             pBatch->commit();
+            return pResetter;
         }
+        return nullptr;
     }
 };
 
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 424e5f6..384bc3e 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -88,17 +88,20 @@ public:
     {
     }
 
-    virtual void preTest(const char* filename) SAL_OVERRIDE
+    virtual std::unique_ptr<Resetter> preTest(const char* filename) SAL_OVERRIDE
     {
         if (OString(filename) == "smartart.docx" || OString(filename) == "strict-smartart.docx" || OString(filename) == "fdo87488.docx")
+        {
+            std::unique_ptr<Resetter> pResetter(new Resetter(
+                [] () {
+                    SvtFilterOptions::Get().SetSmartArt2Shape(false);
+                }));
             SvtFilterOptions::Get().SetSmartArt2Shape(true);
+            return pResetter;
+        }
+        return nullptr;
     }
 
-    virtual void postTest(const char* filename) SAL_OVERRIDE
-    {
-        if (OString(filename) == "smartart.docx" || OString(filename) == "strict-smartart.docx" || OString(filename) == "fdo87488.docx")
-            SvtFilterOptions::Get().SetSmartArt2Shape(false);
-    }
 protected:
     /// Copy&paste helper.
     bool paste(const OUString& rFilename, const uno::Reference<text::XTextRange>& xTextRange)
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index 67efc3d..16e0c4b 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -66,27 +66,32 @@ public:
     {
     }
 
-    virtual void preTest(const char* filename) SAL_OVERRIDE
+    virtual std::unique_ptr<Resetter> preTest(const char* filename) SAL_OVERRIDE
     {
         m_aSavedSettings = Application::GetSettings();
         if (OString(filename) == "fdo48023.rtf" || OString(filename) == "fdo72031.rtf")
         {
+            std::unique_ptr<Resetter> pResetter(new Resetter(
+                [this] () {
+                    Application::SetSettings(this->m_aSavedSettings);
+                }));
             AllSettings aSettings(m_aSavedSettings);
             aSettings.SetLanguageTag(LanguageTag("ru"));
             Application::SetSettings(aSettings);
+            return pResetter;
         }
         else if (OString(filename) == "fdo44211.rtf")
         {
+            std::unique_ptr<Resetter> pResetter(new Resetter(
+                [this] () {
+                    Application::SetSettings(this->m_aSavedSettings);
+                }));
             AllSettings aSettings(m_aSavedSettings);
             aSettings.SetLanguageTag(LanguageTag("lt"));
             Application::SetSettings(aSettings);
+            return pResetter;
         }
-    }
-
-    virtual void postTest(const char* filename) SAL_OVERRIDE
-    {
-        if (OString(filename) == "fdo48023.rtf" || OString(filename) == "fdo72031.rtf" || OString(filename) == "fdo44211.rtf")
-            Application::SetSettings(m_aSavedSettings);
+        return nullptr;
     }
 
 protected:


More information about the Libreoffice-commits mailing list