1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <sal/config.h>
11 #include <unotest/macros_test.hxx>
12 #include <test/bootstrapfixture.hxx>
13 #include <rtl/strbuf.hxx>
14 #include <osl/file.hxx>
16 #include <com/sun/star/frame/XDesktop.hpp>
18 #include <com/sun/star/lang/XComponent.hpp>
19 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/util/SearchOptions.hpp>
22 #include <com/sun/star/frame/Desktop.hpp>
23 #include <com/sun/star/frame/XComponentLoader.hpp>
24 #include <com/sun/star/frame/XStorable.hpp>
25 #include <com/sun/star/document/MacroExecMode.hpp>
26 #include <com/sun/star/document/XEmbeddedScripts.hpp>
27 #include <com/sun/star/script/XLibraryContainer.hpp>
28 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
29 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
30 #include <com/sun/star/drawing/XShapes.hpp>
31 #include <com/sun/star/drawing/XShape.hpp>
32 #include <com/sun/star/drawing/XShapeGrouper.hpp>
33 #include <com/sun/star/drawing/XControlShape.hpp>
34 #include <com/sun/star/text/XTextDocument.hpp>
35 #include <com/sun/star/text/TextContentAnchorType.hpp>
36 #include <com/sun/star/form/XForm.hpp>
37 #include <com/sun/star/form/XFormsSupplier.hpp>
38 #include <com/sun/star/awt/XControlModel.hpp>
39 #include <com/sun/star/container/XIndexContainer.hpp>
41 #include <sfx2/app.hxx>
42 #include <sfx2/docfilt.hxx>
43 #include <sfx2/docfile.hxx>
44 #include <sfx2/sfxmodelfactory.hxx>
45 #include <svl/intitem.hxx>
46 #include <comphelper/processfactory.hxx>
48 #include <basic/sbxdef.hxx>
49 #include <unotools/tempfile.hxx>
51 #include <unocrsr.hxx>
54 #include <IDocumentLayoutAccess.hxx>
55 #include <IDocumentUndoRedo.hxx>
56 #include <IDocumentContentOperations.hxx>
58 #include <unotxdoc.hxx>
60 typedef tools::SvRef
<SwDocShell
> SwDocShellRef
;
62 using namespace ::com::sun::star
;
63 using namespace ::com::sun::star::uno
;
65 /* Implementation of Macros test */
67 class SwMacrosTest
: public test::BootstrapFixture
, public unotest::MacrosTest
72 void createFileURL(const OUString
& aFileBase
, const OUString
& aFileExtension
, OUString
& rFilePath
);
74 virtual void setUp() SAL_OVERRIDE
;
75 virtual void tearDown() SAL_OVERRIDE
;
77 //void testStarBasic();
78 #if !defined MACOSX && !defined WNT
81 void testBookmarkDeleteAndJoin();
82 void testBookmarkDeleteTdf90816();
84 void testControlShapeGrouping();
88 void testFindReplace();
89 CPPUNIT_TEST_SUITE(SwMacrosTest
);
90 #if !defined(MACOSX) && !defined(WNT)
91 //enable this test if you want to play with star basic macros in unit tests
92 //works but does nothing useful yet
93 //CPPUNIT_TEST(testStarBasic);
94 CPPUNIT_TEST(testVba
);
96 CPPUNIT_TEST(testBookmarkDeleteAndJoin
);
97 CPPUNIT_TEST(testBookmarkDeleteTdf90816
);
99 CPPUNIT_TEST(testControlShapeGrouping
);
101 CPPUNIT_TEST(testFdo55289
);
102 CPPUNIT_TEST(testFdo68983
);
103 CPPUNIT_TEST(testFindReplace
);
105 CPPUNIT_TEST_SUITE_END();
108 uno::Reference
<uno::XInterface
> m_xWriterComponent
;
109 OUString m_aBaseString
;
112 void SwMacrosTest::createFileURL(const OUString
& aFileBase
, const OUString
& aFileExtension
, OUString
& rFilePath
)
115 OUStringBuffer
aBuffer( getSrcRootURL() );
116 aBuffer
.append(m_aBaseString
).append(aSep
).append(aFileExtension
);
117 aBuffer
.append(aSep
).append(aFileBase
).append(aFileExtension
);
118 rFilePath
= aBuffer
.makeStringAndClear();
123 void SwMacrosTest::testStarBasic()
125 const OUString
aFileNameBase("StarBasic.");
126 OUString
aFileExtension(aFileFormats
[0].pName
, strlen(aFileFormats
[0].pName
), RTL_TEXTENCODING_UTF8
);
128 createFileURL(aFileNameBase
, aFileExtension
, aFileName
);
129 uno::Reference
< com::sun::star::lang::XComponent
> xComponent
= loadFromDesktop(aFileName
, "com.sun.star.text.TextDocument");
131 CPPUNIT_ASSERT_MESSAGE("Failed to load StarBasic.ods", xComponent
.is());
133 OUString
aURL("vnd.sun.Star.script:Standard.Module1.Macro1?language=Basic&location=document");
136 Sequence
< sal_Int16
> aOutParamIndex
;
137 Sequence
< Any
> aOutParam
;
138 Sequence
< uno::Any
> aParams
;
140 SfxObjectShell
* pFoundShell
= SfxObjectShell::GetShellFromComponent(xComponent
);
142 CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell
);
144 pFoundShell
->CallXScript(xComponent
, sUrl
, aParams
, aRet
, aOutParamIndex
,aOutParam
);
145 pFoundShell
->DoClose();
150 #if !defined MACOSX && !defined WNT
151 void SwMacrosTest::testVba()
153 TestMacroInfo testInfo
[] = {
155 OUString("testVba."),
156 OUString("vnd.sun.Star.script:Project.NewMacros.Macro1?language=Basic&location=document")
159 OUString
aFileExtension( "doc" );
160 for ( sal_uInt32 i
=0; i
<SAL_N_ELEMENTS( testInfo
); ++i
)
163 createFileURL(testInfo
[i
].sFileBaseName
, aFileExtension
, aFileName
);
164 uno::Reference
< com::sun::star::lang::XComponent
> xComponent
= loadFromDesktop(aFileName
, "com.sun.star.text.TextDocument");
165 OUStringBuffer
sMsg( "Failed to load " );
166 sMsg
.append ( aFileName
);
167 CPPUNIT_ASSERT_MESSAGE( OUStringToOString( sMsg
.makeStringAndClear(), RTL_TEXTENCODING_UTF8
).getStr(), xComponent
.is() );
169 OUString sUrl
= testInfo
[i
].sMacroUrl
;
171 Sequence
< sal_Int16
> aOutParamIndex
;
172 Sequence
< Any
> aOutParam
;
173 Sequence
< uno::Any
> aParams
;
175 SfxObjectShell
* pFoundShell
= SfxObjectShell::GetShellFromComponent(xComponent
);
177 CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell
);
178 SfxObjectShell::CallXScript(xComponent
, sUrl
, aParams
, aRet
, aOutParamIndex
,aOutParam
);
181 std::cout
<< "value of Ret " << OUStringToOString( aStringRes
, RTL_TEXTENCODING_UTF8
).getStr() << std::endl
;
182 //CPPUNIT_ASSERT_MESSAGE( "script reported failure",aStringRes == "OK" );
183 pFoundShell
->DoClose();
188 void SwMacrosTest::testBookmarkDeleteAndJoin()
190 SwDoc
*const pDoc
= new SwDoc
;
191 pDoc
->GetIDocumentUndoRedo().DoUndo(true); // bug is in SwUndoDelete
192 SwNodeIndex
aIdx(pDoc
->GetNodes().GetEndOfContent(), -1);
195 IDocumentContentOperations
& rIDCO(pDoc
->getIDocumentContentOperations());
196 rIDCO
.AppendTextNode(*aPaM
.GetPoint());
197 rIDCO
.InsertString(aPaM
, OUString("A"));
198 rIDCO
.AppendTextNode(*aPaM
.GetPoint());
199 rIDCO
.InsertString(aPaM
, OUString("A"));
200 rIDCO
.AppendTextNode(*aPaM
.GetPoint());
201 aPaM
.Move(fnMoveBackward
, fnGoNode
);
202 aPaM
.Move(fnMoveBackward
, fnGoNode
);
203 aPaM
.Move(fnMoveBackward
, fnGoContent
);
205 aPaM
.Move(fnMoveForward
, fnGoDoc
);
206 IDocumentMarkAccess
& rIDMA
= *pDoc
->getIDocumentMarkAccess();
207 sw::mark::IMark
*pMark
=
208 rIDMA
.makeMark(aPaM
, "test", IDocumentMarkAccess::MarkType::BOOKMARK
);
209 CPPUNIT_ASSERT(pMark
);
210 // select so pMark start position is on a node that is fully deleted
211 aPaM
.Move(fnMoveBackward
, fnGoNode
);
212 // must leave un-selected content in last node to get the bJoinPrev flag!
213 aPaM
.Move(fnMoveBackward
, fnGoContent
);
215 aPaM
.Move(fnMoveBackward
, fnGoDoc
);
217 rIDCO
.DeleteAndJoin(aPaM
, false);
219 for (IDocumentMarkAccess::const_iterator_t i
= rIDMA
.getAllMarksBegin(); i
!= rIDMA
.getAllMarksEnd(); ++i
)
221 // problem was that the nContent was pointing at deleted node
222 CPPUNIT_ASSERT((*i
)->GetMarkStart().nNode
.GetNode().GetContentNode() ==
223 static_cast<const SwContentNode
*>((*i
)->GetMarkStart().nContent
.GetIdxReg()));
227 void SwMacrosTest::testBookmarkDeleteTdf90816()
229 SwDoc
*const pDoc
= new SwDoc
;
230 pDoc
->GetIDocumentUndoRedo().DoUndo(true); // bug is in SwUndoDelete
231 SwNodeIndex
aIdx(pDoc
->GetNodes().GetEndOfContent(), -1);
234 IDocumentContentOperations
& rIDCO(pDoc
->getIDocumentContentOperations());
235 rIDCO
.AppendTextNode(*aPaM
.GetPoint());
236 rIDCO
.InsertString(aPaM
, OUString("ABC"));
237 aPaM
.Move(fnMoveBackward
, fnGoContent
);
239 aPaM
.Move(fnMoveBackward
, fnGoContent
);
240 IDocumentMarkAccess
& rIDMA
= *pDoc
->getIDocumentMarkAccess();
241 sw::mark::IMark
*pMark
=
242 rIDMA
.makeMark(aPaM
, "test", IDocumentMarkAccess::MarkType::BOOKMARK
);
243 CPPUNIT_ASSERT(pMark
);
245 // delete the same selection as the bookmark
246 rIDCO
.DeleteAndJoin(aPaM
, false);
248 // bookmark still there?
249 auto iter
= rIDMA
.getAllMarksBegin();
250 CPPUNIT_ASSERT_MESSAGE("the bookmark was deleted",
251 iter
!= rIDMA
.getAllMarksEnd());
252 CPPUNIT_ASSERT(*aPaM
.Start() == (*iter
)->GetMarkPos());
253 CPPUNIT_ASSERT(*aPaM
.End() == (*iter
)->GetOtherMarkPos());
257 void SwMacrosTest::testControlShapeGrouping()
260 createFileURL("testControlShapeGrouping.", "odt", aFileName
);
261 Reference
< com::sun::star::lang::XComponent
> xComponent(
262 loadFromDesktop(aFileName
, "com.sun.star.text.TextDocument"));
263 CPPUNIT_ASSERT(xComponent
.is());
265 uno::Reference
<frame::XModel
> const xModel(xComponent
, UNO_QUERY
);
266 CPPUNIT_ASSERT(xModel
.is());
267 uno::Reference
<lang::XMultiServiceFactory
> xFactory(xModel
, UNO_QUERY
);
268 uno::Reference
<drawing::XDrawPageSupplier
> const xDPS(xModel
, UNO_QUERY
);
269 uno::Reference
<drawing::XDrawPage
> const xDP(xDPS
->getDrawPage(), UNO_QUERY
);
270 CPPUNIT_ASSERT(xDP
.is());
271 uno::Reference
<drawing::XShapes
> const xDPShapes(xDP
, UNO_QUERY
);
272 CPPUNIT_ASSERT(xDPShapes
.is());
273 uno::Reference
<drawing::XShapes
> const xShapes(getMultiServiceFactory()->createInstance("com.sun.star.drawing.ShapeCollection"),
275 CPPUNIT_ASSERT(xShapes
.is());
276 uno::Reference
<container::XIndexAccess
> xShapesIC(xShapes
, UNO_QUERY
);
277 CPPUNIT_ASSERT(xShapesIC
.is());
279 // uno::Reference<beans::XPropertySet> xFormProps(xForm, UNO_QUERY);
280 // xFormProps->setPropertyValue("Name", makeAny("aForm"));
281 uno::Reference
<form::XFormsSupplier
> const xFS(xDP
, UNO_QUERY
);
282 CPPUNIT_ASSERT(xFS
.is());
283 uno::Reference
<container::XIndexContainer
> const xForms(xFS
->getForms(), UNO_QUERY
);
284 CPPUNIT_ASSERT(xForms
.is());
285 uno::Reference
<form::XForm
> xForm(xForms
->getByIndex(0), UNO_QUERY
);
286 CPPUNIT_ASSERT(xForm
.is());
287 uno::Reference
<container::XNameContainer
> xFormNC(xForm
, UNO_QUERY
);
289 uno::Reference
<drawing::XControlShape
> const xDateShape(
290 xFactory
->createInstance("com.sun.star.drawing.ControlShape"),
292 uno::Reference
<awt::XControlModel
> const xDateControlModel(
293 xFactory
->createInstance("com.sun.star.form.component.DateField"),
295 xDateShape
->setControl(xDateControlModel
);
296 uno::Reference
<beans::XPropertySet
> xDateShapeProps(xDateShape
, UNO_QUERY
);
297 xDateShapeProps
->setPropertyValue("AnchorType", makeAny(text::TextContentAnchorType_AT_PARAGRAPH
));
299 uno::Reference
<drawing::XControlShape
> const xTimeShape(
300 xFactory
->createInstance("com.sun.star.drawing.ControlShape"),
302 uno::Reference
<awt::XControlModel
> const xTimeControlModel(
303 xFactory
->createInstance("com.sun.star.form.component.TimeField"),
305 xTimeShape
->setControl(xTimeControlModel
);
306 uno::Reference
<beans::XPropertySet
> xTimeShapeProps(xTimeShape
, UNO_QUERY
);
307 xTimeShapeProps
->setPropertyValue("AnchorType", makeAny(text::TextContentAnchorType_AT_PARAGRAPH
));
309 xFormNC
->insertByName("aDateCntrl", makeAny(xDateControlModel
));
310 xDPShapes
->add(xDateShape
);
311 xFormNC
->insertByName("aTimeCntrl", makeAny(xTimeControlModel
));
312 xDPShapes
->add(xTimeShape
);
314 xShapes
->add(uno::Reference
<drawing::XShape
>(xDateShape
, UNO_QUERY
));
315 xShapes
->add(uno::Reference
<drawing::XShape
>(xTimeShape
, UNO_QUERY
));
316 uno::Reference
<drawing::XShapeGrouper
> const xDPGrouper(xDP
, UNO_QUERY
);
317 CPPUNIT_ASSERT(xDPGrouper
.is());
318 uno::Reference
<drawing::XShapeGroup
> xGroup(xDPGrouper
->group(xShapes
));
319 CPPUNIT_ASSERT(xGroup
.is());
320 uno::Reference
<container::XIndexAccess
> xGroupIC(xGroup
, UNO_QUERY
);
321 CPPUNIT_ASSERT(xGroup
.is());
323 CPPUNIT_ASSERT(xDateShape
->getControl().is());
324 CPPUNIT_ASSERT(xDateShape
->getControl() == xDateControlModel
);
325 CPPUNIT_ASSERT(xTimeShape
->getControl().is());
326 CPPUNIT_ASSERT(xTimeShape
->getControl() == xTimeControlModel
);
329 uno::Reference
< uno::XInterface
> xDI
;
330 xGroupIC
->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(xDS
->getControl() == xDateControlModel
);
336 uno::Reference
< uno::XInterface
> xTI
;
337 xGroupIC
->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(xTS
->getControl() == xTimeControlModel
);
344 uno::Reference
< uno::XInterface
> xDI
;
345 xShapesIC
->getByIndex(0) >>= xDI
;
346 CPPUNIT_ASSERT(xDI
.is());
347 uno::Reference
< drawing::XControlShape
> xDS(xDI
, UNO_QUERY
);
348 CPPUNIT_ASSERT(xDS
.is());
349 CPPUNIT_ASSERT(xDS
->getControl() == xDateControlModel
);
351 uno::Reference
< uno::XInterface
> xTI
;
352 xShapesIC
->getByIndex(1) >>= xTI
;
353 CPPUNIT_ASSERT(xTI
.is());
354 uno::Reference
< drawing::XControlShape
> xTS(xTI
, UNO_QUERY
);
355 CPPUNIT_ASSERT(xTS
.is());
356 CPPUNIT_ASSERT(xTS
->getControl() == xTimeControlModel
);
361 void SwMacrosTest::testFdo55289()
363 SwDoc
*const pDoc
= new SwDoc
;
364 SwDocShellRef pDocShell
= new SwDocShell(pDoc
, SfxObjectCreateMode::EMBEDDED
);
365 // this needs to run with no layout to tickle the bugs in the special
366 // cases in SwXShape re-anchoring
367 assert(!pDoc
->getIDocumentLayoutAccess().GetCurrentLayout());
369 uno::Reference
<frame::XModel
> const xModel(pDocShell
->GetModel());
370 uno::Reference
<drawing::XDrawPageSupplier
> const xDPS(xModel
, UNO_QUERY
);
371 uno::Reference
<drawing::XShapes
> const xShapes(xDPS
->getDrawPage(),
373 uno::Reference
<beans::XPropertySet
> const xShape(
374 uno::Reference
<lang::XMultiServiceFactory
>(xModel
, UNO_QUERY
)->
375 createInstance("com.sun.star.drawing.GraphicObjectShape"),
377 xShape
->setPropertyValue("AnchorType",
378 makeAny(text::TextContentAnchorType_AT_PAGE
));
379 xShapes
->add(uno::Reference
<drawing::XShape
>(xShape
, UNO_QUERY
));
380 xShape
->setPropertyValue("AnchorType",
381 makeAny(text::TextContentAnchorType_AT_CHARACTER
));
382 xShape
->setPropertyValue("AnchorType",
383 makeAny(text::TextContentAnchorType_AS_CHARACTER
));
384 xShape
->setPropertyValue("AnchorType",
385 makeAny(text::TextContentAnchorType_AT_CHARACTER
));
386 xShape
->setPropertyValue("AnchorType",
387 makeAny(text::TextContentAnchorType_AS_CHARACTER
));
388 uno::Reference
<text::XTextRange
> const xEnd
=
389 uno::Reference
<text::XTextDocument
>(xModel
, UNO_QUERY
)->getText()->getEnd();
390 uno::Reference
<text::XTextContent
> const xShapeContent(xShape
, UNO_QUERY
);
391 xShapeContent
->attach(xEnd
);
394 void SwMacrosTest::testFdo68983()
397 createFileURL("fdo68983.", "odt", aFileName
);
398 Reference
< com::sun::star::lang::XComponent
> xComponent
=
399 loadFromDesktop(aFileName
, "com.sun.star.text.TextDocument");
401 CPPUNIT_ASSERT_MESSAGE("Failed to load fdo68983.odt", xComponent
.is());
403 Reference
< frame::XStorable
> xDocStorable(xComponent
, UNO_QUERY_THROW
);
404 CPPUNIT_ASSERT(xDocStorable
.is());
406 utl::TempFile aTempFile
;
407 aTempFile
.EnableKillingFile();
408 Sequence
<beans::PropertyValue
> desc(1);
409 desc
[0].Name
= "FilterName";
410 desc
[0].Value
<<= OUString("writer8");
411 xDocStorable
->storeAsURL(aTempFile
.GetURL(), desc
);
413 Reference
<util::XCloseable
>(xComponent
, UNO_QUERY_THROW
)->close(false);
416 xComponent
= loadFromDesktop(aTempFile
.GetURL(), "com.sun.star.text.TextDocument");
418 // check that password-protected library survived store and re-load
419 Reference
<document::XEmbeddedScripts
> xDocScr(xComponent
, UNO_QUERY_THROW
);
420 Reference
<script::XStorageBasedLibraryContainer
> xStorBasLib(xDocScr
->getBasicLibraries());
421 Reference
<script::XLibraryContainer
> xBasLib(xStorBasLib
, UNO_QUERY_THROW
);
422 Reference
<script::XLibraryContainerPassword
> xBasLibPwd(xStorBasLib
, UNO_QUERY_THROW
);
423 CPPUNIT_ASSERT(xBasLibPwd
->isLibraryPasswordProtected("Library1"));
424 CPPUNIT_ASSERT(xBasLibPwd
->verifyLibraryPassword("Library1", "foo"));
425 xBasLib
->loadLibrary("Library1");
426 CPPUNIT_ASSERT(xBasLib
->isLibraryLoaded("Library1"));
429 Reference
<util::XCloseable
> xDocCloseable(xComponent
, UNO_QUERY_THROW
);
430 xDocCloseable
->close(false);
433 void SwMacrosTest::testFindReplace()
435 // we need a full document with view and layout etc. because ::GetNode()
436 Reference
<lang::XComponent
> const xComponent
=
437 loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
438 SwXTextDocument
*const pTextDoc
= dynamic_cast<SwXTextDocument
*>(xComponent
.get());
439 CPPUNIT_ASSERT(pTextDoc
);
440 SwDoc
*const pDoc
= pTextDoc
->GetDocShell()->GetDoc();
441 SwNodeIndex
aIdx(pDoc
->GetNodes().GetEndOfContent(), -1);
442 // use a UnoCrsr so it will be corrected when deleting nodes
443 SwUnoCrsr
*const pPaM(pDoc
->CreateUnoCrsr(SwPosition(aIdx
), false));
445 IDocumentContentOperations
& rIDCO(pDoc
->getIDocumentContentOperations());
446 rIDCO
.InsertString(*pPaM
, OUString("foo"));
447 rIDCO
.AppendTextNode(*pPaM
->GetPoint());
448 rIDCO
.InsertString(*pPaM
, OUString("bar"));
449 rIDCO
.AppendTextNode(*pPaM
->GetPoint());
450 rIDCO
.InsertString(*pPaM
, OUString("baz"));
451 pPaM
->Move(fnMoveBackward
, fnGoDoc
);
454 util::SearchOptions
opts(
455 util::SearchAlgorithms_REGEXP
,
459 lang::Locale("en", "US", ""),
465 // find newline on 1st paragraph
466 bool bFound
= pPaM
->Find(
467 opts
, false, DOCPOS_CURR
, DOCPOS_END
, bCancel
, FND_IN_BODY
, false);
468 CPPUNIT_ASSERT(bFound
);
469 CPPUNIT_ASSERT(pPaM
->HasMark());
470 CPPUNIT_ASSERT_EQUAL(OUString(""), pPaM
->GetText());
472 // now do another Find, inside the selection from the first Find
473 // opts.searchFlags = 71680;
475 opts
, false, DOCPOS_CURR
, DOCPOS_END
, bCancel
, FND_IN_SEL
, false);
476 CPPUNIT_ASSERT(bFound
);
477 CPPUNIT_ASSERT(pPaM
->HasMark());
478 CPPUNIT_ASSERT_EQUAL(OUString(""), pPaM
->GetText());
480 rIDCO
.ReplaceRange(*pPaM
, " ", true);
483 pPaM
->Move(fnMoveBackward
, fnGoDoc
);
485 // problem was that after the 2nd Find, the wrong newline was selected
486 CPPUNIT_ASSERT_EQUAL(OUString("foo bar"),
487 pPaM
->Start()->nNode
.GetNode().GetTextNode()->GetText());
488 pPaM
->Move(fnMoveForward
, fnGoNode
);
489 CPPUNIT_ASSERT_EQUAL(OUString("baz"),
490 pPaM
->End()->nNode
.GetNode().GetTextNode()->GetText());
493 SwMacrosTest::SwMacrosTest()
494 : m_aBaseString("/sw/qa/core/data")
498 void SwMacrosTest::setUp()
500 test::BootstrapFixture::setUp();
502 // This is a bit of a fudge, we do this to ensure that SwGlobals::ensure,
503 // which is a private symbol to us, gets called
505 getMultiServiceFactory()->createInstance(OUString(
506 "com.sun.star.comp.Writer.TextDocument"));
507 CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xWriterComponent
.is());
508 mxDesktop
= com::sun::star::frame::Desktop::create( comphelper::getComponentContext(getMultiServiceFactory()) );
511 void SwMacrosTest::tearDown()
513 uno::Reference
< lang::XComponent
>( m_xWriterComponent
, UNO_QUERY_THROW
)->dispose();
514 test::BootstrapFixture::tearDown();
517 CPPUNIT_TEST_SUITE_REGISTRATION(SwMacrosTest
);
519 CPPUNIT_PLUGIN_IMPLEMENT();
521 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */