Kaydet (Commit) b3ef2a7f authored tarafından Miklos Vajna's avatar Miklos Vajna

Add SwXTextDocument::registerCallback() testcase.

Change-Id: I435bb683bae1634f156b3912e6120d479a917b00
üst 82bc3505
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <swmodeltestbase.hxx> #include <swmodeltestbase.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <comphelper/string.hxx>
#include <svx/svdpage.hxx> #include <svx/svdpage.hxx>
#include <svx/svdview.hxx> #include <svx/svdview.hxx>
#include <crsskip.hxx> #include <crsskip.hxx>
...@@ -20,14 +21,15 @@ static const char* DATA_DIRECTORY = "/sw/qa/extras/tiledrendering/data/"; ...@@ -20,14 +21,15 @@ static const char* DATA_DIRECTORY = "/sw/qa/extras/tiledrendering/data/";
/// Testsuite for the SwXTextDocument methods implementing the vcl::ITiledRenderable interface. /// Testsuite for the SwXTextDocument methods implementing the vcl::ITiledRenderable interface.
class SwTiledRenderingTest : public SwModelTestBase class SwTiledRenderingTest : public SwModelTestBase
{ {
public: public:
void testRegisterCallback();
void testPostMouseEvent(); void testPostMouseEvent();
void testSetTextSelection(); void testSetTextSelection();
void testSetGraphicSelection(); void testSetGraphicSelection();
void testResetSelection(); void testResetSelection();
CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST_SUITE(SwTiledRenderingTest);
CPPUNIT_TEST(testRegisterCallback);
CPPUNIT_TEST(testPostMouseEvent); CPPUNIT_TEST(testPostMouseEvent);
CPPUNIT_TEST(testSetTextSelection); CPPUNIT_TEST(testSetTextSelection);
CPPUNIT_TEST(testSetGraphicSelection); CPPUNIT_TEST(testSetGraphicSelection);
...@@ -36,6 +38,9 @@ public: ...@@ -36,6 +38,9 @@ public:
private: private:
SwXTextDocument* createDoc(const char* pName); 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) SwXTextDocument* SwTiledRenderingTest::createDoc(const char* pName)
...@@ -48,6 +53,45 @@ SwXTextDocument* SwTiledRenderingTest::createDoc(const char* pName) ...@@ -48,6 +53,45 @@ SwXTextDocument* SwTiledRenderingTest::createDoc(const char* pName)
return pTextDocument; 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() void SwTiledRenderingTest::testPostMouseEvent()
{ {
SwXTextDocument* pXTextDocument = createDoc("dummy.fodt"); SwXTextDocument* pXTextDocument = createDoc("dummy.fodt");
......
...@@ -3179,6 +3179,8 @@ void SwXTextDocument::initializeForTiledRendering() ...@@ -3179,6 +3179,8 @@ void SwXTextDocument::initializeForTiledRendering()
void SwXTextDocument::registerCallback(LibreOfficeKitCallback pCallback, void* pData) void SwXTextDocument::registerCallback(LibreOfficeKitCallback pCallback, void* pData)
{ {
SolarMutexGuard aGuard;
SwDoc* pDoc = pDocShell->GetDoc(); SwDoc* pDoc = pDocShell->GetDoc();
SwViewShell* pViewShell = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell(); SwViewShell* pViewShell = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
pViewShell->registerLibreOfficeKitCallback(pCallback, pData); pViewShell->registerLibreOfficeKitCallback(pCallback, pData);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment