summaryrefslogtreecommitdiff
path: root/sw/qa/uibase/wrtsh/wrtsh.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sw/qa/uibase/wrtsh/wrtsh.cxx')
-rw-r--r--sw/qa/uibase/wrtsh/wrtsh.cxx39
1 files changed, 39 insertions, 0 deletions
diff --git a/sw/qa/uibase/wrtsh/wrtsh.cxx b/sw/qa/uibase/wrtsh/wrtsh.cxx
index 9f63ed2fc7e6..d73ba55ef09f 100644
--- a/sw/qa/uibase/wrtsh/wrtsh.cxx
+++ b/sw/qa/uibase/wrtsh/wrtsh.cxx
@@ -13,6 +13,7 @@
#include <com/sun/star/text/XTextContent.hpp>
#include <com/sun/star/text/XTextRange.hpp>
+#include <com/sun/star/text/XTextDocument.hpp>
#include <rtl/ustring.hxx>
#include <sal/types.h>
@@ -21,6 +22,8 @@
#include <docsh.hxx>
#include <formatlinebreak.hxx>
#include <wrtsh.hxx>
+#include <ndtxt.hxx>
+#include <textcontentcontrol.hxx>
namespace
{
@@ -51,6 +54,42 @@ CPPUNIT_TEST_FIXTURE(Test, testInsertLineBreak)
auto eClear = getProperty<sal_Int16>(xLineBreak, "Clear");
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(SwLineBreakClear::ALL), eClear);
}
+
+CPPUNIT_TEST_FIXTURE(Test, testGotoContentControl)
+{
+ // Given a document with a content control:
+ SwDoc* pDoc = 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);
+ uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY);
+ xContentControlProps->setPropertyValue("ShowingPlaceHolder", uno::makeAny(true));
+ xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
+
+ // When going to that content control in placeholder mode:
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ SwNodeOffset nIndex = pWrtShell->GetCursor()->GetNode().GetIndex();
+ SwTextNode* pTextNode = pDoc->GetNodes()[nIndex]->GetTextNode();
+ SwTextAttr* pAttr = pTextNode->GetTextAttrForCharAt(0, RES_TXTATR_CONTENTCONTROL);
+ auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr);
+ auto& rFormatContentControl
+ = static_cast<SwFormatContentControl&>(pTextContentControl->GetAttr());
+ pWrtShell->GotoContentControl(rFormatContentControl);
+
+ // Then make sure that the content control is selected (without the dummy character):
+ // Without the accompanying fix in place, this test would have failed, the user had to manually
+ // select the placeholder text.
+ sal_Int32 nStart = pWrtShell->GetCursor()->Start()->nContent.GetIndex();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), nStart);
+ sal_Int32 nEnd = pWrtShell->GetCursor()->End()->nContent.GetIndex();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), nEnd);
+}
}
CPPUNIT_PLUGIN_IMPLEMENT();