diff --git a/include/unotest/macros_test.hxx b/include/unotest/macros_test.hxx index 663fcf22b68d..7757e1436545 100644 --- a/include/unotest/macros_test.hxx +++ b/include/unotest/macros_test.hxx @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -92,6 +93,11 @@ public: const OUString& rCommand, const css::uno::Sequence& rPropertyValues); + static css::uno::Any + queryDispatchStatus(css::uno::Reference const& xComponent, + css::uno::Reference const& xContext, + OUString const& rURL); + /// Opens rStreamName from rTempFile, assuming it's a ZIP storage. static std::unique_ptr parseExportStream(const OUString& url, const OUString& rStreamName); diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx index b7dfcd739d61..ef5e948d5abf 100644 --- a/sw/qa/extras/layout/layout3.cxx +++ b/sw/qa/extras/layout/layout3.cxx @@ -1833,6 +1833,14 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testHiddenParagraphFollowFrame) { createSwDoc("hidden-para-follow-frame.fodt"); + uno::Any aOldValue{ queryDispatchStatus(mxComponent, m_xContext, ".uno:ShowHiddenParagraphs") }; + + Resetter g([this, aOldValue] { + uno::Sequence argsSH( + comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", aOldValue } })); + dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH); + }); + uno::Sequence argsSH( comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", uno::Any(true) } })); dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH); @@ -1871,6 +1879,14 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testHiddenParagraphFlys) { createSwDoc("hidden-para-as-char-fly.fodt"); + uno::Any aOldValue{ queryDispatchStatus(mxComponent, m_xContext, ".uno:ShowHiddenParagraphs") }; + + Resetter g([this, aOldValue] { + uno::Sequence argsSH( + comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", aOldValue } })); + dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH); + }); + uno::Sequence argsSH( comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", uno::Any(true) } })); dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH); diff --git a/unotest/source/cpp/macros_test.cxx b/unotest/source/cpp/macros_test.cxx index 83df09259d45..f353eba782e5 100644 --- a/unotest/source/cpp/macros_test.cxx +++ b/unotest/source/cpp/macros_test.cxx @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -98,6 +99,62 @@ MacrosTest::dispatchCommand(const uno::Reference& xComponent, return ret; } +namespace +{ +class StateGetter : public ::cppu::WeakImplHelper +{ +public: + uno::Any& m_rOldValue; + bool m_Received{ false }; + StateGetter(uno::Any& rOldValue) + : m_rOldValue(rOldValue) + { + } + + virtual void SAL_CALL disposing(lang::EventObject const&) override + { + CPPUNIT_ASSERT(m_Received); + } + virtual void SAL_CALL statusChanged(frame::FeatureStateEvent const& rEvent) override + { + if (!m_Received) + { + m_rOldValue = rEvent.State; + m_Received = true; + } + } +}; + +} // namespace + +uno::Any MacrosTest::queryDispatchStatus(uno::Reference const& xComponent, + uno::Reference const& xContext, + OUString const& rURL) +{ + uno::Any ret; + + util::URL url; + url.Complete = rURL; + { + uno::Reference const xParser( + css::util::URLTransformer::create(xContext)); + CPPUNIT_ASSERT(xParser.is()); + xParser->parseStrict(url); + } + + uno::Reference const xController + = uno::Reference(xComponent, uno::UNO_QUERY_THROW)->getCurrentController(); + uno::Reference const xFrame(xController->getFrame(), uno::UNO_QUERY); + CPPUNIT_ASSERT(xFrame.is()); + uno::Reference const xDisp(xFrame->queryDispatch(url, "", 0)); + CPPUNIT_ASSERT(xDisp.is()); + + uno::Reference const xListener{ new StateGetter(ret) }; + xDisp->addStatusListener(xListener, url); + + return ret; +} + std::unique_ptr MacrosTest::parseExportStream(const OUString& url, const OUString& rStreamName) {