nss: upgrade to release 3.73
[LibreOffice.git] / sd / qa / unit / misc-tests.cxx
blob75818805295aae5e6a3b7ef25c73670db3fc5697
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 <officecfg/Office/Common.hxx>
11 #include "sdmodeltestbase.hxx"
13 #include <com/sun/star/uno/Reference.hxx>
15 #include <comphelper/processfactory.hxx>
16 #include <com/sun/star/frame/Desktop.hpp>
17 #include <com/sun/star/frame/XModel2.hpp>
19 #include <com/sun/star/awt/Gradient.hpp>
20 #include <com/sun/star/awt/PosSize.hpp>
21 #include <com/sun/star/drawing/FillStyle.hpp>
22 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
23 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
24 #include <com/sun/star/drawing/XDrawPages.hpp>
25 #include <com/sun/star/drawing/XDrawPage.hpp>
26 #include <com/sun/star/drawing/XShapes.hpp>
27 #include <com/sun/star/graphic/XGraphic.hpp>
28 #include <com/sun/star/container/XIndexAccess.hpp>
29 #include <com/sun/star/frame/XLoadable.hpp>
30 #include <com/sun/star/table/XTable.hpp>
31 #include <com/sun/star/table/XMergeableCellRange.hpp>
33 #include <vcl/scheduler.hxx>
34 #include <osl/thread.hxx>
35 #include <svx/sdr/table/tablecontroller.hxx>
36 #include <sfx2/request.hxx>
37 #include <svx/svdpagv.hxx>
38 #include <svx/svxids.hrc>
39 #include <editeng/eeitem.hxx>
40 #include <editeng/adjustitem.hxx>
41 #include <editeng/outlobj.hxx>
42 #include <editeng/editobj.hxx>
43 #include <SlideSorterViewShell.hxx>
44 #include <SlideSorter.hxx>
45 #include <controller/SlideSorterController.hxx>
46 #include <controller/SlsClipboard.hxx>
47 #include <controller/SlsPageSelector.hxx>
48 #include <undo/undomanager.hxx>
49 #include <GraphicViewShell.hxx>
50 #include <chrono>
51 #include <sdpage.hxx>
52 #include <comphelper/base64.hxx>
53 #include <toolkit/helper/vclunohelper.hxx>
54 #include <LayerTabBar.hxx>
55 #include <vcl/window.hxx>
56 #include <vcl/event.hxx>
57 #include <vcl/keycodes.hxx>
58 #include <svx/svdoashp.hxx>
59 #include <tools/gen.hxx>
60 #include <svx/view3d.hxx>
61 #include <svx/scene3d.hxx>
63 using namespace ::com::sun::star;
65 /// Impress miscellaneous tests.
66 class SdMiscTest : public SdModelTestBaseXML
68 public:
69 void testTdf96206();
70 void testTdf96708();
71 void testTdf99396();
72 void testTdf99396TextEdit();
73 void testFillGradient();
74 void testTdf44774();
75 void testTdf38225();
76 void testTdf101242_ODF_no_settings();
77 void testTdf101242_ODF_add_settings();
78 void testTdf101242_settings_keep();
79 void testTdf101242_settings_remove();
80 void testTdf119392();
81 void testTdf67248();
82 void testTdf119956();
83 void testTdf120527();
84 void testTdf98839_ShearVFlipH();
85 void testTdf130988();
86 void testTdf131033();
87 void testTdf129898LayerDrawnInSlideshow();
88 void testTdf136956();
90 CPPUNIT_TEST_SUITE(SdMiscTest);
91 CPPUNIT_TEST(testTdf96206);
92 CPPUNIT_TEST(testTdf96708);
93 CPPUNIT_TEST(testTdf99396);
94 CPPUNIT_TEST(testTdf99396TextEdit);
95 CPPUNIT_TEST(testFillGradient);
96 CPPUNIT_TEST(testTdf44774);
97 CPPUNIT_TEST(testTdf38225);
98 CPPUNIT_TEST(testTdf101242_ODF_no_settings);
99 CPPUNIT_TEST(testTdf101242_ODF_add_settings);
100 CPPUNIT_TEST(testTdf101242_settings_keep);
101 CPPUNIT_TEST(testTdf101242_settings_remove);
102 CPPUNIT_TEST(testTdf119392);
103 CPPUNIT_TEST(testTdf67248);
104 CPPUNIT_TEST(testTdf119956);
105 CPPUNIT_TEST(testTdf120527);
106 CPPUNIT_TEST(testTdf98839_ShearVFlipH);
107 CPPUNIT_TEST(testTdf130988);
108 CPPUNIT_TEST(testTdf131033);
109 CPPUNIT_TEST(testTdf129898LayerDrawnInSlideshow);
110 CPPUNIT_TEST(testTdf136956);
111 CPPUNIT_TEST_SUITE_END();
113 virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override
115 static const struct { char const * pPrefix; char const * pURI; } namespaces[] =
117 // ODF
118 { "config", "urn:oasis:names:tc:opendocument:xmlns:config:1.0"},
119 { "draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" },
120 { "fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" },
121 { "loext", "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" },
122 { "office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0" },
123 { "style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0" },
124 { "svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" },
125 { "text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0" },
127 for (size_t i = 0; i < SAL_N_ELEMENTS(namespaces); ++i)
129 xmlXPathRegisterNs(pXmlXPathCtx,
130 reinterpret_cast<xmlChar const *>(namespaces[i].pPrefix),
131 reinterpret_cast<xmlChar const *>(namespaces[i].pURI));
135 private:
136 sd::DrawDocShellRef Load(const OUString& rURL, sal_Int32 nFormat);
139 sd::DrawDocShellRef SdMiscTest::Load(const OUString& rURL, sal_Int32 nFormat)
141 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(::comphelper::getProcessComponentContext());
142 CPPUNIT_ASSERT(xDesktop.is());
144 // create a frame
145 uno::Reference< frame::XFrame > xTargetFrame = xDesktop->findFrame("_blank", 0);
146 CPPUNIT_ASSERT(xTargetFrame.is());
148 // This ContainerWindow corresponds to the outermost window of a running LibreOffice.
149 // It needs a non-zero size and must be shown. Otherwise visible elements like the
150 // LayerTabBar in Draw have zero size and cannot get mouse events.
151 // The here used size is freely chosen.
152 uno::Reference<awt::XWindow> xContainerWindow = xTargetFrame->getContainerWindow();
153 CPPUNIT_ASSERT(xContainerWindow.is());
154 xContainerWindow->setPosSize(0, 0, 1024, 768, awt::PosSize::SIZE);
155 VclPtr<vcl::Window> pContainerWindow = VCLUnoHelper::GetWindow(xContainerWindow);
156 CPPUNIT_ASSERT(pContainerWindow);
157 pContainerWindow->Show(true);
159 // 1. Open the document
160 sd::DrawDocShellRef xDocSh = loadURL(rURL, nFormat);
161 CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocSh.is());
163 uno::Reference< frame::XModel2 > xModel2(xDocSh->GetModel(), uno::UNO_QUERY);
164 CPPUNIT_ASSERT(xModel2.is());
166 uno::Reference< frame::XController2 > xController = xModel2->createDefaultViewController(xTargetFrame);
167 CPPUNIT_ASSERT(xController.is());
169 // introduce model/view/controller to each other
170 xController->attachModel(xModel2.get());
171 xModel2->connectController(xController.get());
172 xTargetFrame->setComponent(xController->getComponentWindow(), xController.get());
173 xController->attachFrame(xTargetFrame);
174 xModel2->setCurrentController(xController.get());
176 sd::ViewShell *pViewShell = xDocSh->GetViewShell();
177 CPPUNIT_ASSERT(pViewShell);
179 // Draw has no slidesorter, Impress never shows a LayerTabBar
180 if (sd::ViewShell::ST_DRAW == pViewShell->GetShellType())
182 sd::LayerTabBar* pLayerTabBar = static_cast<sd::GraphicViewShell*>(pViewShell)->GetLayerTabControl();
183 CPPUNIT_ASSERT(pLayerTabBar);
184 pLayerTabBar->StateChanged(StateChangedType::InitShow);
186 else
188 sd::slidesorter::SlideSorterViewShell* pSSVS = nullptr;
189 for (int i = 0; i < 1000; i++)
191 // Process all Tasks - slide sorter is created here
192 while (Scheduler::ProcessTaskScheduling());
193 if ((pSSVS = sd::slidesorter::SlideSorterViewShell::GetSlideSorter(pViewShell->GetViewShellBase())) != nullptr)
194 break;
195 osl::Thread::wait(std::chrono::milliseconds(100));
197 CPPUNIT_ASSERT(pSSVS);
200 return xDocSh;
203 void SdMiscTest::testTdf96206()
205 // Copying/pasting slide referring to a non-default master with a text duplicated the master
207 sd::DrawDocShellRef xDocSh = Load(m_directories.getURLFromSrc("/sd/qa/unit/data/odp/tdf96206.odp"), ODP);
208 sd::ViewShell *pViewShell = xDocSh->GetViewShell();
209 auto pSSVS = sd::slidesorter::SlideSorterViewShell::GetSlideSorter(pViewShell->GetViewShellBase());
210 auto& rSSController = pSSVS->GetSlideSorter().GetController();
212 const sal_uInt16 nMasterPageCnt1 = xDocSh->GetDoc()->GetMasterSdPageCount(PageKind::Standard);
213 CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), nMasterPageCnt1);
214 rSSController.GetClipboard().DoCopy();
215 rSSController.GetClipboard().DoPaste();
216 const sal_uInt16 nMasterPageCnt2 = xDocSh->GetDoc()->GetMasterSdPageCount(PageKind::Standard);
217 CPPUNIT_ASSERT_EQUAL(nMasterPageCnt1, nMasterPageCnt2);
219 xDocSh->DoClose();
222 void SdMiscTest::testTdf96708()
224 sd::DrawDocShellRef xDocSh = Load(m_directories.getURLFromSrc("/sd/qa/unit/data/odp/tdf96708.odp"), ODP);
225 sd::ViewShell *pViewShell = xDocSh->GetViewShell();
226 auto pSSVS = sd::slidesorter::SlideSorterViewShell::GetSlideSorter(pViewShell->GetViewShellBase());
227 auto& rSSController = pSSVS->GetSlideSorter().GetController();
228 auto& rPageSelector = rSSController.GetPageSelector();
230 const sal_uInt16 nMasterPageCnt1 = xDocSh->GetDoc()->GetMasterSdPageCount(PageKind::Standard);
231 CPPUNIT_ASSERT_EQUAL(sal_uInt16(4), nMasterPageCnt1);
232 rPageSelector.SelectAllPages();
233 rSSController.GetClipboard().DoCopy();
235 // Now wait for timers to trigger creation of auto-layout
236 osl::Thread::wait(std::chrono::milliseconds(100));
237 Scheduler::ProcessTaskScheduling();
239 rSSController.GetClipboard().DoPaste();
240 const sal_uInt16 nMasterPageCnt2 = xDocSh->GetDoc()->GetMasterSdPageCount(PageKind::Standard);
241 CPPUNIT_ASSERT_EQUAL(nMasterPageCnt1, nMasterPageCnt2);
243 xDocSh->DoClose();
246 void SdMiscTest::testTdf99396()
248 // Load the document and select the table.
249 sd::DrawDocShellRef xDocSh = Load(m_directories.getURLFromSrc("/sd/qa/unit/data/tdf99396.odp"), ODP);
250 sd::ViewShell *pViewShell = xDocSh->GetViewShell();
251 SdPage* pPage = pViewShell->GetActualPage();
252 SdrObject* pObject = pPage->GetObj(0);
253 SdrView* pView = pViewShell->GetView();
254 pView->MarkObj(pObject, pView->GetSdrPageView());
256 // Make sure that the undo stack is empty.
257 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), xDocSh->GetDoc()->GetUndoManager()->GetUndoActionCount());
259 // Set the vertical alignment of the cells to bottom.
260 sdr::table::SvxTableController* pTableController = dynamic_cast<sdr::table::SvxTableController*>(pView->getSelectionController().get());
261 CPPUNIT_ASSERT(pTableController);
262 SfxRequest aRequest(pViewShell->GetViewFrame(), SID_TABLE_VERT_BOTTOM);
263 pTableController->Execute(aRequest);
264 // This was 0, it wasn't possible to undo a vertical alignment change.
265 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), xDocSh->GetDoc()->GetUndoManager()->GetUndoActionCount());
267 xDocSh->DoClose();
270 void SdMiscTest::testTdf99396TextEdit()
272 // Load the document and select the table.
273 sd::DrawDocShellRef xDocSh = Load(m_directories.getURLFromSrc("/sd/qa/unit/data/tdf99396.odp"), ODP);
274 sd::ViewShell* pViewShell = xDocSh->GetViewShell();
275 SdPage* pPage = pViewShell->GetActualPage();
276 auto pTableObject = dynamic_cast<sdr::table::SdrTableObj*>(pPage->GetObj(0));
277 CPPUNIT_ASSERT(pTableObject);
278 SdrView* pView = pViewShell->GetView();
279 pView->MarkObj(pTableObject, pView->GetSdrPageView());
281 // Make sure that the undo stack is empty.
282 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), xDocSh->GetDoc()->GetUndoManager()->GetUndoActionCount());
284 // Set horizontal and vertical adjustment during text edit.
285 pView->SdrBeginTextEdit(pTableObject);
286 CPPUNIT_ASSERT(pView->GetTextEditObject());
288 SfxRequest aRequest(pViewShell->GetViewFrame(), SID_ATTR_PARA_ADJUST_RIGHT);
289 SfxItemSet aEditAttr(xDocSh->GetDoc()->GetPool());
290 pView->GetAttributes(aEditAttr);
291 SfxItemSet aNewAttr(*(aEditAttr.GetPool()), aEditAttr.GetRanges());
292 aNewAttr.Put(SvxAdjustItem(SvxAdjust::Right, EE_PARA_JUST));
293 aRequest.Done(aNewAttr);
294 const SfxItemSet* pArgs = aRequest.GetArgs();
295 pView->SetAttributes(*pArgs);
298 auto pTableController = dynamic_cast<sdr::table::SvxTableController*>(pView->getSelectionController().get());
299 CPPUNIT_ASSERT(pTableController);
300 SfxRequest aRequest(pViewShell->GetViewFrame(), SID_TABLE_VERT_BOTTOM);
301 pTableController->Execute(aRequest);
303 pView->SdrEndTextEdit();
305 // Check that the result is what we expect.
307 uno::Reference<table::XTable> xTable = pTableObject->getTable();
308 uno::Reference<beans::XPropertySet> xCell(xTable->getCellByPosition(0, 0), uno::UNO_QUERY);
309 drawing::TextVerticalAdjust eAdjust = xCell->getPropertyValue("TextVerticalAdjust").get<drawing::TextVerticalAdjust>();
310 CPPUNIT_ASSERT_EQUAL(int(drawing::TextVerticalAdjust_BOTTOM), static_cast<int>(eAdjust));
313 const EditTextObject& rEdit = pTableObject->getText(0)->GetOutlinerParaObject()->GetTextObject();
314 const SfxItemSet& rParaAttribs = rEdit.GetParaAttribs(0);
315 auto pAdjust = rParaAttribs.GetItem(EE_PARA_JUST);
316 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Right, pAdjust->GetAdjust());
319 // Now undo.
320 xDocSh->GetUndoManager()->Undo();
322 // Check again that the result is what we expect.
324 uno::Reference<table::XTable> xTable = pTableObject->getTable();
325 uno::Reference<beans::XPropertySet> xCell(xTable->getCellByPosition(0, 0), uno::UNO_QUERY);
326 drawing::TextVerticalAdjust eAdjust = xCell->getPropertyValue("TextVerticalAdjust").get<drawing::TextVerticalAdjust>();
327 // This failed: Undo() did not change it from drawing::TextVerticalAdjust_BOTTOM.
328 CPPUNIT_ASSERT_EQUAL(int(drawing::TextVerticalAdjust_TOP), static_cast<int>(eAdjust));
331 const EditTextObject& rEdit = pTableObject->getText(0)->GetOutlinerParaObject()->GetTextObject();
332 const SfxItemSet& rParaAttribs = rEdit.GetParaAttribs(0);
333 auto pAdjust = rParaAttribs.GetItem(EE_PARA_JUST);
334 CPPUNIT_ASSERT_EQUAL(SvxAdjust::Center, pAdjust->GetAdjust());
339 * now test tdf#103950 - Undo does not revert bundled font size changes for table cells
341 pTableObject = dynamic_cast<sdr::table::SdrTableObj*>(pPage->GetObj(0));
342 pView->MarkObj(pTableObject, pView->GetSdrPageView()); // select table
344 SfxRequest aRequest(pViewShell->GetViewFrame(), SID_GROW_FONT_SIZE);
345 static_cast<sd::DrawViewShell*>(pViewShell)->ExecChar(aRequest);
347 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), xDocSh->GetDoc()->GetUndoManager()->GetUndoActionCount());
350 xDocSh->DoClose();
353 void SdMiscTest::testFillGradient()
355 ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, false, DocumentType::Impress);
356 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier = getDoc( xDocShRef );
357 uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages();
358 // Insert a new page.
359 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->insertNewByIndex(0), uno::UNO_SET_THROW );
360 uno::Reference<drawing::XShapes> xShapes(xDrawPage,uno::UNO_QUERY_THROW);
361 uno::Reference<lang::XMultiServiceFactory> const xDoc(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY);
362 // Create a rectangle
363 uno::Reference<drawing::XShape> xShape1(xDoc->createInstance("com.sun.star.drawing.RectangleShape"),uno::UNO_QUERY_THROW );
364 uno::Reference<beans::XPropertySet> xPropSet(xShape1, uno::UNO_QUERY_THROW);
365 // Set FillStyle and FillGradient
366 awt::Gradient aGradient;
367 aGradient.StartColor = sal_Int32(Color(255, 0, 0));
368 aGradient.EndColor = sal_Int32(Color(0, 255, 0));
369 xPropSet->setPropertyValue("FillStyle", uno::makeAny(drawing::FillStyle_GRADIENT));
370 xPropSet->setPropertyValue("FillGradient", uno::makeAny(aGradient));
371 // Add the rectangle to the page.
372 xShapes->add(xShape1);
374 // Retrieve the shape and check FillStyle and FillGradient
375 uno::Reference<container::XIndexAccess> xIndexAccess(xDrawPage, uno::UNO_QUERY_THROW);
376 uno::Reference<beans::XPropertySet > xPropSet2(xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW);
377 drawing::FillStyle eFillStyle;
378 awt::Gradient aGradient2;
379 CPPUNIT_ASSERT(xPropSet2->getPropertyValue("FillStyle") >>= eFillStyle);
380 CPPUNIT_ASSERT_EQUAL(int(drawing::FillStyle_GRADIENT), static_cast<int>(eFillStyle));
381 CPPUNIT_ASSERT(xPropSet2->getPropertyValue("FillGradient") >>= aGradient2);
382 CPPUNIT_ASSERT_EQUAL(sal_Int32(Color(255, 0, 0)),aGradient2.StartColor);
383 CPPUNIT_ASSERT_EQUAL(sal_Int32(Color(0, 255, 0)),aGradient2.EndColor);
385 xDocShRef->DoClose();
388 void SdMiscTest::testTdf44774()
390 sd::DrawDocShellRef xDocShRef = new sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, false,
391 DocumentType::Draw);
392 const uno::Reference<frame::XLoadable> xLoadable(xDocShRef->GetModel(), uno::UNO_QUERY_THROW);
393 xLoadable->initNew();
394 SfxStyleSheetBasePool* pSSPool = xDocShRef->GetStyleSheetPool();
396 // Create a new style with an empty name, like what happens in UI when creating a new style
397 SfxStyleSheetBase& rStyleA = pSSPool->Make("", SfxStyleFamily::Para, SfxStyleSearchBits::UserDefined);
398 // Assign a new name, which does not yet set its ApiName
399 rStyleA.SetName("StyleA");
400 // Create another style
401 SfxStyleSheetBase& rStyleB = pSSPool->Make("StyleB", SfxStyleFamily::Para, SfxStyleSearchBits::UserDefined);
402 // ... and set its parent to the first one
403 rStyleB.SetParent("StyleA");
405 // Now save the file and reload
406 xDocShRef = saveAndReload(xDocShRef.get(), ODG);
407 pSSPool = xDocShRef->GetStyleSheetPool();
409 SfxStyleSheetBase* pStyle = pSSPool->Find("StyleB", SfxStyleFamily::Para);
410 CPPUNIT_ASSERT(pStyle);
411 // The parent set in StyleB used to reset, because parent style's msApiName was empty
412 CPPUNIT_ASSERT_EQUAL(OUString("StyleA"), pStyle->GetParent());
414 xDocShRef->DoClose();
417 void SdMiscTest::testTdf38225()
419 sd::DrawDocShellRef xDocShRef = new sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, false,
420 DocumentType::Draw);
421 const uno::Reference<frame::XLoadable> xLoadable(xDocShRef->GetModel(), uno::UNO_QUERY_THROW);
422 xLoadable->initNew();
423 SfxStyleSheetBasePool* pSSPool = xDocShRef->GetStyleSheetPool();
425 // Create a new style with a name
426 pSSPool->Make("StyleWithName1", SfxStyleFamily::Para, SfxStyleSearchBits::UserDefined);
428 // Now save the file and reload
429 xDocShRef = saveAndReload(xDocShRef.get(), ODG);
430 pSSPool = xDocShRef->GetStyleSheetPool();
432 SfxStyleSheetBase* pStyle = pSSPool->Find("StyleWithName1", SfxStyleFamily::Para);
433 CPPUNIT_ASSERT(pStyle);
435 // Rename the style
436 CPPUNIT_ASSERT(pStyle->SetName("StyleWithName2"));
438 // Save the file and reload again
439 xDocShRef = saveAndReload(xDocShRef.get(), ODG);
440 pSSPool = xDocShRef->GetStyleSheetPool();
442 // The problem was that the style kept the old name upon reloading
443 pStyle = pSSPool->Find("StyleWithName1", SfxStyleFamily::Para);
444 CPPUNIT_ASSERT(!pStyle);
445 pStyle = pSSPool->Find("StyleWithName2", SfxStyleFamily::Para);
446 CPPUNIT_ASSERT(pStyle);
448 xDocShRef->DoClose();
451 void SdMiscTest::testTdf120527()
453 sd::DrawDocShellRef xDocShRef
454 = new sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, false, DocumentType::Draw);
455 uno::Reference<frame::XLoadable> xLoadable(xDocShRef->GetModel(), uno::UNO_QUERY);
456 CPPUNIT_ASSERT(xLoadable.is());
457 xLoadable->initNew();
459 // Load a bitmap into the bitmap table.
460 uno::Reference<lang::XMultiServiceFactory> xFactory(xDocShRef->GetModel(), uno::UNO_QUERY);
461 CPPUNIT_ASSERT(xFactory.is());
462 uno::Reference<container::XNameContainer> xBitmaps(
463 xFactory->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY);
464 CPPUNIT_ASSERT(xBitmaps.is());
465 OUString aGraphicURL = m_directories.getURLFromSrc("/sd/qa/unit/data/tdf120527.jpg");
466 xBitmaps->insertByName("test", uno::makeAny(aGraphicURL));
468 // Create a graphic.
469 uno::Reference<drawing::XShape> xShape(
470 xFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY);
471 CPPUNIT_ASSERT(xShape.is());
472 uno::Reference<beans::XPropertySet> xShapeProperySet(xShape, uno::UNO_QUERY);
473 CPPUNIT_ASSERT(xShapeProperySet.is());
474 xShapeProperySet->setPropertyValue("GraphicURL", xBitmaps->getByName("test"));
476 // Insert it.
477 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xDocShRef->GetModel(),
478 uno::UNO_QUERY);
479 CPPUNIT_ASSERT(xDrawPagesSupplier.is());
480 uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages();
481 CPPUNIT_ASSERT(xDrawPages.is());
482 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY);
483 CPPUNIT_ASSERT(xDrawPage.is());
484 // This failed with a lang.IllegalArgumentException.
485 xDrawPage->add(xShape);
487 // Verify that the graphic was actually consumed.
488 uno::Reference<graphic::XGraphic> xGraphic;
489 xShapeProperySet->getPropertyValue("Graphic") >>= xGraphic;
490 CPPUNIT_ASSERT(xGraphic.is());
492 xDocShRef->DoClose();
495 /// Draw miscellaneous tests.
497 // Since LO 6.2 the visible/printable/locked information for layers is always
498 // written as ODF attributes draw:display and draw:protected. It is only read from
499 // there, if the config items VisibleLayers, PrintableLayers and LockedLayers do
500 // not exist. The user option WriteLayerStateAsConfigItem can be set to 'true' to
501 // write these config items in addition to the ODF attributes for to produce
502 // documents for older LO versions or Apache OpenOffice. With value 'false' no
503 // config items are written. The 'testTdf101242_xyz' tests combine source
504 // files with and without config items with option values 'true' and 'false'.
506 void SdMiscTest::testTdf101242_ODF_add_settings()
508 // Loads a document, which has the visible/printable/locked information for layers
509 // only in the ODF attributes draw:display and draw:protected. The resaved document
510 // should still have the ODF attributes and in addition the config items in settings.xml.
511 // "Load" is needed for to handle layers, simple "loadURL" does not work.
512 sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("/sd/qa/unit/data/tdf101242_ODF.odg"), ODG);
513 CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocShRef.is());
515 // Saving including items in settings.xml
516 std::shared_ptr<comphelper::ConfigurationChanges> pBatch( comphelper::ConfigurationChanges::create() );
517 officecfg::Office::Common::Misc::WriteLayerStateAsConfigItem::set(true, pBatch);
518 pBatch->commit();
519 utl::TempFile aTempFile;
520 aTempFile.EnableKillingFile();
521 save(xDocShRef.get(), getFormat(ODG), aTempFile );
523 // Verify, that the saved document still has the ODF attributes
524 xmlDocUniquePtr pXmlDoc = parseExport(aTempFile, "styles.xml");
525 CPPUNIT_ASSERT_MESSAGE("Failed to get 'styles.xml'", pXmlDoc);
526 const OString sPathStart("/office:document-styles/office:master-styles/draw:layer-set/draw:layer");
527 assertXPath(pXmlDoc, sPathStart + "[@draw:name='backgroundobjects' and @draw:protected='true']");
528 assertXPath(pXmlDoc, sPathStart + "[@draw:name='controls' and @draw:display='screen']");
529 assertXPath(pXmlDoc, sPathStart + "[@draw:name='measurelines' and @draw:display='printer']");
531 // Verify, that the saved document has got the items in settings.xml
532 xmlDocUniquePtr pXmlDoc2 = parseExport(aTempFile, "settings.xml");
533 CPPUNIT_ASSERT_MESSAGE("Failed to get 'settings.xml'", pXmlDoc2);
534 const OString sPathStart2("/office:document-settings/office:settings/config:config-item-set[@config:name='ooo:view-settings']/config:config-item-map-indexed[@config:name='Views']/config:config-item-map-entry");
535 // Value is a bitfield with first Byte in order '* * * measurelines controls backgroundobjects background layout'
536 // The first three bits depend on initialization and may change. The values in file are Base64 encoded.
537 OUString sBase64;
538 uno::Sequence<sal_Int8> aDecodedSeq;
539 sBase64 = getXPathContent(pXmlDoc2, sPathStart2 + "/config:config-item[@config:name='VisibleLayers']");
540 CPPUNIT_ASSERT_MESSAGE( "Item VisibleLayers does not exists.", !sBase64.isEmpty());
541 comphelper::Base64::decode(aDecodedSeq, sBase64);
542 CPPUNIT_ASSERT_EQUAL( 0x0F, static_cast<sal_uInt8>(aDecodedSeq[0]) & 0x1F );
544 sBase64 = getXPathContent(pXmlDoc2, sPathStart2 + "/config:config-item[@config:name='PrintableLayers']");
545 CPPUNIT_ASSERT_MESSAGE( "Item PrintableLayers does not exists.", !sBase64.isEmpty());
546 comphelper::Base64::decode(aDecodedSeq, sBase64);
547 CPPUNIT_ASSERT_EQUAL( 0x17, static_cast<sal_uInt8>(aDecodedSeq[0]) & 0x1F);
549 sBase64 = getXPathContent(pXmlDoc2, sPathStart2 + "/config:config-item[@config:name='LockedLayers']");
550 CPPUNIT_ASSERT_MESSAGE( "Item LockedLayers does not exists.", !sBase64.isEmpty());
551 comphelper::Base64::decode(aDecodedSeq, sBase64);
552 CPPUNIT_ASSERT_EQUAL( 0x04, static_cast<sal_uInt8>(aDecodedSeq[0]) & 0x1F);
554 xDocShRef->DoClose();
557 void SdMiscTest::testTdf101242_ODF_no_settings()
559 // Loads a document, which has the visible/printable/locked information for layers
560 // only in the ODF attributes draw:display and draw:protected. The resave document
561 // should have only the ODF attributes and no config items in settings.xml.
562 sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("/sd/qa/unit/data/tdf101242_ODF.odg"), ODG);
563 CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocShRef.is());
565 // Saving without items in settings.xml
566 std::shared_ptr<comphelper::ConfigurationChanges> pBatch( comphelper::ConfigurationChanges::create() );
567 officecfg::Office::Common::Misc::WriteLayerStateAsConfigItem::set(false, pBatch);
568 pBatch->commit();
569 utl::TempFile aTempFile;
570 aTempFile.EnableKillingFile();
571 save(xDocShRef.get(), getFormat(ODG), aTempFile );
573 // Verify, that the saved document still has the ODF attributes
574 xmlDocUniquePtr pXmlDoc = parseExport(aTempFile, "styles.xml");
575 CPPUNIT_ASSERT_MESSAGE("Failed to get 'styles.xml'", pXmlDoc);
576 const OString sPathStart("/office:document-styles/office:master-styles/draw:layer-set/draw:layer");
577 assertXPath(pXmlDoc, sPathStart + "[@draw:name='backgroundobjects' and @draw:protected='true']");
578 assertXPath(pXmlDoc, sPathStart + "[@draw:name='controls' and @draw:display='screen']");
579 assertXPath(pXmlDoc, sPathStart + "[@draw:name='measurelines' and @draw:display='printer']");
581 // Verify, that the saved document has no layer items in settings.xml
582 xmlDocUniquePtr pXmlDoc2 = parseExport(aTempFile, "settings.xml");
583 CPPUNIT_ASSERT_MESSAGE("Failed to get 'settings.xml'", pXmlDoc2);
584 const OString sPathStart2("/office:document-settings/office:settings/config:config-item-set[@config:name='ooo:view-settings']/config:config-item-map-indexed[@config:name='Views']/config:config-item-map-entry");
585 xmlXPathObjectPtr pXmlObj=getXPathNode(pXmlDoc2, sPathStart2 + "/config:config-item[@config:name='VisibleLayers']");
586 CPPUNIT_ASSERT_EQUAL(0, xmlXPathNodeSetGetLength(pXmlObj->nodesetval));
587 xmlXPathFreeObject(pXmlObj);
588 pXmlObj=getXPathNode(pXmlDoc2, sPathStart2 + "/config:config-item[@config:name='PrintableLayers']");
589 CPPUNIT_ASSERT_EQUAL(0, xmlXPathNodeSetGetLength(pXmlObj->nodesetval));
590 xmlXPathFreeObject(pXmlObj);
591 pXmlObj=getXPathNode(pXmlDoc2, sPathStart2 + "/config:config-item[@config:name='LockedLayers']");
592 CPPUNIT_ASSERT_EQUAL(0, xmlXPathNodeSetGetLength(pXmlObj->nodesetval));
593 xmlXPathFreeObject(pXmlObj);
595 xDocShRef->DoClose();
598 void SdMiscTest::testTdf101242_settings_keep()
600 // Loads a document, which has the visible/printable/locked information for layers
601 // only in the config items in settings.xml. That is the case for all old documents.
602 // The resaved document should have the ODF attributes draw:display and draw:protected
603 // and should still have these config items in settings.xml.
604 sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("/sd/qa/unit/data/tdf101242_settings.odg"), ODG);
605 CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocShRef.is());
607 // Saving including items in settings.xml
608 std::shared_ptr<comphelper::ConfigurationChanges> pBatch( comphelper::ConfigurationChanges::create() );
609 officecfg::Office::Common::Misc::WriteLayerStateAsConfigItem::set(true, pBatch);
610 pBatch->commit();
611 utl::TempFile aTempFile;
612 aTempFile.EnableKillingFile();
613 save(xDocShRef.get(), getFormat(ODG), aTempFile );
615 // Verify, that the saved document has the ODF attributes
616 xmlDocUniquePtr pXmlDoc = parseExport(aTempFile, "styles.xml");
617 CPPUNIT_ASSERT_MESSAGE("Failed to get 'styles.xml'", pXmlDoc);
618 const OString sPathStart("/office:document-styles/office:master-styles/draw:layer-set/draw:layer");
619 assertXPath(pXmlDoc, sPathStart + "[@draw:name='backgroundobjects' and @draw:protected='true']");
620 assertXPath(pXmlDoc, sPathStart + "[@draw:name='controls' and @draw:display='screen']");
621 assertXPath(pXmlDoc, sPathStart + "[@draw:name='measurelines' and @draw:display='printer']");
623 // Verify, that the saved document still has the items in settings.xml
624 xmlDocUniquePtr pXmlDoc2 = parseExport(aTempFile, "settings.xml");
625 CPPUNIT_ASSERT_MESSAGE("Failed to get 'settings.xml'", pXmlDoc2);
626 const OString sPathStart2("/office:document-settings/office:settings/config:config-item-set[@config:name='ooo:view-settings']/config:config-item-map-indexed[@config:name='Views']/config:config-item-map-entry");
627 // Value is a bitfield with first Byte in order '* * * measurelines controls backgroundobjects background layout'
628 // The first three bits depend on initialization and may change. The values in file are Base64 encoded.
629 OUString sBase64;
630 uno::Sequence<sal_Int8> aDecodedSeq;
631 sBase64 = getXPathContent(pXmlDoc2, sPathStart2 + "/config:config-item[@config:name='VisibleLayers']");
632 CPPUNIT_ASSERT_MESSAGE( "Item VisibleLayers does not exists.", !sBase64.isEmpty());
633 comphelper::Base64::decode(aDecodedSeq, sBase64);
634 CPPUNIT_ASSERT_EQUAL( 0x0F, static_cast<sal_uInt8>(aDecodedSeq[0]) & 0x1F );
636 sBase64 = getXPathContent(pXmlDoc2, sPathStart2 + "/config:config-item[@config:name='PrintableLayers']");
637 CPPUNIT_ASSERT_MESSAGE( "Item PrintableLayers does not exists.", !sBase64.isEmpty());
638 comphelper::Base64::decode(aDecodedSeq, sBase64);
639 CPPUNIT_ASSERT_EQUAL( 0x17, static_cast<sal_uInt8>(aDecodedSeq[0]) & 0x1F);
641 sBase64 = getXPathContent(pXmlDoc2, sPathStart2 + "/config:config-item[@config:name='LockedLayers']");
642 CPPUNIT_ASSERT_MESSAGE( "Item LockedLayers does not exists.", !sBase64.isEmpty());
643 comphelper::Base64::decode(aDecodedSeq, sBase64);
644 CPPUNIT_ASSERT_EQUAL( 0x04, static_cast<sal_uInt8>(aDecodedSeq[0]) & 0x1F);
646 xDocShRef->DoClose();
649 void SdMiscTest::testTdf101242_settings_remove()
651 // Loads a document, which has the visible/printable/locked information for layers
652 // only in the config items in settings.xml. That is the case for all old documents.
653 // The resaved document should have only the ODF attributes draw:display and draw:protected
654 // and should have no config items in settings.xml.
655 sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("/sd/qa/unit/data/tdf101242_settings.odg"), ODG);
656 CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocShRef.is());
658 // Saving without config items in settings.xml
659 std::shared_ptr<comphelper::ConfigurationChanges> pBatch( comphelper::ConfigurationChanges::create() );
660 officecfg::Office::Common::Misc::WriteLayerStateAsConfigItem::set(false, pBatch);
661 pBatch->commit();
662 utl::TempFile aTempFile;
663 aTempFile.EnableKillingFile();
664 save(xDocShRef.get(), getFormat(ODG), aTempFile );
666 // Verify, that the saved document has the ODF attributes
667 xmlDocUniquePtr pXmlDoc = parseExport(aTempFile, "styles.xml");
668 CPPUNIT_ASSERT_MESSAGE("Failed to get 'styles.xml'", pXmlDoc);
669 const OString sPathStart("/office:document-styles/office:master-styles/draw:layer-set/draw:layer");
670 assertXPath(pXmlDoc, sPathStart + "[@draw:name='backgroundobjects' and @draw:protected='true']");
671 assertXPath(pXmlDoc, sPathStart + "[@draw:name='controls' and @draw:display='screen']");
672 assertXPath(pXmlDoc, sPathStart + "[@draw:name='measurelines' and @draw:display='printer']");
674 // Verify, that the saved document has no layer items in settings.xml
675 xmlDocUniquePtr pXmlDoc2 = parseExport(aTempFile, "settings.xml");
676 CPPUNIT_ASSERT_MESSAGE("Failed to get 'settings.xml'", pXmlDoc2);
677 const OString sPathStart2("/office:document-settings/office:settings/config:config-item-set[@config:name='ooo:view-settings']/config:config-item-map-indexed[@config:name='Views']/config:config-item-map-entry");
678 xmlXPathObjectPtr pXmlObj=getXPathNode(pXmlDoc2, sPathStart2 + "/config:config-item[@config:name='VisibleLayers']");
679 CPPUNIT_ASSERT_EQUAL(0, xmlXPathNodeSetGetLength(pXmlObj->nodesetval));
680 xmlXPathFreeObject(pXmlObj);
681 pXmlObj=getXPathNode(pXmlDoc2, sPathStart2 + "/config:config-item[@config:name='PrintableLayers']");
682 CPPUNIT_ASSERT_EQUAL(0, xmlXPathNodeSetGetLength(pXmlObj->nodesetval));
683 xmlXPathFreeObject(pXmlObj);
684 pXmlObj=getXPathNode(pXmlDoc2, sPathStart2 + "/config:config-item[@config:name='LockedLayers']");
685 CPPUNIT_ASSERT_EQUAL(0, xmlXPathNodeSetGetLength(pXmlObj->nodesetval));
686 xmlXPathFreeObject(pXmlObj);
688 xDocShRef->DoClose();
691 void SdMiscTest::testTdf119392()
693 // Loads a document which has two user layers "V--" and "V-L". Inserts a new layer "-P-" between them.
694 // Checks, that the bitfields in the saved file have the bits in the correct order, in case
695 // option WriteLayerAsConfigItem is true and the config items are written.
696 std::shared_ptr<comphelper::ConfigurationChanges> batch( comphelper::ConfigurationChanges::create() );
697 officecfg::Office::Common::Misc::WriteLayerStateAsConfigItem::set(true, batch);
698 batch->commit();
700 sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("sd/qa/unit/data/tdf119392_InsertLayer.odg"), ODG);
701 CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocShRef.is());
702 // Insert layer "-P-", not visible, printable, not locked
703 SdrView* pView = xDocShRef -> GetViewShell()->GetView();
704 pView -> InsertNewLayer("-P-", 6); // 0..4 standard layer, 5 layer "V--"
705 SdrPageView* pPageView = pView -> GetSdrPageView();
706 pPageView -> SetLayerVisible("-P-", false);
707 pPageView -> SetLayerPrintable("-P-", true);
708 pPageView -> SetLayerLocked("-P-", false);
709 utl::TempFile aTempFile;
710 aTempFile.EnableKillingFile();
711 save(xDocShRef.get(), getFormat(ODG), aTempFile );
713 // Verify correct bit order in bitfield in the config items in settings.xml
714 xmlDocUniquePtr pXmlDoc = parseExport(aTempFile, "settings.xml");
715 CPPUNIT_ASSERT_MESSAGE("Failed to get 'settings.xml'", pXmlDoc);
716 const OString sPathStart("/office:document-settings/office:settings/config:config-item-set[@config:name='ooo:view-settings']/config:config-item-map-indexed[@config:name='Views']/config:config-item-map-entry");
717 // First Byte is in order 'V-L -P- V-- measurelines controls backgroundobjects background layout'
718 // Bits need to be: visible=10111111=0xbf=191 printable=01011111=0x5f=95 locked=10000000=0x80=128
719 // The values in file are Base64 encoded.
720 OUString sBase64;
721 uno::Sequence<sal_Int8> aDecodedSeq;
722 sBase64 = getXPathContent(pXmlDoc, sPathStart + "/config:config-item[@config:name='VisibleLayers']");
723 CPPUNIT_ASSERT_MESSAGE( "Item VisibleLayers does not exists.", !sBase64.isEmpty());
724 comphelper::Base64::decode(aDecodedSeq, sBase64);
725 CPPUNIT_ASSERT_EQUAL( 0xbF, static_cast<sal_uInt8>(aDecodedSeq[0]) & 0xff); // & 0xff forces unambiguous types for CPPUNIT_ASSERT_EQUAL
727 sBase64 = getXPathContent(pXmlDoc, sPathStart + "/config:config-item[@config:name='PrintableLayers']");
728 CPPUNIT_ASSERT_MESSAGE( "Item PrintableLayers does not exists.", !sBase64.isEmpty());
729 comphelper::Base64::decode(aDecodedSeq, sBase64);
730 CPPUNIT_ASSERT_EQUAL( 0x5f, static_cast<sal_uInt8>(aDecodedSeq[0]) & 0xff);
732 sBase64 = getXPathContent(pXmlDoc, sPathStart + "/config:config-item[@config:name='LockedLayers']");
733 CPPUNIT_ASSERT_MESSAGE( "Item LockedLayers does not exists.", !sBase64.isEmpty());
734 comphelper::Base64::decode(aDecodedSeq, sBase64);
735 CPPUNIT_ASSERT_EQUAL( 0x80, static_cast<sal_uInt8>(aDecodedSeq[0]) & 0xff);
737 xDocShRef->DoClose();
740 void SdMiscTest::testTdf67248()
742 // The document tdf67248.odg has been created with a German UI. It has a user layer named "Background".
743 // On opening the user layer must still exists. The error was, that it was merged into the standard
744 // layer "background".
745 sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("sd/qa/unit/data/tdf67248.odg"), ODG);
746 CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocShRef.is());
747 SdrLayerAdmin& rLayerAdmin = xDocShRef->GetDoc()->GetLayerAdmin();
748 CPPUNIT_ASSERT_EQUAL( sal_uInt16(6), rLayerAdmin.GetLayerCount());
750 xDocShRef->DoClose();
753 void SdMiscTest::testTdf119956()
755 sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("sd/qa/unit/data/tdf119956.odg"), ODG);
756 CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocShRef.is());
757 sd::GraphicViewShell* pGraphicViewShell = static_cast<sd::GraphicViewShell*>(xDocShRef -> GetViewShell());
758 CPPUNIT_ASSERT(pGraphicViewShell);
759 sd::LayerTabBar* pLayerTabBar = pGraphicViewShell->GetLayerTabControl();
760 CPPUNIT_ASSERT(pLayerTabBar);
762 // Alt+Click sets a tab in edit mode, so that you can rename it.
763 // The error was, that Alt+Click on a tab, which was not the current tab, did not set the clicked tab
764 // as current tab. As a result, the entered text was applied to the wrong tab.
766 // The test document has the layer tabs "layout", "controls", "measurelines" and "Layer4" in this order
767 // The "pagePos" is 0, 1, 2, 3
768 // Make sure, that tab "layout" is the current tab.
769 MouseEvent aSyntheticMouseEvent;
770 if (pLayerTabBar->GetCurPagePos() != 0)
772 sal_uInt16 nIdOfTabPos0(pLayerTabBar->GetPageId(0));
773 tools::Rectangle aTabPos0Rect(pLayerTabBar->GetPageRect(nIdOfTabPos0));
774 aSyntheticMouseEvent = MouseEvent(aTabPos0Rect.Center(), 1, MouseEventModifiers::SYNTHETIC, MOUSE_LEFT, 0);
775 pLayerTabBar->MouseButtonDown(aSyntheticMouseEvent);
777 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), pLayerTabBar->GetCurPagePos());
779 // Alt+Click on tab "Layer4"
780 sal_uInt16 nIdOfTabPos3(pLayerTabBar->GetPageId(3));
781 tools::Rectangle aTabPos3Rect(pLayerTabBar->GetPageRect(nIdOfTabPos3));
782 aSyntheticMouseEvent = MouseEvent(aTabPos3Rect.Center(), 1, MouseEventModifiers::SYNTHETIC, MOUSE_LEFT, KEY_MOD2);
783 pLayerTabBar->MouseButtonDown(aSyntheticMouseEvent);
785 // Make sure, tab 3 is current tab now.
786 CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), pLayerTabBar->GetCurPagePos());
788 xDocShRef->DoClose();
791 void SdMiscTest::testTdf98839_ShearVFlipH()
793 // Loads a document with a sheared shape and mirrors it
794 sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("sd/qa/unit/data/tdf98839_ShearVFlipH.odg"), ODG);
795 sd::GraphicViewShell* pViewShell = static_cast<sd::GraphicViewShell*>(xDocShRef->GetViewShell());
796 SdPage* pPage = pViewShell->GetActualPage();
797 SdrObjCustomShape* pShape = static_cast<SdrObjCustomShape*>(pPage->GetObj(0));
798 pShape->Mirror(Point(4000, 2000), Point(4000, 10000));
800 // Save and examine attribute draw:transform
801 utl::TempFile aTempFile;
802 aTempFile.EnableKillingFile();
803 save(xDocShRef.get(), getFormat(ODG), aTempFile);
804 xmlDocUniquePtr pXmlDoc = parseExport(aTempFile, "content.xml");
805 CPPUNIT_ASSERT_MESSAGE("Failed to get 'content.xml'", pXmlDoc);
806 const OString sPathStart("/office:document-content/office:body/office:drawing/draw:page");
807 assertXPath(pXmlDoc, sPathStart);
808 const OUString sTransform = getXPath(pXmlDoc, sPathStart + "/draw:custom-shape","transform");
810 // Error was, that the shear angle had a wrong sign.
811 CPPUNIT_ASSERT_MESSAGE("expected: draw:transform='skewX (-0.64350...)", sTransform.startsWith("skewX (-"));
813 xDocShRef->DoClose();
816 void SdMiscTest::testTdf130988()
818 sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("sd/qa/unit/data/tdf130988_3D_create_lathe.odg"), ODG);
820 //emulate command .uno:ConvertInto3DLathe
821 sd::ViewShell* pViewShell = xDocShRef->GetViewShell();
822 E3dView* pView = dynamic_cast<E3dView*>(pViewShell->GetView());
823 pView->MarkNextObj();
824 pView->ConvertMarkedObjTo3D(false, basegfx::B2DPoint(8000.0, -3000.0), basegfx::B2DPoint(3000.0, -8000.0));
825 E3dScene* pObj = dynamic_cast<E3dScene*>(pView->GetMarkedObjectByIndex(0));
826 CPPUNIT_ASSERT(pObj);
828 // Error was, that the created 3D object had a wrong path. Instead examining
829 // the path directly, I use the scene distance, because that is easier. The
830 // scene distance is calculated from the object while creating.
831 const double fDistance = pObj->GetDistance();
832 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("D3DSceneDistance", 7071.0, fDistance, 0.5);
834 xDocShRef->DoClose();
837 void SdMiscTest::testTdf131033()
839 sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("sd/qa/unit/data/tdf131033_3D_SceneSizeIn2d.odg"), ODG);
841 // The document contains a polygon, so that emulate command .uno:ConvertInto3DLathe
842 // by direct call of ConvertMarkedObjTo3D works.
843 // It produces a rotation around a vertical axis, which is far away from the
844 // generating shape.
845 sd::ViewShell* pViewShell = xDocShRef->GetViewShell();
846 E3dView* pView = dynamic_cast<E3dView*>(pViewShell->GetView());
847 pView->MarkNextObj();
848 pView->ConvertMarkedObjTo3D(false, basegfx::B2DPoint(11000.0, -5000.0), basegfx::B2DPoint(11000.0, -9000.0));
849 E3dScene* pObj = dynamic_cast<E3dScene*>(pView->GetMarkedObjectByIndex(0));
850 CPPUNIT_ASSERT(pObj);
852 // Error was, that the 2D representation of the scene did not contain the default 20°
853 // rotation of the new scene around x-axis and therefore was not high enough.
854 const double fSnapRectHeight = pObj->GetSnapRect().getHeight();
855 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("2D height", 7096.0, fSnapRectHeight, 1.0);
857 xDocShRef->DoClose();
860 void SdMiscTest::testTdf129898LayerDrawnInSlideshow()
862 // Versions LO 6.2 to 6.4 have produced files, where the layer DrawnInSlideshow has
863 // got visible=false and printable=false attributes. Those files should be repaired now.
864 sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc("sd/qa/unit/data/tdf129898_faulty_DrawnInSlideshow.odp"), ODP);
865 CPPUNIT_ASSERT_MESSAGE("Failed to load file.", xDocShRef.is());
867 // Verify model
868 const OUString sName = "DrawnInSlideshow";
869 SdrLayerAdmin& rLayerAdmin = xDocShRef->GetDoc()->GetLayerAdmin();
870 SdrLayer* pLayer = rLayerAdmin.GetLayer(sName);
871 CPPUNIT_ASSERT_MESSAGE("No layer DrawnInSlideshow", pLayer);
872 CPPUNIT_ASSERT(pLayer->IsVisibleODF() && pLayer->IsPrintableODF());
874 // Verify view
875 sd::DrawViewShell* pViewShell = static_cast<sd::DrawViewShell*>(xDocShRef->GetViewShell());
876 SdrPageView* pPageView = pViewShell->GetView()->GetSdrPageView();
877 CPPUNIT_ASSERT(pPageView->IsLayerVisible(sName) && pPageView->IsLayerPrintable(sName));
879 xDocShRef->DoClose();
882 void SdMiscTest::testTdf136956()
884 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc(u"sd/qa/unit/data/odp/cellspan.odp"), ODP);
886 const SdrPage *pPage = GetPage( 1, xDocShRef );
887 sdr::table::SdrTableObj *pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(pPage->GetObj(0));
888 CPPUNIT_ASSERT( pTableObj );
889 uno::Reference< table::XTable > xTable(pTableObj->getTable(), uno::UNO_SET_THROW);
891 uno::Reference< css::table::XMergeableCellRange > xRange(
892 xTable->createCursorByRange( xTable->getCellRangeByPosition( 0, 0, 3, 2 ) ), uno::UNO_QUERY_THROW );
894 // 4x3 Table before merge.
895 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable->getColumnCount());
896 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getRowCount());
898 xRange->merge();
900 // 1x1 Table after merge.
901 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getColumnCount());
902 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTable->getRowCount());
904 xDocShRef->GetUndoManager()->Undo();
906 // 4x3 Table after undo. Undo crashed before.
907 CPPUNIT_ASSERT_EQUAL(sal_Int32(4), xTable->getColumnCount());
908 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getRowCount());
910 xDocShRef->DoClose();
913 CPPUNIT_TEST_SUITE_REGISTRATION(SdMiscTest);
915 CPPUNIT_PLUGIN_IMPLEMENT();
917 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */