diff options
author | Michael Warner <michael.warner.ut+libreoffice@gmail.com> | 2020-07-03 10:18:33 -0400 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-11-09 16:02:50 +0100 |
commit | b4716b277268a4a24b1a83b81b0255b852072c6a (patch) | |
tree | 3d6d24621b7e26c350df305043c4838f0a10608f /sw | |
parent | 41a3d6ee341d1d0c16d5548a687b73cb8cbf16b8 (diff) |
tdf133647 tdf123386 tdf123389 Improved .docx table formula import
Converts table formula syntax from MS Word to LibreOffice.
This version uses the list separator of the document for the
formula regexen; however, it does not convert the decimal or
list separators in the case where the person opening the document
is using a different locale from the author.
(cherry picked from commit 68e74bdf63e992666016c790e8e4cfd5b28d6abe)
Conflicts:
writerfilter/source/dmapper/DomainMapper_Impl.cxx
writerfilter/source/dmapper/SettingsTable.cxx
Change-Id: I9600a0bea060a76705a7ad6b051ed4fdd50b9d40
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105483
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlimport/data/tdf123386.docx | bin | 0 -> 14928 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlimport/data/tdf123389.docx | bin | 0 -> 13649 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlimport/data/tdf133647.docx | bin | 0 -> 14536 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlimport/data/tdf133647_unicode.docx | bin | 0 -> 20920 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 155 |
5 files changed, 155 insertions, 0 deletions
diff --git a/sw/qa/extras/ooxmlimport/data/tdf123386.docx b/sw/qa/extras/ooxmlimport/data/tdf123386.docx Binary files differnew file mode 100644 index 000000000000..1278068ddedf --- /dev/null +++ b/sw/qa/extras/ooxmlimport/data/tdf123386.docx diff --git a/sw/qa/extras/ooxmlimport/data/tdf123389.docx b/sw/qa/extras/ooxmlimport/data/tdf123389.docx Binary files differnew file mode 100644 index 000000000000..4245464b820d --- /dev/null +++ b/sw/qa/extras/ooxmlimport/data/tdf123389.docx diff --git a/sw/qa/extras/ooxmlimport/data/tdf133647.docx b/sw/qa/extras/ooxmlimport/data/tdf133647.docx Binary files differnew file mode 100644 index 000000000000..fb525446c7fc --- /dev/null +++ b/sw/qa/extras/ooxmlimport/data/tdf133647.docx diff --git a/sw/qa/extras/ooxmlimport/data/tdf133647_unicode.docx b/sw/qa/extras/ooxmlimport/data/tdf133647_unicode.docx Binary files differnew file mode 100644 index 000000000000..d5749f89de53 --- /dev/null +++ b/sw/qa/extras/ooxmlimport/data/tdf133647_unicode.docx diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index 4b2c4cc814bf..24a8a21263a2 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -746,6 +746,161 @@ DECLARE_OOXMLIMPORT_TEST(testTdf105975formula, "tdf105975.docx") CPPUNIT_ASSERT_EQUAL(OUString("25"), xEnumerationAccess->getPresentation(false).trim()); } +DECLARE_OOXMLIMPORT_TEST(testTdf133647, "tdf133647.docx") +{ + /* Tests that argument lists, cell references, and cell ranges are translated correctly + * when importing table formulae from MS Word */ + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + if( !xFields->hasMoreElements() ) { + CPPUNIT_ASSERT(false); + return; + } + + uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SUM(1|2|3)"), xEnumerationAccess1->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("6"), xEnumerationAccess1->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("sum(<A1>|<B1>)"), xEnumerationAccess2->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("3"), xEnumerationAccess2->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("(SUM(<C1>|5)*(2+7))*(3+SUM(1|<B1>))"), xEnumerationAccess3->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("432"), xEnumerationAccess3->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess4(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1+(SUM(1|2))"), xEnumerationAccess4->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("4"), xEnumerationAccess4->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess5(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("3*(2+SUM(<A1:C1>)+7)"), xEnumerationAccess5->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("45"), xEnumerationAccess5->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess6(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("(1+2)*SUM(<C1>|<D1>)"), xEnumerationAccess6->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("21"), xEnumerationAccess6->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess7(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SUM(<A1>|5|<B1:C1>|6)"), xEnumerationAccess7->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("17"), xEnumerationAccess7->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess8(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SUM(<C1:D1>)"), xEnumerationAccess8->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("7"), xEnumerationAccess8->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess9(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SUM(<A1>|<B1>)"), xEnumerationAccess9->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("3"), xEnumerationAccess9->getPresentation(false).trim()); +} + +DECLARE_OOXMLIMPORT_TEST(testTdf123386, "tdf123386.docx") +{ + /* Tests that argument lists, cell references, and cell ranges are translated correctly + * when importing table formulae from MS Word */ + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + if( !xFields->hasMoreElements() ) { + CPPUNIT_ASSERT(false); + return; + } + + uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("<A1> L 2"), xEnumerationAccess1->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess1->getPresentation(false).trim()); + + /* Ensures non-cell references passed to DEFINED() are preserved. + * Doesn't test the display string because LO doesn't support DEFINED(). */ + uno::Reference<text::XTextField> xEnumerationAccess10(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("((1) AND (DEFINED(ABC1)))"), xEnumerationAccess10->getPresentation(true).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess9(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("NOT(TRUE)"), xEnumerationAccess9->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("0"), xEnumerationAccess9->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess8(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("((TRUE) OR (FALSE))"), xEnumerationAccess8->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess8->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess7(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("((<A1> EQ 1) OR (<B1> EQ 2))"), xEnumerationAccess7->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess7->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess6(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("(((<A1> L 1)) AND ((<B1> NEQ 2)))"), xEnumerationAccess6->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("0"), xEnumerationAccess6->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess5(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("((<A1> EQ 1) AND (<B1> EQ 2))"), xEnumerationAccess5->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess5->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess4(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("<D1> NEQ 3"), xEnumerationAccess4->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess4->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("<C1> EQ 3"), xEnumerationAccess3->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess3->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("<B1> G 1"), xEnumerationAccess2->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess2->getPresentation(false).trim()); + +} + +DECLARE_OOXMLIMPORT_TEST(testTdf133647_unicode, "tdf133647_unicode.docx") +{ + /* Tests that non-ASCII characters in formulas are preserved when importing from MS Word */ + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + if( !xFields->hasMoreElements() ) { + CPPUNIT_ASSERT(false); + return; + } + + xFields->nextElement(); + xFields->nextElement(); + xFields->nextElement(); + + uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(u"defined(預期結果)"), xEnumerationAccess1->getPresentation(true).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(u"defined(نتيجةمتوقعة)"), xEnumerationAccess2->getPresentation(true).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(u"defined(ExpectedResult)"), xEnumerationAccess3->getPresentation(true).trim()); +} + +DECLARE_OOXMLIMPORT_TEST(testTdf123389, "tdf123389.docx") +{ + /* Tests that argument lists, cell references, and cell ranges are translated correctly + * when importing table formulae from MS Word */ + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + if( !xFields->hasMoreElements() ) { + CPPUNIT_ASSERT(false); + return; + } + + uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("((2.345) ROUND (1))"), xEnumerationAccess1->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("2.3"), xEnumerationAccess1->getPresentation(false).trim()); + + uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("((<A1>) ROUND (2))"), xEnumerationAccess2->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("2.35"), xEnumerationAccess2->getPresentation(false).trim()); +} + + DECLARE_OOXMLIMPORT_TEST(testTdf107784, "tdf107784.docx") { // Make sure the field displays the citation's title and not the identifier |