diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-03-31 11:36:54 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-04-07 09:18:03 +0200 |
commit | f8bd9687e7675641d85effe10898f829c180984a (patch) | |
tree | eb974abfbd3b5e5cff6aab21ea1f29324753b2da /sd/qa | |
parent | android: fix 'make install' in LOAndroid3 (diff) | |
download | core-f8bd9687e7675641d85effe10898f829c180984a.tar.gz core-f8bd9687e7675641d85effe10898f829c180984a.zip |
Add testcase for sd::Window::LogicInvalidate().
Change-Id: I1d2e6ed9691ca43abb18bdf04fcf5a6c73a66f18
Diffstat (limited to 'sd/qa')
-rw-r--r-- | sd/qa/unit/tiledrendering/data/dummy.odp | bin | 0 -> 10303 bytes | |||
-rw-r--r-- | sd/qa/unit/tiledrendering/tiledrendering.cxx | 125 |
2 files changed, 125 insertions, 0 deletions
diff --git a/sd/qa/unit/tiledrendering/data/dummy.odp b/sd/qa/unit/tiledrendering/data/dummy.odp Binary files differnew file mode 100644 index 000000000000..e559de627cec --- /dev/null +++ b/sd/qa/unit/tiledrendering/data/dummy.odp diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx new file mode 100644 index 000000000000..d1e924db3c39 --- /dev/null +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -0,0 +1,125 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#define LOK_USE_UNSTABLE_API +#include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <com/sun/star/frame/Desktop.hpp> +#include <comphelper/processfactory.hxx> +#include <comphelper/string.hxx> +#include <test/bootstrapfixture.hxx> +#include <test/xmltesttools.hxx> +#include <unotest/macros_test.hxx> + +#include <DrawDocShell.hxx> +#include <ViewShell.hxx> +#include <unomodel.hxx> + +using namespace css; + +static const char* DATA_DIRECTORY = "/sd/qa/unit/tiledrendering/data/"; + +class SdTiledRenderingTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools +{ +public: + virtual void setUp() SAL_OVERRIDE; + virtual void tearDown() SAL_OVERRIDE; + + void testRegisterCallback(); + + CPPUNIT_TEST_SUITE(SdTiledRenderingTest); +#if !defined(WNT) && !defined(MACOSX) + CPPUNIT_TEST(testRegisterCallback); +#endif + CPPUNIT_TEST_SUITE_END(); + +private: + SdXImpressDocument* createDoc(const char* pName); + static void callback(int nType, const char* pPayload, void* pData); + void callbackImpl(int nType, const char* pPayload); + + uno::Reference<lang::XComponent> mxComponent; + Rectangle m_aInvalidation; +}; + +void SdTiledRenderingTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory()))); +} + +void SdTiledRenderingTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +SdXImpressDocument* SdTiledRenderingTest::createDoc(const char* pName) +{ + if (mxComponent.is()) + mxComponent->dispose(); + mxComponent = loadFromDesktop(getURLFromSrc(DATA_DIRECTORY) + OUString::createFromAscii(pName), "com.sun.star.presentation.PresentationDocument"); + SdXImpressDocument* pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pImpressDocument); + pImpressDocument->initializeForTiledRendering(); + return pImpressDocument; +} + +void SdTiledRenderingTest::callback(int nType, const char* pPayload, void* pData) +{ + static_cast<SdTiledRenderingTest*>(pData)->callbackImpl(nType, pPayload); +} + +void SdTiledRenderingTest::callbackImpl(int nType, const char* pPayload) +{ + switch (nType) + { + case LOK_CALLBACK_INVALIDATE_TILES: + { + OUString aPayload = OUString::createFromAscii(pPayload); + if (aPayload != "EMPTY" && m_aInvalidation.IsEmpty()) + { + uno::Sequence<OUString> aSeq = comphelper::string::convertCommaSeparated(aPayload); + 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 SdTiledRenderingTest::testRegisterCallback() +{ + // Tests sd::Window::LogicInvalidate(). + SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp"); + pXImpressDocument->registerCallback(&SdTiledRenderingTest::callback, this); + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + + // Append a character to the empty title shape. + vcl::KeyCode aKeyCode(0, 0); + KeyEvent aKeyEvent(static_cast<sal_Unicode>('x'), aKeyCode, 0); + pViewShell->KeyInput(aKeyEvent, 0); + mxComponent->dispose(); + + // Check that the top left 256x256px tile would be invalidated. + CPPUNIT_ASSERT(!m_aInvalidation.IsEmpty()); + Rectangle aTopLeft(0, 0, 256*15, 256*15); // 1 px = 15 twips, assuming 96 DPI. + CPPUNIT_ASSERT(m_aInvalidation.IsOver(aTopLeft)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(SdTiledRenderingTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |