From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- test/source/util/searchdescriptor.cxx | 63 ++++++++++++++++++++++++ test/source/util/xindent.cxx | 54 +++++++++++++++++++++ test/source/util/xmergeable.cxx | 33 +++++++++++++ test/source/util/xrefreshable.cxx | 64 +++++++++++++++++++++++++ test/source/util/xreplaceable.cxx | 85 +++++++++++++++++++++++++++++++++ test/source/util/xreplacedescriptor.cxx | 37 ++++++++++++++ test/source/util/xsearchable.cxx | 65 +++++++++++++++++++++++++ test/source/util/xsearchdescriptor.cxx | 36 ++++++++++++++ 8 files changed, 437 insertions(+) create mode 100644 test/source/util/searchdescriptor.cxx create mode 100644 test/source/util/xindent.cxx create mode 100644 test/source/util/xmergeable.cxx create mode 100644 test/source/util/xrefreshable.cxx create mode 100644 test/source/util/xreplaceable.cxx create mode 100644 test/source/util/xreplacedescriptor.cxx create mode 100644 test/source/util/xsearchable.cxx create mode 100644 test/source/util/xsearchdescriptor.cxx (limited to 'test/source/util') diff --git a/test/source/util/searchdescriptor.cxx b/test/source/util/searchdescriptor.cxx new file mode 100644 index 000000000..d82994558 --- /dev/null +++ b/test/source/util/searchdescriptor.cxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 + +using namespace css; + +namespace apitest +{ +void SearchDescriptor::testSearchDescriptorProperties() +{ + uno::Reference xPS(init(), uno::UNO_QUERY_THROW); + + OUString aPropName; + + aPropName = "SearchBackwards"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchCaseSensitive"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchWords"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchRegularExpression"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchStyles"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchSimilarity"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchSimilarityRelax"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchSimilarityRemove"; + testShortProperty(xPS, aPropName); + + aPropName = "SearchSimilarityAdd"; + testShortProperty(xPS, aPropName); + + aPropName = "SearchSimilarityExchange"; + testShortProperty(xPS, aPropName); + + aPropName = "SearchWildcard"; + testBooleanOptionalProperty(xPS, aPropName); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/util/xindent.cxx b/test/source/util/xindent.cxx new file mode 100644 index 000000000..6b15407f9 --- /dev/null +++ b/test/source/util/xindent.cxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* +* 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 + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XIndent::testIncrementIndent() +{ + uno::Reference xIndent(init(), UNO_QUERY_THROW); + uno::Reference xPropertySet(xIndent, UNO_QUERY_THROW); + uno::Any aAny = xPropertySet->getPropertyValue("ParaIndent"); + sal_Int32 nOldValue = aAny.get(); + + xIndent->incrementIndent(); + + uno::Any aAny2 = xPropertySet->getPropertyValue("ParaIndent"); + sal_Int32 nNewValue = aAny2.get(); + CPPUNIT_ASSERT_MESSAGE("Successfully able to Increment Indent", nOldValue < nNewValue); +} +void XIndent::testDecrementIndent() +{ + uno::Reference xIndent(init(), UNO_QUERY_THROW); + uno::Reference xPropertySet(xIndent, UNO_QUERY_THROW); + xIndent->incrementIndent(); + uno::Any aAny = xPropertySet->getPropertyValue("ParaIndent"); + sal_Int32 nOldValue = aAny.get(); + + xIndent->decrementIndent(); + + uno::Any aAny2 = xPropertySet->getPropertyValue("ParaIndent"); + sal_Int32 nNewValue = aAny2.get(); + CPPUNIT_ASSERT_MESSAGE("Successfully able to Decrement Indent", nOldValue > nNewValue); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/util/xmergeable.cxx b/test/source/util/xmergeable.cxx new file mode 100644 index 000000000..211b2b67f --- /dev/null +++ b/test/source/util/xmergeable.cxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* +* 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 + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XMergeable::testGetIsMergedMerge() +{ + uno::Reference xMergeable(init(), UNO_QUERY_THROW); + bool aIsMerged = xMergeable->getIsMerged(); + xMergeable->merge(!aIsMerged); + bool aIsMerged2 = xMergeable->getIsMerged(); + CPPUNIT_ASSERT_MESSAGE("Successfully able to Get is Merged and Merge", aIsMerged != aIsMerged2); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/util/xrefreshable.cxx b/test/source/util/xrefreshable.cxx new file mode 100644 index 000000000..f448d93e5 --- /dev/null +++ b/test/source/util/xrefreshable.cxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +namespace +{ +class MockedRefreshListener : public ::cppu::WeakImplHelper +{ +public: + MockedRefreshListener() + : m_bListenerCalled(false) + { + } + + bool m_bListenerCalled; + virtual void SAL_CALL refreshed(const lang::EventObject& /* xEvent */) override + { + m_bListenerCalled = true; + } + virtual void SAL_CALL disposing(const lang::EventObject& /* xEventObj */) override {} +}; +} + +void XRefreshable::testRefreshListener() +{ + uno::Reference xRefreshable(init(), uno::UNO_QUERY_THROW); + + rtl::Reference xListener = new MockedRefreshListener(); + xRefreshable->addRefreshListener(uno::Reference(xListener.get())); + + xRefreshable->refresh(); + CPPUNIT_ASSERT(xListener->m_bListenerCalled); + + xListener->m_bListenerCalled = false; + xRefreshable->removeRefreshListener(uno::Reference(xListener.get())); + xRefreshable->refresh(); + CPPUNIT_ASSERT(!xListener->m_bListenerCalled); +} + +} // namespace apitest +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/util/xreplaceable.cxx b/test/source/util/xreplaceable.cxx new file mode 100644 index 000000000..ac9d1a4dc --- /dev/null +++ b/test/source/util/xreplaceable.cxx @@ -0,0 +1,85 @@ +/* -*- 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 + +using namespace css; +using namespace css::uno; + +namespace apitest { + +void XReplaceable::testCreateReplaceDescriptor() +{ + uno::Reference< util::XReplaceable > xReplaceable(init(), UNO_QUERY_THROW); + uno::Reference< util::XReplaceDescriptor> xReplaceDescr = xReplaceable->createReplaceDescriptor(); + CPPUNIT_ASSERT(xReplaceDescr.is()); +} + +void XReplaceable::testReplaceAll() +{ + std::cout << "testReplaceAll" << std::endl; + uno::Reference< util::XReplaceable > xReplaceable(init(), UNO_QUERY_THROW); + uno::Reference< util::XReplaceDescriptor> xReplaceDescr = xReplaceable->createReplaceDescriptor(); + CPPUNIT_ASSERT(xReplaceDescr.is()); + + uno::Reference< util::XSearchDescriptor > xSearchDescr = xReplaceable->createSearchDescriptor(); + xSearchDescr->setSearchString(maSearchString); + + //check that at least one object is there that will be replaced + uno::Reference< uno::XInterface > xElement = xReplaceable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(xElement.is()); + + //check that there is none object with the replace string + xSearchDescr->setSearchString(maReplaceString); + xElement = xReplaceable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(!xElement.is()); + + xReplaceDescr->setSearchString(maSearchString); + xReplaceDescr->setReplaceString(maReplaceString); + + callgrindStart(); + xReplaceable->replaceAll(uno::Reference< util::XSearchDescriptor >(xReplaceDescr, UNO_QUERY_THROW)); + callgrindDump("test:replace_all"); + + //check that now at least one element is found + xElement = xReplaceable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(xElement.is()); + + xSearchDescr->setSearchString(maSearchString); + xElement = xReplaceable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(!xElement.is()); + + //redo the whole thing + xReplaceDescr->setSearchString(maReplaceString); + xReplaceDescr->setReplaceString(maSearchString); + + xReplaceable->replaceAll(uno::Reference< util::XSearchDescriptor >(xReplaceDescr, UNO_QUERY_THROW)); + + //check that it works + xElement = xReplaceable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(xElement.is()); + + //check that there is none object with the replace string + xSearchDescr->setSearchString(maReplaceString); + xElement = xReplaceable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(!xElement.is()); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/util/xreplacedescriptor.cxx b/test/source/util/xreplacedescriptor.cxx new file mode 100644 index 000000000..b3b042a2d --- /dev/null +++ b/test/source/util/xreplacedescriptor.cxx @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 + +using namespace css; + +namespace apitest +{ +void XReplaceDescriptor::testGetSetReplaceString() +{ + uno::Reference xRD(init(), uno::UNO_QUERY_THROW); + const OUString aReplaceStringOld = xRD->getReplaceString(); + CPPUNIT_ASSERT(aReplaceStringOld.isEmpty()); + + xRD->setReplaceString("_XReplaceDescriptor"); + const OUString aReplaceStringNew = xRD->getReplaceString(); + CPPUNIT_ASSERT_EQUAL(OUString("_XReplaceDescriptor"), aReplaceStringNew); + CPPUNIT_ASSERT(aReplaceStringOld != aReplaceStringNew); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/util/xsearchable.cxx b/test/source/util/xsearchable.cxx new file mode 100644 index 000000000..b636377d8 --- /dev/null +++ b/test/source/util/xsearchable.cxx @@ -0,0 +1,65 @@ +/* -*- 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 + +using namespace css; +using namespace css::uno; + +namespace apitest { + +void XSearchable::testFindAll() +{ + uno::Reference< util::XSearchable > xSearchable(init(), UNO_QUERY_THROW); + uno::Reference< util::XSearchDescriptor> xSearchDescr = xSearchable->createSearchDescriptor(); + xSearchDescr->setSearchString(maSearchString); + + uno::Reference< container::XIndexAccess > xIndex = xSearchable->findAll(xSearchDescr); + CPPUNIT_ASSERT(xIndex.is()); + CPPUNIT_ASSERT_EQUAL(mnCount, xIndex->getCount()); +} + +void XSearchable::testFindFirst() +{ + uno::Reference< util::XSearchable > xSearchable(init(), UNO_QUERY_THROW); + uno::Reference< util::XSearchDescriptor> xSearchDescr = xSearchable->createSearchDescriptor(); + xSearchDescr->setSearchString(maSearchString); + + uno::Reference< uno::XInterface > xElement = xSearchable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(xElement.is()); +} + +void XSearchable::testFindNext() +{ + uno::Reference< util::XSearchable > xSearchable(init(), UNO_QUERY_THROW); + uno::Reference< util::XSearchDescriptor> xSearchDescr = xSearchable->createSearchDescriptor(); + xSearchDescr->setSearchString(maSearchString); + + uno::Reference< uno::XInterface > xElement = xSearchable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(xElement.is()); + + if (mnCount > 1) + { + uno::Reference< uno::XInterface > xElement2 = xSearchable->findNext(xElement, xSearchDescr); + CPPUNIT_ASSERT(xElement2.is()); + } +} + +XSearchable::~XSearchable() +{ +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/util/xsearchdescriptor.cxx b/test/source/util/xsearchdescriptor.cxx new file mode 100644 index 000000000..2740b2e26 --- /dev/null +++ b/test/source/util/xsearchdescriptor.cxx @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 + +using namespace css; + +namespace apitest +{ +void XSearchDescriptor::testGetSetSearchString() +{ + uno::Reference xDS(init(), uno::UNO_QUERY_THROW); + const OUString aSearchStringOld = xDS->getSearchString(); + CPPUNIT_ASSERT(aSearchStringOld.isEmpty()); + + xDS->setSearchString("_XSearchDescriptor"); + const OUString aSearchStringNew = xDS->getSearchString(); + CPPUNIT_ASSERT_EQUAL(OUString("_XSearchDescriptor"), aSearchStringNew); + CPPUNIT_ASSERT(aSearchStringOld != aSearchStringNew); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit v1.2.3