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/awt/FontWeight.hpp>
14 #include <com/sun/star/document/XDocumentInsertable.hpp>
15 #include <com/sun/star/table/TableBorder2.hpp>
16 #include <com/sun/star/text/XDocumentIndex.hpp>
17 #include <com/sun/star/text/XTextFrame.hpp>
18 #include <com/sun/star/text/XTextTable.hpp>
19 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
20 #include <com/sun/star/text/XPageCursor.hpp>
21 #include <comphelper/propertysequence.hxx>
22 #include <comphelper/seqstream.hxx>
23 #include <swdtflvr.hxx>
24 #include <o3tl/string_view.hxx>
28 #include <unotxdoc.hxx>
31 #include <IDocumentFieldsAccess.hxx>
32 #include <IDocumentRedlineAccess.hxx>
33 #include <fmtinfmt.hxx>
35 /// Third set of tests asserting the behavior of Writer user interface shells.
36 class SwUiWriterTest3
: public SwModelTestBase
40 : SwModelTestBase(u
"/sw/qa/extras/uiwriter/data/"_ustr
)
45 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testPlaceholderHTMLPaste
)
50 SwWrtShell
* const pWrtShell
= getSwDocShell()->GetWrtShell();
51 pWrtShell
->Insert(u
"AAA"_ustr
);
52 pWrtShell
->SplitNode();
53 pWrtShell
->Insert(u
"BBB"_ustr
);
54 pWrtShell
->SplitNode();
55 pWrtShell
->Insert(u
"CCC"_ustr
);
57 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
58 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
61 createSwDoc("placeholder-bold.fodt");
63 // select placeholder field
64 SwWrtShell
* const pWrtShell
= getSwDocShell()->GetWrtShell();
65 pWrtShell
->Right(SwCursorSkipMode::Chars
, /*bSelect=*/false, 5, /*bBasicCall=*/false);
66 pWrtShell
->Right(SwCursorSkipMode::Chars
, /*bSelect=*/true, 1, /*bBasicCall=*/false);
68 // Paste special as HTML
69 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
70 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::HTML
)) } });
72 dispatchCommand(mxComponent
, u
".uno:ClipboardFormatItems"_ustr
, aPropertyValues
);
74 CPPUNIT_ASSERT_EQUAL(int(4), getParagraphs());
77 awt::FontWeight::NORMAL
,
78 getProperty
<float>(getRun(getParagraph(1), 1, u
"Test "_ustr
), u
"CharWeight"_ustr
));
80 awt::FontWeight::BOLD
,
81 getProperty
<float>(getRun(getParagraph(1), 2, u
"AAA"_ustr
), u
"CharWeight"_ustr
));
82 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD
,
83 getProperty
<float>(getParagraph(2), u
"CharWeight"_ustr
));
84 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD
,
85 getProperty
<float>(getParagraph(3), u
"CharWeight"_ustr
));
87 awt::FontWeight::NORMAL
,
88 getProperty
<float>(getRun(getParagraph(4), 1, u
" test"_ustr
), u
"CharWeight"_ustr
));
91 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testPlaceholderHTMLInsert
)
93 createSwDoc("placeholder-bold-cs.fodt");
95 // select placeholder field
96 uno::Reference
<text::XTextDocument
> xTextDocument(mxComponent
, uno::UNO_QUERY
);
97 uno::Reference
<text::XTextCursor
> xCursor
{ xTextDocument
->getText()->createTextCursor() };
98 xCursor
->gotoStart(false);
99 xCursor
->goRight(5, false);
100 xCursor
->goRight(1, true);
102 sal_Int8
const html
[] = "<meta http-equiv=\"content-type\" content=\"text/html; "
103 "charset=utf-8\"><p>AAA</p><p>BBB</p><p>CCC</p>";
104 uno::Reference
<io::XInputStream
> xStream
{ new comphelper::MemoryInputStream
{ html
,
108 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
109 { { "InputStream", uno::Any(xStream
) },
110 { "Hidden", uno::Any(true) },
111 { "FilterName", uno::Any(u
"HTML (StarWriter)"_ustr
) } });
113 uno::Reference
<document::XDocumentInsertable
> xDocInsert
{ xCursor
, uno::UNO_QUERY
};
114 xDocInsert
->insertDocumentFromURL("private:stream", aPropertyValues
);
116 CPPUNIT_ASSERT_EQUAL(int(4), getParagraphs());
118 CPPUNIT_ASSERT_EQUAL(
119 awt::FontWeight::NORMAL
,
120 getProperty
<float>(getRun(getParagraph(1), 1, u
"Test "_ustr
), u
"CharWeight"_ustr
));
121 CPPUNIT_ASSERT_EQUAL(
122 awt::FontWeight::BOLD
,
123 getProperty
<float>(getRun(getParagraph(1), 2, u
"AAA"_ustr
), u
"CharWeight"_ustr
));
124 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD
,
125 getProperty
<float>(getParagraph(2), u
"CharWeight"_ustr
));
126 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD
,
127 getProperty
<float>(getParagraph(3), u
"CharWeight"_ustr
));
128 CPPUNIT_ASSERT_EQUAL(
129 awt::FontWeight::NORMAL
,
130 getProperty
<float>(getRun(getParagraph(4), 1, u
" test"_ustr
), u
"CharWeight"_ustr
));
133 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf151974
)
135 createSwDoc("tdf151974.odt");
137 CPPUNIT_ASSERT_EQUAL(int(8), getParagraphs());
139 auto pLayout
= parseLayoutDump();
140 for (size_t i
= 1; i
< 9; ++i
)
142 OString
sPath("/root/page[1]/body/txt[" + OString::number(i
)
143 + "]/SwParaPortion/SwLineLayout");
144 assertXPathChildren(pLayout
, sPath
, 1);
147 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
148 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
149 dispatchCommand(mxComponent
, u
".uno:GoDown"_ustr
, {});
151 SwXTextDocument
* pTextDoc
= getSwTextDoc();
152 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
153 Scheduler::ProcessEventsToIdle();
155 // Paste special as RTF
156 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
157 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
159 dispatchCommand(mxComponent
, u
".uno:ClipboardFormatItems"_ustr
, aPropertyValues
);
161 CPPUNIT_ASSERT_EQUAL(int(16), getParagraphs());
163 pLayout
= parseLayoutDump();
164 for (size_t i
= 1; i
< 16; ++i
)
166 OString
sPath("/root/page[1]/body/txt[" + OString::number(i
)
167 + "]/SwParaPortion/SwLineLayout");
169 // Without the fix in place, this test would have failed with
172 // - In <>, XPath '/root/page[1]/body/txt[1]/SwParaPortion/SwLineLayout' number of child-nodes is incorrect
173 assertXPathChildren(pLayout
, sPath
, 1);
177 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf155685
)
179 createSwDoc("tdf155685.docx");
181 CPPUNIT_ASSERT_EQUAL(8, getShapes());
182 CPPUNIT_ASSERT_EQUAL(1, getPages());
184 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
186 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
188 CPPUNIT_ASSERT_EQUAL(0, getShapes());
189 CPPUNIT_ASSERT_EQUAL(1, getPages());
191 // Without the fix in place, this test would have crashed here
192 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
194 CPPUNIT_ASSERT_EQUAL(8, getShapes());
195 CPPUNIT_ASSERT_EQUAL(1, getPages());
198 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf157131
)
200 createSwDoc("tdf157131.docx");
202 CPPUNIT_ASSERT_EQUAL(9, getShapes());
203 CPPUNIT_ASSERT_EQUAL(6, getPages());
205 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
207 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
209 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
210 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
211 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
213 CPPUNIT_ASSERT_GREATER(9, getShapes());
214 CPPUNIT_ASSERT_GREATER(6, getPages());
216 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
217 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
219 // Without the fix in place, this test would have crashed here
220 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
222 CPPUNIT_ASSERT_EQUAL(9, getShapes());
223 CPPUNIT_ASSERT_EQUAL(6, getPages());
226 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf145731
)
228 createSwDoc("tdf145731.odt");
230 CPPUNIT_ASSERT_EQUAL(9, getShapes());
231 CPPUNIT_ASSERT_EQUAL(1, getPages());
233 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
235 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
237 CPPUNIT_ASSERT_EQUAL(0, getShapes());
238 CPPUNIT_ASSERT_EQUAL(1, getPages());
240 // Without the fix in place, this test would have crashed here
241 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
243 CPPUNIT_ASSERT_EQUAL(9, getShapes());
244 CPPUNIT_ASSERT_EQUAL(1, getPages());
247 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf147199
)
249 createSwDoc("tdf147199.docx");
251 CPPUNIT_ASSERT_EQUAL(7, getShapes());
253 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
255 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
257 CPPUNIT_ASSERT_EQUAL(0, getShapes());
259 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
261 CPPUNIT_ASSERT_EQUAL(7, getShapes());
263 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
265 CPPUNIT_ASSERT_EQUAL(14, getShapes());
267 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
269 CPPUNIT_ASSERT_EQUAL(7, getShapes());
271 // Without the fix in place, this test would have crashed here
272 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
274 CPPUNIT_ASSERT_EQUAL(0, getShapes());
276 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
278 CPPUNIT_ASSERT_EQUAL(7, getShapes());
281 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf139843
)
283 createSwDoc("tdf139843.odt");
285 int nPages
= getPages();
287 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
289 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
291 CPPUNIT_ASSERT_EQUAL(1, getPages());
293 // Without the fix in place, this test would have crashed here
294 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
296 CPPUNIT_ASSERT_EQUAL(nPages
, getPages());
299 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf143574
)
301 createSwDoc("tdf143574.odt");
303 CPPUNIT_ASSERT_EQUAL(1, getShapes());
304 uno::Reference
<drawing::XShapes
> xGroupShape(getShape(1), uno::UNO_QUERY
);
305 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xGroupShape
->getCount());
307 uno::Reference
<beans::XPropertySet
> xProperties(xGroupShape
->getByIndex(2), uno::UNO_QUERY
);
308 CPPUNIT_ASSERT_EQUAL(false, xProperties
->getPropertyValue(u
"TextBox"_ustr
).get
<bool>());
311 dispatchCommand(mxComponent
, u
".uno:EnterGroup"_ustr
, {});
313 // Select a shape in the group
314 SwXTextDocument
* pTextDoc
= getSwTextDoc();
315 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
316 Scheduler::ProcessEventsToIdle();
318 // Without the fix in place, this test would have crashed
319 dispatchCommand(mxComponent
, u
".uno:AddTextBox"_ustr
, {});
321 CPPUNIT_ASSERT_EQUAL(true, xProperties
->getPropertyValue(u
"TextBox"_ustr
).get
<bool>());
324 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf146848
)
326 // Reuse existing document
327 createSwDoc("tdf77014.odt");
329 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
331 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
333 uno::Reference
<text::XTextFieldsSupplier
> xTextFieldsSupplier(mxComponent
, uno::UNO_QUERY
);
334 uno::Reference
<container::XEnumerationAccess
> xFieldsAccess(
335 xTextFieldsSupplier
->getTextFields());
336 uno::Reference
<container::XEnumeration
> xFields(xFieldsAccess
->createEnumeration());
337 CPPUNIT_ASSERT(!xFields
->hasMoreElements());
339 // Without the fix in place, this test would have crashed here
340 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
342 xFields
= xFieldsAccess
->createEnumeration();
344 int nFieldsCount
= 0;
345 while (xFields
->hasMoreElements())
347 xFields
->nextElement();
350 CPPUNIT_ASSERT_EQUAL(4, nFieldsCount
);
353 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf149507
)
355 createSwDoc("tdf149507.docx");
357 CPPUNIT_ASSERT_EQUAL(1, getShapes());
358 CPPUNIT_ASSERT_EQUAL(1, getPages());
360 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
362 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
364 CPPUNIT_ASSERT_EQUAL(0, getShapes());
365 CPPUNIT_ASSERT_EQUAL(1, getPages());
367 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
369 CPPUNIT_ASSERT_EQUAL(1, getShapes());
370 CPPUNIT_ASSERT_EQUAL(1, getPages());
372 // Without the fix in place, this test would have crashed here
373 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
375 CPPUNIT_ASSERT_EQUAL(0, getShapes());
376 CPPUNIT_ASSERT_EQUAL(1, getPages());
378 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
380 CPPUNIT_ASSERT_EQUAL(1, getShapes());
381 CPPUNIT_ASSERT_EQUAL(1, getPages());
384 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf114973
)
386 createSwDoc("tdf114973.fodt");
388 SwWrtShell
* const pWrtShell
= getSwDocShell()->GetWrtShell();
389 pWrtShell
->SttEndDoc(true);
391 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
393 // bug: cursor jumped into header
394 CPPUNIT_ASSERT(!pWrtShell
->IsInHeaderFooter());
396 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
398 // check that hidden paragraphs at start and end are deleted
399 dispatchCommand(mxComponent
, u
".uno:Delete"_ustr
, {});
401 CPPUNIT_ASSERT_EQUAL(int(1), getParagraphs());
402 CPPUNIT_ASSERT_EQUAL(OUString(), getParagraph(1)->getString());
404 // check that hidden paragraphs at start and end are copied
405 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
407 CPPUNIT_ASSERT_EQUAL(int(3), getParagraphs());
408 CPPUNIT_ASSERT_EQUAL(u
"hidden first paragraph"_ustr
, getParagraph(1)->getString());
409 CPPUNIT_ASSERT_EQUAL(u
"Press CTRL+A for dispatching .uno:SelectAll. You see that "
410 "nothing will be selected. The cursor jumps to the header"_ustr
,
411 getParagraph(2)->getString());
412 CPPUNIT_ASSERT_EQUAL(u
"hidden last paragraph"_ustr
, getParagraph(3)->getString());
415 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf145321
)
417 createSwDoc("tdf145321.odt");
419 CPPUNIT_ASSERT_EQUAL(3, getShapes());
420 CPPUNIT_ASSERT_EQUAL(3, getPages());
422 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
424 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
426 CPPUNIT_ASSERT_EQUAL(0, getShapes());
427 CPPUNIT_ASSERT_EQUAL(1, getPages());
429 // Without the fix in place, this test would have crashed here
430 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
432 CPPUNIT_ASSERT_EQUAL(3, getShapes());
433 CPPUNIT_ASSERT_EQUAL(3, getPages());
436 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testVariableFieldTableRowSplitHeader
)
438 createSwDoc("variable-field-table-row-split-header.fodt");
439 SwDoc
* const pDoc
= getSwDoc();
442 Scheduler::ProcessEventsToIdle();
443 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
445 // the fields in cell are: variable-get variable-set variable-get
448 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
452 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
456 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
460 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
462 assertXPath(pXmlDoc
, "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
464 assertXPath(pXmlDoc
, "/root/page[1]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
466 // here the header had shown the wrong value
469 "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
473 "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
477 "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
479 assertXPath(pXmlDoc
, "/root/page[2]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
481 assertXPath(pXmlDoc
, "/root/page[2]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
486 "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
490 "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
494 "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
496 assertXPath(pXmlDoc
, "/root/page[3]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
498 assertXPath(pXmlDoc
, "/root/page[3]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
503 "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
507 "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
511 "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
513 assertXPath(pXmlDoc
, "/root/page[4]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
515 assertXPath(pXmlDoc
, "/root/page[4]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
518 assertXPath(pXmlDoc
, "/root/page[5]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
520 assertXPath(pXmlDoc
, "/root/page[5]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
523 // update and check again
524 pDoc
->getIDocumentFieldsAccess().UpdateFields(true);
525 Scheduler::ProcessEventsToIdle();
526 pXmlDoc
= parseLayoutDump();
528 // the fields in cell are: variable-get variable-set variable-get
531 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion",
535 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
539 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
543 "/root/page[1]/body/tab/row[1]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
545 assertXPath(pXmlDoc
, "/root/page[1]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
547 assertXPath(pXmlDoc
, "/root/page[1]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
549 // here the header had shown the wrong value
552 "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
556 "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
560 "/root/page[2]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
562 assertXPath(pXmlDoc
, "/root/page[2]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
564 assertXPath(pXmlDoc
, "/root/page[2]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
569 "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
573 "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
577 "/root/page[3]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
579 assertXPath(pXmlDoc
, "/root/page[3]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
581 assertXPath(pXmlDoc
, "/root/page[3]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
586 "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
590 "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[2]",
594 "/root/page[4]/body/tab/row[2]/cell[2]/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[3]",
596 assertXPath(pXmlDoc
, "/root/page[4]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
598 assertXPath(pXmlDoc
, "/root/page[4]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
601 assertXPath(pXmlDoc
, "/root/page[5]/header/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
603 assertXPath(pXmlDoc
, "/root/page[5]/footer/txt[1]/SwParaPortion/SwLineLayout/SwFieldPortion[1]",
607 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf147126
)
609 createSwDoc("tdf147126.docx");
611 xmlDocUniquePtr pLayoutXML1
= parseLayoutDump();
613 for (auto nFly
= 1; nFly
< 8; ++nFly
)
615 const auto nFlyLeft
= getXPath(pLayoutXML1
,
616 "/root/page/body/txt[2]/anchored/fly["
617 + OString::number(nFly
) + "]/infos/bounds",
620 const auto nFlyRight
= getXPath(pLayoutXML1
,
621 "/root/page/body/txt[2]/anchored/fly["
622 + OString::number(nFly
) + "]/infos/bounds",
625 const auto nFlyTop
= getXPath(pLayoutXML1
,
626 "/root/page/body/txt[2]/anchored/fly[" + OString::number(nFly
)
630 const auto nFlyBottom
= getXPath(pLayoutXML1
,
631 "/root/page/body/txt[2]/anchored/fly["
632 + OString::number(nFly
) + "]/infos/bounds",
636 const auto sDrawRect
= getXPath(
638 "/root/page/body/txt[2]/anchored/SwAnchoredDrawObject/SdrObjGroup/SdrObjList/SdrObject["
639 + OString::number(nFly
) + "]",
642 const auto nComaPos1
= sDrawRect
.indexOf(',', 0);
643 const auto nComaPos2
= sDrawRect
.indexOf(',', nComaPos1
+ 1);
644 const auto nComaPos3
= sDrawRect
.indexOf(',', nComaPos2
+ 1);
646 const auto nDraw1
= o3tl::toInt64(sDrawRect
.subView(0, nComaPos1
));
647 const auto nDraw2
= o3tl::toInt64(sDrawRect
.subView(nComaPos1
+ 1, nComaPos2
- nComaPos1
));
648 const auto nDraw3
= o3tl::toInt64(sDrawRect
.subView(nComaPos2
+ 1, nComaPos3
- nComaPos2
));
649 const auto nDraw4
= o3tl::toInt64(
650 sDrawRect
.subView(nComaPos3
+ 1, sDrawRect
.getLength() - nComaPos3
- 1));
652 CPPUNIT_ASSERT_GREATER(nDraw1
, nFlyLeft
);
653 CPPUNIT_ASSERT_GREATER(nDraw2
, nFlyTop
);
654 CPPUNIT_ASSERT_LESS(nDraw3
, nFlyRight
);
655 CPPUNIT_ASSERT_LESS(nDraw4
, nFlyBottom
);
658 SwXTextDocument
* pTextDoc
= getSwTextDoc();
659 for (auto nLineBreakCount
= 0; nLineBreakCount
< 4; ++nLineBreakCount
)
661 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
662 Scheduler::ProcessEventsToIdle();
664 for (auto nSpaceCount
= 0; nSpaceCount
< 10; ++nSpaceCount
)
666 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_SPACE
);
667 Scheduler::ProcessEventsToIdle();
670 xmlDocUniquePtr pLayoutXML2
= parseLayoutDump();
672 for (auto nFly
= 1; nFly
< 8; ++nFly
)
674 const auto nFlyLeft
= getXPath(pLayoutXML2
,
675 "/root/page/body/txt[6]/anchored/fly["
676 + OString::number(nFly
) + "]/infos/bounds",
679 const auto nFlyRight
= getXPath(pLayoutXML2
,
680 "/root/page/body/txt[6]/anchored/fly["
681 + OString::number(nFly
) + "]/infos/bounds",
684 const auto nFlyTop
= getXPath(pLayoutXML2
,
685 "/root/page/body/txt[6]/anchored/fly[" + OString::number(nFly
)
689 const auto nFlyBottom
= getXPath(pLayoutXML2
,
690 "/root/page/body/txt[6]/anchored/fly["
691 + OString::number(nFly
) + "]/infos/bounds",
695 const auto sDrawRect
= getXPath(
697 "/root/page/body/txt[6]/anchored/SwAnchoredDrawObject/SdrObjGroup/SdrObjList/SdrObject["
698 + OString::number(nFly
) + "]",
701 const auto nComaPos1
= sDrawRect
.indexOf(',', 0);
702 const auto nComaPos2
= sDrawRect
.indexOf(',', nComaPos1
+ 1);
703 const auto nComaPos3
= sDrawRect
.indexOf(',', nComaPos2
+ 1);
705 const auto nDraw1
= o3tl::toInt64(sDrawRect
.subView(0, nComaPos1
));
706 const auto nDraw2
= o3tl::toInt64(sDrawRect
.subView(nComaPos1
+ 1, nComaPos2
- nComaPos1
));
707 const auto nDraw3
= o3tl::toInt64(sDrawRect
.subView(nComaPos2
+ 1, nComaPos3
- nComaPos2
));
708 const auto nDraw4
= o3tl::toInt64(
709 sDrawRect
.subView(nComaPos3
+ 1, sDrawRect
.getLength() - nComaPos3
- 1));
711 CPPUNIT_ASSERT_GREATER(nDraw1
, nFlyLeft
);
712 CPPUNIT_ASSERT_GREATER(nDraw2
, nFlyTop
);
713 CPPUNIT_ASSERT_LESS(nDraw3
, nFlyRight
);
714 CPPUNIT_ASSERT_LESS(nDraw4
, nFlyBottom
);
718 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf148868
)
720 createSwDoc("tdf148868.odt");
721 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
723 CPPUNIT_ASSERT_EQUAL(1, getShapes());
724 CPPUNIT_ASSERT_EQUAL(1, getPages());
726 pWrtShell
->EndPg(/*bSelect=*/false);
727 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/true, 5, /*bBasicCall=*/false);
728 pWrtShell
->Insert(u
"X"_ustr
);
730 // Without the fix in place, this test would have failed with
733 CPPUNIT_ASSERT_EQUAL(1, getShapes());
734 CPPUNIT_ASSERT_EQUAL(1, getPages());
737 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf129382
)
739 createSwDoc("tdf129382.docx");
741 CPPUNIT_ASSERT_EQUAL(8, getShapes());
742 CPPUNIT_ASSERT_EQUAL(2, getPages());
744 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
746 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
748 CPPUNIT_ASSERT_EQUAL(3, getShapes());
749 CPPUNIT_ASSERT_EQUAL(1, getPages());
751 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
753 CPPUNIT_ASSERT_EQUAL(8, getShapes());
754 CPPUNIT_ASSERT_EQUAL(2, getPages());
755 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
756 CPPUNIT_ASSERT_EQUAL(3, getShapes());
757 CPPUNIT_ASSERT_EQUAL(1, getPages());
759 // without the fix, it crashes
760 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
761 CPPUNIT_ASSERT_EQUAL(8, getShapes());
764 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf135662
)
766 createSwDoc("tdf135662.odt");
768 CPPUNIT_ASSERT_EQUAL(2, getShapes());
770 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
772 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
774 CPPUNIT_ASSERT_EQUAL(0, getShapes());
776 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
778 // Without the fix in place, this test would have failed with
781 CPPUNIT_ASSERT_EQUAL(2, getShapes());
784 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf134227
)
786 createSwDoc("tdf134227.docx");
788 CPPUNIT_ASSERT_EQUAL(4, getShapes());
790 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
791 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
793 // Without the fix in place, it would have crashed here
794 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
796 CPPUNIT_ASSERT_EQUAL(0, getShapes());
798 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
800 CPPUNIT_ASSERT_EQUAL(4, getShapes());
802 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
803 CPPUNIT_ASSERT_EQUAL(0, getShapes());
805 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
806 CPPUNIT_ASSERT_EQUAL(4, getShapes());
809 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf139638
)
811 createSwDoc("tdf139638.odt");
813 uno::Reference
<text::XDocumentIndexesSupplier
> xIndexSupplier(mxComponent
, uno::UNO_QUERY
);
814 uno::Reference
<container::XIndexAccess
> xIndexes
= xIndexSupplier
->getDocumentIndexes();
815 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexes
->getCount());
816 uno::Reference
<text::XDocumentIndex
> xTOCIndex(xIndexes
->getByIndex(0), uno::UNO_QUERY
);
818 // Without the fix in place, this test would have crashed
822 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf114773
)
824 createSwDoc("tdf114773.odt");
826 uno::Reference
<text::XDocumentIndexesSupplier
> xIndexSupplier(mxComponent
, uno::UNO_QUERY
);
827 uno::Reference
<container::XIndexAccess
> xIndexes
= xIndexSupplier
->getDocumentIndexes();
828 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexes
->getCount());
829 uno::Reference
<text::XDocumentIndex
> xTOCIndex(xIndexes
->getByIndex(0), uno::UNO_QUERY
);
832 uno::Reference
<text::XTextRange
> xTextRange
= xTOCIndex
->getAnchor();
833 uno::Reference
<text::XText
> xText
= xTextRange
->getText();
834 uno::Reference
<text::XTextCursor
> xTextCursor
= xText
->createTextCursor();
835 xTextCursor
->gotoRange(xTextRange
->getStart(), false);
836 xTextCursor
->gotoRange(xTextRange
->getEnd(), true);
837 OUString
aIndexString(convertLineEnd(xTextCursor
->getString(), LineEnd::LINEEND_LF
));
839 // Without the fix in place, this test would have failed with
840 // - Expected: 2 Heading Level 1 2-1
841 // - Actual : 2 Heading Level 1 2 -1
842 CPPUNIT_ASSERT_EQUAL(u
"Full ToC\n"
843 "2 Heading Level 1\t2-1\n"
844 "2.1 Heading Level 2\t2-2\n"
845 "2.1.1 Heading Level 3\t2-2\n"
846 "2.1.1.1 Heading Level 4\t2-2"_ustr
,
850 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf104315
)
852 createSwDoc("tdf104315.odt");
854 uno::Reference
<text::XDocumentIndexesSupplier
> xIndexSupplier(mxComponent
, uno::UNO_QUERY
);
855 uno::Reference
<container::XIndexAccess
> xIndexes
= xIndexSupplier
->getDocumentIndexes();
856 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexes
->getCount());
857 uno::Reference
<text::XDocumentIndex
> xTOCIndex(xIndexes
->getByIndex(0), uno::UNO_QUERY
);
860 uno::Reference
<text::XTextRange
> xTextRange
= xTOCIndex
->getAnchor();
861 uno::Reference
<text::XText
> xText
= xTextRange
->getText();
862 uno::Reference
<text::XTextCursor
> xTextCursor
= xText
->createTextCursor();
863 xTextCursor
->gotoRange(xTextRange
->getStart(), false);
864 xTextCursor
->gotoRange(xTextRange
->getEnd(), true);
865 OUString
aIndexString(convertLineEnd(xTextCursor
->getString(), LineEnd::LINEEND_LF
));
867 // Without the fix in place, this test would have failed with
868 // - Expected: This is a headlinex 1
869 // - Actual : This is a headlinx 1
870 CPPUNIT_ASSERT_EQUAL(u
"Table of contents\n"
871 "This is a headlinex\t1\n"
872 "This is another headlinex\t1"_ustr
,
876 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf135412
)
878 createSwDoc("tdf135412.docx");
880 CPPUNIT_ASSERT_EQUAL(4, getShapes());
881 uno::Reference
<text::XTextRange
> xShape(getShape(1), uno::UNO_QUERY
);
882 CPPUNIT_ASSERT_EQUAL(u
"X"_ustr
, xShape
->getString());
884 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
886 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
888 CPPUNIT_ASSERT_EQUAL(0, getShapes());
890 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
892 CPPUNIT_ASSERT_EQUAL(4, getShapes());
894 // Without the fix in place, the text in the shape wouldn't be pasted
895 xShape
.set(getShape(1), uno::UNO_QUERY
);
896 CPPUNIT_ASSERT_EQUAL(u
"X"_ustr
, xShape
->getString());
898 //Without the fix in place, it would have crashed here
899 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
900 CPPUNIT_ASSERT_EQUAL(0, getShapes());
901 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
902 CPPUNIT_ASSERT_EQUAL(4, getShapes());
903 xShape
.set(getShape(1), uno::UNO_QUERY
);
904 CPPUNIT_ASSERT_EQUAL(u
"X"_ustr
, xShape
->getString());
907 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf138482
)
909 createSwDoc("tdf138482.docx");
911 CPPUNIT_ASSERT_EQUAL(2, getShapes());
913 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
915 // Without the fix in place, this test would have crashed here
916 dispatchCommand(mxComponent
, u
".uno:Delete"_ustr
, {});
917 CPPUNIT_ASSERT_EQUAL(0, getShapes());
919 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
920 CPPUNIT_ASSERT_EQUAL(2, getShapes());
923 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf134965
)
925 createSwDoc("tdf134965.odt");
927 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
928 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
930 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
932 for (sal_Int32 i
= 0; i
< 10; ++i
)
934 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
936 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
938 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
940 // Without the fix in place, this test would have crashed here
941 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
943 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
947 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf128375
)
949 for (sal_Int32 i
= 0; i
< 2; ++i
)
951 createSwDoc("tdf128375.docx");
953 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
954 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
956 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
958 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
960 // Without the fix in place, this test would have crashed cutting the second document
961 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
963 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
967 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf135061
)
969 createSwDoc("tdf135061.odt");
971 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
972 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
974 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
975 CPPUNIT_ASSERT_EQUAL(4, getShapes());
977 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
979 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
981 for (sal_Int32 i
= 0; i
< 5; ++i
)
983 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
986 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xIndexAccess
->getCount());
987 CPPUNIT_ASSERT_EQUAL(20, getShapes());
989 for (sal_Int32 i
= 0; i
< 5; ++i
)
991 // Without the fix in place, this test would have crashed here
992 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
995 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
996 CPPUNIT_ASSERT_EQUAL(4, getShapes());
999 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132911
)
1001 createSwDoc("tdf132911.odt");
1003 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1004 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1006 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1007 CPPUNIT_ASSERT_EQUAL(4, getShapes());
1009 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1011 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
1013 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
1014 CPPUNIT_ASSERT_EQUAL(0, getShapes());
1016 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1018 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1019 CPPUNIT_ASSERT_EQUAL(4, getShapes());
1021 // Without the fix in place, it would have crashed here
1022 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1023 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1024 CPPUNIT_ASSERT_EQUAL(8, getShapes());
1026 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1027 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1028 CPPUNIT_ASSERT_EQUAL(4, getShapes());
1030 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1031 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
1032 CPPUNIT_ASSERT_EQUAL(0, getShapes());
1034 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1035 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1036 CPPUNIT_ASSERT_EQUAL(4, getShapes());
1038 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1039 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1040 CPPUNIT_ASSERT_EQUAL(8, getShapes());
1042 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1043 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1044 CPPUNIT_ASSERT_EQUAL(4, getShapes());
1046 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1047 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
1048 CPPUNIT_ASSERT_EQUAL(0, getShapes());
1050 //tdf#135247: Without the fix in place, this would have crashed
1051 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1052 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1053 CPPUNIT_ASSERT_EQUAL(4, getShapes());
1056 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf61154
)
1058 createSwDoc("tdf61154.fodt");
1059 SwDoc
* pDoc
= getSwDoc();
1060 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1062 pWrtShell
->GotoNextTOXBase();
1065 pDoc
->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::ShowDelete
1066 | RedlineFlags::ShowInsert
);
1067 CPPUNIT_ASSERT_MESSAGE("redlining should be off",
1068 !pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
1069 CPPUNIT_ASSERT_MESSAGE(
1070 "redlines should be visible",
1071 IDocumentRedlineAccess::IsShowChanges(pDoc
->getIDocumentRedlineAccess().GetRedlineFlags()));
1073 const SwTOXBase
* pTOXBase
= pWrtShell
->GetCurTOX();
1074 pWrtShell
->UpdateTableOf(*pTOXBase
);
1075 SwCursorShell
* pShell(pDoc
->GetEditShell());
1076 CPPUNIT_ASSERT(pShell
);
1077 SwTextNode
* pTitleNode
= pShell
->GetCursor()->GetPointNode().GetTextNode();
1078 SwNodeIndex
aIdx(*pTitleNode
);
1080 // table of contents node shouldn't contain tracked deletion
1081 // This was "Text InsertedDeleted\t1"
1082 SwTextNode
* pNext
= static_cast<SwTextNode
*>(SwNodes::GoNext(&aIdx
));
1083 CPPUNIT_ASSERT_EQUAL(u
"Text Inserted\t1"_ustr
, pNext
->GetText());
1086 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf124904
)
1088 // don't show deletions in referenced text,
1089 // (except if the full text is deleted)
1090 createSwDoc("tdf124904.fodt");
1091 SwDoc
* pDoc
= getSwDoc();
1094 pDoc
->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On
| RedlineFlags::ShowDelete
1095 | RedlineFlags::ShowInsert
);
1096 CPPUNIT_ASSERT_MESSAGE("redlining should be on",
1097 pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
1098 CPPUNIT_ASSERT_MESSAGE(
1099 "redlines should be visible",
1100 IDocumentRedlineAccess::IsShowChanges(pDoc
->getIDocumentRedlineAccess().GetRedlineFlags()));
1102 // remove the first word "Heading" (with change tracking) to update the referenced text
1103 dispatchCommand(mxComponent
, u
".uno:DelToEndOfWord"_ustr
, {});
1105 // This was "Reference to Heading of document file"
1106 CPPUNIT_ASSERT_EQUAL(u
"Reference to of example document "_ustr
, getParagraph(2)->getString());
1108 // don't hide the wholly deleted referenced text
1109 dispatchCommand(mxComponent
, u
".uno:DelToEndOfLine"_ustr
, {});
1110 CPPUNIT_ASSERT_EQUAL(u
"Reference to Heading of example document file"_ustr
,
1111 getParagraph(2)->getString());
1114 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf100691
)
1116 createSwDoc("tdf100691.fodt");
1117 SwDoc
* pDoc
= getSwDoc();
1118 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1120 pWrtShell
->GotoNextTOXBase();
1122 const SwTOXBase
* pTOXBase
= pWrtShell
->GetCurTOX();
1123 pWrtShell
->UpdateTableOf(*pTOXBase
);
1124 SwCursorShell
* pShell(pDoc
->GetEditShell());
1125 CPPUNIT_ASSERT(pShell
);
1126 SwTextNode
* pTitleNode
= pShell
->GetCursor()->GetPointNode().GetTextNode();
1127 SwNodeIndex
aIdx(*pTitleNode
);
1129 // table of contents node shouldn't contain invisible text
1130 // This was "Text Hidden\t1"
1131 SwTextNode
* pNext
= static_cast<SwTextNode
*>(SwNodes::GoNext(&aIdx
));
1132 CPPUNIT_ASSERT_EQUAL(u
"Text\t1"_ustr
, pNext
->GetText());
1135 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf134404
)
1137 createSwDoc("tdf134404.odt");
1139 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1140 CPPUNIT_ASSERT_EQUAL(1, getPages());
1142 dispatchCommand(mxComponent
, u
".uno:GoToEndOfPage"_ustr
, {});
1143 dispatchCommand(mxComponent
, u
".uno:InsertPagebreak"_ustr
, {});
1145 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1146 CPPUNIT_ASSERT_EQUAL(2, getPages());
1148 dispatchCommand(mxComponent
, u
".uno:SwBackspace"_ustr
, {});
1150 // Without the fix in place, the image would have been deleted
1151 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1152 CPPUNIT_ASSERT_EQUAL(1, getPages());
1154 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1155 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1156 CPPUNIT_ASSERT_EQUAL(2, getPages());
1159 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf112342
)
1161 createSwDoc("tdf112342.docx");
1164 uno::Reference
<text::XTextRange
> xPara
= getParagraph(3);
1165 auto xCur
= xPara
->getText()->createTextCursor();
1166 //Go to the end of it
1167 xCur
->gotoEnd(false);
1168 //And let's remove the last 2 chars (the last para with its char).
1169 xCur
->goLeft(2, true);
1170 xCur
->setString(u
""_ustr
);
1172 //If the second paragraph on the second page, this will be passed.
1173 CPPUNIT_ASSERT_EQUAL_MESSAGE("Page break does not match", 2, getPages());
1176 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132321
)
1178 createSwDoc("tdf132321.odt");
1180 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1182 dispatchCommand(mxComponent
, u
".uno:GoToEndOfPage"_ustr
, {});
1183 dispatchCommand(mxComponent
, u
".uno:SwBackspace"_ustr
, {});
1185 // Without the fix in place, the button form would have also been deleted
1186 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1188 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1189 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1192 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf135056
)
1194 createSwDoc("tdf135056.odt");
1195 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1197 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pWrtShell
->GetTOXCount());
1199 const SwTOXBase
* pTOX
= pWrtShell
->GetTOX(0);
1200 CPPUNIT_ASSERT(pTOX
);
1202 //Without the fix in place, it would have hung here
1203 pWrtShell
->DeleteTOX(*pTOX
, true);
1205 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pWrtShell
->GetTOXCount());
1207 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1209 CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), pWrtShell
->GetTOXCount());
1212 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132597
)
1214 createSwDoc("tdf132597.odt");
1216 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1217 CPPUNIT_ASSERT_EQUAL(1, getPages());
1219 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1221 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1223 // Paste special as RTF
1224 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1225 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
1227 dispatchCommand(mxComponent
, u
".uno:ClipboardFormatItems"_ustr
, aPropertyValues
);
1229 // Without the fix in place, this test would have crashed here
1230 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1232 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1233 CPPUNIT_ASSERT_EQUAL(1, getPages());
1236 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf139737
)
1238 createSwDoc("tdf139737.fodt");
1240 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1242 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1244 // Paste special as RTF
1245 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1246 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
1248 dispatchCommand(mxComponent
, u
".uno:ClipboardFormatItems"_ustr
, aPropertyValues
);
1250 // Without the fix in place, this test would have crashed here
1251 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1254 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf150845
)
1258 // Insert text box with ctrl key
1259 // Without the fix in place, this test would have crashed here
1260 uno::Sequence
<beans::PropertyValue
> aArgs(
1261 comphelper::InitPropertySequence({ { "KeyModifier", uno::Any(KEY_MOD1
) } }));
1262 dispatchCommand(mxComponent
, u
".uno:Edit"_ustr
, aArgs
);
1264 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1267 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf147961
)
1270 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1272 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1273 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1275 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
1277 pWrtShell
->Insert(u
"++"_ustr
);
1279 // Without the fix in place, this test would have crashed here
1280 SwXTextDocument
* pTextDoc
= getSwTextDoc();
1281 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
1282 Scheduler::ProcessEventsToIdle();
1284 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1287 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf147206
)
1290 SwDoc
* pDoc
= getSwDoc();
1291 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1293 // insert empty paragraph and heading text
1294 pWrtShell
->SplitNode();
1295 pWrtShell
->Insert(u
"abc"_ustr
);
1296 pWrtShell
->SplitNode();
1298 // set one to heading so there will be an entry in the tox
1299 pWrtShell
->Up(false, 1);
1300 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence({
1301 { "Style", uno::Any(u
"Heading 1"_ustr
) },
1302 { "FamilyName", uno::Any(u
"ParagraphStyles"_ustr
) },
1304 dispatchCommand(mxComponent
, u
".uno:StyleApply"_ustr
, aPropertyValues
);
1306 pWrtShell
->EndOfSection(false);
1308 // tdf#142423: Without the fix in place, this test would have failed with
1311 CPPUNIT_ASSERT_EQUAL(18.0f
, getProperty
<float>(getParagraph(2), u
"CharHeight"_ustr
));
1313 // insert table of contents
1314 SwTOXMgr
mgr(pWrtShell
);
1315 SwTOXDescription desc
{ TOX_CONTENT
};
1316 mgr
.UpdateOrInsertTOX(desc
, nullptr, nullptr);
1318 // get url of heading cross reference mark
1319 IDocumentMarkAccess
& rIDMA(*pDoc
->getIDocumentMarkAccess());
1320 auto const headingMark
1321 = std::find_if(rIDMA
.getAllMarksBegin(), rIDMA
.getAllMarksEnd(), [](auto const* const it
) {
1322 return it
->GetName().startsWith(
1323 IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix());
1325 CPPUNIT_ASSERT(headingMark
!= rIDMA
.getAllMarksEnd());
1326 OUString
const headingLink("#" + (*headingMark
)->GetName());
1329 pWrtShell
->SttEndDoc(false);
1330 pWrtShell
->Up(false, 1);
1331 pWrtShell
->EndPara(true);
1333 rtl::Reference
<SwTransferable
> xTransfer
= new SwTransferable(*pWrtShell
);
1336 pWrtShell
->SttEndDoc(true);
1338 // Paste special as RTF
1339 TransferableDataHelper
helper(xTransfer
);
1340 SwTransferable::PasteFormat(*pWrtShell
, helper
, SotClipboardFormatId::RTF
);
1341 Scheduler::ProcessEventsToIdle();
1343 // check hyperlinking
1344 CPPUNIT_ASSERT_EQUAL(
1346 getProperty
<OUString
>(getRun(getParagraph(1), 1, u
"abc\t1"_ustr
), u
"HyperLinkURL"_ustr
));
1347 CPPUNIT_ASSERT_EQUAL(OUString(), getProperty
<OUString
>(getRun(getParagraph(2), 1, OUString()),
1348 u
"HyperLinkURL"_ustr
));
1349 CPPUNIT_ASSERT_EQUAL(
1350 OUString(), getProperty
<OUString
>(getRun(getParagraph(3), 1, u
"Table of Contents"_ustr
),
1351 u
"HyperLinkURL"_ustr
));
1352 CPPUNIT_ASSERT_EQUAL(
1354 getProperty
<OUString
>(getRun(getParagraph(4), 1, u
"abc\t1"_ustr
), u
"HyperLinkURL"_ustr
));
1355 CPPUNIT_ASSERT_EQUAL(OUString(), getProperty
<OUString
>(getRun(getParagraph(5), 1, OUString()),
1356 u
"HyperLinkURL"_ustr
));
1359 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf48459
)
1362 SwDoc
* pDoc
= getSwDoc();
1363 SwWrtShell
* pWrtShell
= pDoc
->GetDocShell()->GetWrtShell();
1365 // insert paragraph text
1366 pWrtShell
->Insert(u
"Heading and normal text"_ustr
);
1368 // select the first word (proposed for inline heading)
1369 pWrtShell
->SttEndDoc(/*bStart=*/true);
1370 pWrtShell
->Right(SwCursorSkipMode::Chars
, /*bSelect=*/true, 7, /*bBasicCall=*/false);
1372 // apply styles only on the selected word -> create inline heading
1373 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence({
1374 { "Style", uno::Any(u
"Heading 1"_ustr
) },
1375 { "FamilyName", uno::Any(u
"ParagraphStyles"_ustr
) },
1377 dispatchCommand(mxComponent
, u
".uno:StyleApply"_ustr
, aPropertyValues
);
1379 uno::Reference
<frame::XFrames
> xFrames
= mxDesktop
->getFrames();
1381 // inline heading frame
1382 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xFrames
->getCount());
1384 pWrtShell
->EndOfSection(false);
1386 // insert table of contents to check ToC content (containing only the inline heading)
1387 SwTOXMgr
mgr(pWrtShell
);
1388 SwTOXDescription desc
{ TOX_CONTENT
};
1389 mgr
.UpdateOrInsertTOX(desc
, nullptr, nullptr);
1391 CPPUNIT_ASSERT_EQUAL(int(3), getParagraphs());
1393 // first paragraph: selected text moved to the inline heading frame
1394 CPPUNIT_ASSERT_EQUAL(u
" and normal text"_ustr
, getParagraph(1)->getString());
1397 CPPUNIT_ASSERT_EQUAL(u
"Table of Contents"_ustr
, getParagraph(2)->getString());
1399 // ToC contains only the inline heading
1400 CPPUNIT_ASSERT_EQUAL(u
"Heading\t1"_ustr
, getParagraph(3)->getString());
1403 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf144840
)
1405 createSwDoc("tdf144840.odt");
1407 CPPUNIT_ASSERT_EQUAL(1, getPages());
1408 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1409 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1411 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1413 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1415 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
1417 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
1419 // Paste special as RTF
1420 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1421 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
1423 dispatchCommand(mxComponent
, u
".uno:ClipboardFormatItems"_ustr
, aPropertyValues
);
1425 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1427 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1429 table::TableBorder2 tableBorder
1430 = getProperty
<table::TableBorder2
>(xTextTable
, u
"TableBorder2"_ustr
);
1432 // Without the fix in place, this test would have failed with
1435 CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), tableBorder
.TopLine
.LineWidth
);
1436 CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), tableBorder
.LeftLine
.LineWidth
);
1437 CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), tableBorder
.RightLine
.LineWidth
);
1438 CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), tableBorder
.BottomLine
.LineWidth
);
1441 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf131963
)
1443 createSwDoc("tdf131963.docx");
1445 CPPUNIT_ASSERT(11 == getPages() || 12 == getPages());
1447 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1449 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1451 // Paste special as RTF
1452 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1453 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
1455 dispatchCommand(mxComponent
, u
".uno:ClipboardFormatItems"_ustr
, aPropertyValues
);
1457 // Without the fix in place, this test would have crashed here
1459 // tdf#133169: without the fix in place, it would have been 2 instead of 11
1460 CPPUNIT_ASSERT(11 == getPages() || 12 == getPages());
1463 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132596
)
1465 createSwDoc("tdf132596.docx");
1467 CPPUNIT_ASSERT_EQUAL(2, getPages());
1469 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1471 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1473 // Paste special as RTF
1474 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
1475 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
1477 dispatchCommand(mxComponent
, u
".uno:ClipboardFormatItems"_ustr
, aPropertyValues
);
1479 // Without the fix in place, this test would have crashed here
1480 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1482 CPPUNIT_ASSERT_EQUAL(2, getPages());
1485 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf126626
)
1487 createSwDoc("tdf126626.docx");
1489 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1491 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1493 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1495 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1497 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1498 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1500 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1501 CPPUNIT_ASSERT_EQUAL(4, getShapes());
1503 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1504 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1506 // without the fix, it crashes
1507 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1508 CPPUNIT_ASSERT_EQUAL(4, getShapes());
1511 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf133967
)
1513 createSwDoc("tdf133967.odt");
1515 CPPUNIT_ASSERT_EQUAL(6, getPages());
1517 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1519 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
1521 for (sal_Int32 i
= 0; i
< 10; ++i
)
1523 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1525 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {});
1528 // Without the fix in place, this test would have failed with:
1531 CPPUNIT_ASSERT_EQUAL(1, getPages());
1534 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132187
)
1536 createSwDoc("tdf132187.odt");
1538 CPPUNIT_ASSERT_EQUAL(1, getPages());
1540 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1542 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1544 dispatchCommand(mxComponent
, u
".uno:GoToEndOfDoc"_ustr
, {});
1546 for (sal_Int32 i
= 0; i
< 10; ++i
)
1548 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1551 //without the fix in place, this test would fail with:
1555 CPPUNIT_ASSERT_EQUAL(1, getPages());
1558 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf130094
)
1560 createSwDoc("tdf130094.fodt");
1561 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1563 CPPUNIT_ASSERT_EQUAL(u
"First"_ustr
, getParagraph(1)->getString());
1564 CPPUNIT_ASSERT_EQUAL(u
"Second"_ustr
, getParagraph(2)->getString());
1565 CPPUNIT_ASSERT_EQUAL(u
"Third"_ustr
, getParagraph(3)->getString());
1567 // Select the first and second lines
1568 pWrtShell
->Down(/*bSelect=*/true);
1569 pWrtShell
->Down(/*bSelect=*/true);
1571 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1573 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1575 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1577 CPPUNIT_ASSERT_EQUAL(u
"First"_ustr
, getParagraph(1)->getString());
1578 CPPUNIT_ASSERT_EQUAL(u
"Second"_ustr
, getParagraph(2)->getString());
1579 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, getParagraph(3)->getString());
1581 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1583 CPPUNIT_ASSERT_EQUAL(u
"First"_ustr
, getParagraph(1)->getString());
1584 CPPUNIT_ASSERT_EQUAL(u
"Second"_ustr
, getParagraph(2)->getString());
1585 CPPUNIT_ASSERT_EQUAL(u
"Third"_ustr
, getParagraph(3)->getString());
1587 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1589 CPPUNIT_ASSERT_EQUAL(u
"First"_ustr
, getParagraph(1)->getString());
1590 CPPUNIT_ASSERT_EQUAL(u
"Second"_ustr
, getParagraph(2)->getString());
1592 // Without the fix in place, this test would have failed with
1595 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, getParagraph(3)->getString());
1598 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf135733
)
1600 createSwDoc("tdf135733.odt");
1601 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1603 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1604 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1606 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1607 CPPUNIT_ASSERT_EQUAL(1, getPages());
1608 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1610 //Move the cursor inside the table
1611 pWrtShell
->Down(/*bSelect=*/false);
1612 pWrtShell
->Down(/*bSelect=*/false);
1614 //Select first column
1615 pWrtShell
->Down(/*bSelect=*/true);
1616 pWrtShell
->Down(/*bSelect=*/true);
1617 pWrtShell
->Down(/*bSelect=*/true);
1619 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
1621 pWrtShell
->SttPg(/*bSelect=*/false);
1623 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1625 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1626 // the table is inserted before the first paragraph, which has a pagedesc
1627 CPPUNIT_ASSERT_EQUAL(2, getPages());
1628 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1630 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1632 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1633 CPPUNIT_ASSERT_EQUAL(1, getPages());
1634 CPPUNIT_ASSERT_EQUAL(0, getShapes());
1636 // without the fix, it crashes
1637 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1639 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1640 CPPUNIT_ASSERT_EQUAL(1, getPages());
1641 CPPUNIT_ASSERT_EQUAL(2, getShapes());
1644 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf128739
)
1646 createSwDoc("tdf128739.docx");
1648 CPPUNIT_ASSERT_EQUAL(u
"Fehler: Verweis nicht gefunden"_ustr
, getParagraph(1)->getString());
1650 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1652 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
1654 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, getParagraph(1)->getString());
1656 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1657 CPPUNIT_ASSERT_EQUAL(u
"Fehler: Verweis nicht gefunden"_ustr
, getParagraph(1)->getString());
1659 // without the fix, it crashes
1660 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1661 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, getParagraph(1)->getString());
1664 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf124722
)
1666 createSwDoc("tdf124722.rtf");
1668 CPPUNIT_ASSERT_EQUAL(22, getPages());
1670 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1672 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1674 CPPUNIT_ASSERT_EQUAL(22, getPages());
1676 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1677 CPPUNIT_ASSERT_EQUAL(43, getPages());
1679 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1680 CPPUNIT_ASSERT_EQUAL(22, getPages());
1683 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testToxmarkLinks
)
1685 createSwDoc("udindex3.odt");
1686 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1687 SwView
& rView(*getSwDocShell()->GetView());
1690 for (auto i
= pWrtShell
->GetTOXCount(); 0 < i
;)
1693 pWrtShell
->UpdateTableOf(*pWrtShell
->GetTOX(i
));
1696 // click on the links...
1698 static OUString
constexpr tmp(u
"Table of Contents"_ustr
);
1699 pWrtShell
->GotoNextTOXBase(&tmp
);
1703 pWrtShell
->Down(false);
1704 SfxItemSet
aSet(pWrtShell
->GetAttrPool(),
1705 svl::Items
<RES_TXTATR_INETFMT
, RES_TXTATR_INETFMT
>);
1706 pWrtShell
->GetCurAttr(aSet
);
1707 CPPUNIT_ASSERT(aSet
.HasItem(RES_TXTATR_INETFMT
));
1709 OUString
const url(aSet
.GetItem
<SwFormatINetFormat
>(RES_TXTATR_INETFMT
)->GetValue());
1710 CPPUNIT_ASSERT_EQUAL(u
"#1%19the%20tocmark%19C%7Ctoxmark"_ustr
, url
);
1711 rView
.JumpToSwMark(url
.subView(1)); // SfxApplication::OpenDocExec_Impl eats the "#"
1712 CPPUNIT_ASSERT_EQUAL(OUString(OUStringChar(CH_TXTATR_INWORD
) + "tocmark"),
1713 pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1714 pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
1718 pWrtShell
->Down(false);
1719 SfxItemSet
aSet(pWrtShell
->GetAttrPool(),
1720 svl::Items
<RES_TXTATR_INETFMT
, RES_TXTATR_INETFMT
>);
1721 pWrtShell
->GetCurAttr(aSet
);
1722 CPPUNIT_ASSERT(aSet
.HasItem(RES_TXTATR_INETFMT
));
1724 OUString
const url(aSet
.GetItem
<SwFormatINetFormat
>(RES_TXTATR_INETFMT
)->GetValue());
1725 CPPUNIT_ASSERT_EQUAL(u
"#__RefHeading___Toc105_706348105"_ustr
, url
);
1726 rView
.JumpToSwMark(url
.subView(1));
1727 CPPUNIT_ASSERT_EQUAL(u
"foo"_ustr
,
1728 pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1729 pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
1733 static OUString
constexpr tmp(u
"User-Defined1"_ustr
);
1734 pWrtShell
->GotoNextTOXBase(&tmp
);
1738 pWrtShell
->Down(false);
1739 SfxItemSet
aSet(pWrtShell
->GetAttrPool(),
1740 svl::Items
<RES_TXTATR_INETFMT
, RES_TXTATR_INETFMT
>);
1741 pWrtShell
->GetCurAttr(aSet
);
1742 CPPUNIT_ASSERT(aSet
.HasItem(RES_TXTATR_INETFMT
));
1744 OUString
const url(aSet
.GetItem
<SwFormatINetFormat
>(RES_TXTATR_INETFMT
)->GetValue());
1745 CPPUNIT_ASSERT_EQUAL(u
"#1%19the%20udmark%19UUser-Defined%20Index%7Ctoxmark"_ustr
,
1746 url
); // User-Defined => User-Defined Index, tdf#161574
1747 rView
.JumpToSwMark(url
.subView(1));
1748 CPPUNIT_ASSERT_EQUAL(OUString(OUStringChar(CH_TXTATR_INWORD
) + "udmark the first"),
1749 pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1750 pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
1753 { // UD1 toxmark 2 (with same text)
1754 pWrtShell
->Down(false);
1755 SfxItemSet
aSet(pWrtShell
->GetAttrPool(),
1756 svl::Items
<RES_TXTATR_INETFMT
, RES_TXTATR_INETFMT
>);
1757 pWrtShell
->GetCurAttr(aSet
);
1758 CPPUNIT_ASSERT(aSet
.HasItem(RES_TXTATR_INETFMT
));
1760 OUString
const url(aSet
.GetItem
<SwFormatINetFormat
>(RES_TXTATR_INETFMT
)->GetValue());
1761 CPPUNIT_ASSERT_EQUAL(u
"#2%19the%20udmark%19UUser-Defined%20Index%7Ctoxmark"_ustr
,
1762 url
); // User-Defined => User-Defined Index, tdf#161574
1763 rView
.JumpToSwMark(url
.subView(1));
1764 CPPUNIT_ASSERT_EQUAL(OUString(OUStringChar(CH_TXTATR_INWORD
) + "udmark the 2nd"),
1765 pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1766 pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
1770 pWrtShell
->Down(false);
1771 SfxItemSet
aSet(pWrtShell
->GetAttrPool(),
1772 svl::Items
<RES_TXTATR_INETFMT
, RES_TXTATR_INETFMT
>);
1773 pWrtShell
->GetCurAttr(aSet
);
1774 CPPUNIT_ASSERT(aSet
.HasItem(RES_TXTATR_INETFMT
));
1776 OUString
const url(aSet
.GetItem
<SwFormatINetFormat
>(RES_TXTATR_INETFMT
)->GetValue());
1777 CPPUNIT_ASSERT_EQUAL(u
"#__RefHeading___Toc105_706348105"_ustr
, url
);
1778 rView
.JumpToSwMark(url
.subView(1));
1779 CPPUNIT_ASSERT_EQUAL(u
"foo"_ustr
,
1780 pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1781 pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
1785 static OUString
constexpr tmp(u
"NewUD!|1"_ustr
);
1786 pWrtShell
->GotoNextTOXBase(&tmp
);
1789 { // UD2 toxmark, with same text as those in other UD
1790 pWrtShell
->Down(false);
1791 SfxItemSet
aSet(pWrtShell
->GetAttrPool(),
1792 svl::Items
<RES_TXTATR_INETFMT
, RES_TXTATR_INETFMT
>);
1793 pWrtShell
->GetCurAttr(aSet
);
1794 CPPUNIT_ASSERT(aSet
.HasItem(RES_TXTATR_INETFMT
));
1796 OUString
const url(aSet
.GetItem
<SwFormatINetFormat
>(RES_TXTATR_INETFMT
)->GetValue());
1797 CPPUNIT_ASSERT_EQUAL(u
"#1%19the%20udmark%19UNewUD!%7C%7Ctoxmark"_ustr
, url
);
1798 rView
.JumpToSwMark(url
.subView(1));
1799 CPPUNIT_ASSERT_EQUAL(u
"the udmark"_ustr
,
1800 pWrtShell
->GetCursor()->GetPointNode().GetTextNode()->GetText());
1801 pWrtShell
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
1805 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf125261
)
1807 createSwDoc("tdf125261.odt");
1809 CPPUNIT_ASSERT_EQUAL(u
"https://www.example.com/"_ustr
,
1810 getProperty
<OUString
>(getRun(getParagraph(1), 1), u
"HyperLinkURL"_ustr
));
1811 //apply autocorrect StartAutoCorrect
1812 dispatchCommand(mxComponent
, u
".uno:AutoFormatApply"_ustr
, {});
1813 CPPUNIT_ASSERT_EQUAL(u
"https://www.example.com/"_ustr
,
1814 getProperty
<OUString
>(getRun(getParagraph(1), 1), u
"HyperLinkURL"_ustr
));
1815 // without the fix, it hangs
1816 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1817 CPPUNIT_ASSERT_EQUAL(u
"https://www.example.com/"_ustr
,
1818 getProperty
<OUString
>(getRun(getParagraph(1), 1), u
"HyperLinkURL"_ustr
));
1821 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf141175
)
1823 createSwDoc("tdf141175.odt");
1825 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1826 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1828 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1829 CPPUNIT_ASSERT_EQUAL(1, getPages());
1831 //Use selectAll 3 times in a row
1832 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1833 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1834 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1836 //Without the fix in place, this test would have crashed here
1837 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
1839 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1840 CPPUNIT_ASSERT_EQUAL(1, getPages());
1842 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1844 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1845 CPPUNIT_ASSERT_EQUAL(1, getPages());
1848 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf133990
)
1850 createSwDoc("tdf133990.odt");
1852 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1853 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1855 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xIndexAccess
->getCount());
1856 CPPUNIT_ASSERT_EQUAL(1, getPages());
1858 //Use selectAll 3 times in a row
1859 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1860 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1861 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1863 dispatchCommand(mxComponent
, u
".uno:Delete"_ustr
, {});
1864 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
1866 //Without the fix in place, it would have crashed here
1867 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1868 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xIndexAccess
->getCount());
1869 CPPUNIT_ASSERT_EQUAL(1, getPages());
1872 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf126504
)
1874 createSwDoc("tdf126504.odt");
1876 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1877 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1879 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1880 CPPUNIT_ASSERT_EQUAL(1, getPages());
1882 //Use selectAll 2 times in a row
1883 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1884 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1885 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1887 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1889 dispatchCommand(mxComponent
, u
".uno:GoToEndOfPage"_ustr
, {});
1891 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1893 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xIndexAccess
->getCount());
1894 CPPUNIT_ASSERT_EQUAL(1, getPages());
1896 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1898 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1899 CPPUNIT_ASSERT_EQUAL(1, getPages());
1901 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {});
1903 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xIndexAccess
->getCount());
1904 CPPUNIT_ASSERT_EQUAL(1, getPages());
1906 //Without the fix in place, it would have crashed here
1907 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1909 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1910 CPPUNIT_ASSERT_EQUAL(1, getPages());
1913 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf133982
)
1915 createSwDoc("tdf133982.docx");
1917 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1918 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1920 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1922 //Use selectAll 3 times in a row
1923 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1924 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1925 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1926 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1928 //Without the fix in place, it would have crashed here
1929 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
1930 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
1932 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1933 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1936 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf134253
)
1938 createSwDoc("tdf134253.odt");
1940 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1941 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1943 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1944 CPPUNIT_ASSERT_EQUAL(6, getPages());
1946 //Use selectAll 3 times in a row
1947 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1948 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1949 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1951 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1952 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1954 //Without the fix in place, it would have crashed here
1955 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1957 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1958 CPPUNIT_ASSERT_EQUAL(6, getPages());
1961 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testNotebookBar
)
1965 //tdf#154282: Without the fix in place, this test would have crashed
1966 dispatchCommand(mxComponent
, u
".uno:ToolbarMode?Mode:string=notebookbar.ui"_ustr
, {});
1967 dispatchCommand(mxComponent
, u
".uno:ToolbarMode?Mode:string=Single"_ustr
, {});
1968 dispatchCommand(mxComponent
, u
".uno:ToolbarMode?Mode:string=Sidebar"_ustr
, {});
1969 dispatchCommand(mxComponent
, u
".uno:ToolbarMode?Mode:string=notebookbar_compact.ui"_ustr
, {});
1970 dispatchCommand(mxComponent
,
1971 u
".uno:ToolbarMode?Mode:string=notebookbar_groupedbar_compact.ui"_ustr
, {});
1972 dispatchCommand(mxComponent
, u
".uno:ToolbarMode?Mode:string=notebookbar_single.ui"_ustr
, {});
1973 dispatchCommand(mxComponent
, u
".uno:ToolbarMode?Mode:string=Default"_ustr
, {});
1976 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, TestAsCharTextBox
)
1979 // tdf#138598 Replace vertical alignment of As_char textboxes in footer
1980 // tdf#140158 Remove horizontal positioning of As_char textboxes, because
1981 // the anchor moving does the same for it.
1983 createSwDoc("AsCharTxBxTest.docx");
1985 // Add 3x tab to the doc
1986 SwXTextDocument
* pTextDoc
= getSwTextDoc();
1987 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
1988 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
1989 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
1990 Scheduler::ProcessEventsToIdle();
1992 auto pExportDump
= parseLayoutDump();
1993 CPPUNIT_ASSERT(pExportDump
);
1995 // Check if the texbox fallen apart due to the tabs
1996 const double nLeftSideOfShape1
1997 = getXPath(pExportDump
, "/root/page/body/txt/anchored/SwAnchoredDrawObject/bounds", "left")
1999 const double nLeftSideOfTxBx1
2000 = getXPath(pExportDump
, "/root/page/body/txt/anchored/fly/infos/bounds", "left").toDouble();
2002 CPPUNIT_ASSERT(nLeftSideOfShape1
< nLeftSideOfTxBx1
);
2004 // Another test is for the tdf#138598: Check footer textbox
2005 const double nLeftSideOfShape2
2006 = getXPath(pExportDump
, "/root/page[2]/footer/txt/anchored/SwAnchoredDrawObject/bounds",
2009 const double nLeftSideOfTxBx2
2010 = getXPath(pExportDump
, "/root/page[2]/footer/txt/anchored/fly/infos/bounds", "left")
2013 CPPUNIT_ASSERT(nLeftSideOfShape2
< nLeftSideOfTxBx2
);
2015 const double nTopSideOfShape2
2016 = getXPath(pExportDump
, "/root/page[2]/footer/txt/anchored/SwAnchoredDrawObject/bounds",
2019 const double nTopSideOfTxBx2
2020 = getXPath(pExportDump
, "/root/page[2]/footer/txt/anchored/fly/infos/bounds", "top")
2023 CPPUNIT_ASSERT(nTopSideOfShape2
< nTopSideOfTxBx2
);
2024 // Without the fix in place the two texboxes has been fallen apart, and asserts will broken.
2027 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf155028
)
2029 createSwDoc("tdf155028.odt");
2031 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2032 uno::Reference
<drawing::XShapes
> xGroupShape(getShape(1), uno::UNO_QUERY
);
2033 CPPUNIT_ASSERT_EQUAL(sal_Int32(10), xGroupShape
->getCount());
2036 dispatchCommand(mxComponent
, u
".uno:EnterGroup"_ustr
, {});
2038 // Select a shape in the group
2039 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2040 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
2041 Scheduler::ProcessEventsToIdle();
2043 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
2045 // Without the fix in place, this test would have crashed
2046 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
2048 CPPUNIT_ASSERT_EQUAL(sal_Int32(11), xGroupShape
->getCount());
2050 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2052 CPPUNIT_ASSERT_EQUAL(sal_Int32(10), xGroupShape
->getCount());
2055 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf135581
)
2057 createSwDoc("tdf135581.odt");
2060 dispatchCommand(mxComponent
, u
".uno:SetAnchorAtChar"_ustr
, {}); // this is "to char"
2062 // Without the fix, the image was moving when the anchor changed, letting text flow back.
2063 CPPUNIT_ASSERT_EQUAL(2, getPages());
2064 // Make sure that the image is still on the first page, and the text is on the second
2065 auto pExportDump
= parseLayoutDump();
2066 assertXPath(pExportDump
, "//page[1]/body/txt/anchored/fly");
2067 assertXPath(pExportDump
, "//page[1]/body/txt//SwLineLayout", "length", u
"0");
2068 assertXPath(pExportDump
, "//page[2]/body/txt//SwLineLayout", "length", u
"26");
2071 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf140975
)
2074 createSwDoc("tdf140975.docx");
2076 // Set the Anchor of the shape to As_Char
2078 dispatchCommand(mxComponent
, u
".uno:SetAnchorToChar"_ustr
, {});
2080 // Get the layout of the textbox
2081 auto pExportDump
= parseLayoutDump();
2082 CPPUNIT_ASSERT(pExportDump
);
2084 const sal_Int32 nShpTop
2085 = getXPath(pExportDump
, "/root/page/body/txt[4]/anchored/SwAnchoredDrawObject/bounds",
2088 const sal_Int32 nFrmTop
2089 = getXPath(pExportDump
, "/root/page/body/txt[4]/anchored/fly/infos/bounds", "top")
2092 // Without the fix in place, the frame has less value for Top than
2093 // the shape. This means the frame is outside from the shape.
2094 CPPUNIT_ASSERT_GREATER(nShpTop
, nFrmTop
);
2097 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf76636
)
2099 createSwDoc("tdf76636.doc");
2101 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2102 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2104 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2105 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2106 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
2107 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable
->getColumns()->getCount());
2110 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2111 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DOWN
);
2112 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DOWN
);
2113 Scheduler::ProcessEventsToIdle();
2115 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
2116 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
2117 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
2118 Scheduler::ProcessEventsToIdle();
2120 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_LEFT
| KEY_SHIFT
);
2121 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_LEFT
| KEY_SHIFT
);
2122 Scheduler::ProcessEventsToIdle();
2124 dispatchCommand(mxComponent
, u
".uno:MergeCells"_ustr
, {});
2125 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2126 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
2127 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTextTable
->getColumns()->getCount());
2129 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2130 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2131 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
2132 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable
->getColumns()->getCount());
2135 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf76636_2
)
2137 createSwDoc("tdf76636.doc");
2139 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2140 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2142 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2143 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2144 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
2145 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable
->getColumns()->getCount());
2147 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2148 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DOWN
);
2149 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DOWN
);
2150 Scheduler::ProcessEventsToIdle();
2152 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
2153 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
2154 Scheduler::ProcessEventsToIdle();
2156 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RIGHT
| KEY_SHIFT
);
2157 Scheduler::ProcessEventsToIdle();
2159 dispatchCommand(mxComponent
, u
".uno:MergeCells"_ustr
, {});
2160 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2161 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
2162 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTextTable
->getColumns()->getCount());
2164 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2165 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2166 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
2167 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable
->getColumns()->getCount());
2170 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf140828
)
2172 createSwDoc("tdf140828.docx");
2174 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2175 uno::Reference
<drawing::XShape
> xShp
= getShape(1);
2176 CPPUNIT_ASSERT(xShp
);
2178 uno::Reference
<beans::XPropertySet
> ShpProps(xShp
, uno::UNO_QUERY_THROW
);
2181 dispatchCommand(mxComponent
, u
".uno:SetAnchorAtChar"_ustr
, {});
2183 CPPUNIT_ASSERT_EQUAL(
2184 text::TextContentAnchorType::TextContentAnchorType_AT_CHARACTER
,
2185 ShpProps
->getPropertyValue(u
"AnchorType"_ustr
).get
<text::TextContentAnchorType
>());
2187 uno::Reference
<text::XTextFrame
> xTxBx(SwTextBoxHelper::getUnoTextFrame(xShp
));
2188 CPPUNIT_ASSERT(xTxBx
);
2190 uno::Reference
<beans::XPropertySet
> TxBxProps(xTxBx
, uno::UNO_QUERY_THROW
);
2191 CPPUNIT_ASSERT_EQUAL(u
"top left image"_ustr
, xTxBx
->getText()->getString());
2193 CPPUNIT_ASSERT_MESSAGE("Bad Relative Orientation and Position!",
2194 TxBxProps
->getPropertyValue(u
"HoriOrientRelation"_ustr
).get
<sal_Int16
>()
2195 != text::RelOrientation::CHAR
);
2198 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132725
)
2200 createSwDoc("tdf132725.odt");
2202 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2203 CPPUNIT_ASSERT_EQUAL(u
"AA"_ustr
, getParagraph(1)->getString());
2205 dispatchCommand(mxComponent
, u
".uno:GoToEndOfPara"_ustr
, {});
2207 dispatchCommand(mxComponent
, u
".uno:SwBackspace"_ustr
, {});
2208 dispatchCommand(mxComponent
, u
".uno:SwBackspace"_ustr
, {});
2210 // tdf#137587 fly is no longer deleted by backspace
2211 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2212 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, getParagraph(1)->getString());
2214 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2215 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2217 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2218 CPPUNIT_ASSERT_EQUAL(u
"AA"_ustr
, getParagraph(1)->getString());
2220 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {});
2221 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {});
2223 // tdf#137587 fly is no longer deleted by backspace
2224 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2225 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, getParagraph(1)->getString());
2227 //Without the fix in place, it would crash here
2228 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2230 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2231 CPPUNIT_ASSERT_EQUAL(u
"A"_ustr
, getParagraph(1)->getString());
2234 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf126340
)
2236 createSwDoc("tdf126340.odt");
2238 dispatchCommand(mxComponent
, u
".uno:GoDown"_ustr
, {});
2239 // without the fix, it crashes
2240 dispatchCommand(mxComponent
, u
".uno:Delete"_ustr
, {});
2241 CPPUNIT_ASSERT_EQUAL(u
"foo"_ustr
, getParagraph(1)->getString());
2242 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2243 CPPUNIT_ASSERT_EQUAL(u
"foo"_ustr
, getParagraph(1)->getString());
2246 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf124397
)
2248 createSwDoc("tdf124397.docx");
2250 uno::Reference
<text::XTextFramesSupplier
> xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
2251 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextFramesSupplier
->getTextFrames(),
2254 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2256 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2257 dispatchCommand(mxComponent
, u
".uno:Delete"_ustr
, {});
2258 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
2259 // Without the fix in place, it would crash here
2260 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2261 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2264 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf108124
)
2266 createSwDoc("tdf108124.odt");
2268 uno::Reference
<text::XTextGraphicObjectsSupplier
> xTextGraphicObjectsSupplier(mxComponent
,
2270 uno::Reference
<container::XIndexAccess
> xIndexAccess(
2271 xTextGraphicObjectsSupplier
->getGraphicObjects(), uno::UNO_QUERY
);
2273 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
2275 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2277 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
2279 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
2281 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
2283 uno::Reference
<drawing::XShape
> xOldShape1(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2284 uno::Reference
<drawing::XShape
> xOldShape2(xIndexAccess
->getByIndex(1), uno::UNO_QUERY
);
2286 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2288 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
2290 uno::Reference
<drawing::XShape
> xNewShape1(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2291 uno::Reference
<drawing::XShape
> xNewShape2(xIndexAccess
->getByIndex(1), uno::UNO_QUERY
);
2293 // there should be 2 different objects now but they have the same names,
2294 // so rely on the object identity for testing...
2295 CPPUNIT_ASSERT(xOldShape1
.get() != xNewShape1
.get());
2296 CPPUNIT_ASSERT(xOldShape1
.get() != xNewShape2
.get());
2297 CPPUNIT_ASSERT(xOldShape2
.get() != xNewShape1
.get());
2298 CPPUNIT_ASSERT(xOldShape2
.get() != xNewShape2
.get());
2300 // Without the fix in place, this test would have crashed here
2301 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {});
2303 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
2306 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf134021
)
2308 createSwDoc("tdf134021.docx");
2310 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2311 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2313 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2314 CPPUNIT_ASSERT_EQUAL(12, getPages());
2316 dispatchCommand(mxComponent
, u
".uno:JumpToNextTable"_ustr
, {});
2318 dispatchCommand(mxComponent
, u
".uno:DeleteTable"_ustr
, {});
2319 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
2320 CPPUNIT_ASSERT_EQUAL(1, getPages());
2322 // Without the fix in place, it would have crashed here
2323 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2325 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2326 CPPUNIT_ASSERT_EQUAL(12, getPages());
2329 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf136778
)
2331 createSwDoc("tdf136778.docx");
2333 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2334 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2336 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2337 CPPUNIT_ASSERT_EQUAL(1, getPages());
2339 dispatchCommand(mxComponent
, u
".uno:JumpToNextTable"_ustr
, {});
2341 dispatchCommand(mxComponent
, u
".uno:DeleteTable"_ustr
, {});
2342 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
2343 CPPUNIT_ASSERT_EQUAL(1, getPages());
2345 // Without the fix in place, it would have crashed here
2346 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2348 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2349 CPPUNIT_ASSERT_EQUAL(1, getPages());
2352 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf123285
)
2354 createSwDoc("tdf123285.odt");
2356 CPPUNIT_ASSERT_EQUAL(true,
2357 getParagraph(1)->getString().endsWith(
2358 ". Here is a short sentence demonstrating this very peculiar bug"
2359 ". Here is a short sentence demonstrating this very peculiar bug."));
2361 dispatchCommand(mxComponent
, u
".uno:GoToEndOfPage"_ustr
, {});
2363 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2364 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
2365 Scheduler::ProcessEventsToIdle();
2367 // Without the fix in place, the last "sentence" would have been changed to " entence"
2368 CPPUNIT_ASSERT_EQUAL(true,
2369 getParagraph(1)->getString().endsWith(
2370 ". Here is a short sentence demonstrating this very peculiar bug"
2371 ". Here is a short sentence demonstrating this very peculiar bug."));
2374 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf130746
)
2376 createSwDoc("tdf130746.odt");
2378 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2379 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2381 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2383 dispatchCommand(mxComponent
, u
".uno:JumpToNextTable"_ustr
, {});
2385 uno::Reference
<frame::XModel
> xModel(mxComponent
, uno::UNO_QUERY
);
2386 uno::Reference
<text::XTextViewCursorSupplier
> xTextViewCursorSupplier(
2387 xModel
->getCurrentController(), uno::UNO_QUERY
);
2388 uno::Reference
<text::XPageCursor
> xCursor(xTextViewCursorSupplier
->getViewCursor(),
2390 CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xCursor
->getPage());
2392 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2393 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
2394 Scheduler::ProcessEventsToIdle();
2396 CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor
->getPage());
2398 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_UP
| KEY_MOD2
);
2399 Scheduler::ProcessEventsToIdle();
2401 CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor
->getPage());
2403 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2405 CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xCursor
->getPage());
2406 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2409 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf129805
)
2411 createSwDoc("tdf129805.docx");
2413 CPPUNIT_ASSERT_EQUAL(u
"x"_ustr
, getParagraph(1)->getString());
2414 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2416 // without the fix in place, it would crash here
2417 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
2418 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, getParagraph(1)->getString());
2420 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2421 CPPUNIT_ASSERT_EQUAL(u
"x"_ustr
, getParagraph(1)->getString());
2424 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf130685
)
2426 createSwDoc("tdf130685.odt");
2428 CPPUNIT_ASSERT_EQUAL(2, getPages());
2429 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2431 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
2433 CPPUNIT_ASSERT_EQUAL(1, getPages());
2435 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
2436 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
2438 // Without fix in place, this test would have failed with:
2441 CPPUNIT_ASSERT_EQUAL(2, getPages());
2443 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2444 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2445 CPPUNIT_ASSERT_EQUAL(1, getPages());
2447 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2448 CPPUNIT_ASSERT_EQUAL(2, getPages());
2451 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf132944
)
2453 createSwDoc("tdf132944.odt");
2455 CPPUNIT_ASSERT_EQUAL(1, getPages());
2457 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2458 dispatchCommand(mxComponent
, u
".uno:Delete"_ustr
, {});
2459 CPPUNIT_ASSERT_EQUAL(1, getPages());
2461 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2463 // Without the fix in place, the document would have had 2 pages
2464 CPPUNIT_ASSERT_EQUAL(1, getPages());
2467 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf104649
)
2469 createSwDoc("tdf104649.docx");
2471 CPPUNIT_ASSERT_EQUAL(u
"Test"_ustr
, getParagraph(1)->getString());
2473 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2474 dispatchCommand(mxComponent
, u
".uno:Delete"_ustr
, {});
2475 CPPUNIT_ASSERT_EQUAL(1, getPages());
2477 // Without the fix in place, this test would have crashed here
2478 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2480 CPPUNIT_ASSERT_EQUAL(u
"Test"_ustr
, getParagraph(1)->getString());
2483 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf111969_lastHalfcharOfSelection
)
2485 // Given a document with a selected character,
2486 // the last half of the character should also be considered to be "in the selection"
2488 SwDocShell
* pDocShell
= getSwDocShell();
2489 SwWrtShell
* pWrtShell
= pDocShell
->GetWrtShell();
2490 // move the cursor after the "o" (this is better/safer than testing cursor at end of paragraph)
2491 pWrtShell
->Insert2(u
"Hello!"_ustr
);
2492 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/false, 1, /*bBasicCall=*/false);
2493 // get last pixel that will be part of the selection (current position 1pt wide).
2494 Point
aLogicL(pWrtShell
->GetCharRect().Center());
2495 // cursor pos WOULD be in the selection, but just reduce by one for good measure...
2496 aLogicL
.AdjustX(-1);
2497 // sanity check - pixel after should NOT be in the selection
2498 Point
aLogicR(pWrtShell
->GetCharRect().Center());
2502 //now select the letter 'o'
2503 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/true, 1, /*bBasicCall=*/false);
2505 // sanity check - the selection really does contain (or not) the two logic points
2506 pWrtShell
->GetCursor_()->FillStartEnd(aStartRect
, aEndRect
);
2507 SwRect
aSel(aStartRect
.TopLeft(), aEndRect
.BottomRight());
2508 CPPUNIT_ASSERT(aSel
.Contains(aLogicL
));
2509 CPPUNIT_ASSERT(!aSel
.Contains(aLogicR
));
2511 // the pixel just at the end of the selection is considered to be in ModelPositionForViewPoint
2512 CPPUNIT_ASSERT(pWrtShell
->TestCurrPam(aLogicL
));
2513 // the pixel just past the end of the selection is not considered to be inside.
2514 CPPUNIT_ASSERT(!pWrtShell
->TestCurrPam(aLogicR
));
2517 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf134931
)
2519 createSwDoc("tdf134931.odt");
2521 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2522 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2524 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2525 CPPUNIT_ASSERT_EQUAL(1, getPages());
2527 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2529 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
2531 dispatchCommand(mxComponent
, u
".uno:GoDown"_ustr
, {});
2533 for (sal_Int32 i
= 0; i
< 10; ++i
)
2535 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
2538 CPPUNIT_ASSERT_EQUAL(sal_Int32(11), xIndexAccess
->getCount());
2540 // Without the fix in place, this test would have failed with:
2543 // Because the tables are pasted but not displayed
2545 CPPUNIT_ASSERT_EQUAL(4, getPages());
2548 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf130680
)
2550 createSwDoc("tdf130680.odt");
2552 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2553 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2555 CPPUNIT_ASSERT_EQUAL(sal_Int32(23), xIndexAccess
->getCount());
2557 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2559 rtl::Reference
<SwDoc
> xClpDoc(new SwDoc());
2560 xClpDoc
->SetClipBoard(true);
2562 // without the fix, it crashes
2563 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
2565 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
2567 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
2568 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2571 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2572 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
2574 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2575 CPPUNIT_ASSERT_EQUAL(sal_Int32(23), xIndexAccess
->getCount());
2578 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf150457
)
2582 emulateTyping(u
"a");
2583 dispatchCommand(mxComponent
, u
".uno:InsertFootnote"_ustr
, {});
2584 emulateTyping(u
"abc");
2586 uno::Reference
<text::XFootnotesSupplier
> xFootnotesSupplier(mxComponent
, uno::UNO_QUERY
);
2587 auto xFootnotes
= xFootnotesSupplier
->getFootnotes();
2588 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(1), xFootnotes
->getCount());
2589 auto xParagraph
= uno::Reference
<text::XTextRange
>(xFootnotes
->getByIndex(0), uno::UNO_QUERY
);
2590 CPPUNIT_ASSERT_EQUAL(u
"abc"_ustr
, xParagraph
->getString());
2592 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2593 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_PAGEUP
);
2594 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
2595 emulateTyping(u
"d");
2597 dispatchCommand(mxComponent
, u
".uno:InsertFootnote"_ustr
, {});
2598 emulateTyping(u
"def");
2600 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(2), xFootnotes
->getCount());
2601 xParagraph
= uno::Reference
<text::XTextRange
>(xFootnotes
->getByIndex(1), uno::UNO_QUERY
);
2602 CPPUNIT_ASSERT_EQUAL(u
"def"_ustr
, xParagraph
->getString());
2604 // This key sequence deletes a footnote and its number (without the fix applied)
2605 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_UP
);
2606 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_HOME
);
2607 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_SHIFT
| KEY_DOWN
);
2608 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DELETE
);
2610 // Page up moves the cursor from the footnote area to the main text, then
2611 // doing select all and pressing delete removes all the text and footnote references,
2612 // thus removing all the footnotes
2613 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_PAGEUP
);
2614 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, awt::Key::SELECT_ALL
);
2615 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DELETE
);
2617 // Without having fix in place, segfault happens after running next line
2618 Scheduler::ProcessEventsToIdle();
2620 // Without the fix, the above action should have already created a crash,
2621 // but here we also check to make sure that the number of footnotes are
2622 // exactly zero, as expected
2623 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32
>(0), xFootnotes
->getCount());
2626 CPPUNIT_TEST_FIXTURE(SwUiWriterTest3
, testTdf140061
)
2628 createSwDoc("tdf140061.odt");
2630 CPPUNIT_ASSERT_EQUAL(2, getPages());
2632 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2634 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
2637 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
2639 CPPUNIT_ASSERT_EQUAL(2, getPages());
2641 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2643 CPPUNIT_ASSERT_EQUAL(1, getPages());
2645 // Paste special as RTF
2646 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence(
2647 { { "SelectedFormat", uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
2649 dispatchCommand(mxComponent
, u
".uno:ClipboardFormatItems"_ustr
, aPropertyValues
);
2651 CPPUNIT_ASSERT_EQUAL(2, getPages());
2653 // Without the fix in place, this test would have crashed here
2654 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2655 CPPUNIT_ASSERT_EQUAL(1, getPages());
2658 CPPUNIT_PLUGIN_IMPLEMENT();
2660 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */