sw/qa/extras/uiwriter/uiwriter2.cxx | 149 ++++++++++++++++++++++++++++++++++++ sw/source/core/crsr/bookmrk.cxx | 8 + 2 files changed, 156 insertions(+), 1 deletion(-)
New commits: commit 898b02dc11980204d31a3bf10b15eea68d70dce7 Author: Tamás Zolnai <[email protected]> AuthorDate: Thu Jul 11 17:20:59 2019 +0200 Commit: Andras Timar <[email protected]> CommitDate: Sun Jul 14 00:20:23 2019 +0200 MSForms: Test date fieldmark's content and current date related methods These methods are used by the field's properties dialog, it's drop-down button and DOCX export. Reviewed-on: https://gerrit.libreoffice.org/75463 Reviewed-by: Tamás Zolnai <[email protected]> Tested-by: Tamás Zolnai <[email protected]> (cherry picked from commit d0ff1090762ac61ce08f54bc76685232699d98a0) Change-Id: I2b75e69b452a736cc72785d251516f3b3bf1d1f1 Reviewed-on: https://gerrit.libreoffice.org/75555 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Andras Timar <[email protected]> diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 3455692a678f..d19db15bae8f 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -54,6 +54,9 @@ public: void testImageComment(); void testImageCommentAtChar(); void testDateFormFieldInsertion(); + void testDateFormFieldContentOperations(); + void testDateFormFieldCurrentDateHandling(); + void testDateFormFieldCurrentDateInvalidation(); CPPUNIT_TEST_SUITE(SwUiWriterTest2); CPPUNIT_TEST(testTdf101534); @@ -69,6 +72,9 @@ public: CPPUNIT_TEST(testImageComment); CPPUNIT_TEST(testImageCommentAtChar); CPPUNIT_TEST(testDateFormFieldInsertion); + CPPUNIT_TEST(testDateFormFieldContentOperations); + CPPUNIT_TEST(testDateFormFieldCurrentDateHandling); + CPPUNIT_TEST(testDateFormFieldCurrentDateInvalidation); CPPUNIT_TEST_SUITE_END(); private: @@ -641,6 +647,149 @@ void SwUiWriterTest2::testDateFormFieldInsertion() CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname()); } +void SwUiWriterTest2::testDateFormFieldContentOperations() +{ + SwDoc* pDoc = createDoc(); + CPPUNIT_ASSERT(pDoc); + IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); + CPPUNIT_ASSERT(pMarkAccess); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount()); + + // Insert a date form field + lcl_dispatchCommand(mxComponent, ".uno:DatePickerFormField", {}); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount()); + + // Check whether the fieldmark is created + auto aIter = pMarkAccess->getAllMarksBegin(); + CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd()); + ::sw::mark::IDateFieldmark* pFieldmark = dynamic_cast<::sw::mark::IDateFieldmark*>(aIter->get()); + CPPUNIT_ASSERT(pFieldmark); + CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname()); + + // Check the default content added by insertion + uno::Reference<text::XTextRange> xPara = getParagraph(1); + sal_Unicode vEnSpaces[5] = { 8194, 8194, 8194, 8194, 8194 }; + CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), pFieldmark->GetContent()); + + // Set content to empty string + pFieldmark->ReplaceContent(""); + CPPUNIT_ASSERT_EQUAL(OUString(""), pFieldmark->GetContent()); + + // Replace empty string with a valid content + pFieldmark->ReplaceContent("2019-10-23"); + CPPUNIT_ASSERT_EQUAL(OUString("2019-10-23"), pFieldmark->GetContent()); +} + +void SwUiWriterTest2::testDateFormFieldCurrentDateHandling() +{ + SwDoc* pDoc = createDoc(); + CPPUNIT_ASSERT(pDoc); + IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); + CPPUNIT_ASSERT(pMarkAccess); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount()); + + // Insert a date form field + lcl_dispatchCommand(mxComponent, ".uno:DatePickerFormField", {}); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount()); + + // Check whether the fieldmark is created + auto aIter = pMarkAccess->getAllMarksBegin(); + CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd()); + ::sw::mark::IDateFieldmark* pFieldmark = dynamic_cast<::sw::mark::IDateFieldmark*>(aIter->get()); + CPPUNIT_ASSERT(pFieldmark); + CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname()); + + // The default content is not a valid date + uno::Reference<text::XTextRange> xPara = getParagraph(1); + sal_Unicode vEnSpaces[5] = { 8194, 8194, 8194, 8194, 8194 }; + CPPUNIT_ASSERT_EQUAL(OUString(vEnSpaces, 5), pFieldmark->GetContent()); + std::pair<bool, double> aResult = pFieldmark->GetCurrentDate(); + CPPUNIT_ASSERT(!aResult.first); + + // Check empty string + pFieldmark->ReplaceContent(""); + aResult = pFieldmark->GetCurrentDate(); + CPPUNIT_ASSERT(!aResult.first); + + // Check valid date + // Set date format first + sw::mark::IFieldmark::parameter_map_t* pParameters = pFieldmark->GetParameters(); + (*pParameters)[ODF_FORMDATE_DATEFORMAT] <<= OUString("YYYY/MM/DD"); + (*pParameters)[ODF_FORMDATE_DATEFORMAT_LANGUAGE] <<= OUString("en-US"); + + // Set date value and check whether the content is formatted correctly + pFieldmark->SetCurrentDate(48000.0); + aResult = pFieldmark->GetCurrentDate(); + CPPUNIT_ASSERT(aResult.first); + CPPUNIT_ASSERT_EQUAL(48000.0, aResult.second); + CPPUNIT_ASSERT_EQUAL(OUString("2031/06/01"), pFieldmark->GetContent()); + // Current date param contains date in a "standard format" + OUString sCurrentDate; + auto pResult = pParameters->find(ODF_FORMDATE_CURRENTDATE); + if (pResult != pParameters->end()) + { + pResult->second >>= sCurrentDate; + } + CPPUNIT_ASSERT_EQUAL(OUString("2031-06-01"), sCurrentDate); +} + +void SwUiWriterTest2::testDateFormFieldCurrentDateInvalidation() +{ + SwDoc* pDoc = createDoc(); + CPPUNIT_ASSERT(pDoc); + IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess(); + CPPUNIT_ASSERT(pMarkAccess); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pMarkAccess->getAllMarksCount()); + + // Insert a date form field + lcl_dispatchCommand(mxComponent, ".uno:DatePickerFormField", {}); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount()); + + // Check whether the fieldmark is created + auto aIter = pMarkAccess->getAllMarksBegin(); + CPPUNIT_ASSERT(aIter != pMarkAccess->getAllMarksEnd()); + ::sw::mark::IDateFieldmark* pFieldmark = dynamic_cast<::sw::mark::IDateFieldmark*>(aIter->get()); + CPPUNIT_ASSERT(pFieldmark); + CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname()); + + // Set a date first + sw::mark::IFieldmark::parameter_map_t* pParameters = pFieldmark->GetParameters(); + pFieldmark->SetCurrentDate(48000.0); + std::pair<bool, double> aResult = pFieldmark->GetCurrentDate(); + CPPUNIT_ASSERT(aResult.first); + CPPUNIT_ASSERT_EQUAL(48000.0, aResult.second); + + // Do the layouting to trigger invalidation + // Since we have the current date consistent with the field content + // This invalidation won't change anything + calcLayout(); + Scheduler::ProcessEventsToIdle(); + + // Current date param contains date in a "standard format" + OUString sCurrentDate; + auto pResult = pParameters->find(ODF_FORMDATE_CURRENTDATE); + if (pResult != pParameters->end()) + { + pResult->second >>= sCurrentDate; + } + // We have the current date parameter set + CPPUNIT_ASSERT_EQUAL(OUString("2031-06-01"), sCurrentDate); + + // Now change the content of the field + pFieldmark->ReplaceContent("[select date]"); + // Do the layouting to trigger invalidation + calcLayout(); + Scheduler::ProcessEventsToIdle(); + + sCurrentDate.clear(); + pResult = pParameters->find(ODF_FORMDATE_CURRENTDATE); + if (pResult != pParameters->end()) + { + pResult->second >>= sCurrentDate; + } + CPPUNIT_ASSERT_EQUAL(OUString(""), sCurrentDate); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 2b6d46f2c5496de4fd66d063c32f24aae3cc4095 Author: Tamás Zolnai <[email protected]> AuthorDate: Wed Jul 10 12:07:09 2019 +0200 Commit: Andras Timar <[email protected]> CommitDate: Sun Jul 14 00:20:04 2019 +0200 MSForms: date field: handle replacing empty content It occurs when the date field is empty and the user trying to set a date with the date picker. Change-Id: I182930258b05071d861c2b326c139c73e2339af9 Reviewed-on: https://gerrit.libreoffice.org/75461 Reviewed-by: Tamás Zolnai <[email protected]> Tested-by: Tamás Zolnai <[email protected]> (cherry picked from commit fcb36a995dde68456b862db8a931b98176f9eca7) Reviewed-on: https://gerrit.libreoffice.org/75554 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Andras Timar <[email protected]> diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx index 09cd5375f2f3..b524aa05aef7 100644 --- a/sw/source/core/crsr/bookmrk.cxx +++ b/sw/source/core/crsr/bookmrk.cxx @@ -634,12 +634,18 @@ namespace sw { namespace mark const sal_Int32 nStart(GetMarkStart().nContent.GetIndex()); const sal_Int32 nEnd (GetMarkEnd().nContent.GetIndex()); - if(nStart + 1 < pTextNode->GetText().getLength() && nEnd <= pTextNode->GetText().getLength()) + if(nStart + 1 < pTextNode->GetText().getLength() && nEnd <= pTextNode->GetText().getLength() && + nEnd > nStart + 2) { SwPaM aFieldPam(GetMarkStart().nNode, nStart + 1, GetMarkStart().nNode, nEnd - 1); m_pDocumentContentOperationsManager->ReplaceRange(aFieldPam, sNewContent, false); } + else + { + SwPaM aFieldStartPam(GetMarkStart().nNode, nStart + 1); + m_pDocumentContentOperationsManager->InsertString(aFieldStartPam, sNewContent); + } } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
