summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2016-02-12 15:47:05 +0100
committerAndras Timar <andras.timar@collabora.com>2016-02-22 08:58:13 +0100
commit70b0751d51492acf83f66060241d2352e52e715b (patch)
tree33659e0d1c0f35ab71805078700b5dec684be8d9
parentc6fe577cc579cc0ae5f0a7d63bc86b1718eddeeb (diff)
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@libreoffice.org> Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> (cherry picked from commit 938ddc33ed55579ea40d25bd9cd5704d31b0034e)
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx18
-rw-r--r--sw/qa/extras/inc/swmodeltestbase.hxx34
-rw-r--r--sw/qa/extras/odfexport/odfexport.cxx22
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport.cxx15
-rw-r--r--sw/qa/extras/rtfimport/rtfimport.cxx19
5 files changed, 71 insertions, 37 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 2ce1040b2d16..4f24c351c0c6 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 879c4f96d647..e34d76fcbee4 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 0e106facbbf2..2506ec3160a3 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 424e5f6d120c..384bc3e24f7f 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 67efc3dd1122..16e0c4bddb77 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: