summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorVasily Melenchuk <vasily.melenchuk@cib.de>2023-07-06 12:45:11 +0300
committerThorsten Behrens <thorsten.behrens@allotropia.de>2023-07-17 15:56:14 +0200
commitda2e7b1e0b58aed20d44b7c588ee86d922d614a8 (patch)
tree54af8d96d251b76032c91f25b965a194c51ae848 /sw
parente73b2bc4e6fdaba3098fa2c701342e1df112514c (diff)
tdf#156030: sw: better import of IF field for RTF and DOCX
Since long time IF field was converted to ConditionalText, but no parameters were given. So condition, then text and else text were lost during import. Change-Id: I9b45e8ab394f3c53bb34370bf3ea15a939a400fe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154101 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/rtfexport/data/tdf156030.rtf11
-rw-r--r--sw/qa/extras/rtfexport/rtfexport7.cxx38
2 files changed, 49 insertions, 0 deletions
diff --git a/sw/qa/extras/rtfexport/data/tdf156030.rtf b/sw/qa/extras/rtfexport/data/tdf156030.rtf
new file mode 100644
index 000000000000..db501d5bffac
--- /dev/null
+++ b/sw/qa/extras/rtfexport/data/tdf156030.rtf
@@ -0,0 +1,11 @@
+{\rtf1
+{\field{\*\fldinst IF 1 = 2 "true value 1" "false value 1"}}\par
+{\field{\*\fldinst IF 1 == 2 "true value 2" "false value 2"}}\par
+{\field{\*\fldinst IF 1 != 2 "true value 3" "false value 3"}}\par
+{\field{\*\fldinst IF 1 <> 2 "true value 4" "false value 4"}}\par
+{\field{\*\fldinst IF 1 > 2 "true value 5" "false value 5"}}\par
+{\field{\*\fldinst IF 1 < 2 "true value 6" "false value 6"}}\par
+{\field{\*\fldinst IF 1 1 = 1 2 1 true value 7 false value 7}}\par
+{\field{\*\fldinst IF 1 1 = "1 2 1 true value 8 fal"se "value 8}}\par
+{\field{\*\fldinst IF a}}\par
+}
diff --git a/sw/qa/extras/rtfexport/rtfexport7.cxx b/sw/qa/extras/rtfexport/rtfexport7.cxx
index 11eaadee6a88..ad9249bedeb8 100644
--- a/sw/qa/extras/rtfexport/rtfexport7.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport7.cxx
@@ -683,6 +683,44 @@ DECLARE_RTFEXPORT_TEST(testTdf113202, "tdf113202.rtf")
CPPUNIT_ASSERT(getProperty<bool>(getParagraph(4), "ParaContextMargin"));
}
+DECLARE_RTFEXPORT_TEST(testTdf156030, "tdf156030.rtf")
+{
+ uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xFieldsAccess(
+ xTextFieldsSupplier->getTextFields());
+ uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+
+ // As usual, fields given by FieldsAccess are not in same order as in the document
+ std::vector<std::vector<OUString>> aExpectedValues = {
+ { "1 FORMULA 2", "true value 1", "false value 1" }, // #1, condition should be 1 = 2
+ { "", "", "" }, // #9, not enough field params
+ { "1 1 FORMULA 1 2 1 true value 8 fal", "se", "value 8" }, // #8, nonsense in field params
+ { "1 1 FORMULA 1 2 1 true value 7 false", "value", "7" }, // #7, another parse error
+ { "1 < 2", "true value 6", "false value 6" }, // #6
+ { "1 > 2", "true value 5", "false value 5" }, // #5
+ { "1 <> 2", "true value 4", "false value 4" }, // #4
+ { "1 != 2", "true value 3", "false value 3" }, // #3
+ { "1 FORMULA FORMULA 2", "true value 2", "false value 2" }, // #2, condition expected 1 == 2
+ };
+ uno::Reference<beans::XPropertySet> xPropertySet;
+ OUString sValue;
+
+ for (const auto& aValues : aExpectedValues)
+ {
+ xPropertySet.set(xFields->nextElement(), uno::UNO_QUERY_THROW);
+ CPPUNIT_ASSERT(xPropertySet.is());
+ CPPUNIT_ASSERT(xPropertySet->getPropertyValue("Condition") >>= sValue);
+ CPPUNIT_ASSERT_EQUAL(aValues[0], sValue);
+ CPPUNIT_ASSERT(xPropertySet->getPropertyValue("TrueContent") >>= sValue);
+ CPPUNIT_ASSERT_EQUAL(aValues[1], sValue);
+ CPPUNIT_ASSERT(xPropertySet->getPropertyValue("FalseContent") >>= sValue);
+ CPPUNIT_ASSERT_EQUAL(aValues[2], sValue);
+ }
+
+ // No more fields
+ CPPUNIT_ASSERT(!xFields->hasMoreElements());
+}
+
DECLARE_RTFEXPORT_TEST(testTdf153195, "tdf153195.rtf")
{
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);