From c89131d1c6dc4fe19f214ec800412c173c2420f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Vajngerl?= Date: Fri, 7 Jun 2024 10:14:39 +0900 Subject: [PATCH] annot: Add tests for annotations - insert, delete, undo/redo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie9d88c15af13fb481bb48c838b3b0ef2f41f11e7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168512 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- sd/CppunitTest_sd_annotation_tests.mk | 78 ++++++++++ sd/Module_sd.mk | 1 + sd/inc/sdpage.hxx | 6 +- sd/qa/unit/AnnotationTest.cxx | 198 ++++++++++++++++++++++++++ 4 files changed, 280 insertions(+), 3 deletions(-) create mode 100644 sd/CppunitTest_sd_annotation_tests.mk create mode 100644 sd/qa/unit/AnnotationTest.cxx diff --git a/sd/CppunitTest_sd_annotation_tests.mk b/sd/CppunitTest_sd_annotation_tests.mk new file mode 100644 index 000000000000..6df4fef04477 --- /dev/null +++ b/sd/CppunitTest_sd_annotation_tests.mk @@ -0,0 +1,78 @@ +# -*- 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_annotation_tests)) + +$(eval $(call gb_CppunitTest_use_externals,sd_annotation_tests,\ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_use_common_precompiled_header,sd_annotation_tests)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sd_annotation_tests, \ + sd/qa/unit/AnnotationTest \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sd_annotation_tests, \ + basegfx \ + comphelper \ + cppu \ + cppuhelper \ + drawinglayer \ + docmodel \ + editeng \ + for \ + forui \ + i18nlangtag \ + sal \ + salhelper \ + sax \ + sd \ + sfx \ + sot \ + subsequenttest \ + svl \ + svt \ + svx \ + svxcore \ + test \ + tl \ + tk \ + ucbhelper \ + unotest \ + utl \ + vcl \ + xo \ +)) + +$(eval $(call gb_CppunitTest_set_include,sd_annotation_tests,\ + -I$(SRCDIR)/sd/source/ui/inc \ + -I$(SRCDIR)/sd/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,sd_annotation_tests)) +$(eval $(call gb_CppunitTest_use_ure,sd_annotation_tests)) +$(eval $(call gb_CppunitTest_use_vcl,sd_annotation_tests)) +$(eval $(call gb_CppunitTest_use_rdb,sd_annotation_tests,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,sd_annotation_tests,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sd_annotation_tests)) + +$(eval $(call gb_CppunitTest_add_arguments,sd_annotation_tests, \ + -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 b606b8a56a9e..29ffccbb89f5 100644 --- a/sd/Module_sd.mk +++ b/sd/Module_sd.mk @@ -52,6 +52,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sd,\ CppunitTest_sd_a11y \ CppunitTest_sd_textfitting_tests \ CppunitTest_sd_theme_tests \ + CppunitTest_sd_annotation_tests \ )) endif diff --git a/sd/inc/sdpage.hxx b/sd/inc/sdpage.hxx index b0cb6f105c46..faf7e9157af7 100644 --- a/sd/inc/sdpage.hxx +++ b/sd/inc/sdpage.hxx @@ -364,11 +364,11 @@ public: */ bool IsPrecious() const { return mbIsPrecious; } - rtl::Reference createAnnotation() override; - void addAnnotation(rtl::Reference const& xAnnotation, int nIndex = -1) override; + SD_DLLPUBLIC rtl::Reference createAnnotation() override; + SD_DLLPUBLIC void addAnnotation(rtl::Reference const& xAnnotation, int nIndex = -1) override; void addAnnotationNoNotify(rtl::Reference const& xAnnotation, int nIndex = -1) override; - void removeAnnotation(rtl::Reference const& xAnnotation) override; + SD_DLLPUBLIC void removeAnnotation(rtl::Reference const& xAnnotation) override; void removeAnnotationNoNotify(rtl::Reference const& xAnnotation) override; bool Equals(const SdPage&) const; diff --git a/sd/qa/unit/AnnotationTest.cxx b/sd/qa/unit/AnnotationTest.cxx new file mode 100644 index 000000000000..36f9ef40d459 --- /dev/null +++ b/sd/qa/unit/AnnotationTest.cxx @@ -0,0 +1,198 @@ +/* -*- 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 "sdmodeltestbase.hxx" + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +using namespace css; + +class AnnotationTest : public SdModelTestBase +{ +public: + AnnotationTest() + : SdModelTestBase("/sd/qa/unit/data/") + { + } +}; + +CPPUNIT_TEST_FIXTURE(AnnotationTest, testAnnotation) +{ + createSdDrawDoc(); + + auto pXImpressDocument = dynamic_cast(mxComponent.get()); + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + + SdPage* pPage = pViewShell->GetActualPage(); + CPPUNIT_ASSERT_EQUAL(size_t(0), pPage->GetObjCount()); + + { + rtl::Reference xAnnotation = pPage->createAnnotation(); + CPPUNIT_ASSERT_EQUAL(size_t(0), pPage->GetObjCount()); + + xAnnotation->setAuthor("A"); + uno::Reference xText(xAnnotation->getTextRange()); + xText->setString("X"); + + xAnnotation->setPosition(geometry::RealPoint2D(0.0, 0.0)); + xAnnotation->setSize(geometry::RealSize2D(10.0, 10.0)); + + pPage->addAnnotation(xAnnotation, -1); + + CPPUNIT_ASSERT_EQUAL(size_t(1), pPage->getAnnotations().size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), pPage->GetObjCount()); + } + + SdrObject* pObject = pPage->GetObj(0); + CPPUNIT_ASSERT_EQUAL(SdrObjKind::Annotation, pObject->GetObjIdentifier()); + + { + rtl::Reference xAnnotation = pPage->createAnnotation(); + CPPUNIT_ASSERT_EQUAL(size_t(1), pPage->GetObjCount()); + + xAnnotation->setAuthor("B"); + uno::Reference xText(xAnnotation->getTextRange()); + xText->setString("XXX"); + + xAnnotation->setPosition(geometry::RealPoint2D(10.0, 10.0)); + xAnnotation->setSize(geometry::RealSize2D(10.0, 10.0)); + sdr::annotation::CreationInfo aInfo; + aInfo.meType = sdr::annotation::AnnotationType::Square; + aInfo.maColor = COL_LIGHTRED; + xAnnotation->setCreationInfo(aInfo); + + pPage->addAnnotation(xAnnotation, -1); + + CPPUNIT_ASSERT_EQUAL(size_t(2), pPage->getAnnotations().size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), pPage->GetObjCount()); + } +} + +CPPUNIT_TEST_FIXTURE(AnnotationTest, testAnnotationInsert) +{ + createSdDrawDoc(); + + auto pXImpressDocument = dynamic_cast(mxComponent.get()); + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + + SdPage* pPage = pViewShell->GetActualPage(); + CPPUNIT_ASSERT_EQUAL(size_t(0), pPage->GetObjCount()); + + dispatchCommand(mxComponent, ".uno:InsertAnnotation", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(size_t(1), pPage->GetObjCount()); + CPPUNIT_ASSERT_EQUAL(size_t(1), pPage->getAnnotations().size()); +} + +CPPUNIT_TEST_FIXTURE(AnnotationTest, testAnnotationDelete) +{ + createSdDrawDoc(); + + auto pXImpressDocument = dynamic_cast(mxComponent.get()); + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + + SdPage* pPage = pViewShell->GetActualPage(); + CPPUNIT_ASSERT_EQUAL(size_t(0), pPage->GetObjCount()); + + dispatchCommand(mxComponent, ".uno:InsertAnnotation", {}); + dispatchCommand(mxComponent, ".uno:InsertAnnotation", {}); + dispatchCommand(mxComponent, ".uno:InsertAnnotation", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(size_t(3), pPage->GetObjCount()); + + sal_uInt32 nID = pPage->getAnnotations().front()->GetId(); + + CPPUNIT_ASSERT_EQUAL(size_t(3), pPage->getAnnotations().size()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 0), pPage->getAnnotations().at(0)->GetId()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 1), pPage->getAnnotations().at(1)->GetId()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 2), pPage->getAnnotations().at(2)->GetId()); + + auto xAnnotation = pPage->getAnnotations().at(1); + + uno::Sequence aPropertyValues(comphelper::InitPropertySequence({ + { "Id", uno::Any(OUString::number(xAnnotation->GetId())) }, + })); + dispatchCommand(mxComponent, ".uno:DeleteAnnotation", aPropertyValues); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(size_t(2), pPage->GetObjCount()); + CPPUNIT_ASSERT_EQUAL(size_t(2), pPage->getAnnotations().size()); + + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 0), pPage->getAnnotations().at(0)->GetId()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 2), pPage->getAnnotations().at(1)->GetId()); +} + +CPPUNIT_TEST_FIXTURE(AnnotationTest, testAnnotationInsertUndoRedo) +{ + createSdDrawDoc(); + + auto pXImpressDocument = dynamic_cast(mxComponent.get()); + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + + SdPage* pPage = pViewShell->GetActualPage(); + CPPUNIT_ASSERT_EQUAL(size_t(0), pPage->GetObjCount()); + + dispatchCommand(mxComponent, ".uno:InsertAnnotation", {}); + dispatchCommand(mxComponent, ".uno:InsertAnnotation", {}); + Scheduler::ProcessEventsToIdle(); + + CPPUNIT_ASSERT_EQUAL(size_t(2), pPage->GetObjCount()); + SdrObject* pObject = pPage->GetObj(0); + CPPUNIT_ASSERT_EQUAL(SdrObjKind::Annotation, pObject->GetObjIdentifier()); + + sal_uInt32 nID = pPage->getAnnotations().front()->GetId(); + + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 0), pPage->getAnnotations().at(0)->GetId()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 1), pPage->getAnnotations().at(1)->GetId()); + + dispatchCommand(mxComponent, ".uno:Undo", {}); + CPPUNIT_ASSERT_EQUAL(size_t(1), pPage->GetObjCount()); + CPPUNIT_ASSERT_EQUAL(size_t(1), pPage->getAnnotations().size()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 0), pPage->getAnnotations().at(0)->GetId()); + + dispatchCommand(mxComponent, ".uno:Redo", {}); + CPPUNIT_ASSERT_EQUAL(size_t(2), pPage->GetObjCount()); + CPPUNIT_ASSERT_EQUAL(size_t(2), pPage->getAnnotations().size()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 0), pPage->getAnnotations().at(0)->GetId()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 1), pPage->getAnnotations().at(1)->GetId()); + + dispatchCommand(mxComponent, ".uno:DeleteAnnotation", {}); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(size_t(1), pPage->GetObjCount()); + CPPUNIT_ASSERT_EQUAL(size_t(1), pPage->getAnnotations().size()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 0), pPage->getAnnotations().at(0)->GetId()); + + dispatchCommand(mxComponent, ".uno:Undo", {}); + Scheduler::ProcessEventsToIdle(); + CPPUNIT_ASSERT_EQUAL(size_t(2), pPage->GetObjCount()); + CPPUNIT_ASSERT_EQUAL(size_t(2), pPage->getAnnotations().size()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 0), pPage->getAnnotations().at(0)->GetId()); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(nID + 1), pPage->getAnnotations().at(1)->GetId()); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */