summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-06-07 10:14:39 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-06-11 12:48:58 +0200
commitc89131d1c6dc4fe19f214ec800412c173c2420f0 (patch)
treeaa9a3738b86f25d318ead0e5f190e00be489ee0a /sd
parente17c56bfc7930d3c14c3ff4cfd59828e8dcc0229 (diff)
annot: Add tests for annotations - insert, delete, undo/redo
Change-Id: Ie9d88c15af13fb481bb48c838b3b0ef2f41f11e7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168512 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sd')
-rw-r--r--sd/CppunitTest_sd_annotation_tests.mk78
-rw-r--r--sd/Module_sd.mk1
-rw-r--r--sd/inc/sdpage.hxx6
-rw-r--r--sd/qa/unit/AnnotationTest.cxx198
4 files changed, 280 insertions, 3 deletions
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<sdr::annotation::Annotation> createAnnotation() override;
- void addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, int nIndex = -1) override;
+ SD_DLLPUBLIC rtl::Reference<sdr::annotation::Annotation> createAnnotation() override;
+ SD_DLLPUBLIC void addAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, int nIndex = -1) override;
void addAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation, int nIndex = -1) override;
- void removeAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation) override;
+ SD_DLLPUBLIC void removeAnnotation(rtl::Reference<sdr::annotation::Annotation> const& xAnnotation) override;
void removeAnnotationNoNotify(rtl::Reference<sdr::annotation::Annotation> 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 <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: */