diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-06-01 08:30:03 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-06-01 09:09:40 +0200 |
commit | 9cb1a07dc2760a30d7f321aa7fa4ce2a460dfa6c (patch) | |
tree | 9d2d703bc1d8dfbb8f5cdc61f3c4607daeae4d56 /sw/qa | |
parent | 64f8a70298695d1952c3a399e897755ab861add5 (diff) |
sw content controls, date: add LOK API
- send a LOK_CALLBACK_CONTENT_CONTROL with date=true when entering a
date content control
- extend lok::Document::sendContentControlEvent() to be able to set the
date of a date content control (after the client's date picker is
closed)
- update gtktiledviewer to work with these
Change-Id: I0abf21eb1d4ba233050f0aa2607b68740c048262
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135214
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 2a8c05fe19e6..a9205c07841a 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -172,6 +172,7 @@ public: void testContentControl(); void testDropDownContentControl(); void testPictureContentControl(); + void testDateContentControl(); CPPUNIT_TEST_SUITE(SwTiledRenderingTest); CPPUNIT_TEST(testRegisterCallback); @@ -262,6 +263,7 @@ public: CPPUNIT_TEST(testContentControl); CPPUNIT_TEST(testDropDownContentControl); CPPUNIT_TEST(testPictureContentControl); + CPPUNIT_TEST(testDateContentControl); CPPUNIT_TEST_SUITE_END(); private: @@ -3784,6 +3786,61 @@ void SwTiledRenderingTest::testPictureContentControl() } +void SwTiledRenderingTest::testDateContentControl() +{ + // Given a document with a date content control: + SwXTextDocument* pXTextDocument = createDoc(); + SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); + setupLibreOfficeKitViewCallback(pWrtShell->GetSfxViewShell()); + 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, "choose a date", /*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("Date", uno::Any(true)); + xContentControlProps->setPropertyValue("DateFormat", uno::Any(OUString("YYYY-MM-DD"))); + xContentControlProps->setPropertyValue("DateLanguage", uno::Any(OUString("en-US"))); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); + pWrtShell->SttEndDoc(/*bStt=*/true); + m_aContentControl.clear(); + + // When entering that content control: + pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, /*nCount=*/1, /*bBasicCall=*/false); + + // Then make sure that the callback is emitted: + CPPUNIT_ASSERT(!m_aContentControl.isEmpty()); + { + std::stringstream aStream(m_aContentControl.getStr()); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + OString sAction = aTree.get_child("action").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("show"), sAction); + OString sRectangles = aTree.get_child("rectangles").get_value<std::string>().c_str(); + CPPUNIT_ASSERT(!sRectangles.isEmpty()); + boost::optional<boost::property_tree::ptree&> oDate = aTree.get_child_optional("date"); + CPPUNIT_ASSERT(oDate); + } + + // And when selecting a date: + std::map<OUString, OUString> aArguments; + aArguments.emplace("type", "date"); + aArguments.emplace("selected", "2022-05-30T00:00:00Z"); + pXTextDocument->executeContentControlEvent(aArguments); + + // Then make sure that the document is updated accordingly: + SwTextNode* pTextNode = pWrtShell->GetCursor()->GetNode().GetTextNode(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2022-05-30 + // - Actual : choose a date + // i.e. the document text was not updated. + CPPUNIT_ASSERT_EQUAL(OUString("2022-05-30"), pTextNode->GetExpandText(pWrtShell->GetLayout())); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwTiledRenderingTest); CPPUNIT_PLUGIN_IMPLEMENT(); |