diff options
Diffstat (limited to 'sw/qa/uibase/shells/shells.cxx')
-rw-r--r-- | sw/qa/uibase/shells/shells.cxx | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/sw/qa/uibase/shells/shells.cxx b/sw/qa/uibase/shells/shells.cxx index 4361920b3e87..01be5fda10b3 100644 --- a/sw/qa/uibase/shells/shells.cxx +++ b/sw/qa/uibase/shells/shells.cxx @@ -26,6 +26,7 @@ #include <comphelper/propertyvalue.hxx> #include <unotools/ucbstreamhelper.hxx> #include <xmloff/odffields.hxx> +#include <comphelper/string.hxx> #include <IDocumentContentOperations.hxx> #include <cmdid.h> @@ -35,6 +36,7 @@ #include <IDocumentDrawModelAccess.hxx> #include <drawdoc.hxx> #include <docsh.hxx> +#include <ndtxt.hxx> /// Covers sw/source/uibase/shells/ fixes. class SwUibaseShellsTest : public SwModelTestBase @@ -314,6 +316,67 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testInsertTextFormField) CPPUNIT_ASSERT_EQUAL(OUString("aaa\nbbb"), aActualResult); } +CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testUpdateFieldmarks) +{ + // Given a document with 2 fieldmarks: + createSwDoc(); + { + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(OUString(ODF_UNHANDLED))), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM old command 1"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("old result 1"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + } + { + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(OUString(ODF_UNHANDLED))), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM old command 2"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("old result 2"))), + }; + dispatchCommand(mxComponent, ".uno:TextFormField", aArgs); + } + + // When updating those fieldmarks: + uno::Sequence<css::beans::PropertyValue> aField1{ + comphelper::makePropertyValue("FieldType", uno::Any(OUString(ODF_UNHANDLED))), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM new command 1"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("new result 1"))), + }; + uno::Sequence<css::beans::PropertyValue> aField2{ + comphelper::makePropertyValue("FieldType", uno::Any(OUString(ODF_UNHANDLED))), + comphelper::makePropertyValue("FieldCommand", + uno::Any(OUString("ADDIN ZOTERO_ITEM new command 2"))), + comphelper::makePropertyValue("FieldResult", uno::Any(OUString("new result 2"))), + }; + uno::Sequence<uno::Sequence<css::beans::PropertyValue>> aFields = { aField1, aField2 }; + uno::Sequence<css::beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FieldType", uno::Any(OUString(ODF_UNHANDLED))), + comphelper::makePropertyValue("FieldCommandPrefix", + uno::Any(OUString("ADDIN ZOTERO_ITEM"))), + comphelper::makePropertyValue("Fields", uno::Any(aFields)), + }; + dispatchCommand(mxComponent, ".uno:TextFormFields", aArgs); + + // Then make sure that the document text contains the new field results: + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(/*bStt=*/true); + SwCursor* pCursor = pWrtShell->GetCursor(); + OUString aActual = pCursor->Start()->GetNode().GetTextNode()->GetText(); + static sal_Unicode const aForbidden[] + = { CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDSEP, CH_TXT_ATR_FIELDEND, 0 }; + aActual = comphelper::string::removeAny(aActual, aForbidden); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: new result 1new result 2 + // - Actual : old result 1old result 2 + // i.e. the fieldmarks were not updated. + CPPUNIT_ASSERT_EQUAL(OUString("new result 1new result 2"), aActual); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |