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/text/baseindex.cxx | 151 +++++++++++++++++++++++++++++ test/source/text/textcontent.cxx | 68 +++++++++++++ test/source/text/textdocumentindex.cxx | 36 +++++++ test/source/text/textdocumentsettings.cxx | 42 ++++++++ test/source/text/textprintersettings.cxx | 39 ++++++++ test/source/text/textsettings.cxx | 153 ++++++++++++++++++++++++++++++ test/source/text/xdocumentindex.cxx | 66 +++++++++++++ test/source/text/xsimpletext.cxx | 76 +++++++++++++++ test/source/text/xtext.cxx | 30 ++++++ test/source/text/xtextcontent.cxx | 58 +++++++++++ test/source/text/xtextfield.cxx | 43 +++++++++ test/source/text/xtextrange.cxx | 61 ++++++++++++ 12 files changed, 823 insertions(+) create mode 100644 test/source/text/baseindex.cxx create mode 100644 test/source/text/textcontent.cxx create mode 100644 test/source/text/textdocumentindex.cxx create mode 100644 test/source/text/textdocumentsettings.cxx create mode 100644 test/source/text/textprintersettings.cxx create mode 100644 test/source/text/textsettings.cxx create mode 100644 test/source/text/xdocumentindex.cxx create mode 100644 test/source/text/xsimpletext.cxx create mode 100644 test/source/text/xtext.cxx create mode 100644 test/source/text/xtextcontent.cxx create mode 100644 test/source/text/xtextfield.cxx create mode 100644 test/source/text/xtextrange.cxx (limited to 'test/source/text') diff --git a/test/source/text/baseindex.cxx b/test/source/text/baseindex.cxx new file mode 100644 index 000000000..79ec57270 --- /dev/null +++ b/test/source/text/baseindex.cxx @@ -0,0 +1,151 @@ +/* -*- 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 +#include +#include + +#include +#include + +namespace +{ +BitmapEx createExampleBitmap() +{ + vcl::bitmap::RawBitmap aRawBitmap(Size(4, 4), 24); + aRawBitmap.SetPixel(0, 0, COL_LIGHTBLUE); + aRawBitmap.SetPixel(0, 1, COL_LIGHTGREEN); + aRawBitmap.SetPixel(1, 0, COL_LIGHTRED); + aRawBitmap.SetPixel(1, 1, COL_LIGHTMAGENTA); + return vcl::bitmap::CreateFromData(std::move(aRawBitmap)); +} + +void writerFileWithBitmap(OUString const& rURL) +{ + BitmapEx aBitmapEx = createExampleBitmap(); + SvFileStream aFileStream(rURL, StreamMode::READ | StreamMode::WRITE); + vcl::PNGWriter aWriter(aBitmapEx); + aWriter.Write(aFileStream); + aFileStream.Seek(STREAM_SEEK_TO_BEGIN); + aFileStream.Close(); +} +} + +namespace apitest +{ +BaseIndex::~BaseIndex() {} + +void BaseIndex::testBaseIndexProperties() +{ + css::uno::Reference xBaseIndex(init(), css::uno::UNO_QUERY_THROW); + testStringProperty(xBaseIndex, "Title", "Value"); + testBooleanProperty(xBaseIndex, "IsProtected"); + + testStringProperty(xBaseIndex, "ParaStyleHeading", "Value"); + testStringProperty(xBaseIndex, "ParaStyleLevel1", "Value"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel2"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel3"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel4"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel5"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel6"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel7"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel8"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel9"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel10"); + testStringOptionalProperty(xBaseIndex, "ParaStyleSeparator"); + + // [property] XTextColumns TextColumns; + { + OUString name = "TextColumns"; + + css::uno::Reference xGetTextColumns; + CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xGetTextColumns); + + xGetTextColumns->setColumnCount(xGetTextColumns->getColumnCount() + 1); + xBaseIndex->setPropertyValue(name, css::uno::makeAny(xGetTextColumns)); + + css::uno::Reference xSetTextColumns; + CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xSetTextColumns); + + //CPPUNIT_ASSERT_EQUAL(xGetTextColumns->getColumnCount(), xSetTextColumns->getColumnCount()); + } + + // [property] com::sun::star::graphic::XGraphic BackGraphic; + // [property] string BackGraphicURL; + { + OUString name = "BackGraphicURL"; + bool bOK = false; + try + { + xBaseIndex->getPropertyValue(name); + } + catch (css::uno::RuntimeException const& /*ex*/) + { + bOK = true; + } + // BackGraphicURL is "set-only" attribute + CPPUNIT_ASSERT_MESSAGE("Expected RuntimeException wasn't thrown", bOK); + + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + writerFileWithBitmap(aTempFile.GetURL()); + + css::uno::Reference xGraphic; + CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic); + CPPUNIT_ASSERT(!xGraphic.is()); + + xBaseIndex->setPropertyValue(name, css::uno::makeAny(aTempFile.GetURL())); + + CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic); + CPPUNIT_ASSERT(xGraphic.is()); + } + + testStringProperty(xBaseIndex, "BackGraphicFilter", "Value"); + + // [property] com::sun::star::style::GraphicLocation BackGraphicLocation; + + testColorProperty(xBaseIndex, "BackColor"); + testBooleanProperty(xBaseIndex, "BackTransparent"); + + // [optional, property] com::sun::star::container::XIndexReplace LevelFormat; + + testBooleanOptionalProperty(xBaseIndex, "CreateFromChapter"); + + // [property] com::sun::star::text::XTextSection ContentSection; + { + OUString name = "ContentSection"; + + css::uno::Reference xGetTextSection; + CPPUNIT_ASSERT_MESSAGE(name.toUtf8().getStr(), + xBaseIndex->getPropertyValue(name) >>= xGetTextSection); + CPPUNIT_ASSERT_EQUAL_MESSAGE(name.toUtf8().getStr(), OUString(""), + xGetTextSection->getAnchor()->getString()); + } + + // [property] com::sun::star::text::XTextSection HeaderSection; + { + OUString name = "HeaderSection"; + + css::uno::Reference xGetTextSection; + if (xBaseIndex->getPropertyValue(name).hasValue()) + CPPUNIT_ASSERT_MESSAGE(name.toUtf8().getStr(), + xBaseIndex->getPropertyValue(name) >>= xGetTextSection); + } +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/textcontent.cxx b/test/source/text/textcontent.cxx new file mode 100644 index 000000000..132981b2a --- /dev/null +++ b/test/source/text/textcontent.cxx @@ -0,0 +1,68 @@ +/* -*- 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 + +using namespace css; + +namespace apitest +{ +void TextContent::testTextContentProperties() +{ + uno::Reference xPS(init(), uno::UNO_QUERY_THROW); + + text::TextContentAnchorType aExpectedTCAT; + CPPUNIT_ASSERT(xPS->getPropertyValue("AnchorType") >>= aExpectedTCAT); + CPPUNIT_ASSERT_EQUAL(m_aExpectedTCAT, aExpectedTCAT); + + try + { + xPS->setPropertyValue("AnchorType", uno::makeAny(m_aNewTCAT)); + text::TextContentAnchorType aNewTCAT; + CPPUNIT_ASSERT(xPS->getPropertyValue("AnchorType") >>= aNewTCAT); + CPPUNIT_ASSERT_EQUAL(m_aNewTCAT, aNewTCAT); + } + catch (const beans::UnknownPropertyException& /* ex */) + { + // ignore if property is optional + } + + uno::Sequence aAnchorTypes; + CPPUNIT_ASSERT(xPS->getPropertyValue("AnchorTypes") >>= aAnchorTypes); + CPPUNIT_ASSERT(aAnchorTypes.hasElements()); + + text::WrapTextMode aExpectedWTM; + CPPUNIT_ASSERT(xPS->getPropertyValue("TextWrap") >>= aExpectedWTM); + CPPUNIT_ASSERT_EQUAL(m_aExpectedWTM, aExpectedWTM); + + try + { + xPS->setPropertyValue("TextWrap", uno::makeAny(m_aNewWTM)); + text::WrapTextMode aNewWTM; + CPPUNIT_ASSERT(xPS->getPropertyValue("TextWrap") >>= aNewWTM); + CPPUNIT_ASSERT_EQUAL(m_aNewWTM, aNewWTM); + } + catch (const beans::UnknownPropertyException& /* ex */) + { + // ignore if property is optional + } +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/text/textdocumentindex.cxx b/test/source/text/textdocumentindex.cxx new file mode 100644 index 000000000..63873e2b4 --- /dev/null +++ b/test/source/text/textdocumentindex.cxx @@ -0,0 +1,36 @@ +/* -*- 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 + +namespace apitest +{ +TextDocumentIndex::~TextDocumentIndex() {} + +void TextDocumentIndex::testDocumentIndexProperties() +{ + css::uno::Reference xDocumnetIndex(init(), css::uno::UNO_QUERY_THROW); + + testBooleanProperty(xDocumnetIndex, "UseAlphabeticalSeparators"); + testBooleanProperty(xDocumnetIndex, "UseKeyAsEntry"); + testBooleanProperty(xDocumnetIndex, "UseCombinedEntries"); + testBooleanProperty(xDocumnetIndex, "IsCaseSensitive"); + testBooleanProperty(xDocumnetIndex, "UsePP"); + testBooleanProperty(xDocumnetIndex, "UseDash"); + testBooleanProperty(xDocumnetIndex, "UseUpperCase"); + testStringOptionalProperty(xDocumnetIndex, "MainEntryCharacterStyleName"); + // [readonly, property] sequence DocumentIndexMarks; + // [property] com::sun::star::lang::Locale Locale; + testStringProperty(xDocumnetIndex, "SortAlgorithm", "Value"); +} +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/textdocumentsettings.cxx b/test/source/text/textdocumentsettings.cxx new file mode 100644 index 000000000..9ef0518b0 --- /dev/null +++ b/test/source/text/textdocumentsettings.cxx @@ -0,0 +1,42 @@ +/* -*- 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 + +using namespace css::uno; + +namespace apitest +{ +TextDocumentSettings::~TextDocumentSettings() {} + +void TextDocumentSettings::testDocumentSettingsProperties() +{ + css::uno::Reference xDocumentSettings(init(), + css::uno::UNO_QUERY_THROW); + + testBooleanOptionalProperty(xDocumentSettings, "ChartAutoUpdate"); + testBooleanOptionalProperty(xDocumentSettings, "AddParaTableSpacing"); + testBooleanOptionalProperty(xDocumentSettings, "AddParaTableSpacingAtStart"); + testBooleanOptionalProperty(xDocumentSettings, "AlignTabStopPosition"); + testBooleanOptionalProperty(xDocumentSettings, "SaveGlobalDocumentLinks"); + testBooleanOptionalProperty(xDocumentSettings, "IsLabelDocument"); + testBooleanOptionalProperty(xDocumentSettings, "UseFormerLineSpacing"); + testBooleanOptionalProperty(xDocumentSettings, "AddParaSpacingToTableCells"); + testBooleanOptionalProperty(xDocumentSettings, "UseFormerObjectPositioning"); + testBooleanOptionalProperty(xDocumentSettings, "ConsiderTextWrapOnObjPos"); + testBooleanOptionalProperty(xDocumentSettings, "MathBaselineAlignment"); +} + +} // end namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/textprintersettings.cxx b/test/source/text/textprintersettings.cxx new file mode 100644 index 000000000..b28c65241 --- /dev/null +++ b/test/source/text/textprintersettings.cxx @@ -0,0 +1,39 @@ +/* -*- 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 + +namespace apitest +{ +TextPrinterSettings::~TextPrinterSettings() {} +void TextPrinterSettings::testPrinterSettingsProperties() +{ + css::uno::Reference xPrinterSettings(init(), + css::uno::UNO_QUERY_THROW); + + testBooleanProperty(xPrinterSettings, "PrintGraphics"); + testBooleanProperty(xPrinterSettings, "PrintTables"); + testBooleanProperty(xPrinterSettings, "PrintDrawings"); + testBooleanProperty(xPrinterSettings, "PrintLeftPages"); + testBooleanProperty(xPrinterSettings, "PrintRightPages"); + testBooleanProperty(xPrinterSettings, "PrintControls"); + testBooleanProperty(xPrinterSettings, "PrintReversed"); + testBooleanProperty(xPrinterSettings, "PrintControls"); + testStringProperty(xPrinterSettings, "PrintFaxName", "FaxName"); + testBooleanProperty(xPrinterSettings, "PrintProspect"); + testBooleanProperty(xPrinterSettings, "PrintPageBackground"); + testBooleanProperty(xPrinterSettings, "PrintBlackFonts"); + testBooleanOptionalProperty(xPrinterSettings, "PrintEmptyPages"); +} +} // end namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/textsettings.cxx b/test/source/text/textsettings.cxx new file mode 100644 index 000000000..880206e09 --- /dev/null +++ b/test/source/text/textsettings.cxx @@ -0,0 +1,153 @@ +/* -*- 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 + +namespace +{ +bool extstsProperty(css::uno::Reference const& rxPropertySet, + OUString const& rPropertyName) +{ + css::uno::Reference xPropertySetInfo( + rxPropertySet->getPropertySetInfo()); + return xPropertySetInfo->hasPropertyByName(rPropertyName); +} + +bool isPropertyReadOnly(css::uno::Reference const& rxPropertySet, + OUString const& rPropertyName) +{ + css::uno::Reference xPropertySetInfo( + rxPropertySet->getPropertySetInfo()); + const css::uno::Sequence xProperties = xPropertySetInfo->getProperties(); + + for (auto const& rProperty : xProperties) + { + if (rProperty.Name == rPropertyName) + return (rProperty.Attributes & com::sun::star::beans::PropertyAttribute::READONLY) != 0; + } + + return false; +} +// [property] string PrinterName; +void testPrinterName(css::uno::Reference const& rxSettings) +{ + const OUString rPropertyName("PrinterName"); + + if (!extstsProperty(rxSettings, rPropertyName)) + return; // Property is sometimes not set - bug? it is not defined as optional + + OUString aPrinterName_Get; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue", + rxSettings->getPropertyValue(rPropertyName) >>= aPrinterName_Get); + + OUString aPrinterName_Set; + css::uno::Any aNewValue; + aNewValue <<= aPrinterName_Get; + rxSettings->setPropertyValue(rPropertyName, aNewValue); + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue", + rxSettings->getPropertyValue(rPropertyName) >>= aPrinterName_Set); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue", aPrinterName_Get, aPrinterName_Set); +} + +// [optional, property] short PrinterIndependentLayout; +void testPrinterIndependentLayout(css::uno::Reference const& rxSettings) +{ + const OUString rPropertyName("PrinterIndependentLayout"); + + if (!extstsProperty(rxSettings, rPropertyName)) + return; // Property is optional + + sal_Int16 aValue_Get = {}; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue", + rxSettings->getPropertyValue(rPropertyName) >>= aValue_Get); + + sal_Int16 aValue_New; + aValue_New = (aValue_Get == 1 ? 3 : 1); + rxSettings->setPropertyValue(rPropertyName, css::uno::Any(aValue_New)); + + sal_Int16 aValue_Set; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue", + rxSettings->getPropertyValue(rPropertyName) >>= aValue_Set); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue", aValue_New, aValue_Set); +} + +// [optional, property] com::sun::star::i18n::XForbiddenCharacters ForbiddenCharacters; +void testForbiddenCharacters(css::uno::Reference const& rxSettings) +{ + const OUString rPropertyName("ForbiddenCharacters"); + + if (!extstsProperty(rxSettings, rPropertyName)) + return; // Property is optional + + CPPUNIT_ASSERT_MESSAGE("Property is read-only but shouldn't be", + !isPropertyReadOnly(rxSettings, rPropertyName)); + + css::uno::Reference aValue_Get; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue", + rxSettings->getPropertyValue(rPropertyName) >>= aValue_Get); + CPPUNIT_ASSERT_MESSAGE("Empty reference to XForbiddenCharacters", aValue_Get.is()); +} +} + +namespace apitest +{ +TextSettings::~TextSettings() {} +void TextSettings::testSettingsProperties() +{ + css::uno::Reference xSettings(init(), css::uno::UNO_QUERY_THROW); + + testForbiddenCharacters(xSettings); + //testShortOptionalProperty(xSettings, "LinkUpdateMode"); + testPrinterName(xSettings); + // [property] sequence< byte > PrinterSetup; + testBooleanOptionalProperty(xSettings, "IsKernAsianPunctuation"); + //testShortOptionalProperty(xSettings, "CharacterCompressionType"); + testBooleanOptionalProperty(xSettings, "ApplyUserData"); + testBooleanOptionalProperty(xSettings, "SaveVersionOnClose"); + testBooleanOptionalProperty(xSettings, "UpdateFromTemplate"); + testBooleanOptionalProperty(xSettings, "FieldAutoUpdate"); + testStringOptionalProperty(xSettings, "CurrentDatabaseDataSource"); + testStringOptionalProperty(xSettings, "CurrentDatabaseCommand"); + testLongOptionalProperty(xSettings, "CurrentDatabaseCommandType"); + testLongOptionalProperty(xSettings, "DefaultTabStop"); + testBooleanOptionalProperty(xSettings, "IsPrintBooklet"); + testBooleanOptionalProperty(xSettings, "IsPrintBookletFront"); + testBooleanOptionalProperty(xSettings, "IsPrintBookletBack"); + testLongOptionalProperty(xSettings, "PrintQuality"); + testStringOptionalProperty(xSettings, "ColorTableURL"); + testStringOptionalProperty(xSettings, "DashTableURL"); + testStringOptionalProperty(xSettings, "LineEndTableURL"); + testStringOptionalProperty(xSettings, "HatchTableURL"); + testStringOptionalProperty(xSettings, "GradientTableURL"); + testStringOptionalProperty(xSettings, "BitmapTableURL"); + testBooleanOptionalProperty(xSettings, "AutoCalculate"); + testPrinterIndependentLayout(xSettings); + testBooleanOptionalProperty(xSettings, "AddExternalLeading"); + testBooleanOptionalProperty(xSettings, "EmbedFonts"); + testBooleanOptionalProperty(xSettings, "EmbedSystemFonts"); + testBooleanOptionalProperty(xSettings, "EmbedOnlyUsedFonts"); + testBooleanOptionalProperty(xSettings, "EmbedLatinScriptFonts"); + testBooleanOptionalProperty(xSettings, "EmbedAsianScriptFonts"); + testBooleanOptionalProperty(xSettings, "EmbedComplexScriptFonts"); +} +} // end namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/xdocumentindex.cxx b/test/source/text/xdocumentindex.cxx new file mode 100644 index 000000000..9f9ad73c8 --- /dev/null +++ b/test/source/text/xdocumentindex.cxx @@ -0,0 +1,66 @@ +/* -*- 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 + +namespace apitest +{ +XDocumentIndex::~XDocumentIndex() {} +/** + * Gets the document from relation and insert a new index mark. + * Then it stores the text content of document index before + * update and after.

