From b4716b277268a4a24b1a83b81b0255b852072c6a Mon Sep 17 00:00:00 2001 From: Michael Warner Date: Fri, 3 Jul 2020 10:18:33 -0400 Subject: 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 Reviewed-by: Miklos Vajna --- sw/qa/extras/ooxmlimport/data/tdf123386.docx | Bin 0 -> 14928 bytes sw/qa/extras/ooxmlimport/data/tdf123389.docx | Bin 0 -> 13649 bytes sw/qa/extras/ooxmlimport/data/tdf133647.docx | Bin 0 -> 14536 bytes .../extras/ooxmlimport/data/tdf133647_unicode.docx | Bin 0 -> 20920 bytes sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 155 +++++++++++++++++++++ 5 files changed, 155 insertions(+) create mode 100644 sw/qa/extras/ooxmlimport/data/tdf123386.docx create mode 100644 sw/qa/extras/ooxmlimport/data/tdf123389.docx create mode 100644 sw/qa/extras/ooxmlimport/data/tdf133647.docx create mode 100644 sw/qa/extras/ooxmlimport/data/tdf133647_unicode.docx (limited to 'sw') 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 Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf123386.docx 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 Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf123389.docx 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 Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf133647.docx 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 Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf133647_unicode.docx differ 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 xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + + if( !xFields->hasMoreElements() ) { + CPPUNIT_ASSERT(false); + return; + } + + uno::Reference 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 xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("sum(|)"), xEnumerationAccess2->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("3"), xEnumerationAccess2->getPresentation(false).trim()); + + uno::Reference xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("(SUM(|5)*(2+7))*(3+SUM(1|))"), xEnumerationAccess3->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("432"), xEnumerationAccess3->getPresentation(false).trim()); + + uno::Reference 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 xEnumerationAccess5(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("3*(2+SUM()+7)"), xEnumerationAccess5->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("45"), xEnumerationAccess5->getPresentation(false).trim()); + + uno::Reference xEnumerationAccess6(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("(1+2)*SUM(|)"), xEnumerationAccess6->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("21"), xEnumerationAccess6->getPresentation(false).trim()); + + uno::Reference xEnumerationAccess7(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SUM(|5||6)"), xEnumerationAccess7->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("17"), xEnumerationAccess7->getPresentation(false).trim()); + + uno::Reference xEnumerationAccess8(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SUM()"), xEnumerationAccess8->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("7"), xEnumerationAccess8->getPresentation(false).trim()); + + uno::Reference xEnumerationAccess9(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("SUM(|)"), 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 xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + + if( !xFields->hasMoreElements() ) { + CPPUNIT_ASSERT(false); + return; + } + + uno::Reference xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(" 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 xEnumerationAccess10(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("((1) AND (DEFINED(ABC1)))"), xEnumerationAccess10->getPresentation(true).trim()); + + uno::Reference 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 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 xEnumerationAccess7(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("(( EQ 1) OR ( EQ 2))"), xEnumerationAccess7->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess7->getPresentation(false).trim()); + + uno::Reference xEnumerationAccess6(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("((( L 1)) AND (( NEQ 2)))"), xEnumerationAccess6->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("0"), xEnumerationAccess6->getPresentation(false).trim()); + + uno::Reference xEnumerationAccess5(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("(( EQ 1) AND ( EQ 2))"), xEnumerationAccess5->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess5->getPresentation(false).trim()); + + uno::Reference xEnumerationAccess4(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(" NEQ 3"), xEnumerationAccess4->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess4->getPresentation(false).trim()); + + uno::Reference xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(" EQ 3"), xEnumerationAccess3->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("1"), xEnumerationAccess3->getPresentation(false).trim()); + + uno::Reference xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(" 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 xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + + if( !xFields->hasMoreElements() ) { + CPPUNIT_ASSERT(false); + return; + } + + xFields->nextElement(); + xFields->nextElement(); + xFields->nextElement(); + + uno::Reference xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(u"defined(預期結果)"), xEnumerationAccess1->getPresentation(true).trim()); + + uno::Reference xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString(u"defined(نتيجةمتوقعة)"), xEnumerationAccess2->getPresentation(true).trim()); + + uno::Reference 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 xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference xFields(xFieldsAccess->createEnumeration()); + + if( !xFields->hasMoreElements() ) { + CPPUNIT_ASSERT(false); + return; + } + + uno::Reference 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 xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("(() 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 -- cgit