summaryrefslogtreecommitdiff
path: root/sw/qa/uibase
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2023-01-12 15:13:00 +0100
committerMiklos Vajna <vmiklos@collabora.com>2023-01-13 07:13:00 +0000
commit81f690ec0cb2a6dc0d6ca0f6de3adcc07eb7bc12 (patch)
tree4a5c8b5dba081f8ed6c08d5a12a1e1fa10559975 /sw/qa/uibase
parent14df26ac57696c11fd344bb16ec22738e42377fc (diff)
sw lok: expose name of refmark under cursor
This is similar to commit 4bcb66ec7b417fbe113267f2615e78fe47eb55ca (sw lok: expose name of bookmark under cursor, 2023-01-11), but that was for the bookmark under the cursor and this is for refmarks. Change-Id: I0acf0181d0acfdc087e1ed737b3c18ab3736031a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145405 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sw/qa/uibase')
-rw-r--r--sw/qa/uibase/uno/uno.cxx35
1 files changed, 35 insertions, 0 deletions
diff --git a/sw/qa/uibase/uno/uno.cxx b/sw/qa/uibase/uno/uno.cxx
index d2be66457b81..7a1b731634bd 100644
--- a/sw/qa/uibase/uno/uno.cxx
+++ b/sw/qa/uibase/uno/uno.cxx
@@ -475,6 +475,41 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetBookmark)
CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_BREF_1"), aBookmark.get<std::string>("name"));
}
+CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetField)
+{
+ // Given a document with a refmark:
+ createSwDoc();
+ uno::Sequence<css::beans::PropertyValue> aArgs = {
+ comphelper::makePropertyValue("TypeName", uno::Any(OUString("SetRef"))),
+ comphelper::makePropertyValue("Name",
+ uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} refmark"))),
+ comphelper::makePropertyValue("Content", uno::Any(OUString("content"))),
+ };
+ dispatchCommand(mxComponent, ".uno:InsertField", aArgs);
+
+ // When in the refmark with the cursor and getting the command value for .uno:Field:
+ SwDoc* pDoc = getSwDoc();
+ SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ pWrtShell->SttEndDoc(/*bStt=*/false);
+ pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
+ tools::JsonWriter aJsonWriter;
+ std::string_view aCommand(".uno:Field?typeName=SetRef&namePrefix=ZOTERO_ITEM%20CSL_CITATION");
+ auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ pXTextDocument->getCommandValues(aJsonWriter, aCommand);
+
+ // Then make sure we find the inserted refmark:
+ std::unique_ptr<char[], o3tl::free_delete> pJSON(aJsonWriter.extractData());
+ std::stringstream aStream(pJSON.get());
+ boost::property_tree::ptree aTree;
+ boost::property_tree::read_json(aStream, aTree);
+ boost::property_tree::ptree aBookmark = aTree.get_child("setRef");
+ // Without the accompanying fix in place, this test would have failed with:
+ // - No such node (setRef)
+ // i.e. the returned JSON was an empty object.
+ CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} refmark"),
+ aBookmark.get<std::string>("name"));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */