diff options
author | Michael Stahl <mstahl@redhat.com> | 2016-02-12 15:47:05 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2016-02-12 18:54:32 +0100 |
commit | e2bfae9006e6adc4de17d0167dac6661b002f126 (patch) | |
tree | 1156ea989ef4e83f092d8ef10ea96cf50a8b3033 /sw/qa/extras/inc/swmodeltestbase.hxx | |
parent | 2edfb8d9b4da733a2d825cd5fc791fea5352dffe (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.
Change-Id: I748f9edf15a7f860607ae4cce891450db254c73e
Diffstat (limited to 'sw/qa/extras/inc/swmodeltestbase.hxx')
-rw-r--r-- | sw/qa/extras/inc/swmodeltestbase.hxx | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx index b154efebef6d..95eee3514266 100644 --- a/sw/qa/extras/inc/swmodeltestbase.hxx +++ b/sw/qa/extras/inc/swmodeltestbase.hxx @@ -149,6 +149,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. |