[Libreoffice-commits] core.git: Branch 'feature/msforms' - sw/qa
Tamás Zolnai (via logerrit)
logerrit at kemper.freedesktop.org
Thu Jul 11 17:24:39 UTC 2019
Rebased ref, commits from common ancestor:
commit ff5e5931034c9e8fe36f8f7cee2f53c9ea7e6d23
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Thu Jul 11 17:20:59 2019 +0200
Commit: Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Thu Jul 11 19:23:33 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.
Change-Id: I2b75e69b452a736cc72785d251516f3b3bf1d1f1
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 5818597caae4..d8a1d0571d5e 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -1802,4 +1802,148 @@ 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 = OUString("");
+ 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: */
More information about the Libreoffice-commits
mailing list