diff options
author | Serge Krot <Serge.Krot@cib.de> | 2017-12-13 17:13:35 +0100 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2017-12-14 13:25:18 +0100 |
commit | 29378bd510226adb23659525203beec18f8708a3 (patch) | |
tree | 77286470b83b3dc6ff1fa0ebe2972c024e98a3bc /sw/qa | |
parent | e6b7f73f06aa35e60b7b56d78f24a724fe7c888e (diff) |
tdf#43569 DOC input: insert ConditionalText field instead of field marks
In case of IF field input inside DOC document the ConditionalText field
should be created instead of the two field marks that leads to handling
of unsupported field routine.
Added unit tests.
Change-Id: I31875d8e6be7f536766ef640a366b843f7e0532c
Reviewed-on: https://gerrit.libreoffice.org/46022
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'sw/qa')
-rwxr-xr-x | sw/qa/extras/odfexport/data/tdf43569_conditionalfield.doc | bin | 0 -> 22016 bytes | |||
-rw-r--r-- | sw/qa/extras/odfexport/odfexport.cxx | 108 |
2 files changed, 108 insertions, 0 deletions
diff --git a/sw/qa/extras/odfexport/data/tdf43569_conditionalfield.doc b/sw/qa/extras/odfexport/data/tdf43569_conditionalfield.doc Binary files differnew file mode 100755 index 000000000000..456a6ed833cf --- /dev/null +++ b/sw/qa/extras/odfexport/data/tdf43569_conditionalfield.doc diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index eea19faccea8..f571b66cfbe8 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -36,6 +36,7 @@ #include <comphelper/fileformat.h> #include <comphelper/propertysequence.hxx> #include <unotools/streamwrap.hxx> +#include <docufld.hxx> // for SwHiddenTextField::ParseIfFieldDefinition() method call class Test : public SwModelTestBase { @@ -114,6 +115,113 @@ DECLARE_ODFEXPORT_TEST(testMathObjectFlatExport, "2_MathType3.docx") CPPUNIT_ASSERT_EQUAL(OUString(" size 12{2+2=4} {}"), formula2); } +void testTdf43569_CheckIfFieldParse() +{ + { + const OUString fieldDefinition("IF A B C"); + + OUString paramCondition; + OUString paramTrue; + OUString paramFalse; + + SwHiddenTextField::ParseIfFieldDefinition(fieldDefinition, paramCondition, paramTrue, paramFalse); + + CPPUNIT_ASSERT_EQUAL(OUString("A"), paramCondition); + CPPUNIT_ASSERT_EQUAL(OUString("B"), paramTrue); + CPPUNIT_ASSERT_EQUAL(OUString("C"), paramFalse); + } + + { + const OUString fieldDefinition(" IF AAA BBB CCC "); + + OUString paramCondition; + OUString paramTrue; + OUString paramFalse; + + SwHiddenTextField::ParseIfFieldDefinition(fieldDefinition, paramCondition, paramTrue, paramFalse); + + CPPUNIT_ASSERT_EQUAL(OUString("AAA"), paramCondition); + CPPUNIT_ASSERT_EQUAL(OUString("BBB"), paramTrue); + CPPUNIT_ASSERT_EQUAL(OUString("CCC"), paramFalse); + } + + { + const OUString fieldDefinition(" IF AAA \"BBB\" \"CCC\" "); + + OUString paramCondition; + OUString paramTrue; + OUString paramFalse; + + SwHiddenTextField::ParseIfFieldDefinition(fieldDefinition, paramCondition, paramTrue, paramFalse); + + CPPUNIT_ASSERT_EQUAL(OUString("AAA"), paramCondition); + CPPUNIT_ASSERT_EQUAL(OUString("BBB"), paramTrue); + CPPUNIT_ASSERT_EQUAL(OUString("CCC"), paramFalse); + } + + // true-case and false-case have spaces inside + { + const OUString fieldDefinition(" IF A A A \"B B B\" \"C C C\" "); + + OUString paramCondition; + OUString paramTrue; + OUString paramFalse; + + SwHiddenTextField::ParseIfFieldDefinition(fieldDefinition, paramCondition, paramTrue, paramFalse); + + CPPUNIT_ASSERT_EQUAL(OUString("A A A"), paramCondition); + CPPUNIT_ASSERT_EQUAL(OUString("B B B"), paramTrue); + CPPUNIT_ASSERT_EQUAL(OUString("C C C"), paramFalse); + } + + // true-case and false-case have leading/trailing space + { + const OUString fieldDefinition("IF A1 A2 A3 \"B1 B2 \" \" C1 C2\" "); + + OUString paramCondition; + OUString paramTrue; + OUString paramFalse; + + SwHiddenTextField::ParseIfFieldDefinition(fieldDefinition, paramCondition, paramTrue, paramFalse); + + CPPUNIT_ASSERT_EQUAL(OUString("A1 A2 A3"), paramCondition); + CPPUNIT_ASSERT_EQUAL(OUString("B1 B2 "), paramTrue); + CPPUNIT_ASSERT_EQUAL(OUString(" C1 C2"), paramFalse); + } + + // true-case and false-case are empty + { + const OUString fieldDefinition("IF condition \"\" \"\" "); + + OUString paramCondition; + OUString paramTrue; + OUString paramFalse; + + SwHiddenTextField::ParseIfFieldDefinition(fieldDefinition, paramCondition, paramTrue, paramFalse); + + CPPUNIT_ASSERT_EQUAL(OUString("condition"), paramCondition); + CPPUNIT_ASSERT_EQUAL(OUString(""), paramTrue); + CPPUNIT_ASSERT_EQUAL(OUString(""), paramFalse); + } +} + +// Input document contains only one IF-field, +// and it should be imported as com.sun.star.text.TextField.ConditionalText in any case, +// instead of insertion of the the pair of two field-marks: <field:fieldmark-start> + <field:fieldmark-end>. +DECLARE_ODFEXPORT_TEST(testTdf43569, "tdf43569_conditionalfield.doc") +{ + // check if our parser is valid + testTdf43569_CheckIfFieldParse(); + + // now check field creation during import + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + // at least one field should be detected + CPPUNIT_ASSERT(xFields->hasMoreElements()); +} + DECLARE_ODFEXPORT_TEST(testTdf103567, "tdf103567.odt") { uno::Reference<drawing::XShape> const xShape(getShape(1)); |