diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-04-04 08:23:06 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-04-04 09:14:57 +0200 |
commit | cb35526e9221d9781abb3cee2ba6971736b6b333 (patch) | |
tree | 37ef44a035d4a2b9aeb6a7a34913b7b8ad00a2de /sw/qa | |
parent | 85d5113dc0472f59b60ce34ccf70c21a0edbe097 (diff) |
sw content controls: include this in the UNO API text portion enum
Which is how UNO API clients (e.g. ODT export) will be able to read
RES_TXTATR_CONTENTCONTROL.
Change-Id: Idf87312b1b89a0e44e7de2578de44b263fa8689a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132491
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/core/unocore/unocore.cxx | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx index b03c91b39425..c9bca82ae2f8 100644 --- a/sw/qa/core/unocore/unocore.cxx +++ b/sw/qa/core/unocore/unocore.cxx @@ -371,6 +371,41 @@ CPPUNIT_TEST_FIXTURE(SwModelTestBase, testImageTooltip) CPPUNIT_ASSERT_EQUAL(aExpected, getProperty<OUString>(xImageProps, "Tooltip")); } +CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testContentControlTextPortionEnum) +{ + // Given a document with a content control around one or more text portions: + createSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + xMSF->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + + // When enumerating the text portions of the only paragraph in the document: + uno::Reference<css::text::XTextRange> xTextPortion = getRun(getParagraph(1), 1); + + // Then make sure that the text portion type is correct + the content can be read: + auto aPortionType = getProperty<OUString>(xTextPortion, "TextPortionType"); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: ContentControl + // - Actual : Text + // i.e. the content control text attribute was ignored. + CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType); + xContentControl + = getProperty<uno::Reference<text::XTextContent>>(xTextPortion, "ContentControl"); + uno::Reference<text::XTextRange> xContentControlRange(xContentControl, uno::UNO_QUERY); + xText = xContentControlRange->getText(); + uno::Reference<container::XEnumerationAccess> xContentEnumAccess(xText, uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xContentEnum = xContentEnumAccess->createEnumeration(); + uno::Reference<text::XTextRange> xContent(xContentEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("test"), xContent->getString()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |