summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
authorMichael Warner <michael.warner.ut+libreoffice@gmail.com>2020-07-03 10:18:33 -0400
committerLászló Németh <nemeth@numbertext.org>2020-08-17 11:15:25 +0200
commit68e74bdf63e992666016c790e8e4cfd5b28d6abe (patch)
tree903d1bfbe952d5ff6c800d49a2329d1eb2153bf1 /sw/qa
parent3297c44c14d088c83bf729457e3d4ca629dc283c (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. Change-Id: I9600a0bea060a76705a7ad6b051ed4fdd50b9d40 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98614 Tested-by: Jenkins Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/extras/ooxmlimport/data/tdf123386.docxbin0 -> 14928 bytes
-rw-r--r--sw/qa/extras/ooxmlimport/data/tdf123389.docxbin0 -> 13649 bytes
-rw-r--r--sw/qa/extras/ooxmlimport/data/tdf133647.docxbin0 -> 14536 bytes
-rw-r--r--sw/qa/extras/ooxmlimport/data/tdf133647_unicode.docxbin0 -> 20920 bytes
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport.cxx155
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
new file mode 100644
index 000000000000..1278068ddedf
--- /dev/null
+++ b/sw/qa/extras/ooxmlimport/data/tdf123386.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/data/tdf123389.docx b/sw/qa/extras/ooxmlimport/data/tdf123389.docx
new file mode 100644
index 000000000000..4245464b820d
--- /dev/null
+++ b/sw/qa/extras/ooxmlimport/data/tdf123389.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/data/tdf133647.docx b/sw/qa/extras/ooxmlimport/data/tdf133647.docx
new file mode 100644
index 000000000000..fb525446c7fc
--- /dev/null
+++ b/sw/qa/extras/ooxmlimport/data/tdf133647.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/data/tdf133647_unicode.docx b/sw/qa/extras/ooxmlimport/data/tdf133647_unicode.docx
new file mode 100644
index 000000000000..d5749f89de53
--- /dev/null
+++ b/sw/qa/extras/ooxmlimport/data/tdf133647_unicode.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 1f534cb2fbbf..7079fd8bfd19 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -796,6 +796,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