sw/qa/extras/tiledrendering/tiledrendering.cxx | 46 ++++++++++++++++++++++++- sw/source/uibase/uno/unotxdoc.cxx | 2 + 2 files changed, 47 insertions(+), 1 deletion(-)
New commits: commit 20d26e398a8fa67f39696d2d82c69399df546c1f Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Tue Mar 17 16:12:26 2015 +0100 Add SwXTextDocument::registerCallback() testcase. Change-Id: I435bb683bae1634f156b3912e6120d479a917b00 diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 2b28b7c..9bc1537 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -9,6 +9,7 @@ #include <swmodeltestbase.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <comphelper/string.hxx> #include <svx/svdpage.hxx> #include <svx/svdview.hxx> #include <crsskip.hxx> @@ -20,14 +21,15 @@ static const char* DATA_DIRECTORY = "/sw/qa/extras/tiledrendering/data/"; /// Testsuite for the SwXTextDocument methods implementing the vcl::ITiledRenderable interface. class SwTiledRenderingTest : public SwModelTestBase { - public: + void testRegisterCallback(); void testPostMouseEvent(); void testSetTextSelection(); void testSetGraphicSelection(); void testResetSelection(); CPPUNIT_TEST_SUITE(SwTiledRenderingTest); + CPPUNIT_TEST(testRegisterCallback); CPPUNIT_TEST(testPostMouseEvent); CPPUNIT_TEST(testSetTextSelection); CPPUNIT_TEST(testSetGraphicSelection); @@ -36,6 +38,9 @@ public: private: SwXTextDocument* createDoc(const char* pName); + static void callback(int nType, const char* pPayload, void* pData); + void callbackImpl(int nType, const char* pPayload); + Rectangle m_aInvalidation; }; SwXTextDocument* SwTiledRenderingTest::createDoc(const char* pName) @@ -48,6 +53,45 @@ SwXTextDocument* SwTiledRenderingTest::createDoc(const char* pName) return pTextDocument; } +void SwTiledRenderingTest::callback(int nType, const char* pPayload, void* pData) +{ + static_cast<SwTiledRenderingTest*>(pData)->callbackImpl(nType, pPayload); +} + +void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload) +{ + switch (nType) + { + case LOK_CALLBACK_INVALIDATE_TILES: + { + if (m_aInvalidation.IsEmpty()) + { + uno::Sequence<OUString> aSeq = comphelper::string::convertCommaSeparated(OUString::createFromAscii(pPayload)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), aSeq.getLength()); + m_aInvalidation.setX(aSeq[0].toInt32()); + m_aInvalidation.setY(aSeq[1].toInt32()); + m_aInvalidation.setWidth(aSeq[2].toInt32()); + m_aInvalidation.setHeight(aSeq[3].toInt32()); + } + } + break; + } +} + +void SwTiledRenderingTest::testRegisterCallback() +{ + SwXTextDocument* pXTextDocument = createDoc("dummy.fodt"); + pXTextDocument->registerCallback(&SwTiledRenderingTest::callback, this); + SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); + // Insert a character at the begining of the document. + pWrtShell->Insert("x"); + + // Check that the top left 256x256px tile would be invalidated. + Rectangle aTopLeft(0, 0, 256*15, 256*15); // 1 px = 15 twips, assuming 96 DPI. + CPPUNIT_ASSERT(!m_aInvalidation.IsEmpty()); + CPPUNIT_ASSERT(m_aInvalidation.IsOver(aTopLeft)); +} + void SwTiledRenderingTest::testPostMouseEvent() { SwXTextDocument* pXTextDocument = createDoc("dummy.fodt"); diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index e806a50..e818ffe 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3175,6 +3175,8 @@ void SwXTextDocument::initializeForTiledRendering() void SwXTextDocument::registerCallback(LibreOfficeKitCallback pCallback, void* pData) { + SolarMutexGuard aGuard; + SwDoc* pDoc = pDocShell->GetDoc(); SwViewShell* pViewShell = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell(); pViewShell->registerLibreOfficeKitCallback(pCallback, pData); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits