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 3c9ae60c35a6f87f6167bcfe29f133670978d984 Author: Michael Stahl <mst...@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. Change-Id: I748f9edf15a7f860607ae4cce891450db254c73e (cherry picked from commit e2bfae9006e6adc4de17d0167dac6661b002f126) Reviewed-on: https://gerrit.libreoffice.org/22333 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Markus Mohrhard <markus.mohrh...@googlemail.com> diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 74d6bd1..c9d20e1 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) override + virtual std::unique_ptr<Resetter> preTest(const char* filename) 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) 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 273bdfc..9098d2b 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: @@ -193,7 +218,7 @@ protected: { maTempFile.EnableKillingFile(false); header(); - preTest(filename); + std::unique_ptr<Resetter> const pChanges(preTest(filename)); load(mpTestDocumentPath, filename); postTest(filename); verify(); @@ -211,7 +236,7 @@ protected: { maTempFile.EnableKillingFile(false); header(); - preTest(filename); + std::unique_ptr<Resetter> const pChanges(preTest(filename)); load(mpTestDocumentPath, filename); postLoad(filename); reload(mpFilter, filename); @@ -231,7 +256,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); @@ -259,8 +284,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 04d1d3c..e61c08a 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -56,24 +56,24 @@ public: return std::find(aBlacklist.begin(), aBlacklist.end(), filename) == aBlacklist.end(); } - virtual void preTest(const char* pFilename) override + virtual std::unique_ptr<Resetter> preTest(const char* pFilename) 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) 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 2151d55..b2c48e7 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -89,17 +89,20 @@ public: { } - virtual void preTest(const char* filename) override + virtual std::unique_ptr<Resetter> preTest(const char* filename) 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) 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 f466361..0c6bd4b 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) override + virtual std::unique_ptr<Resetter> preTest(const char* filename) 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) override - { - if (OString(filename) == "fdo48023.rtf" || OString(filename) == "fdo72031.rtf" || OString(filename) == "fdo44211.rtf") - Application::SetSettings(m_aSavedSettings); + return nullptr; } protected: _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits