diff options
author | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-07-11 17:20:59 +0200 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-07-12 15:02:26 +0200 |
commit | d0ff1090762ac61ce08f54bc76685232699d98a0 (patch) | |
tree | fb63699fe8e8ec2c924bca01f29bdfdeb2bb39e2 /sw/qa | |
parent | fcb36a995dde68456b862db8a931b98176f9eca7 (diff) |
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.
Change-Id: I2b75e69b452a736cc72785d251516f3b3bf1d1f1
Reviewed-on: https://gerrit.libreoffice.org/75463
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Tested-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index f5b98fc4cb84..f2c6e6ee4249 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -1815,4 +1815,147 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testDateFormFieldInsertion) CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname()); } +CPPUNIT_TEST_FIXTURE(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); + 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()); +} + +CPPUNIT_TEST_FIXTURE(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); + 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); +} + +CPPUNIT_TEST_FIXTURE(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); + 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); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |