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/filter/PDFiumLibrary.hxx>
13 #include <vcl/scheduler.hxx>
14 #include <vcl/TypeSerializer.hxx>
15 #include <com/sun/star/awt/FontWeight.hpp>
16 #include <com/sun/star/drawing/GraphicExportFilter.hpp>
17 #include <IDocumentDrawModelAccess.hxx>
18 #include <com/sun/star/text/XTextFrame.hpp>
19 #include <com/sun/star/text/XTextTable.hpp>
20 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
21 #include <com/sun/star/text/XPageCursor.hpp>
22 #include <com/sun/star/view/XSelectionSupplier.hpp>
23 #include <comphelper/propertysequence.hxx>
24 #include <boost/property_tree/json_parser.hpp>
25 #include <frameformats.hxx>
26 #include <tools/json_writer.hxx>
27 #include <unotools/streamwrap.hxx>
28 #include <editeng/lrspitem.hxx>
29 #include <sfx2/linkmgr.hxx>
32 #include <UndoManager.hxx>
33 #include <unotxdoc.hxx>
34 #include <drawdoc.hxx>
35 #include <dcontact.hxx>
36 #include <svx/svdpage.hxx>
39 #include <IDocumentFieldsAccess.hxx>
40 #include <IDocumentLinksAdministration.hxx>
41 #include <IDocumentRedlineAccess.hxx>
42 #include <rootfrm.hxx>
43 #include <redline.hxx>
44 #include <itabenum.hxx>
45 #include <officecfg/Office/Common.hxx>
49 /// 8th set of tests asserting the behavior of Writer user interface shells.
50 class SwUiWriterTest8
: public SwModelTestBase
54 : SwModelTestBase(u
"/sw/qa/extras/uiwriter/data/"_ustr
)
59 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf131684
)
61 createSwDoc("tdf131684.docx");
63 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
64 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
66 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
68 //Use selectAll 3 times in a row
69 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
70 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
71 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
73 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
74 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
76 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
77 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
79 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
80 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
82 // without the fix, it crashes
83 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
84 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
86 // check that the text frame has the correct upper
87 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
88 OUString
const sectionId
= getXPath(pXmlDoc
, "/root/page[1]/body/section[7]", "id");
89 OUString
const sectionLower
= getXPath(pXmlDoc
, "/root/page[1]/body/section[7]", "lower");
90 OUString
const textId
= getXPath(pXmlDoc
, "/root/page[1]/body/section[7]/txt[1]", "id");
91 OUString
const textUpper
= getXPath(pXmlDoc
, "/root/page[1]/body/section[7]/txt[1]", "upper");
92 CPPUNIT_ASSERT_EQUAL(textId
, sectionLower
);
93 CPPUNIT_ASSERT_EQUAL(sectionId
, textUpper
);
96 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf132420
)
98 createSwDoc("tdf132420.odt");
100 CPPUNIT_ASSERT_EQUAL(12, getShapes());
102 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
104 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
105 CPPUNIT_ASSERT_EQUAL(0, getShapes());
107 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
109 //Without the fix in place, 1 frame and 1 image would be gone and getShapes would return 10
110 CPPUNIT_ASSERT_EQUAL(12, getShapes());
113 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf132744
)
115 createSwDoc("tdf132744.odt");
116 SwDoc
* pDoc
= getSwDoc();
118 // disable change tracking to cut the table
119 pDoc
->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::ShowDelete
120 | RedlineFlags::ShowInsert
);
122 CPPUNIT_ASSERT_MESSAGE("redlining should be off",
123 !pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
125 CPPUNIT_ASSERT_EQUAL(1, getShapes());
127 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
129 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
131 CPPUNIT_ASSERT_EQUAL(0, getShapes());
133 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
135 //Without the fix in place, the image wouldn't be pasted
136 CPPUNIT_ASSERT_EQUAL(1, getShapes());
139 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf146622
)
141 createSwDoc("TC-table-del-add.docx");
142 SwDoc
* pDoc
= getSwDoc();
143 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
144 CPPUNIT_ASSERT(pWrtShell
);
146 CPPUNIT_ASSERT_MESSAGE("redlining should be on",
147 pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
149 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY
);
150 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables(),
152 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTables
->getCount());
153 uno::Reference
<container::XNameAccess
> xTableNames
= xTablesSupplier
->getTextTables();
154 CPPUNIT_ASSERT(xTableNames
->hasByName(u
"Table1"_ustr
));
155 uno::Reference
<text::XTextTable
> xTable1(xTableNames
->getByName(u
"Table1"_ustr
),
157 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable1
->getRows()->getCount());
159 dispatchCommand(mxComponent
, u
".uno:DeleteRows"_ustr
, {});
161 // This was 3 (deleting the already deleted row with change tracking)
162 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable1
->getRows()->getCount());
164 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
165 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
167 dispatchCommand(mxComponent
, u
".uno:DeleteRows"_ustr
, {});
168 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable1
->getRows()->getCount());
170 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
171 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
173 dispatchCommand(mxComponent
, u
".uno:DeleteRows"_ustr
, {});
174 // This was 2 (deleting the already deleted table with change tracking)
175 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTables
->getCount());
176 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable1
->getRows()->getCount());
178 // check that the first table was deleted with change tracking
179 dispatchCommand(mxComponent
, u
".uno:AcceptAllTrackedChanges"_ustr
, {});
180 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables
->getCount());
182 // Undo AcceptAllTrackedChanges and DeleteRows
183 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
184 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
186 // now only the second table deleted by AcceptAllTrackedChanges
187 dispatchCommand(mxComponent
, u
".uno:AcceptAllTrackedChanges"_ustr
, {});
188 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables
->getCount());
191 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf146962
)
193 // load a 2-row table, set Hide Changes mode and delete the first row with change tracking
194 createSwDoc("tdf116789.fodt");
195 SwDoc
* pDoc
= getSwDoc();
196 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
197 CPPUNIT_ASSERT(pWrtShell
);
200 dispatchCommand(mxComponent
, u
".uno:TrackChanges"_ustr
, {});
201 CPPUNIT_ASSERT_MESSAGE("redlining should be on",
202 pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
204 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
205 CPPUNIT_ASSERT(pWrtShell
->GetLayout()->IsHideRedlines());
207 dispatchCommand(mxComponent
, u
".uno:DeleteRows"_ustr
, {});
209 // Without the fix in place, the deleted row would be visible
211 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
213 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 1);
215 // check it in Show Changes mode
217 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
218 CPPUNIT_ASSERT(!pWrtShell
->GetLayout()->IsHideRedlines());
220 pXmlDoc
= parseLayoutDump();
221 // 2 rows are visible now
222 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 2);
224 // check it in Hide Changes mode again
226 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
227 CPPUNIT_ASSERT(pWrtShell
->GetLayout()->IsHideRedlines());
229 pXmlDoc
= parseLayoutDump();
230 // only a single row is visible again
231 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 1);
233 // tdf#148227 check Undo of tracked table row deletion
235 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
236 pXmlDoc
= parseLayoutDump();
238 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 2);
241 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf159026
)
243 // load a floating table (tables in DOCX footnotes
244 // imported as floating tables in Writer)
245 createSwDoc("tdf159026.docx");
246 SwDoc
* pDoc
= getSwDoc();
247 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
248 CPPUNIT_ASSERT(pWrtShell
);
251 dispatchCommand(mxComponent
, u
".uno:TrackChanges"_ustr
, {});
252 CPPUNIT_ASSERT_MESSAGE("redlining should be on",
253 pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
255 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
256 CPPUNIT_ASSERT(pWrtShell
->GetLayout()->IsHideRedlines());
258 // select table with SelectionSupplier
259 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
260 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
262 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
264 uno::Reference
<frame::XModel
> xModel(mxComponent
, uno::UNO_QUERY
);
265 uno::Reference
<view::XSelectionSupplier
> xSelSupplier(xModel
->getCurrentController(),
266 uno::UNO_QUERY_THROW
);
267 // select floating table (table in a frame)
268 xSelSupplier
->select(xIndexAccess
->getByIndex(0));
270 // delete table with track changes
271 dispatchCommand(mxComponent
, u
".uno:DeleteTable"_ustr
, {});
273 // tracked table deletion
274 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
277 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
278 assertXPath(pXmlDoc
, "//tab", 0);
281 uno::Reference
<text::XTextFramesSupplier
> xTextFramesSupplier(mxComponent
, uno::UNO_QUERY
);
282 uno::Reference
<container::XIndexAccess
> xIndexAccess2(xTextFramesSupplier
->getTextFrames(),
284 xSelSupplier
->select(xIndexAccess2
->getByIndex(0));
285 dispatchCommand(mxComponent
, u
".uno:Delete"_ustr
, {});
287 // undo frame deletion
288 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
290 // undo tracked table deletion
292 // This resulted crashing
293 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
296 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf147347
)
298 // load a 2-row table, set Hide Changes mode and delete the table with change tracking
299 createSwDoc("tdf116789.fodt");
300 SwDoc
* pDoc
= getSwDoc();
301 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
302 CPPUNIT_ASSERT(pWrtShell
);
305 dispatchCommand(mxComponent
, u
".uno:TrackChanges"_ustr
, {});
306 CPPUNIT_ASSERT_MESSAGE("redlining should be on",
307 pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
309 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
310 CPPUNIT_ASSERT(pWrtShell
->GetLayout()->IsHideRedlines());
312 dispatchCommand(mxComponent
, u
".uno:DeleteTable"_ustr
, {});
314 // Without the fix in place, the deleted row would be visible
316 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
318 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 0);
320 // check it in Show Changes mode
322 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
323 CPPUNIT_ASSERT(!pWrtShell
->GetLayout()->IsHideRedlines());
325 pXmlDoc
= parseLayoutDump();
326 // 2 rows are visible now
327 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 2);
329 // check it in Hide Changes mode again
331 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
332 CPPUNIT_ASSERT(pWrtShell
->GetLayout()->IsHideRedlines());
334 pXmlDoc
= parseLayoutDump();
335 // no visible row again
336 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 0);
338 // tdf#148228 check Undo of tracked table deletion
340 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
341 pXmlDoc
= parseLayoutDump();
343 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 2);
346 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf153819
)
348 // copy a table before a deleted table in Hide Changes mode
349 createSwDoc("tdf153819.fodt");
350 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
351 CPPUNIT_ASSERT(pWrtShell
);
354 CPPUNIT_ASSERT(pWrtShell
->GetLayout()->IsHideRedlines());
356 dispatchCommand(mxComponent
, u
".uno:SelectTable"_ustr
, {});
357 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
358 dispatchCommand(mxComponent
, u
".uno:GoDown"_ustr
, {});
360 // Without the fix in place, this test would have crashed here
361 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
363 // FIXME: Show Changes, otherwise ~SwTableNode() would have crashed
364 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
367 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf148345
)
369 // load a 2-row table, set Hide Changes mode and delete the first row with change tracking
370 createSwDoc("tdf116789.fodt");
371 SwDoc
* pDoc
= getSwDoc();
372 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
373 CPPUNIT_ASSERT(pWrtShell
);
376 dispatchCommand(mxComponent
, u
".uno:TrackChanges"_ustr
, {});
377 CPPUNIT_ASSERT_MESSAGE("redlining should be on",
378 pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
380 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
381 CPPUNIT_ASSERT(pWrtShell
->GetLayout()->IsHideRedlines());
383 dispatchCommand(mxComponent
, u
".uno:DeleteRows"_ustr
, {});
385 // Without the fix in place, the deleted row would be visible
387 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
389 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 1);
391 // check it in Show Changes mode
393 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
394 CPPUNIT_ASSERT(!pWrtShell
->GetLayout()->IsHideRedlines());
396 pXmlDoc
= parseLayoutDump();
397 // 2 rows are visible now
398 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 2);
400 // check it in Hide Changes mode again
402 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
403 CPPUNIT_ASSERT(pWrtShell
->GetLayout()->IsHideRedlines());
405 pXmlDoc
= parseLayoutDump();
406 // only a single row is visible again
407 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 1);
409 // tdf#148227 check Reject All of tracked table row deletion
411 dispatchCommand(mxComponent
, u
".uno:RejectAllTrackedChanges"_ustr
, {});
412 pXmlDoc
= parseLayoutDump();
414 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 2);
417 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf141391
)
419 // table insertion in the first paragraph of the cell
420 // overwrites the row content, instead of inserting a nested table
422 // load a 2-row table
423 createSwDoc("tdf116789.fodt");
424 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
425 CPPUNIT_ASSERT(pWrtShell
);
427 // select the table, and copy it into at paragraph start of cell "A2"
429 dispatchCommand(mxComponent
, u
".uno:SelectTable"_ustr
, {});
430 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
431 // remove the selection and positionate the cursor at beginning of A2
432 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/false, 1, /*bBasicCall=*/false);
433 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
435 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
436 // 3-row, overwriting cells of the second row and inserting a new row
437 // with the 2-row clipboard table content
438 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 3);
439 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[2]/cell[1]/txt/SwParaPortion/SwLineLayout",
440 "portion", u
"hello");
444 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
445 pXmlDoc
= parseLayoutDump();
446 // 2 rows again, no copied text content
447 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 2);
448 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[2]/cell[1]/SwParaPortion", 0);
450 // insert the 2-row table into the second paragraph of cell "A2" as a nested table
451 // For this it's enough to positionate the text cursor not in the first paragraph
453 // insert some text and an empty paragraph
454 pWrtShell
->Insert(u
"Some text..."_ustr
);
455 pWrtShell
->SplitNode();
456 Scheduler::ProcessEventsToIdle();
457 pXmlDoc
= parseLayoutDump();
458 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 2);
459 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[2]/cell[1]/txt", 2);
460 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[2]/cell[1]/txt[1]/SwParaPortion/SwLineLayout",
461 "portion", u
"Some text...");
462 // the empty paragraph in A2
463 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[2]/cell[1]/txt[2]/SwParaPortion", 0);
465 // insert the table, as a nested one in cell "A2"
466 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
467 pXmlDoc
= parseLayoutDump();
468 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 2);
469 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[2]/cell[1]/tab", 1);
470 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[2]/cell[1]/tab/row", 2);
474 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
475 pXmlDoc
= parseLayoutDump();
476 // 2 rows again, no copied text content
477 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 2);
478 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[2]/cell[1]/txt[1]/SwParaPortion/SwLineLayout",
479 "portion", u
"Some text...");
481 // copy the 2-row table into the first paragraph of cell "A2",
482 // but not at paragraph start (changed behaviour)
484 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/false, 1, /*bBasicCall=*/false);
485 pWrtShell
->Insert(u
"and some text again in the first paragraph to be sure..."_ustr
);
486 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
488 pXmlDoc
= parseLayoutDump();
490 // 3-row, overwriting cells of the second row and inserting a new row
491 // with the 2-row clipboard table content
493 // This was 2 (nested table)
494 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 3);
495 // This was "Some text..." with a nested table
496 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[2]/cell[1]/txt/SwParaPortion/SwLineLayout",
497 "portion", u
"hello");
500 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf148791
)
502 // test Paste as Rows Above with centered table alignment
504 // load a 2-row table
505 createSwDoc("tdf116789.fodt");
506 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
507 CPPUNIT_ASSERT(pWrtShell
);
509 // select and copy the table, and Paste As Rows Above
511 dispatchCommand(mxComponent
, u
".uno:SelectTable"_ustr
, {});
512 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
513 // remove the selection and positionate the cursor at beginning of A2
514 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/false, 1, /*bBasicCall=*/false);
515 pWrtShell
->Up(/*bSelect=*/false);
516 dispatchCommand(mxComponent
, u
".uno:PasteRowsBefore"_ustr
, {});
518 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
519 // Paste as Rows Above results 4-row table with default table alignment
520 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 4);
521 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[1]/cell[1]/txt/SwParaPortion/SwLineLayout",
522 "portion", u
"hello");
523 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[3]/cell[1]/txt/SwParaPortion/SwLineLayout",
524 "portion", u
"hello");
526 // set table alignment to center, select and copy the table again
527 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
528 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
530 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
532 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
534 // Default table alignment
535 CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::FULL
,
536 getProperty
<sal_Int16
>(xTextTable
, u
"HoriOrient"_ustr
));
538 //CPPUNIT_ASSERT_EQUAL(OUString(""), getProperty<OUString>(xTextTable, "TableTemplateName"));
539 uno::Reference
<beans::XPropertySet
> xTableProps(xTextTable
, uno::UNO_QUERY_THROW
);
541 xTableProps
->setPropertyValue(u
"HoriOrient"_ustr
, uno::Any(text::HoriOrientation::CENTER
));
543 CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::CENTER
,
544 getProperty
<sal_Int16
>(xTextTable
, u
"HoriOrient"_ustr
));
546 dispatchCommand(mxComponent
, u
".uno:SelectTable"_ustr
, {});
547 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
548 // remove the selection and positionate the cursor at beginning of A2
549 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/false, 1, /*bBasicCall=*/false);
550 pWrtShell
->Up(/*bSelect=*/false);
551 pWrtShell
->Up(/*bSelect=*/false);
552 pWrtShell
->Up(/*bSelect=*/false);
553 dispatchCommand(mxComponent
, u
".uno:PasteRowsBefore"_ustr
, {});
555 pXmlDoc
= parseLayoutDump();
556 // This was 5 (inserting only a single row for the 4-row clipboard content, and
557 // overwriting 3 existing rows)
558 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 8);
559 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[1]/cell[1]/txt/SwParaPortion/SwLineLayout",
560 "portion", u
"hello");
561 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[3]/cell[1]/txt/SwParaPortion/SwLineLayout",
562 "portion", u
"hello");
563 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[5]/cell[1]/txt/SwParaPortion/SwLineLayout",
564 "portion", u
"hello");
565 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row[7]/cell[1]/txt/SwParaPortion/SwLineLayout",
566 "portion", u
"hello");
568 // tdf#64902 add a test case for nested tables
570 // insert a nested table, and copy as paste as rows above the whole table with it
571 dispatchCommand(mxComponent
, u
".uno:PasteNestedTable"_ustr
, {});
572 dispatchCommand(mxComponent
, u
".uno:SelectTable"_ustr
, {});
573 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
574 // remove the selection and positionate the cursor at beginning of A2
575 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/false, 1, /*bBasicCall=*/false);
576 // skip 7 table rows plus 4 rows of the nested table
577 for (int i
= 0; i
< 7 + 4; ++i
)
578 pWrtShell
->Up(/*bSelect=*/false);
579 dispatchCommand(mxComponent
, u
".uno:PasteRowsBefore"_ustr
, {});
581 pXmlDoc
= parseLayoutDump();
582 // rows of the nested table doesn't effect row number of the main table
583 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 16);
584 // there are two nested tables after the paste
585 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row/cell/tab", 2);
587 // tdf#64902 add a test case for repeated table headings
589 xTableProps
->setPropertyValue(u
"RepeatHeadline"_ustr
, uno::Any(true));
590 CPPUNIT_ASSERT(getProperty
<bool>(xTextTable
, u
"RepeatHeadline"_ustr
));
592 xTableProps
->setPropertyValue(u
"HeaderRowCount"_ustr
, uno::Any(sal_Int32(3)));
593 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getProperty
<sal_Int32
>(xTextTable
, u
"HeaderRowCount"_ustr
));
595 dispatchCommand(mxComponent
, u
".uno:SelectTable"_ustr
, {});
596 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
597 // remove the selection and positionate the cursor at beginning of A2
598 pWrtShell
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/false, 1, /*bBasicCall=*/false);
599 // skip 15 table rows plus 4 * 2 rows of the nested tables
600 for (int i
= 0; i
< 15 + 4 * 2; ++i
)
601 pWrtShell
->Up(/*bSelect=*/false);
602 dispatchCommand(mxComponent
, u
".uno:PasteRowsBefore"_ustr
, {});
604 pXmlDoc
= parseLayoutDump();
605 // repeating table header (and its thead/tbody indentation) doesn't effect row number
606 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row", 32);
607 // there are two nested tables after the paste
608 assertXPath(pXmlDoc
, "/root/page[1]/body/tab/row/cell/tab", 4);
611 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf135014
)
615 uno::Sequence
<beans::PropertyValue
> aArgs(
616 comphelper::InitPropertySequence({ { "KeyModifier", uno::Any(sal_Int32(0)) } }));
618 // Toggle Numbering List
619 dispatchCommand(mxComponent
, u
".uno:DefaultBullet"_ustr
, aArgs
);
621 uno::Sequence
<beans::PropertyValue
> aArgs2(comphelper::InitPropertySequence(
622 { { "Param", uno::Any(u
"NewNumberingStyle"_ustr
) },
623 { "Family", uno::Any(static_cast<sal_Int16
>(SfxStyleFamily::Pseudo
)) } }));
625 // New Style from selection
626 dispatchCommand(mxComponent
, u
".uno:StyleNewByExample"_ustr
, aArgs2
);
628 // Without the fix in place, this test would have failed here
629 saveAndReload(u
"Office Open XML Text"_ustr
);
631 xmlDocUniquePtr pXmlStyles
= parseExport(u
"word/styles.xml"_ustr
);
632 assertXPath(pXmlStyles
, "/w:styles/w:style[@w:styleId='NewNumberingStyle']/w:qFormat", 1);
635 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf130629
)
639 uno::Sequence
<beans::PropertyValue
> aArgs(
640 comphelper::InitPropertySequence({ { "KeyModifier", uno::Any(KEY_MOD1
) } }));
642 dispatchCommand(mxComponent
, u
".uno:BasicShapes.diamond"_ustr
, aArgs
);
644 CPPUNIT_ASSERT_EQUAL(1, getShapes());
647 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
648 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
650 CPPUNIT_ASSERT_EQUAL(0, getShapes());
652 // Shape toolbar is active, use ESC before inserting a new shape
653 SwXTextDocument
* pTextDoc
= getSwTextDoc();
654 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_ESCAPE
);
655 Scheduler::ProcessEventsToIdle();
657 // Without the fix in place, this test would have crashed here
658 dispatchCommand(mxComponent
, u
".uno:BasicShapes.diamond"_ustr
, aArgs
);
660 CPPUNIT_ASSERT_EQUAL(1, getShapes());
663 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf145584
)
665 std::shared_ptr
<vcl::pdf::PDFium
> pPDFium
= vcl::pdf::PDFiumLibrary::get();
671 SwWrtShell
* const pWrtSh
= getSwDocShell()->GetWrtShell();
672 CPPUNIT_ASSERT(pWrtSh
);
674 pWrtSh
->Insert(u
"Hello World"_ustr
);
677 pWrtSh
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/true, 5, /*bBasicCall=*/false);
680 uno::Sequence
<beans::PropertyValue
> aFilterData(
681 comphelper::InitPropertySequence({ { "Selection", uno::Any(true) } }));
683 uno::Sequence
<beans::PropertyValue
> aDescriptor(
684 comphelper::InitPropertySequence({ { "FilterName", uno::Any(u
"writer_pdf_Export"_ustr
) },
685 { "FilterData", uno::Any(aFilterData
) },
686 { "URL", uno::Any(maTempFile
.GetURL()) } }));
688 // Without the fix in place, this test would have crashed here
689 dispatchCommand(mxComponent
, u
".uno:ExportToPDF"_ustr
, aDescriptor
);
691 std::unique_ptr
<vcl::pdf::PDFiumDocument
> pPdfDocument
= parsePDFExport();
692 CPPUNIT_ASSERT_EQUAL(1, pPdfDocument
->getPageCount());
693 std::unique_ptr
<vcl::pdf::PDFiumPage
> pPdfPage
= pPdfDocument
->openPage(/*nIndex=*/0);
694 CPPUNIT_ASSERT(pPdfPage
);
695 CPPUNIT_ASSERT_EQUAL(1, pPdfPage
->getObjectCount());
696 std::unique_ptr
<vcl::pdf::PDFiumTextPage
> pPdfTextPage
= pPdfPage
->getTextPage();
697 CPPUNIT_ASSERT(pPdfTextPage
);
699 std::unique_ptr
<vcl::pdf::PDFiumPageObject
> pPageObject
= pPdfPage
->getObject(0);
700 OUString sText
= pPageObject
->getText(pPdfTextPage
);
701 CPPUNIT_ASSERT_EQUAL(u
"World"_ustr
, sText
);
704 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf131728
)
706 std::shared_ptr
<vcl::pdf::PDFium
> pPDFium
= vcl::pdf::PDFiumLibrary::get();
711 createSwDoc("tdf131728.docx");
712 SwDoc
* const pDoc
= getSwDoc();
713 SwWrtShell
* const pWrtSh
= pDoc
->GetDocShell()->GetWrtShell();
714 CPPUNIT_ASSERT(pWrtSh
);
717 uno::Sequence
<beans::PropertyValue
> aFilterData(comphelper::InitPropertySequence(
718 { { "ExportBookmarksToPDFDestination", uno::Any(true) } }));
720 uno::Sequence
<beans::PropertyValue
> aDescriptor(
721 comphelper::InitPropertySequence({ { "FilterName", uno::Any(u
"writer_pdf_Export"_ustr
) },
722 { "FilterData", uno::Any(aFilterData
) },
723 { "URL", uno::Any(maTempFile
.GetURL()) } }));
725 dispatchCommand(mxComponent
, u
".uno:ExportToPDF"_ustr
, aDescriptor
);
727 std::unique_ptr
<vcl::pdf::PDFiumDocument
> pPdfDocument
= parsePDFExport();
728 CPPUNIT_ASSERT_EQUAL(1, pPdfDocument
->getPageCount());
730 std::unique_ptr
<vcl::pdf::PDFiumPage
> pPdfPage
= pPdfDocument
->openPage(/*nIndex=*/0);
731 CPPUNIT_ASSERT(pPdfPage
);
733 // Without the fix in place, this test would have bad order
734 // (starting with the outlines of text frames)
735 CPPUNIT_ASSERT_EQUAL(u
"Article 1. Definitions\n"
740 "Article 2. Three style separators in one line!\n"
742 " Heading 2 Again\n"_ustr
,
743 pPdfDocument
->getBookmarks());
746 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf95239
)
748 std::shared_ptr
<vcl::pdf::PDFium
> pPDFium
= vcl::pdf::PDFiumLibrary::get();
753 createSwDoc("tdf95239.fodt");
754 SwDoc
* const pDoc
= getSwDoc();
755 SwWrtShell
* const pWrtSh
= pDoc
->GetDocShell()->GetWrtShell();
756 CPPUNIT_ASSERT(pWrtSh
);
759 uno::Sequence
<beans::PropertyValue
> aFilterData(comphelper::InitPropertySequence(
760 { { "ExportBookmarksToPDFDestination", uno::Any(true) } }));
762 uno::Sequence
<beans::PropertyValue
> aDescriptor(
763 comphelper::InitPropertySequence({ { "FilterName", uno::Any(u
"writer_pdf_Export"_ustr
) },
764 { "FilterData", uno::Any(aFilterData
) },
765 { "URL", uno::Any(maTempFile
.GetURL()) } }));
767 dispatchCommand(mxComponent
, u
".uno:ExportToPDF"_ustr
, aDescriptor
);
769 std::unique_ptr
<vcl::pdf::PDFiumDocument
> pPdfDocument
= parsePDFExport();
770 CPPUNIT_ASSERT_EQUAL(2, pPdfDocument
->getPageCount());
772 std::unique_ptr
<vcl::pdf::PDFiumPage
> pPdfPage
= pPdfDocument
->openPage(/*nIndex=*/0);
773 CPPUNIT_ASSERT(pPdfPage
);
775 // Without the fix in place, this test would have bad order
776 // (starting with the outlines of text frames)
777 CPPUNIT_ASSERT_EQUAL(u
"H1\n"
802 pPdfDocument
->getBookmarks());
805 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf152575
)
807 // FIXME: the DPI check should be removed when either (1) the test is fixed to work with
808 // non-default DPI; or (2) unit tests on Windows are made to use svp VCL plugin.
811 std::shared_ptr
<vcl::pdf::PDFium
> pPDFium
= vcl::pdf::PDFiumLibrary::get();
815 createSwDoc("152575.fodt");
818 uno::Sequence
<beans::PropertyValue
> aFilterData(
819 comphelper::InitPropertySequence({ { "ExportNotesInMargin", uno::Any(true) } }));
821 uno::Sequence
<beans::PropertyValue
> aDescriptor(
822 comphelper::InitPropertySequence({ { "FilterName", uno::Any(u
"writer_pdf_Export"_ustr
) },
823 { "FilterData", uno::Any(aFilterData
) },
824 { "URL", uno::Any(maTempFile
.GetURL()) } }));
826 // Without the fix in place, this test would have crashed here
827 dispatchCommand(mxComponent
, u
".uno:ExportToPDF"_ustr
, aDescriptor
);
829 std::unique_ptr
<vcl::pdf::PDFiumDocument
> pPdfDocument
= parsePDFExport();
830 CPPUNIT_ASSERT_EQUAL(3, pPdfDocument
->getPageCount());
831 std::unique_ptr
<vcl::pdf::PDFiumPage
> pPdfPage
= pPdfDocument
->openPage(/*nIndex=*/1);
832 CPPUNIT_ASSERT(pPdfPage
);
833 // Without the fix for tdf#152575 this would be only 42 objects
834 CPPUNIT_ASSERT_EQUAL(50, pPdfPage
->getObjectCount());
837 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf140731
)
840 SwDoc
* const pDoc
= getSwDoc();
841 SwWrtShell
* const pWrtSh
= getSwDocShell()->GetWrtShell();
842 CPPUNIT_ASSERT(pWrtSh
);
844 pWrtSh
->Insert(u
"Lorem"_ustr
);
846 SwXTextDocument
* pTextDoc
= getSwTextDoc();
847 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_F3
);
848 Scheduler::ProcessEventsToIdle();
850 // generating a big text with ~60k words and several paragraphs
851 for (sal_Int32 i
= 0; i
< 8; ++i
)
853 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
855 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
857 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
859 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
862 dispatchCommand(mxComponent
, u
".uno:GoToStartOfDoc"_ustr
, {});
864 // Format->Text operations on small selections (which would generate <~500 redlines)
865 // changetracking still working
866 dispatchCommand(mxComponent
, u
".uno:TrackChanges"_ustr
, {});
868 SwCursorShell
* pShell(pDoc
->GetEditShell());
869 CPPUNIT_ASSERT(pShell
);
871 pShell
->SelectTextModel(1, 500);
873 dispatchCommand(mxComponent
, u
".uno:ChangeCaseToTitleCase"_ustr
, {});
875 SwEditShell
* const pEditShell(pDoc
->GetEditShell());
876 CPPUNIT_ASSERT(pEditShell
);
877 CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type
>(120),
878 pEditShell
->GetRedlineCount());
880 //Removing all the redlines.
881 dispatchCommand(mxComponent
, u
".uno:RejectAllTrackedChanges"_ustr
, {});
883 CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type
>(0), pEditShell
->GetRedlineCount());
885 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
887 dispatchCommand(mxComponent
, u
".uno:ChangeCaseToTitleCase"_ustr
, {});
889 // Without the fix in place, on big selections writer would freeze. Now it ignores change tracking.
890 CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type
>(0), pEditShell
->GetRedlineCount());
892 // The patch has no effects on the Format->Text operations
893 CPPUNIT_ASSERT(getParagraph(1)->getString().startsWith("Lorem Ipsum Dolor Sit Amet"));
895 dispatchCommand(mxComponent
, u
".uno:ChangeCaseToUpper"_ustr
, {});
897 CPPUNIT_ASSERT(getParagraph(1)->getString().startsWith("LOREM IPSUM DOLOR SIT AMET"));
900 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf116315
)
903 SwWrtShell
* const pWrtSh
= getSwDocShell()->GetWrtShell();
904 CPPUNIT_ASSERT(pWrtSh
);
906 pWrtSh
->Insert(u
"This is a test"_ustr
);
907 pWrtSh
->Left(SwCursorSkipMode::Chars
, /*bSelect=*/true, 4, /*bBasicCall=*/false);
909 SwXTextDocument
* pTextDoc
= getSwTextDoc();
910 for (sal_Int32 i
= 0; i
< 5; ++i
)
912 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_SHIFT
| KEY_F3
);
913 Scheduler::ProcessEventsToIdle();
916 CPPUNIT_ASSERT_EQUAL(u
"This is a Test"_ustr
, getParagraph(1)->getString());
918 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_SHIFT
| KEY_F3
);
919 Scheduler::ProcessEventsToIdle();
922 CPPUNIT_ASSERT_EQUAL(u
"This is a TEST"_ustr
, getParagraph(1)->getString());
924 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_SHIFT
| KEY_F3
);
925 Scheduler::ProcessEventsToIdle();
928 CPPUNIT_ASSERT_EQUAL(u
"This is a test"_ustr
, getParagraph(1)->getString());
932 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testInsertAutoTextIntoListFromParaStyle
)
934 createSwDoc("stylewithlistandindents.fodt");
935 SwWrtShell
* const pWrtShell
= getSwDocShell()->GetWrtShell();
936 CPPUNIT_ASSERT(pWrtShell
);
938 pWrtShell
->FwdPara();
939 pWrtShell
->EndPara(/*bSelect=*/false);
940 // expands autotext (via F3)
941 pWrtShell
->Insert(u
" jacr"_ustr
);
943 SwXTextDocument
* pTextDoc
= getSwTextDoc();
944 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_F3
);
945 Scheduler::ProcessEventsToIdle();
947 pWrtShell
->SttEndDoc(/*bStt=*/true);
948 pWrtShell
->FwdPara();
951 SvxTextLeftMarginItem
const* pTextLeftMargin
;
952 SvxFirstLineIndentItem
const* pFirstLineIndent
;
955 SwTextNode
& rNode
{ *pWrtShell
->GetCursor()->GetPoint()->GetNode().GetTextNode() };
956 // numrule from paragraph style, but not from direct formatting
957 auto pSet
{ rNode
.GetpSwAttrSet() };
958 CPPUNIT_ASSERT(pSet
);
960 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_PARATR_LIST_ID
, false));
961 // the numrule is set on the paragraph style, not on the paragraph
962 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
, pSet
->GetItemState(RES_PARATR_NUMRULE
, false));
963 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_PARATR_NUMRULE
, true));
964 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
,
965 pSet
->GetItemState(RES_MARGIN_FIRSTLINE
, false));
966 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_MARGIN_FIRSTLINE
, true));
967 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
, pSet
->GetItemState(RES_MARGIN_TEXTLEFT
, false));
968 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_MARGIN_TEXTLEFT
, true));
969 CPPUNIT_ASSERT_EQUAL(u
"ListAndIndents"_ustr
, rNode
.GetTextColl()->GetName());
970 CPPUNIT_ASSERT_EQUAL(u
"Item We confirm receipt of your application material."_ustr
,
972 pNumRule
= rNode
.GetNumRule();
973 pTextLeftMargin
= &rNode
.GetAttr(RES_MARGIN_TEXTLEFT
);
974 pFirstLineIndent
= &rNode
.GetAttr(RES_MARGIN_FIRSTLINE
);
977 pWrtShell
->FwdPara();
980 SwTextNode
& rNode
{ *pWrtShell
->GetCursor()->GetPoint()->GetNode().GetTextNode() };
981 auto pSet
{ rNode
.GetpSwAttrSet() };
982 CPPUNIT_ASSERT(pSet
);
984 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_PARATR_LIST_ID
, false));
985 // middle paragraph was pasted - has numrule and indents applied directly
986 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_PARATR_NUMRULE
, false));
987 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_MARGIN_FIRSTLINE
, false));
988 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_MARGIN_TEXTLEFT
, false));
989 CPPUNIT_ASSERT_EQUAL(u
"Default Paragraph Style"_ustr
, rNode
.GetTextColl()->GetName());
990 CPPUNIT_ASSERT(rNode
.GetText().startsWith("As more applicants applied"));
991 CPPUNIT_ASSERT_EQUAL(pNumRule
, rNode
.GetNumRule());
992 CPPUNIT_ASSERT_EQUAL(pTextLeftMargin
->ResolveTextLeft({}),
993 rNode
.GetAttr(RES_MARGIN_TEXTLEFT
).ResolveTextLeft({}));
994 CPPUNIT_ASSERT_EQUAL(pFirstLineIndent
->ResolveTextFirstLineOffset({}),
995 rNode
.GetAttr(RES_MARGIN_FIRSTLINE
).ResolveTextFirstLineOffset({}));
998 pWrtShell
->FwdPara();
1001 SwTextNode
& rNode
{ *pWrtShell
->GetCursor()->GetPoint()->GetNode().GetTextNode() };
1002 // numrule from paragraph style, but not from direct formatting
1003 auto pSet
{ rNode
.GetpSwAttrSet() };
1004 CPPUNIT_ASSERT(pSet
);
1006 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_PARATR_LIST_ID
, false));
1007 // the numrule is set on the paragraph style, not on the paragraph
1008 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
, pSet
->GetItemState(RES_PARATR_NUMRULE
, false));
1009 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_PARATR_NUMRULE
, true));
1010 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
,
1011 pSet
->GetItemState(RES_MARGIN_FIRSTLINE
, false));
1012 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_MARGIN_FIRSTLINE
, true));
1013 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
, pSet
->GetItemState(RES_MARGIN_TEXTLEFT
, false));
1014 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_MARGIN_TEXTLEFT
, true));
1015 CPPUNIT_ASSERT_EQUAL(u
"ListAndIndents"_ustr
, rNode
.GetTextColl()->GetName());
1016 CPPUNIT_ASSERT(rNode
.GetText().endsWith("as soon as we have come to a decision."));
1017 CPPUNIT_ASSERT_EQUAL(pNumRule
, rNode
.GetNumRule());
1018 CPPUNIT_ASSERT_EQUAL(pTextLeftMargin
->ResolveTextLeft({}),
1019 rNode
.GetAttr(RES_MARGIN_TEXTLEFT
).ResolveTextLeft({}));
1020 CPPUNIT_ASSERT_EQUAL(pFirstLineIndent
->ResolveTextFirstLineOffset({}),
1021 rNode
.GetAttr(RES_MARGIN_FIRSTLINE
).ResolveTextFirstLineOffset({}));
1024 pWrtShell
->FwdPara();
1027 SwTextNode
& rNode
{ *pWrtShell
->GetCursor()->GetPoint()->GetNode().GetTextNode() };
1028 // numrule from paragraph style, but not from direct formatting
1029 auto pSet
{ rNode
.GetpSwAttrSet() };
1030 CPPUNIT_ASSERT(pSet
);
1032 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_PARATR_LIST_ID
, false));
1033 // the numrule is set on the paragraph style, not on the paragraph
1034 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
, pSet
->GetItemState(RES_PARATR_NUMRULE
, false));
1035 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_PARATR_NUMRULE
, true));
1036 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
,
1037 pSet
->GetItemState(RES_MARGIN_FIRSTLINE
, false));
1038 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_MARGIN_FIRSTLINE
, true));
1039 CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT
, pSet
->GetItemState(RES_MARGIN_TEXTLEFT
, false));
1040 CPPUNIT_ASSERT_EQUAL(SfxItemState::SET
, pSet
->GetItemState(RES_MARGIN_TEXTLEFT
, true));
1041 CPPUNIT_ASSERT_EQUAL(u
"ListAndIndents"_ustr
, rNode
.GetTextColl()->GetName());
1042 CPPUNIT_ASSERT_EQUAL(u
"more"_ustr
, rNode
.GetText()); // pre-existing list item
1043 CPPUNIT_ASSERT_EQUAL(pNumRule
, rNode
.GetNumRule());
1044 CPPUNIT_ASSERT_EQUAL(pTextLeftMargin
->ResolveTextLeft({}),
1045 rNode
.GetAttr(RES_MARGIN_TEXTLEFT
).ResolveTextLeft({}));
1046 CPPUNIT_ASSERT_EQUAL(pFirstLineIndent
->ResolveTextFirstLineOffset({}),
1047 rNode
.GetAttr(RES_MARGIN_FIRSTLINE
).ResolveTextFirstLineOffset({}));
1051 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf144364
)
1054 SwWrtShell
* const pWrtSh
= getSwDocShell()->GetWrtShell();
1055 CPPUNIT_ASSERT(pWrtSh
);
1057 // expands autotext (via F3)
1058 pWrtSh
->Insert(u
"AR"_ustr
);
1060 SwXTextDocument
* pTextDoc
= getSwTextDoc();
1061 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_F3
);
1062 Scheduler::ProcessEventsToIdle();
1064 // was ...'letter of <placeholder:"November 21, 2004":"Click placeholder and overwrite">'
1065 CPPUNIT_ASSERT_EQUAL(
1066 u
"We hereby acknowledge the receipt of your letter of <November 21, 2004>."_ustr
,
1067 getParagraph(1)->getString());
1070 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf146248
)
1072 createSwDoc("tdf146248.docx");
1074 uno::Reference
<beans::XPropertySet
> xPageStyle(
1075 getStyles(u
"PageStyles"_ustr
)->getByName(u
"Standard"_ustr
), uno::UNO_QUERY
);
1076 CPPUNIT_ASSERT_EQUAL(true, getProperty
<bool>(xPageStyle
, u
"HeaderIsOn"_ustr
));
1078 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1080 // Delete the header
1081 pWrtShell
->ChangeHeaderOrFooter(u
"Default Page Style", true, false, false);
1083 CPPUNIT_ASSERT_EQUAL(false, getProperty
<bool>(xPageStyle
, u
"HeaderIsOn"_ustr
));
1085 // Without the fix in place, this test would have crashed here
1086 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1088 CPPUNIT_ASSERT_EQUAL(true, getProperty
<bool>(xPageStyle
, u
"HeaderIsOn"_ustr
));
1091 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf161741
)
1093 // Redo of header change causes LO to crash
1095 SwDoc
* pDoc
= getSwDoc();
1096 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1097 sw::UndoManager
& rUndoManager
= pDoc
->GetUndoManager();
1099 uno::Reference
<beans::XPropertySet
> xPageStyle(
1100 getStyles(u
"PageStyles"_ustr
)->getByName(u
"Standard"_ustr
), uno::UNO_QUERY
);
1102 // sanity checks: verify baseline status
1103 CPPUNIT_ASSERT_EQUAL(false, getProperty
<bool>(xPageStyle
, u
"HeaderIsOn"_ustr
));
1104 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rUndoManager
.GetUndoActionCount());
1107 pWrtShell
->ChangeHeaderOrFooter(u
"Default Page Style", /*header*/ true, /*on*/ true, false);
1108 CPPUNIT_ASSERT_EQUAL(true, getProperty
<bool>(xPageStyle
, u
"HeaderIsOn"_ustr
));
1110 // create an additional non-header undo point
1111 pWrtShell
->Insert(u
"crash_test"_ustr
); // three undo points
1112 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), rUndoManager
.GetUndoActionCount());
1114 // undo all the changes in one pass
1115 uno::Sequence
<beans::PropertyValue
> aPropertyValues(comphelper::InitPropertySequence({
1116 { "Undo", uno::Any(sal_Int32(4)) },
1118 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, aPropertyValues
); // undo all 4 actions
1119 CPPUNIT_ASSERT_EQUAL(false, getProperty
<bool>(xPageStyle
, u
"HeaderIsOn"_ustr
));
1120 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), rUndoManager
.GetUndoActionCount());
1122 // Crash avoided by clearing the entire redo stack. This redo request will do nothing.
1123 // Without the fix in place, this test would have crashed here
1124 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {}); // redo first (Header) change
1125 // Since Redo is "cleared", the redo did nothing, thus the Header remains off
1126 CPPUNIT_ASSERT_EQUAL(false, getProperty
<bool>(xPageStyle
, u
"HeaderIsOn"_ustr
));
1129 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf152964
)
1133 dispatchCommand(mxComponent
, u
".uno:TrackChanges"_ustr
, {});
1134 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
1136 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
1137 { { "Rows", uno::Any(sal_Int32(2)) }, { "Columns", uno::Any(sal_Int32(2)) } }));
1139 dispatchCommand(mxComponent
, u
".uno:InsertTable"_ustr
, aArgs
);
1141 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1142 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1144 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1145 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1146 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getRows()->getCount());
1147 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getColumns()->getCount());
1149 SwDoc
* pDoc
= getSwDoc();
1150 SwEditShell
* const pEditShell(pDoc
->GetEditShell());
1151 CPPUNIT_ASSERT(pEditShell
);
1152 CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type
>(1), pEditShell
->GetRedlineCount());
1153 dispatchCommand(mxComponent
, u
".uno:GoDown"_ustr
, {});
1154 dispatchCommand(mxComponent
, u
".uno:DeleteRows"_ustr
, {});
1155 dispatchCommand(mxComponent
, u
".uno:DeleteRows"_ustr
, {});
1157 CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type
>(2), pEditShell
->GetRedlineCount());
1159 // Without the fix in place, this test would have crashed here
1160 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1162 CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type
>(1), pEditShell
->GetRedlineCount());
1164 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1166 CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type
>(0), pEditShell
->GetRedlineCount());
1168 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {});
1170 CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type
>(1), pEditShell
->GetRedlineCount());
1171 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {});
1173 CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type
>(2), pEditShell
->GetRedlineCount());
1176 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf107427
)
1182 u
".uno:InsertPageHeader?PageStyle:string=Default%20Page%20Style&On:bool=true"_ustr
, {});
1183 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
1184 { { "Rows", uno::Any(sal_Int32(2)) }, { "Columns", uno::Any(sal_Int32(2)) } }));
1186 dispatchCommand(mxComponent
, u
".uno:InsertTable"_ustr
, aArgs
);
1188 xmlDocUniquePtr pLayout
= parseLayoutDump();
1189 assertXPath(pLayout
, "/root/page[1]/header/tab/row", 2);
1191 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1192 // Delete the header
1193 pWrtShell
->ChangeHeaderOrFooter(u
"Default Page Style", true, false, false);
1195 pLayout
= parseLayoutDump();
1196 assertXPath(pLayout
, "/root/page[1]/header", 0);
1198 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1200 pLayout
= parseLayoutDump();
1201 assertXPath(pLayout
, "/root/page[1]/header/tab/row", 2);
1204 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf141613
)
1207 SwWrtShell
* const pWrtSh
= getSwDocShell()->GetWrtShell();
1208 CPPUNIT_ASSERT(pWrtSh
);
1210 pWrtSh
->Insert(u
"Test"_ustr
);
1214 u
".uno:InsertPageHeader?PageStyle:string=Default%20Page%20Style&On:bool=true"_ustr
, {});
1216 uno::Reference
<beans::XPropertySet
> xPageStyle(
1217 getStyles(u
"PageStyles"_ustr
)->getByName(u
"Standard"_ustr
), uno::UNO_QUERY
);
1218 CPPUNIT_ASSERT_EQUAL(true, getProperty
<bool>(xPageStyle
, u
"HeaderIsOn"_ustr
));
1219 CPPUNIT_ASSERT_EQUAL(u
"Test"_ustr
, getParagraph(1)->getString());
1221 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1223 CPPUNIT_ASSERT_EQUAL(false, getProperty
<bool>(xPageStyle
, u
"HeaderIsOn"_ustr
));
1224 CPPUNIT_ASSERT_EQUAL(u
"Test"_ustr
, getParagraph(1)->getString());
1226 // Without the fix in place, this test would have crashed here
1227 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1228 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, getParagraph(1)->getString());
1231 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf107494
)
1235 // Create a graphic object, but don't insert it yet.
1236 uno::Reference
<lang::XMultiServiceFactory
> xFactory(mxComponent
, uno::UNO_QUERY
);
1237 uno::Reference
<beans::XPropertySet
> xTextGraphic(
1238 xFactory
->createInstance(u
"com.sun.star.text.TextGraphicObject"_ustr
), uno::UNO_QUERY
);
1240 uno::Reference
<text::XTextContent
> xTextContent(xTextGraphic
, uno::UNO_QUERY
);
1242 uno::Reference
<beans::XPropertySet
> xPageStyle(
1243 getStyles(u
"PageStyles"_ustr
)->getByName(u
"Standard"_ustr
), uno::UNO_QUERY
);
1245 xPageStyle
->setPropertyValue(u
"HeaderIsOn"_ustr
, uno::Any(true));
1247 uno::Reference
<text::XText
> xHeader(
1248 getProperty
<uno::Reference
<text::XText
>>(xPageStyle
, u
"HeaderText"_ustr
));
1249 CPPUNIT_ASSERT(xHeader
.is());
1250 uno::Reference
<text::XTextCursor
> xHeaderCursor(xHeader
->createTextCursor());
1252 xHeader
->insertTextContent(xHeaderCursor
, xTextContent
, false);
1254 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1256 xPageStyle
->setPropertyValue(u
"HeaderIsOn"_ustr
, uno::Any(false));
1258 CPPUNIT_ASSERT_EQUAL(0, getShapes());
1260 xPageStyle
->setPropertyValue(u
"FooterIsOn"_ustr
, uno::Any(true));
1262 uno::Reference
<text::XText
> xFooter(
1263 getProperty
<uno::Reference
<text::XText
>>(xPageStyle
, u
"FooterText"_ustr
));
1264 CPPUNIT_ASSERT(xFooter
.is());
1265 uno::Reference
<text::XTextCursor
> xFooterCursor(xFooter
->createTextCursor());
1267 xTextGraphic
.set(xFactory
->createInstance(u
"com.sun.star.text.TextGraphicObject"_ustr
),
1270 xTextContent
.set(xTextGraphic
, uno::UNO_QUERY
);
1272 xFooter
->insertTextContent(xFooterCursor
, xTextContent
, false);
1274 CPPUNIT_ASSERT_EQUAL(1, getShapes());
1276 xPageStyle
->setPropertyValue(u
"FooterIsOn"_ustr
, uno::Any(false));
1278 CPPUNIT_ASSERT_EQUAL(0, getShapes());
1281 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf133358
)
1284 SwWrtShell
* const pWrtSh
= getSwDocShell()->GetWrtShell();
1285 CPPUNIT_ASSERT(pWrtSh
);
1287 pWrtSh
->Insert(u
"Test"_ustr
);
1289 CPPUNIT_ASSERT_EQUAL(u
"Test"_ustr
, getParagraph(1)->getString());
1291 uno::Reference
<beans::XPropertyState
> xParagraph(getParagraph(1), uno::UNO_QUERY
);
1293 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty
<sal_Int32
>(xParagraph
, u
"ParaLeftMargin"_ustr
));
1295 dispatchCommand(mxComponent
, u
".uno:IncrementIndent"_ustr
, {});
1297 CPPUNIT_ASSERT_EQUAL(sal_Int32(1251),
1298 getProperty
<sal_Int32
>(xParagraph
, u
"ParaLeftMargin"_ustr
));
1300 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1302 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty
<sal_Int32
>(xParagraph
, u
"ParaLeftMargin"_ustr
));
1304 // Without the fix in place, this test would have crashed here
1305 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {});
1307 CPPUNIT_ASSERT_EQUAL(sal_Int32(1251),
1308 getProperty
<sal_Int32
>(xParagraph
, u
"ParaLeftMargin"_ustr
));
1311 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf131771
)
1315 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
1316 { { "Rows", uno::Any(sal_Int32(2)) }, { "Columns", uno::Any(sal_Int32(2)) } }));
1318 dispatchCommand(mxComponent
, u
".uno:InsertTable"_ustr
, aArgs
);
1320 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1321 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1323 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1325 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1327 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, getProperty
<OUString
>(xTextTable
, u
"TableTemplateName"_ustr
));
1328 uno::Reference
<beans::XPropertySet
> xTableProps(xTextTable
, uno::UNO_QUERY_THROW
);
1329 xTableProps
->setPropertyValue(u
"TableTemplateName"_ustr
, uno::Any(u
"Default Style"_ustr
));
1331 CPPUNIT_ASSERT_EQUAL(u
"Default Style"_ustr
,
1332 getProperty
<OUString
>(xTextTable
, u
"TableTemplateName"_ustr
));
1334 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1335 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1336 dispatchCommand(mxComponent
, u
".uno:GoDown"_ustr
, {});
1337 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1339 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xIndexAccess
->getCount());
1341 CPPUNIT_ASSERT_EQUAL(u
"Default Style"_ustr
,
1342 getProperty
<OUString
>(xTextTable
, u
"TableTemplateName"_ustr
));
1344 uno::Reference
<text::XTextTable
> xTextTable2(xIndexAccess
->getByIndex(1), uno::UNO_QUERY
);
1346 // Without the fix in place, this test would have failed with
1347 // - Expected: Default Style
1349 CPPUNIT_ASSERT_EQUAL(u
"Default Style"_ustr
,
1350 getProperty
<OUString
>(xTextTable2
, u
"TableTemplateName"_ustr
));
1353 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf156546
)
1357 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
1358 { { "Rows", uno::Any(sal_Int32(2)) }, { "Columns", uno::Any(sal_Int32(2)) } }));
1360 dispatchCommand(mxComponent
, u
".uno:InsertTable"_ustr
, aArgs
);
1362 uno::Reference
<text::XTextTablesSupplier
> xTableSupplier(mxComponent
, uno::UNO_QUERY
);
1363 uno::Reference
<container::XIndexAccess
> xTables(xTableSupplier
->getTextTables(),
1366 // check that table was created and inserted into the document
1367 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables
->getCount());
1368 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1369 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1370 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1372 // create another document
1374 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1376 uno::Reference
<text::XTextTablesSupplier
> xTableSupplier2(mxComponent
, uno::UNO_QUERY
);
1377 uno::Reference
<container::XIndexAccess
> xTables2(xTableSupplier2
->getTextTables(),
1380 // check table exists after paste/undo
1381 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables2
->getCount());
1382 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1383 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xTables2
->getCount());
1385 // without the test, writer freezes on redo table paste into new doc
1386 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {});
1387 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables2
->getCount());
1390 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf80663
)
1394 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
1395 { { "Rows", uno::Any(sal_Int32(2)) }, { "Columns", uno::Any(sal_Int32(2)) } }));
1397 dispatchCommand(mxComponent
, u
".uno:InsertTable"_ustr
, aArgs
);
1399 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1400 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1402 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1403 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1404 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getRows()->getCount());
1405 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getColumns()->getCount());
1407 dispatchCommand(mxComponent
, u
".uno:DeleteRows"_ustr
, {});
1409 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1410 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable
->getRows()->getCount());
1411 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getColumns()->getCount());
1413 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1415 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1416 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getRows()->getCount());
1417 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getColumns()->getCount());
1420 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf130805
)
1422 createSwDoc("tdf130805.odt");
1423 SwDoc
* pDoc
= getSwDoc();
1425 const auto& rFrmFormats
= *pDoc
->GetSpzFrameFormats();
1426 CPPUNIT_ASSERT(rFrmFormats
.size() >= size_t(o3tl::make_unsigned(1)));
1427 auto pShape
= rFrmFormats
.front();
1428 CPPUNIT_ASSERT(pShape
);
1430 SwTextBoxHelper::create(pShape
, pShape
->FindRealSdrObject());
1431 auto pTxBxFrm
= SwTextBoxHelper::getOtherTextBoxFormat(getShape(1));
1432 CPPUNIT_ASSERT(pTxBxFrm
);
1434 const SwNode
* pTxAnch
= pTxBxFrm
->GetAnchor().GetAnchorNode();
1435 const SwNode
* pShpAnch
= pShape
->GetAnchor().GetAnchorNode();
1436 CPPUNIT_ASSERT(pTxAnch
);
1437 CPPUNIT_ASSERT(pShpAnch
);
1439 CPPUNIT_ASSERT_EQUAL_MESSAGE("The textbox got apart!", pTxAnch
->GetIndex(),
1440 pShpAnch
->GetIndex());
1443 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf107893
)
1445 //Open the sample doc
1446 createSwDoc("tdf107893.odt");
1447 SwDoc
* pDoc
= getSwDoc();
1449 //Get the format of the shape
1450 const auto& rFrmFormats
= *pDoc
->GetSpzFrameFormats();
1451 CPPUNIT_ASSERT(rFrmFormats
.size() >= size_t(o3tl::make_unsigned(1)));
1452 auto pShape
= rFrmFormats
.front();
1453 CPPUNIT_ASSERT(pShape
);
1456 SwTextBoxHelper::create(pShape
, pShape
->FindRealSdrObject());
1457 SwFrameFormat
* pTxBxFrm
= SwTextBoxHelper::getOtherTextBoxFormat(getShape(1));
1458 CPPUNIT_ASSERT(pTxBxFrm
);
1460 //Remove the textbox using Undo
1461 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1464 SwTextBoxHelper::create(pShape
, pShape
->FindRealSdrObject());
1465 pTxBxFrm
= SwTextBoxHelper::getOtherTextBoxFormat(getShape(1));
1467 //This was nullptr because of unsuccessful re-adding
1468 CPPUNIT_ASSERT_MESSAGE("Textbox cannot be readd after Undo!", pTxBxFrm
);
1471 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf121031
)
1475 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
1476 { { "Rows", uno::Any(sal_Int32(3)) }, { "Columns", uno::Any(sal_Int32(3)) } }));
1478 dispatchCommand(mxComponent
, u
".uno:InsertTable"_ustr
, aArgs
);
1480 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1481 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1483 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1485 dispatchCommand(mxComponent
, u
".uno:DeleteTable"_ustr
, {});
1486 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
1488 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1489 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1491 // Without the fix in place, the table would be hidden
1492 xmlDocUniquePtr pXmlDoc
= parseLayoutDump();
1493 assertXPath(pXmlDoc
, "/root/page[1]/body/tab", 1);
1496 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, TestTextBoxCrashAfterLineDel
)
1498 // Open the desired file
1499 createSwDoc("txbx_crash.odt");
1500 SwDoc
* pDoc
= getSwDoc();
1502 // Get the format of the shape
1503 const auto& rFrmFormats
= *pDoc
->GetSpzFrameFormats();
1504 CPPUNIT_ASSERT(rFrmFormats
.size() >= size_t(o3tl::make_unsigned(1)));
1505 auto pShape
= rFrmFormats
.front();
1506 CPPUNIT_ASSERT(pShape
);
1509 SwTextBoxHelper::create(pShape
, pShape
->FindRealSdrObject());
1510 SwFrameFormat
* pTxBxFrm
= SwTextBoxHelper::getOtherTextBoxFormat(getShape(1));
1511 CPPUNIT_ASSERT(pTxBxFrm
);
1513 // remove the last paragraph
1514 auto xCursor
= getParagraph(1)->getText()->createTextCursor();
1515 xCursor
->gotoEnd(false);
1516 xCursor
->goLeft(3, true);
1518 // This caused crash before, now it should pass with the patch.
1519 xCursor
->setString(OUString());
1522 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf146356
)
1524 createSwDoc("tdf146356.odt");
1526 SwXTextDocument
* pTextDoc
= getSwTextDoc();
1527 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_MOD2
| awt::Key::RETURN
);
1528 Scheduler::ProcessEventsToIdle();
1530 emulateTyping(u
"Some Text");
1532 // Without the fix in place, this test would have failed with
1533 // - Expected: Some Text
1534 // - Actual : Table of Contents
1535 CPPUNIT_ASSERT_EQUAL(u
"Some Text"_ustr
, getParagraph(1)->getString());
1537 // tdf#160095: Without the fix in place, this test would have crashed here
1538 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_MOD2
| awt::Key::RETURN
);
1539 Scheduler::ProcessEventsToIdle();
1541 CPPUNIT_ASSERT_EQUAL(u
"Some Text"_ustr
, getParagraph(1)->getString());
1544 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf121546
)
1546 createSwDoc("tdf121546.odt");
1548 CPPUNIT_ASSERT_EQUAL(u
"xxxxxxxxxxxxxxxxxxxx"_ustr
, getParagraph(2)->getString());
1550 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1552 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
1554 CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
1556 // Create a new document
1559 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1561 CPPUNIT_ASSERT_EQUAL(u
"xxxxxxxxxxxxxxxxxxxx"_ustr
, getParagraph(2)->getString());
1563 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1565 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
1567 CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
1569 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1571 CPPUNIT_ASSERT_EQUAL(u
"xxxxxxxxxxxxxxxxxxxx"_ustr
, getParagraph(2)->getString());
1573 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1575 // Without the fix in place, this test would have crashed here
1576 SwXTextDocument
* pTextDoc
= getSwTextDoc();
1577 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RETURN
);
1578 Scheduler::ProcessEventsToIdle();
1580 CPPUNIT_ASSERT_EQUAL(2, getParagraphs());
1583 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf145621
)
1585 createSwDoc("tdf145621.odt");
1587 CPPUNIT_ASSERT_EQUAL(u
"AAAAAA"_ustr
, getParagraph(1)->getString());
1589 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1591 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
1593 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, getParagraph(1)->getString());
1595 // Without the fix in place, this test would have crashed
1596 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1598 CPPUNIT_ASSERT_EQUAL(u
"AAAAAA"_ustr
, getParagraph(1)->getString());
1601 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf134626
)
1603 createSwDoc("tdf134626.odt");
1604 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1606 CPPUNIT_ASSERT_EQUAL(u
"Apple"_ustr
, getParagraph(1)->getString());
1608 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1610 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1612 // Create a new document
1614 pWrtShell
= getSwDocShell()->GetWrtShell();
1615 CPPUNIT_ASSERT(pWrtShell
);
1617 // Without the fix in place, this test would have crashed here
1618 for (sal_Int32 i
= 0; i
< 5; ++i
)
1620 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1622 CPPUNIT_ASSERT_EQUAL(u
"Apple"_ustr
, getParagraph(1)->getString());
1624 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1626 CPPUNIT_ASSERT_EQUAL(u
"AppleApple"_ustr
, getParagraph(1)->getString());
1628 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1630 CPPUNIT_ASSERT_EQUAL(u
"Apple"_ustr
, getParagraph(1)->getString());
1632 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1634 CPPUNIT_ASSERT_EQUAL(u
""_ustr
, getParagraph(1)->getString());
1638 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf139566
)
1641 SwWrtShell
* pWrtSh
= getSwDocShell()->GetWrtShell();
1643 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
1644 { { "Rows", uno::Any(sal_Int32(1)) }, { "Columns", uno::Any(sal_Int32(1)) } }));
1646 dispatchCommand(mxComponent
, u
".uno:InsertTable"_ustr
, aArgs
);
1648 // Move the cursor outside the table
1649 pWrtSh
->Down(/*bSelect=*/false);
1651 pWrtSh
->Insert(u
"Test"_ustr
);
1653 CPPUNIT_ASSERT_EQUAL(u
"Test"_ustr
, getParagraph(2)->getString());
1655 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1657 uno::Reference
<frame::XFrames
> xFrames
= mxDesktop
->getFrames();
1658 sal_Int32 nFrames
= xFrames
->getCount();
1660 // Create a second window so the first window looses focus
1661 dispatchCommand(mxComponent
, u
".uno:NewWindow"_ustr
, {});
1663 CPPUNIT_ASSERT_EQUAL(nFrames
+ 1, xFrames
->getCount());
1665 dispatchCommand(mxComponent
, u
".uno:CloseWin"_ustr
, {});
1667 CPPUNIT_ASSERT_EQUAL(nFrames
, xFrames
->getCount());
1669 uno::Reference
<frame::XModel
> xModel(mxComponent
, uno::UNO_QUERY
);
1670 uno::Reference
<container::XIndexAccess
> xSelections(xModel
->getCurrentSelection(),
1673 // Without the fix in place, this test would have failed here
1674 CPPUNIT_ASSERT(xSelections
.is());
1677 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf96067
)
1681 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
1682 { { "Rows", uno::Any(sal_Int32(3)) }, { "Columns", uno::Any(sal_Int32(3)) } }));
1684 dispatchCommand(mxComponent
, u
".uno:InsertTable"_ustr
, aArgs
);
1686 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1687 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1689 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1690 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1691 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
1692 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getColumns()->getCount());
1694 dispatchCommand(mxComponent
, u
".uno:SelectTable"_ustr
, {});
1695 dispatchCommand(mxComponent
, u
".uno:InsertRowsBefore"_ustr
, {});
1697 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1698 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable
->getRows()->getCount());
1699 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getColumns()->getCount());
1701 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1703 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1704 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getRows()->getCount());
1705 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getColumns()->getCount());
1708 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf87199
)
1712 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
1713 { { "Rows", uno::Any(sal_Int32(2)) }, { "Columns", uno::Any(sal_Int32(1)) } }));
1715 dispatchCommand(mxComponent
, u
".uno:InsertTable"_ustr
, aArgs
);
1717 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1718 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1720 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1721 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1722 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getRows()->getCount());
1723 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable
->getColumns()->getCount());
1725 uno::Reference
<text::XTextRange
> xCellA1(xTextTable
->getCellByName(u
"A1"_ustr
), uno::UNO_QUERY
);
1726 xCellA1
->setString(u
"test1"_ustr
);
1728 uno::Reference
<text::XTextRange
> xCellA2(xTextTable
->getCellByName(u
"A2"_ustr
), uno::UNO_QUERY
);
1729 xCellA2
->setString(u
"test2"_ustr
);
1731 dispatchCommand(mxComponent
, u
".uno:EntireColumn"_ustr
, {});
1732 dispatchCommand(mxComponent
, u
".uno:MergeCells"_ustr
, {});
1734 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1735 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable
->getRows()->getCount());
1736 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable
->getColumns()->getCount());
1738 CPPUNIT_ASSERT(xCellA1
->getString().endsWith("test2"));
1740 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
1742 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
1743 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getRows()->getCount());
1744 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable
->getColumns()->getCount());
1746 xCellA1
.set(xTextTable
->getCellByName(u
"A1"_ustr
), uno::UNO_QUERY
);
1748 CPPUNIT_ASSERT(xCellA1
->getString().endsWith("test1"));
1751 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf39828
)
1753 createSwDoc("tdf39828.fodt");
1754 SwDoc
* pDoc
= getSwDoc();
1757 pDoc
->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::ShowDelete
1758 | RedlineFlags::ShowInsert
);
1759 CPPUNIT_ASSERT_MESSAGE("redlining should be off",
1760 !pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
1761 CPPUNIT_ASSERT_MESSAGE(
1762 "redlines should be visible",
1763 IDocumentRedlineAccess::IsShowChanges(pDoc
->getIDocumentRedlineAccess().GetRedlineFlags()));
1765 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1766 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1768 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1770 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTextTable
->getRows()->getCount());
1772 uno::Reference
<text::XTextRange
> xCellA1(xTextTable
->getCellByName(u
"A1"_ustr
), uno::UNO_QUERY
);
1773 // deleted "1", inserted "2"
1774 CPPUNIT_ASSERT_EQUAL(u
"12"_ustr
, xCellA1
->getString());
1775 uno::Reference
<text::XTextRange
> xCellA3(xTextTable
->getCellByName(u
"A3"_ustr
), uno::UNO_QUERY
);
1776 // This was 14 (bad sum: 2 + A1, where A1 was 12 instead of the correct 2)
1777 CPPUNIT_ASSERT_EQUAL(u
"4"_ustr
, xCellA3
->getString());
1778 uno::Reference
<text::XTextRange
> xCellA4(xTextTable
->getCellByName(u
"A4"_ustr
), uno::UNO_QUERY
);
1779 // This was 28 (bad sum: 2 + A1 + A3, where A1 was 12 and A3 was 14)
1780 CPPUNIT_ASSERT_EQUAL(u
"8"_ustr
, xCellA4
->getString());
1783 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf146573
)
1785 createSwDoc("tdf39828.fodt");
1786 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1788 // remove redlines, add a footnote, and change the value
1789 // of the cell with the footnote
1790 dispatchCommand(mxComponent
, u
".uno:AcceptAllTrackedChanges"_ustr
, {});
1791 pWrtShell
->Right(SwCursorSkipMode::Cells
, /*bSelect=*/false, /*nCount=*/1,
1792 /*bBasicCall=*/false);
1793 dispatchCommand(mxComponent
, u
".uno:InsertFootnote"_ustr
, {});
1794 dispatchCommand(mxComponent
, u
".uno:PageUp"_ustr
, {}); // leave footnote
1795 pWrtShell
->Left(SwCursorSkipMode::Cells
, /*bSelect=*/false, /*nCount=*/1, /*bBasicCall=*/false);
1796 pWrtShell
->Left(SwCursorSkipMode::Cells
, /*bSelect=*/true, /*nCount=*/1, /*bBasicCall=*/false);
1797 pWrtShell
->Insert(u
"100"_ustr
);
1799 // trigger recalculation by leaving the cell
1800 pWrtShell
->Down(/*bSelect=*/false, /*nCount=*/1);
1802 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1803 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
1805 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
1807 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTextTable
->getRows()->getCount());
1809 uno::Reference
<text::XTextRange
> xCellA1(xTextTable
->getCellByName(u
"A1"_ustr
), uno::UNO_QUERY
);
1810 // value "100" and footnote index "1"
1811 CPPUNIT_ASSERT_EQUAL(u
"1001"_ustr
, xCellA1
->getString());
1812 uno::Reference
<text::XTextRange
> xCellA3(xTextTable
->getCellByName(u
"A3"_ustr
), uno::UNO_QUERY
);
1813 // This was 4 (missing recalculation)
1814 CPPUNIT_ASSERT_EQUAL(u
"102"_ustr
, xCellA3
->getString());
1815 uno::Reference
<text::XTextRange
> xCellA4(xTextTable
->getCellByName(u
"A4"_ustr
), uno::UNO_QUERY
);
1816 // This was 8 (missing recalculation)
1817 CPPUNIT_ASSERT_EQUAL(u
"204"_ustr
, xCellA4
->getString());
1820 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf157132
)
1822 createSwDoc("tdf157132.odt");
1824 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1827 pWrtShell
->Down(/*bSelect=*/false, /*nCount=*/1);
1829 // Select A2 and A3 and copy
1830 pWrtShell
->Down(/*bSelect=*/true, /*nCount=*/1);
1832 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
1834 // Go to A4 and paste
1835 pWrtShell
->Down(/*bSelect=*/false, /*nCount=*/1);
1837 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
1839 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1840 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(),
1843 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTables
->getCount());
1845 uno::Reference
<text::XTextTable
> xTextTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
1847 uno::Reference
<text::XTextRange
> xCellA2(xTextTable
->getCellByName(u
"A2"_ustr
), uno::UNO_QUERY
);
1848 CPPUNIT_ASSERT_EQUAL(u
"2"_ustr
, xCellA2
->getString());
1849 uno::Reference
<text::XTextRange
> xCellA3(xTextTable
->getCellByName(u
"A3"_ustr
), uno::UNO_QUERY
);
1850 CPPUNIT_ASSERT_EQUAL(u
"3"_ustr
, xCellA3
->getString());
1851 uno::Reference
<text::XTextRange
> xCellA4(xTextTable
->getCellByName(u
"A4"_ustr
), uno::UNO_QUERY
);
1853 // Without the fix in place, this test would have failed with
1856 CPPUNIT_ASSERT_EQUAL(u
"6"_ustr
, xCellA4
->getString());
1857 uno::Reference
<text::XTextRange
> xCellA5(xTextTable
->getCellByName(u
"A5"_ustr
), uno::UNO_QUERY
);
1858 CPPUNIT_ASSERT_EQUAL(u
"7"_ustr
, xCellA5
->getString());
1860 xTextTable
.set(xTables
->getByIndex(1), uno::UNO_QUERY
);
1862 xCellA2
.set(xTextTable
->getCellByName(u
"A2"_ustr
), uno::UNO_QUERY
);
1864 // tdf#158336: Without the fix in place, this test would have failed with
1866 // - Actual : ** Expression is faulty **
1867 CPPUNIT_ASSERT_EQUAL(u
"2"_ustr
, xCellA2
->getString());
1868 xCellA3
.set(xTextTable
->getCellByName(u
"A3"_ustr
), uno::UNO_QUERY
);
1869 CPPUNIT_ASSERT_EQUAL(u
"3"_ustr
, xCellA3
->getString());
1870 xCellA4
.set(xTextTable
->getCellByName(u
"A4"_ustr
), uno::UNO_QUERY
);
1871 CPPUNIT_ASSERT_EQUAL(u
"6"_ustr
, xCellA4
->getString());
1872 xCellA5
.set(xTextTable
->getCellByName(u
"A5"_ustr
), uno::UNO_QUERY
);
1873 CPPUNIT_ASSERT_EQUAL(u
"7"_ustr
, xCellA5
->getString());
1876 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf147938
)
1878 createSwDoc("tdf147938.fodt");
1880 SwDoc
* pDoc
= getSwDoc();
1881 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1883 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->getIDocumentRedlineAccess().GetRedlineTable().size());
1884 CPPUNIT_ASSERT_EQUAL(u
"Bar\nbaz "_ustr
,
1885 pDoc
->getIDocumentRedlineAccess().GetRedlineTable()[0]->GetText());
1887 pWrtShell
->Down(/*bSelect=*/false, /*nCount=*/1);
1888 pWrtShell
->TableToText('\t');
1890 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->getIDocumentRedlineAccess().GetRedlineTable().size());
1891 CPPUNIT_ASSERT_EQUAL(u
"Bar\nbaz "_ustr
,
1892 pDoc
->getIDocumentRedlineAccess().GetRedlineTable()[0]->GetText());
1894 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
1895 SwInsertTableOptions
const opts(SwInsertTableFlags::NONE
, 0);
1896 pWrtShell
->TextToTable(opts
, '\t', nullptr);
1900 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->getIDocumentRedlineAccess().GetRedlineTable().size());
1901 CPPUNIT_ASSERT_EQUAL(u
"Bar\nbaz "_ustr
,
1902 pDoc
->getIDocumentRedlineAccess().GetRedlineTable()[0]->GetText());
1906 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->getIDocumentRedlineAccess().GetRedlineTable().size());
1907 CPPUNIT_ASSERT_EQUAL(u
"Bar\nbaz "_ustr
,
1908 pDoc
->getIDocumentRedlineAccess().GetRedlineTable()[0]->GetText());
1912 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->getIDocumentRedlineAccess().GetRedlineTable().size());
1913 CPPUNIT_ASSERT_EQUAL(u
"Bar\nbaz "_ustr
,
1914 pDoc
->getIDocumentRedlineAccess().GetRedlineTable()[0]->GetText());
1920 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->getIDocumentRedlineAccess().GetRedlineTable().size());
1921 CPPUNIT_ASSERT_EQUAL(u
"Bar\nbaz "_ustr
,
1922 pDoc
->getIDocumentRedlineAccess().GetRedlineTable()[0]->GetText());
1926 CPPUNIT_ASSERT_EQUAL(size_t(1), pDoc
->getIDocumentRedlineAccess().GetRedlineTable().size());
1927 CPPUNIT_ASSERT_EQUAL(u
"Bar\nbaz "_ustr
,
1928 pDoc
->getIDocumentRedlineAccess().GetRedlineTable()[0]->GetText());
1931 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf148799
)
1933 // load a document with table formulas with comma delimiter,
1934 // but with a document language with default point delimiter
1935 createSwDoc("tdf148799.docx");
1936 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1938 // check formula update
1940 // put cursor in the first table row
1941 pWrtShell
->Down(/*bSelect=*/false, /*nCount=*/1);
1943 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1944 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(),
1947 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables
->getCount());
1949 uno::Reference
<text::XTextTable
> xTextTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
1951 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTextTable
->getRows()->getCount());
1953 // These were "** Expression is faulty **"
1955 uno::Reference
<text::XTextRange
> xCellA1(xTextTable
->getCellByName(u
"D3"_ustr
), uno::UNO_QUERY
);
1956 CPPUNIT_ASSERT_EQUAL(u
"2.3"_ustr
, xCellA1
->getString());
1957 uno::Reference
<text::XTextRange
> xCellA3(xTextTable
->getCellByName(u
"D4"_ustr
), uno::UNO_QUERY
);
1958 CPPUNIT_ASSERT_EQUAL(u
"2345"_ustr
, xCellA3
->getString());
1959 uno::Reference
<text::XTextRange
> xCellA4(xTextTable
->getCellByName(u
"D5"_ustr
), uno::UNO_QUERY
);
1960 CPPUNIT_ASSERT_EQUAL(u
"23684.5"_ustr
, xCellA4
->getString());
1963 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf151993
)
1965 // load a document with table formulas with comma delimiter
1966 // (with a document language with default comma delimiter)
1967 createSwDoc("tdf151993.docx");
1968 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1970 // check formula update
1972 // put cursor in the first table row
1973 pWrtShell
->Down(/*bSelect=*/false, /*nCount=*/1);
1975 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
1976 uno::Reference
<container::XIndexAccess
> xTables(xTextTablesSupplier
->getTextTables(),
1979 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables
->getCount());
1981 uno::Reference
<text::XTextTable
> xTextTable(xTables
->getByIndex(0), uno::UNO_QUERY
);
1983 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getRows()->getCount());
1986 uno::Reference
<text::XTextRange
> xCellA1(xTextTable
->getCellByName(u
"A2"_ustr
), uno::UNO_QUERY
);
1987 CPPUNIT_ASSERT_EQUAL(u
"30"_ustr
, xCellA1
->getString());
1990 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf148849
)
1992 // load a document with a table and an empty paragraph before the table
1993 createSwDoc("tdf148849.fodt");
1994 SwDoc
* pDoc
= getSwDoc();
1995 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
1998 pDoc
->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On
| RedlineFlags::ShowDelete
1999 | RedlineFlags::ShowInsert
);
2000 CPPUNIT_ASSERT_MESSAGE("redlining should be on",
2001 pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
2003 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
2004 CPPUNIT_ASSERT(pWrtShell
->GetLayout()->IsHideRedlines());
2006 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2007 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables(),
2009 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables
->getCount());
2011 // put cursor in the first table row
2012 pWrtShell
->Down(/*bSelect=*/false, /*nCount=*/1);
2014 // delete a table row
2015 pWrtShell
->DeleteRow();
2017 // check cursor position
2019 // This was "", because the text cursor jumped to the start of the document
2020 // after deleting a table row instead of remaining in the next table row
2021 SwNode
& rNode
= pWrtShell
->GetCursor()->GetPoint()->GetNode();
2022 CPPUNIT_ASSERT_EQUAL(u
"Row 2"_ustr
, rNode
.GetTextNode()->GetText());
2025 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf150576
)
2027 // load a document with a table and an empty paragraph before the table
2028 createSwDoc("tdf148849.fodt");
2029 SwDoc
* pDoc
= getSwDoc();
2030 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
2033 pDoc
->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On
| RedlineFlags::ShowDelete
2034 | RedlineFlags::ShowInsert
);
2035 CPPUNIT_ASSERT_MESSAGE("redlining should be on",
2036 pDoc
->getIDocumentRedlineAccess().IsRedlineOn());
2038 dispatchCommand(mxComponent
, u
".uno:ShowTrackedChanges"_ustr
, {});
2039 CPPUNIT_ASSERT(pWrtShell
->GetLayout()->IsHideRedlines());
2041 uno::Reference
<text::XTextTablesSupplier
> xTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2042 uno::Reference
<container::XIndexAccess
> xTables(xTablesSupplier
->getTextTables(),
2044 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables
->getCount());
2046 // Check deletion of the first row, if the second row deleted already
2048 // put cursor in the second table row
2049 pWrtShell
->Down(/*bSelect=*/false, /*nCount=*/2);
2050 SwNode
& rNode
= pWrtShell
->GetCursor()->GetPoint()->GetNode();
2051 CPPUNIT_ASSERT_EQUAL(u
"Row 2"_ustr
, rNode
.GetTextNode()->GetText());
2053 // delete the second table row
2054 pWrtShell
->DeleteRow();
2056 // check cursor position (row 3)
2057 SwNode
& rNode2
= pWrtShell
->GetCursor()->GetPoint()->GetNode();
2058 CPPUNIT_ASSERT_EQUAL(u
"Row 3"_ustr
, rNode2
.GetTextNode()->GetText());
2060 // put cursor in the first row
2061 pWrtShell
->Up(/*bSelect=*/false, /*nCount=*/1);
2062 SwNode
& rNode3
= pWrtShell
->GetCursor()->GetPoint()->GetNode();
2063 CPPUNIT_ASSERT_EQUAL(u
"12"_ustr
, rNode3
.GetTextNode()->GetText());
2065 // delete the first row
2066 pWrtShell
->DeleteRow();
2068 // This was empty (cursor jumped in the start of the document instead of
2069 // the next not deleted row)
2070 SwNode
& rNode4
= pWrtShell
->GetCursor()->GetPoint()->GetNode();
2071 CPPUNIT_ASSERT_EQUAL(u
"Row 3"_ustr
, rNode4
.GetTextNode()->GetText());
2073 // Check skipping previous lines
2075 // restore deleted rows
2076 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2077 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2078 SwNode
& rNode5
= pWrtShell
->GetCursor()->GetPoint()->GetNode();
2079 CPPUNIT_ASSERT_EQUAL(u
"Row 2"_ustr
, rNode5
.GetTextNode()->GetText());
2081 // delete the second row
2082 pWrtShell
->DeleteRow();
2083 SwNode
& rNode7
= pWrtShell
->GetCursor()->GetPoint()->GetNode();
2084 CPPUNIT_ASSERT_EQUAL(u
"Row 3"_ustr
, rNode7
.GetTextNode()->GetText());
2086 // delete the third, i.e. last row
2087 pWrtShell
->DeleteRow();
2088 SwNode
& rNode8
= pWrtShell
->GetCursor()->GetPoint()->GetNode();
2090 // This was empty (cursor jumped in the start of the document instead of
2091 // the previous not deleted row)
2092 CPPUNIT_ASSERT_EQUAL(u
"12"_ustr
, rNode8
.GetTextNode()->GetText());
2095 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf132603
)
2099 uno::Sequence
<beans::PropertyValue
> aPropertyValues
2100 = comphelper::InitPropertySequence({ { "Text", uno::Any(u
"Comment"_ustr
) } });
2102 dispatchCommand(mxComponent
, u
".uno:InsertAnnotation"_ustr
, aPropertyValues
);
2104 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2106 // Without the fix in place, it would crash here
2107 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
2109 tools::JsonWriter aJsonWriter
;
2110 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2111 pTextDoc
->getPostIts(aJsonWriter
);
2112 OString pChar
= aJsonWriter
.finishAndGetAsOString();
2113 std::stringstream
aStream((std::string(pChar
)));
2114 boost::property_tree::ptree aTree
;
2115 boost::property_tree::read_json(aStream
, aTree
);
2116 for (const boost::property_tree::ptree::value_type
& rValue
: aTree
.get_child("comments"))
2118 const boost::property_tree::ptree
& rComment
= rValue
.second
;
2120 OString
aText(rComment
.get
<std::string
>("html"));
2121 CPPUNIT_ASSERT_EQUAL("<div>Comment</div>"_ostr
, aText
);
2125 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf117601
)
2129 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
2130 { { "Rows", uno::Any(sal_Int32(5)) }, { "Columns", uno::Any(sal_Int32(3)) } }));
2132 dispatchCommand(mxComponent
, u
".uno:InsertTable"_ustr
, aArgs
);
2134 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2135 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2137 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2138 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2139 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTextTable
->getRows()->getCount());
2140 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getColumns()->getCount());
2142 uno::Reference
<text::XTextRange
> xCellB1(xTextTable
->getCellByName(u
"B1"_ustr
), uno::UNO_QUERY
);
2143 xCellB1
->setString(u
"test1"_ustr
);
2145 uno::Reference
<text::XTextRange
> xCellB2(xTextTable
->getCellByName(u
"B2"_ustr
), uno::UNO_QUERY
);
2146 xCellB2
->setString(u
"test2"_ustr
);
2149 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2150 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_UP
);
2151 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RIGHT
);
2152 Scheduler::ProcessEventsToIdle();
2154 dispatchCommand(mxComponent
, u
".uno:EntireColumn"_ustr
, {});
2155 dispatchCommand(mxComponent
, u
".uno:MergeCells"_ustr
, {});
2157 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2158 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTextTable
->getRows()->getCount());
2159 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getColumns()->getCount());
2161 CPPUNIT_ASSERT(xCellB1
->getString().endsWith("test2"));
2163 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2165 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2166 CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTextTable
->getRows()->getCount());
2167 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTextTable
->getColumns()->getCount());
2169 CPPUNIT_ASSERT(xCellB1
->getString().endsWith("test1"));
2172 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf138130
)
2174 createSwDoc("tdf138130.docx");
2176 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2177 uno::Reference
<drawing::XShape
> xShape
= getShape(1);
2179 awt::Point aPos
= xShape
->getPosition();
2181 //select shape and change the anchor
2184 // Without the fix in place, this test would have crashed here
2185 dispatchCommand(mxComponent
, u
".uno:SetAnchorToPage"_ustr
, {});
2187 //position has changed
2188 CPPUNIT_ASSERT(aPos
.X
< xShape
->getPosition().X
);
2189 CPPUNIT_ASSERT(aPos
.Y
< xShape
->getPosition().Y
);
2191 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2193 CPPUNIT_ASSERT_EQUAL(aPos
.X
, xShape
->getPosition().X
);
2194 CPPUNIT_ASSERT_EQUAL(aPos
.Y
, xShape
->getPosition().Y
);
2197 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf136385
)
2199 createSwDoc("tdf136385.odt");
2201 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2202 uno::Reference
<drawing::XShape
> xShape
= getShape(1);
2204 awt::Point aPos
= xShape
->getPosition();
2206 //select shape and change the anchor
2209 dispatchCommand(mxComponent
, u
".uno:SetAnchorToPage"_ustr
, {});
2211 //position has changed
2212 CPPUNIT_ASSERT(aPos
.X
< xShape
->getPosition().X
);
2213 CPPUNIT_ASSERT(aPos
.Y
< xShape
->getPosition().Y
);
2215 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2217 //Without the fix in place, this test would have failed with
2220 CPPUNIT_ASSERT_EQUAL(aPos
.X
, xShape
->getPosition().X
);
2221 CPPUNIT_ASSERT_EQUAL(aPos
.Y
, xShape
->getPosition().Y
);
2224 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf145207
)
2226 createSwDoc("tdf145207.odt");
2228 CPPUNIT_ASSERT_EQUAL(1, getPages());
2229 CPPUNIT_ASSERT_EQUAL(3, getShapes());
2231 //select one shape and use the TAB key to iterate over the different shapes
2234 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2235 for (sal_Int32 i
= 0; i
< 10; ++i
)
2237 // Without the fix in place, this test would have crashed here
2238 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
2239 Scheduler::ProcessEventsToIdle();
2243 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf128782
)
2245 createSwDoc("tdf128782.odt");
2247 CPPUNIT_ASSERT_EQUAL(2, getShapes());
2248 uno::Reference
<drawing::XShape
> xShape1
= getShape(1);
2249 uno::Reference
<drawing::XShape
> xShape2
= getShape(2);
2252 aPos
[0] = xShape1
->getPosition();
2253 aPos
[1] = xShape2
->getPosition();
2255 //select shape 2 and move it down
2258 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2259 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DOWN
);
2260 Scheduler::ProcessEventsToIdle();
2262 CPPUNIT_ASSERT_EQUAL(aPos
[0].X
, xShape1
->getPosition().X
);
2263 CPPUNIT_ASSERT_EQUAL(aPos
[0].Y
, xShape1
->getPosition().Y
);
2264 CPPUNIT_ASSERT_EQUAL(aPos
[1].X
, xShape2
->getPosition().X
);
2265 //Y position in shape 2 has changed
2266 CPPUNIT_ASSERT(aPos
[1].Y
< xShape2
->getPosition().Y
);
2268 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2270 CPPUNIT_ASSERT_EQUAL(aPos
[0].X
, xShape1
->getPosition().X
);
2271 CPPUNIT_ASSERT_EQUAL(aPos
[0].Y
, xShape1
->getPosition().Y
);
2272 CPPUNIT_ASSERT_EQUAL(aPos
[1].X
, xShape2
->getPosition().X
);
2273 // Shape2 has come back to the original position
2274 // without the fix in place, it would have failed
2275 CPPUNIT_ASSERT_EQUAL(aPos
[1].Y
, xShape2
->getPosition().Y
);
2278 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf135623
)
2280 createSwDoc("tdf135623.docx");
2282 CPPUNIT_ASSERT_EQUAL(2, getShapes());
2283 CPPUNIT_ASSERT_EQUAL(2, getPages());
2285 uno::Reference
<drawing::XShape
> xShape1
= getShape(1);
2286 uno::Reference
<drawing::XShape
> xShape2
= getShape(2);
2289 aPos
[0] = xShape1
->getPosition();
2290 aPos
[1] = xShape2
->getPosition();
2292 //select shape 1 and move it down
2295 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2296 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DOWN
);
2297 Scheduler::ProcessEventsToIdle();
2299 CPPUNIT_ASSERT_EQUAL(aPos
[0].X
, xShape1
->getPosition().X
);
2300 //Y position in shape 1 has changed
2301 CPPUNIT_ASSERT(aPos
[0].Y
< xShape1
->getPosition().Y
);
2302 CPPUNIT_ASSERT_EQUAL(aPos
[1].X
, xShape2
->getPosition().X
);
2303 CPPUNIT_ASSERT_EQUAL(aPos
[1].Y
, xShape2
->getPosition().Y
);
2305 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2307 CPPUNIT_ASSERT_EQUAL(aPos
[0].X
, xShape1
->getPosition().X
);
2308 CPPUNIT_ASSERT_EQUAL(aPos
[0].Y
, xShape1
->getPosition().Y
);
2309 CPPUNIT_ASSERT_EQUAL(aPos
[1].X
, xShape2
->getPosition().X
);
2311 // Without the fix in place, this test would have failed here
2314 CPPUNIT_ASSERT_EQUAL(aPos
[1].Y
, xShape2
->getPosition().Y
);
2316 CPPUNIT_ASSERT_EQUAL(2, getPages());
2319 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf133490
)
2321 createSwDoc("tdf133490.odt");
2323 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2325 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2327 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
2329 CPPUNIT_ASSERT_EQUAL(0, getShapes());
2331 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
2333 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2335 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
2337 CPPUNIT_ASSERT_EQUAL(2, getShapes());
2339 uno::Reference
<drawing::XShape
> xShape1
= getShape(1);
2340 uno::Reference
<drawing::XShape
> xShape2
= getShape(2);
2343 aPos
[0] = xShape1
->getPosition();
2344 aPos
[1] = xShape2
->getPosition();
2346 //select shape 2 and move it to the right
2349 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2350 for (sal_Int32 i
= 0; i
< 5; ++i
)
2352 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_RIGHT
);
2353 Scheduler::ProcessEventsToIdle();
2356 CPPUNIT_ASSERT_EQUAL(aPos
[0].X
, xShape1
->getPosition().X
);
2357 CPPUNIT_ASSERT_EQUAL(aPos
[0].Y
, xShape1
->getPosition().Y
);
2358 //X position in shape 2 has changed
2359 CPPUNIT_ASSERT(aPos
[1].X
< xShape2
->getPosition().X
);
2360 CPPUNIT_ASSERT_EQUAL(aPos
[1].Y
, xShape2
->getPosition().Y
);
2362 for (sal_Int32 i
= 0; i
< 4; ++i
)
2364 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2366 // Without the fix in place, undo action would have changed shape1's position
2367 // and this test would have failed with
2370 CPPUNIT_ASSERT_EQUAL(aPos
[0].X
, xShape1
->getPosition().X
);
2371 CPPUNIT_ASSERT_EQUAL(aPos
[0].Y
, xShape1
->getPosition().Y
);
2372 CPPUNIT_ASSERT(aPos
[1].X
< xShape2
->getPosition().X
);
2373 CPPUNIT_ASSERT_EQUAL(aPos
[1].Y
, xShape2
->getPosition().Y
);
2376 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2378 CPPUNIT_ASSERT_EQUAL(aPos
[0].X
, xShape1
->getPosition().X
);
2379 CPPUNIT_ASSERT_EQUAL(aPos
[0].Y
, xShape1
->getPosition().Y
);
2380 // Shape 2 has come back to the original position
2381 CPPUNIT_ASSERT_EQUAL(aPos
[1].X
, xShape2
->getPosition().X
);
2382 CPPUNIT_ASSERT_EQUAL(aPos
[1].Y
, xShape2
->getPosition().Y
);
2384 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2386 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2388 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2390 CPPUNIT_ASSERT_EQUAL(0, getShapes());
2392 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2394 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2397 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf132637_protectTrackChanges
)
2399 createSwDoc("tdf132637_protectTrackChanges.doc");
2401 // The password should only prevent turning off track changes, not open as read-only
2402 CPPUNIT_ASSERT(!getSwDocShell()->IsReadOnly());
2405 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf127652
)
2407 createSwDoc("tdf127652.odt");
2408 SwDoc
* pDoc
= getSwDoc();
2409 SwWrtShell
* const pWrtShell
= getSwDocShell()->GetWrtShell();
2411 // get a page cursor
2412 uno::Reference
<frame::XModel
> xModel(mxComponent
, uno::UNO_QUERY
);
2413 uno::Reference
<text::XTextViewCursorSupplier
> xTextViewCursorSupplier(
2414 xModel
->getCurrentController(), uno::UNO_QUERY
);
2415 uno::Reference
<text::XPageCursor
> xCursor(xTextViewCursorSupplier
->getViewCursor(),
2418 // go to the start of page 4
2419 xCursor
->jumpToPage(4);
2420 xCursor
->jumpToStartOfPage();
2422 // mark a section that overlaps multiple pages
2423 pWrtShell
->Down(false, 2);
2424 pWrtShell
->Up(true, 5);
2426 // delete the marked section
2427 pWrtShell
->DelRight();
2429 // go to the start of page 4
2430 xCursor
->jumpToPage(4);
2431 xCursor
->jumpToStartOfPage();
2433 // move up to page 3
2434 pWrtShell
->Up(false, 5);
2436 // check that we are on the third page
2437 // in the bug one issue was that the cursor was placed incorrectly, so
2438 // moving up to the previous page would not work any more
2439 sal_uInt16 assertPage
= 3;
2440 SwCursorShell
* pShell(pDoc
->GetEditShell());
2441 CPPUNIT_ASSERT(pShell
);
2442 sal_uInt16 currentPage
= pShell
->GetPageNumSeqNonEmpty();
2443 CPPUNIT_ASSERT_EQUAL_MESSAGE("We are on the wrong page!", assertPage
, currentPage
);
2446 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, AtPageTextBoxCrash
)
2449 createSwDoc("AtPageTextBoxCrash.odt");
2450 SwDoc
* pDoc
= getSwDoc();
2452 // Get the format of the shape
2453 const auto& rFrmFormats
= *pDoc
->GetSpzFrameFormats();
2454 CPPUNIT_ASSERT(rFrmFormats
.size() >= size_t(o3tl::make_unsigned(1)));
2455 auto pShape
= rFrmFormats
.front();
2456 CPPUNIT_ASSERT(pShape
);
2458 // Add a textbox to the shape
2459 SwTextBoxHelper::create(pShape
, pShape
->FindRealSdrObject());
2460 auto pTxBxFrm
= SwTextBoxHelper::getOtherTextBoxFormat(getShape(1));
2461 CPPUNIT_ASSERT(pTxBxFrm
);
2463 // Change its anchor to page
2464 uno::Reference
<beans::XPropertySet
> xShpProps(getShape(1), uno::UNO_QUERY_THROW
);
2465 xShpProps
->setPropertyValue(
2466 u
"AnchorType"_ustr
, uno::Any(text::TextContentAnchorType::TextContentAnchorType_AT_PAGE
));
2468 // The page anchored objects must not have content anchor
2469 // unless this will lead to crash later, for example on
2470 // removing the paragraph where it is anchored to...
2471 CPPUNIT_ASSERT_EQUAL(RndStdIds::FLY_AT_PAGE
, pTxBxFrm
->GetAnchor().GetAnchorId());
2472 CPPUNIT_ASSERT(!pTxBxFrm
->GetAnchor().GetAnchorNode());
2474 // Remove the paragraph where the textframe should be anchored
2475 // before. Now with the patch it must not crash...
2476 auto xPara
= getParagraph(1);
2477 xPara
->getText()->setString(OUString());
2480 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf135661
)
2482 createSwDoc("tdf135661.odt");
2484 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2485 uno::Reference
<drawing::XShape
> xShape(getShape(1), uno::UNO_QUERY
);
2486 CPPUNIT_ASSERT_EQUAL(sal_Int32(3424), xShape
->getPosition().X
);
2487 CPPUNIT_ASSERT_EQUAL(sal_Int32(1545), xShape
->getPosition().Y
);
2489 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2490 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
2492 CPPUNIT_ASSERT_EQUAL(0, getShapes());
2494 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2496 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2498 xShape
.set(getShape(1), uno::UNO_QUERY
);
2500 //Without the fix in place, the shape position would have been 0,0
2501 CPPUNIT_ASSERT_EQUAL(sal_Int32(3424), xShape
->getPosition().X
);
2502 CPPUNIT_ASSERT_EQUAL(sal_Int32(1545), xShape
->getPosition().Y
);
2505 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf133477
)
2507 if (getDefaultDeviceBitCount() < 24)
2509 createSwDoc("tdf133477.fodt");
2511 // Save the shape to a BMP.
2512 uno::Reference
<drawing::XGraphicExportFilter
> xGraphicExporter
2513 = drawing::GraphicExportFilter::create(m_xContext
);
2514 uno::Reference
<lang::XComponent
> xSourceDoc(getShape(1), uno::UNO_QUERY
);
2515 xGraphicExporter
->setSourceDocument(xSourceDoc
);
2517 SvMemoryStream aStream
;
2518 uno::Reference
<io::XOutputStream
> xOutputStream(new utl::OStreamWrapper(aStream
));
2519 uno::Sequence
<beans::PropertyValue
> aDescriptor(comphelper::InitPropertySequence(
2520 { { "OutputStream", uno::Any(xOutputStream
) }, { "FilterName", uno::Any(u
"BMP"_ustr
) } }));
2521 xGraphicExporter
->filter(aDescriptor
);
2522 aStream
.Seek(STREAM_SEEK_TO_BEGIN
);
2524 // Read it back and check the color of the first pixel.
2525 // (Actually check at one-pixel offset, because imprecise shape positioning may
2526 // result in blending with background for the first pixel).
2528 TypeSerializer
aSerializer(aStream
);
2529 aSerializer
.readGraphic(aGraphic
);
2531 BitmapEx aBitmap
= aGraphic
.GetBitmapEx();
2532 CPPUNIT_ASSERT_EQUAL(Color(0, 102, 204), aBitmap
.GetPixelColor(1, 1));
2535 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf137964
)
2537 createSwDoc("tdf137964.odt");
2538 SwDoc
* pDoc
= getSwDoc();
2539 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
2541 CPPUNIT_ASSERT_EQUAL(1, getShapes());
2542 uno::Reference
<drawing::XShape
> xShape(getShape(1), uno::UNO_QUERY
);
2543 CPPUNIT_ASSERT_EQUAL(sal_Int32(3579), xShape
->getPosition().X
);
2544 CPPUNIT_ASSERT_EQUAL(sal_Int32(4090), xShape
->getPosition().Y
);
2546 SdrPage
* pPage
= pDoc
->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
2547 SdrObject
* pObject
= pPage
->GetObj(1);
2548 SwContact
* pTextBox
= static_cast<SwContact
*>(pObject
->GetUserCall());
2549 CPPUNIT_ASSERT_EQUAL(sal_uInt16(RES_FLYFRMFMT
), pTextBox
->GetFormat()->Which());
2551 pWrtShell
->SelectObj(Point(), 0, pObject
);
2553 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2554 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_SHIFT
| KEY_UP
);
2555 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_SHIFT
| KEY_LEFT
);
2556 Scheduler::ProcessEventsToIdle();
2558 // Without the fix in place, the shape would have stayed where it was
2559 CPPUNIT_ASSERT_EQUAL(sal_Int32(2579), xShape
->getPosition().X
);
2560 CPPUNIT_ASSERT_EQUAL(sal_Int32(3090), xShape
->getPosition().Y
);
2563 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf143244
)
2565 createSwDoc("tdf143244.odt");
2567 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2568 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2570 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2571 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2572 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable
->getRows()->getCount());
2573 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getColumns()->getCount());
2575 uno::Reference
<text::XTextRange
> xCell(xTextTable
->getCellByName(u
"A1"_ustr
), uno::UNO_QUERY
);
2576 CPPUNIT_ASSERT_EQUAL(Color(0x009353), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2578 xCell
.set(xTextTable
->getCellByName(u
"A2"_ustr
), uno::UNO_QUERY
);
2579 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2581 xCell
.set(xTextTable
->getCellByName(u
"A3"_ustr
), uno::UNO_QUERY
);
2582 CPPUNIT_ASSERT_EQUAL(Color(0xdddddd), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2584 xCell
.set(xTextTable
->getCellByName(u
"A4"_ustr
), uno::UNO_QUERY
);
2585 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2587 xCell
.set(xTextTable
->getCellByName(u
"A5"_ustr
), uno::UNO_QUERY
);
2588 CPPUNIT_ASSERT_EQUAL(Color(0xdddddd), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2590 xCell
.set(xTextTable
->getCellByName(u
"A6"_ustr
), uno::UNO_QUERY
);
2591 CPPUNIT_ASSERT_EQUAL(Color(0xbee3d3), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2593 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2594 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
2596 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess
->getCount());
2598 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
2600 xTextTable
.set(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2601 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable
->getRows()->getCount());
2602 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getColumns()->getCount());
2604 dispatchCommand(mxComponent
, u
".uno:GoUp"_ustr
, {});
2606 SwXTextDocument
* pTextDoc
= getSwTextDoc();
2607 for (sal_Int32 i
= 0; i
< 6; ++i
)
2609 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_TAB
);
2610 Scheduler::ProcessEventsToIdle();
2613 for (sal_Int32 i
= 0; i
< 5; ++i
)
2615 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2618 xTextTable
.set(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2619 CPPUNIT_ASSERT_EQUAL(sal_Int32(6), xTextTable
->getRows()->getCount());
2620 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getColumns()->getCount());
2622 for (sal_Int32 i
= 0; i
< 5; ++i
)
2624 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {});
2627 xTextTable
.set(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2628 CPPUNIT_ASSERT_EQUAL(sal_Int32(9), xTextTable
->getRows()->getCount());
2629 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getColumns()->getCount());
2631 xCell
.set(xTextTable
->getCellByName(u
"A1"_ustr
), uno::UNO_QUERY
);
2632 CPPUNIT_ASSERT_EQUAL(Color(0x009353), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2634 xCell
.set(xTextTable
->getCellByName(u
"A2"_ustr
), uno::UNO_QUERY
);
2635 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2637 xCell
.set(xTextTable
->getCellByName(u
"A3"_ustr
), uno::UNO_QUERY
);
2638 CPPUNIT_ASSERT_EQUAL(Color(0xdddddd), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2640 xCell
.set(xTextTable
->getCellByName(u
"A4"_ustr
), uno::UNO_QUERY
);
2641 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2643 xCell
.set(xTextTable
->getCellByName(u
"A5"_ustr
), uno::UNO_QUERY
);
2644 CPPUNIT_ASSERT_EQUAL(Color(0xdddddd), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2646 xCell
.set(xTextTable
->getCellByName(u
"A6"_ustr
), uno::UNO_QUERY
);
2648 // Without the fix in place, this test would have failed with
2649 // - Expected: Color: R:255 G:255 B:255 A:255
2650 // - Actual : Color: R:190 G:227 B:211 A:0
2651 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2653 xCell
.set(xTextTable
->getCellByName(u
"A7"_ustr
), uno::UNO_QUERY
);
2654 CPPUNIT_ASSERT_EQUAL(Color(0xdddddd), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2656 xCell
.set(xTextTable
->getCellByName(u
"A8"_ustr
), uno::UNO_QUERY
);
2657 CPPUNIT_ASSERT_EQUAL(COL_AUTO
, getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2659 xCell
.set(xTextTable
->getCellByName(u
"A9"_ustr
), uno::UNO_QUERY
);
2660 CPPUNIT_ASSERT_EQUAL(Color(0xbee3d3), getProperty
<Color
>(xCell
, u
"BackColor"_ustr
));
2663 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf136715
)
2665 createSwDoc("tdf136715.odt");
2667 uno::Reference
<text::XTextTablesSupplier
> xTextTablesSupplier(mxComponent
, uno::UNO_QUERY
);
2668 uno::Reference
<container::XIndexAccess
> xIndexAccess(xTextTablesSupplier
->getTextTables(),
2670 uno::Reference
<text::XTextTable
> xTextTable(xIndexAccess
->getByIndex(0), uno::UNO_QUERY
);
2671 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess
->getCount());
2672 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTextTable
->getRows()->getCount());
2673 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable
->getColumns()->getCount());
2675 uno::Reference
<text::XTextRange
> xCell(xTextTable
->getCellByName(u
"A1"_ustr
), uno::UNO_QUERY
);
2676 uno::Reference
<container::XEnumerationAccess
> xParaEnumAccess(xCell
->getText(), uno::UNO_QUERY
);
2677 uno::Reference
<container::XEnumeration
> xParaEnum
= xParaEnumAccess
->createEnumeration();
2678 uno::Reference
<text::XTextRange
> xPara(xParaEnum
->nextElement(), uno::UNO_QUERY
);
2679 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD
, getProperty
<float>(xPara
, u
"CharWeight"_ustr
));
2681 xCell
.set(xTextTable
->getCellByName(u
"A2"_ustr
), uno::UNO_QUERY
);
2682 xParaEnumAccess
.set(xCell
->getText(), uno::UNO_QUERY
);
2683 xParaEnum
.set(xParaEnumAccess
->createEnumeration());
2684 xPara
.set(xParaEnum
->nextElement(), uno::UNO_QUERY
);
2685 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL
, getProperty
<float>(xPara
, u
"CharWeight"_ustr
));
2687 xCell
.set(xTextTable
->getCellByName(u
"A3"_ustr
), uno::UNO_QUERY
);
2688 xParaEnumAccess
.set(xCell
->getText(), uno::UNO_QUERY
);
2689 xParaEnum
.set(xParaEnumAccess
->createEnumeration());
2690 xPara
.set(xParaEnum
->nextElement(), uno::UNO_QUERY
);
2691 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL
, getProperty
<float>(xPara
, u
"CharWeight"_ustr
));
2693 xCell
.set(xTextTable
->getCellByName(u
"A4"_ustr
), uno::UNO_QUERY
);
2694 xParaEnumAccess
.set(xCell
->getText(), uno::UNO_QUERY
);
2695 xParaEnum
.set(xParaEnumAccess
->createEnumeration());
2696 xPara
.set(xParaEnum
->nextElement(), uno::UNO_QUERY
);
2697 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD
, getProperty
<float>(xPara
, u
"CharWeight"_ustr
));
2699 dispatchCommand(mxComponent
, u
".uno:GoDown"_ustr
, {});
2700 dispatchCommand(mxComponent
, u
".uno:GoDown"_ustr
, {});
2701 dispatchCommand(mxComponent
, u
".uno:LineDownSel"_ustr
, {});
2702 dispatchCommand(mxComponent
, u
".uno:DeleteRows"_ustr
, {});
2704 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable
->getRows()->getCount());
2705 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable
->getColumns()->getCount());
2707 xCell
.set(xTextTable
->getCellByName(u
"A1"_ustr
), uno::UNO_QUERY
);
2708 xParaEnumAccess
.set(xCell
->getText(), uno::UNO_QUERY
);
2709 xParaEnum
.set(xParaEnumAccess
->createEnumeration());
2710 xPara
.set(xParaEnum
->nextElement(), uno::UNO_QUERY
);
2711 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD
, getProperty
<float>(xPara
, u
"CharWeight"_ustr
));
2713 xCell
.set(xTextTable
->getCellByName(u
"A2"_ustr
), uno::UNO_QUERY
);
2714 xParaEnumAccess
.set(xCell
->getText(), uno::UNO_QUERY
);
2715 xParaEnum
.set(xParaEnumAccess
->createEnumeration());
2716 xPara
.set(xParaEnum
->nextElement(), uno::UNO_QUERY
);
2717 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD
, getProperty
<float>(xPara
, u
"CharWeight"_ustr
));
2719 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2721 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTextTable
->getRows()->getCount());
2722 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTextTable
->getColumns()->getCount());
2724 xCell
.set(xTextTable
->getCellByName(u
"A1"_ustr
), uno::UNO_QUERY
);
2725 xParaEnumAccess
.set(xCell
->getText(), uno::UNO_QUERY
);
2726 xParaEnum
.set(xParaEnumAccess
->createEnumeration());
2727 xPara
.set(xParaEnum
->nextElement(), uno::UNO_QUERY
);
2728 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD
, getProperty
<float>(xPara
, u
"CharWeight"_ustr
));
2730 xCell
.set(xTextTable
->getCellByName(u
"A2"_ustr
), uno::UNO_QUERY
);
2731 xParaEnumAccess
.set(xCell
->getText(), uno::UNO_QUERY
);
2732 xParaEnum
.set(xParaEnumAccess
->createEnumeration());
2733 xPara
.set(xParaEnum
->nextElement(), uno::UNO_QUERY
);
2735 // Without the fix in place, this test would have failed with
2738 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL
, getProperty
<float>(xPara
, u
"CharWeight"_ustr
));
2740 xCell
.set(xTextTable
->getCellByName(u
"A3"_ustr
), uno::UNO_QUERY
);
2741 xParaEnumAccess
.set(xCell
->getText(), uno::UNO_QUERY
);
2742 xParaEnum
.set(xParaEnumAccess
->createEnumeration());
2743 xPara
.set(xParaEnum
->nextElement(), uno::UNO_QUERY
);
2744 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL
, getProperty
<float>(xPara
, u
"CharWeight"_ustr
));
2746 xCell
.set(xTextTable
->getCellByName(u
"A4"_ustr
), uno::UNO_QUERY
);
2747 xParaEnumAccess
.set(xCell
->getText(), uno::UNO_QUERY
);
2748 xParaEnum
.set(xParaEnumAccess
->createEnumeration());
2749 xPara
.set(xParaEnum
->nextElement(), uno::UNO_QUERY
);
2750 CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD
, getProperty
<float>(xPara
, u
"CharWeight"_ustr
));
2753 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf138897
)
2755 createSwDoc("tdf100018-1.odt");
2757 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2758 dispatchCommand(mxComponent
, u
".uno:Cut"_ustr
, {});
2759 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
2760 // this was crashing
2761 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2762 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {});
2763 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
2764 dispatchCommand(mxComponent
, u
".uno:Redo"_ustr
, {});
2767 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf136740
)
2770 css::uno::Reference
<css::lang::XMultiServiceFactory
> xFact(mxComponent
,
2771 css::uno::UNO_QUERY_THROW
);
2772 css::uno::Reference
<css::beans::XPropertySet
> xTextDefaults(
2773 xFact
->createInstance(u
"com.sun.star.text.Defaults"_ustr
), css::uno::UNO_QUERY_THROW
);
2774 const css::uno::Any aOrig
= xTextDefaults
->getPropertyValue(u
"TabStopDistance"_ustr
);
2775 sal_Int32 nDefTab
= aOrig
.get
<sal_Int32
>();
2776 CPPUNIT_ASSERT(nDefTab
!= 0);
2778 css::uno::Reference
<css::text::XTextRange
> const xParagraph(getParagraphOrTable(1),
2779 css::uno::UNO_QUERY_THROW
);
2780 xParagraph
->setString(u
"Foo"_ustr
);
2782 CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
2783 CPPUNIT_ASSERT_EQUAL(u
"Foo"_ustr
, xParagraph
->getString());
2785 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2786 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
2787 dispatchCommand(mxComponent
, u
".uno:GoToEndOfDoc"_ustr
, {});
2789 const css::uno::Any
aNew(nDefTab
* 2);
2790 xTextDefaults
->setPropertyValue(u
"TabStopDistance"_ustr
, aNew
);
2791 // it may become slightly different because of conversions, so get the actual value
2792 const css::uno::Any aNewCorrected
= xTextDefaults
->getPropertyValue(u
"TabStopDistance"_ustr
);
2793 CPPUNIT_ASSERT_DOUBLES_EQUAL(nDefTab
* 2, aNewCorrected
.get
<sal_Int32
>(), 1);
2795 // Paste special as RTF
2796 const auto aPropertyValues
= comphelper::InitPropertySequence(
2797 { { "SelectedFormat",
2798 css::uno::Any(static_cast<sal_uInt32
>(SotClipboardFormatId::RTF
)) } });
2799 dispatchCommand(mxComponent
, u
".uno:ClipboardFormatItems"_ustr
, aPropertyValues
);
2801 CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
2802 CPPUNIT_ASSERT_EQUAL(u
"FooFoo"_ustr
, xParagraph
->getString());
2804 // Without the fix in place, this would fail with
2805 // equality assertion failed
2806 // - Expected: <Any: (long) 2501>
2807 // - Actual : <Any: (long) 1251>
2808 // i.e., pasting RTF would reset the modified default tab stop distance to hardcoded default
2809 CPPUNIT_ASSERT_EQUAL(aNewCorrected
, xTextDefaults
->getPropertyValue(u
"TabStopDistance"_ustr
));
2812 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf128106
)
2814 createSwDoc("cross_reference_demo_bmk.odt");
2816 const auto aPropertyValues
2817 = comphelper::InitPropertySequence({ { "FileName", css::uno::Any(maTempFile
.GetURL()) } });
2818 dispatchCommand(mxComponent
, u
".uno:NewGlobalDoc"_ustr
, aPropertyValues
);
2820 // Use loadFromDesktop instead of loadFromURL to avoid calling mxComponent->dispose()
2821 // Otherwise it fails with 'DeInitVCL: some top Windows are still alive'
2822 mxComponent
= loadFromDesktop(maTempFile
.GetURL());
2824 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
2825 SwDoc
* const pMasterDoc(pWrtShell
->GetDoc());
2826 CPPUNIT_ASSERT_EQUAL(
2828 pMasterDoc
->getIDocumentLinksAdministration().GetLinkManager().GetLinks().size());
2829 // no way to set SwDocShell::m_nUpdateDocMode away from NO_UPDATE ?
2830 // pMasterDoc->getIDocumentLinksAdministration().UpdateLinks();
2831 pMasterDoc
->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks(
2832 false, false, nullptr, u
""_ustr
);
2833 // note: this has called SwGetRefFieldType::UpdateGetReferences()
2834 SwFieldType
const* const pType(
2835 pMasterDoc
->getIDocumentFieldsAccess().GetSysFieldType(SwFieldIds::GetRef
));
2836 std::vector
<SwFormatField
*> fields
;
2837 pType
->GatherFields(fields
);
2838 CPPUNIT_ASSERT_EQUAL(size_t(6), fields
.size());
2839 std::sort(fields
.begin(), fields
.end(), [](auto const* const pA
, auto const* const pB
) {
2840 SwTextField
const* const pHintA(pA
->GetTextField());
2841 SwTextField
const* const pHintB(pB
->GetTextField());
2842 // in this document: only 1 field per node
2843 CPPUNIT_ASSERT(pA
== pB
|| &pHintA
->GetTextNode() != &pHintB
->GetTextNode());
2844 return pHintA
->GetTextNode().GetIndex() < pHintB
->GetTextNode().GetIndex();
2846 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK
), fields
[0]->GetField()->GetSubType());
2847 CPPUNIT_ASSERT_EQUAL(u
"bookmarkchapter1_text"_ustr
,
2848 static_cast<SwGetRefField
const*>(fields
[0]->GetField())->GetSetRefName());
2849 CPPUNIT_ASSERT_EQUAL(u
"Text"_ustr
,
2850 static_cast<SwGetRefField
const*>(fields
[0]->GetField())
2851 ->GetExpandedTextOfReferencedTextNode(*pWrtShell
->GetLayout()));
2852 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK
), fields
[1]->GetField()->GetSubType());
2854 static_cast<SwGetRefField
const*>(fields
[1]->GetField())->IsRefToHeadingCrossRefBookmark());
2855 CPPUNIT_ASSERT_EQUAL(u
"Chapter 2"_ustr
,
2856 static_cast<SwGetRefField
const*>(fields
[1]->GetField())->GetPar2());
2857 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK
), fields
[2]->GetField()->GetSubType());
2858 CPPUNIT_ASSERT_EQUAL(u
"Bookmarkchapter1"_ustr
,
2859 static_cast<SwGetRefField
const*>(fields
[2]->GetField())->GetSetRefName());
2860 CPPUNIT_ASSERT_EQUAL(u
"Chapter 1"_ustr
,
2861 static_cast<SwGetRefField
const*>(fields
[2]->GetField())->GetPar2());
2862 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK
), fields
[3]->GetField()->GetSubType());
2863 CPPUNIT_ASSERT_EQUAL(u
"bookmarkchapter1_text"_ustr
,
2864 static_cast<SwGetRefField
const*>(fields
[3]->GetField())->GetSetRefName());
2865 CPPUNIT_ASSERT_EQUAL(u
"Text"_ustr
,
2866 static_cast<SwGetRefField
const*>(fields
[3]->GetField())->GetPar2());
2867 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK
), fields
[4]->GetField()->GetSubType());
2869 static_cast<SwGetRefField
const*>(fields
[4]->GetField())->IsRefToHeadingCrossRefBookmark());
2870 CPPUNIT_ASSERT_EQUAL(u
"Chapter 1.1"_ustr
,
2871 static_cast<SwGetRefField
const*>(fields
[4]->GetField())->GetPar2());
2872 CPPUNIT_ASSERT_EQUAL(sal_uInt16(REF_BOOKMARK
), fields
[5]->GetField()->GetSubType());
2874 static_cast<SwGetRefField
const*>(fields
[5]->GetField())->IsRefToHeadingCrossRefBookmark());
2875 CPPUNIT_ASSERT_EQUAL(u
"Chapter 2"_ustr
,
2876 static_cast<SwGetRefField
const*>(fields
[5]->GetField())->GetPar2());
2879 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf103612
)
2881 createSwGlobalDoc("DUMMY.odm");
2882 SwDoc
* pDoc
= getSwDoc();
2883 CPPUNIT_ASSERT_EQUAL(
2884 size_t(1), pDoc
->getIDocumentLinksAdministration().GetLinkManager().GetLinks().size());
2885 pDoc
->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks(false, false, nullptr,
2888 xmlDocUniquePtr pLayout
= parseLayoutDump();
2890 assertXPath(pLayout
, "/root/page[1]/body/section[1]/txt[1]/SwParaPortion/SwLineLayout[1]",
2891 "portion", u
"Text before section");
2892 // the inner section and its content was hidden
2893 assertXPath(pLayout
, "/root/page[1]/body/section[2]/txt[1]/SwParaPortion/SwLineLayout[1]",
2894 "portion", u
"Text inside section before ToC");
2895 assertXPath(pLayout
, "/root/page[1]/body/section[3]/txt[1]/SwParaPortion/SwLineLayout[1]",
2896 "portion", u
"Table of Contents");
2897 assertXPath(pLayout
, "/root/page[1]/body/section[4]/txt[1]/SwParaPortion/SwLineLayout[1]",
2898 "portion", u
"First header*1");
2899 assertXPath(pLayout
, "/root/page[1]/body/section[4]/txt[2]/SwParaPortion/SwLineLayout[1]",
2900 "portion", u
"Second header*1");
2901 assertXPath(pLayout
, "/root/page[1]/body/section[5]/txt[2]/SwParaPortion/SwLineLayout[1]",
2902 "portion", u
"Text inside section after ToC");
2903 assertXPath(pLayout
, "/root/page[1]/body/section[6]/txt[1]/SwParaPortion/SwLineLayout[1]",
2904 "portion", u
"Text after section");
2907 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf97899
)
2910 SwDoc
* pDoc
= getSwDoc();
2911 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
2912 SwCursorShell
* pShell(pDoc
->GetEditShell());
2913 CPPUNIT_ASSERT(pShell
);
2914 SwPaM
* pCursor
= pShell
->GetCursor();
2916 IDocumentContentOperations
& rIDCO(pDoc
->getIDocumentContentOperations());
2918 // Create an Ordered List
2919 rIDCO
.InsertString(*pCursor
, u
"\ta"_ustr
);
2920 pWrtShell
->SplitNode();
2921 rIDCO
.InsertString(*pCursor
, u
" b"_ustr
);
2922 pWrtShell
->SplitNode();
2923 rIDCO
.InsertString(*pCursor
, u
" \t c"_ustr
);
2925 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
2926 dispatchCommand(mxComponent
, u
".uno:DefaultNumbering"_ustr
, {});
2928 // tdf#109285: RemoveLeadingWhiteSpace from all numbered paragraphs
2929 getParagraph(1, u
"a"_ustr
);
2930 getParagraph(2, u
"b"_ustr
);
2931 getParagraph(3, u
"c"_ustr
);
2933 // Save it as DOCX & load it again
2934 saveAndReload(u
"Office Open XML Text"_ustr
);
2935 uno::Reference
<container::XIndexAccess
> xNumberingRules
2936 = getProperty
<uno::Reference
<container::XIndexAccess
>>(getParagraph(1),
2937 u
"NumberingRules"_ustr
);
2938 CPPUNIT_ASSERT(xNumberingRules
->getCount());
2939 uno::Sequence
<beans::PropertyValue
> aNumbering
;
2940 xNumberingRules
->getByIndex(0) >>= aNumbering
;
2941 OUString sCharStyleName
;
2942 for (const auto& prop
: aNumbering
)
2944 if (prop
.Name
== "CharStyleName")
2946 prop
.Value
>>= sCharStyleName
;
2950 CPPUNIT_ASSERT(!sCharStyleName
.isEmpty());
2953 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf40142
)
2955 createSwDoc("tdf40142.odt");
2956 dispatchCommand(mxComponent
, u
".uno:UpdateAllIndexes"_ustr
, {});
2958 xmlDocUniquePtr pLayout
= parseLayoutDump();
2959 // Without the fix in place, this test would have failed with
2962 assertXPath(pLayout
, "/root/page[1]/body/section[2]/txt", 2);
2965 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf151462
)
2967 createSwDoc("tdf151462.odt");
2968 dispatchCommand(mxComponent
, u
".uno:UpdateAllIndexes"_ustr
, {});
2970 xmlDocUniquePtr pLayout
= parseLayoutDump();
2971 // Without the fix in place, there would be just the first index entry
2972 assertXPath(pLayout
,
2973 "/root/page[1]/body/txt[2]/anchored/fly/section/txt[1]/SwParaPortion/"
2974 "SwLineLayout[1]/SwLinePortion[1]",
2975 "portion", u
"sub one");
2976 assertXPath(pLayout
,
2977 "/root/page[1]/body/txt[2]/anchored/fly/section/txt[2]/SwParaPortion/"
2978 "SwLineLayout[1]/SwLinePortion[1]",
2979 "portion", u
"sub two");
2980 assertXPath(pLayout
,
2981 "/root/page[1]/body/txt[2]/anchored/fly/section/txt[3]/SwParaPortion/"
2982 "SwLineLayout[1]/SwLinePortion[1]",
2983 "portion", u
"sub three");
2985 // Without the fix in place, there would be just the first index entry
2986 assertXPath(pLayout
,
2987 "/root/page[1]/body/txt[6]/anchored/fly/section/txt[1]/SwParaPortion/"
2988 "SwLineLayout[1]/SwLinePortion[1]",
2989 "portion", u
"another sub one");
2990 assertXPath(pLayout
,
2991 "/root/page[1]/body/txt[6]/anchored/fly/section/txt[2]/SwParaPortion/"
2992 "SwLineLayout[1]/SwLinePortion[1]",
2993 "portion", u
"another sub two");
2994 assertXPath(pLayout
,
2995 "/root/page[1]/body/txt[6]/anchored/fly/section/txt[3]/SwParaPortion/"
2996 "SwLineLayout[1]/SwLinePortion[1]",
2997 "portion", u
"another sub three");
3000 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf153636
)
3002 createSwDoc("tdf153636.odt");
3003 dispatchCommand(mxComponent
, u
".uno:UpdateAllIndexes"_ustr
, {});
3004 saveAndReload(u
"writer8"_ustr
);
3006 xmlDocUniquePtr pXmlDoc
= parseExport(u
"content.xml"_ustr
);
3007 CPPUNIT_ASSERT(pXmlDoc
);
3009 for (int i
= 1; i
<= 3; i
+= 2)
3011 const OUString frameStyleName
3013 "/office:document-content/office:body/office:text/"
3014 "text:user-index[@text:name='User-Defined1']/text:index-body/text:p["
3015 + OString::number(i
) + "]",
3017 const OUString tableStyleName
3019 "/office:document-content/office:body/office:text/"
3020 "text:user-index[@text:name='User-Defined1']/text:index-body/text:p["
3021 + OString::number(i
+ 1) + "]",
3024 // Without the fix in place, the frame and table indentation would differ
3025 CPPUNIT_ASSERT_EQUAL(frameStyleName
, tableStyleName
);
3029 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf157129
)
3031 // Unit test for tdf#157129
3032 // Test to see if cursor moves to the end after paste
3034 // First document containing test data
3035 createSwDoc("tdf157129.doc");
3036 CPPUNIT_ASSERT_EQUAL(5, getParagraphs());
3037 // Copy data from first document
3038 dispatchCommand(mxComponent
, u
".uno:SelectAll"_ustr
, {});
3039 dispatchCommand(mxComponent
, u
".uno:Copy"_ustr
, {});
3041 // Create a new document
3043 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
3045 CPPUNIT_ASSERT_EQUAL(1, getParagraphs());
3047 // Paste data from first document
3048 dispatchCommand(mxComponent
, u
".uno:Paste"_ustr
, {});
3049 CPPUNIT_ASSERT_EQUAL(5, getParagraphs());
3051 // Save cursor position after paste occurs
3052 SwPosition
aCursorPosPaste(*pWrtShell
->GetCursor()->GetPoint());
3054 // Move cursor position to the end
3055 pWrtShell
->SttEndDoc(false); //bStart = false
3057 // Save cursor position at end
3058 SwPosition
aCursorPosEnd(*pWrtShell
->GetCursor()->GetPoint());
3060 // Assert the cursor position after paste is at the end
3061 // Without the test in place, the cursor position is at the beginning of the document
3062 // - Expected : SwPosition (node 18, offset 0)
3063 // - Actual : SwPosition (node 6, offset 0)
3064 CPPUNIT_ASSERT_EQUAL(aCursorPosEnd
, aCursorPosPaste
);
3067 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testCursorPositionAfterUndo
)
3069 createSwDoc("cursor_position_after_undo.odt");
3070 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
3072 // switch on "Outline Folding" mode
3073 dispatchCommand(mxComponent
, u
".uno:ShowOutlineContentVisibilityButton"_ustr
, {});
3074 CPPUNIT_ASSERT(pWrtShell
->GetViewOptions()->IsShowOutlineContentVisibilityButton());
3076 // move the cursor to the beginning of the 3rd word in the 3rd paragraph, "tincidunt"
3077 pWrtShell
->FwdPara();
3078 pWrtShell
->FwdPara();
3079 pWrtShell
->Right(SwCursorSkipMode::Chars
, /*bSelect=*/false, 16, /*bBasicCall=*/false);
3082 dispatchCommand(mxComponent
, u
".uno:SelectWord"_ustr
, {});
3084 // check the word is select
3085 SwShellCursor
* pShellCursor
= pWrtShell
->getShellCursor(false);
3086 CPPUNIT_ASSERT_EQUAL(u
"tincidunt"_ustr
, pShellCursor
->GetText());
3088 // remember the cursor position for comparison
3089 SwPosition
aCursorPos(*pWrtShell
->GetCursor()->GetPoint());
3091 // delete the selected word
3092 pWrtShell
->Delete();
3095 dispatchCommand(mxComponent
, u
".uno:Undo"_ustr
, {});
3097 // without the fix in place, the cursor would have been set to the start of the outline node
3098 // - Expected: SwPosition (node 11, offset 25)
3099 // - Actual : SwPosition (node 9, offset 0)
3100 CPPUNIT_ASSERT_EQUAL(aCursorPos
, *pWrtShell
->GetCursor()->GetPoint());
3102 // switch off "Outline Folding" mode
3103 dispatchCommand(mxComponent
, u
".uno:ShowOutlineContentVisibilityButton"_ustr
, {});
3104 CPPUNIT_ASSERT(!pWrtShell
->GetViewOptions()->IsShowOutlineContentVisibilityButton());
3107 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf73483
)
3109 // Given a document with a first paragraph having a manually set page break with page style
3110 createSwDoc("pageBreakWithPageStyle.fodt");
3111 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
3113 CPPUNIT_ASSERT_EQUAL(u
"Right Page"_ustr
, pWrtShell
->GetCurPageStyle());
3115 dispatchCommand(mxComponent
, u
".uno:ResetAttributes"_ustr
,
3116 {}); // Ctrl+M "Clear Direct Formatting"
3117 // Make sure that clearing direct formatting doesn't clear the page style
3118 CPPUNIT_ASSERT_EQUAL(u
"Right Page"_ustr
, pWrtShell
->GetCurPageStyle());
3120 // Make sure that the page break with page style survives ODF save-and-reload
3121 saveAndReload(u
"writer8"_ustr
);
3123 xmlDocUniquePtr pXml
= parseExport(u
"content.xml"_ustr
);
3124 CPPUNIT_ASSERT(pXml
);
3125 OUString para_style_name
3126 = getXPath(pXml
, "/office:document-content/office:body/office:text/text:p", "style-name");
3127 // Without the fix in place, this would fail
3128 CPPUNIT_ASSERT(!para_style_name
.equalsIgnoreAsciiCase("Standard"));
3130 OString para_style_path
3131 = "/office:document-content/office:automatic-styles/style:style[@style:name='"
3132 + para_style_name
.toUtf8() + "']";
3133 assertXPath(pXml
, para_style_path
, "family", u
"paragraph");
3134 // Without the fix in place, the autostyle had no parent
3135 assertXPath(pXml
, para_style_path
, "parent-style-name", u
"Standard");
3136 assertXPath(pXml
, para_style_path
, "master-page-name", u
"Right_20_Page");
3139 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf62032ApplyStyle
)
3141 createSwDoc("tdf62032_apply_style.odt");
3142 SwWrtShell
* pWrtSh
= getSwDocShell()->GetWrtShell();
3144 pWrtSh
->Down(/*bSelect=*/false);
3146 uno::Sequence
<beans::PropertyValue
> aPropertyValues
= comphelper::InitPropertySequence({
3147 { "Style", uno::Any(u
"A 2"_ustr
) },
3148 { "FamilyName", uno::Any(u
"ParagraphStyles"_ustr
) },
3150 dispatchCommand(mxComponent
, u
".uno:StyleApply"_ustr
, aPropertyValues
);
3152 // Without the fix in place, it fails with:
3155 CPPUNIT_ASSERT_EQUAL(u
"1.1"_ustr
,
3156 getProperty
<OUString
>(getParagraph(2), u
"ListLabelString"_ustr
).trim());
3159 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf156560
)
3161 createSwDoc("tdf156560.docx");
3163 uno::Reference
<beans::XPropertySet
> xPageStyle(
3164 getStyles(u
"PageStyles"_ustr
)->getByName(u
"Standard"_ustr
), uno::UNO_QUERY
);
3165 CPPUNIT_ASSERT_EQUAL(true, getProperty
<bool>(xPageStyle
, u
"HeaderIsOn"_ustr
));
3167 SwXTextDocument
* pTextDoc
= getSwTextDoc();
3168 pTextDoc
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_MOD1
| KEY_PAGEUP
);
3171 // Without the fix in place, this test would have got SIGABRT here
3172 dispatchCommand(mxComponent
, u
".uno:InsertHeader"_ustr
, {});
3175 CPPUNIT_TEST_FIXTURE(SwUiWriterTest8
, testTdf158459
)
3177 createSwDoc("tdf158459_tracked_changes_across_nodes.fodt");
3178 SwDoc
* pDoc
= getSwDoc();
3180 SwWrtShell
* pWrtShell
= getSwDocShell()->GetWrtShell();
3181 CPPUNIT_ASSERT(pWrtShell
);
3182 pWrtShell
->FwdPara(); // Skip first paragraph
3183 pWrtShell
->EndOfSection(true); // Select everything to the end
3186 pWrtShell
->Copy(aClipboard
); // This must not crash
3188 pWrtShell
->SelAll();
3189 pWrtShell
->Delete();
3190 pWrtShell
->Paste(aClipboard
); // Replace everything with the copied stuff
3192 SwNodes
& rNodes
= pDoc
->GetNodes();
3193 SwNodeIndex
aIdx(rNodes
.GetEndOfExtras());
3194 SwContentNode
* pContentNode
= SwNodes::GoNext(&aIdx
);
3195 CPPUNIT_ASSERT(pContentNode
);
3196 SwTextNode
* pTextNode
= pContentNode
->GetTextNode();
3197 CPPUNIT_ASSERT(pTextNode
);
3198 // Check that deleted parts (paragraph break, "c", "e") haven't been pasted
3199 CPPUNIT_ASSERT_EQUAL(u
"abdf"_ustr
, pTextNode
->GetText());
3202 } // end of anonymous namespace
3203 CPPUNIT_PLUGIN_IMPLEMENT();
3205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */