From 60ca9c8fd48225069ed6c9c0cbcada4717999724 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Thu, 21 Nov 2024 01:13:38 +0100 Subject: CppunitTest_sd_tiledrendering2: move to tiledrendering folder In preparation for a follow-up commit Change-Id: Ifb3ee72cef3493cb1774c0a0c5ac6b5850309396 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176878 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- sd/CppunitTest_sd_tiledrendering2.mk | 2 +- sd/qa/unit/tiledrendering/data/data/dummy.odp | Bin 0 -> 10763 bytes sd/qa/unit/tiledrendering/tiledrendering2.cxx | 159 +++++++++++++++++++++++++ sd/qa/unit/tiledrendering2/data/dummy.odp | Bin 10763 -> 0 bytes sd/qa/unit/tiledrendering2/tiledrendering2.cxx | 159 ------------------------- 5 files changed, 160 insertions(+), 160 deletions(-) create mode 100644 sd/qa/unit/tiledrendering/data/data/dummy.odp create mode 100644 sd/qa/unit/tiledrendering/tiledrendering2.cxx delete mode 100644 sd/qa/unit/tiledrendering2/data/dummy.odp delete mode 100644 sd/qa/unit/tiledrendering2/tiledrendering2.cxx (limited to 'sd') diff --git a/sd/CppunitTest_sd_tiledrendering2.mk b/sd/CppunitTest_sd_tiledrendering2.mk index 838f13fc3ece..07b867cc1309 100644 --- a/sd/CppunitTest_sd_tiledrendering2.mk +++ b/sd/CppunitTest_sd_tiledrendering2.mk @@ -14,7 +14,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sd_tiledrendering2)) $(eval $(call gb_CppunitTest_use_common_precompiled_header,sd_tiledrendering2)) $(eval $(call gb_CppunitTest_add_exception_objects,sd_tiledrendering2, \ - sd/qa/unit/tiledrendering2/tiledrendering2 \ + sd/qa/unit/tiledrendering/tiledrendering2 \ )) $(eval $(call gb_CppunitTest_use_libraries,sd_tiledrendering2, \ diff --git a/sd/qa/unit/tiledrendering/data/data/dummy.odp b/sd/qa/unit/tiledrendering/data/data/dummy.odp new file mode 100644 index 000000000000..83dee413c5ed Binary files /dev/null and b/sd/qa/unit/tiledrendering/data/data/dummy.odp differ diff --git a/sd/qa/unit/tiledrendering/tiledrendering2.cxx b/sd/qa/unit/tiledrendering/tiledrendering2.cxx new file mode 100644 index 000000000000..a9b0b6e5b8ff --- /dev/null +++ b/sd/qa/unit/tiledrendering/tiledrendering2.cxx @@ -0,0 +1,159 @@ +/* -*- 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/. + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace css; + +namespace +{ +/// Impress tests with comphelper::LibreOfficeKit::isActive() enabled, part 2. +class Test : public UnoApiXmlTest +{ +public: + Test(); + virtual void setUp() override; + virtual void tearDown() override; + +protected: + SdXImpressDocument* createDoc(const char* pName, + const uno::Sequence& rArguments = {}); +}; + +Test::Test() + : UnoApiXmlTest(u"/sd/qa/unit/tiledrendering/data/"_ustr) +{ +} + +void Test::setUp() +{ + UnoApiXmlTest::setUp(); + + comphelper::LibreOfficeKit::setActive(true); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + { + mxComponent->dispose(); + mxComponent.clear(); + } + + comphelper::LibreOfficeKit::setActive(false); + + UnoApiXmlTest::tearDown(); +} + +SdXImpressDocument* Test::createDoc(const char* pName, + const uno::Sequence& rArguments) +{ + loadFromFile(OUString::createFromAscii(pName)); + SdXImpressDocument* pImpressDocument = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pImpressDocument); + pImpressDocument->initializeForTiledRendering(rArguments); + return pImpressDocument; +} + +/// A view callback tracks callbacks invoked on one specific view. +class ViewCallback final +{ + SfxViewShell* mpViewShell; + int mnView; + +public: + std::map m_aStateChanges; + TestLokCallbackWrapper m_callbackWrapper; + + ViewCallback() + : m_callbackWrapper(&callback, this) + { + mpViewShell = SfxViewShell::Current(); + mpViewShell->setLibreOfficeKitViewCallback(&m_callbackWrapper); + mnView = SfxLokHelper::getView(); + m_callbackWrapper.setLOKViewId(mnView); + } + + ~ViewCallback() + { + SfxLokHelper::setView(mnView); + mpViewShell->setLibreOfficeKitViewCallback(nullptr); + } + + static void callback(int nType, const char* pPayload, void* pData) + { + static_cast(pData)->callbackImpl(nType, pPayload); + } + + void callbackImpl(int nType, const char* pPayload) + { + switch (nType) + { + case LOK_CALLBACK_STATE_CHANGED: + { + std::stringstream aStream(pPayload); + if (!aStream.str().starts_with("{")) + { + break; + } + + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + auto it = aTree.find("commandName"); + if (it == aTree.not_found()) + { + break; + } + + std::string aCommandName = it->second.get_value(); + m_aStateChanges[aCommandName] = aTree; + } + break; + } + } +}; + +CPPUNIT_TEST_FIXTURE(Test, testSidebarSwitchDeck) +{ + // Given an impress document, with a visible sidebar (ModifyPage deck): + createDoc("dummy.odp"); + ViewCallback aView; + sfx2::sidebar::Sidebar::Setup(u""); + Scheduler::ProcessEventsToIdle(); + aView.m_aStateChanges.clear(); + + // When switching to the MasterSlidesPanel deck: + dispatchCommand(mxComponent, u".uno:MasterSlidesPanel"_ustr, {}); + + // Then make sure notifications are sent for both the old and the new decks: + auto it = aView.m_aStateChanges.find(".uno:ModifyPage"); + // Without the accompanying fix in place, this test would have failed, the notification for the + // old deck was missing. + CPPUNIT_ASSERT(it != aView.m_aStateChanges.end()); + boost::property_tree::ptree aTree = it->second; + CPPUNIT_ASSERT(aTree.get_child_optional("state").has_value()); + CPPUNIT_ASSERT_EQUAL(std::string("false"), aTree.get_child("state").get_value()); + it = aView.m_aStateChanges.find(".uno:MasterSlidesPanel"); + CPPUNIT_ASSERT(it != aView.m_aStateChanges.end()); +} +} +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/qa/unit/tiledrendering2/data/dummy.odp b/sd/qa/unit/tiledrendering2/data/dummy.odp deleted file mode 100644 index 83dee413c5ed..000000000000 Binary files a/sd/qa/unit/tiledrendering2/data/dummy.odp and /dev/null differ diff --git a/sd/qa/unit/tiledrendering2/tiledrendering2.cxx b/sd/qa/unit/tiledrendering2/tiledrendering2.cxx deleted file mode 100644 index 7abaa222e371..000000000000 --- a/sd/qa/unit/tiledrendering2/tiledrendering2.cxx +++ /dev/null @@ -1,159 +0,0 @@ -/* -*- 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/. - */ - -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include - -using namespace css; - -namespace -{ -/// Impress tests with comphelper::LibreOfficeKit::isActive() enabled, part 2. -class Test : public UnoApiXmlTest -{ -public: - Test(); - virtual void setUp() override; - virtual void tearDown() override; - -protected: - SdXImpressDocument* createDoc(const char* pName, - const uno::Sequence& rArguments = {}); -}; - -Test::Test() - : UnoApiXmlTest(u"/sd/qa/unit/tiledrendering2/data/"_ustr) -{ -} - -void Test::setUp() -{ - UnoApiXmlTest::setUp(); - - comphelper::LibreOfficeKit::setActive(true); -} - -void Test::tearDown() -{ - if (mxComponent.is()) - { - mxComponent->dispose(); - mxComponent.clear(); - } - - comphelper::LibreOfficeKit::setActive(false); - - UnoApiXmlTest::tearDown(); -} - -SdXImpressDocument* Test::createDoc(const char* pName, - const uno::Sequence& rArguments) -{ - loadFromFile(OUString::createFromAscii(pName)); - SdXImpressDocument* pImpressDocument = dynamic_cast(mxComponent.get()); - CPPUNIT_ASSERT(pImpressDocument); - pImpressDocument->initializeForTiledRendering(rArguments); - return pImpressDocument; -} - -/// A view callback tracks callbacks invoked on one specific view. -class ViewCallback final -{ - SfxViewShell* mpViewShell; - int mnView; - -public: - std::map m_aStateChanges; - TestLokCallbackWrapper m_callbackWrapper; - - ViewCallback() - : m_callbackWrapper(&callback, this) - { - mpViewShell = SfxViewShell::Current(); - mpViewShell->setLibreOfficeKitViewCallback(&m_callbackWrapper); - mnView = SfxLokHelper::getView(); - m_callbackWrapper.setLOKViewId(mnView); - } - - ~ViewCallback() - { - SfxLokHelper::setView(mnView); - mpViewShell->setLibreOfficeKitViewCallback(nullptr); - } - - static void callback(int nType, const char* pPayload, void* pData) - { - static_cast(pData)->callbackImpl(nType, pPayload); - } - - void callbackImpl(int nType, const char* pPayload) - { - switch (nType) - { - case LOK_CALLBACK_STATE_CHANGED: - { - std::stringstream aStream(pPayload); - if (!aStream.str().starts_with("{")) - { - break; - } - - boost::property_tree::ptree aTree; - boost::property_tree::read_json(aStream, aTree); - auto it = aTree.find("commandName"); - if (it == aTree.not_found()) - { - break; - } - - std::string aCommandName = it->second.get_value(); - m_aStateChanges[aCommandName] = aTree; - } - break; - } - } -}; - -CPPUNIT_TEST_FIXTURE(Test, testSidebarSwitchDeck) -{ - // Given an impress document, with a visible sidebar (ModifyPage deck): - createDoc("dummy.odp"); - ViewCallback aView; - sfx2::sidebar::Sidebar::Setup(u""); - Scheduler::ProcessEventsToIdle(); - aView.m_aStateChanges.clear(); - - // When switching to the MasterSlidesPanel deck: - dispatchCommand(mxComponent, u".uno:MasterSlidesPanel"_ustr, {}); - - // Then make sure notifications are sent for both the old and the new decks: - auto it = aView.m_aStateChanges.find(".uno:ModifyPage"); - // Without the accompanying fix in place, this test would have failed, the notification for the - // old deck was missing. - CPPUNIT_ASSERT(it != aView.m_aStateChanges.end()); - boost::property_tree::ptree aTree = it->second; - CPPUNIT_ASSERT(aTree.get_child_optional("state").has_value()); - CPPUNIT_ASSERT_EQUAL(std::string("false"), aTree.get_child("state").get_value()); - it = aView.m_aStateChanges.find(".uno:MasterSlidesPanel"); - CPPUNIT_ASSERT(it != aView.m_aStateChanges.end()); -} -} -CPPUNIT_PLUGIN_IMPLEMENT(); - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit