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>
This commit is contained in:
Tomaž Vajngerl 2024-06-07 10:14:39 +09:00 committed by Tomaž Vajngerl
parent e17c56bfc7
commit c89131d1c6
4 changed files with 280 additions and 3 deletions

View file

@ -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:

View file

@ -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

View file

@ -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;

View file

@ -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: */