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>
11 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
12 #include <vcl/scheduler.hxx>
13 #include <com/sun/star/table/TableBorder2.hpp>
14 #include <com/sun/star/text/XDocumentIndex.hpp>
15 #include <com/sun/star/text/XTextFrame.hpp>
16 #include <com/sun/star/text/XTextTable.hpp>
17 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
18 #include <com/sun/star/text/XPageCursor.hpp>
19 #include <comphelper/propertysequence.hxx>
20 #include <swdtflvr.hxx>
21 #include <o3tl/string_view.hxx>
25 #include <unotxdoc.hxx>
28 #include <IDocumentFieldsAccess.hxx>
29 #include <IDocumentRedlineAccess.hxx>
30 #include <fmtinfmt.hxx>
32 /// Third set of tests asserting the behavior of Writer user interface shells.
33 class SwUiWriterTest3
: public SwModelTestBase
37 : SwModelTestBase("/sw/qa/extras/uiwriter/data/")
42 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf151974
)
44 createSwDoc("tdf151974.odt");
46 CPPUNIT_ASSERT_EQUAL(int(8), getParagraphs());
48 auto pLayout
= parseLayoutDump();
49 for (size_t i
= 1; i
< 9; ++i
)
51 OString
sPath("/root/page[1]/body/txt[" + OString::number(i
)
52 + "]/SwParaPortion/SwLineLayout");
53 assertXPathChildren(pLayout
, sPath
, 1);
56 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
57 dispatchCommand(mxComponent
, ".uno:Copy", {});
58 dispatchCommand(mxComponent
, ".uno:GoDown", {});
60 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
61 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
62 Scheduler::ProcessEventsToIdle();
64 // Paste special as RTF
65 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
66 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
68 dispatchCommand(mxComponent
, ".uno:ClipboardFormatItems", aPropertyValues
);
70 CPPUNIT_ASSERT_EQUAL(int(16), getParagraphs());
72 dumpLayout(mxComponent
);
73 pLayout
= parseLayoutDump();
74 for (size_t i
= 1; i
< 16; ++i
)
76 OString
sPath("/root/page[1]/body/txt[" + OString::number(i
)
77 + "]/SwParaPortion/SwLineLayout");
79 // Without the fix in place, this test would have failed with
82 // - In <>, XPath '/root/page[1]/body/txt[1]/SwParaPortion/SwLineLayout' number of child-nodes is incorrect
83 assertXPathChildren(pLayout
, sPath
, 1);
87 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf145731
)
89 createSwDoc("tdf145731.odt");
91 CPPUNIT_ASSERT_EQUAL(9, getShapes());
92 CPPUNIT_ASSERT_EQUAL(1, getPages());
94 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
96 dispatchCommand(mxComponent
, ".uno:Cut", {});
98 CPPUNIT_ASSERT_EQUAL(0, getShapes());
99 CPPUNIT_ASSERT_EQUAL(1, getPages());
101 // Without the fix in place, this test would have crashed here
102 dispatchCommand(mxComponent
, ".uno:Paste", {});
104 CPPUNIT_ASSERT_EQUAL(9, getShapes());
105 CPPUNIT_ASSERT_EQUAL(1, getPages());
108 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf147199
)
110 createSwDoc("tdf147199.docx");
112 CPPUNIT_ASSERT_EQUAL(7, getShapes());
114 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
116 dispatchCommand(mxComponent
, ".uno:Cut", {});
118 CPPUNIT_ASSERT_EQUAL(0, getShapes());
120 dispatchCommand(mxComponent
, ".uno:Paste", {});
122 CPPUNIT_ASSERT_EQUAL(7, getShapes());
124 dispatchCommand(mxComponent
, ".uno:Paste", {});
126 CPPUNIT_ASSERT_EQUAL(14, getShapes());
128 dispatchCommand(mxComponent
, ".uno:Undo", {});
130 CPPUNIT_ASSERT_EQUAL(7, getShapes());
132 // Without the fix in place, this test would have crashed here
133 dispatchCommand(mxComponent
, ".uno:Undo", {});
135 CPPUNIT_ASSERT_EQUAL(0, getShapes());
137 dispatchCommand(mxComponent
, ".uno:Undo", {});
139 CPPUNIT_ASSERT_EQUAL(7, getShapes());
142 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf139843
)
144 createSwDoc("tdf139843.odt");
146 int nPages
= getPages();
148 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
150 dispatchCommand(mxComponent
, ".uno:Cut", {});
152 CPPUNIT_ASSERT_EQUAL(1, getPages());
154 // Without the fix in place, this test would have crashed here
155 dispatchCommand(mxComponent
, ".uno:Paste", {});
157 CPPUNIT_ASSERT_EQUAL(nPages
, getPages());
160 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf143574
)
162 createSwDoc("tdf143574.odt");
163 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
165 CPPUNIT_ASSERT_EQUAL(1, getShapes());
166 uno::Reference
<drawing::XShapes
> xGroupShape(getShape(1), uno::UNO_QUERY
);
167 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xGroupShape
->getCount());
169 uno::Reference
<beans::XPropertySet
> xProperties(xGroupShape
->getByIndex(2), uno::UNO_QUERY
);
170 CPPUNIT_ASSERT_EQUAL(false, xProperties
->getPropertyValue("TextBox").get
<bool>());
173 dispatchCommand(mxComponent
, ".uno:EnterGroup", {});
175 // Select a shape in the group
176 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
177 Scheduler::ProcessEventsToIdle();
179 // Without the fix in place, this test would have crashed
180 dispatchCommand(mxComponent
, ".uno:AddTextBox", {});
182 CPPUNIT_ASSERT_EQUAL(true, xProperties
->getPropertyValue("TextBox").get
<bool>());
185 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf146848
)
187 // Reuse existing document
188 createSwDoc("tdf77014.odt");
190 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
192 dispatchCommand(mxComponent
, ".uno:Cut", {});
194 uno::Reference
<text::XTextFieldsSupplier
> xTextFieldsSupplier(mxComponent
, uno::UNO_QUERY
);
195 uno::Reference
<container::XEnumerationAccess
> xFieldsAccess(
196 xTextFieldsSupplier
->getTextFields());
197 uno::Reference
<container::XEnumeration
> xFields(xFieldsAccess
->createEnumeration());
198 CPPUNIT_ASSERT(!xFields
->hasMoreElements());
200 // Without the fix in place, this test would have crashed here
201 dispatchCommand(mxComponent
, ".uno:Paste", {});
203 xFields
= xFieldsAccess
->createEnumeration();
205 int nFieldsCount
= 0;
206 while (xFields
->hasMoreElements())
208 xFields
->nextElement();
211 CPPUNIT_ASSERT_EQUAL(4, nFieldsCount
);
214 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf149507
)
216 createSwDoc("tdf149507.docx");
218 CPPUNIT_ASSERT_EQUAL(1, getShapes());
219 CPPUNIT_ASSERT_EQUAL(1, getPages());
221 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
223 dispatchCommand(mxComponent
, ".uno:Cut", {});
225 CPPUNIT_ASSERT_EQUAL(0, getShapes());
226 CPPUNIT_ASSERT_EQUAL(1, getPages());
228 dispatchCommand(mxComponent
, ".uno:Paste", {});
230 CPPUNIT_ASSERT_EQUAL(1, getShapes());
231 CPPUNIT_ASSERT_EQUAL(1, getPages());
233 // Without the fix in place, this test would have crashed here
234 dispatchCommand(mxComponent
, ".uno:Undo", {});
236 CPPUNIT_ASSERT_EQUAL(0, getShapes());
237 CPPUNIT_ASSERT_EQUAL(1, getPages());
239 dispatchCommand(mxComponent
, ".uno:Undo", {});
241 CPPUNIT_ASSERT_EQUAL(1, getShapes());
242 CPPUNIT_ASSERT_EQUAL(1, getPages());
245 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf114973
)
247 createSwDoc("tdf114973.fodt");
249 SwDoc
* const pDoc
= getSwDoc();
250 SwWrtShell
* const pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
251 pWrtShell
->SttEndDoc(true);
253 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
255 // bug: cursor jumped into header
256 CPPUNIT_ASSERT(!pWrtShell
->IsInHeaderFooter());
258 dispatchCommand(mxComponent
, ".uno:Copy", {});
260 // check that hidden paragraphs at start and end are deleted
261 dispatchCommand(mxComponent
, ".uno:Delete", {});
263 CPPUNIT_ASSERT_EQUAL(int(1), getParagraphs());
264 CPPUNIT_ASSERT_EQUAL(OUString(), getParagraph(1)->getString());
266 // check that hidden paragraphs at start and end are copied
267 dispatchCommand(mxComponent
, ".uno:Paste", {});
269 CPPUNIT_ASSERT_EQUAL(int(3), getParagraphs());
270 CPPUNIT_ASSERT_EQUAL(OUString("hidden first paragraph"), getParagraph(1)->getString());
271 CPPUNIT_ASSERT_EQUAL(OUString("Press CTRL+A for dispatching .uno:SelectAll. You see that "
272 "nothing will be selected. The cursor jumps to the header"),
273 getParagraph(2)->getString());
274 CPPUNIT_ASSERT_EQUAL(OUString("hidden last paragraph"), getParagraph(3)->getString());
277 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf145321
)
279 createSwDoc("tdf145321.odt");
281 CPPUNIT_ASSERT_EQUAL(3, getShapes());
282 CPPUNIT_ASSERT_EQUAL(3, getPages());
284 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
286 dispatchCommand(mxComponent
, ".uno:Cut", {});
288 CPPUNIT_ASSERT_EQUAL(0, getShapes());
289 CPPUNIT_ASSERT_EQUAL(1, getPages());
291 // Without the fix in place, this test would have crashed here
292 dispatchCommand(mxComponent
, ".uno:Undo", {});
294 CPPUNIT_ASSERT_EQUAL(3, getShapes());
295 CPPUNIT_ASSERT_EQUAL(3, getPages());
298 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testVariableFieldTableRowSplitHeader
)
300 createSwDoc("variable-field-table-row-split-header.fodt");
301 SwDoc
* const pDoc
= getSwDoc();
304 Scheduler::ProcessEventsToIdle();
305 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
307 // the fields in cell are: variable-get variable-set variable-get
310 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
314 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
318 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
322 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
324 assertXPath(pXmlDoc
, "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
326 assertXPath(pXmlDoc
, "/root/page[1]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
328 // here the header had shown the wrong value
331 "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
335 "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
339 "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
341 assertXPath(pXmlDoc
, "/root/page[2]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
343 assertXPath(pXmlDoc
, "/root/page[2]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
348 "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
352 "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
356 "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
358 assertXPath(pXmlDoc
, "/root/page[3]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
360 assertXPath(pXmlDoc
, "/root/page[3]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
365 "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
369 "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
373 "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
375 assertXPath(pXmlDoc
, "/root/page[4]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
377 assertXPath(pXmlDoc
, "/root/page[4]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
380 assertXPath(pXmlDoc
, "/root/page[5]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
382 assertXPath(pXmlDoc
, "/root/page[5]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
385 discardDumpedLayout();
386 // update and check again
387 pDoc
->getIDocumentFieldsAccess().UpdateFields(true);
388 Scheduler::ProcessEventsToIdle();
389 pXmlDoc
= parseLayoutDump();
391 // the fields in cell are: variable-get variable-set variable-get
394 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
398 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
402 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
406 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
408 assertXPath(pXmlDoc
, "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
410 assertXPath(pXmlDoc
, "/root/page[1]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
412 // here the header had shown the wrong value
415 "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
419 "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
423 "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
425 assertXPath(pXmlDoc
, "/root/page[2]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
427 assertXPath(pXmlDoc
, "/root/page[2]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
432 "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
436 "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
440 "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
442 assertXPath(pXmlDoc
, "/root/page[3]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
444 assertXPath(pXmlDoc
, "/root/page[3]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
449 "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
453 "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
457 "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
459 assertXPath(pXmlDoc
, "/root/page[4]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
461 assertXPath(pXmlDoc
, "/root/page[4]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
464 assertXPath(pXmlDoc
, "/root/page[5]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
466 assertXPath(pXmlDoc
, "/root/page[5]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
470 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf147126
)
472 createSwDoc("tdf147126.docx");
473 CPPUNIT_ASSERT(mxComponent
);
474 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
475 CPPUNIT_ASSERT(pTextDoc
);
477 const auto pLayoutXML1
= parseLayoutDump();
479 for (auto nFly
= 1; nFly
< 8; ++nFly
)
481 const auto nFlyLeft
= getXPath(pLayoutXML1
,
482 "/root/page/body/txt[2]/anchored/fly["
483 + OString::number(nFly
) + "]/infos/bounds",
486 const auto nFlyRight
= getXPath(pLayoutXML1
,
487 "/root/page/body/txt[2]/anchored/fly["
488 + OString::number(nFly
) + "]/infos/bounds",
491 const auto nFlyTop
= getXPath(pLayoutXML1
,
492 "/root/page/body/txt[2]/anchored/fly[" + OString::number(nFly
)
496 const auto nFlyBottom
= getXPath(pLayoutXML1
,
497 "/root/page/body/txt[2]/anchored/fly["
498 + OString::number(nFly
) + "]/infos/bounds",
502 const auto sDrawRect
= getXPath(
504 "/root/page/body/txt[2]/anchored/SwAnchoredDrawObject/SdrObjGroup/SdrObjList/SdrObject["
505 + OString::number(nFly
) + "]",
508 const auto nComaPos1
= sDrawRect
.indexOf(',', 0);
509 const auto nComaPos2
= sDrawRect
.indexOf(',', nComaPos1
+ 1);
510 const auto nComaPos3
= sDrawRect
.indexOf(',', nComaPos2
+ 1);
512 const auto nDraw1
= o3tl::toInt64(sDrawRect
.subView(0, nComaPos1
));
513 const auto nDraw2
= o3tl::toInt64(sDrawRect
.subView(nComaPos1
+ 1, nComaPos2
- nComaPos1
));
514 const auto nDraw3
= o3tl::toInt64(sDrawRect
.subView(nComaPos2
+ 1, nComaPos3
- nComaPos2
));
515 const auto nDraw4
= o3tl::toInt64(
516 sDrawRect
.subView(nComaPos3
+ 1, sDrawRect
.getLength() - nComaPos3
- 1));
518 CPPUNIT_ASSERT_GREATER(nDraw1
, nFlyLeft
);
519 CPPUNIT_ASSERT_GREATER(nDraw2
, nFlyTop
);
520 CPPUNIT_ASSERT_LESS(nDraw3
, nFlyRight
);
521 CPPUNIT_ASSERT_LESS(nDraw4
, nFlyBottom
);
524 for (auto nLineBreakCount
= 0; nLineBreakCount
< 4; ++nLineBreakCount
)
526 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
527 Scheduler::ProcessEventsToIdle();
529 for (auto nSpaceCount
= 0; nSpaceCount
< 10; ++nSpaceCount
)
531 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_SPACE
);
532 Scheduler::ProcessEventsToIdle();
535 dumpLayout(mxComponent
);
536 const auto pLayoutXML2
= parseLayoutDump();
538 for (auto nFly
= 1; nFly
< 8; ++nFly
)
540 const auto nFlyLeft
= getXPath(pLayoutXML2
,
541 "/root/page/body/txt[6]/anchored/fly["
542 + OString::number(nFly
) + "]/infos/bounds",
545 const auto nFlyRight
= getXPath(pLayoutXML2
,
546 "/root/page/body/txt[6]/anchored/fly["
547 + OString::number(nFly
) + "]/infos/bounds",
550 const auto nFlyTop
= getXPath(pLayoutXML2
,
551 "/root/page/body/txt[6]/anchored/fly[" + OString::number(nFly
)
555 const auto nFlyBottom
= getXPath(pLayoutXML2
,
556 "/root/page/body/txt[6]/anchored/fly["
557 + OString::number(nFly
) + "]/infos/bounds",
561 const auto sDrawRect
= getXPath(
563 "/root/page/body/txt[6]/anchored/SwAnchoredDrawObject/SdrObjGroup/SdrObjList/SdrObject["
564 + OString::number(nFly
) + "]",
567 const auto nComaPos1
= sDrawRect
.indexOf(',', 0);
568 const auto nComaPos2
= sDrawRect
.indexOf(',', nComaPos1
+ 1);
569 const auto nComaPos3
= sDrawRect
.indexOf(',', nComaPos2
+ 1);
571 const auto nDraw1
= o3tl::toInt64(sDrawRect
.subView(0, nComaPos1
));
572 const auto nDraw2
= o3tl::toInt64(sDrawRect
.subView(nComaPos1
+ 1, nComaPos2
- nComaPos1
));
573 const auto nDraw3
= o3tl::toInt64(sDrawRect
.subView(nComaPos2
+ 1, nComaPos3
- nComaPos2
));
574 const auto nDraw4
= o3tl::toInt64(
575 sDrawRect
.subView(nComaPos3
+ 1, sDrawRect
.getLength() - nComaPos3
- 1));
577 CPPUNIT_ASSERT_GREATER(nDraw1
, nFlyLeft
);
578 CPPUNIT_ASSERT_GREATER(nDraw2
, nFlyTop
);
579 CPPUNIT_ASSERT_LESS(nDraw3
, nFlyRight
);
580 CPPUNIT_ASSERT_LESS(nDraw4
, nFlyBottom
);
584 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf148868
)
586 createSwDoc("tdf148868.odt");
587 SwDoc
* pDoc
= getSwDoc();
588 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
590 CPPUNIT_ASSERT_EQUAL(1, getShapes());
591 CPPUNIT_ASSERT_EQUAL(1, getPages());
593 pWrtShell
->EndPg(/*bSelect=*/false);
594 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/true, 5, /*bBasicCall=*/false);
595 pWrtShell
->Insert("X");
597 // Without the fix in place, this test would have failed with
600 CPPUNIT_ASSERT_EQUAL(1, getShapes());
601 CPPUNIT_ASSERT_EQUAL(1, getPages());
604 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf129382
)
606 createSwDoc("tdf129382.docx");
608 CPPUNIT_ASSERT_EQUAL(8, getShapes());
609 CPPUNIT_ASSERT_EQUAL(2, getPages());
611 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
613 dispatchCommand(mxComponent
, ".uno:Cut", {});
615 CPPUNIT_ASSERT_EQUAL(3, getShapes());
616 CPPUNIT_ASSERT_EQUAL(1, getPages());
618 dispatchCommand(mxComponent
, ".uno:Paste", {});
620 CPPUNIT_ASSERT_EQUAL(8, getShapes());
621 CPPUNIT_ASSERT_EQUAL(2, getPages());
622 dispatchCommand(mxComponent
, ".uno:Undo", {});
623 CPPUNIT_ASSERT_EQUAL(3, getShapes());
624 CPPUNIT_ASSERT_EQUAL(1, getPages());
626 // without the fix, it crashes
627 dispatchCommand(mxComponent
, ".uno:Undo", {});
628 CPPUNIT_ASSERT_EQUAL(8, getShapes());
631 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf135662
)
633 createSwDoc("tdf135662.odt");
635 CPPUNIT_ASSERT_EQUAL(2, getShapes());
637 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
639 dispatchCommand(mxComponent
, ".uno:Cut", {});
641 CPPUNIT_ASSERT_EQUAL(0, getShapes());
643 dispatchCommand(mxComponent
, ".uno:Paste", {});
645 // Without the fix in place, this test would have failed with
648 CPPUNIT_ASSERT_EQUAL(2, getShapes());
651 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf134227
)
653 createSwDoc("tdf134227.docx");
655 CPPUNIT_ASSERT_EQUAL(4, getShapes());
657 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
658 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
660 // Without the fix in place, it would have crashed here
661 dispatchCommand(mxComponent
, ".uno:Cut", {});
663 CPPUNIT_ASSERT_EQUAL(0, getShapes());
665 dispatchCommand(mxComponent
, ".uno:Paste", {});
667 CPPUNIT_ASSERT_EQUAL(4, getShapes());
669 dispatchCommand(mxComponent
, ".uno:Undo", {});
670 CPPUNIT_ASSERT_EQUAL(0, getShapes());
672 dispatchCommand(mxComponent
, ".uno:Undo", {});
673 CPPUNIT_ASSERT_EQUAL(4, getShapes());
676 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf139638
)
678 createSwDoc("tdf139638.odt");
680 uno::Reference
<text::XDocumentIndexesSupplier
> xIndexSupplier(mxComponent
, uno::UNO_QUERY
);
681 uno::Reference
<container::XIndexAccess
> xIndexes
= xIndexSupplier
->getDocumentIndexes();
682 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexes
->getCount());
683 uno::Reference
<text::XDocumentIndex
> xTOCIndex(xIndexes
->getByIndex(0), uno::UNO_QUERY
);
685 // Without the fix in place, this test would have crashed
689 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf114773
)
691 createSwDoc("tdf114773.odt");
693 uno::Reference
<text::XDocumentIndexesSupplier
> xIndexSupplier(mxComponent
, uno::UNO_QUERY
);
694 uno::Reference
<container::XIndexAccess
> xIndexes
= xIndexSupplier
->getDocumentIndexes();
695 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexes
->getCount());
696 uno::Reference
<text::XDocumentIndex
> xTOCIndex(xIndexes
->getByIndex(0), uno::UNO_QUERY
);
699 uno::Reference
<text::XTextRange
> xTextRange
= xTOCIndex
->getAnchor();
700 uno::Reference
<text::XText
> xText
= xTextRange
->getText();
701 uno::Reference
<text::XTextCursor
> xTextCursor
= xText
->createTextCursor();
702 xTextCursor
->gotoRange(xTextRange
->getStart(), false);
703 xTextCursor
->gotoRange(xTextRange
->getEnd(), true);
704 OUString
aIndexString(convertLineEnd(xTextCursor
->getString(), LineEnd::LINEEND_LF
));
706 // Without the fix in place, this test would have failed with
707 // - Expected: 2 Heading Level 1 2-1
708 // - Actual : 2 Heading Level 1 2 -1
709 CPPUNIT_ASSERT_EQUAL(OUString("Full ToC\n"
710 "2 Heading Level 1\t2-1\n"
711 "2.1 Heading Level 2\t2-2\n"
712 "2.1.1 Heading Level 3\t2-2\n"
713 "2.1.1.1 Heading Level 4\t2-2"),
717 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf104315
)
719 createSwDoc("tdf104315.odt");
721 uno::Reference
<text::XDocumentIndexesSupplier
> xIndexSupplier(mxComponent
, uno::UNO_QUERY
);
722 uno::Reference
<container::XIndexAccess
> xIndexes
= xIndexSupplier
->getDocumentIndexes();
723 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexes
->getCount());
724 uno::Reference
<text::XDocumentIndex
> xTOCIndex(xIndexes
->getByIndex(0), uno::UNO_QUERY
);
727 uno::Reference
<text::XTextRange
> xTextRange
= xTOCIndex
->getAnchor();
728 uno::Reference
<text::XText
> xText
= xTextRange
->getText();
729 uno::Reference
<text::XTextCursor
> xTextCursor
= xText
->createTextCursor();
730 xTextCursor
->gotoRange(xTextRange
->getStart(), false);
731 xTextCursor
->gotoRange(xTextRange
->getEnd(), true);
732 OUString
aIndexString(convertLineEnd(xTextCursor
->getString(), LineEnd::LINEEND_LF
));
734 // Without the fix in place, this test would have failed with
735 // - Expected: This is a headlinex 1
736 // - Actual : This is a headlinx 1
737 CPPUNIT_ASSERT_EQUAL(OUString("Table of contents\n"
738 "This is a headlinex\t1\n"
739 "This is another headlinex\t1"),
743 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf135412
)
745 createSwDoc("tdf135412.docx");
747 CPPUNIT_ASSERT_EQUAL(4, getShapes());
748 uno::Reference
<text::XTextRange
> xShape(getShape(1), uno::UNO_QUERY
);
749 CPPUNIT_ASSERT_EQUAL(OUString("X"), xShape
->getString());
751 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
753 dispatchCommand(mxComponent
, ".uno:Cut", {});
755 CPPUNIT_ASSERT_EQUAL(0, getShapes());
757 dispatchCommand(mxComponent
, ".uno:Paste", {});
759 CPPUNIT_ASSERT_EQUAL(4, getShapes());
761 // Without the fix in place, the text in the shape wouldn't be pasted
762 xShape
.set(getShape(1), uno::UNO_QUERY
);
763 CPPUNIT_ASSERT_EQUAL(OUString("X"), xShape
->getString());
765 //Without the fix in place, it would have crashed here
766 dispatchCommand(mxComponent
, ".uno:Undo", {});
767 CPPUNIT_ASSERT_EQUAL(0, getShapes());
768 dispatchCommand(mxComponent
, ".uno:Undo", {});
769 CPPUNIT_ASSERT_EQUAL(4, getShapes());
770 xShape
.set(getShape(1), uno::UNO_QUERY
);
771 CPPUNIT_ASSERT_EQUAL(OUString("X"), xShape
->getString());
774 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf138482
)
776 createSwDoc("tdf138482.docx");
778 CPPUNIT_ASSERT_EQUAL(2, getShapes());
780 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
782 // Without the fix in place, this test would have crashed here
783 dispatchCommand(mxComponent
, ".uno:Delete", {});
784 CPPUNIT_ASSERT_EQUAL(0, getShapes());
786 dispatchCommand(mxComponent
, ".uno:Undo", {});
787 CPPUNIT_ASSERT_EQUAL(2, getShapes());
790 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf134965
)
792 createSwDoc("tdf134965.odt");
794 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
795 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
797 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
799 for (sal_Int32 i
= 0; i
< 10; ++i
)
801 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
803 dispatchCommand(mxComponent
, ".uno:Cut", {});
805 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
807 // Without the fix in place, this test would have crashed here
808 dispatchCommand(mxComponent
, ".uno:Paste", {});
810 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
814 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf128375
)
816 for (sal_Int32 i
= 0; i
< 2; ++i
)
818 createSwDoc("tdf128375.docx");
820 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
821 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
823 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
825 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
827 // Without the fix in place, this test would have crashed cutting the second document
828 dispatchCommand(mxComponent
, ".uno:Cut", {});
830 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
834 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf135061
)
836 createSwDoc("tdf135061.odt");
838 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
839 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
841 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
842 CPPUNIT_ASSERT_EQUAL(4, getShapes());
844 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
846 dispatchCommand(mxComponent
, ".uno:Copy", {});
848 for (sal_Int32 i
= 0; i
< 5; ++i
)
850 dispatchCommand(mxComponent
, ".uno:Paste", {});
853 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xIndexAccess
->getCount());
854 CPPUNIT_ASSERT_EQUAL(20, getShapes());
856 for (sal_Int32 i
= 0; i
< 5; ++i
)
858 // Without the fix in place, this test would have crashed here
859 dispatchCommand(mxComponent
, ".uno:Undo", {});
862 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
863 CPPUNIT_ASSERT_EQUAL(4, getShapes());
866 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132911
)
868 createSwDoc("tdf132911.odt");
870 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
871 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
873 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
874 CPPUNIT_ASSERT_EQUAL(4, getShapes());
876 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
878 dispatchCommand(mxComponent
, ".uno:Cut", {});
880 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
881 CPPUNIT_ASSERT_EQUAL(0, getShapes());
883 dispatchCommand(mxComponent
, ".uno:Paste", {});
885 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
886 CPPUNIT_ASSERT_EQUAL(4, getShapes());
888 // Without the fix in place, it would have crashed here
889 dispatchCommand(mxComponent
, ".uno:Paste", {});
890 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
891 CPPUNIT_ASSERT_EQUAL(8, getShapes());
893 dispatchCommand(mxComponent
, ".uno:Undo", {});
894 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
895 CPPUNIT_ASSERT_EQUAL(4, getShapes());
897 dispatchCommand(mxComponent
, ".uno:Undo", {});
898 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
899 CPPUNIT_ASSERT_EQUAL(0, getShapes());
901 dispatchCommand(mxComponent
, ".uno:Paste", {});
902 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
903 CPPUNIT_ASSERT_EQUAL(4, getShapes());
905 dispatchCommand(mxComponent
, ".uno:Paste", {});
906 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
907 CPPUNIT_ASSERT_EQUAL(8, getShapes());
909 dispatchCommand(mxComponent
, ".uno:Undo", {});
910 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
911 CPPUNIT_ASSERT_EQUAL(4, getShapes());
913 dispatchCommand(mxComponent
, ".uno:Undo", {});
914 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
915 CPPUNIT_ASSERT_EQUAL(0, getShapes());
917 //tdf#135247: Without the fix in place, this would have crashed
918 dispatchCommand(mxComponent
, ".uno:Undo", {});
919 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
920 CPPUNIT_ASSERT_EQUAL(4, getShapes());
923 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf61154
)
925 createSwDoc("tdf61154.fodt");
926 SwDoc
* pDoc
= getSwDoc();
927 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
929 pWrtShell
->GotoNextTOXBase();
932 pDoc
->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::ShowDelete
933 | RedlineFlags::ShowInsert
);
934 CPPUNIT_ASSERT_MESSAGE("redlining should be off",
935 !pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
936 CPPUNIT_ASSERT_MESSAGE(
937 "redlines should be visible",
938 IDocumentRedlineAccess::IsShowChanges(pDoc
->getIDocumentRedlineAccess().GetRedlineFlags()));
940 const SwTOXBase
* pTOXBase
= pWrtShell
->GetCurTOX();
941 pWrtShell
->UpdateTableOf(*pTOXBase
);
942 SwCursorShell
* pShell(pDoc
->GetEditShell());
943 SwTextNode
* pTitleNode
= pShell
->GetCursor()->GetPointNode().GetTextNode();
944 SwNodeIndex
aIdx(*pTitleNode
);
946 // table of contents node shouldn't contain tracked deletion
947 // This was "Text InsertedDeleted\t1"
948 SwTextNode
* pNext
= static_cast<SwTextNode
*>(pDoc
->GetNodes().GoNext(&aIdx
));
949 CPPUNIT_ASSERT_EQUAL(OUString("Text Inserted\t1"), pNext
->GetText());
952 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf124904
)
954 // don't show deletions in referenced text,
955 // (except if the full text is deleted)
956 createSwDoc("tdf124904.fodt");
957 SwDoc
* pDoc
= getSwDoc();
960 pDoc
->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On
| RedlineFlags::ShowDelete
961 | RedlineFlags::ShowInsert
);
962 CPPUNIT_ASSERT_MESSAGE("redlining should be on",
963 pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
964 CPPUNIT_ASSERT_MESSAGE(
965 "redlines should be visible",
966 IDocumentRedlineAccess::IsShowChanges(pDoc
->getIDocumentRedlineAccess().GetRedlineFlags()));
968 // remove the first word "Heading" (with change tracking) to update the referenced text
969 dispatchCommand(mxComponent
, ".uno:DelToEndOfWord", {});
971 // This was "Reference to Heading of document file"
972 CPPUNIT_ASSERT_EQUAL(OUString("Reference to of example document "),
973 getParagraph(2)->getString());
975 // don't hide the wholly deleted referenced text
976 dispatchCommand(mxComponent
, ".uno:DelToEndOfLine", {});
977 CPPUNIT_ASSERT_EQUAL(OUString("Reference to Heading of example document file"),
978 getParagraph(2)->getString());
981 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf100691
)
983 createSwDoc("tdf100691.fodt");
984 SwDoc
* pDoc
= getSwDoc();
985 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
987 pWrtShell
->GotoNextTOXBase();
989 const SwTOXBase
* pTOXBase
= pWrtShell
->GetCurTOX();
990 pWrtShell
->UpdateTableOf(*pTOXBase
);
991 SwCursorShell
* pShell(pDoc
->GetEditShell());
992 SwTextNode
* pTitleNode
= pShell
->GetCursor()->GetPointNode().GetTextNode();
993 SwNodeIndex
aIdx(*pTitleNode
);
995 // table of contents node shouldn't contain invisible text
996 // This was "Text Hidden\t1"
997 SwTextNode
* pNext
= static_cast<SwTextNode
*>(pDoc
->GetNodes().GoNext(&aIdx
));
998 CPPUNIT_ASSERT_EQUAL(OUString("Text\t1"), pNext
->GetText());
1001 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf134404
)
1003 createSwDoc("tdf134404.odt");
1005 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1006 CPPUNIT_ASSERT_EQUAL(1, getPages());
1008 dispatchCommand(mxComponent
, ".uno:GoToEndOfPage", {});
1009 dispatchCommand(mxComponent
, ".uno:InsertPagebreak", {});
1011 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1012 CPPUNIT_ASSERT_EQUAL(2, getPages());
1014 dispatchCommand(mxComponent
, ".uno:SwBackspace", {});
1016 // Without the fix in place, the image would have been deleted
1017 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1018 CPPUNIT_ASSERT_EQUAL(1, getPages());
1020 dispatchCommand(mxComponent
, ".uno:Undo", {});
1021 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1022 CPPUNIT_ASSERT_EQUAL(2, getPages());
1025 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf112342
)
1027 createSwDoc("tdf112342.docx");
1030 uno::Reference
<text::XTextRange
> xPara
= getParagraph(3);
1031 auto xCur
= xPara
->getText()->createTextCursor();
1032 //Go to the end of it
1033 xCur
->gotoEnd(false);
1034 //And let's remove the last 2 chars (the last para with its char).
1035 xCur
->goLeft(2, true);
1036 xCur
->setString("");
1038 //If the second paragraph on the second page, this will be passed.
1039 CPPUNIT_ASSERT_EQUAL_MESSAGE("Page break does not match", 2, getPages());
1042 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132321
)
1044 createSwDoc("tdf132321.odt");
1046 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1048 dispatchCommand(mxComponent
, ".uno:GoToEndOfPage", {});
1049 dispatchCommand(mxComponent
, ".uno:SwBackspace", {});
1051 // Without the fix in place, the button form would have also been deleted
1052 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1054 dispatchCommand(mxComponent
, ".uno:Undo", {});
1055 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1058 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf135056
)
1060 createSwDoc("tdf135056.odt");
1061 SwDoc
* pDoc
= getSwDoc();
1062 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1064 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pWrtShell
->GetTOXCount());
1066 const SwTOXBase
* pTOX
= pWrtShell
->GetTOX(0);
1067 CPPUNIT_ASSERT(pTOX
);
1069 //Without the fix in place, it would have hung here
1070 pWrtShell
->DeleteTOX(*pTOX
, true);
1072 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pWrtShell
->GetTOXCount());
1074 dispatchCommand(mxComponent
, ".uno:Undo", {});
1076 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pWrtShell
->GetTOXCount());
1079 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132597
)
1081 createSwDoc("tdf132597.odt");
1083 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1084 CPPUNIT_ASSERT_EQUAL(1, getPages());
1086 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1088 dispatchCommand(mxComponent
, ".uno:Copy", {});
1090 // Paste special as RTF
1091 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1092 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
1094 dispatchCommand(mxComponent
, ".uno:ClipboardFormatItems", aPropertyValues
);
1096 // Without the fix in place, this test would have crashed here
1097 dispatchCommand(mxComponent
, ".uno:Undo", {});
1099 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1100 CPPUNIT_ASSERT_EQUAL(1, getPages());
1103 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf139737
)
1105 createSwDoc("tdf139737.fodt");
1107 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1109 dispatchCommand(mxComponent
, ".uno:Copy", {});
1111 // Paste special as RTF
1112 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1113 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
1115 dispatchCommand(mxComponent
, ".uno:ClipboardFormatItems", aPropertyValues
);
1117 // Without the fix in place, this test would have crashed here
1118 dispatchCommand(mxComponent
, ".uno:Undo", {});
1121 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf150845
)
1125 // Insert text box with ctrl key
1126 // Without the fix in place, this test would have crashed here
1127 uno::Sequence
<beans::PropertyValue
> aArgs(
1128 comphelper::InitPropertySequence({ { "KeyModifier", uno::Any(KEY_MOD1
) } }));
1129 dispatchCommand(mxComponent
, ".uno:Edit", aArgs
);
1131 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1134 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf147961
)
1137 SwDoc
* pDoc
= getSwDoc();
1138 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1140 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1141 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1143 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
1145 pWrtShell
->Insert("++");
1147 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
1149 // Without the fix in place, this test would have crashed here
1150 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
1151 Scheduler::ProcessEventsToIdle();
1153 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1156 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf147206
)
1159 SwDoc
* pDoc
= getSwDoc();
1160 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1162 // insert empty paragraph and heading text
1163 pWrtShell
->SplitNode();
1164 pWrtShell
->Insert("abc");
1165 pWrtShell
->SplitNode();
1167 // set one to heading so there will be an entry in the tox
1168 pWrtShell
->Up(false, 1);
1169 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence({
1170 { "Style", uno::Any(OUString("Heading 1")) },
1171 { "FamilyName", uno::Any(OUString("ParagraphStyles")) },
1173 dispatchCommand(mxComponent
, ".uno:StyleApply", aPropertyValues
);
1175 pWrtShell
->EndOfSection(false);
1177 // tdf#142423: Without the fix in place, this test would have failed with
1180 CPPUNIT_ASSERT_EQUAL(18.0f
, getProperty
<float>(getParagraph(2), "CharHeight"));
1182 // insert table of contents
1183 SwTOXMgr
mgr(pWrtShell
);
1184 SwTOXDescription desc
{ TOX_CONTENT
};
1185 mgr
.UpdateOrInsertTOX(desc
, nullptr, nullptr);
1187 // get url of heading cross reference mark
1188 IDocumentMarkAccess
& rIDMA(*pDoc
->getIDocumentMarkAccess());
1189 auto const headingMark
1190 = std::find_if(rIDMA
.getAllMarksBegin(), rIDMA
.getAllMarksEnd(), [](auto const* const it
) {
1191 return it
->GetName().startsWith(
1192 IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix());
1194 CPPUNIT_ASSERT(headingMark
!= rIDMA
.getAllMarksEnd());
1195 OUString
const headingLink("#" + (*headingMark
)->GetName());
1198 pWrtShell
->SttEndDoc(false);
1199 pWrtShell
->Up(false, 1);
1200 pWrtShell
->EndPara(true);
1202 rtl::Reference
<SwTransferable
> xTransfer
= new SwTransferable(*pWrtShell
);
1205 pWrtShell
->SttEndDoc(true);
1207 // Paste special as RTF
1208 TransferableDataHelper
helper(xTransfer
);
1209 SwTransferable::PasteFormat(*pWrtShell
, helper
, SotClipboardFormatId::RTF
);
1210 Scheduler::ProcessEventsToIdle();
1212 // check hyperlinking
1213 CPPUNIT_ASSERT_EQUAL(
1214 headingLink
, getProperty
<OUString
>(getRun(getParagraph(1), 1, "abc\t1"), "HyperLinkURL"));
1215 CPPUNIT_ASSERT_EQUAL(
1216 OUString(), getProperty
<OUString
>(getRun(getParagraph(2), 1, OUString()), "HyperLinkURL"));
1217 CPPUNIT_ASSERT_EQUAL(
1219 getProperty
<OUString
>(getRun(getParagraph(3), 1, "Table of Contents"), "HyperLinkURL"));
1220 CPPUNIT_ASSERT_EQUAL(
1221 headingLink
, getProperty
<OUString
>(getRun(getParagraph(4), 1, "abc\t1"), "HyperLinkURL"));
1222 CPPUNIT_ASSERT_EQUAL(
1223 OUString(), getProperty
<OUString
>(getRun(getParagraph(5), 1, OUString()), "HyperLinkURL"));
1226 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf144840
)
1228 createSwDoc("tdf144840.odt");
1230 CPPUNIT_ASSERT_EQUAL(1, getPages());
1231 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1232 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1234 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1236 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1238 dispatchCommand(mxComponent
, ".uno:Cut", {});
1240 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
1242 // Paste special as RTF
1243 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1244 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
1246 dispatchCommand(mxComponent
, ".uno:ClipboardFormatItems", aPropertyValues
);
1248 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1250 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1252 table::TableBorder2 tableBorder
= getProperty
<table::TableBorder2
>(xTextTable
, "TableBorder2");
1254 // Without the fix in place, this test would have failed with
1257 CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), tableBorder
.TopLine
.LineWidth
);
1258 CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), tableBorder
.LeftLine
.LineWidth
);
1259 CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), tableBorder
.RightLine
.LineWidth
);
1260 CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), tableBorder
.BottomLine
.LineWidth
);
1263 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf131963
)
1265 createSwDoc("tdf131963.docx");
1267 CPPUNIT_ASSERT_EQUAL(11, getPages());
1269 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1271 dispatchCommand(mxComponent
, ".uno:Copy", {});
1273 // Paste special as RTF
1274 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1275 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
1277 dispatchCommand(mxComponent
, ".uno:ClipboardFormatItems", aPropertyValues
);
1279 // Without the fix in place, this test would have crashed here
1281 // tdf#133169: without the fix in place, it would have been 2 instead of 11
1282 CPPUNIT_ASSERT_EQUAL(11, getPages());
1285 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132596
)
1287 createSwDoc("tdf132596.docx");
1289 CPPUNIT_ASSERT_EQUAL(2, getPages());
1291 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1293 dispatchCommand(mxComponent
, ".uno:Copy", {});
1295 // Paste special as RTF
1296 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1297 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
1299 dispatchCommand(mxComponent
, ".uno:ClipboardFormatItems", aPropertyValues
);
1301 // Without the fix in place, this test would have crashed here
1302 dispatchCommand(mxComponent
, ".uno:Undo", {});
1304 CPPUNIT_ASSERT_EQUAL(2, getPages());
1307 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf126626
)
1309 createSwDoc("tdf126626.docx");
1311 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1313 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1315 dispatchCommand(mxComponent
, ".uno:Copy", {});
1317 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1319 dispatchCommand(mxComponent
, ".uno:Paste", {});
1320 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1322 dispatchCommand(mxComponent
, ".uno:Paste", {});
1323 CPPUNIT_ASSERT_EQUAL(4, getShapes());
1325 dispatchCommand(mxComponent
, ".uno:Undo", {});
1326 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1328 // without the fix, it crashes
1329 dispatchCommand(mxComponent
, ".uno:Paste", {});
1330 CPPUNIT_ASSERT_EQUAL(4, getShapes());
1333 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf133967
)
1335 createSwDoc("tdf133967.odt");
1337 CPPUNIT_ASSERT_EQUAL(6, getPages());
1339 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1341 dispatchCommand(mxComponent
, ".uno:Cut", {});
1343 for (sal_Int32 i
= 0; i
< 10; ++i
)
1345 dispatchCommand(mxComponent
, ".uno:Undo", {});
1347 dispatchCommand(mxComponent
, ".uno:Redo", {});
1350 // Without the fix in place, this test would have failed with:
1353 CPPUNIT_ASSERT_EQUAL(1, getPages());
1356 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132187
)
1358 createSwDoc("tdf132187.odt");
1360 CPPUNIT_ASSERT_EQUAL(1, getPages());
1362 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1364 dispatchCommand(mxComponent
, ".uno:Copy", {});
1366 dispatchCommand(mxComponent
, ".uno:GoToEndOfDoc", {});
1368 for (sal_Int32 i
= 0; i
< 10; ++i
)
1370 dispatchCommand(mxComponent
, ".uno:Paste", {});
1373 //without the fix in place, this test would fail with:
1377 CPPUNIT_ASSERT_EQUAL(1, getPages());
1380 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf130094
)
1382 createSwDoc("tdf130094.fodt");
1383 SwDoc
* pDoc
= getSwDoc();
1384 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1386 CPPUNIT_ASSERT_EQUAL(OUString("First"), getParagraph(1)->getString());
1387 CPPUNIT_ASSERT_EQUAL(OUString("Second"), getParagraph(2)->getString());
1388 CPPUNIT_ASSERT_EQUAL(OUString("Third"), getParagraph(3)->getString());
1390 // Select the first and second lines
1391 pWrtShell
->Down(/*bSelect=*/true);
1392 pWrtShell
->Down(/*bSelect=*/true);
1394 dispatchCommand(mxComponent
, ".uno:Copy", {});
1396 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1398 dispatchCommand(mxComponent
, ".uno:Paste", {});
1400 CPPUNIT_ASSERT_EQUAL(OUString("First"), getParagraph(1)->getString());
1401 CPPUNIT_ASSERT_EQUAL(OUString("Second"), getParagraph(2)->getString());
1402 CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(3)->getString());
1404 dispatchCommand(mxComponent
, ".uno:Undo", {});
1406 CPPUNIT_ASSERT_EQUAL(OUString("First"), getParagraph(1)->getString());
1407 CPPUNIT_ASSERT_EQUAL(OUString("Second"), getParagraph(2)->getString());
1408 CPPUNIT_ASSERT_EQUAL(OUString("Third"), getParagraph(3)->getString());
1410 dispatchCommand(mxComponent
, ".uno:Paste", {});
1412 CPPUNIT_ASSERT_EQUAL(OUString("First"), getParagraph(1)->getString());
1413 CPPUNIT_ASSERT_EQUAL(OUString("Second"), getParagraph(2)->getString());
1415 // Without the fix in place, this test would have failed with
1418 CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(3)->getString());
1421 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf135733
)
1423 createSwDoc("tdf135733.odt");
1424 SwDoc
* pDoc
= getSwDoc();
1425 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1427 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1428 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1430 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1431 CPPUNIT_ASSERT_EQUAL(1, getPages());
1432 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1434 //Move the cursor inside the table
1435 pWrtShell
->Down(/*bSelect=*/false);
1436 pWrtShell
->Down(/*bSelect=*/false);
1438 //Select first column
1439 pWrtShell
->Down(/*bSelect=*/true);
1440 pWrtShell
->Down(/*bSelect=*/true);
1441 pWrtShell
->Down(/*bSelect=*/true);
1443 dispatchCommand(mxComponent
, ".uno:Cut", {});
1445 pWrtShell
->SttPg(/*bSelect=*/false);
1447 dispatchCommand(mxComponent
, ".uno:Paste", {});
1449 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1450 CPPUNIT_ASSERT_EQUAL(1, getPages());
1451 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1453 dispatchCommand(mxComponent
, ".uno:Undo", {});
1455 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1456 CPPUNIT_ASSERT_EQUAL(1, getPages());
1457 CPPUNIT_ASSERT_EQUAL(0, getShapes());
1459 // without the fix, it crashes
1460 dispatchCommand(mxComponent
, ".uno:Undo", {});
1462 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1463 CPPUNIT_ASSERT_EQUAL(1, getPages());
1464 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1467 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf128739
)
1469 createSwDoc("tdf128739.docx");
1471 CPPUNIT_ASSERT_EQUAL(OUString("Fehler: Verweis nicht gefunden"), getParagraph(1)->getString());
1473 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1475 dispatchCommand(mxComponent
, ".uno:Cut", {});
1477 CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString());
1479 dispatchCommand(mxComponent
, ".uno:Paste", {});
1480 CPPUNIT_ASSERT_EQUAL(OUString("Fehler: Verweis nicht gefunden"), getParagraph(1)->getString());
1482 // without the fix, it crashes
1483 dispatchCommand(mxComponent
, ".uno:Undo", {});
1484 CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString());
1487 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf124722
)
1489 createSwDoc("tdf124722.rtf");
1491 CPPUNIT_ASSERT_EQUAL(22, getPages());
1493 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1495 dispatchCommand(mxComponent
, ".uno:Copy", {});
1497 CPPUNIT_ASSERT_EQUAL(22, getPages());
1499 dispatchCommand(mxComponent
, ".uno:Paste", {});
1500 CPPUNIT_ASSERT_EQUAL(43, getPages());
1502 dispatchCommand(mxComponent
, ".uno:Undo", {});
1503 CPPUNIT_ASSERT_EQUAL(22, getPages());
1506 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testToxmarkLinks
)
1508 createSwDoc("udindex3.odt");
1509 SwDoc
* pDoc
= getSwDoc();
1510 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1511 SwView
& rView(*pDoc
->GetDocShell()->GetView());
1514 for (auto i
= pWrtShell
->GetTOXCount(); 0 < i
;)
1517 pWrtShell
->UpdateTableOf(*pWrtShell
->GetTOX(i
));
1520 // click on the links...
1522 OUString
const tmp("Table of Contents");
1523 pWrtShell
->GotoNextTOXBase(&tmp
);
1527 pWrtShell
->Down(false);
1528 SfxItemSet
aSet(pWrtShell
->GetAttrPool(),
1529 svl::Items
<RES_TXTATR_INETFMT
, RES_TXTATR_INETFMT
>);
1530 pWrtShell
->GetCurAttr(aSet
);
1531 CPPUNIT_ASSERT(aSet
.HasItem(RES_TXTATR_INETFMT
));
1533 OUString
const url(aSet
.GetItem
<SwFormatINetFormat
>(RES_TXTATR_INETFMT
)->GetValue());
1534 CPPUNIT_ASSERT_EQUAL(OUString("#1%19the%20tocmark%19C%7Ctoxmark"), url
);
1535 rView
.JumpToSwMark(url
.subView(1)); // SfxApplication::OpenDocExec_Impl eats the "#"
1536 CPPUNIT_ASSERT_EQUAL(OUString(OUStringChar(CH_TXTATR_INWORD
) + "tocmark"),
1537 pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1538 pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
1542 pWrtShell
->Down(false);
1543 SfxItemSet
aSet(pWrtShell
->GetAttrPool(),
1544 svl::Items
<RES_TXTATR_INETFMT
, RES_TXTATR_INETFMT
>);
1545 pWrtShell
->GetCurAttr(aSet
);
1546 CPPUNIT_ASSERT(aSet
.HasItem(RES_TXTATR_INETFMT
));
1548 OUString
const url(aSet
.GetItem
<SwFormatINetFormat
>(RES_TXTATR_INETFMT
)->GetValue());
1549 CPPUNIT_ASSERT_EQUAL(OUString("#__RefHeading___Toc105_706348105"), url
);
1550 rView
.JumpToSwMark(url
.subView(1));
1551 CPPUNIT_ASSERT_EQUAL(OUString("foo"),
1552 pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1553 pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
1557 OUString
const tmp("User-Defined1");
1558 pWrtShell
->GotoNextTOXBase(&tmp
);
1562 pWrtShell
->Down(false);
1563 SfxItemSet
aSet(pWrtShell
->GetAttrPool(),
1564 svl::Items
<RES_TXTATR_INETFMT
, RES_TXTATR_INETFMT
>);
1565 pWrtShell
->GetCurAttr(aSet
);
1566 CPPUNIT_ASSERT(aSet
.HasItem(RES_TXTATR_INETFMT
));
1568 OUString
const url(aSet
.GetItem
<SwFormatINetFormat
>(RES_TXTATR_INETFMT
)->GetValue());
1569 CPPUNIT_ASSERT_EQUAL(OUString("#1%19the%20udmark%19UUser-Defined%7Ctoxmark"), url
);
1570 rView
.JumpToSwMark(url
.subView(1));
1571 CPPUNIT_ASSERT_EQUAL(OUString(OUStringChar(CH_TXTATR_INWORD
) + "udmark the first"),
1572 pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1573 pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
1576 { // UD1 toxmark 2 (with same text)
1577 pWrtShell
->Down(false);
1578 SfxItemSet
aSet(pWrtShell
->GetAttrPool(),
1579 svl::Items
<RES_TXTATR_INETFMT
, RES_TXTATR_INETFMT
>);
1580 pWrtShell
->GetCurAttr(aSet
);
1581 CPPUNIT_ASSERT(aSet
.HasItem(RES_TXTATR_INETFMT
));
1583 OUString
const url(aSet
.GetItem
<SwFormatINetFormat
>(RES_TXTATR_INETFMT
)->GetValue());
1584 CPPUNIT_ASSERT_EQUAL(OUString("#2%19the%20udmark%19UUser-Defined%7Ctoxmark"), url
);
1585 rView
.JumpToSwMark(url
.subView(1));
1586 CPPUNIT_ASSERT_EQUAL(OUString(OUStringChar(CH_TXTATR_INWORD
) + "udmark the 2nd"),
1587 pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1588 pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
1592 pWrtShell
->Down(false);
1593 SfxItemSet
aSet(pWrtShell
->GetAttrPool(),
1594 svl::Items
<RES_TXTATR_INETFMT
, RES_TXTATR_INETFMT
>);
1595 pWrtShell
->GetCurAttr(aSet
);
1596 CPPUNIT_ASSERT(aSet
.HasItem(RES_TXTATR_INETFMT
));
1598 OUString
const url(aSet
.GetItem
<SwFormatINetFormat
>(RES_TXTATR_INETFMT
)->GetValue());
1599 CPPUNIT_ASSERT_EQUAL(OUString("#__RefHeading___Toc105_706348105"), url
);
1600 rView
.JumpToSwMark(url
.subView(1));
1601 CPPUNIT_ASSERT_EQUAL(OUString("foo"),
1602 pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1603 pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
1607 OUString
const tmp("NewUD!|1");
1608 pWrtShell
->GotoNextTOXBase(&tmp
);
1611 { // UD2 toxmark, with same text as those in other UD
1612 pWrtShell
->Down(false);
1613 SfxItemSet
aSet(pWrtShell
->GetAttrPool(),
1614 svl::Items
<RES_TXTATR_INETFMT
, RES_TXTATR_INETFMT
>);
1615 pWrtShell
->GetCurAttr(aSet
);
1616 CPPUNIT_ASSERT(aSet
.HasItem(RES_TXTATR_INETFMT
));
1618 OUString
const url(aSet
.GetItem
<SwFormatINetFormat
>(RES_TXTATR_INETFMT
)->GetValue());
1619 CPPUNIT_ASSERT_EQUAL(OUString("#1%19the%20udmark%19UNewUD!%7C%7Ctoxmark"), url
);
1620 rView
.JumpToSwMark(url
.subView(1));
1621 CPPUNIT_ASSERT_EQUAL(OUString("the udmark"),
1622 pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1623 pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
1627 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf125261
)
1629 createSwDoc("tdf125261.odt");
1631 CPPUNIT_ASSERT_EQUAL(OUString("https://www.example.com/"),
1632 getProperty
<OUString
>(getRun(getParagraph(1), 1), "HyperLinkURL"));
1633 //apply autocorrect StartAutoCorrect
1634 dispatchCommand(mxComponent
, ".uno:AutoFormatApply", {});
1635 CPPUNIT_ASSERT_EQUAL(OUString("https://www.example.com/"),
1636 getProperty
<OUString
>(getRun(getParagraph(1), 1), "HyperLinkURL"));
1637 // without the fix, it hangs
1638 dispatchCommand(mxComponent
, ".uno:Undo", {});
1639 CPPUNIT_ASSERT_EQUAL(OUString("https://www.example.com/"),
1640 getProperty
<OUString
>(getRun(getParagraph(1), 1), "HyperLinkURL"));
1643 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf141175
)
1645 createSwDoc("tdf141175.odt");
1647 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1648 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1650 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1651 CPPUNIT_ASSERT_EQUAL(1, getPages());
1653 //Use selectAll 3 times in a row
1654 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1655 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1656 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1658 //Without the fix in place, this test would have crashed here
1659 dispatchCommand(mxComponent
, ".uno:Cut", {});
1661 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1662 CPPUNIT_ASSERT_EQUAL(1, getPages());
1664 dispatchCommand(mxComponent
, ".uno:Paste", {});
1666 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1667 CPPUNIT_ASSERT_EQUAL(1, getPages());
1670 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf133990
)
1672 createSwDoc("tdf133990.odt");
1674 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1675 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1677 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xIndexAccess
->getCount());
1678 CPPUNIT_ASSERT_EQUAL(1, getPages());
1680 //Use selectAll 3 times in a row
1681 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1682 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1683 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1685 dispatchCommand(mxComponent
, ".uno:Delete", {});
1686 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
1688 //Without the fix in place, it would have crashed here
1689 dispatchCommand(mxComponent
, ".uno:Undo", {});
1690 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xIndexAccess
->getCount());
1691 CPPUNIT_ASSERT_EQUAL(1, getPages());
1694 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf126504
)
1696 createSwDoc("tdf126504.odt");
1698 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1699 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1701 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1702 CPPUNIT_ASSERT_EQUAL(1, getPages());
1704 //Use selectAll 2 times in a row
1705 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1706 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1707 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1709 dispatchCommand(mxComponent
, ".uno:Copy", {});
1711 dispatchCommand(mxComponent
, ".uno:GoToEndOfPage", {});
1713 dispatchCommand(mxComponent
, ".uno:Paste", {});
1715 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xIndexAccess
->getCount());
1716 CPPUNIT_ASSERT_EQUAL(1, getPages());
1718 dispatchCommand(mxComponent
, ".uno:Undo", {});
1720 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1721 CPPUNIT_ASSERT_EQUAL(1, getPages());
1723 dispatchCommand(mxComponent
, ".uno:Redo", {});
1725 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xIndexAccess
->getCount());
1726 CPPUNIT_ASSERT_EQUAL(1, getPages());
1728 //Without the fix in place, it would have crashed here
1729 dispatchCommand(mxComponent
, ".uno:Undo", {});
1731 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1732 CPPUNIT_ASSERT_EQUAL(1, getPages());
1735 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf133982
)
1737 createSwDoc("tdf133982.docx");
1739 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1740 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1742 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1744 //Use selectAll 3 times in a row
1745 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1746 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1747 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1748 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1750 //Without the fix in place, it would have crashed here
1751 dispatchCommand(mxComponent
, ".uno:Cut", {});
1752 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
1754 dispatchCommand(mxComponent
, ".uno:Paste", {});
1755 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1758 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf134253
)
1760 createSwDoc("tdf134253.odt");
1762 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1763 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1765 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1766 CPPUNIT_ASSERT_EQUAL(6, getPages());
1768 //Use selectAll 3 times in a row
1769 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1770 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1771 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
1773 dispatchCommand(mxComponent
, ".uno:Copy", {});
1774 dispatchCommand(mxComponent
, ".uno:Paste", {});
1776 //Without the fix in place, it would have crashed here
1777 dispatchCommand(mxComponent
, ".uno:Undo", {});
1779 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1780 CPPUNIT_ASSERT_EQUAL(6, getPages());
1783 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testNotebookBar
)
1787 //tdf#154282: Without the fix in place, this test would have crashed
1788 dispatchCommand(mxComponent
, ".uno:ToolbarMode?Mode:string=notebookbar.ui", {});
1789 dispatchCommand(mxComponent
, ".uno:ToolbarMode?Mode:string=Single", {});
1790 dispatchCommand(mxComponent
, ".uno:ToolbarMode?Mode:string=Sidebar", {});
1791 dispatchCommand(mxComponent
, ".uno:ToolbarMode?Mode:string=notebookbar_compact.ui", {});
1792 dispatchCommand(mxComponent
, ".uno:ToolbarMode?Mode:string=notebookbar_groupedbar_compact.ui",
1794 dispatchCommand(mxComponent
, ".uno:ToolbarMode?Mode:string=notebookbar_single.ui", {});
1795 dispatchCommand(mxComponent
, ".uno:ToolbarMode?Mode:string=Default", {});
1798 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, TestAsCharTextBox
)
1801 // tdf#138598 Replace vertical alignment of As_char textboxes in footer
1802 // tdf#140158 Remove horizontal positioning of As_char textboxes, because
1803 // the anchor moving does the same for it.
1805 createSwDoc("AsCharTxBxTest.docx");
1806 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
1808 // Add 3x tab to the doc
1809 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
1810 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
1811 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
1812 Scheduler::ProcessEventsToIdle();
1814 auto pExportDump
= parseLayoutDump();
1815 CPPUNIT_ASSERT(pExportDump
);
1817 // Check if the texbox fallen apart due to the tabs
1818 const double nLeftSideOfShape1
1819 = getXPath(pExportDump
, "/root/page/body/txt/anchored/SwAnchoredDrawObject/bounds", "left")
1821 const double nLeftSideOfTxBx1
1822 = getXPath(pExportDump
, "/root/page/body/txt/anchored/fly/infos/bounds", "left").toDouble();
1824 CPPUNIT_ASSERT(nLeftSideOfShape1
< nLeftSideOfTxBx1
);
1826 // Another test is for the tdf#138598: Check footer textbox
1827 const double nLeftSideOfShape2
1828 = getXPath(pExportDump
, "/root/page[2]/footer/txt/anchored/SwAnchoredDrawObject/bounds",
1831 const double nLeftSideOfTxBx2
1832 = getXPath(pExportDump
, "/root/page[2]/footer/txt/anchored/fly/infos/bounds", "left")
1835 CPPUNIT_ASSERT(nLeftSideOfShape2
< nLeftSideOfTxBx2
);
1837 const double nTopSideOfShape2
1838 = getXPath(pExportDump
, "/root/page[2]/footer/txt/anchored/SwAnchoredDrawObject/bounds",
1841 const double nTopSideOfTxBx2
1842 = getXPath(pExportDump
, "/root/page[2]/footer/txt/anchored/fly/infos/bounds", "top")
1845 CPPUNIT_ASSERT(nTopSideOfShape2
< nTopSideOfTxBx2
);
1846 // Without the fix in place the two texboxes has been fallen apart, and asserts will broken.
1849 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf155028
)
1851 createSwDoc("tdf155028.odt");
1852 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
1854 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1855 uno::Reference
<drawing::XShapes
> xGroupShape(getShape(1), uno::UNO_QUERY
);
1856 CPPUNIT_ASSERT_EQUAL(sal_Int32(10), xGroupShape
->getCount());
1859 dispatchCommand(mxComponent
, ".uno:EnterGroup", {});
1861 // Select a shape in the group
1862 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
1863 Scheduler::ProcessEventsToIdle();
1865 dispatchCommand(mxComponent
, ".uno:Copy", {});
1867 // Without the fix in place, this test would have crashed
1868 dispatchCommand(mxComponent
, ".uno:Paste", {});
1870 CPPUNIT_ASSERT_EQUAL(sal_Int32(11), xGroupShape
->getCount());
1872 dispatchCommand(mxComponent
, ".uno:Undo", {});
1874 CPPUNIT_ASSERT_EQUAL(sal_Int32(10), xGroupShape
->getCount());
1877 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf135581
)
1879 createSwDoc("tdf135581.odt");
1882 dispatchCommand(mxComponent
, ".uno:SetAnchorAtChar", {}); // this is "to char"
1884 // Without the fix, the image was moving when the anchor changed, letting text flow back.
1885 CPPUNIT_ASSERT_EQUAL(2, getPages());
1888 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf140975
)
1891 createSwDoc("tdf140975.docx");
1893 // Set the Anchor of the shape to As_Char
1895 dispatchCommand(mxComponent
, ".uno:SetAnchorToChar", {});
1897 // Get the layout of the textbox
1898 auto pExportDump
= parseLayoutDump();
1899 CPPUNIT_ASSERT(pExportDump
);
1901 const sal_Int32 nShpTop
1902 = getXPath(pExportDump
, "/root/page/body/txt[4]/anchored/SwAnchoredDrawObject/bounds",
1905 const sal_Int32 nFrmTop
1906 = getXPath(pExportDump
, "/root/page/body/txt[4]/anchored/fly/infos/bounds", "top")
1909 // Without the fix in place, the frame has less value for Top than
1910 // the shape. This means the frame is outside from the shape.
1911 CPPUNIT_ASSERT_GREATER(nShpTop
, nFrmTop
);
1914 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf76636
)
1916 createSwDoc("tdf76636.doc");
1917 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
1919 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1920 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1922 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1923 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1924 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
1925 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable
->getColumns()->getCount());
1928 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DOWN
);
1929 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DOWN
);
1930 Scheduler::ProcessEventsToIdle();
1932 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
1933 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
1934 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
1935 Scheduler::ProcessEventsToIdle();
1937 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_LEFT
| KEY_SHIFT
);
1938 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_LEFT
| KEY_SHIFT
);
1939 Scheduler::ProcessEventsToIdle();
1941 dispatchCommand(mxComponent
, ".uno:MergeCells", {});
1942 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1943 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
1944 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTextTable
->getColumns()->getCount());
1946 dispatchCommand(mxComponent
, ".uno:Undo", {});
1947 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1948 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
1949 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable
->getColumns()->getCount());
1952 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf76636_2
)
1954 createSwDoc("tdf76636.doc");
1955 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
1957 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1958 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1960 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1961 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1962 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
1963 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable
->getColumns()->getCount());
1965 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DOWN
);
1966 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DOWN
);
1967 Scheduler::ProcessEventsToIdle();
1969 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
1970 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
1971 Scheduler::ProcessEventsToIdle();
1973 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RIGHT
| KEY_SHIFT
);
1974 Scheduler::ProcessEventsToIdle();
1976 dispatchCommand(mxComponent
, ".uno:MergeCells", {});
1977 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1978 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
1979 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTextTable
->getColumns()->getCount());
1981 dispatchCommand(mxComponent
, ".uno:Undo", {});
1982 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1983 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
1984 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable
->getColumns()->getCount());
1987 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf140828
)
1989 createSwDoc("tdf140828.docx");
1991 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1992 uno::Reference
<drawing::XShape
> xShp
= getShape(1);
1993 CPPUNIT_ASSERT(xShp
);
1995 uno::Reference
<beans::XPropertySet
> ShpProps(xShp
, uno::UNO_QUERY_THROW
);
1998 dispatchCommand(mxComponent
, ".uno:SetAnchorAtChar", {});
2000 CPPUNIT_ASSERT_EQUAL(
2001 text::TextContentAnchorType::TextContentAnchorType_AT_CHARACTER
,
2002 ShpProps
->getPropertyValue("AnchorType").get
<text::TextContentAnchorType
>());
2004 uno::Reference
<text::XTextFrame
> xTxBx(SwTextBoxHelper::getUnoTextFrame(xShp
));
2005 CPPUNIT_ASSERT(xTxBx
);
2007 uno::Reference
<beans::XPropertySet
> TxBxProps(xTxBx
, uno::UNO_QUERY_THROW
);
2008 CPPUNIT_ASSERT_EQUAL(OUString("top left image"), xTxBx
->getText()->getString());
2010 CPPUNIT_ASSERT_MESSAGE("Bad Relative Orientation and Position!",
2011 TxBxProps
->getPropertyValue("HoriOrientRelation").get
<sal_Int16
>()
2012 != text::RelOrientation::CHAR
);
2015 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132725
)
2017 createSwDoc("tdf132725.odt");
2019 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2020 CPPUNIT_ASSERT_EQUAL(OUString("AA"), getParagraph(1)->getString());
2022 dispatchCommand(mxComponent
, ".uno:GoToEndOfPara", {});
2024 dispatchCommand(mxComponent
, ".uno:SwBackspace", {});
2025 dispatchCommand(mxComponent
, ".uno:SwBackspace", {});
2027 // tdf#137587 fly is no longer deleted by backspace
2028 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2029 CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString());
2031 dispatchCommand(mxComponent
, ".uno:Undo", {});
2032 dispatchCommand(mxComponent
, ".uno:Undo", {});
2034 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2035 CPPUNIT_ASSERT_EQUAL(OUString("AA"), getParagraph(1)->getString());
2037 dispatchCommand(mxComponent
, ".uno:Redo", {});
2038 dispatchCommand(mxComponent
, ".uno:Redo", {});
2040 // tdf#137587 fly is no longer deleted by backspace
2041 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2042 CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString());
2044 //Without the fix in place, it would crash here
2045 dispatchCommand(mxComponent
, ".uno:Undo", {});
2047 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2048 CPPUNIT_ASSERT_EQUAL(OUString("A"), getParagraph(1)->getString());
2051 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf126340
)
2053 createSwDoc("tdf126340.odt");
2055 dispatchCommand(mxComponent
, ".uno:GoDown", {});
2056 // without the fix, it crashes
2057 dispatchCommand(mxComponent
, ".uno:Delete", {});
2058 CPPUNIT_ASSERT_EQUAL(OUString("foo"), getParagraph(1)->getString());
2059 dispatchCommand(mxComponent
, ".uno:Undo", {});
2060 CPPUNIT_ASSERT_EQUAL(OUString("foo"), getParagraph(1)->getString());
2063 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf124397
)
2065 createSwDoc("tdf124397.docx");
2067 uno::Reference
<text::XTextFramesSupplier
> xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
2068 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextFramesSupplier
->getTextFrames(),
2071 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2073 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
2074 dispatchCommand(mxComponent
, ".uno:Delete", {});
2075 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
2076 // Without the fix in place, it would crash here
2077 dispatchCommand(mxComponent
, ".uno:Undo", {});
2078 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2081 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf108124
)
2083 createSwDoc("tdf108124.odt");
2085 uno::Reference
<text::XTextGraphicObjectsSupplier
> xTextGraphicObjectsSupplier(mxComponent
,
2087 uno::Reference
<container::XIndexAccess
> xIndexAccess(
2088 xTextGraphicObjectsSupplier
->getGraphicObjects(), uno::UNO_QUERY
);
2090 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
2092 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
2094 dispatchCommand(mxComponent
, ".uno:Copy", {});
2096 dispatchCommand(mxComponent
, ".uno:Paste", {});
2098 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
2100 uno::Reference
<drawing::XShape
> xOldShape1(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2101 uno::Reference
<drawing::XShape
> xOldShape2(xIndexAccess
->getByIndex(1), uno::UNO_QUERY
);
2103 dispatchCommand(mxComponent
, ".uno:Undo", {});
2105 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
2107 uno::Reference
<drawing::XShape
> xNewShape1(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2108 uno::Reference
<drawing::XShape
> xNewShape2(xIndexAccess
->getByIndex(1), uno::UNO_QUERY
);
2110 // there should be 2 different objects now but they have the same names,
2111 // so rely on the object identity for testing...
2112 CPPUNIT_ASSERT(xOldShape1
.get() != xNewShape1
.get());
2113 CPPUNIT_ASSERT(xOldShape1
.get() != xNewShape2
.get());
2114 CPPUNIT_ASSERT(xOldShape2
.get() != xNewShape1
.get());
2115 CPPUNIT_ASSERT(xOldShape2
.get() != xNewShape2
.get());
2117 // Without the fix in place, this test would have crashed here
2118 dispatchCommand(mxComponent
, ".uno:Redo", {});
2120 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
2123 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf134021
)
2125 createSwDoc("tdf134021.docx");
2127 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2128 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2130 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2131 CPPUNIT_ASSERT_EQUAL(12, getPages());
2133 dispatchCommand(mxComponent
, ".uno:JumpToNextTable", {});
2135 dispatchCommand(mxComponent
, ".uno:DeleteTable", {});
2136 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
2137 CPPUNIT_ASSERT_EQUAL(1, getPages());
2139 // Without the fix in place, it would have crashed here
2140 dispatchCommand(mxComponent
, ".uno:Undo", {});
2142 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2143 CPPUNIT_ASSERT_EQUAL(12, getPages());
2146 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf136778
)
2148 createSwDoc("tdf136778.docx");
2150 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2151 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2153 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2154 CPPUNIT_ASSERT_EQUAL(1, getPages());
2156 dispatchCommand(mxComponent
, ".uno:JumpToNextTable", {});
2158 dispatchCommand(mxComponent
, ".uno:DeleteTable", {});
2159 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
2160 CPPUNIT_ASSERT_EQUAL(1, getPages());
2162 // Without the fix in place, it would have crashed here
2163 dispatchCommand(mxComponent
, ".uno:Undo", {});
2165 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2166 CPPUNIT_ASSERT_EQUAL(1, getPages());
2169 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf123285
)
2171 createSwDoc("tdf123285.odt");
2172 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
2174 CPPUNIT_ASSERT_EQUAL(true,
2175 getParagraph(1)->getString().endsWith(
2176 ". Here is a short sentence demonstrating this very peculiar bug"
2177 ". Here is a short sentence demonstrating this very peculiar bug."));
2179 dispatchCommand(mxComponent
, ".uno:GoToEndOfPage", {});
2181 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
2182 Scheduler::ProcessEventsToIdle();
2184 // Without the fix in place, the last "sentence" would have been changed to " entence"
2185 CPPUNIT_ASSERT_EQUAL(true,
2186 getParagraph(1)->getString().endsWith(
2187 ". Here is a short sentence demonstrating this very peculiar bug"
2188 ". Here is a short sentence demonstrating this very peculiar bug."));
2191 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf130746
)
2193 createSwDoc("tdf130746.odt");
2194 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
2196 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2197 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2199 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2201 dispatchCommand(mxComponent
, ".uno:JumpToNextTable", {});
2203 uno::Reference
<frame::XModel
> xModel(mxComponent
, uno::UNO_QUERY
);
2204 uno::Reference
<text::XTextViewCursorSupplier
> xTextViewCursorSupplier(
2205 xModel
->getCurrentController(), uno::UNO_QUERY
);
2206 uno::Reference
<text::XPageCursor
> xCursor(xTextViewCursorSupplier
->getViewCursor(),
2208 CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xCursor
->getPage());
2210 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
2211 Scheduler::ProcessEventsToIdle();
2213 CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor
->getPage());
2215 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_UP
| KEY_MOD2
);
2216 Scheduler::ProcessEventsToIdle();
2218 CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor
->getPage());
2220 dispatchCommand(mxComponent
, ".uno:Undo", {});
2222 CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xCursor
->getPage());
2223 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2226 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf129805
)
2228 createSwDoc("tdf129805.docx");
2230 CPPUNIT_ASSERT_EQUAL(OUString("x"), getParagraph(1)->getString());
2231 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
2233 // without the fix in place, it would crash here
2234 dispatchCommand(mxComponent
, ".uno:Cut", {});
2235 CPPUNIT_ASSERT_EQUAL(OUString(""), getParagraph(1)->getString());
2237 dispatchCommand(mxComponent
, ".uno:Undo", {});
2238 CPPUNIT_ASSERT_EQUAL(OUString("x"), getParagraph(1)->getString());
2241 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf130685
)
2243 createSwDoc("tdf130685.odt");
2245 CPPUNIT_ASSERT_EQUAL(2, getPages());
2246 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
2248 dispatchCommand(mxComponent
, ".uno:Cut", {});
2250 CPPUNIT_ASSERT_EQUAL(1, getPages());
2252 dispatchCommand(mxComponent
, ".uno:Paste", {});
2253 dispatchCommand(mxComponent
, ".uno:Paste", {});
2255 // Without fix in place, this test would have failed with:
2258 CPPUNIT_ASSERT_EQUAL(2, getPages());
2260 dispatchCommand(mxComponent
, ".uno:Undo", {});
2261 dispatchCommand(mxComponent
, ".uno:Undo", {});
2262 CPPUNIT_ASSERT_EQUAL(1, getPages());
2264 dispatchCommand(mxComponent
, ".uno:Undo", {});
2265 CPPUNIT_ASSERT_EQUAL(2, getPages());
2268 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132944
)
2270 createSwDoc("tdf132944.odt");
2272 CPPUNIT_ASSERT_EQUAL(1, getPages());
2274 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
2275 dispatchCommand(mxComponent
, ".uno:Delete", {});
2276 CPPUNIT_ASSERT_EQUAL(1, getPages());
2278 dispatchCommand(mxComponent
, ".uno:Undo", {});
2280 // Without the fix in place, the document would have had 2 pages
2281 CPPUNIT_ASSERT_EQUAL(1, getPages());
2284 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf104649
)
2286 createSwDoc("tdf104649.docx");
2288 CPPUNIT_ASSERT_EQUAL(OUString("Test"), getParagraph(1)->getString());
2290 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
2291 dispatchCommand(mxComponent
, ".uno:Delete", {});
2292 CPPUNIT_ASSERT_EQUAL(1, getPages());
2294 // Without the fix in place, this test would have crashed here
2295 dispatchCommand(mxComponent
, ".uno:Undo", {});
2297 CPPUNIT_ASSERT_EQUAL(OUString("Test"), getParagraph(1)->getString());
2300 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf134931
)
2302 createSwDoc("tdf134931.odt");
2304 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2305 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2307 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2308 CPPUNIT_ASSERT_EQUAL(1, getPages());
2310 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
2312 dispatchCommand(mxComponent
, ".uno:Copy", {});
2314 dispatchCommand(mxComponent
, ".uno:GoDown", {});
2316 for (sal_Int32 i
= 0; i
< 10; ++i
)
2318 dispatchCommand(mxComponent
, ".uno:Paste", {});
2321 CPPUNIT_ASSERT_EQUAL(sal_Int32(11), xIndexAccess
->getCount());
2323 // Without the fix in place, this test would have failed with:
2326 // Because the tables are pasted but not displayed
2328 CPPUNIT_ASSERT_EQUAL(4, getPages());
2331 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf130680
)
2333 createSwDoc("tdf130680.odt");
2335 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2336 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2338 CPPUNIT_ASSERT_EQUAL(sal_Int32(23), xIndexAccess
->getCount());
2340 dispatchCommand(mxComponent
, ".uno:SelectAll", {});
2342 rtl::Reference
<SwDoc
> xClpDoc(new SwDoc());
2343 xClpDoc
->SetClipBoard(true);
2345 // without the fix, it crashes
2346 dispatchCommand(mxComponent
, ".uno:Cut", {});
2348 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
2350 dispatchCommand(mxComponent
, ".uno:Paste", {});
2351 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2354 dispatchCommand(mxComponent
, ".uno:Undo", {});
2355 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
2357 dispatchCommand(mxComponent
, ".uno:Undo", {});
2358 CPPUNIT_ASSERT_EQUAL(sal_Int32(23), xIndexAccess
->getCount());
2361 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf150457
)
2364 SwXTextDocument
* pTextDoc
= dynamic_cast<SwXTextDocument
*>(mxComponent
.get());
2366 emulateTyping(*pTextDoc
, u
"a");
2367 dispatchCommand(mxComponent
, ".uno:InsertFootnote", {});
2368 emulateTyping(*pTextDoc
, u
"abc");
2370 auto xFootnotes
= pTextDoc
->getFootnotes();
2371 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(1), xFootnotes
->getCount());
2372 auto xParagraph
= uno::Reference
<text::XTextRange
>(xFootnotes
->getByIndex(0), uno::UNO_QUERY
);
2373 CPPUNIT_ASSERT_EQUAL(OUString("abc"), xParagraph
->getString());
2375 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_PAGEUP
);
2376 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
2377 emulateTyping(*pTextDoc
, u
"d");
2379 dispatchCommand(mxComponent
, ".uno:InsertFootnote", {});
2380 emulateTyping(*pTextDoc
, u
"def");
2382 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(2), xFootnotes
->getCount());
2383 xParagraph
= uno::Reference
<text::XTextRange
>(xFootnotes
->getByIndex(1), uno::UNO_QUERY
);
2384 CPPUNIT_ASSERT_EQUAL(OUString("def"), xParagraph
->getString());
2386 // This key sequence deletes a footnote and its number (without the fix applied)
2387 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_UP
);
2388 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_HOME
);
2389 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_SHIFT
| KEY_DOWN
);
2390 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DELETE
);
2392 // Page up moves the cursor from the footnote area to the main text, then
2393 // doing select all and pressing delete removes all the text and footnote references,
2394 // thus removing all the footnotes
2395 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_PAGEUP
);
2396 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, awt::Key::SELECT_ALL
);
2397 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DELETE
);
2399 // Without having fix in place, segfault happens after running next line
2400 Scheduler::ProcessEventsToIdle();
2402 // Without the fix, the above action should have already created a crash,
2403 // but here we also check to make sure that the number of footnotes are
2404 // exactly zero, as expected
2405 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0), xFootnotes
->getCount());
2408 CPPUNIT_PLUGIN_IMPLEMENT();
2410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */