Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sd / qa / unit / uiimpress.cxx
blobc4cdc0a5e33826b78e33dfc294bd796012559aa0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "sdmodeltestbase.hxx"
12 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
14 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <com/sun/star/uno/Reference.hxx>
16 #include <com/sun/star/drawing/FillStyle.hpp>
17 #include <com/sun/star/drawing/XDrawView.hpp>
18 #include <com/sun/star/drawing/XDrawPage.hpp>
19 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
20 #include <com/sun/star/table/XMergeableCell.hpp>
21 #include <com/sun/star/text/WritingMode2.hpp>
22 #include <com/sun/star/view/XSelectionSupplier.hpp>
24 #include <comphelper/propertysequence.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <sfx2/request.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <svl/intitem.hxx>
29 #include <svl/srchitem.hxx>
30 #include <svx/svxids.hrc>
31 #include <svx/svdoashp.hxx>
32 #include <svx/svdotable.hxx>
33 #include <svx/xfillit0.hxx>
34 #include <svx/xflclit.hxx>
35 #include <svx/xflgrit.hxx>
36 #include <svx/xlndsit.hxx>
37 #include <SlideSorterViewShell.hxx>
38 #include <SlideSorter.hxx>
39 #include <controller/SlsClipboard.hxx>
40 #include <controller/SlideSorterController.hxx>
41 #include <controller/SlsPageSelector.hxx>
42 #include <svl/stritem.hxx>
43 #include <undo/undomanager.hxx>
44 #include <vcl/scheduler.hxx>
45 #include <docmodel/uno/UnoComplexColor.hxx>
46 #include <comphelper/propertyvalue.hxx>
47 #include <comphelper/sequenceashashmap.hxx>
48 #include <docmodel/uno/UnoTheme.hxx>
49 #include <docmodel/theme/Theme.hxx>
51 #include <drawdoc.hxx>
52 #include <DrawDocShell.hxx>
53 #include <ViewShell.hxx>
54 #include <app.hrc>
55 #include <sdpage.hxx>
56 #include <unomodel.hxx>
57 #include <osl/thread.hxx>
58 #include <slideshow.hxx>
60 using namespace ::com::sun::star;
62 /// Impress UI tests.
63 class SdUiImpressTest : public SdModelTestBase
65 public:
66 SdUiImpressTest()
67 : SdModelTestBase("/sd/qa/unit/data/")
71 void checkCurrentPageNumber(sal_uInt16 nNum);
72 void typeString(SdXImpressDocument* rImpressDocument, const std::u16string_view& rStr);
73 void typeKey(SdXImpressDocument* rImpressDocument, const sal_uInt16 nKey);
74 void insertStringToObject(sal_uInt16 nObj, const std::u16string_view& rStr, bool bUseEscape);
75 sd::slidesorter::SlideSorterViewShell* getSlideSorterViewShell();
76 void lcl_search(const OUString& rKey, bool bFindAll = false, bool bBackwards = false);
79 void SdUiImpressTest::checkCurrentPageNumber(sal_uInt16 nNum)
81 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
82 uno::Reference<drawing::XDrawView> xDrawView(xModel->getCurrentController(), uno::UNO_QUERY);
83 uno::Reference<drawing::XDrawPage> xPage(xDrawView->getCurrentPage(), uno::UNO_SET_THROW);
84 uno::Reference<beans::XPropertySet> xPropertySet(xPage, uno::UNO_QUERY);
86 sal_uInt16 nPageNumber;
87 xPropertySet->getPropertyValue("Number") >>= nPageNumber;
88 CPPUNIT_ASSERT_EQUAL(nNum, nPageNumber);
91 void SdUiImpressTest::typeKey(SdXImpressDocument* rImpressDocument, const sal_uInt16 nKey)
93 rImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, nKey);
94 rImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, nKey);
95 Scheduler::ProcessEventsToIdle();
98 void SdUiImpressTest::typeString(SdXImpressDocument* rImpressDocument,
99 const std::u16string_view& rStr)
101 for (const char16_t c : rStr)
103 rImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, c, 0);
104 rImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, c, 0);
105 Scheduler::ProcessEventsToIdle();
109 void SdUiImpressTest::insertStringToObject(sal_uInt16 nObj, const std::u16string_view& rStr,
110 bool bUseEscape)
112 auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
113 sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
114 SdPage* pPage = pViewShell->GetActualPage();
115 SdrObject* pShape = pPage->GetObj(nObj);
116 CPPUNIT_ASSERT_MESSAGE("No Shape", pShape);
117 SdrView* pView = pViewShell->GetView();
118 pView->MarkObj(pShape, pView->GetSdrPageView());
119 Scheduler::ProcessEventsToIdle();
121 CPPUNIT_ASSERT(!pView->IsTextEdit());
123 typeString(pImpressDocument, rStr);
125 CPPUNIT_ASSERT(pView->IsTextEdit());
127 if (bUseEscape)
129 typeKey(pImpressDocument, KEY_ESCAPE);
130 CPPUNIT_ASSERT(!pView->IsTextEdit());
134 sd::slidesorter::SlideSorterViewShell* SdUiImpressTest::getSlideSorterViewShell()
136 auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
137 sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
138 sd::slidesorter::SlideSorterViewShell* pSSVS = nullptr;
139 // Same as in sd/qa/unit/misc-tests.cxx
140 for (int i = 0; i < 1000; i++)
142 // Process all Tasks - slide sorter is created here
143 Scheduler::ProcessEventsToIdle();
144 if ((pSSVS = sd::slidesorter::SlideSorterViewShell::GetSlideSorter(
145 pViewShell->GetViewShellBase()))
146 != nullptr)
147 break;
148 osl::Thread::wait(std::chrono::milliseconds(100));
150 CPPUNIT_ASSERT(pSSVS);
151 return pSSVS;
154 void SdUiImpressTest::lcl_search(const OUString& rKey, bool bFindAll, bool bBackwards)
156 Scheduler::ProcessEventsToIdle();
157 SvxSearchCmd eSearch = bFindAll ? SvxSearchCmd::FIND_ALL : SvxSearchCmd::FIND;
159 uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence({
160 { "SearchItem.SearchString", uno::Any(rKey) },
161 { "SearchItem.Backward", uno::Any(bBackwards) },
162 { "SearchItem.Command", uno::Any(sal_uInt16(eSearch)) },
163 }));
165 dispatchCommand(mxComponent, ".uno:ExecuteSearch", aPropertyValues);
168 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf111522)
170 // Load the document and create two new windows.
171 createSdImpressDoc("tdf111522.odp");
172 auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
173 sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
174 pViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_NEWWINDOW, SfxCallMode::SYNCHRON);
175 sd::ViewShell* pViewShell1 = pImpressDocument->GetDocShell()->GetViewShell();
176 pViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_NEWWINDOW, SfxCallMode::SYNCHRON);
177 sd::ViewShell* pViewShell2 = pImpressDocument->GetDocShell()->GetViewShell();
178 CPPUNIT_ASSERT(pViewShell1 != pViewShell2);
180 // Have slide 1 in window 1, slide 2 in window 2.
181 SfxRequest aRequest(*pViewShell2->GetViewFrame(), SID_SWITCHPAGE);
182 aRequest.AppendItem(SfxUInt32Item(ID_VAL_WHATPAGE, 1));
183 aRequest.AppendItem(
184 SfxUInt32Item(ID_VAL_WHATKIND, static_cast<sal_uInt32>(PageKind::Standard)));
185 pViewShell2->ExecuteSlot(aRequest, /*bAsync=*/false);
187 // Start text edit in window 1.
188 SdPage* pPage1 = pViewShell1->GetActualPage();
189 SdrObject* pShape1 = pPage1->GetObj(0);
190 SdrView* pView1 = pViewShell1->GetView();
191 pView1->MarkObj(pShape1, pView1->GetSdrPageView());
192 pView1->SdrBeginTextEdit(pShape1);
193 CPPUNIT_ASSERT(pView1->IsTextEdit());
195 // Move the shape in window 2 & undo.
196 SdPage* pPage2 = pViewShell2->GetActualPage();
197 CPPUNIT_ASSERT(pPage1 != pPage2);
198 SdrObject* pShape2 = pPage2->GetObj(0);
199 SdrView* pView2 = pViewShell2->GetView();
200 pView2->MarkObj(pShape2, pView2->GetSdrPageView());
201 pView2->MoveMarkedObj(Size(1, 1), /*bCopy=*/false);
202 // Without the accompanying fix in place, this test would have failed with an assertion failure
203 // in SdrObjEditView::SdrEndTextEdit() as mpOldTextEditUndoManager was not nullptr.
204 pViewShell2->GetViewFrame()->GetDispatcher()->Execute(SID_UNDO, SfxCallMode::SYNCHRON);
206 // Rotate the shape in window 2 & undo.
207 pView2->MarkObj(pShape2, pView2->GetSdrPageView());
208 pView2->RotateMarkedObj(pShape2->GetLastBoundRect().Center(), /*nAngle=*/45_deg100);
209 // Without the accompanying fix in place, this test would have failed with an assertion failure
210 // in SdrObjEditView::SdrEndTextEdit() as mpOldTextEditUndoManager was not nullptr.
211 pViewShell2->GetViewFrame()->GetDispatcher()->Execute(SID_UNDO, SfxCallMode::SYNCHRON);
213 // Start text edit in window 2.
214 // tdf#125824
215 pView2->MarkObj(pShape2, pView2->GetSdrPageView());
216 pView2->SdrBeginTextEdit(pShape2);
217 CPPUNIT_ASSERT(pView2->IsTextEdit());
218 // Write 'test' inside the shape
219 SfxStringItem aInputString(SID_ATTR_CHAR, "test");
220 pViewShell2->GetViewFrame()->GetDispatcher()->ExecuteList(SID_ATTR_CHAR, SfxCallMode::SYNCHRON,
221 { &aInputString });
222 CPPUNIT_ASSERT(pView2->GetTextEditObject());
223 EditView& rEditView = pView2->GetTextEditOutlinerView()->GetEditView();
224 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), rEditView.GetSelection().nStartPos);
225 pView2->SdrEndTextEdit();
226 // Without the accompanying fix in place, this test would have failed with an assertion failure
227 // in SdrObjEditView::SdrEndTextEdit() as mpOldTextEditUndoManager was not nullptr.
228 pViewShell2->GetViewFrame()->GetDispatcher()->Execute(SID_UNDO, SfxCallMode::SYNCHRON);
231 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf126197)
233 // Load the document and create two new windows.
234 createSdImpressDoc("tdf126197.odp");
235 auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
236 sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
237 pViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_NEWWINDOW, SfxCallMode::SYNCHRON);
238 sd::ViewShell* pViewShell1 = pImpressDocument->GetDocShell()->GetViewShell();
239 pViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_NEWWINDOW, SfxCallMode::SYNCHRON);
240 sd::ViewShell* pViewShell2 = pImpressDocument->GetDocShell()->GetViewShell();
241 CPPUNIT_ASSERT(pViewShell1 != pViewShell2);
243 // Start text edit in window 1.
244 SdPage* pPage1 = pViewShell1->GetActualPage();
245 SdrObject* pShape1 = pPage1->GetObj(0);
246 SdrView* pView1 = pViewShell1->GetView();
247 pView1->MarkObj(pShape1, pView1->GetSdrPageView());
248 pView1->SdrBeginTextEdit(pShape1);
249 CPPUNIT_ASSERT(pView1->IsTextEdit());
251 SdPage* pPage2 = pViewShell2->GetActualPage();
252 CPPUNIT_ASSERT_EQUAL(pPage1, pPage2);
253 SdrObject* pShape2 = pPage2->GetObj(0);
254 CPPUNIT_ASSERT_EQUAL(pShape1, pShape2);
255 SdrView* pView2 = pViewShell2->GetView();
256 pView2->MarkObj(pShape2, pView2->GetSdrPageView());
258 // Without the accompanying fix in place, this test would have failed with an assertion failure
259 // in SdrObjEditView::SdrEndTextEdit()
260 pViewShell2->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SfxCallMode::SYNCHRON);
263 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf124708)
265 createSdImpressDoc("tdf124708.ppt");
267 dispatchCommand(mxComponent, ".uno:NextPage", {});
269 checkCurrentPageNumber(2);
271 auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
272 sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
273 SdPage* pActualPage = pViewShell->GetActualPage();
274 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(16), pActualPage->GetObjCount());
276 dispatchCommand(mxComponent, ".uno:SelectAll", {});
278 // Without the fix in place, this test would have crashed here
279 dispatchCommand(mxComponent, ".uno:Delete", {});
281 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pActualPage->GetObjCount());
283 dispatchCommand(mxComponent, ".uno:Undo", {});
285 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(16), pActualPage->GetObjCount());
288 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf143412)
290 createSdImpressDoc();
292 auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
293 sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
295 SdPage* pActualPage = pViewShell->GetActualPage();
296 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), pActualPage->GetObjCount());
298 OUString aImageURL = createFileURL(u"tdf143412.svg");
299 uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence({
300 { "FileName", uno::Any(aImageURL) },
301 }));
302 dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs);
304 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), pActualPage->GetObjCount());
306 // Without the fix in place, this test would have crashed
307 // Check that converting an image to the different options doesn't crash
309 dispatchCommand(mxComponent, ".uno:ChangeBezier", {});
311 dispatchCommand(mxComponent, ".uno:ChangePolygon", {});
313 dispatchCommand(mxComponent, ".uno:convert_to_contour", {});
315 dispatchCommand(mxComponent, ".uno:ConvertInto3D", {});
317 dispatchCommand(mxComponent, ".uno:ConvertInto3DLatheFast", {});
319 dispatchCommand(mxComponent, ".uno:ConvertIntoBitmap", {});
321 dispatchCommand(mxComponent, ".uno:ConvertIntoMetaFile", {});
323 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), pActualPage->GetObjCount());
326 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf96206)
328 // Copying/pasting slide referring to a non-default master with a text duplicated the master
330 createSdImpressDoc("odp/tdf96206.odp");
332 sd::slidesorter::SlideSorterViewShell* pSSVS = getSlideSorterViewShell();
333 auto& rSSController = pSSVS->GetSlideSorter().GetController();
335 SdXImpressDocument* pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
336 SdDrawDocument* pDoc = pXImpressDocument->GetDoc();
337 const sal_uInt16 nMasterPageCnt1 = pDoc->GetMasterSdPageCount(PageKind::Standard);
338 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), nMasterPageCnt1);
339 rSSController.GetClipboard().DoCopy();
340 rSSController.GetClipboard().DoPaste();
341 const sal_uInt16 nMasterPageCnt2 = pDoc->GetMasterSdPageCount(PageKind::Standard);
342 CPPUNIT_ASSERT_EQUAL(nMasterPageCnt1, nMasterPageCnt2);
345 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf96708)
347 createSdImpressDoc("odp/tdf96708.odp");
349 sd::slidesorter::SlideSorterViewShell* pSSVS = getSlideSorterViewShell();
350 auto& rSSController = pSSVS->GetSlideSorter().GetController();
351 auto& rPageSelector = rSSController.GetPageSelector();
353 SdXImpressDocument* pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
354 SdDrawDocument* pDoc = pXImpressDocument->GetDoc();
355 const sal_uInt16 nMasterPageCnt1 = pDoc->GetMasterSdPageCount(PageKind::Standard);
356 CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), nMasterPageCnt1);
357 rSSController.GetClipboard().DoCopy();
358 rPageSelector.SelectAllPages();
360 // Now wait for timers to trigger creation of auto-layout
361 osl::Thread::wait(std::chrono::milliseconds(100));
362 Scheduler::ProcessEventsToIdle();
364 rSSController.GetClipboard().DoPaste();
366 const sal_uInt16 nMasterPageCnt2 = pDoc->GetMasterSdPageCount(PageKind::Standard);
367 //FIXME: tdf#151802: Number of master pages should be 4, it's 5 instead
368 //CPPUNIT_ASSERT_EQUAL(nMasterPageCnt1, nMasterPageCnt2);
369 CPPUNIT_ASSERT_EQUAL(sal_uInt16(5), nMasterPageCnt2);
372 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf139996)
374 createSdImpressDoc();
376 sd::slidesorter::SlideSorterViewShell* pSSVS = getSlideSorterViewShell();
377 auto& rSSController = pSSVS->GetSlideSorter().GetController();
378 auto& rPageSelector = rSSController.GetPageSelector();
380 CPPUNIT_ASSERT_EQUAL(1, rPageSelector.GetSelectedPageCount());
382 rPageSelector.DeselectAllPages();
384 CPPUNIT_ASSERT_EQUAL(0, rPageSelector.GetSelectedPageCount());
386 // Without the fix in place, this test would have crashed here
387 dispatchCommand(mxComponent, ".uno:MovePageUp", {});
389 dispatchCommand(mxComponent, ".uno:MovePageDown", {});
391 dispatchCommand(mxComponent, ".uno:MovePageTop", {});
393 dispatchCommand(mxComponent, ".uno:MovePageBottom", {});
395 CPPUNIT_ASSERT_EQUAL(0, rPageSelector.GetSelectedPageCount());
398 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf128651)
400 // Error was, that undo and redo changes size of the shape. Affected actions were e.g.
401 // extrusion on/off, shadow on/off, changes on line or fill attributes.
402 // All these actions do not change the snap rectangle.
403 createSdImpressDoc("tdf128651_CustomShapeUndo.odp");
404 auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
405 sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
406 SdPage* pActualPage = pViewShell->GetActualPage();
407 SdrObject* pObject = pActualPage->GetObj(0);
408 auto pCustomShape = dynamic_cast<SdrObjCustomShape*>(pObject);
409 CPPUNIT_ASSERT_MESSAGE("No Shape", pCustomShape);
410 const sal_Int32 nOrigWidth(pCustomShape->GetSnapRect().GetWidth());
412 SdDrawDocument* pDocument = pXImpressDocument->GetDoc();
413 sd::UndoManager* pUndoManager = pDocument->GetUndoManager();
414 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pUndoManager->GetUndoActionCount());
415 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pUndoManager->GetRedoActionCount());
417 SdrView* pView = pViewShell->GetView();
418 pView->MarkObj(pCustomShape, pView->GetSdrPageView());
419 pViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_EXTRUSION_TOGGLE,
420 SfxCallMode::SYNCHRON);
421 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pUndoManager->GetUndoActionCount());
423 pViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_UNDO, SfxCallMode::SYNCHRON);
424 const sal_Int32 nUndoWidth(pCustomShape->GetSnapRect().GetWidth());
425 CPPUNIT_ASSERT_EQUAL_MESSAGE("Undo changes width", nOrigWidth, nUndoWidth);
427 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pUndoManager->GetRedoActionCount());
428 pViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_REDO, SfxCallMode::SYNCHRON);
429 const sal_Int32 nRedoWidth(pCustomShape->GetSnapRect().GetWidth());
430 CPPUNIT_ASSERT_EQUAL_MESSAGE("Redo changes width", nUndoWidth, nRedoWidth);
433 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf126605)
435 createSdImpressDoc();
437 dispatchCommand(mxComponent, ".uno:InsertPage", {});
439 insertStringToObject(0, u"Test", /*bUseEscape*/ false);
441 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
442 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(1),
443 uno::UNO_QUERY);
445 uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
447 uno::Reference<text::XText> xText
448 = uno::Reference<text::XTextRange>(xShape, uno::UNO_QUERY_THROW)->getText();
449 CPPUNIT_ASSERT_MESSAGE("Not a text shape", xText.is());
451 uno::Reference<container::XEnumerationAccess> paraEnumAccess(xText, uno::UNO_QUERY);
452 uno::Reference<container::XEnumeration> paraEnum(paraEnumAccess->createEnumeration());
454 // Get first paragraph
455 uno::Reference<text::XTextRange> xParagraph(paraEnum->nextElement(), uno::UNO_QUERY_THROW);
456 uno::Reference<beans::XPropertySet> xPropSet(xParagraph, uno::UNO_QUERY_THROW);
458 sal_Int16 nWritingMode = 0;
459 xPropSet->getPropertyValue("WritingMode") >>= nWritingMode;
460 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::LR_TB, nWritingMode);
462 // Without the fix in place, this test would have crashed here
463 dispatchCommand(mxComponent, ".uno:ParaRightToLeft", {});
465 xPropSet->getPropertyValue("WritingMode") >>= nWritingMode;
466 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::RL_TB, nWritingMode);
468 dispatchCommand(mxComponent, ".uno:ParaLeftToRight", {});
470 xPropSet->getPropertyValue("WritingMode") >>= nWritingMode;
471 CPPUNIT_ASSERT_EQUAL(text::WritingMode2::LR_TB, nWritingMode);
474 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf100950)
476 createSdImpressDoc();
478 dispatchCommand(mxComponent, ".uno:InsertPage", {});
480 dispatchCommand(mxComponent, ".uno:InsertPage", {});
482 insertStringToObject(0, u"Test", /*bUseEscape*/ true);
484 dispatchCommand(mxComponent, ".uno:Undo", {});
486 sd::slidesorter::SlideSorterViewShell* pSSVS = getSlideSorterViewShell();
487 auto& rSSController = pSSVS->GetSlideSorter().GetController();
488 auto& rPageSelector = rSSController.GetPageSelector();
490 // Without the fix in place, this test would have failed here
491 CPPUNIT_ASSERT(rPageSelector.IsPageSelected(2));
494 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf129346)
496 createSdImpressDoc();
498 dispatchCommand(mxComponent, ".uno:DiaMode", {});
499 checkCurrentPageNumber(1);
501 dispatchCommand(mxComponent, ".uno:InsertPage", {});
502 checkCurrentPageNumber(2);
504 dispatchCommand(mxComponent, ".uno:Undo", {});
505 checkCurrentPageNumber(1);
508 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testmoveSlides)
510 createSdImpressDoc();
512 auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
513 sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
515 uno::Sequence<beans::PropertyValue> aArgs(
516 comphelper::InitPropertySequence({ { "PageName", uno::Any(OUString("Test 1")) },
517 { "WhatLayout", uno::Any(sal_Int32(1)) },
518 { "IsPageBack", uno::Any(false) },
519 { "IsPageObj", uno::Any(false) } }));
521 dispatchCommand(mxComponent, ".uno:InsertPage", aArgs);
522 checkCurrentPageNumber(2);
524 CPPUNIT_ASSERT_EQUAL(OUString("Test 1"), pViewShell->GetActualPage()->GetName());
526 aArgs = comphelper::InitPropertySequence({ { "PageName", uno::Any(OUString("Test 2")) },
527 { "WhatLayout", uno::Any(sal_Int32(1)) },
528 { "IsPageBack", uno::Any(false) },
529 { "IsPageObj", uno::Any(false) } });
531 dispatchCommand(mxComponent, ".uno:InsertPage", aArgs);
532 checkCurrentPageNumber(3);
534 CPPUNIT_ASSERT_EQUAL(OUString("Test 2"), pViewShell->GetActualPage()->GetName());
536 // Move slide 'Test 2' up
537 for (size_t i = 2; i > 0; --i)
539 dispatchCommand(mxComponent, ".uno:MovePageUp", {});
540 checkCurrentPageNumber(i);
541 CPPUNIT_ASSERT_EQUAL(OUString("Test 2"), pViewShell->GetActualPage()->GetName());
544 // Move slide 'Test 2' down
545 for (size_t i = 2; i < 4; ++i)
547 dispatchCommand(mxComponent, ".uno:MovePageDown", {});
548 checkCurrentPageNumber(i);
549 CPPUNIT_ASSERT_EQUAL(OUString("Test 2"), pViewShell->GetActualPage()->GetName());
552 // Move slide 'Test 2' to the top
553 dispatchCommand(mxComponent, ".uno:MovePageFirst", {});
554 checkCurrentPageNumber(1);
555 CPPUNIT_ASSERT_EQUAL(OUString("Test 2"), pViewShell->GetActualPage()->GetName());
557 // Move slide 'Test 2' to the bottom
558 dispatchCommand(mxComponent, ".uno:MovePageLast", {});
559 checkCurrentPageNumber(3);
560 CPPUNIT_ASSERT_EQUAL(OUString("Test 2"), pViewShell->GetActualPage()->GetName());
563 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf148620)
565 createSdImpressDoc();
567 auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
569 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
570 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
571 uno::UNO_QUERY);
572 uno::Reference<text::XTextRange> xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY);
573 CPPUNIT_ASSERT_EQUAL(OUString(u""), xShape->getString());
575 insertStringToObject(1, u"one", /*bUseEscape*/ false);
576 typeKey(pXImpressDocument, KEY_RETURN);
577 typeString(pXImpressDocument, u"two");
578 typeKey(pXImpressDocument, KEY_RETURN);
579 typeString(pXImpressDocument, u"three");
580 typeKey(pXImpressDocument, KEY_RETURN);
581 typeString(pXImpressDocument, u"four");
582 typeKey(pXImpressDocument, KEY_RETURN);
583 typeString(pXImpressDocument, u"five");
584 typeKey(pXImpressDocument, KEY_RETURN);
585 typeString(pXImpressDocument, u"six");
587 CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nThree\nFour\nFive\nsix"), xShape->getString());
589 uno::Sequence<beans::PropertyValue> aArgs(
590 comphelper::InitPropertySequence({ { "KeyModifier", uno::Any(sal_Int32(0)) } }));
591 dispatchCommand(mxComponent, ".uno:OutlineUp", aArgs);
593 CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nThree\nFour\nsix\nFive"), xShape->getString());
595 dispatchCommand(mxComponent, ".uno:OutlineUp", aArgs);
597 CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nThree\nsix\nFour\nFive"), xShape->getString());
599 dispatchCommand(mxComponent, ".uno:OutlineUp", aArgs);
601 CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nsix\nThree\nFour\nFive"), xShape->getString());
603 dispatchCommand(mxComponent, ".uno:OutlineUp", aArgs);
605 CPPUNIT_ASSERT_EQUAL(OUString(u"One\nsix\nTwo\nThree\nFour\nFive"), xShape->getString());
607 dispatchCommand(mxComponent, ".uno:OutlineUp", aArgs);
609 CPPUNIT_ASSERT_EQUAL(OUString(u"six\nOne\nTwo\nThree\nFour\nFive"), xShape->getString());
611 dispatchCommand(mxComponent, ".uno:OutlineDown", aArgs);
613 CPPUNIT_ASSERT_EQUAL(OUString(u"One\nsix\nTwo\nThree\nFour\nFive"), xShape->getString());
615 dispatchCommand(mxComponent, ".uno:OutlineDown", aArgs);
617 CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nsix\nThree\nFour\nFive"), xShape->getString());
619 dispatchCommand(mxComponent, ".uno:OutlineDown", aArgs);
621 CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nThree\nsix\nFour\nFive"), xShape->getString());
623 dispatchCommand(mxComponent, ".uno:OutlineDown", aArgs);
625 CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nThree\nFour\nsix\nFive"), xShape->getString());
627 dispatchCommand(mxComponent, ".uno:OutlineDown", aArgs);
629 CPPUNIT_ASSERT_EQUAL(OUString(u"One\nTwo\nThree\nFour\nFive\nsix"), xShape->getString());
632 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf141703)
634 createSdImpressDoc();
636 auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
638 uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
639 { { "Rows", uno::Any(sal_Int32(2)) }, { "Columns", uno::Any(sal_Int32(2)) } }));
641 dispatchCommand(mxComponent, ".uno:InsertTable", aArgs);
643 // Move to A1 using Alt + Tab and write 'A'
644 for (int i = 0; i < 3; i++)
646 pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_SHIFT | KEY_TAB);
647 pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_SHIFT | KEY_TAB);
648 Scheduler::ProcessEventsToIdle();
651 typeString(pXImpressDocument, u"A");
653 // Move to A2 with Tab and write 'B'
654 typeKey(pXImpressDocument, KEY_TAB);
656 typeString(pXImpressDocument, u"B");
658 typeKey(pXImpressDocument, KEY_ESCAPE);
660 sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
661 SdPage* pActualPage = pViewShell->GetActualPage();
662 auto pTableObject = dynamic_cast<sdr::table::SdrTableObj*>(pActualPage->GetObj(2));
663 CPPUNIT_ASSERT(pTableObject);
665 uno::Reference<css::table::XTable> xTable(pTableObject->getTable(), uno::UNO_SET_THROW);
666 uno::Reference<css::table::XMergeableCell> xCellA1(xTable->getCellByPosition(0, 0),
667 uno::UNO_QUERY_THROW);
668 uno::Reference<css::table::XMergeableCell> xCellA2(xTable->getCellByPosition(1, 0),
669 uno::UNO_QUERY_THROW);
671 uno::Reference<text::XText> xTextA1
672 = uno::Reference<text::XTextRange>(xCellA1, uno::UNO_QUERY_THROW)->getText();
674 // Without the fix in place, this test would have failed with
675 // - Expected: A
676 // - Actual :
677 CPPUNIT_ASSERT_EQUAL(OUString("A"), xTextA1->getString());
679 uno::Reference<text::XText> xTextA2
680 = uno::Reference<text::XTextRange>(xCellA2, uno::UNO_QUERY_THROW)->getText();
681 CPPUNIT_ASSERT_EQUAL(OUString("B"), xTextA2->getString());
684 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf127481)
686 createSdImpressDoc();
688 auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
689 sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
690 SdPage* pActualPage = pViewShell->GetActualPage();
691 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), pActualPage->GetObjCount());
693 uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
694 { { "Rows", uno::Any(sal_Int32(1)) }, { "Columns", uno::Any(sal_Int32(1)) } }));
696 dispatchCommand(mxComponent, ".uno:InsertTable", aArgs);
698 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), pActualPage->GetObjCount());
700 dispatchCommand(mxComponent, ".uno:DuplicatePage", aArgs);
702 checkCurrentPageNumber(2);
704 pActualPage = pViewShell->GetActualPage();
705 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), pActualPage->GetObjCount());
707 auto pTableObject = dynamic_cast<sdr::table::SdrTableObj*>(pActualPage->GetObj(2));
708 CPPUNIT_ASSERT(pTableObject);
710 //without the fix, it would crash here
711 pViewShell->GetView()->SdrBeginTextEdit(pTableObject);
713 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), pActualPage->GetObjCount());
716 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testPageFillColor)
718 // Load the document and create two new windows.
719 createSdImpressDoc("tdf126197.odp");
720 auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
721 sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
723 // Set FillPageColor
725 uno::Sequence<beans::PropertyValue> aPropertyValues = {
726 comphelper::makePropertyValue("FillColor", static_cast<sal_Int32>(0xff0000)),
728 dispatchCommand(mxComponent, ".uno:FillPageColor", aPropertyValues);
730 SdPage* pPage = pViewShell->getCurrentPage();
731 const SfxItemSet& rPageAttr = pPage->getSdrPageProperties().GetItemSet();
733 const XFillStyleItem* pFillStyle = rPageAttr.GetItem(XATTR_FILLSTYLE);
734 drawing::FillStyle eXFS = pFillStyle->GetValue();
735 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID, eXFS);
737 Color aColor = rPageAttr.GetItem(XATTR_FILLCOLOR)->GetColorValue();
738 CPPUNIT_ASSERT_EQUAL(Color(0xff0000), aColor);
741 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testPageFillGradient)
743 // Load the document and create two new windows.
744 createSdImpressDoc("tdf126197.odp");
745 auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
746 sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
748 // Set FillPageColor
750 uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence({
751 { "FillPageGradientJSON",
752 uno::Any(
753 OUString("{\"style\":\"LINEAR\",\"startcolor\":\"ff0000\",\"endcolor\":\"0000ff\","
754 "\"angle\":\"300\",\"border\":\"0\",\"x\":\"0\",\"y\":\"0\",\"intensstart\":"
755 "\"100\",\"intensend\":\"100\",\"stepcount\":\"0\"}")) },
756 }));
758 dispatchCommand(mxComponent, ".uno:FillPageGradient", aPropertyValues);
760 SdPage* pPage = pViewShell->getCurrentPage();
761 const SfxItemSet& rPageAttr = pPage->getSdrPageProperties().GetItemSet();
763 const XFillStyleItem* pFillStyle = rPageAttr.GetItem(XATTR_FILLSTYLE);
764 drawing::FillStyle eXFS = pFillStyle->GetValue();
765 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, eXFS);
767 basegfx::BGradient aGradient(rPageAttr.GetItem(XATTR_FILLGRADIENT)->GetGradientValue());
768 const basegfx::BColorStops& rColorStops(aGradient.GetColorStops());
770 CPPUNIT_ASSERT_EQUAL(size_t(2), rColorStops.size());
771 CPPUNIT_ASSERT(basegfx::fTools::equal(rColorStops[0].getStopOffset(), 0.0));
772 CPPUNIT_ASSERT_EQUAL(rColorStops[0].getStopColor(), basegfx::BColor(1.0, 0.0, 0.0));
773 CPPUNIT_ASSERT(basegfx::fTools::equal(rColorStops[1].getStopOffset(), 1.0));
774 CPPUNIT_ASSERT_EQUAL(rColorStops[1].getStopColor(), basegfx::BColor(0.0, 0.0, 1.0));
777 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf134053)
779 // Error was, that dashes and dots were longer than in MS Office.
780 createSdImpressDoc("pptx/tdf134053_dashdot.pptx");
781 auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
782 sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
783 SdPage* pActualPage = pViewShell->GetActualPage();
784 SdrObject* pShape = pActualPage->GetObj(0);
785 CPPUNIT_ASSERT_MESSAGE("No Shape", pShape);
787 SdDrawDocument* pDocument = pXImpressDocument->GetDoc();
788 sd::UndoManager* pUndoManager = pDocument->GetUndoManager();
790 // tdf#114613: Without the fix in place, this test would have failed with
791 // - Expected: 0
792 // - Actual : 8
793 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pUndoManager->GetUndoActionCount());
794 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pUndoManager->GetRedoActionCount());
796 XDash dash = pShape->GetMergedItem(XATTR_LINEDASH).GetDashValue();
798 // Because 0% is not possible as dash length (as of June 2020) 1% is used in the fix.
799 CPPUNIT_ASSERT_EQUAL_MESSAGE("Distance", 399.0, dash.GetDistance());
800 CPPUNIT_ASSERT_EQUAL_MESSAGE("Dot length", 301.0, dash.GetDotLen());
801 CPPUNIT_ASSERT_EQUAL_MESSAGE("Dash length", 1.0, dash.GetDashLen());
804 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testSpellOnlineParameter)
806 createSdImpressDoc();
807 auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
808 bool bSet = pImpressDocument->GetDoc()->GetOnlineSpell();
810 uno::Sequence<beans::PropertyValue> params(
811 comphelper::InitPropertySequence({ { "Enable", uno::Any(!bSet) } }));
812 dispatchCommand(mxComponent, ".uno:SpellOnline", params);
813 CPPUNIT_ASSERT_EQUAL(!bSet, pImpressDocument->GetDoc()->GetOnlineSpell());
815 // set the same state as now and we don't expect any change (no-toggle)
816 params = comphelper::InitPropertySequence({ { "Enable", uno::Any(!bSet) } });
817 dispatchCommand(mxComponent, ".uno:SpellOnline", params);
818 CPPUNIT_ASSERT_EQUAL(!bSet, pImpressDocument->GetDoc()->GetOnlineSpell());
821 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf38669)
823 createSdImpressDoc();
824 auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
825 CPPUNIT_ASSERT(pImpressDocument);
827 // Insert shape with ctrl key
828 uno::Sequence<beans::PropertyValue> aArgs(
829 comphelper::InitPropertySequence({ { "KeyModifier", uno::Any(KEY_MOD1) } }));
830 dispatchCommand(mxComponent, ".uno:BasicShapes.rectangle", aArgs);
832 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
833 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
834 uno::UNO_QUERY);
835 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xDrawPage->getCount());
837 typeString(pImpressDocument, u"°");
839 uno::Reference<text::XTextRange> xShape(xDrawPage->getByIndex(2), uno::UNO_QUERY);
840 // Without the fix in place, this test would have failed with:
841 // - Expected: °
842 // - Actual : ㅀ
843 CPPUNIT_ASSERT_EQUAL(OUString(u"°"), xShape->getString());
846 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf151417)
848 createSdImpressDoc();
849 auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
850 CPPUNIT_ASSERT(pImpressDocument);
852 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
853 uno::Reference<container::XIndexAccess> xDraws = xDrawPagesSupplier->getDrawPages();
854 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDraws->getCount());
856 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
857 uno::UNO_QUERY);
858 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xDrawPage->getCount());
860 uno::Sequence<beans::PropertyValue> aArgs(
861 comphelper::InitPropertySequence({ { "KeyModifier", uno::Any(KEY_MOD1) } }));
863 // Without the fix in place, this test would have crashed here
864 dispatchCommand(mxComponent, ".uno:Edit", aArgs);
866 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xDrawPage->getCount());
869 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf123841)
871 // To check if selecting unfilled rectangle produces unfilled rectangle
872 createSdImpressDoc();
873 auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
874 CPPUNIT_ASSERT(pImpressDocument);
876 uno::Sequence<beans::PropertyValue> aArgs(
877 comphelper::InitPropertySequence({ { "KeyModifier", uno::Any(KEY_MOD1) } }));
878 dispatchCommand(mxComponent, ".uno:Rect_Unfilled", aArgs);
880 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
881 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
882 uno::UNO_QUERY);
884 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xDrawPage->getCount());
886 for (int i = 0; i < 3; i++)
888 uno::Reference<beans::XPropertySet> XPropSet(xDrawPage->getByIndex(i), uno::UNO_QUERY);
889 drawing::FillStyle eFillStyle = drawing::FillStyle_NONE;
890 XPropSet->getPropertyValue("FillStyle") >>= eFillStyle;
892 // Without the fix in place, this test would have failed with
893 // with drawing::FillStyle_NONE != drawing::FillStyle_SOLID
894 CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_NONE, eFillStyle);
898 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testSearchAllInDocumentAndNotes)
900 // tdf#142478
901 // "find all" produces a crash when the search string exists in notes
902 // and the document
904 createSdImpressDoc("odp/search-all-notes.odp");
906 auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
907 sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
908 CPPUNIT_ASSERT(pViewShell);
910 lcl_search("Crash", /*bFindAll=*/true, /*bBackwards=*/true);
913 #if !defined(_WIN32) && !defined(MACOSX)
914 // for some reason, the search for "second" (or "Second") didn't return page 2 in WIN and MACOS
915 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf123658_SearchAfterSlideChange)
917 createSdImpressDoc("odp/tdf123658_SearchAfterSlideChange.odp");
919 auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
921 lcl_search("second");
922 checkCurrentPageNumber(2);
924 pXImpressDocument->setPart(0); // Switch to 1st page
926 lcl_search("of");
927 // Instead of finding this on the 1st page (or on the 2nd page would be acceptable too)
928 // it was going to the third page.
929 checkCurrentPageNumber(1);
931 #endif
933 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf142589)
935 createSdImpressDoc();
937 auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
938 sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
940 SfxRequest aRequest(*pViewShell->GetViewFrame(), SID_PRESENTATION);
941 pImpressDocument->GetDoc()->getPresentationSettings().mbCustomShow = true;
942 pImpressDocument->GetDoc()->getPresentationSettings().mbStartCustomShow = true;
943 sd::slideshowhelp::ShowSlideShow(aRequest, *pImpressDocument->GetDoc());
944 CPPUNIT_ASSERT_EQUAL(false, pImpressDocument->GetDoc()->getPresentationSettings().mbCustomShow);
947 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testCharColorTheme)
949 // Given an Impress document with a shape, with its text selected:
950 createSdImpressDoc();
951 uno::Reference<drawing::XDrawPagesSupplier> xPagesSupplier(mxComponent, uno::UNO_QUERY);
952 uno::Reference<drawing::XDrawPage> xPage(xPagesSupplier->getDrawPages()->getByIndex(0),
953 uno::UNO_QUERY);
954 uno::Reference<text::XTextRange> xShape(xPage->getByIndex(0), uno::UNO_QUERY);
956 uno::Reference<text::XSimpleText> xText = xShape->getText();
957 xText->insertString(xText->getStart(), u"test", false);
959 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
960 uno::Reference<view::XSelectionSupplier> xController(xModel->getCurrentController(),
961 uno::UNO_QUERY);
962 xController->select(uno::Any(xShape));
963 Scheduler::ProcessEventsToIdle();
964 dispatchCommand(mxComponent, ".uno:Text", {});
965 auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
966 sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
967 SdrView* pView = pViewShell->GetView();
968 CPPUNIT_ASSERT(pView->IsTextEdit());
969 dispatchCommand(mxComponent, ".uno:SelectAll", {});
971 // When picking a theme color on the sidebar:
972 uno::Sequence<beans::PropertyValue> aColorArgs = {
973 comphelper::makePropertyValue("Color", static_cast<sal_Int32>(0xdae3f3)), // 80% light blue
974 comphelper::makePropertyValue("ColorThemeIndex", static_cast<sal_Int16>(4)), // accent 1
975 comphelper::makePropertyValue("ColorLumMod", static_cast<sal_Int16>(2000)),
976 comphelper::makePropertyValue("ColorLumOff", static_cast<sal_Int16>(8000)),
978 dispatchCommand(mxComponent, ".uno:Color", aColorArgs);
980 // Then make sure the theme "metadata" is set in the document model:
981 pView->EndTextEditCurrentView();
982 CPPUNIT_ASSERT(!pView->IsTextEdit());
983 uno::Reference<container::XEnumerationAccess> xShapeParaAccess(xShape, uno::UNO_QUERY);
984 uno::Reference<container::XEnumerationAccess> xPara(
985 xShapeParaAccess->createEnumeration()->nextElement(), uno::UNO_QUERY);
986 uno::Reference<beans::XPropertySet> xPortion(xPara->createEnumeration()->nextElement(),
987 uno::UNO_QUERY);
989 uno::Reference<util::XComplexColor> xComplexColor;
990 CPPUNIT_ASSERT(xPortion->getPropertyValue("CharComplexColor") >>= xComplexColor);
991 CPPUNIT_ASSERT(xComplexColor.is());
992 auto aComplexColor = model::color::getFromXComplexColor(xComplexColor);
993 CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1, aComplexColor.getSchemeType());
994 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod,
995 aComplexColor.getTransformations()[0].meType);
996 CPPUNIT_ASSERT_EQUAL(sal_Int16(2000), aComplexColor.getTransformations()[0].mnValue);
997 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff,
998 aComplexColor.getTransformations()[1].meType);
999 CPPUNIT_ASSERT_EQUAL(sal_Int16(8000), aComplexColor.getTransformations()[1].mnValue);
1003 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testFillColorTheme)
1005 // Given an Impress document with a selected shape:
1006 createSdImpressDoc();
1007 uno::Reference<drawing::XDrawPagesSupplier> xPagesSupplier(mxComponent, uno::UNO_QUERY);
1008 uno::Reference<drawing::XDrawPage> xPage(xPagesSupplier->getDrawPages()->getByIndex(0),
1009 uno::UNO_QUERY);
1010 uno::Reference<beans::XPropertySet> xShape(xPage->getByIndex(0), uno::UNO_QUERY);
1011 uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
1012 uno::Reference<view::XSelectionSupplier> xController(xModel->getCurrentController(),
1013 uno::UNO_QUERY);
1014 xController->select(uno::Any(xShape));
1016 // When setting the fill color of that shape, with theme metadata & effects:
1017 uno::Sequence<beans::PropertyValue> aColorArgs = {
1018 comphelper::makePropertyValue("FillColor", static_cast<sal_Int32>(0xed7d31)), // orange
1019 comphelper::makePropertyValue("ColorThemeIndex", static_cast<sal_Int16>(4)), // accent 1
1020 comphelper::makePropertyValue("ColorLumMod", static_cast<sal_Int16>(4000)),
1021 comphelper::makePropertyValue("ColorLumOff", static_cast<sal_Int16>(6000)),
1023 dispatchCommand(mxComponent, ".uno:FillColor", aColorArgs);
1025 // Then make sure the theme index is not lost when the sidebar sets it:
1027 uno::Reference<util::XComplexColor> xComplexColor;
1028 CPPUNIT_ASSERT(xShape->getPropertyValue("FillComplexColor") >>= xComplexColor);
1029 CPPUNIT_ASSERT(xComplexColor.is());
1030 auto aComplexColor = model::color::getFromXComplexColor(xComplexColor);
1031 CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1, aComplexColor.getSchemeType());
1032 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumMod,
1033 aComplexColor.getTransformations()[0].meType);
1034 CPPUNIT_ASSERT_EQUAL(sal_Int16(4000), aComplexColor.getTransformations()[0].mnValue);
1035 CPPUNIT_ASSERT_EQUAL(model::TransformationType::LumOff,
1036 aComplexColor.getTransformations()[1].meType);
1037 CPPUNIT_ASSERT_EQUAL(sal_Int16(6000), aComplexColor.getTransformations()[1].mnValue);
1041 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testFillColorNoColor)
1043 // Given an empty Impress document:
1044 createSdImpressDoc();
1045 auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
1046 sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();
1047 SfxDispatcher* pDispatcher = pViewShell->GetViewFrame()->GetDispatcher();
1049 // When dispatching a fill color that only has a fill style (no color), then make sure we don't
1050 // crash:
1051 XFillStyleItem aXFillStyleItem(drawing::FillStyle_NONE);
1052 pDispatcher->ExecuteList(SID_ATTR_FILL_COLOR, SfxCallMode::RECORD, { &aXFillStyleItem });
1055 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf153161)
1057 createSdImpressDoc("odp/tdf153161_FlushToSave.odp");
1059 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
1060 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
1061 uno::UNO_QUERY);
1062 uno::Reference<text::XTextRange> xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY);
1063 OUString sOldText(xShape->getString());
1064 CPPUNIT_ASSERT(sOldText.startsWith(u"在没有版本控制系统的时期"));
1066 // Type something, getting into text editing mode (appending) automatically
1067 insertStringToObject(1, u"Foo Bar", /*bUseEscape*/ false);
1069 saveAndReload("impress8");
1071 xDrawPagesSupplier.set(mxComponent, uno::UNO_QUERY);
1072 xDrawPage.set(xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
1073 xShape.set(xDrawPage->getByIndex(1), uno::UNO_QUERY);
1074 OUString sExpectedText = sOldText + "Foo Bar";
1075 CPPUNIT_ASSERT_EQUAL(sExpectedText, xShape->getString());
1078 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf148810)
1080 createSdImpressDoc("pptx/tdf148810_PARA_OUTLLEVEL.pptx");
1082 // type something to get into text editing mode (instead of shape selection).
1083 insertStringToObject(1, u"x", /*bUseEscape*/ false);
1085 auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
1086 typeKey(pXImpressDocument, KEY_HOME);
1088 typeKey(pXImpressDocument, KEY_BACKSPACE);
1090 uno::Reference<beans::XPropertySet> xShape(getShapeFromPage(1, 0));
1091 uno::Reference<text::XTextRange> xParagraph(getParagraphFromShape(0, xShape));
1092 uno::Reference<beans::XPropertySet> xPropSet(xParagraph, uno::UNO_QUERY_THROW);
1093 sal_Int16 nNumberingLevel = -1;
1094 xPropSet->getPropertyValue("NumberingLevel") >>= nNumberingLevel;
1095 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nNumberingLevel);
1097 dispatchCommand(mxComponent, ".uno:Undo", {});
1099 nNumberingLevel = -1;
1100 xPropSet->getPropertyValue("NumberingLevel") >>= nNumberingLevel;
1102 // Without the fix in place, this test would have failed with
1103 // - Expected: 0
1104 // - Actual : -1
1105 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nNumberingLevel);
1108 CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf127696)
1110 createSdImpressDoc();
1112 dispatchCommand(mxComponent, ".uno:InsertPage", {});
1114 insertStringToObject(0, u"Test", /*bUseEscape*/ false);
1115 dispatchCommand(mxComponent, ".uno:SelectAll", {});
1116 dispatchCommand(mxComponent, ".uno:OutlineFont", {});
1118 // Save it as PPTX and load it again.
1119 saveAndReload("Impress Office Open XML");
1121 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
1122 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(1),
1123 uno::UNO_QUERY);
1125 uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
1127 uno::Reference<text::XText> xText
1128 = uno::Reference<text::XTextRange>(xShape, uno::UNO_QUERY_THROW)->getText();
1129 CPPUNIT_ASSERT_MESSAGE("Not a text shape", xText.is());
1131 uno::Reference<container::XEnumerationAccess> paraEnumAccess(xText, uno::UNO_QUERY);
1132 uno::Reference<container::XEnumeration> paraEnum(paraEnumAccess->createEnumeration());
1134 uno::Reference<text::XTextRange> xParagraph(paraEnum->nextElement(), uno::UNO_QUERY_THROW);
1136 uno::Reference<container::XEnumerationAccess> runEnumAccess(xParagraph, uno::UNO_QUERY);
1137 uno::Reference<container::XEnumeration> runEnum = runEnumAccess->createEnumeration();
1139 uno::Reference<text::XTextRange> xRun(runEnum->nextElement(), uno::UNO_QUERY);
1140 uno::Reference<beans::XPropertySet> xPropSet(xRun, uno::UNO_QUERY_THROW);
1142 bool bContoured = false;
1143 xPropSet->getPropertyValue("CharContoured") >>= bContoured;
1144 CPPUNIT_ASSERT(bContoured);
1147 // TODO - Readd when we implement style level fill color and set that for default style
1148 /*CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testThemeShapeInsert)
1150 // Given a document with a theme, accent1 color is set to 0x000004:
1151 createSdImpressDoc();
1152 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
1153 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
1154 uno::UNO_QUERY);
1155 uno::Reference<drawing::XMasterPageTarget> xMasterPageTarget(xDrawPage, uno::UNO_QUERY);
1156 uno::Reference<beans::XPropertySet> xMasterPage(xMasterPageTarget->getMasterPage(),
1157 uno::UNO_QUERY);
1159 auto pTheme = std::make_shared<model::Theme>("mytheme");
1160 auto pColorSet = std::make_shared<model::ColorSet>("mycolorscheme");
1161 pColorSet->add(model::ThemeColorType::Dark1, 0x0);
1162 pColorSet->add(model::ThemeColorType::Light1, 0x1);
1163 pColorSet->add(model::ThemeColorType::Dark2, 0x2);
1164 pColorSet->add(model::ThemeColorType::Light2, 0x3);
1165 pColorSet->add(model::ThemeColorType::Accent1, 0x4);
1166 pColorSet->add(model::ThemeColorType::Accent2, 0x5);
1167 pColorSet->add(model::ThemeColorType::Accent3, 0x6);
1168 pColorSet->add(model::ThemeColorType::Accent4, 0x7);
1169 pColorSet->add(model::ThemeColorType::Accent5, 0x8);
1170 pColorSet->add(model::ThemeColorType::Accent6, 0x9);
1171 pColorSet->add(model::ThemeColorType::Hyperlink, 0xa);
1172 pColorSet->add(model::ThemeColorType::FollowedHyperlink, 0xb);
1173 pTheme->setColorSet(pColorSet);
1175 xMasterPage->setPropertyValue("Theme", uno::Any(model::theme::createXTheme(pTheme)));
1177 // When inserting a shape:
1178 uno::Sequence<beans::PropertyValue> aArgs = {
1179 comphelper::makePropertyValue("CreateDirectly", true),
1181 dispatchCommand(mxComponent, ".uno:BasicShapes.round-rectangle", aArgs);
1183 // Then make sure the that fill color of the last shape is the accent1 color:
1184 sal_Int32 nShapeIndex = xDrawPage->getCount() - 1;
1185 uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(nShapeIndex), uno::UNO_QUERY);
1186 sal_Int32 nFillColor{};
1187 xShape->getPropertyValue("FillColor") >>= nFillColor;
1188 // Without the accompanying fix in place, this test would have failed with:
1189 // - Expected: 0 / 0x000004 (~black)
1190 // - Actual : 7512015 / 0x729fcf (~blue)
1191 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x4), nFillColor);
1194 CPPUNIT_PLUGIN_IMPLEMENT();
1196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */