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 <swmodeltestbase.hxx>
12 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
13 #include <com/sun/star/document/XFilter.hpp>
14 #include <com/sun/star/document/XImporter.hpp>
15 #include <com/sun/star/text/XPageCursor.hpp>
16 #include <com/sun/star/view/XSelectionSupplier.hpp>
17 #include <com/sun/star/text/XTextTable.hpp>
18 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
20 #include <comphelper/propertyvalue.hxx>
21 #include <sfx2/docfile.hxx>
22 #include <rtl/ustrbuf.hxx>
23 #include <unotools/streamwrap.hxx>
24 #include <unotools/ucbstreamhelper.hxx>
25 #include <vcl/scheduler.hxx>
26 #include <comphelper/configuration.hxx>
27 #include <officecfg/Office/Writer.hxx>
29 #include <IDocumentLayoutAccess.hxx>
31 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
32 #include <rootfrm.hxx>
33 #include <unotxdoc.hxx>
39 void SwModelTestBase::paste(std::u16string_view aFilename
, OUString aInstance
,
40 uno::Reference
<text::XTextRange
> const& xTextRange
)
42 uno::Reference
<document::XFilter
> xFilter(m_xSFactory
->createInstance(aInstance
),
43 uno::UNO_QUERY_THROW
);
44 uno::Reference
<document::XImporter
> xImporter(xFilter
, uno::UNO_QUERY_THROW
);
45 xImporter
->setTargetDocument(mxComponent
);
46 std::unique_ptr
<SvStream
> pStream
= utl::UcbStreamHelper::CreateStream(
47 m_directories
.getURLFromSrc(u
"/sw/qa/extras/") + aFilename
, StreamMode::STD_READ
);
48 CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE
, pStream
->GetError());
49 uno::Reference
<io::XStream
> xStream(new utl::OStreamWrapper(std::move(pStream
)));
50 uno::Sequence aDescriptor
{ comphelper::makePropertyValue("InputStream", xStream
),
51 comphelper::makePropertyValue("InsertMode", true),
52 comphelper::makePropertyValue("TextInsertModeRange", xTextRange
) };
53 CPPUNIT_ASSERT(xFilter
->filter(aDescriptor
));
56 SwModelTestBase::SwModelTestBase(const OUString
& pTestDocumentPath
, const OUString
& pFilter
)
57 : UnoApiXmlTest(pTestDocumentPath
)
59 , mpXmlBuffer(nullptr)
65 void SwModelTestBase::executeImportTest(const char* filename
, const char* pPassword
)
67 maTempFile
.EnableKillingFile(false);
69 std::unique_ptr
<Resetter
> const pChanges(preTest(filename
));
70 loadURL(createFileURL(OUString::createFromAscii(filename
)), pPassword
);
73 maTempFile
.EnableKillingFile();
76 void SwModelTestBase::executeLoadVerifyReloadVerify(const char* filename
, const char* pPassword
)
78 maTempFile
.EnableKillingFile(false);
80 std::unique_ptr
<Resetter
> const pChanges(preTest(filename
));
81 loadURL(createFileURL(OUString::createFromAscii(filename
)), pPassword
);
84 saveAndReload(mpFilter
, pPassword
);
87 maTempFile
.EnableKillingFile();
90 void SwModelTestBase::executeLoadReloadVerify(const char* filename
, const char* pPassword
)
92 maTempFile
.EnableKillingFile(false);
94 std::unique_ptr
<Resetter
> const pChanges(preTest(filename
));
95 loadURL(createFileURL(OUString::createFromAscii(filename
)), pPassword
);
97 saveAndReload(mpFilter
, pPassword
);
100 maTempFile
.EnableKillingFile();
103 void SwModelTestBase::executeImportExport(const char* filename
, const char* pPassword
)
105 maTempFile
.EnableKillingFile(false);
107 std::unique_ptr
<Resetter
> const pChanges(preTest(filename
));
108 loadAndSave(filename
, pPassword
);
109 maTempFile
.EnableKillingFile(false);
112 maTempFile
.EnableKillingFile();
115 void SwModelTestBase::dumpLayout(const uno::Reference
<lang::XComponent
>& rComponent
)
117 // create the xml writer
118 mpXmlBuffer
= xmlBufferCreate();
119 xmlTextWriterPtr pXmlWriter
= xmlNewTextWriterMemory(mpXmlBuffer
, 0);
120 (void)xmlTextWriterStartDocument(pXmlWriter
, nullptr, nullptr, nullptr);
123 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(rComponent
.get());
124 CPPUNIT_ASSERT(pTextDoc
);
125 SwDoc
* pDoc
= pTextDoc
->GetDocShell()->GetDoc();
126 SwRootFrame
* pLayout
= pDoc
->getIDocumentLayoutAccess().GetCurrentLayout();
127 pLayout
->dumpAsXml(pXmlWriter
);
130 (void)xmlTextWriterEndDocument(pXmlWriter
);
131 xmlFreeTextWriter(pXmlWriter
);
134 void SwModelTestBase::discardDumpedLayout()
138 xmlBufferFree(mpXmlBuffer
);
139 mpXmlBuffer
= nullptr;
143 void SwModelTestBase::calcLayout()
145 getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell()->CalcLayout();
148 int SwModelTestBase::getLength() const { return getBodyText().getLength(); }
150 OUString
SwModelTestBase::getBodyText() const
152 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
153 uno::Reference
<container::XEnumerationAccess
> xParaEnumAccess(xTextDocument
->getText(),
155 uno::Reference
<container::XEnumeration
> xParaEnum
= xParaEnumAccess
->createEnumeration();
157 while (xParaEnum
->hasMoreElements())
159 uno::Reference
<container::XEnumerationAccess
> xRangeEnumAccess(xParaEnum
->nextElement(),
161 uno::Reference
<container::XEnumeration
> xRangeEnum
= xRangeEnumAccess
->createEnumeration();
162 while (xRangeEnum
->hasMoreElements())
164 uno::Reference
<text::XTextRange
> xRange(xRangeEnum
->nextElement(), uno::UNO_QUERY
);
165 aBuf
.append(xRange
->getString());
168 return aBuf
.makeStringAndClear();
171 uno::Reference
<container::XNameAccess
> SwModelTestBase::getStyles(const OUString
& aFamily
)
173 uno::Reference
<style::XStyleFamiliesSupplier
> xStyleFamiliesSupplier(mxComponent
,
175 uno::Reference
<container::XNameAccess
> xStyleFamilies
176 = xStyleFamiliesSupplier
->getStyleFamilies();
177 uno::Reference
<container::XNameAccess
> xStyleFamily(xStyleFamilies
->getByName(aFamily
),
182 uno::Reference
<style::XAutoStyleFamily
> SwModelTestBase::getAutoStyles(const OUString
& aFamily
)
184 uno::Reference
<style::XAutoStylesSupplier
> xAutoStylesSupplier(mxComponent
, uno::UNO_QUERY
);
185 uno::Reference
<style::XAutoStyles
> xAutoStyles(xAutoStylesSupplier
->getAutoStyles());
186 uno::Reference
<style::XAutoStyleFamily
> xAutoStyleFamily(xAutoStyles
->getByName(aFamily
),
188 return xAutoStyleFamily
;
191 xmlDocUniquePtr
SwModelTestBase::parseLayoutDump()
194 dumpLayout(mxComponent
);
196 auto pBuffer
= reinterpret_cast<const char*>(xmlBufferContent(mpXmlBuffer
));
197 SAL_INFO("sw.qa", "SwModelTestBase::parseLayoutDump: pBuffer is '" << pBuffer
<< "'");
198 return xmlDocUniquePtr(xmlParseMemory(pBuffer
, xmlBufferLength(mpXmlBuffer
)));
201 OUString
SwModelTestBase::parseDump(const OString
& aXPath
, const OString
& aAttribute
)
203 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
205 xmlXPathContextPtr pXmlXpathCtx
= xmlXPathNewContext(pXmlDoc
.get());
206 xmlXPathObjectPtr pXmlXpathObj
207 = xmlXPathEvalExpression(BAD_CAST(aXPath
.getStr()), pXmlXpathCtx
);
208 CPPUNIT_ASSERT_MESSAGE("xpath evaluation failed", pXmlXpathObj
);
209 xmlChar
* pXpathStrResult
;
210 if (pXmlXpathObj
->type
== XPATH_NODESET
)
212 xmlNodeSetPtr pXmlNodes
= pXmlXpathObj
->nodesetval
;
213 CPPUNIT_ASSERT_EQUAL_MESSAGE("xpath should match exactly 1 node", 1,
214 xmlXPathNodeSetGetLength(pXmlNodes
));
215 xmlNodePtr pXmlNode
= pXmlNodes
->nodeTab
[0];
216 if (aAttribute
.getLength())
217 pXpathStrResult
= xmlGetProp(pXmlNode
, BAD_CAST(aAttribute
.getStr()));
219 pXpathStrResult
= xmlNodeGetContent(pXmlNode
);
223 // the xpath expression evaluated to a value, not a node
224 CPPUNIT_ASSERT_EQUAL_MESSAGE("attr name should not be supplied when xpath evals to a value",
225 sal_Int32(0), aAttribute
.getLength());
226 pXpathStrResult
= xmlXPathCastToString(pXmlXpathObj
);
227 CPPUNIT_ASSERT_MESSAGE("xpath result cannot be cast to string", pXpathStrResult
);
230 OUString
aRet(reinterpret_cast<char*>(pXpathStrResult
), xmlStrlen(pXpathStrResult
),
231 RTL_TEXTENCODING_UTF8
);
232 xmlFree(pXpathStrResult
);
233 xmlFree(pXmlXpathObj
);
234 xmlFree(pXmlXpathCtx
);
239 bool SwModelTestBase::hasProperty(const uno::Reference
<uno::XInterface
>& obj
,
240 const OUString
& name
) const
242 uno::Reference
<beans::XPropertySet
> properties(obj
, uno::UNO_QUERY_THROW
);
243 return properties
->getPropertySetInfo()->hasPropertyByName(name
);
246 xml::AttributeData
SwModelTestBase::getUserDefineAttribute(const uno::Any
& obj
,
247 const OUString
& name
,
248 const OUString
& rValue
) const
250 uno::Reference
<container::XNameContainer
> attrsCnt(
251 getProperty
<uno::Any
>(obj
, "UserDefinedAttributes"), uno::UNO_QUERY_THROW
);
253 xml::AttributeData aValue
;
254 attrsCnt
->getByName(name
) >>= aValue
;
255 if (!rValue
.isEmpty())
256 CPPUNIT_ASSERT_EQUAL_MESSAGE("attribute of cell does not contain expected value", rValue
,
262 int SwModelTestBase::getParagraphs(uno::Reference
<text::XText
> const& xText
)
268 uno::Reference
<container::XEnumerationAccess
> xParaEnumAccess(xText
->getText(), uno::UNO_QUERY
);
269 uno::Reference
<container::XEnumeration
> xParaEnum
= xParaEnumAccess
->createEnumeration();
270 while (xParaEnum
->hasMoreElements())
272 xParaEnum
->nextElement();
278 int SwModelTestBase::getParagraphs()
280 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
281 return getParagraphs(xTextDocument
->getText());
284 uno::Reference
<text::XTextContent
>
285 SwModelTestBase::getParagraphOrTable(int number
, uno::Reference
<text::XText
> const& xText
) const
287 assert(number
!= 0); // this thing is 1-based
288 uno::Reference
<container::XEnumerationAccess
> paraEnumAccess
;
290 paraEnumAccess
.set(xText
, uno::UNO_QUERY
);
293 uno::Reference
<text::XTextDocument
> textDocument(mxComponent
, uno::UNO_QUERY
);
294 paraEnumAccess
.set(textDocument
->getText(), uno::UNO_QUERY
);
296 uno::Reference
<container::XEnumeration
> paraEnum
= paraEnumAccess
->createEnumeration();
297 for (int i
= 1; i
< number
; ++i
)
298 paraEnum
->nextElement();
299 uno::Reference
<text::XTextContent
> const xElem(paraEnum
->nextElement(), uno::UNO_QUERY_THROW
);
303 uno::Reference
<text::XTextRange
> SwModelTestBase::getParagraph(int number
,
304 const OUString
& content
) const
306 uno::Reference
<text::XTextRange
> const xParagraph(getParagraphOrTable(number
),
307 uno::UNO_QUERY_THROW
);
308 if (!content
.isEmpty())
309 CPPUNIT_ASSERT_EQUAL_MESSAGE("paragraph does not have expected content", content
,
310 xParagraph
->getString());
314 sal_Int16
SwModelTestBase::getNumberingTypeOfParagraph(int nPara
)
316 sal_Int16 nNumberingType
= -1;
317 uno::Reference
<text::XTextRange
> xPara(getParagraph(nPara
));
318 uno::Reference
<beans::XPropertySet
> properties(xPara
, uno::UNO_QUERY
);
319 bool isNumber
= false;
320 properties
->getPropertyValue("NumberingIsNumber") >>= isNumber
;
323 uno::Reference
<container::XIndexAccess
> xLevels(
324 properties
->getPropertyValue("NumberingRules"), uno::UNO_QUERY
);
325 sal_Int16 nNumberingLevel
= -1;
326 properties
->getPropertyValue("NumberingLevel") >>= nNumberingLevel
;
327 if (nNumberingLevel
>= 0 && nNumberingLevel
< xLevels
->getCount())
329 uno::Sequence
<beans::PropertyValue
> aPropertyValue
;
330 xLevels
->getByIndex(nNumberingLevel
) >>= aPropertyValue
;
331 auto pProp
= std::find_if(
332 std::cbegin(aPropertyValue
), std::cend(aPropertyValue
),
333 [](const beans::PropertyValue
& rProp
) { return rProp
.Name
== "NumberingType"; });
334 if (pProp
!= std::cend(aPropertyValue
))
335 nNumberingType
= pProp
->Value
.get
<sal_Int16
>();
338 return nNumberingType
;
341 uno::Reference
<text::XTextRange
>
342 SwModelTestBase::getParagraphOfText(int number
, uno::Reference
<text::XText
> const& xText
,
343 const OUString
& content
) const
345 uno::Reference
<text::XTextRange
> const xParagraph(getParagraphOrTable(number
, xText
),
346 uno::UNO_QUERY_THROW
);
347 if (!content
.isEmpty())
348 CPPUNIT_ASSERT_EQUAL_MESSAGE("paragraph does not contain expected content", content
,
349 xParagraph
->getString());
353 uno::Reference
<beans::XPropertySet
>
354 SwModelTestBase::getParagraphAnchoredObject(int const index
,
355 uno::Reference
<text::XTextRange
> const& xPara
) const
357 uno::Reference
<container::XContentEnumerationAccess
> xContentEnumAccess(xPara
, uno::UNO_QUERY
);
358 uno::Reference
<container::XEnumeration
> xContentEnum
359 = xContentEnumAccess
->createContentEnumeration("com.sun.star.text.TextContent");
360 for (int i
= 1; i
< index
; ++i
)
362 xContentEnum
->nextElement();
364 return uno::Reference
<beans::XPropertySet
>(xContentEnum
->nextElement(), uno::UNO_QUERY
);
367 uno::Reference
<text::XTextRange
>
368 SwModelTestBase::getRun(uno::Reference
<text::XTextRange
> const& xParagraph
, int number
,
369 const OUString
& content
) const
371 uno::Reference
<container::XEnumerationAccess
> xRunEnumAccess(xParagraph
, uno::UNO_QUERY
);
372 uno::Reference
<container::XEnumeration
> xRunEnum
= xRunEnumAccess
->createEnumeration();
373 for (int i
= 1; i
< number
; ++i
)
374 xRunEnum
->nextElement();
375 uno::Reference
<text::XTextRange
> xRun(xRunEnum
->nextElement(), uno::UNO_QUERY
);
376 if (!content
.isEmpty())
377 CPPUNIT_ASSERT_EQUAL_MESSAGE("run does not contain expected content", content
,
382 OUString
SwModelTestBase::getFormula(uno::Reference
<text::XTextRange
> const& xRun
) const
384 uno::Reference
<container::XContentEnumerationAccess
> xContentEnumAccess(xRun
, uno::UNO_QUERY
);
385 uno::Reference
<container::XEnumeration
> xContentEnum
386 = xContentEnumAccess
->createContentEnumeration("");
387 uno::Reference
<beans::XPropertySet
> xFormula(xContentEnum
->nextElement(), uno::UNO_QUERY
);
388 return getProperty
<OUString
>(
389 getProperty
<uno::Reference
<beans::XPropertySet
>>(xFormula
, "Model"), "Formula");
392 uno::Reference
<table::XCell
>
393 SwModelTestBase::getCell(uno::Reference
<uno::XInterface
> const& xTableIfc
, OUString
const& rCell
,
394 OUString
const& rContent
)
396 uno::Reference
<text::XTextTable
> const xTable(xTableIfc
, uno::UNO_QUERY_THROW
);
397 uno::Reference
<table::XCell
> const xCell(xTable
->getCellByName(rCell
), uno::UNO_SET_THROW
);
398 if (!rContent
.isEmpty())
400 uno::Reference
<text::XText
> const xCellText(xCell
, uno::UNO_QUERY_THROW
);
401 CPPUNIT_ASSERT_EQUAL_MESSAGE("cell does not contain expected content", rContent
,
402 xCellText
->getString());
407 uno::Reference
<drawing::XShape
> SwModelTestBase::getShape(int number
)
409 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(mxComponent
, uno::UNO_QUERY
);
410 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
411 uno::Reference
<drawing::XShape
> xShape(xDrawPage
->getByIndex(number
- 1), uno::UNO_QUERY
);
415 void SwModelTestBase::selectShape(int number
)
417 SwXTextDocument
* pXTextDocument
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
418 uno::Reference
<view::XSelectionSupplier
> xSelectionSupplier(
419 pXTextDocument
->getCurrentController(), uno::UNO_QUERY
);
420 xSelectionSupplier
->select(uno::Any(getShape(number
)));
421 CPPUNIT_ASSERT(xSelectionSupplier
->getSelection().hasValue());
423 SwDoc
* pDoc
= pXTextDocument
->GetDocShell()->GetDoc();
424 SwView
* pView
= pDoc
->GetDocShell()->GetView();
425 // Make sure SwTextShell is replaced with SwDrawShell right now, not after 120 ms, as set in the
427 pView
->StopShellTimer();
430 uno::Reference
<drawing::XShape
> SwModelTestBase::getShapeByName(std::u16string_view aName
)
432 uno::Reference
<drawing::XShape
> xRet
;
434 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(mxComponent
, uno::UNO_QUERY
);
435 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
436 for (sal_Int32 i
= 0; i
< xDrawPage
->getCount(); ++i
)
438 uno::Reference
<container::XNamed
> xShape(xDrawPage
->getByIndex(i
), uno::UNO_QUERY
);
439 if (xShape
->getName() == aName
)
441 xRet
.set(xShape
, uno::UNO_QUERY
);
449 uno::Reference
<drawing::XShape
> SwModelTestBase::getTextFrameByName(const OUString
& aName
)
451 uno::Reference
<text::XTextFramesSupplier
> xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
452 uno::Reference
<container::XNameAccess
> xNameAccess
= xTextFramesSupplier
->getTextFrames();
453 uno::Reference
<drawing::XShape
> xShape(xNameAccess
->getByName(aName
), uno::UNO_QUERY
);
457 void SwModelTestBase::header() {}
459 void SwModelTestBase::loadURL(OUString
const& rURL
, const char* pPassword
)
461 // Output name at load time, so in the case of a hang, the name of the hanging input file is visible.
464 std::cout
<< rURL
<< ":\n";
465 mnStartTime
= osl_getGlobalTimer();
468 UnoApiXmlTest::load(rURL
, pPassword
);
470 CPPUNIT_ASSERT(!getSwDocShell()->GetMedium()->GetWarningError());
472 discardDumpedLayout();
476 void SwModelTestBase::saveAndReload(const OUString
& pFilter
, const char* pPassword
)
478 save(pFilter
, pPassword
);
481 loadURL(maTempFile
.GetURL(), pPassword
);
484 void SwModelTestBase::loadAndSave(const char* pName
, const char* pPassword
)
486 loadURL(createFileURL(OUString::createFromAscii(pName
)), pPassword
);
491 void SwModelTestBase::loadAndReload(const char* pName
)
493 loadURL(createFileURL(OUString::createFromAscii(pName
)));
494 saveAndReload(mpFilter
);
497 void SwModelTestBase::finish()
499 sal_uInt32 nEndTime
= osl_getGlobalTimer();
500 std::cout
<< (nEndTime
- mnStartTime
) << std::endl
;
501 discardDumpedLayout();
504 int SwModelTestBase::getPages() const
506 uno::Reference
<frame::XModel
> xModel(mxComponent
, uno::UNO_QUERY
);
507 uno::Reference
<text::XTextViewCursorSupplier
> xTextViewCursorSupplier(
508 xModel
->getCurrentController(), uno::UNO_QUERY
);
509 uno::Reference
<text::XPageCursor
> xCursor(xTextViewCursorSupplier
->getViewCursor(),
511 xCursor
->jumpToLastPage();
512 return xCursor
->getPage();
515 int SwModelTestBase::getShapes() const
517 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(mxComponent
, uno::UNO_QUERY
);
518 uno::Reference
<container::XIndexAccess
> xDraws
= xDrawPageSupplier
->getDrawPage();
519 return xDraws
->getCount();
522 xmlDocUniquePtr
SwModelTestBase::parseExportedFile()
524 auto stream(SvFileStream(maTempFile
.GetURL(), StreamMode::READ
| StreamMode::TEMPORARY
));
525 return parseXmlStream(&stream
);
528 void SwModelTestBase::createSwDoc(const char* pName
, const char* pPassword
)
531 loadURL("private:factory/swriter");
533 loadURL(createFileURL(OUString::createFromAscii(pName
)), pPassword
);
535 uno::Reference
<lang::XServiceInfo
> xServiceInfo(mxComponent
, uno::UNO_QUERY_THROW
);
536 CPPUNIT_ASSERT(xServiceInfo
->supportsService("com.sun.star.text.TextDocument"));
539 void SwModelTestBase::createSwWebDoc(const char* pName
)
542 loadURL("private:factory/swriter/web");
544 loadURL(createFileURL(OUString::createFromAscii(pName
)));
546 uno::Reference
<lang::XServiceInfo
> xServiceInfo(mxComponent
, uno::UNO_QUERY_THROW
);
547 CPPUNIT_ASSERT(xServiceInfo
->supportsService("com.sun.star.text.WebDocument"));
550 void SwModelTestBase::createSwGlobalDoc(const char* pName
)
553 loadURL("private:factory/swriter/GlobalDocument");
555 loadURL(createFileURL(OUString::createFromAscii(pName
)));
557 uno::Reference
<lang::XServiceInfo
> xServiceInfo(mxComponent
, uno::UNO_QUERY_THROW
);
558 CPPUNIT_ASSERT(xServiceInfo
->supportsService("com.sun.star.text.GlobalDocument"));
561 SwDoc
* SwModelTestBase::getSwDoc() { return getSwDocShell()->GetDoc(); }
563 SwDocShell
* SwModelTestBase::getSwDocShell()
565 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
566 CPPUNIT_ASSERT(pTextDoc
);
568 return pTextDoc
->GetDocShell();
571 xmlDocUniquePtr
SwModelTestBase::WrapReqifFromTempFile()
573 SvMemoryStream aStream
;
574 aStream
.WriteOString("<reqif-xhtml:html xmlns:reqif-xhtml=\"http://www.w3.org/1999/xhtml\">\n");
575 SvFileStream
aFileStream(maTempFile
.GetURL(), StreamMode::READ
);
576 aStream
.WriteStream(aFileStream
);
577 aStream
.WriteOString("</reqif-xhtml:html>\n");
579 xmlDocUniquePtr pXmlDoc
= parseXmlStream(&aStream
);
580 // Make sure the output is well-formed.
581 CPPUNIT_ASSERT(pXmlDoc
);
585 void SwModelTestBase::WrapFromTempFile(SvMemoryStream
& rStream
)
587 SvFileStream
aFileStream(maTempFile
.GetURL(), StreamMode::READ
);
588 rStream
.WriteStream(aFileStream
);
592 void SwModelTestBase::emulateTyping(SwXTextDocument
& rTextDoc
, const std::u16string_view
& rStr
)
594 for (const char16_t c
: rStr
)
596 rTextDoc
.postKeyEvent(LOK_KEYEVENT_KEYINPUT
, c
, 0);
597 rTextDoc
.postKeyEvent(LOK_KEYEVENT_KEYUP
, c
, 0);
598 Scheduler::ProcessEventsToIdle();
602 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */