sw/CppunitTest_sw_apitests.mk | 3 sw/qa/api/SwXFieldEnumeration.cxx | 109 ++++++++++++++++++++++++++++++ sw/qa/api/SwXFrames.cxx | 90 +++++++++++++++++++++++++ sw/qa/api/SwXNumberingRules.cxx | 134 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 336 insertions(+)
New commits: commit 73367f09716f5709264885486a2bb03626d39884 Author: anfanite396 <[email protected]> AuthorDate: Tue Jul 11 21:05:30 2023 +0530 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Fri Jul 14 03:13:35 2023 +0200 Move SwXNumberingRules Java tests to C++ Change-Id: I3f5b1b6ce5ed475ef923f2c605c6ada7d29e0439 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154336 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/sw/CppunitTest_sw_apitests.mk b/sw/CppunitTest_sw_apitests.mk index e0af4cb0b29d..659b582b49c0 100644 --- a/sw/CppunitTest_sw_apitests.mk +++ b/sw/CppunitTest_sw_apitests.mk @@ -32,6 +32,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sw_apitests, \ sw/qa/api/SwXFootnoteText \ sw/qa/api/SwXFootnotes \ sw/qa/api/SwXHeadFootText \ + sw/qa/api/SwXNumberingRules \ sw/qa/api/SwXStyleFamilies \ sw/qa/api/SwXTextFrame \ sw/qa/api/SwXTextField \ diff --git a/sw/qa/api/SwXNumberingRules.cxx b/sw/qa/api/SwXNumberingRules.cxx new file mode 100644 index 000000000000..74febc1c027a --- /dev/null +++ b/sw/qa/api/SwXNumberingRules.cxx @@ -0,0 +1,134 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/beans/xpropertyset.hxx> +#include <test/container/xindexaccess.hxx> + +#include <com/sun/star/frame/Desktop.hpp> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/text/ControlCharacter.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> + +using namespace css; +using namespace css::uno; + +namespace +{ +/** + * Initial tests for SwXNumberingRules. + */ +class SwXNumberingRules final : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XPropertySet +{ +public: + SwXNumberingRules() + : UnoApiTest("") + , XElementAccess(cppu::UnoType<Sequence<beans::PropertyValue>>::get()) + , XIndexAccess(10) + { + } + + virtual void setUp() override + { + UnoApiTest::setUp(); + mxDesktop.set(frame::Desktop::create(mxComponentContext)); + mxComponent = loadFromDesktop("private:factory/swriter"); + CPPUNIT_ASSERT(mxComponent.is()); + } + + Reference<XInterface> init() override + { + Reference<text::XTextDocument> xTextDocument(mxComponent, UNO_QUERY_THROW); + + Reference<container::XIndexAccess> xIndexAccess; + Reference<container::XIndexAccess> xNumRules; + + Reference<text::XText> xText = xTextDocument->getText(); + Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + + try + { + xText->insertString(xCursor, "The quick brown fox jumps over the lazy dog", false); + xText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, false); + } + catch (lang::IllegalArgumentException&) + { + } + + Reference<style::XStyleFamiliesSupplier> xStyleFam(xTextDocument, UNO_QUERY_THROW); + + try + { + Reference<container::XNameAccess> xStyleFamNames = xStyleFam->getStyleFamilies(); + Reference<container::XNameContainer> xNumStyles( + xStyleFamNames->getByName("NumberingStyles"), UNO_QUERY_THROW); + xIndexAccess = Reference<container::XIndexAccess>(xNumStyles, UNO_QUERY_THROW); + } + catch (lang::WrappedTargetException&) + { + } + catch (container::NoSuchElementException&) + { + } + catch (lang::IllegalArgumentException&) + { + } + + try + { + Reference<beans::XPropertySet> xPropSet(xIndexAccess->getByIndex(0), UNO_QUERY_THROW); + xNumRules = Reference<container::XIndexAccess>( + xPropSet->getPropertyValue("NumberingRules"), UNO_QUERY_THROW); + } + catch (lang::WrappedTargetException&) + { + } + catch (lang::IndexOutOfBoundsException&) + { + } + catch (beans::UnknownPropertyException&) + { + } + catch (lang::IllegalArgumentException&) + { + } + + return Reference<XInterface>(xNumRules, UNO_QUERY_THROW); + } + + CPPUNIT_TEST_SUITE(SwXNumberingRules); + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + CPPUNIT_TEST(testGetCount); + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST(testGetPropertySetInfo); + CPPUNIT_TEST(testSetPropertyValue); + CPPUNIT_TEST(testGetPropertyValue); + CPPUNIT_TEST(testPropertyChangeListener); + CPPUNIT_TEST(testVetoableChangeListener); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(SwXNumberingRules); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 9460302fdda20fa83e795e84a9d8234ac78b0fd2 Author: anfanite396 <[email protected]> AuthorDate: Tue Jul 11 16:53:43 2023 +0530 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Fri Jul 14 03:13:29 2023 +0200 Move SwXFrames Java tests to C++ Change-Id: I92276f7b0b6537ebf2c5b4d554be1759c09e9544 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154299 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/sw/CppunitTest_sw_apitests.mk b/sw/CppunitTest_sw_apitests.mk index 7d44286f60cb..e0af4cb0b29d 100644 --- a/sw/CppunitTest_sw_apitests.mk +++ b/sw/CppunitTest_sw_apitests.mk @@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sw_apitests, \ sw/qa/api/SwXDocumentIndexMark \ sw/qa/api/SwXDocumentSettings \ sw/qa/api/SwXFieldEnumeration \ + sw/qa/api/SwXFrames \ sw/qa/api/SwXFootnote \ sw/qa/api/SwXFootnoteProperties \ sw/qa/api/SwXFootnoteText \ diff --git a/sw/qa/api/SwXFrames.cxx b/sw/qa/api/SwXFrames.cxx new file mode 100644 index 000000000000..18bc2e204763 --- /dev/null +++ b/sw/qa/api/SwXFrames.cxx @@ -0,0 +1,90 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/container/xelementaccess.hxx> +#include <test/container/xindexaccess.hxx> +#include <test/container/xnameaccess.hxx> + +#include <com/sun/star/frame/Desktop.hpp> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextFrame.hpp> +#include <com/sun/star/text/XTextFramesSupplier.hpp> + +using namespace css; +using namespace css::uno; + +namespace +{ +/** + * Initial tests for SwXFramesText. + */ +class SwXFramesText final : public UnoApiTest, + public apitest::XElementAccess, + public apitest::XIndexAccess, + public apitest::XNameAccess +{ +public: + SwXFramesText() + : UnoApiTest("") + , XElementAccess(cppu::UnoType<text::XTextFrame>::get()) + , XIndexAccess(1) + , XNameAccess("Frame1") + { + } + + virtual void setUp() override + { + UnoApiTest::setUp(); + mxDesktop.set(frame::Desktop::create(mxComponentContext)); + mxComponent = loadFromDesktop("private:factory/swriter"); + CPPUNIT_ASSERT(mxComponent.is()); + } + + Reference<XInterface> init() override + { + Reference<text::XTextDocument> xTextDocument(mxComponent, UNO_QUERY_THROW); + Reference<lang::XMultiServiceFactory> xMSF(mxComponent, UNO_QUERY_THROW); + + Reference<text::XTextFrame> xTextFrame(xMSF->createInstance("com.sun.star.text.TextFrame"), + UNO_QUERY_THROW); + + Reference<text::XText> xText = xTextDocument->getText(); + Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + + xText->insertTextContent(xCursor, xTextFrame, false); + + Reference<text::XTextFramesSupplier> xSupplier(xTextDocument, UNO_QUERY_THROW); + + // Reference<container::XNameAccess> xNA = xSupplier->getTextFrames(); + // Sequence<OUString> aNames = xNA->getElementNames(); + // std::cout << aNames[0] << std::endl; + + return Reference<XInterface>(xSupplier->getTextFrames(), UNO_QUERY_THROW); + } + + CPPUNIT_TEST_SUITE(SwXFramesText); + CPPUNIT_TEST(testGetByName); + CPPUNIT_TEST(testGetElementNames); + CPPUNIT_TEST(testHasByName); + CPPUNIT_TEST(testGetElementType); + CPPUNIT_TEST(testHasElements); + CPPUNIT_TEST(testGetCount); + CPPUNIT_TEST(testGetByIndex); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(SwXFramesText); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 979bdded307531f8b6a930a6515c675d9445de65 Author: anfanite396 <[email protected]> AuthorDate: Tue Jul 11 16:08:57 2023 +0530 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Fri Jul 14 03:13:20 2023 +0200 Move SwXFieldEnumeration Java tests to C++ Change-Id: I6f1eb42e9284593bcc0db1934f3b14d090349d91 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154298 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/sw/CppunitTest_sw_apitests.mk b/sw/CppunitTest_sw_apitests.mk index c1d323dc5df1..7d44286f60cb 100644 --- a/sw/CppunitTest_sw_apitests.mk +++ b/sw/CppunitTest_sw_apitests.mk @@ -25,6 +25,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sw_apitests, \ sw/qa/api/SwXDocumentIndexes \ sw/qa/api/SwXDocumentIndexMark \ sw/qa/api/SwXDocumentSettings \ + sw/qa/api/SwXFieldEnumeration \ sw/qa/api/SwXFootnote \ sw/qa/api/SwXFootnoteProperties \ sw/qa/api/SwXFootnoteText \ diff --git a/sw/qa/api/SwXFieldEnumeration.cxx b/sw/qa/api/SwXFieldEnumeration.cxx new file mode 100644 index 000000000000..53c437ed18d3 --- /dev/null +++ b/sw/qa/api/SwXFieldEnumeration.cxx @@ -0,0 +1,109 @@ +/* -*- 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 <test/unoapi_test.hxx> +#include <test/container/xenumeration.hxx> + +#include <com/sun/star/frame/Desktop.hpp> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/text/XDependentTextField.hpp> +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> + +using namespace css; +using namespace css::uno; + +namespace +{ +/** + * Initial tests for SwXFieldEnumeration. + */ +class SwXFieldEnumeration final : public UnoApiTest, public apitest::XEnumeration +{ +public: + SwXFieldEnumeration() + : UnoApiTest("") + { + } + + virtual void setUp() override + { + UnoApiTest::setUp(); + mxDesktop.set(frame::Desktop::create(mxComponentContext)); + mxComponent = loadFromDesktop("private:factory/swriter"); + CPPUNIT_ASSERT(mxComponent.is()); + } + + Reference<XInterface> init() override + { + Reference<text::XTextDocument> xTextDocument(mxComponent, UNO_QUERY_THROW); + Reference<lang::XMultiServiceFactory> xMSF(mxComponent, UNO_QUERY_THROW); + + Reference<beans::XPropertySet> xFieldMaster; + Reference<text::XDependentTextField> xTF; + + try + { + xFieldMaster = Reference<beans::XPropertySet>( + xMSF->createInstance("com.sun.star.text.FieldMaster.Database"), UNO_QUERY_THROW); + xTF = Reference<text::XDependentTextField>( + xMSF->createInstance("com.sun.star.text.TextField.Database"), UNO_QUERY_THROW); + } + catch (Exception&) + { + } + + try + { + xFieldMaster->setPropertyValue("DataBaseName", Any(OUString("Bibliography"))); + xFieldMaster->setPropertyValue("DataTableName", Any(OUString("biblio"))); + xFieldMaster->setPropertyValue("DataColumnName", Any(OUString("Address"))); + } + catch (lang::WrappedTargetException&) + { + } + catch (lang::IllegalArgumentException&) + { + } + catch (beans::UnknownPropertyException&) + { + } + catch (beans::PropertyVetoException&) + { + } + + Reference<text::XText> xText = xTextDocument->getText(); + Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + Reference<text::XTextContent> xTextContent(xTF, UNO_QUERY_THROW); + + xTF->attachTextFieldMaster(xFieldMaster); + xText->insertTextContent(xCursor, xTextContent, false); + + Reference<text::XTextFieldsSupplier> xTFS(xTextDocument, UNO_QUERY_THROW); + Reference<container::XEnumerationAccess> xEnumerationAccess = xTFS->getTextFields(); + + return Reference<XInterface>(xEnumerationAccess->createEnumeration(), UNO_QUERY_THROW); + } + + CPPUNIT_TEST_SUITE(SwXFieldEnumeration); + CPPUNIT_TEST(testHasMoreElements); + CPPUNIT_TEST(testNextElement); + CPPUNIT_TEST_SUITE_END(); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(SwXFieldEnumeration); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
