Filter out more unwanted command URIs
[LibreOffice.git] / sw / qa / uibase / uno / uno.cxx
blob046dd88c686196bb566287848337bb87ebba2d40
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <swmodeltestbase.hxx>
12 #include <boost/property_tree/json_parser.hpp>
14 #include <com/sun/star/frame/XModel2.hpp>
15 #include <com/sun/star/text/XTextViewTextRangeSupplier.hpp>
16 #include <com/sun/star/util/XCloseable.hpp>
17 #include <com/sun/star/text/XTextDocument.hpp>
18 #include <com/sun/star/beans/PropertyAttribute.hpp>
20 #include <vcl/scheduler.hxx>
21 #include <tools/json_writer.hxx>
22 #include <comphelper/propertyvalue.hxx>
23 #include <xmloff/odffields.hxx>
25 #include <docsh.hxx>
26 #include <edtwin.hxx>
27 #include <unotextrange.hxx>
28 #include <view.hxx>
29 #include <wrtsh.hxx>
30 #include <rootfrm.hxx>
31 #include <sortedobjs.hxx>
32 #include <anchoredobject.hxx>
33 #include <frameformats.hxx>
34 #include <fmtanchr.hxx>
35 #include <unotxdoc.hxx>
37 /// Covers sw/source/uibase/uno/ fixes.
38 class SwUibaseUnoTest : public SwModelTestBase
40 public:
41 SwUibaseUnoTest()
42 : SwModelTestBase(u"/sw/qa/uibase/uno/data/"_ustr)
47 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testLockControllers)
49 createSwDoc();
51 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY_THROW);
52 xModel->lockControllers();
55 uno::Reference<util::XCloseable> xCloseable(mxComponent, uno::UNO_QUERY_THROW);
56 xCloseable->close(false);
58 // Without the accompanying fix in place, this test would have crashed.
59 mxComponent.clear();
62 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testCondFieldCachedValue)
64 createSwDoc("cond-field-cached-value.docx");
65 Scheduler::ProcessEventsToIdle();
67 // Without the accompanying fix in place, this test would have failed with:
68 // - Expected: 1
69 // - Actual :
70 // i.e. the conditional field lost its cached content.
71 getParagraph(2, u"1"_ustr);
74 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testCreateTextRangeByPixelPosition)
76 // Given a document with 2 characters, and the pixel position of the point between them:
77 createSwDoc();
78 SwDoc* pDoc = getSwDoc();
79 SwDocShell* pDocShell = getSwDocShell();
80 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
81 pWrtShell->Insert2(u"AZ"_ustr);
82 pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
83 Point aLogic = pWrtShell->GetCharRect().Center();
84 SwView* pView = pDocShell->GetView();
85 SwEditWin& rEditWin = pView->GetEditWin();
86 Point aPixel = rEditWin.LogicToPixel(aLogic);
88 // When converting that pixel position to a document model position (text range):
89 uno::Reference<frame::XModel2> xModel(mxComponent, uno::UNO_QUERY);
90 uno::Reference<container::XEnumeration> xControllers = xModel->getControllers();
91 uno::Reference<text::XTextViewTextRangeSupplier> xController(xControllers->nextElement(),
92 uno::UNO_QUERY);
93 awt::Point aPoint(aPixel.getX(), aPixel.getY());
94 uno::Reference<text::XTextRange> xTextRange
95 = xController->createTextRangeByPixelPosition(aPoint);
97 // Then make sure that text range points after the first character:
98 auto pTextRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
99 SwPaM aPaM(pDoc->GetNodes());
100 pTextRange->GetPositions(aPaM);
101 sal_Int32 nActual = aPaM.GetPoint()->GetContentIndex();
102 // Without the needed PixelToLogic() call in place, this test would have failed with:
103 // - Expected: 1
104 // - Actual : 0
105 // i.e. the returned text range pointed before the first character, not between the first and
106 // the second character.
107 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), nActual);
110 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testCreateTextRangeByPixelPositionGraphic)
112 // Given a document with an as-char image and the center of that image in pixels:
113 createSwDoc();
114 uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
115 uno::Reference<beans::XPropertySet> xTextGraphic(
116 xFactory->createInstance(u"com.sun.star.text.TextGraphicObject"_ustr), uno::UNO_QUERY);
117 xTextGraphic->setPropertyValue(u"AnchorType"_ustr,
118 uno::Any(text::TextContentAnchorType_AS_CHARACTER));
119 xTextGraphic->setPropertyValue(u"Width"_ustr, uno::Any(static_cast<sal_Int32>(10000)));
120 xTextGraphic->setPropertyValue(u"Height"_ustr, uno::Any(static_cast<sal_Int32>(10000)));
121 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
122 uno::Reference<text::XText> xBodyText = xTextDocument->getText();
123 uno::Reference<text::XTextCursor> xCursor(xBodyText->createTextCursor());
124 uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY);
125 xBodyText->insertTextContent(xCursor, xTextContent, false);
126 SwDoc* pDoc = getSwDoc();
127 SwDocShell* pDocShell = getSwDocShell();
128 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
129 SwRootFrame* pLayout = pWrtShell->GetLayout();
130 SwFrame* pPage = pLayout->GetLower();
131 SwFrame* pBody = pPage->GetLower();
132 SwFrame* pText = pBody->GetLower();
133 SwSortedObjs& rDrawObjs = *pText->GetDrawObjs();
134 SwAnchoredObject* pAnchored = rDrawObjs[0];
135 Point aLogic = pAnchored->GetObjRect().Center();
136 SwView* pView = pDocShell->GetView();
137 SwEditWin& rEditWin = pView->GetEditWin();
138 Point aPixel = rEditWin.LogicToPixel(aLogic);
140 // When converting that pixel position to a document model position (text range):
141 uno::Reference<frame::XModel2> xModel(mxComponent, uno::UNO_QUERY);
142 uno::Reference<container::XEnumeration> xControllers = xModel->getControllers();
143 uno::Reference<text::XTextViewTextRangeSupplier> xController(xControllers->nextElement(),
144 uno::UNO_QUERY);
145 awt::Point aPoint(aPixel.getX(), aPixel.getY());
146 // Without the accompanying fix in place, this test would have crashed, because an XTextRange
147 // can't point to a graphic node.
148 uno::Reference<text::XTextRange> xTextRange
149 = xController->createTextRangeByPixelPosition(aPoint);
151 // Then make sure that the anchor of the image is returned:
152 const auto& rFormats = *pDoc->GetSpzFrameFormats();
153 const auto pFormat = rFormats[0];
154 SwPosition aAnchorPos(*pFormat->GetAnchor().GetContentAnchor());
155 auto pTextRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
156 SwPaM aPaM(pDoc->GetNodes());
157 pTextRange->GetPositions(aPaM);
158 CPPUNIT_ASSERT_EQUAL(aAnchorPos, *aPaM.GetPoint());
161 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testCreateTextRangeByPixelPositionAtPageGraphic)
163 // Given a document with an at-page anchored image:
164 createSwDoc();
165 uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY);
166 uno::Reference<beans::XPropertySet> xTextGraphic(
167 xFactory->createInstance(u"com.sun.star.text.TextGraphicObject"_ustr), uno::UNO_QUERY);
168 xTextGraphic->setPropertyValue(u"AnchorType"_ustr,
169 uno::Any(text::TextContentAnchorType_AT_PAGE));
170 xTextGraphic->setPropertyValue(u"AnchorPageNo"_ustr, uno::Any(static_cast<sal_Int16>(1)));
171 xTextGraphic->setPropertyValue(u"Width"_ustr, uno::Any(static_cast<sal_Int32>(10000)));
172 xTextGraphic->setPropertyValue(u"Height"_ustr, uno::Any(static_cast<sal_Int32>(10000)));
173 uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
174 uno::Reference<text::XText> xBodyText = xTextDocument->getText();
175 uno::Reference<text::XTextCursor> xCursor(xBodyText->createTextCursor());
176 uno::Reference<text::XTextContent> xTextContent(xTextGraphic, uno::UNO_QUERY);
177 xBodyText->insertTextContent(xCursor, xTextContent, false);
178 SwDocShell* pDocShell = getSwDocShell();
179 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
180 SwRootFrame* pLayout = pWrtShell->GetLayout();
181 SwFrame* pPage = pLayout->GetLower();
182 SwSortedObjs& rDrawObjs = *pPage->GetDrawObjs();
183 SwAnchoredObject* pAnchored = rDrawObjs[0];
184 Point aLogic = pAnchored->GetObjRect().Center();
185 SwView* pView = pDocShell->GetView();
186 SwEditWin& rEditWin = pView->GetEditWin();
187 Point aPixel = rEditWin.LogicToPixel(aLogic);
189 // When asking for the doc model pos of the image's anchor by pixel position:
190 uno::Reference<frame::XModel2> xModel(mxComponent, uno::UNO_QUERY);
191 uno::Reference<container::XEnumeration> xControllers = xModel->getControllers();
192 uno::Reference<text::XTextViewTextRangeSupplier> xController(xControllers->nextElement(),
193 uno::UNO_QUERY);
194 awt::Point aPoint(aPixel.getX(), aPixel.getY());
195 // Without the accompanying fix in place, this test would have crashed.
196 uno::Reference<text::XTextRange> xTextRange
197 = xController->createTextRangeByPixelPosition(aPoint);
199 // Then make sure that the result is empty, since the image is at-page anchored:
200 CPPUNIT_ASSERT(!xTextRange.is());
203 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetTextFormFields)
205 // Given a document with 3 fieldmarks: 2 zotero items and a zotero
206 // bibliography:
207 createSwDoc();
208 for (int i = 0; i < 2; ++i)
210 uno::Sequence<css::beans::PropertyValue> aArgs = {
211 comphelper::makePropertyValue(u"FieldType"_ustr, uno::Any(ODF_UNHANDLED)),
212 comphelper::makePropertyValue(u"FieldCommand"_ustr,
213 uno::Any(u"ADDIN ZOTERO_ITEM foo bar"_ustr)),
214 comphelper::makePropertyValue(u"FieldResult"_ustr, uno::Any(u"result"_ustr)),
216 dispatchCommand(mxComponent, u".uno:TextFormField"_ustr, aArgs);
219 uno::Sequence<css::beans::PropertyValue> aArgs = {
220 comphelper::makePropertyValue(u"FieldType"_ustr, uno::Any(ODF_UNHANDLED)),
221 comphelper::makePropertyValue(u"FieldCommand"_ustr,
222 uno::Any(u"ADDIN ZOTERO_BIBL foo bar"_ustr)),
223 comphelper::makePropertyValue(u"FieldResult"_ustr,
224 uno::Any(u"<p>aaa</p><p>bbb</p>"_ustr)),
226 dispatchCommand(mxComponent, u".uno:TextFormField"_ustr, aArgs);
229 // When getting the zotero items:
230 tools::JsonWriter aJsonWriter;
231 std::string_view aCommand(".uno:TextFormFields?type=vnd.oasis.opendocument.field.UNHANDLED&"
232 "commandPrefix=ADDIN%20ZOTERO_ITEM");
233 getSwTextDoc()->getCommandValues(aJsonWriter, aCommand);
235 // Then make sure we find the 2 items and ignore the bibliography:
236 OString pJSON(aJsonWriter.finishAndGetAsOString());
237 std::stringstream aStream((std::string(pJSON)));
238 boost::property_tree::ptree aTree;
239 boost::property_tree::read_json(aStream, aTree);
240 // Without the accompanying fix in place, this test would have failed with:
241 // - No such node (fields)
242 // i.e. the returned JSON was just empty.
243 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aTree.get_child("fields").count(""));
246 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetDocumentProperties)
248 // Given a document with 3 custom properties: 2 Zotero ones and one other:
249 createSwDoc();
250 SwDocShell* pDocShell = getSwDocShell();
251 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(pDocShell->GetModel(),
252 uno::UNO_QUERY);
253 uno::Reference<document::XDocumentProperties> xDP = xDPS->getDocumentProperties();
254 uno::Reference<beans::XPropertyContainer> xUDP = xDP->getUserDefinedProperties();
255 xUDP->addProperty(u"ZOTERO_PREF_1"_ustr, beans::PropertyAttribute::REMOVABLE,
256 uno::Any(u"foo"_ustr));
257 xUDP->addProperty(u"ZOTERO_PREF_2"_ustr, beans::PropertyAttribute::REMOVABLE,
258 uno::Any(u"bar"_ustr));
259 xUDP->addProperty(u"OTHER"_ustr, beans::PropertyAttribute::REMOVABLE, uno::Any(u"baz"_ustr));
261 // When getting the zotero properties:
262 tools::JsonWriter aJsonWriter;
263 std::string_view aCommand(".uno:SetDocumentProperties?namePrefix=ZOTERO_PREF_");
264 getSwTextDoc()->getCommandValues(aJsonWriter, aCommand);
266 // Then make sure we find the 2 properties and ignore the other one:
267 OString pJSON(aJsonWriter.finishAndGetAsOString());
268 std::stringstream aStream((std::string(pJSON)));
269 boost::property_tree::ptree aTree;
270 boost::property_tree::read_json(aStream, aTree);
271 // Without the accompanying fix in place, this test would have failed with:
272 // - No such node (userDefinedProperties)
273 // i.e. the returned JSON was just empty.
274 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2),
275 aTree.get_child("userDefinedProperties").count(""));
278 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetBookmarks)
280 // Given a document with 3 bookmarks: 2 zotero references and a zotero bibliography:
281 createSwDoc();
283 uno::Sequence<css::beans::PropertyValue> aArgs = {
284 comphelper::makePropertyValue(u"Bookmark"_ustr, uno::Any(u"ZOTERO_BREF_1"_ustr)),
286 dispatchCommand(mxComponent, u".uno:InsertBookmark"_ustr, aArgs);
289 uno::Sequence<css::beans::PropertyValue> aArgs = {
290 comphelper::makePropertyValue(u"Bookmark"_ustr, uno::Any(u"ZOTERO_BREF_2"_ustr)),
292 dispatchCommand(mxComponent, u".uno:InsertBookmark"_ustr, aArgs);
295 uno::Sequence<css::beans::PropertyValue> aArgs = {
296 comphelper::makePropertyValue(u"Bookmark"_ustr, uno::Any(u"ZOTERO_BIBL"_ustr)),
298 dispatchCommand(mxComponent, u".uno:InsertBookmark"_ustr, aArgs);
301 // When getting the reference bookmarks:
302 tools::JsonWriter aJsonWriter;
303 std::string_view aCommand(".uno:Bookmarks?namePrefix=ZOTERO_BREF_");
304 getSwTextDoc()->getCommandValues(aJsonWriter, aCommand);
306 // Then make sure we get the 2 references but not the bibliography:
307 OString pJSON(aJsonWriter.finishAndGetAsOString());
308 std::stringstream aStream((std::string(pJSON)));
309 boost::property_tree::ptree aTree;
310 boost::property_tree::read_json(aStream, aTree);
311 // Without the accompanying fix in place, this test would have failed with:
312 // - No such node (bookmarks)
313 // i.e. the returned JSON was just empty.
314 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aTree.get_child("bookmarks").count(""));
317 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetFields)
319 // Given a document with a refmark:
320 createSwDoc();
321 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
322 OUString aName(u"ZOTERO_ITEM CSL_CITATION {} "_ustr);
323 for (int i = 0; i < 5; ++i)
325 uno::Sequence<css::beans::PropertyValue> aArgs = {
326 comphelper::makePropertyValue(u"TypeName"_ustr, uno::Any(u"SetRef"_ustr)),
327 comphelper::makePropertyValue(u"Name"_ustr, uno::Any(aName + OUString::number(i + 1))),
328 comphelper::makePropertyValue(u"Content"_ustr, uno::Any(u"mycontent"_ustr)),
330 dispatchCommand(mxComponent, u".uno:InsertField"_ustr, aArgs);
331 pWrtShell->SttEndDoc(/*bStt=*/false);
332 pWrtShell->SplitNode();
333 pWrtShell->SttEndDoc(/*bStt=*/false);
336 // When getting the refmarks:
337 tools::JsonWriter aJsonWriter;
338 std::string_view aCommand(".uno:Fields?typeName=SetRef&namePrefix=ZOTERO_ITEM%20CSL_CITATION");
339 getSwTextDoc()->getCommandValues(aJsonWriter, aCommand);
341 // Then make sure we get the 1 refmark:
342 OString pJSON(aJsonWriter.finishAndGetAsOString());
343 std::stringstream aStream((std::string(pJSON)));
344 boost::property_tree::ptree aTree;
345 boost::property_tree::read_json(aStream, aTree);
346 // Without the accompanying fix in place, this test would have failed with:
347 // - No such node (setRefs)
348 // i.e. the returned JSON was just empty.
349 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(5), aTree.get_child("setRefs").count(""));
350 auto it = aTree.get_child("setRefs").begin();
351 boost::property_tree::ptree aRef = (it++)->second;
352 CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} 1"),
353 aRef.get<std::string>("name"));
354 aRef = (it++)->second;
355 CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} 2"),
356 aRef.get<std::string>("name"));
357 aRef = (it++)->second;
358 // Without the accompanying fix in place, this test would have failed with:
359 // - Expected: ZOTERO_ITEM CSL_CITATION {} 3
360 // - Actual : ZOTERO_ITEM CSL_CITATION {} 4
361 // i.e. the output was unsorted.
362 CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} 3"),
363 aRef.get<std::string>("name"));
364 aRef = (it++)->second;
365 CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} 4"),
366 aRef.get<std::string>("name"));
367 aRef = (it++)->second;
368 CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} 5"),
369 aRef.get<std::string>("name"));
372 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetTextFormField)
374 // Given a document with a fieldmark:
375 createSwDoc();
376 uno::Sequence<css::beans::PropertyValue> aArgs = {
377 comphelper::makePropertyValue(u"FieldType"_ustr, uno::Any(ODF_UNHANDLED)),
378 comphelper::makePropertyValue(u"FieldCommand"_ustr,
379 uno::Any(u"ADDIN ZOTERO_ITEM foo bar"_ustr)),
380 comphelper::makePropertyValue(u"FieldResult"_ustr, uno::Any(u"result"_ustr)),
382 dispatchCommand(mxComponent, u".uno:TextFormField"_ustr, aArgs);
384 // When stepping into the fieldmark with the cursor and getting the command value for
385 // uno:TextFormField:
386 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
387 pWrtShell->SttEndDoc(/*bStt=*/false);
388 pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
389 tools::JsonWriter aJsonWriter;
390 std::string_view aCommand(".uno:TextFormField?type=vnd.oasis.opendocument.field.UNHANDLED&"
391 "commandPrefix=ADDIN%20ZOTERO_ITEM");
392 getSwTextDoc()->getCommandValues(aJsonWriter, aCommand);
394 // Then make sure we find the inserted fieldmark:
395 OString pJSON(aJsonWriter.finishAndGetAsOString());
396 std::stringstream aStream((std::string(pJSON)));
397 boost::property_tree::ptree aTree;
398 boost::property_tree::read_json(aStream, aTree);
399 // Without the accompanying fix in place, this test would have failed with:
400 // - No such node (type)
401 // i.e. the returned JSON was just an empty object.
402 auto field = aTree.get_child("field");
403 CPPUNIT_ASSERT_EQUAL(std::string("vnd.oasis.opendocument.field.UNHANDLED"),
404 field.get<std::string>("type"));
405 CPPUNIT_ASSERT_EQUAL(std::string("ADDIN ZOTERO_ITEM foo bar"),
406 field.get<std::string>("command"));
409 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetSections)
411 // Given a document with a section:
412 createSwDoc();
413 uno::Sequence<css::beans::PropertyValue> aArgs = {
414 comphelper::makePropertyValue(
415 u"RegionName"_ustr, uno::Any(u"ZOTERO_BIBL {} CSL_BIBLIOGRAPHY RNDRfiit6mXBc"_ustr)),
416 comphelper::makePropertyValue(u"Content"_ustr, uno::Any(u"<p>aaa</p><p>bbb</p>"_ustr)),
418 dispatchCommand(mxComponent, u".uno:InsertSection"_ustr, aArgs);
420 // When asking for a list of section names:
421 tools::JsonWriter aJsonWriter;
422 std::string_view aCommand(".uno:Sections?namePrefix=ZOTERO_BIBL");
423 getSwTextDoc()->getCommandValues(aJsonWriter, aCommand);
425 // Make sure we find our just inserted section:
426 OString pJSON(aJsonWriter.finishAndGetAsOString());
427 std::stringstream aStream((std::string(pJSON)));
428 boost::property_tree::ptree aTree;
429 boost::property_tree::read_json(aStream, aTree);
430 // Without the accompanying fix in place, this test would have failed with:
431 // - No such node (sections)
432 // i.e. the returned JSON was an empty object.
433 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aTree.get_child("sections").count(""));
436 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetBookmark)
438 // Given a document with a bookmark:
439 createSwDoc();
440 uno::Sequence<css::beans::PropertyValue> aArgs = {
441 comphelper::makePropertyValue(u"Bookmark"_ustr, uno::Any(u"ZOTERO_BREF_1"_ustr)),
442 comphelper::makePropertyValue(u"BookmarkText"_ustr, uno::Any(u"<p>aaa</p><p>bbb</p>"_ustr)),
444 dispatchCommand(mxComponent, u".uno:InsertBookmark"_ustr, aArgs);
446 // When stepping into the bookmark with the cursor and getting the command value for
447 // .uno:Bookmark:
448 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
449 pWrtShell->SttEndDoc(/*bStt=*/false);
450 pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
451 tools::JsonWriter aJsonWriter;
452 std::string_view aCommand(".uno:Bookmark?namePrefix=ZOTERO_BREF_");
453 getSwTextDoc()->getCommandValues(aJsonWriter, aCommand);
455 // Then make sure we find the inserted bookmark:
456 OString pJSON(aJsonWriter.finishAndGetAsOString());
457 std::stringstream aStream((std::string(pJSON)));
458 boost::property_tree::ptree aTree;
459 boost::property_tree::read_json(aStream, aTree);
460 boost::property_tree::ptree aBookmark = aTree.get_child("bookmark");
461 // Without the accompanying fix in place, this test would have failed with:
462 // - No such node (bookmark)
463 // i.e. the returned JSON was an empty object.
464 CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_BREF_1"), aBookmark.get<std::string>("name"));
467 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testGetField)
469 // Given a document with a refmark:
470 createSwDoc();
471 uno::Sequence<css::beans::PropertyValue> aArgs = {
472 comphelper::makePropertyValue(u"TypeName"_ustr, uno::Any(u"SetRef"_ustr)),
473 comphelper::makePropertyValue(u"Name"_ustr,
474 uno::Any(u"ZOTERO_ITEM CSL_CITATION {} refmark"_ustr)),
475 comphelper::makePropertyValue(u"Content"_ustr, uno::Any(u"content"_ustr)),
477 dispatchCommand(mxComponent, u".uno:InsertField"_ustr, aArgs);
479 // When in the refmark with the cursor and getting the command value for .uno:Field:
480 SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
481 pWrtShell->SttEndDoc(/*bStt=*/false);
482 pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
483 tools::JsonWriter aJsonWriter;
484 std::string_view aCommand(".uno:Field?typeName=SetRef&namePrefix=ZOTERO_ITEM%20CSL_CITATION");
485 getSwTextDoc()->getCommandValues(aJsonWriter, aCommand);
487 // Then make sure we find the inserted refmark:
488 OString pJSON(aJsonWriter.finishAndGetAsOString());
489 std::stringstream aStream((std::string(pJSON)));
490 boost::property_tree::ptree aTree;
491 boost::property_tree::read_json(aStream, aTree);
492 boost::property_tree::ptree aBookmark = aTree.get_child("setRef");
493 // Without the accompanying fix in place, this test would have failed with:
494 // - No such node (setRef)
495 // i.e. the returned JSON was an empty object.
496 CPPUNIT_ASSERT_EQUAL(std::string("ZOTERO_ITEM CSL_CITATION {} refmark"),
497 aBookmark.get<std::string>("name"));
500 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testDoNotBreakWrappedTables)
502 // Given an empty document:
503 createSwDoc();
505 // When checking the state of the DoNotBreakWrappedTables compat flag:
506 uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY);
507 uno::Reference<beans::XPropertySet> xSettings(
508 xDocument->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY);
509 bool bDoNotBreakWrappedTables{};
510 // Without the accompanying fix in place, this test would have failed with:
511 // An uncaught exception of type com.sun.star.beans.UnknownPropertyException
512 // i.e. the compat flag was not recognized.
513 xSettings->getPropertyValue(u"DoNotBreakWrappedTables"_ustr) >>= bDoNotBreakWrappedTables;
514 // Then make sure it's false by default:
515 CPPUNIT_ASSERT(!bDoNotBreakWrappedTables);
517 // And when setting DoNotBreakWrappedTables=true:
518 xSettings->setPropertyValue(u"DoNotBreakWrappedTables"_ustr, uno::Any(true));
519 // Then make sure it gets enabled:
520 xSettings->getPropertyValue(u"DoNotBreakWrappedTables"_ustr) >>= bDoNotBreakWrappedTables;
521 CPPUNIT_ASSERT(bDoNotBreakWrappedTables);
524 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testAllowTextAfterFloatingTableBreak)
526 // Given an empty document:
527 createSwDoc();
529 // When checking the state of the AllowTextAfterFloatingTableBreak compat flag:
530 uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY);
531 uno::Reference<beans::XPropertySet> xSettings(
532 xDocument->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY);
533 bool bAllowTextAfterFloatingTableBreak{};
534 // Without the accompanying fix in place, this test would have failed with:
535 // An uncaught exception of type com.sun.star.beans.UnknownPropertyException
536 // i.e. the compat flag was not recognized.
537 xSettings->getPropertyValue(u"AllowTextAfterFloatingTableBreak"_ustr)
538 >>= bAllowTextAfterFloatingTableBreak;
539 // Then make sure it's false by default:
540 CPPUNIT_ASSERT(!bAllowTextAfterFloatingTableBreak);
542 // And when setting AllowTextAfterFloatingTableBreak=true:
543 xSettings->setPropertyValue(u"AllowTextAfterFloatingTableBreak"_ustr, uno::Any(true));
544 // Then make sure it gets enabled:
545 xSettings->getPropertyValue(u"AllowTextAfterFloatingTableBreak"_ustr)
546 >>= bAllowTextAfterFloatingTableBreak;
547 CPPUNIT_ASSERT(bAllowTextAfterFloatingTableBreak);
550 CPPUNIT_TEST_FIXTURE(SwUibaseUnoTest, testDoNotMirrorRtlDrawObjs)
552 // Given an empty document:
553 createSwDoc();
555 // When checking the state of the DoNotMirrorRtlDrawObjs compat flag:
556 uno::Reference<lang::XMultiServiceFactory> xDocument(mxComponent, uno::UNO_QUERY);
557 uno::Reference<beans::XPropertySet> xSettings(
558 xDocument->createInstance(u"com.sun.star.document.Settings"_ustr), uno::UNO_QUERY);
559 bool bDoNotMirrorRtlDrawObjs{};
560 // Without the accompanying fix in place, this test would have failed with:
561 // An uncaught exception of type com.sun.star.beans.UnknownPropertyException
562 // i.e. the compat flag was not recognized.
563 xSettings->getPropertyValue(u"DoNotMirrorRtlDrawObjs"_ustr) >>= bDoNotMirrorRtlDrawObjs;
564 // Then make sure it's false by default:
565 CPPUNIT_ASSERT(!bDoNotMirrorRtlDrawObjs);
567 // And when setting DoNotMirrorRtlDrawObjs=true:
568 xSettings->setPropertyValue(u"DoNotMirrorRtlDrawObjs"_ustr, uno::Any(true));
569 // Then make sure it gets enabled:
570 xSettings->getPropertyValue(u"DoNotMirrorRtlDrawObjs"_ustr) >>= bDoNotMirrorRtlDrawObjs;
571 CPPUNIT_ASSERT(bDoNotMirrorRtlDrawObjs);
574 CPPUNIT_PLUGIN_IMPLEMENT();
576 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */