sd/CppunitTest_sd_annotation_tests.mk | 78 +++++++++++++ sd/Module_sd.mk | 1 sd/qa/unit/AnnotationTest.cxx | 198 ++++++++++++++++++++++++++++++++++ 3 files changed, 277 insertions(+)
New commits: commit fec3f4bbf0606720d99bf92cbdaa1c18e1c0a570 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Jun 7 10:14:39 2024 +0900 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Jun 18 11:14:47 2024 +0200 annot: Add tests for annotations - insert, delete, undo/redo Change-Id: Ie9d88c15af13fb481bb48c838b3b0ef2f41f11e7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168603 Tested-by: Miklos Vajna <vmik...@collabora.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> 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 b3a825254652..e66dc4bcdb28 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/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 <test/unoapi_test.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/text/XTextRange.hpp> + +#include <comphelper/propertysequence.hxx> +#include <vcl/scheduler.hxx> +#include <svx/unoapi.hxx> +#include <svx/annotation/Annotation.hxx> +#include <svx/svdorect.hxx> +#include <svx/svdview.hxx> + +#include <DrawDocShell.hxx> +#include <unomodel.hxx> +#include <sdpage.hxx> +#include <ViewShell.hxx> + +using namespace css; + +class AnnotationTest : public SdModelTestBase +{ +public: + AnnotationTest() + : SdModelTestBase("/sd/qa/unit/data/") + { + } +}; + +CPPUNIT_TEST_FIXTURE(AnnotationTest, testAnnotation) +{ + createSdDrawDoc(); + + auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get()); + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + + SdPage* pPage = pViewShell->GetActualPage(); + CPPUNIT_ASSERT_EQUAL(size_t(0), pPage->GetObjCount()); + + { + rtl::Reference<sdr::annotation::Annotation> xAnnotation = pPage->createAnnotation(); + CPPUNIT_ASSERT_EQUAL(size_t(0), pPage->GetObjCount()); + + xAnnotation->setAuthor("A"); + uno::Reference<text::XText> 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<sdr::annotation::Annotation> xAnnotation = pPage->createAnnotation(); + CPPUNIT_ASSERT_EQUAL(size_t(1), pPage->GetObjCount()); + + xAnnotation->setAuthor("B"); + uno::Reference<text::XText> 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<SdXImpressDocument*>(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<SdXImpressDocument*>(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<beans::PropertyValue> 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<SdXImpressDocument*>(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: */