+ * + * Has OK status if index content is changed and + * new index contains index mark inserted.

+ */ +void XDocumentIndex::testUpdate() +{ + css::uno::Reference xDocumentIndex(init(), + css::uno::UNO_QUERY_THROW); + + bool bOK = true; + try + { + auto xText = getTextDocument()->getText(); + auto xTextRange = xText->getEnd(); + xTextRange->setString("IndexMark"); + css::uno::Reference xFactory(getTextDocument(), + css::uno::UNO_QUERY_THROW); + css::uno::Reference xTextContentMark( + xFactory->createInstance("com.sun.star.text.DocumentIndexMark"), + css::uno::UNO_QUERY_THROW); + xText->insertTextContent(xTextRange, xTextContentMark, true); + } + catch (css::uno::Exception /*exception*/) + { + bOK = false; + } + + CPPUNIT_ASSERT_MESSAGE("Couldn't create the document index mark", bOK); + + OUString sContentBefore = xDocumentIndex->getAnchor()->getString(); + xDocumentIndex->update(); + OUString sContentAfter = xDocumentIndex->getAnchor()->getString(); + + CPPUNIT_ASSERT_MESSAGE("Before and after shouldn't be equal", sContentBefore != sContentAfter); + CPPUNIT_ASSERT_MESSAGE("Content after should contain string 'IndexMark'", + sContentAfter.indexOf("IndexMark") >= 0); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/xsimpletext.cxx b/test/source/text/xsimpletext.cxx new file mode 100644 index 000000000..23ea6c785 --- /dev/null +++ b/test/source/text/xsimpletext.cxx @@ -0,0 +1,76 @@ +/* -*- 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 XSimpleText::testCreateTextCursor() +{ + uno::Reference xSimpleText(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT(xSimpleText->createTextCursor()); +} + +void XSimpleText::testCreateTextCursorByRange() +{ + uno::Reference xSimpleText(init(), UNO_QUERY_THROW); + uno::Reference xCursor(xSimpleText->createTextCursor(), UNO_SET_THROW); + + xCursor->gotoStart(false); + + CPPUNIT_ASSERT(xSimpleText->createTextCursorByRange(xCursor)); +} + +void XSimpleText::testInsertString() +{ + uno::Reference xSimpleText(init(), UNO_QUERY_THROW); + uno::Reference xCursor(xSimpleText->createTextCursor(), UNO_QUERY_THROW); + ::rtl::OUString sString = "TestString"; + + xSimpleText->insertString(xCursor, sString, false); + ::rtl::OUString gString = xSimpleText->getText()->getString(); + + CPPUNIT_ASSERT(!gString.isEmpty()); + CPPUNIT_ASSERT(gString.indexOf(sString) >= 0); +} + +void XSimpleText::testInsertControlCharacter() +{ + bool bOK = true; + + uno::Reference xSimpleText(init(), UNO_QUERY_THROW); + uno::Reference xCursor(xSimpleText->createTextCursor(), UNO_QUERY_THROW); + + try + { + xSimpleText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, + false); + xSimpleText->insertControlCharacter(xCursor, text::ControlCharacter::LINE_BREAK, false); + xSimpleText->insertString(xSimpleText->createTextCursor(), "newLine", false); + } + catch (const lang::IllegalArgumentException&) + { + bOK = false; + } + + OUString gString = xSimpleText->getString(); + CPPUNIT_ASSERT(bOK); + CPPUNIT_ASSERT(gString.indexOf("\n") > -1); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/xtext.cxx b/test/source/text/xtext.cxx new file mode 100644 index 000000000..6ab646d0a --- /dev/null +++ b/test/source/text/xtext.cxx @@ -0,0 +1,30 @@ +/* -*- 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 + +using namespace css; +using namespace css::uno; + +namespace apitest { + +XText::~XText() {} + +void XText::testInsertRemoveTextContent() +{ + uno::Reference xText(init(), UNO_QUERY_THROW); + uno::Reference xCursor(xText->createTextCursor(), UNO_QUERY_THROW); + + xText->insertTextContent(xCursor, getTextContent(), false); + xText->removeTextContent(getTextContent()); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/xtextcontent.cxx b/test/source/text/xtextcontent.cxx new file mode 100644 index 000000000..b4b60aaea --- /dev/null +++ b/test/source/text/xtextcontent.cxx @@ -0,0 +1,58 @@ +/* -*- 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 XTextContent::testGetAnchor() +{ + uno::Reference< text::XTextContent > xTextContent(init(), UNO_QUERY_THROW); + uno::Reference< uno::XInterface > xAnchor(xTextContent->getAnchor()); + CPPUNIT_ASSERT(xAnchor.is()); +} + +void XTextContent::testAttach() +{ + uno::Reference< text::XTextContent > xTextContent(init(), UNO_QUERY_THROW); + + uno::Reference< text::XTextContent > xContent(getTextContent(), UNO_SET_THROW); + uno::Reference< text::XTextRange > xRange(getTextRange(), UNO_SET_THROW); + + try + { + if (xContent.is()) + xContent->attach(xRange); + else + xTextContent->attach(xRange); + } + catch (const lang::IllegalArgumentException&) + { + bool bAttachSupported = isAttachSupported(); + if (bAttachSupported) + CPPUNIT_ASSERT(false); + } + catch (const RuntimeException&) + { + bool bAttachSupported = isAttachSupported(); + if (bAttachSupported) + CPPUNIT_ASSERT(false); + } +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/xtextfield.cxx b/test/source/text/xtextfield.cxx new file mode 100644 index 000000000..ceefcceed --- /dev/null +++ b/test/source/text/xtextfield.cxx @@ -0,0 +1,43 @@ +/* -*- 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 XTextField::testGetPresentation() +{ + uno::Reference xTextField(init(), uno::UNO_QUERY_THROW); + + OUString aString = xTextField->getPresentation(true); + CPPUNIT_ASSERT(!aString.isEmpty()); + aString = xTextField->getPresentation(false); + CPPUNIT_ASSERT(!aString.isEmpty()); +} + +void XTextField::testGetPresentationEmptyString() +{ + uno::Reference xTextField(init(), uno::UNO_QUERY_THROW); + + OUString aString = xTextField->getPresentation(true); + CPPUNIT_ASSERT(aString.isEmpty()); + aString = xTextField->getPresentation(false); + CPPUNIT_ASSERT(aString.isEmpty()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/text/xtextrange.cxx b/test/source/text/xtextrange.cxx new file mode 100644 index 000000000..64428b476 --- /dev/null +++ b/test/source/text/xtextrange.cxx @@ -0,0 +1,61 @@ +/* -*- 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 XTextRange::testGetEnd() +{ + uno::Reference xTextRange(init(), uno::UNO_QUERY_THROW); + + xTextRange->setString("UnitTest"); + uno::Reference xTR_end(xTextRange->getEnd(), uno::UNO_SET_THROW); + xTR_end->setString("End"); + + CPPUNIT_ASSERT(xTextRange->getText()->getString().endsWith("End")); +} + +void XTextRange::testGetSetString() +{ + uno::Reference xTextRange(init(), uno::UNO_QUERY_THROW); + + xTextRange->setString("UnitTest"); + CPPUNIT_ASSERT_EQUAL(OUString("UnitTest"), xTextRange->getString()); +} + +void XTextRange::testGetStart() +{ + uno::Reference xTextRange(init(), uno::UNO_QUERY_THROW); + + xTextRange->setString("UnitTest"); + uno::Reference xTR_start(xTextRange->getStart(), uno::UNO_SET_THROW); + xTR_start->setString("Start"); + + CPPUNIT_ASSERT(xTextRange->getText()->getString().startsWith("Start")); +} + +void XTextRange::testGetText() +{ + uno::Reference xTextRange(init(), uno::UNO_QUERY_THROW); + + xTextRange->setString("UnitTest"); + uno::Reference xText(xTextRange->getText(), uno::UNO_SET_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("UnitTest"), xTextRange->getString()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit v1.2.3