Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / sw / qa / core / macros-test.cxx
blob22d8126fa039792ec3e6c432c214e10fc55a182d
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 <sal/config.h>
12 #include <string_view>
14 #include <test/unoapi_test.hxx>
16 #include <com/sun/star/beans/XPropertySet.hpp>
17 #include <com/sun/star/container/XIndexContainer.hpp>
18 #include <com/sun/star/container/XNameContainer.hpp>
19 #include <com/sun/star/document/XEmbeddedScripts.hpp>
20 #include <com/sun/star/drawing/XControlShape.hpp>
21 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
22 #include <com/sun/star/drawing/XShapeGrouper.hpp>
23 #include <com/sun/star/drawing/XShape.hpp>
24 #include <com/sun/star/drawing/XShapes.hpp>
25 #include <com/sun/star/form/XForm.hpp>
26 #include <com/sun/star/form/XFormsSupplier.hpp>
27 #include <com/sun/star/frame/Desktop.hpp>
28 #include <com/sun/star/frame/XStorable.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/script/XLibraryContainer.hpp>
31 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
32 #include <com/sun/star/text/TextContentAnchorType.hpp>
33 #include <com/sun/star/text/XTextDocument.hpp>
34 #include <com/sun/star/util/SearchAlgorithms2.hpp>
35 #include <com/sun/star/util/SearchFlags.hpp>
37 #include <i18nutil/searchopt.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <comphelper/propertysequence.hxx>
40 #include <comphelper/scopeguard.hxx>
42 #include <unotools/tempfile.hxx>
44 #include <unocrsr.hxx>
45 #include <ndtxt.hxx>
46 #include <doc.hxx>
47 #include <IDocumentLayoutAccess.hxx>
48 #include <IDocumentMarkAccess.hxx>
49 #include <IDocumentUndoRedo.hxx>
50 #include <IDocumentContentOperations.hxx>
51 #include <docsh.hxx>
52 #include <unotxdoc.hxx>
54 typedef rtl::Reference<SwDocShell> SwDocShellRef;
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
59 /* Implementation of Macros test */
61 class SwMacrosTest : public UnoApiTest
63 public:
64 SwMacrosTest();
66 void testVba();
67 void testModernVBADelete();
68 void testBookmarkDeleteAndJoin();
69 void testBookmarkDeleteTdf90816();
70 void testControlShapeGrouping();
71 void testTdf151846();
72 void testTdf162431();
73 void testFdo55289();
74 void testFdo68983();
75 void testFdo87530();
76 void testFindReplace();
78 CPPUNIT_TEST_SUITE(SwMacrosTest);
79 CPPUNIT_TEST(testVba);
80 CPPUNIT_TEST(testModernVBADelete);
81 CPPUNIT_TEST(testBookmarkDeleteAndJoin);
82 CPPUNIT_TEST(testBookmarkDeleteTdf90816);
83 CPPUNIT_TEST(testControlShapeGrouping);
84 CPPUNIT_TEST(testTdf151846);
85 CPPUNIT_TEST(testTdf162431);
86 CPPUNIT_TEST(testFdo55289);
87 CPPUNIT_TEST(testFdo68983);
88 CPPUNIT_TEST(testFdo87530);
89 CPPUNIT_TEST(testFindReplace);
90 CPPUNIT_TEST_SUITE_END();
93 void SwMacrosTest::testVba()
95 TestMacroInfo testInfo[] = {
97 u"testVBA.docm"_ustr,
98 u"vnd.sun.Star.script:Project.ThisDocument.testAll?language=Basic&location=document"_ustr
101 u"testModernVBA.docm"_ustr,
102 u"vnd.sun.Star.script:Project.ThisDocument.testAll?language=Basic&location=document"_ustr
105 u"testFind.docm"_ustr,
106 u"vnd.sun.Star.script:Project.Module1.testAll?language=Basic&location=document"_ustr
109 u"testDocumentRange.docm"_ustr,
110 u"vnd.sun.Star.script:Project.Module1.testAll?language=Basic&location=document"_ustr
113 OUString("testSelectionFind.docm"),
114 OUString("vnd.sun.Star.script:Project.Module1.testAll?language=Basic&location=document")
117 //current working tests here!
119 OUString("testFontColor.docm"),
120 OUString("vnd.sun.Star.script:Project.ThisDocument.testAll?language=Basic&location=document")
122 // TODO - make these pass in Writer
124 OUString("testSentences.docm"),
125 OUString("vnd.sun.Star.script:Project.ThisDocument.TestAll?language=Basic&location=document")
128 OUString("testWords.docm"),
129 OUString("vnd.sun.Star.script:Project.ThisDocument.TestAll?language=Basic&location=document")
132 OUString("testParagraphFormat.docm"),
133 OUString("vnd.sun.Star.script:Project.ThisDocument.TestAll?language=Basic&location=document")
134 },*/
136 u"testTables.docm"_ustr,
137 u"vnd.sun.Star.script:Project.ThisDocument.TestAll?language=Basic&location=document"_ustr
140 for (auto const & [ sFileBaseName, sMacroUrl ] : testInfo)
142 OUString sFileName("docm/" + sFileBaseName);
143 loadFromFile(sFileName);
145 uno::Any aRet = executeMacro(sMacroUrl);
146 OUString aStringRes;
147 CPPUNIT_ASSERT_MESSAGE(sFileName.toUtf8().getStr(), aRet >>= aStringRes);
148 CPPUNIT_ASSERT_EQUAL(u"OK"_ustr, aStringRes);
152 void SwMacrosTest::testModernVBADelete()
154 TestMacroInfo testInfo =
156 u"testModernVBADelete.docm"_ustr,
157 u"vnd.sun.Star.script:Project.ThisDocument.testAll?language=Basic&location=document"_ustr
160 OUString sFileName("docm/" + testInfo.sFileBaseName);
161 loadFromFile(sFileName);
163 SwXTextDocument *const pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
164 SwDoc *const pDoc = pTextDoc->GetDocShell()->GetDoc();
165 pDoc->GetIDocumentUndoRedo().DoUndo(true);
166 CPPUNIT_ASSERT(!pDoc->GetIDocumentUndoRedo().GetUndoActionCount());
168 uno::Any aRet = executeMacro(testInfo.sMacroUrl);
169 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pDoc->GetIDocumentUndoRedo().GetUndoActionCount());
171 OUString aStringRes;
172 CPPUNIT_ASSERT(aRet >>= aStringRes);
173 CPPUNIT_ASSERT_EQUAL(u"OK"_ustr, aStringRes);
176 void SwMacrosTest::testBookmarkDeleteAndJoin()
178 rtl::Reference<SwDoc> const pDoc(new SwDoc);
179 pDoc->GetIDocumentUndoRedo().DoUndo(true); // bug is in SwUndoDelete
180 SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
181 SwPaM aPaM(aIdx);
183 IDocumentContentOperations & rIDCO(pDoc->getIDocumentContentOperations());
184 rIDCO.AppendTextNode(*aPaM.GetPoint());
185 rIDCO.InsertString(aPaM, u"A"_ustr);
186 rIDCO.AppendTextNode(*aPaM.GetPoint());
187 rIDCO.InsertString(aPaM, u"A"_ustr);
188 rIDCO.AppendTextNode(*aPaM.GetPoint());
189 aPaM.Move(fnMoveBackward, GoInNode);
190 aPaM.Move(fnMoveBackward, GoInNode);
191 aPaM.Move(fnMoveBackward, GoInContent);
192 aPaM.SetMark();
193 aPaM.Move(fnMoveForward, GoInDoc);
194 IDocumentMarkAccess & rIDMA = *pDoc->getIDocumentMarkAccess();
195 sw::mark::MarkBase *pMark =
196 rIDMA.makeMark(aPaM, u"test"_ustr, IDocumentMarkAccess::MarkType::BOOKMARK,
197 ::sw::mark::InsertMode::New);
198 CPPUNIT_ASSERT(pMark);
199 // select so pMark start position is on a node that is fully deleted
200 aPaM.Move(fnMoveBackward, GoInNode);
201 // must leave un-selected content in last node to get the bJoinPrev flag!
202 aPaM.Move(fnMoveBackward, GoInContent);
203 aPaM.Exchange();
204 aPaM.Move(fnMoveBackward, GoInDoc);
205 // delete
206 rIDCO.DeleteAndJoin(aPaM);
208 for (auto i = rIDMA.getAllMarksBegin(); i != rIDMA.getAllMarksEnd(); ++i)
210 // problem was that the nContent was pointing at deleted node
211 CPPUNIT_ASSERT_EQUAL((*i)->GetMarkStart().GetContentNode(),
212 static_cast<const SwContentNode*>((*i)->GetMarkStart().GetNode().GetContentNode()));
216 void SwMacrosTest::testBookmarkDeleteTdf90816()
218 rtl::Reference<SwDoc> const pDoc(new SwDoc);
219 pDoc->GetIDocumentUndoRedo().DoUndo(true); // bug is in SwUndoDelete
220 SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
221 SwPaM aPaM(aIdx);
223 IDocumentContentOperations & rIDCO(pDoc->getIDocumentContentOperations());
224 rIDCO.AppendTextNode(*aPaM.GetPoint());
225 rIDCO.InsertString(aPaM, u"ABC"_ustr);
226 aPaM.Move(fnMoveBackward, GoInContent);
227 aPaM.SetMark();
228 aPaM.Move(fnMoveBackward, GoInContent);
229 IDocumentMarkAccess & rIDMA = *pDoc->getIDocumentMarkAccess();
230 sw::mark::MarkBase *pMark =
231 rIDMA.makeMark(aPaM, u"test"_ustr, IDocumentMarkAccess::MarkType::BOOKMARK,
232 ::sw::mark::InsertMode::New);
233 CPPUNIT_ASSERT(pMark);
235 // delete the same selection as the bookmark
236 rIDCO.DeleteAndJoin(aPaM);
238 // bookmark still there?
239 auto iter = rIDMA.getAllMarksBegin();
240 CPPUNIT_ASSERT_MESSAGE("the bookmark was deleted",
241 iter != rIDMA.getAllMarksEnd());
242 CPPUNIT_ASSERT_EQUAL((*iter)->GetMarkPos(), *aPaM.Start());
243 CPPUNIT_ASSERT_EQUAL((*iter)->GetOtherMarkPos(), *aPaM.End());
246 void SwMacrosTest::testControlShapeGrouping()
248 loadFromFile(u"odt/testControlShapeGrouping.odt");
250 uno::Reference<frame::XModel> const xModel(mxComponent, UNO_QUERY);
251 CPPUNIT_ASSERT(xModel.is());
252 uno::Reference<lang::XMultiServiceFactory> xFactory(xModel, UNO_QUERY);
253 uno::Reference<drawing::XDrawPageSupplier> const xDPS(xModel, UNO_QUERY);
254 uno::Reference<drawing::XDrawPage> const xDP = xDPS->getDrawPage();
255 CPPUNIT_ASSERT(xDP.is());
256 uno::Reference<drawing::XShapes> const xDPShapes = xDP;
257 CPPUNIT_ASSERT(xDPShapes.is());
258 uno::Reference<drawing::XShapes> const xShapes(getMultiServiceFactory()->createInstance(u"com.sun.star.drawing.ShapeCollection"_ustr),
259 UNO_QUERY);
260 CPPUNIT_ASSERT(xShapes.is());
261 uno::Reference<container::XIndexAccess> xShapesIC = xShapes;
262 CPPUNIT_ASSERT(xShapesIC.is());
264 // uno::Reference<beans::XPropertySet> xFormProps(xForm, UNO_QUERY);
265 // xFormProps->setPropertyValue("Name", makeAny("aForm"));
266 uno::Reference<form::XFormsSupplier> const xFS(xDP, UNO_QUERY);
267 CPPUNIT_ASSERT(xFS.is());
268 uno::Reference<container::XIndexContainer> const xForms(xFS->getForms(), UNO_QUERY);
269 CPPUNIT_ASSERT(xForms.is());
270 uno::Reference<form::XForm> xForm(xForms->getByIndex(0), UNO_QUERY);
271 CPPUNIT_ASSERT(xForm.is());
272 uno::Reference<container::XNameContainer> xFormNC(xForm, UNO_QUERY);
274 uno::Reference<drawing::XControlShape> const xDateShape(
275 xFactory->createInstance(u"com.sun.star.drawing.ControlShape"_ustr),
276 UNO_QUERY);
277 uno::Reference<awt::XControlModel> const xDateControlModel(
278 xFactory->createInstance(u"com.sun.star.form.component.DateField"_ustr),
279 UNO_QUERY);
280 xDateShape->setControl(xDateControlModel);
281 uno::Reference<beans::XPropertySet> xDateShapeProps(xDateShape, UNO_QUERY);
282 xDateShapeProps->setPropertyValue(u"AnchorType"_ustr, Any(text::TextContentAnchorType_AT_PARAGRAPH));
284 uno::Reference<drawing::XControlShape> const xTimeShape(
285 xFactory->createInstance(u"com.sun.star.drawing.ControlShape"_ustr),
286 UNO_QUERY);
287 uno::Reference<awt::XControlModel> const xTimeControlModel(
288 xFactory->createInstance(u"com.sun.star.form.component.TimeField"_ustr),
289 UNO_QUERY);
290 xTimeShape->setControl(xTimeControlModel);
291 uno::Reference<beans::XPropertySet> xTimeShapeProps(xTimeShape, UNO_QUERY);
292 xTimeShapeProps->setPropertyValue(u"AnchorType"_ustr, Any(text::TextContentAnchorType_AT_PARAGRAPH));
294 xFormNC->insertByName(u"aDateCntrl"_ustr, Any(xDateControlModel));
295 xDPShapes->add(xDateShape);
296 xFormNC->insertByName(u"aTimeCntrl"_ustr, Any(xTimeControlModel));
297 xDPShapes->add(xTimeShape);
299 xShapes->add(xDateShape);
300 xShapes->add(xTimeShape);
301 uno::Reference<drawing::XShapeGrouper> const xDPGrouper(xDP, UNO_QUERY);
302 CPPUNIT_ASSERT(xDPGrouper.is());
303 uno::Reference<drawing::XShapeGroup> xGroup(xDPGrouper->group(xShapes));
304 CPPUNIT_ASSERT(xGroup.is());
306 #if 0
307 uno::Reference<container::XIndexAccess> xGroupIC(xGroup, UNO_QUERY);
308 CPPUNIT_ASSERT(xDateShape->getControl().is());
309 CPPUNIT_ASSERT_EQUAL(xDateShape->getControl(), xDateControlModel);
310 CPPUNIT_ASSERT(xTimeShape->getControl().is());
311 CPPUNIT_ASSERT_EQUAL(xTimeShape->getControl(), xTimeControlModel);
314 uno::Reference< uno::XInterface > xDI;
315 xGroupIC->getByIndex(0) >>= xDI;
316 CPPUNIT_ASSERT(xDI.is());
317 uno::Reference< drawing::XControlShape > xDS(xDI, UNO_QUERY);
318 CPPUNIT_ASSERT(xDS.is());
319 CPPUNIT_ASSERT_EQUAL(xDS->getControl(), xDateControlModel);
321 uno::Reference< uno::XInterface > xTI;
322 xGroupIC->getByIndex(1) >>= xTI;
323 CPPUNIT_ASSERT(xTI.is());
324 uno::Reference< drawing::XControlShape > xTS(xTI, UNO_QUERY);
325 CPPUNIT_ASSERT(xTS.is());
326 CPPUNIT_ASSERT_EQUAL(xTS->getControl(), xTimeControlModel);
329 uno::Reference< uno::XInterface > xDI;
330 xShapesIC->getByIndex(0) >>= xDI;
331 CPPUNIT_ASSERT(xDI.is());
332 uno::Reference< drawing::XControlShape > xDS(xDI, UNO_QUERY);
333 CPPUNIT_ASSERT(xDS.is());
334 CPPUNIT_ASSERT_EQUAL(xDS->getControl(), xDateControlModel);
336 uno::Reference< uno::XInterface > xTI;
337 xShapesIC->getByIndex(1) >>= xTI;
338 CPPUNIT_ASSERT(xTI.is());
339 uno::Reference< drawing::XControlShape > xTS(xTI, UNO_QUERY);
340 CPPUNIT_ASSERT(xTS.is());
341 CPPUNIT_ASSERT_EQUAL(xTS->getControl(), xTimeControlModel);
343 #endif
346 void SwMacrosTest::testTdf151846()
348 loadFromFile(u"odt/tdf151846.odt");
350 // Without the fix in place, this test would have failed with
351 // Property or method not found: createDiagramByDataSource.
352 executeMacro(u"vnd.sun.Star.script:Standard.Module1.Main?language=Basic&location=document"_ustr);
354 uno::Reference<text::XTextEmbeddedObjectsSupplier> xTEOSupplier(mxComponent, uno::UNO_QUERY);
355 uno::Reference<container::XNameAccess> xAccess(xTEOSupplier->getEmbeddedObjects());
356 uno::Sequence<OUString> aSeq(xAccess->getElementNames());
358 // Check number of embedded objects.
359 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aSeq.getLength());
362 void SwMacrosTest::testTdf162431()
364 loadFromFile(u"odt/tdf162431.odt");
366 uno::Any aRet = executeMacro(
367 u"vnd.sun.Star.script:Standard.Module1.TestIsMissingUnoParameter?language=Basic&location=document"_ustr);
369 OUString aStringRes;
370 CPPUNIT_ASSERT(aRet >>= aStringRes);
371 CPPUNIT_ASSERT_EQUAL(u"OK"_ustr, aStringRes);
374 void SwMacrosTest::testFdo55289()
376 SwDoc* const pDoc = new SwDoc;
377 SwDocShellRef pDocShell = new SwDocShell(*pDoc, SfxObjectCreateMode::EMBEDDED);
378 // this needs to run with no layout to tickle the bugs in the special
379 // cases in SwXShape re-anchoring
380 assert(!pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
382 uno::Reference<frame::XModel> const xModel(pDocShell->GetModel());
383 uno::Reference<drawing::XDrawPageSupplier> const xDPS(xModel, UNO_QUERY);
384 uno::Reference<drawing::XShapes> const xShapes = xDPS->getDrawPage();
385 uno::Reference<beans::XPropertySet> const xShape(
386 uno::Reference<lang::XMultiServiceFactory>(xModel, UNO_QUERY_THROW)->
387 createInstance(u"com.sun.star.drawing.GraphicObjectShape"_ustr),
388 UNO_QUERY);
389 xShape->setPropertyValue(u"AnchorType"_ustr,
390 Any(text::TextContentAnchorType_AT_PAGE));
391 xShapes->add(uno::Reference<drawing::XShape>(xShape, UNO_QUERY));
392 xShape->setPropertyValue(u"AnchorType"_ustr,
393 Any(text::TextContentAnchorType_AT_CHARACTER));
394 xShape->setPropertyValue(u"AnchorType"_ustr,
395 Any(text::TextContentAnchorType_AS_CHARACTER));
396 xShape->setPropertyValue(u"AnchorType"_ustr,
397 Any(text::TextContentAnchorType_AT_CHARACTER));
398 xShape->setPropertyValue(u"AnchorType"_ustr,
399 Any(text::TextContentAnchorType_AS_CHARACTER));
400 uno::Reference<text::XTextRange> const xEnd =
401 uno::Reference<text::XTextDocument>(xModel, UNO_QUERY_THROW)->getText()->getEnd();
402 uno::Reference<text::XTextContent> const xShapeContent(xShape, UNO_QUERY);
403 xShapeContent->attach(xEnd);
404 pDocShell->DoClose();
407 void SwMacrosTest::testFdo68983()
409 loadFromFile(u"odt/fdo68983.odt");
410 Reference< frame::XStorable > xDocStorable(mxComponent, UNO_QUERY_THROW);
412 saveAndReload(u"writer8"_ustr);
414 // check that password-protected library survived store and re-load
415 Reference<document::XEmbeddedScripts> xDocScr(mxComponent, UNO_QUERY_THROW);
416 Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries());
417 Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW);
418 Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW);
419 CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected(u"Library1"_ustr));
420 CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword(u"Library1"_ustr, u"foo"_ustr));
421 xBasLib->loadLibrary(u"Library1"_ustr);
422 CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(u"Library1"_ustr));
425 void SwMacrosTest::testFdo87530()
427 loadFromURL(u"private:factory/swriter"_ustr);
430 // insert initial password protected library
431 Reference<document::XEmbeddedScripts> xDocScr(mxComponent, UNO_QUERY_THROW);
432 Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries());
433 Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW);
434 Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW);
435 Reference<container::XNameContainer> xLibrary(xBasLib->createLibrary(u"BarLibrary"_ustr));
436 xLibrary->insertByName(u"BarModule"_ustr,
437 uno::Any(u"Sub Main\nEnd Sub\n"_ustr));
438 xBasLibPwd->changeLibraryPassword(u"BarLibrary"_ustr, u""_ustr, u"foo"_ustr);
441 saveAndReload(u"writer8"_ustr);
444 // check that password-protected library survived store and re-load
445 Reference<document::XEmbeddedScripts> xDocScr(mxComponent, UNO_QUERY_THROW);
446 Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries());
447 Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW);
448 Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW);
449 CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected(u"BarLibrary"_ustr));
450 CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword(u"BarLibrary"_ustr, u"foo"_ustr));
451 xBasLib->loadLibrary(u"BarLibrary"_ustr);
452 CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(u"BarLibrary"_ustr));
453 Reference<container::XNameContainer> xLibrary(xBasLib->getByName(u"BarLibrary"_ustr), UNO_QUERY);
454 Any module(xLibrary->getByName(u"BarModule"_ustr));
455 CPPUNIT_ASSERT_EQUAL(u"Sub Main\nEnd Sub\n"_ustr, module.get<OUString>());
457 // add a second module now - tdf#87530 happened here
458 Reference<container::XNameContainer> xFooLib(xBasLib->createLibrary(u"FooLibrary"_ustr));
459 xFooLib->insertByName(u"FooModule"_ustr,
460 uno::Any(u"Sub Main\nEnd Sub\n"_ustr));
461 xBasLibPwd->changeLibraryPassword(u"FooLibrary"_ustr, u""_ustr, u"foo"_ustr);
464 saveAndReload(u"writer8"_ustr);
466 // check that password-protected library survived store and re-load
467 Reference<document::XEmbeddedScripts> xDocScr(mxComponent, UNO_QUERY_THROW);
468 Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries());
469 Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW);
470 Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW);
471 CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected(u"FooLibrary"_ustr));
472 CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword(u"FooLibrary"_ustr, u"foo"_ustr));
473 xBasLib->loadLibrary(u"FooLibrary"_ustr);
474 CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(u"FooLibrary"_ustr));
475 Reference<container::XNameContainer> xLibrary(xBasLib->getByName(u"FooLibrary"_ustr), UNO_QUERY);
476 Any module(xLibrary->getByName(u"FooModule"_ustr));
477 CPPUNIT_ASSERT_EQUAL(u"Sub Main\nEnd Sub\n"_ustr, module.get<OUString>());
481 void SwMacrosTest::testFindReplace()
483 // we need a full document with view and layout etc. because ::GetNode()
484 loadFromURL(u"private:factory/swriter"_ustr);
486 SwXTextDocument *const pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
487 CPPUNIT_ASSERT(pTextDoc);
488 SwDoc *const pDoc = pTextDoc->GetDocShell()->GetDoc();
489 SwNodeIndex aIdx(pDoc->GetNodes().GetEndOfContent(), -1);
490 // use a UnoCursor so it will be corrected when deleting nodes
491 auto pPaM(pDoc->CreateUnoCursor(SwPosition(aIdx)));
493 IDocumentContentOperations & rIDCO(pDoc->getIDocumentContentOperations());
494 rIDCO.InsertString(*pPaM, u"foo"_ustr);
495 rIDCO.AppendTextNode(*pPaM->GetPoint());
496 rIDCO.InsertString(*pPaM, u"bar"_ustr);
497 rIDCO.AppendTextNode(*pPaM->GetPoint());
498 rIDCO.InsertString(*pPaM, u"baz"_ustr);
499 pPaM->Move(fnMoveBackward, GoInDoc);
501 bool bCancel(false);
502 i18nutil::SearchOptions2 opts(
503 css::util::SearchFlags::LEV_RELAXED,
504 u"$"_ustr,
505 u""_ustr,
506 lang::Locale(u"en"_ustr, u"US"_ustr, u""_ustr),
510 TransliterationFlags::IGNORE_CASE | TransliterationFlags::IGNORE_WIDTH |
511 TransliterationFlags::IGNORE_KASHIDA_CTL | TransliterationFlags::IGNORE_DIACRITICS_CTL,
512 util::SearchAlgorithms2::REGEXP,
513 '\\');
515 // find newline on 1st paragraph
516 bool bFound = pPaM->Find_Text(
517 opts, false, SwDocPositions::Curr, SwDocPositions::End, bCancel, FindRanges::InBody);
518 CPPUNIT_ASSERT(bFound);
519 CPPUNIT_ASSERT(pPaM->HasMark());
520 CPPUNIT_ASSERT(pPaM->GetPoint()->GetNode() != pPaM->GetMark()->GetNode());
521 CPPUNIT_ASSERT_EQUAL(OUString(OUStringChar(CH_TXTATR_NEWLINE)), pPaM->GetText());
523 // now do another Find, inside the selection from the first Find
524 // opts.searchFlags = 71680;
525 bFound = pPaM->Find_Text(
526 opts, false, SwDocPositions::Curr, SwDocPositions::End, bCancel, FindRanges::InSel);
527 CPPUNIT_ASSERT(bFound);
528 CPPUNIT_ASSERT(pPaM->HasMark());
529 CPPUNIT_ASSERT(pPaM->GetPoint()->GetNode() != pPaM->GetMark()->GetNode());
530 CPPUNIT_ASSERT_EQUAL(OUString(OUStringChar(CH_TXTATR_NEWLINE)), pPaM->GetText());
532 rIDCO.ReplaceRange(*pPaM, u" "_ustr, true);
534 pPaM->DeleteMark();
535 pPaM->Move(fnMoveBackward, GoInDoc);
537 // problem was that after the 2nd Find, the wrong newline was selected
538 CPPUNIT_ASSERT_EQUAL(u"foo bar"_ustr,
539 pPaM->Start()->GetNode().GetTextNode()->GetText());
540 pPaM->Move(fnMoveForward, GoInNode);
541 CPPUNIT_ASSERT_EQUAL(u"baz"_ustr,
542 pPaM->End()->GetNode().GetTextNode()->GetText());
545 SwMacrosTest::SwMacrosTest()
546 : UnoApiTest(u"/sw/qa/core/data/"_ustr)
550 CPPUNIT_TEST_SUITE_REGISTRATION(SwMacrosTest);
552 CPPUNIT_PLUGIN_IMPLEMENT();
554 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */