diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-10-21 12:09:56 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-10-22 15:53:21 +0200 |
commit | a21c6a3dd36aee21bf1536183dc8ccde2ff52672 (patch) | |
tree | 4362424f8ba2e52eb7c9c971d51d0ce797594cf4 /sd | |
parent | 71a24a911bb091885fb03d124d3936d955b13399 (diff) |
revert unittests to use plain text-based LibreOfficeKitCallback
At least for now it seems that the more complex
SfxLokCallbackInterface is just an unnecessary complication for unit
tests. The performance doesn't matter, and handling all the
specialized callbacks makes things more complicated. In the future
it'd be also useful to make the tests (optionally?) use also
CallbackFlushHandler as the provider of the messages, in order
to test CallbackFlushHandler more thoroughly, so perhaps in the end
it makes more sense to keep unit tests using the plain text interface.
This reverts unittest-related parts of 3b729db05553c1a6d461fb41c89
and adds a smaller wrapper callback class that converts messages
from SfxLokCallbackInterface to LibreOfficeKitCallback format.
Change-Id: I6c14f0be4ed7b777444b131140be54188d309cca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124000
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/qa/unit/tiledrendering/CallbackRecorder.hxx | 29 | ||||
-rw-r--r-- | sd/qa/unit/tiledrendering/tiledrendering.cxx | 89 |
2 files changed, 63 insertions, 55 deletions
diff --git a/sd/qa/unit/tiledrendering/CallbackRecorder.hxx b/sd/qa/unit/tiledrendering/CallbackRecorder.hxx index 60092ba50ca1..306a90f8d3bd 100644 --- a/sd/qa/unit/tiledrendering/CallbackRecorder.hxx +++ b/sd/qa/unit/tiledrendering/CallbackRecorder.hxx @@ -14,7 +14,7 @@ #include <comphelper/string.hxx> #include <osl/conditn.hxx> #include <sfx2/viewsh.hxx> -#include <sfx2/lokcallback.hxx> +#include <test/lokcallback.hxx> namespace { @@ -45,7 +45,7 @@ void lcl_convertRectangle(const OUString& rString, tools::Rectangle& rRectangle) } } -struct CallbackRecorder : public SfxLokCallbackInterface +struct CallbackRecorder { CallbackRecorder() : m_bFound(true) @@ -53,6 +53,7 @@ struct CallbackRecorder : public SfxLokCallbackInterface , m_nSelectionBeforeSearchResult(0) , m_nSelectionAfterSearchResult(0) , m_nSearchResultCount(0) + , m_callbackWrapper(&callback, this) { } @@ -67,17 +68,24 @@ struct CallbackRecorder : public SfxLokCallbackInterface int m_nSearchResultCount; /// For document size changed callback. osl::Condition m_aDocumentSizeCondition; + TestLokCallbackWrapper m_callbackWrapper; - void libreOfficeKitViewCallback(int nType, const char* pPayload) override + static void callback(int nType, const char* pPayload, void* pData) { - libreOfficeKitViewCallback(nType, pPayload, -1); + static_cast<CallbackRecorder*>(pData)->processCallback(nType, pPayload); } - void libreOfficeKitViewCallback(int nType, const char* pPayload, int /*nViewId*/) override + + void processCallback(int nType, const char* pPayload) { switch (nType) { case LOK_CALLBACK_INVALIDATE_TILES: - abort(); + { + OUString aPayload = OUString::createFromAscii(pPayload); + if (aPayload != "EMPTY" && m_aInvalidation.IsEmpty()) + lcl_convertRectangle(aPayload, m_aInvalidation); + } + break; case LOK_CALLBACK_TEXT_SELECTION: { OUString aPayload = OUString::createFromAscii(pPayload); @@ -131,16 +139,9 @@ struct CallbackRecorder : public SfxLokCallbackInterface } } - virtual void libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect, - int /*nPart*/) override - { - if (pRect != nullptr && m_aInvalidation.IsEmpty()) - m_aInvalidation = *pRect; - } - void registerCallbacksFor(SfxViewShell& rViewShell) { - rViewShell.setLibreOfficeKitViewCallback(this); + rViewShell.setLibreOfficeKitViewCallback(&m_callbackWrapper); } }; diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 2d354dc39b03..e2a0e8a46501 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -18,7 +18,6 @@ #include <boost/property_tree/json_parser.hpp> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <sfx2/lokhelper.hxx> -#include <sfx2/lokcallback.hxx> #include <com/sun/star/frame/Desktop.hpp> #include <comphelper/dispatchcommand.hxx> #include <comphelper/processfactory.hxx> @@ -42,6 +41,7 @@ #include <svx/svdoutl.hxx> #include <unotools/datetime.hxx> #include <tools/UnitConversion.hxx> +#include <test/lokcallback.hxx> #include <DrawDocShell.hxx> #include <ViewShellBase.hxx> @@ -76,7 +76,7 @@ static std::ostream& operator<<(std::ostream& os, ViewShellId id) return os; } -class SdTiledRenderingTest : public SdModelTestBase, public XmlTestTools, public SfxLokCallbackInterface +class SdTiledRenderingTest : public SdModelTestBase, public XmlTestTools { public: SdTiledRenderingTest(); @@ -201,13 +201,10 @@ public: CPPUNIT_TEST(testShapeEditInMultipleViews); CPPUNIT_TEST_SUITE_END(); - virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) override; - virtual void libreOfficeKitViewCallback(int nType, const char* pPayload, int nViewId) override; - virtual void libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect, - int nPart) override; - private: SdXImpressDocument* createDoc(const char* pName, const uno::Sequence<beans::PropertyValue>& rArguments = uno::Sequence<beans::PropertyValue>()); + static void callback(int nType, const char* pPayload, void* pData); + void callbackImpl(int nType, const char* pPayload); xmlDocUniquePtr parseXmlDump(); uno::Reference<lang::XComponent> mxComponent; @@ -223,6 +220,7 @@ private: /// For document size changed callback. osl::Condition m_aDocumentSizeCondition; xmlBufferPtr m_pXmlBuffer; + TestLokCallbackWrapper m_callbackWrapper; }; SdTiledRenderingTest::SdTiledRenderingTest() @@ -230,7 +228,8 @@ SdTiledRenderingTest::SdTiledRenderingTest() m_nPart(0), m_nSelectionBeforeSearchResult(0), m_nSelectionAfterSearchResult(0), - m_pXmlBuffer(nullptr) + m_pXmlBuffer(nullptr), + m_callbackWrapper(&callback, this) { } @@ -269,6 +268,11 @@ SdXImpressDocument* SdTiledRenderingTest::createDoc(const char* pName, const uno return pImpressDocument; } +void SdTiledRenderingTest::callback(int nType, const char* pPayload, void* pData) +{ + static_cast<SdTiledRenderingTest*>(pData)->callbackImpl(nType, pPayload); +} + namespace { @@ -301,17 +305,17 @@ void lcl_convertRectangle(const OUString& rString, ::tools::Rectangle& rRectangl } // end anonymous namespace -void SdTiledRenderingTest::libreOfficeKitViewCallback(int nType, const char* pPayload, int /*nViewId*/) -{ - libreOfficeKitViewCallback(nType, pPayload); // the view id is also included in payload -} - -void SdTiledRenderingTest::libreOfficeKitViewCallback(int nType, const char* pPayload) +void SdTiledRenderingTest::callbackImpl(int nType, const char* pPayload) { switch (nType) { case LOK_CALLBACK_INVALIDATE_TILES: - abort(); + { + OUString aPayload = OUString::createFromAscii(pPayload); + if (aPayload != "EMPTY" && m_aInvalidation.IsEmpty()) + lcl_convertRectangle(aPayload, m_aInvalidation); + } + break; case LOK_CALLBACK_TEXT_SELECTION: { OUString aPayload = OUString::createFromAscii(pPayload); @@ -361,13 +365,6 @@ void SdTiledRenderingTest::libreOfficeKitViewCallback(int nType, const char* pPa } } -void SdTiledRenderingTest::libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect, - int /*nPart*/) -{ - if (pRect != nullptr && m_aInvalidation.IsEmpty()) - m_aInvalidation = *pRect; -} - xmlDocUniquePtr SdTiledRenderingTest::parseXmlDump() { if (m_pXmlBuffer) @@ -407,7 +404,7 @@ void SdTiledRenderingTest::testRegisterCallback() { SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp"); sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); - pViewShell->GetViewShellBase().setLibreOfficeKitViewCallback(this); + pViewShell->GetViewShellBase().setLibreOfficeKitViewCallback(&m_callbackWrapper); // Start text edit of the empty title shape. SdPage* pActualPage = pViewShell->GetActualPage(); @@ -637,7 +634,7 @@ void SdTiledRenderingTest::testInsertDeletePage() { SdXImpressDocument* pXImpressDocument = createDoc("insert-delete.odp"); sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); - pViewShell->GetViewShellBase().setLibreOfficeKitViewCallback(this); + pViewShell->GetViewShellBase().setLibreOfficeKitViewCallback(&m_callbackWrapper); SdDrawDocument* pDoc = pXImpressDocument->GetDocShell()->GetDoc(); CPPUNIT_ASSERT(pDoc); @@ -889,7 +886,7 @@ void SdTiledRenderingTest::testResizeTableColumn() namespace { /// A view callback tracks callbacks invoked on one specific view. -class ViewCallback final : public SfxLokCallbackInterface +class ViewCallback final { SfxViewShell* mpViewShell; int mnView; @@ -908,6 +905,7 @@ public: bool m_bViewSelectionSet; boost::property_tree::ptree m_aCommentCallbackResult; OString m_ShapeSelection; + TestLokCallbackWrapper m_callbackWrapper; ViewCallback() : m_bGraphicSelectionInvalidated(false), @@ -917,10 +915,11 @@ public: m_bCursorVisible(false), m_bViewLock(false), m_bTilesInvalidated(false), - m_bViewSelectionSet(false) + m_bViewSelectionSet(false), + m_callbackWrapper(&callback, this) { mpViewShell = SfxViewShell::Current(); - mpViewShell->setLibreOfficeKitViewCallback(this); + mpViewShell->setLibreOfficeKitViewCallback(&m_callbackWrapper); mnView = SfxLokHelper::getView(); } @@ -930,17 +929,32 @@ public: mpViewShell->setLibreOfficeKitViewCallback(nullptr); } - virtual void libreOfficeKitViewCallback(int nType, const char* pPayload) override + static void callback(int nType, const char* pPayload, void* pData) { - libreOfficeKitViewCallback(nType, pPayload, -1); + static_cast<ViewCallback*>(pData)->callbackImpl(nType, pPayload); } - virtual void libreOfficeKitViewCallback(int nType, const char* pPayload, int nViewId) override + void callbackImpl(int nType, const char* pPayload) { switch (nType) { case LOK_CALLBACK_INVALIDATE_TILES: - abort(); + { + m_bTilesInvalidated = true; + OString text(pPayload); + if (!text.startsWith("EMPTY")) + { + uno::Sequence<OUString> aSeq = comphelper::string::convertCommaSeparated(OUString::createFromAscii(pPayload)); + CPPUNIT_ASSERT(aSeq.getLength() == 4 || aSeq.getLength() == 5); + tools::Rectangle aInvalidationRect; + aInvalidationRect.SetLeft(aSeq[0].toInt32()); + aInvalidationRect.SetTop(aSeq[1].toInt32()); + aInvalidationRect.setWidth(aSeq[2].toInt32()); + aInvalidationRect.setHeight(aSeq[3].toInt32()); + m_aInvalidations.push_back(aInvalidationRect); + } + } + break; case LOK_CALLBACK_GRAPHIC_SELECTION: { m_bGraphicSelectionInvalidated = true; @@ -976,7 +990,7 @@ public: std::stringstream aStream(pPayload); boost::property_tree::ptree aTree; boost::property_tree::read_json(aStream, aTree); - nViewId = aTree.get_child("viewId").get_value<int>(); + int nViewId = aTree.get_child("viewId").get_value<int>(); m_aViewCursorInvalidations[nViewId] = true; } break; @@ -985,7 +999,7 @@ public: std::stringstream aStream(pPayload); boost::property_tree::ptree aTree; boost::property_tree::read_json(aStream, aTree); - nViewId = aTree.get_child("viewId").get_value<int>(); + const int nViewId = aTree.get_child("viewId").get_value<int>(); m_aViewCursorVisibilities[nViewId] = std::string_view("true") == pPayload; } break; @@ -1004,13 +1018,6 @@ public: break; } } - virtual void libreOfficeKitViewInvalidateTilesCallback(const tools::Rectangle* pRect, - int /*nPart*/) override - { - m_bTilesInvalidated = true; - if (pRect != nullptr) - m_aInvalidations.push_back(*pRect); - } }; } @@ -2527,7 +2534,7 @@ void SdTiledRenderingTest::testCutSelectionChange() CPPUNIT_ASSERT(pXImpressDocument); sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); - pViewShell->GetViewShellBase().setLibreOfficeKitViewCallback(this); + pViewShell->GetViewShellBase().setLibreOfficeKitViewCallback(&m_callbackWrapper); Scheduler::ProcessEventsToIdle(); // Select first text object |