diff --git a/sd/CppunitTest_sd_tiledrendering2.mk b/sd/CppunitTest_sd_tiledrendering2.mk new file mode 100644 index 000000000000..838f13fc3ece --- /dev/null +++ b/sd/CppunitTest_sd_tiledrendering2.mk @@ -0,0 +1,71 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# 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/. +# +#************************************************************************* + +$(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 \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sd_tiledrendering2, \ + comphelper \ + cppu \ + cppuhelper \ + drawinglayer \ + editeng \ + sal \ + sfx \ + subsequenttest \ + svl \ + svt \ + svxcore \ + sd \ + test \ + unotest \ + vcl \ + tl \ + utl \ +)) + +$(eval $(call gb_CppunitTest_use_externals,sd_tiledrendering2,\ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_set_include,sd_tiledrendering2,\ + -I$(SRCDIR)/sd/inc \ + -I$(SRCDIR)/sd/source/ui/inc \ + -I$(SRCDIR)/sd/qa/unit \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,sd_tiledrendering2)) + +$(eval $(call gb_CppunitTest_use_ure,sd_tiledrendering2)) +$(eval $(call gb_CppunitTest_use_vcl,sd_tiledrendering2)) + +$(eval $(call gb_CppunitTest_use_rdb,sd_tiledrendering2,services)) + +$(eval $(call gb_CppunitTest_use_configuration,sd_tiledrendering2)) + +$(eval $(call gb_CppunitTest_use_uiconfigs,sd_tiledrendering2, \ + modules/simpress \ + svx \ +)) + + +$(eval $(call gb_CppunitTest_add_arguments,sd_tiledrendering2, \ + -env:arg-env=$(gb_Helper_LIBRARY_PATH_VAR)"$$$${$(gb_Helper_LIBRARY_PATH_VAR)+=$$$$$(gb_Helper_LIBRARY_PATH_VAR)}" \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/sd/Module_sd.mk b/sd/Module_sd.mk index b3a825254652..b606b8a56a9e 100644 --- a/sd/Module_sd.mk +++ b/sd/Module_sd.mk @@ -60,6 +60,7 @@ ifeq ($(OS),LINUX) $(eval $(call gb_Module_add_slowcheck_targets,sd,\ CppunitTest_sd_svg_export_tests \ CppunitTest_sd_tiledrendering \ + CppunitTest_sd_tiledrendering2 \ )) endif endif diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index d270579e6c07..8f0fd9cfc4ae 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -2983,30 +2983,6 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testSidebarHide) CPPUNIT_ASSERT(it != aView.m_aStateChanges.end()); } -CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, 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, ".uno:MasterSlidesPanel", {}); - - // 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 new file mode 100644 index 000000000000..83dee413c5ed Binary files /dev/null and b/sd/qa/unit/tiledrendering2/data/dummy.odp differ diff --git a/sd/qa/unit/tiledrendering2/tiledrendering2.cxx b/sd/qa/unit/tiledrendering2/tiledrendering2.cxx new file mode 100644 index 000000000000..193bc01e4426 --- /dev/null +++ b/sd/qa/unit/tiledrendering2/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("/sd/qa/unit/tiledrendering2/data/") +{ +} + +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, ".uno:MasterSlidesPanel", {}); + + // 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: */