Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / sd / qa / unit / export-tests.cxx
blob57fe771339f11380c1a0ad16f9aba19354872686
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 */
9 #include <officecfg/Office/Common.hxx>
10 #include "sdmodeltestbase.hxx"
11 #include <sdpage.hxx>
13 #include <editeng/editobj.hxx>
14 #include <editeng/outlobj.hxx>
15 #include <editeng/colritem.hxx>
17 #include <svx/svdotext.hxx>
18 #include <svx/svdograf.hxx>
19 #include <svx/svdomedia.hxx>
20 #include <unotools/mediadescriptor.hxx>
21 #include <rtl/ustring.hxx>
23 #include <vcl/opengl/OpenGLWrapper.hxx>
25 #include <com/sun/star/drawing/XDrawPage.hpp>
26 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/awt/XBitmap.hpp>
29 #include <com/sun/star/graphic/XGraphic.hpp>
30 #include <com/sun/star/graphic/GraphicType.hpp>
31 #include <com/sun/star/frame/XStorable.hpp>
32 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
33 #include <com/sun/star/table/BorderLine2.hpp>
36 #include <svx/svdotable.hxx>
37 #include <config_features.h>
39 using namespace css;
40 using namespace css::animations;
42 class SdExportTest : public SdModelTestBaseXML
44 public:
45 void testBackgroundImage();
46 void testMediaEmbedding();
47 void testFdo84043();
48 void testTdf97630();
49 void testSwappedOutImageExport();
50 void testOOoXMLAnimations();
51 void testBnc480256();
52 void testUnknownAttributes();
53 void testTdf80020();
54 void testLinkedGraphicRT();
55 void testImageWithSpecialID();
56 void testTdf62176();
57 void testTransparentBackground();
58 void testEmbeddedPdf();
59 void testEmbeddedText();
60 void testTdf98477();
61 void testAuthorField();
62 void testTdf50499();
63 void testTdf100926();
64 void testPageWithTransparentBackground();
65 void testTextRotation();
66 void testTdf115394PPT();
67 void testBulletsAsImage();
68 void testTdf113818();
69 void testTdf119629();
70 void testTdf123557();
71 void testTdf113822();
72 void testTdf126761();
74 CPPUNIT_TEST_SUITE(SdExportTest);
76 CPPUNIT_TEST(testBackgroundImage);
77 CPPUNIT_TEST(testMediaEmbedding);
78 CPPUNIT_TEST(testFdo84043);
79 CPPUNIT_TEST(testTdf97630);
80 CPPUNIT_TEST(testSwappedOutImageExport);
81 CPPUNIT_TEST(testOOoXMLAnimations);
82 CPPUNIT_TEST(testBnc480256);
83 CPPUNIT_TEST(testUnknownAttributes);
84 CPPUNIT_TEST(testTdf80020);
85 CPPUNIT_TEST(testLinkedGraphicRT);
86 CPPUNIT_TEST(testImageWithSpecialID);
87 CPPUNIT_TEST(testTdf62176);
88 CPPUNIT_TEST(testTransparentBackground);
89 CPPUNIT_TEST(testEmbeddedPdf);
90 CPPUNIT_TEST(testEmbeddedText);
91 CPPUNIT_TEST(testTdf98477);
92 CPPUNIT_TEST(testAuthorField);
93 CPPUNIT_TEST(testTdf50499);
94 CPPUNIT_TEST(testTdf100926);
95 CPPUNIT_TEST(testPageWithTransparentBackground);
96 CPPUNIT_TEST(testTextRotation);
97 CPPUNIT_TEST(testTdf115394PPT);
98 CPPUNIT_TEST(testBulletsAsImage);
99 CPPUNIT_TEST(testTdf113818);
100 CPPUNIT_TEST(testTdf119629);
101 CPPUNIT_TEST(testTdf123557);
102 CPPUNIT_TEST(testTdf113822);
103 CPPUNIT_TEST(testTdf126761);
105 CPPUNIT_TEST_SUITE_END();
107 virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override
109 static const struct { char const * pPrefix; char const * pURI; } namespaces[] =
111 // ODF
112 { "anim", "urn:oasis:names:tc:opendocument:xmlns:animation:1.0" },
113 { "draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" },
114 { "fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" },
115 { "number", "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" },
116 { "office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0" },
117 { "presentation", "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" },
118 { "style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0" },
119 { "svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" },
120 { "table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0" },
121 { "text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0" },
122 { "xlink", "http://www.w3c.org/1999/xlink" },
123 { "loext", "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" },
124 { "smil", "urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" },
125 // user-defined
126 { "foo", "http://example.com/" },
128 for (size_t i = 0; i < SAL_N_ELEMENTS(namespaces); ++i)
130 xmlXPathRegisterNs(pXmlXPathCtx,
131 reinterpret_cast<xmlChar const *>(namespaces[i].pPrefix),
132 reinterpret_cast<xmlChar const *>(namespaces[i].pURI));
138 namespace
140 uno::Reference<awt::XBitmap> getBitmapFromTable(const sd::DrawDocShellRef& xDocShRef,
141 OUString const& rName)
143 uno::Reference<awt::XBitmap> xBitmap;
145 uno::Reference<lang::XMultiServiceFactory> xFactory(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY);
149 uno::Reference<container::XNameAccess> xBitmapTable(xFactory->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY);
150 uno::Any rValue = xBitmapTable->getByName(rName);
151 if (rValue.has<uno::Reference<awt::XBitmap>>())
153 return rValue.get<uno::Reference<awt::XBitmap>>();
156 catch (const uno::Exception & /*rEx*/)
160 return xBitmap;
165 void SdExportTest::testBackgroundImage()
167 // Initial bug: N821567
169 // Check if Slide background image is imported from PPTX and exported to PPTX, PPT and ODP correctly
171 OUString bgImageName;
172 sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/n821567.pptx"), PPTX);
174 // Check that imported background image from PPTX exists
176 uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW);
177 CPPUNIT_ASSERT_EQUAL_MESSAGE("not exactly one page", static_cast<sal_Int32>(1), xDoc->getDrawPages()->getCount());
178 uno::Reference<drawing::XDrawPage> xPage(getPage(0, xDocShRef));
180 uno::Reference<beans::XPropertySet> xPropertySet(xPage, uno::UNO_QUERY);
181 uno::Any aAny = xPropertySet->getPropertyValue("Background");
182 if (aAny.has<uno::Reference<beans::XPropertySet>>())
184 uno::Reference<beans::XPropertySet> xBackgroundPropSet;
185 aAny >>= xBackgroundPropSet;
186 aAny = xBackgroundPropSet->getPropertyValue("FillBitmapName");
187 aAny >>= bgImageName;
189 CPPUNIT_ASSERT_EQUAL_MESSAGE("Slide Background is not imported from PPTX correctly", OUString("msFillBitmap 1"), bgImageName);
191 uno::Reference<awt::XBitmap> xBitmap = getBitmapFromTable(xDocShRef, bgImageName);
192 CPPUNIT_ASSERT_MESSAGE("Slide Background Bitmap is missing when imported from PPTX", xBitmap.is());
195 // Save as PPTX, reload and check again so we make sure exporting to PPTX is working correctly
197 xDocShRef = saveAndReload(xDocShRef.get(), PPTX);
198 uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW);
199 CPPUNIT_ASSERT_EQUAL_MESSAGE("not exactly one page", static_cast<sal_Int32>(1), xDoc->getDrawPages()->getCount());
200 uno::Reference<drawing::XDrawPage> xPage(getPage(0, xDocShRef));
202 uno::Reference<beans::XPropertySet> xPropertySet(xPage, uno::UNO_QUERY);
203 uno::Any aAny = xPropertySet->getPropertyValue("Background");
204 if (aAny.hasValue())
206 uno::Reference<beans::XPropertySet> xBackgroundPropSet;
207 aAny >>= xBackgroundPropSet;
208 aAny = xBackgroundPropSet->getPropertyValue("FillBitmapName");
209 aAny >>= bgImageName;
211 CPPUNIT_ASSERT_EQUAL_MESSAGE("Slide Background is not exported from PPTX correctly", OUString("msFillBitmap 1"), bgImageName);
213 uno::Reference<awt::XBitmap> xBitmap = getBitmapFromTable(xDocShRef, bgImageName);
214 CPPUNIT_ASSERT_MESSAGE("Slide Background Bitmap is missing when exported from PPTX", xBitmap.is());
217 // Save as ODP, reload and check again so we make sure exporting and importing to ODP is working correctly
219 xDocShRef = saveAndReload(xDocShRef.get(), ODP);
220 uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW);
221 CPPUNIT_ASSERT_EQUAL_MESSAGE("not exactly one page", static_cast<sal_Int32>(1), xDoc->getDrawPages()->getCount());
222 uno::Reference<drawing::XDrawPage> xPage(getPage(0, xDocShRef));
224 uno::Reference<beans::XPropertySet> xPropertySet(xPage, uno::UNO_QUERY);
225 uno::Any aAny = xPropertySet->getPropertyValue("Background");
226 if (aAny.hasValue())
228 uno::Reference<beans::XPropertySet> xBackgroundPropSet;
229 aAny >>= xBackgroundPropSet;
230 aAny = xBackgroundPropSet->getPropertyValue("FillBitmapName");
231 aAny >>= bgImageName;
233 CPPUNIT_ASSERT_EQUAL_MESSAGE("Slide Background is not exported or imported from ODP correctly", OUString("msFillBitmap 1"), bgImageName);
235 uno::Reference<awt::XBitmap> xBitmap = getBitmapFromTable(xDocShRef, bgImageName);
236 CPPUNIT_ASSERT_MESSAGE("Slide Background Bitmap is missing when exported or imported from ODP", xBitmap.is());
239 xDocShRef->DoClose();
242 namespace {
244 template< typename ItemValue, typename ItemType >
245 void checkFontAttributes( const SdrTextObj* pObj, ItemValue nVal)
247 CPPUNIT_ASSERT_MESSAGE( "no object", pObj != nullptr);
248 const EditTextObject& aEdit = pObj->GetOutlinerParaObject()->GetTextObject();
249 std::vector<EECharAttrib> rLst;
250 aEdit.GetCharAttribs(0, rLst);
251 for( std::vector<EECharAttrib>::reverse_iterator it = rLst.rbegin(); it!=rLst.rend(); ++it)
253 const ItemType* pAttrib = dynamic_cast<const ItemType *>((*it).pAttr);
254 if (pAttrib)
256 CPPUNIT_ASSERT_EQUAL( nVal, static_cast<ItemValue>(pAttrib->GetValue()));
263 void SdExportTest::testTransparentBackground()
265 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/odp/transparent_background.odp"), ODP);
266 xDocShRef = saveAndReload( xDocShRef.get(), ODP );
268 const SdrPage *pPage = GetPage( 1, xDocShRef );
270 const SdrTextObj *pObj1 = dynamic_cast<SdrTextObj *>( pPage->GetObj( 0 ) );
271 checkFontAttributes<Color, SvxBackgroundColorItem>( pObj1, COL_TRANSPARENT );
273 const SdrTextObj *pObj2 = dynamic_cast<SdrTextObj *>( pPage->GetObj( 1 ) );
274 checkFontAttributes<Color, SvxBackgroundColorItem>( pObj2, COL_YELLOW);
276 xDocShRef->DoClose();
279 void SdExportTest::testMediaEmbedding()
281 if (!OpenGLWrapper::isVCLOpenGLEnabled())
282 return;
284 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/media_embedding.odp"), ODP);
286 const SdrPage *pPage = GetPage( 1, xDocShRef );
288 // Second object is a sound
289 SdrMediaObj *pMediaObj = dynamic_cast<SdrMediaObj*>( pPage->GetObj( 3 ));
290 CPPUNIT_ASSERT_MESSAGE( "missing media object", pMediaObj != nullptr);
291 CPPUNIT_ASSERT_EQUAL( OUString( "vnd.sun.star.Package:Media/button-1.wav" ), pMediaObj->getMediaProperties().getURL());
292 CPPUNIT_ASSERT_EQUAL( OUString( "application/vnd.sun.star.media" ), pMediaObj->getMediaProperties().getMimeType());
294 xDocShRef->DoClose();
297 void SdExportTest::testFdo84043()
299 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/fdo84043.odp"), ODP);
300 xDocShRef = saveAndReload( xDocShRef.get(), ODP );
302 // the bug was duplicate attributes, causing crash in a build with asserts
303 const SdrPage *pPage = GetPage( 1, xDocShRef );
304 SdrObject const* pShape = pPage->GetObj(1);
305 CPPUNIT_ASSERT_MESSAGE("no shape", pShape != nullptr);
307 xDocShRef->DoClose();
310 void SdExportTest::testTdf97630()
312 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/fit-to-size.fodp"), FODP);
315 uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDocShRef->GetModel(), uno::UNO_QUERY);
316 uno::Reference<drawing::XDrawPage> xDP(xDPS->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
318 drawing::TextFitToSizeType tmp;
319 // text shapes
320 uno::Reference<beans::XPropertySet> xShape0(xDP->getByIndex(0), uno::UNO_QUERY);
321 xShape0->getPropertyValue("TextFitToSize") >>= tmp;
322 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_NONE, tmp);
323 uno::Reference<beans::XPropertySet> xShape1(xDP->getByIndex(1), uno::UNO_QUERY);
324 xShape1->getPropertyValue("TextFitToSize") >>= tmp;
325 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_PROPORTIONAL, tmp);
326 uno::Reference<beans::XPropertySet> xShape2(xDP->getByIndex(2), uno::UNO_QUERY);
327 xShape2->getPropertyValue("TextFitToSize") >>= tmp;
328 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_ALLLINES, tmp);
329 uno::Reference<beans::XPropertySet> xShape3(xDP->getByIndex(3), uno::UNO_QUERY);
330 xShape3->getPropertyValue("TextFitToSize") >>= tmp;
331 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_AUTOFIT, tmp);
333 // fontworks
334 uno::Reference<beans::XPropertySet> xShape4(xDP->getByIndex(4), uno::UNO_QUERY);
335 xShape4->getPropertyValue("TextFitToSize") >>= tmp;
336 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_NONE, tmp);
337 uno::Reference<beans::XPropertySet> xShape5(xDP->getByIndex(5), uno::UNO_QUERY);
338 xShape5->getPropertyValue("TextFitToSize") >>= tmp;
339 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_ALLLINES, tmp);
343 utl::TempFile aTempFile;
344 xDocShRef = saveAndReload(xDocShRef.get(), ODP, &aTempFile);
347 uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDocShRef->GetModel(), uno::UNO_QUERY);
348 uno::Reference<drawing::XDrawPage> xDP(xDPS->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
350 drawing::TextFitToSizeType tmp;
351 // text shapes
352 uno::Reference<beans::XPropertySet> xShape0(xDP->getByIndex(0), uno::UNO_QUERY);
353 xShape0->getPropertyValue("TextFitToSize") >>= tmp;
354 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_NONE, tmp);
355 uno::Reference<beans::XPropertySet> xShape1(xDP->getByIndex(1), uno::UNO_QUERY);
356 xShape1->getPropertyValue("TextFitToSize") >>= tmp;
357 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_PROPORTIONAL, tmp);
358 uno::Reference<beans::XPropertySet> xShape2(xDP->getByIndex(2), uno::UNO_QUERY);
359 xShape2->getPropertyValue("TextFitToSize") >>= tmp;
360 #if 1
361 // TODO see TODO in sdpropls.cxx
362 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_ALLLINES, tmp);
363 #else
364 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_PROPORTIONAL, tmp);
365 #endif
366 uno::Reference<beans::XPropertySet> xShape3(xDP->getByIndex(3), uno::UNO_QUERY);
367 xShape3->getPropertyValue("TextFitToSize") >>= tmp;
368 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_AUTOFIT, tmp);
370 // fontworks
371 uno::Reference<beans::XPropertySet> xShape4(xDP->getByIndex(4), uno::UNO_QUERY);
372 xShape4->getPropertyValue("TextFitToSize") >>= tmp;
373 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_NONE, tmp);
374 uno::Reference<beans::XPropertySet> xShape5(xDP->getByIndex(5), uno::UNO_QUERY);
375 xShape5->getPropertyValue("TextFitToSize") >>= tmp;
376 #if 1
377 // TODO see TODO in sdpropls.cxx
378 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_ALLLINES, tmp);
379 #else
380 CPPUNIT_ASSERT_EQUAL(drawing::TextFitToSizeType_PROPORTIONAL, tmp);
381 #endif
384 xmlDocPtr pXmlDoc = parseExport(aTempFile, "content.xml");
385 // text shapes
386 assertXPath(pXmlDoc, "//style:style[@style:family='presentation']/style:graphic-properties[@draw:fit-to-size='false' and @style:shrink-to-fit='false']", 1);
387 #if 1
388 // TODO see TODO in sdpropls.cxx
389 assertXPath(pXmlDoc, "//style:style[@style:family='presentation']/style:graphic-properties[@draw:fit-to-size='true' and @style:shrink-to-fit='false']", 1);
390 assertXPath(pXmlDoc, "//style:style[@style:family='presentation']/style:graphic-properties[@draw:fit-to-size='all' and @style:shrink-to-fit='false']", 1);
391 assertXPath(pXmlDoc, "//style:style[@style:family='presentation']/style:graphic-properties[@draw:fit-to-size='shrink-to-fit' and @style:shrink-to-fit='true']", 1);
392 #else
393 assertXPath(pXmlDoc, "//style:style[@style:family='presentation']/style:graphic-properties[@draw:fit-to-size='true' and @style:shrink-to-fit='false']", 2);
394 assertXPath(pXmlDoc, "//style:style[@style:family='presentation']/style:graphic-properties[@draw:fit-to-size='false' and @style:shrink-to-fit='true']", 1);
395 #endif
396 // fontworks
397 assertXPath(pXmlDoc, "//style:style[@style:family='graphic']/style:graphic-properties[@draw:fit-to-size='false' and @style:shrink-to-fit='false']", 1);
398 #if 1
399 // TODO see TODO in sdpropls.cxx
400 assertXPath(pXmlDoc, "//style:style[@style:family='graphic']/style:graphic-properties[@draw:fit-to-size='all' and @style:shrink-to-fit='false']", 1);
401 #else
402 assertXPath(pXmlDoc, "//style:style[@style:family='graphic']/style:graphic-properties[@draw:fit-to-size='true' and @style:shrink-to-fit='false']", 1);
403 #endif
405 xDocShRef->DoClose();
408 void SdExportTest::testSwappedOutImageExport()
410 // Problem was with the swapped out images, which were not swapped in during export.
411 const sal_Int32 vFormats[] = {
412 ODP,
413 PPT,
414 PPTX,
417 // Set cache size to a very small value to make sure one of the images is swapped out
418 std::shared_ptr< comphelper::ConfigurationChanges > xBatch(comphelper::ConfigurationChanges::create());
419 officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(sal_Int32(1), xBatch);
420 xBatch->commit();
422 for( size_t nExportFormat = 0; nExportFormat < SAL_N_ELEMENTS(vFormats); ++nExportFormat )
424 // Load the original file with one image
425 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/odp/document_with_two_images.odp"), ODP);
426 const OString sFailedMessage = OStringLiteral("Failed on filter: ") + aFileFormats[vFormats[nExportFormat]].pFilterName;
428 // Export the document and import again for a check
429 uno::Reference< lang::XComponent > xComponent = xDocShRef->GetModel();
430 uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY);
431 utl::MediaDescriptor aMediaDescriptor;
432 aMediaDescriptor["FilterName"] <<= OStringToOUString(OString(aFileFormats[vFormats[nExportFormat]].pFilterName), RTL_TEXTENCODING_UTF8);
434 utl::TempFile aTempFile;
435 aTempFile.EnableKillingFile();
436 xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
437 xComponent.set(xStorable, uno::UNO_QUERY);
438 xComponent->dispose();
439 xDocShRef = loadURL(aTempFile.GetURL(), nExportFormat);
441 // Check whether graphic exported well after it was swapped out
442 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xDocShRef->GetModel(), uno::UNO_QUERY);
443 CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), static_cast<sal_Int32>(2), xDrawPagesSupplier->getDrawPages()->getCount());
444 uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW );
446 uno::Reference<drawing::XShape> xImage(xDrawPage->getByIndex(2), uno::UNO_QUERY);
447 uno::Reference< beans::XPropertySet > XPropSet( xImage, uno::UNO_QUERY_THROW );
449 // Check Graphic, Size
451 uno::Reference<graphic::XGraphic> xGraphic;
452 XPropSet->getPropertyValue("Graphic") >>= xGraphic;
453 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
454 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic->getType() != graphic::GraphicType::EMPTY);
455 uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
456 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
457 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(610), xBitmap->getSize().Width );
458 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(381), xBitmap->getSize().Height );
461 // Second Image
462 xDrawPage.set(xDrawPagesSupplier->getDrawPages()->getByIndex(1), uno::UNO_QUERY_THROW );
463 xImage.set(xDrawPage->getByIndex(1), uno::UNO_QUERY);
464 XPropSet.set( xImage, uno::UNO_QUERY_THROW );
466 // Check Graphic, Size
468 uno::Reference<graphic::XGraphic> xGraphic;
469 XPropSet->getPropertyValue("Graphic") >>= xGraphic;
470 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
471 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic->getType() != graphic::GraphicType::EMPTY);
472 uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
473 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
474 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(900), xBitmap->getSize().Width );
475 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(600), xBitmap->getSize().Height );
477 xDocShRef->DoClose();
481 void SdExportTest::testOOoXMLAnimations()
483 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/sxi/ooo41061-1.sxi"), SXI);
485 uno::Reference<lang::XComponent> xComponent = xDocShRef->GetModel();
486 uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY);
487 utl::MediaDescriptor aMediaDescriptor;
488 aMediaDescriptor["FilterName"] <<= OStringToOUString(OString(getFormat(ODP)->pFilterName), RTL_TEXTENCODING_UTF8);
489 utl::TempFile aTempFile;
490 aTempFile.EnableKillingFile();
491 xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
493 xDocShRef->DoClose();
495 // the problem was that legacy OOoXML animations were lost if store
496 // immediately follows load because they were "converted" async by a timer
497 xmlDocPtr pXmlDoc = parseExport(aTempFile, "content.xml");
498 assertXPath(pXmlDoc, "//anim:par[@presentation:node-type='timing-root']", 26);
499 // currently getting 52 of these without the fix (depends on timing)
500 assertXPath(pXmlDoc, "//anim:par", 223);
503 void SdExportTest::testBnc480256()
505 sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/bnc480256.pptx"), PPTX);
506 // In the document, there are two tables with table background properties.
507 // Make sure colors are set properly for individual cells.
509 // TODO: If you are working on improving table background support, expect
510 // this unit test to fail. In that case, feel free to change the numbers.
512 const SdrPage *pPage = GetPage( 1, xDocShRef );
514 sdr::table::SdrTableObj *pTableObj;
515 uno::Reference< table::XCellRange > xTable;
516 uno::Reference< beans::XPropertySet > xCell;
517 sal_Int32 nColor;
518 table::BorderLine2 aBorderLine;
520 pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(pPage->GetObj(0));
521 CPPUNIT_ASSERT( pTableObj );
522 xTable.set(pTableObj->getTable(), uno::UNO_QUERY_THROW);
524 xCell.set(xTable->getCellByPosition(0, 0), uno::UNO_QUERY_THROW);
525 xCell->getPropertyValue("FillColor") >>= nColor;
526 CPPUNIT_ASSERT_EQUAL(sal_Int32(10208238), nColor);
527 xCell->getPropertyValue("LeftBorder") >>= aBorderLine;
528 CPPUNIT_ASSERT_EQUAL(util::Color(5609427), aBorderLine.Color);
530 xCell.set(xTable->getCellByPosition(0, 1), uno::UNO_QUERY_THROW);
531 xCell->getPropertyValue("FillColor") >>= nColor;
532 CPPUNIT_ASSERT_EQUAL(sal_Int32(13032959), nColor);
533 xCell->getPropertyValue("TopBorder") >>= aBorderLine;
534 CPPUNIT_ASSERT_EQUAL(util::Color(5609427), aBorderLine.Color);
536 pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(pPage->GetObj(1));
537 CPPUNIT_ASSERT( pTableObj );
538 xTable.set(pTableObj->getTable(), uno::UNO_QUERY_THROW);
540 xCell.set(xTable->getCellByPosition(0, 0), uno::UNO_QUERY_THROW);
541 xCell->getPropertyValue("FillColor") >>= nColor;
542 CPPUNIT_ASSERT_EQUAL(sal_Int32(7056614), nColor);
543 xCell->getPropertyValue("LeftBorder") >>= aBorderLine;
544 CPPUNIT_ASSERT_EQUAL(util::Color(12505062), aBorderLine.Color);
546 xCell.set(xTable->getCellByPosition(0, 1), uno::UNO_QUERY_THROW);
547 xCell->getPropertyValue("FillColor") >>= nColor;
548 CPPUNIT_ASSERT_EQUAL(sal_Int32(4626400), nColor);
550 xCell.set(xTable->getCellByPosition(1, 0), uno::UNO_QUERY_THROW);
551 xCell->getPropertyValue("BottomBorder") >>= aBorderLine;
552 CPPUNIT_ASSERT_EQUAL(util::Color(COL_AUTO), aBorderLine.Color);
554 xDocShRef->DoClose();
557 void SdExportTest::testUnknownAttributes()
559 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/unknown-attribute.fodp"), FODP);
561 uno::Reference<lang::XComponent> xComponent = xDocShRef->GetModel();
562 uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY);
563 utl::MediaDescriptor aMediaDescriptor;
564 aMediaDescriptor["FilterName"] <<= OStringToOUString(OString(getFormat(ODP)->pFilterName), RTL_TEXTENCODING_UTF8);
565 utl::TempFile aTempFile;
566 aTempFile.EnableKillingFile();
567 xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
569 xDocShRef->DoClose();
571 xmlDocPtr pXmlDoc = parseExport(aTempFile, "content.xml");
572 assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:name='gr1']/style:graphic-properties[@foo:non-existent-att='bar']");
573 // TODO: if the namespace is *known*, the attribute is not preserved, but that seems to be a pre-existing problem, or maybe it's even intentional?
574 // assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:name='gr1']/style:graphic-properties[@svg:non-existent-att='blah']");
575 // this was on style:graphic-properties on the import, but the export moves it to root node which is OK
576 assertXPathNSDef(pXmlDoc, "/office:document-content", "foo", "http://example.com/");
579 void SdExportTest::testTdf80020()
581 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/odp/tdf80020.odp"), ODP);
583 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xDocShRef->GetModel(), uno::UNO_QUERY);
584 uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
585 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("graphics"), uno::UNO_QUERY);
586 uno::Reference<style::XStyle> xStyle(xStyleFamily->getByName("Test Style"), uno::UNO_QUERY);
587 CPPUNIT_ASSERT_EQUAL(OUString("text"), xStyle->getParentStyle());
588 xDocShRef = saveAndReload( xDocShRef.get(), ODP );
590 uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(xDocShRef->GetModel(), uno::UNO_QUERY);
591 uno::Reference<container::XNameAccess> xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies();
592 uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("graphics"), uno::UNO_QUERY);
593 uno::Reference<style::XStyle> xStyle(xStyleFamily->getByName("Test Style"), uno::UNO_QUERY);
594 CPPUNIT_ASSERT_EQUAL(OUString("text"), xStyle->getParentStyle());
596 xDocShRef->DoClose();
599 void SdExportTest::testLinkedGraphicRT()
601 // Problem was with linked images
602 const sal_Int32 vFormats[] = {
603 ODP,
604 PPT,
605 // PPTX, -> this fails now, need a fix
608 for( size_t nExportFormat = 0; nExportFormat < SAL_N_ELEMENTS(vFormats); ++nExportFormat )
610 // Load the original file with one image
611 sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/odp/document_with_linked_graphic.odp"), ODP);
613 // Export the document and import again for a check
614 uno::Reference< lang::XComponent > xComponent = xDocShRef->GetModel();
615 uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY);
616 utl::MediaDescriptor aMediaDescriptor;
617 aMediaDescriptor["FilterName"] <<= OStringToOUString(OString(aFileFormats[vFormats[nExportFormat]].pFilterName), RTL_TEXTENCODING_UTF8);
619 // Check if the graphic has been imported correctly (before doing the export/import run)
621 const OString sFailedImportMessage = "Failed to correctly import the document";
622 SdDrawDocument* pDoc = xDocShRef->GetDoc();
623 CPPUNIT_ASSERT_MESSAGE(sFailedImportMessage.getStr(), pDoc != nullptr);
624 const SdrPage* pPage = pDoc->GetPage(1);
625 CPPUNIT_ASSERT_MESSAGE(sFailedImportMessage.getStr(), pPage != nullptr);
626 SdrGrafObj* pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(2));
627 CPPUNIT_ASSERT_MESSAGE(sFailedImportMessage.getStr(), pObject != nullptr );
628 CPPUNIT_ASSERT_MESSAGE(sFailedImportMessage.getStr(), pObject->IsLinkedGraphic() );
630 const GraphicObject& rGraphicObj = pObject->GetGraphicObject(true);
631 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedImportMessage.getStr(), int(GraphicType::Bitmap), int(rGraphicObj.GetGraphic().GetType()));
632 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedImportMessage.getStr(), sal_uLong(864900), rGraphicObj.GetGraphic().GetSizeBytes());
635 // Save and reload
636 utl::TempFile aTempFile;
637 aTempFile.EnableKillingFile();
638 xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
639 xComponent.set(xStorable, uno::UNO_QUERY);
640 xComponent->dispose();
641 xDocShRef = loadURL(aTempFile.GetURL(), nExportFormat);
643 // Check whether graphic imported well after export
645 const OString sFailedMessage = OStringLiteral("Failed on filter: ") + aFileFormats[vFormats[nExportFormat]].pFilterName;
647 SdDrawDocument *pDoc = xDocShRef->GetDoc();
648 CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pDoc != nullptr );
649 const SdrPage *pPage = pDoc->GetPage(1);
650 CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pPage != nullptr );
651 SdrGrafObj* pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(2));
652 CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pObject != nullptr );
653 CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pObject->IsLinkedGraphic() );
655 const GraphicObject& rGraphicObj = pObject->GetGraphicObject(true);
656 CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), int(GraphicType::Bitmap), int(rGraphicObj.GetGraphic().GetType()));
657 CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), sal_uLong(864900), rGraphicObj.GetGraphic().GetSizeBytes());
660 xDocShRef->DoClose();
664 void SdExportTest::testImageWithSpecialID()
666 // Check how LO handles when the imported graphic's ID is different from that one
667 // which is generated by LO.
668 const sal_Int32 vFormats[] = {
669 ODP,
670 PPT,
671 PPTX,
674 // Trigger swap out mechanism to test swapped state factor too.
675 std::shared_ptr< comphelper::ConfigurationChanges > batch(comphelper::ConfigurationChanges::create());
676 officecfg::Office::Common::Cache::GraphicManager::TotalCacheSize::set(sal_Int32(1), batch);
677 batch->commit();
679 for( size_t nExportFormat = 0; nExportFormat < SAL_N_ELEMENTS(vFormats); ++nExportFormat )
681 // Load the original file
682 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/odp/images_with_special_IDs.odp"), ODP);
683 const OString sFailedMessage = OStringLiteral("Failed on filter: ") + aFileFormats[vFormats[nExportFormat]].pFilterName;
685 // Export the document and import again for a check
686 uno::Reference< lang::XComponent > xComponent = xDocShRef->GetModel();
687 uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY);
688 utl::MediaDescriptor aMediaDescriptor;
689 aMediaDescriptor["FilterName"] <<= OStringToOUString(OString(aFileFormats[vFormats[nExportFormat]].pFilterName), RTL_TEXTENCODING_UTF8);
691 utl::TempFile aTempFile;
692 aTempFile.EnableKillingFile();
693 xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
694 xComponent.set(xStorable, uno::UNO_QUERY);
695 xComponent->dispose();
696 xDocShRef = loadURL(aTempFile.GetURL(), nExportFormat);
698 // Check whether graphic was exported well
699 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xDocShRef->GetModel(), uno::UNO_QUERY);
700 CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), static_cast<sal_Int32>(2), xDrawPagesSupplier->getDrawPages()->getCount() );
701 uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW );
703 uno::Reference<drawing::XShape> xImage(xDrawPage->getByIndex(2), uno::UNO_QUERY);
704 uno::Reference< beans::XPropertySet > XPropSet( xImage, uno::UNO_QUERY_THROW );
706 // Check Graphic, Size
708 uno::Reference<graphic::XGraphic> xGraphic;
709 XPropSet->getPropertyValue("Graphic") >>= xGraphic;
710 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
711 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic->getType() != graphic::GraphicType::EMPTY);
712 uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
713 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
714 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(610), xBitmap->getSize().Width );
715 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(381), xBitmap->getSize().Height );
718 // Second Image
719 xDrawPage.set(xDrawPagesSupplier->getDrawPages()->getByIndex(1), uno::UNO_QUERY_THROW );
720 xImage.set(xDrawPage->getByIndex(1), uno::UNO_QUERY);
721 XPropSet.set( xImage, uno::UNO_QUERY_THROW );
723 // Check Graphic, Size
725 uno::Reference<graphic::XGraphic> xGraphic;
726 XPropSet->getPropertyValue("Graphic") >>= xGraphic;
727 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
728 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic->getType() != graphic::GraphicType::EMPTY);
729 uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
730 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
731 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(900), xBitmap->getSize().Width );
732 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(600), xBitmap->getSize().Height );
734 xDocShRef->DoClose();
738 void SdExportTest::testTdf62176()
740 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/odp/Tdf62176.odp"), ODP);
741 uno::Reference<drawing::XDrawPage> xPage( getPage( 0, xDocShRef ) );
743 //there should be only *one* shape
744 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xPage->getCount());
746 uno::Reference<beans::XPropertySet> xShape( getShape( 0, xPage ) );
747 //checking Paragraph's Left Margin with expected value
748 sal_Int32 nParaLeftMargin = 0;
749 xShape->getPropertyValue("ParaLeftMargin") >>= nParaLeftMargin;
750 CPPUNIT_ASSERT_EQUAL(sal_Int32(2000), nParaLeftMargin);
751 //checking Paragraph's First Line Indent with expected value
752 sal_Int32 nParaFirstLineIndent = 0;
753 xShape->getPropertyValue("ParaFirstLineIndent") >>= nParaFirstLineIndent;
754 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1300), nParaFirstLineIndent);
756 //Checking the *Text* in TextBox
757 uno::Reference<text::XTextRange> xParagraph( getParagraphFromShape( 0, xShape ) );
758 CPPUNIT_ASSERT_EQUAL(OUString("Hello World"), xParagraph->getString());
760 //Saving and Reloading the file
761 xDocShRef = saveAndReload( xDocShRef.get(), ODP );
762 uno::Reference<drawing::XDrawPage> xPage2( getPage(0, xDocShRef ) );
763 //there should be only *one* shape
764 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xPage2->getCount());
766 uno::Reference<beans::XPropertySet> xShape2( getShape( 0, xPage2 ) );
767 //checking Paragraph's Left Margin with expected value
768 sal_Int32 nParaLeftMargin2 = 0;
769 xShape2->getPropertyValue("ParaLeftMargin") >>= nParaLeftMargin2;
770 CPPUNIT_ASSERT_EQUAL(sal_Int32(2000), nParaLeftMargin2);
771 //checking Paragraph's First Line Indent with expected value
772 sal_Int32 nParaFirstLineIndent2 = 0;
773 xShape2->getPropertyValue("ParaFirstLineIndent") >>= nParaFirstLineIndent2;
774 CPPUNIT_ASSERT_EQUAL(sal_Int32(-1300), nParaFirstLineIndent2);
776 //Checking the *Text* in TextBox
777 uno::Reference<text::XTextRange> xParagraph2( getParagraphFromShape( 0, xShape2 ) );
778 CPPUNIT_ASSERT_EQUAL(OUString("Hello World"), xParagraph2->getString());
780 xDocShRef->DoClose();
783 void SdExportTest::testEmbeddedPdf()
785 #if HAVE_FEATURE_PDFIUM
786 sd::DrawDocShellRef xShell = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/odp/embedded-pdf.odp"), ODP);
787 xShell = saveAndReload( xShell.get(), ODP );
788 uno::Reference<drawing::XDrawPage> xPage = getPage(0, xShell);
789 uno::Reference<beans::XPropertySet> xShape(xPage->getByIndex(0), uno::UNO_QUERY);
790 uno::Reference<graphic::XGraphic> xGraphic;
791 xShape->getPropertyValue("ReplacementGraphic") >>= xGraphic;
792 CPPUNIT_ASSERT(xGraphic.is());
793 xShell->DoClose();
794 #endif
797 void SdExportTest::testEmbeddedText()
799 sd::DrawDocShellRef xShell = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/objectwithtext.fodg"), FODG);
800 xShell = saveAndReload( xShell.get(), ODG );
802 uno::Reference<drawing::XDrawPage> xPage = getPage(0, xShell);
803 uno::Reference<beans::XPropertySet> xShape(xPage->getByIndex(0), uno::UNO_QUERY);
804 uno::Reference<text::XText> xText(xShape, uno::UNO_QUERY);
805 CPPUNIT_ASSERT(xText.is());
807 uno::Reference<container::XEnumerationAccess> xEA(xShape, uno::UNO_QUERY);
808 CPPUNIT_ASSERT(xEA->hasElements());
809 uno::Reference<container::XEnumeration> xEnum(xEA->createEnumeration());
810 uno::Reference<text::XTextContent> xTC;
811 xEnum->nextElement() >>= xTC;
812 CPPUNIT_ASSERT(xTC.is());
814 uno::Reference<container::XEnumerationAccess> xParaEA(xTC, uno::UNO_QUERY);
815 uno::Reference<container::XEnumeration> xParaEnum(xParaEA->createEnumeration());
816 uno::Reference<beans::XPropertySet> xPortion(xParaEnum->nextElement(), uno::UNO_QUERY);
817 CPPUNIT_ASSERT(xPortion.is());
818 uno::Reference<text::XTextRange> xRange(xPortion, uno::UNO_QUERY);
819 OUString type;
820 xPortion->getPropertyValue("TextPortionType") >>= type;
821 CPPUNIT_ASSERT_EQUAL(OUString("Text"), type);
822 CPPUNIT_ASSERT_EQUAL(OUString("foobar"), xRange->getString()); //tdf#112547
824 xShell->DoClose();
827 void SdExportTest::testTdf98477()
829 utl::TempFile tempFile;
830 sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/tdf98477grow.pptx"), PPTX);
832 xDocShRef = saveAndReload(xDocShRef.get(), ODP, &tempFile);
834 xmlDocPtr pXmlDoc = parseExport(tempFile, "content.xml");
835 assertXPath(pXmlDoc, "//anim:animateTransform", "by", "0.5,0.5");
836 xDocShRef->DoClose();
839 void SdExportTest::testAuthorField()
841 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/odp/author_fixed.odp"), ODP);
843 xDocShRef = saveAndReload( xDocShRef.get(), ODP );
845 uno::Reference< text::XTextField > xField = getTextFieldFromPage(0, 0, 0, 0, xDocShRef);
846 CPPUNIT_ASSERT_MESSAGE("Where is the text field?", xField.is() );
848 uno::Reference< beans::XPropertySet > xPropSet( xField, uno::UNO_QUERY_THROW );
849 bool bFixed = false;
850 xPropSet->getPropertyValue("IsFixed") >>= bFixed;
851 CPPUNIT_ASSERT_MESSAGE("Author field is not fixed", bFixed);
853 xDocShRef->DoClose();
856 void SdExportTest::testTdf50499()
858 utl::TempFile tempFile;
859 sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/tdf50499.pptx"), PPTX);
861 xDocShRef = saveAndReload(xDocShRef.get(), ODP, &tempFile);
863 xmlDocPtr pXmlDoc = parseExport(tempFile, "content.xml");
864 assertXPath(pXmlDoc, "//anim:animate[1]", "from", "(-width/2)");
865 assertXPath(pXmlDoc, "//anim:animate[1]", "to", "(x)");
866 assertXPath(pXmlDoc, "//anim:animate[3]", "by", "(height/3+width*0.1)");
868 xDocShRef->DoClose();
871 void SdExportTest::testTdf100926()
873 sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/tdf100926_ODP.pptx"), PPTX);
875 xDocShRef = saveAndReload(xDocShRef.get(), ODP);
877 const SdrPage* pPage = GetPage(1, xDocShRef);
878 CPPUNIT_ASSERT(pPage != nullptr);
880 sdr::table::SdrTableObj *pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(pPage->GetObj(0));
881 CPPUNIT_ASSERT(pTableObj != nullptr);
882 uno::Reference< table::XCellRange > xTable(pTableObj->getTable(), uno::UNO_QUERY_THROW);
884 sal_Int32 nRotation = 0;
885 uno::Reference< beans::XPropertySet > xCell(xTable->getCellByPosition(0, 0), uno::UNO_QUERY_THROW);
886 xCell->getPropertyValue("RotateAngle") >>= nRotation;
887 CPPUNIT_ASSERT_EQUAL(sal_Int32(27000), nRotation);
889 xCell.set(xTable->getCellByPosition(1, 0), uno::UNO_QUERY_THROW);
890 xCell->getPropertyValue("RotateAngle") >>= nRotation;
891 CPPUNIT_ASSERT_EQUAL(sal_Int32(9000), nRotation);
893 xCell.set(xTable->getCellByPosition(2, 0), uno::UNO_QUERY_THROW);
894 xCell->getPropertyValue("RotateAngle") >>= nRotation;
895 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nRotation);
897 xDocShRef->DoClose();
900 void SdExportTest::testPageWithTransparentBackground()
902 ::sd::DrawDocShellRef xDocShRef = loadURL( m_directories.getURLFromSrc("/sd/qa/unit/data/odp/page_transparent_background.odp"), ODP );
904 xDocShRef = saveAndReload( xDocShRef.get(), ODP );
905 uno::Reference< drawing::XDrawPagesSupplier > xDoc(
906 xDocShRef->GetDoc()->getUnoModel(), uno::UNO_QUERY_THROW );
907 CPPUNIT_ASSERT_EQUAL_MESSAGE( "There should be exactly one page", static_cast<sal_Int32>(1), xDoc->getDrawPages()->getCount() );
909 uno::Reference< drawing::XDrawPage > xPage( getPage( 0, xDocShRef ) );
911 uno::Reference< beans::XPropertySet > xPropSet( xPage, uno::UNO_QUERY );
912 uno::Any aAny = xPropSet->getPropertyValue( "Background" );
913 CPPUNIT_ASSERT_MESSAGE("Slide background is missing", aAny.hasValue());
915 uno::Reference< beans::XPropertySet > aXBackgroundPropSet;
916 aAny >>= aXBackgroundPropSet;
917 sal_Int32 nTransparence;
918 aAny = aXBackgroundPropSet->getPropertyValue( "FillTransparence" );
919 aAny >>= nTransparence;
920 CPPUNIT_ASSERT_EQUAL_MESSAGE("Slide background transparency is wrong", sal_Int32(42), nTransparence);
922 xDocShRef->DoClose();
925 void SdExportTest::testTextRotation()
927 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/shape-text-rotate.pptx"), PPTX);
928 utl::TempFile tempFile;
929 xDocShRef = saveAndReload(xDocShRef.get(), ODP, &tempFile);
931 uno::Reference<drawing::XDrawPage> xPage(getPage(0, xDocShRef));
932 uno::Reference<beans::XPropertySet> xPropSet(getShape(0, xPage));
934 CPPUNIT_ASSERT(xPropSet.is());
936 auto aGeomPropSeq = xPropSet->getPropertyValue("CustomShapeGeometry").get<uno::Sequence<beans::PropertyValue>>();
937 comphelper::SequenceAsHashMap aCustomShapeGeometry(aGeomPropSeq);
939 auto it = aCustomShapeGeometry.find("TextRotateAngle");
940 CPPUNIT_ASSERT(it != aCustomShapeGeometry.end());
942 CPPUNIT_ASSERT_EQUAL(double(-90), aCustomShapeGeometry["TextRotateAngle"].get<double>());
944 xDocShRef->DoClose();
947 void SdExportTest::testTdf115394PPT()
949 sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/ppt/tdf115394.ppt"), PPT);
951 // Export the document and import again for a check
952 uno::Reference< lang::XComponent > xComponent = xDocShRef->GetModel();
953 uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY);
954 utl::MediaDescriptor aMediaDescriptor;
955 aMediaDescriptor["FilterName"] <<= OStringToOUString(OString(aFileFormats[PPT].pFilterName), RTL_TEXTENCODING_UTF8);
957 utl::TempFile aTempFile;
958 aTempFile.EnableKillingFile();
959 xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
960 xComponent.set(xStorable, uno::UNO_QUERY);
961 xComponent->dispose();
962 xDocShRef = loadURL(aTempFile.GetURL(), PPT);
964 double fTransitionDuration;
966 // Fast
967 SdPage* pPage1 = xDocShRef->GetDoc()->GetSdPage(0, PageKind::Standard);
968 fTransitionDuration = pPage1->getTransitionDuration();
969 CPPUNIT_ASSERT_EQUAL(0.5, fTransitionDuration);
971 // Medium
972 SdPage* pPage2 = xDocShRef->GetDoc()->GetSdPage(1, PageKind::Standard);
973 fTransitionDuration = pPage2->getTransitionDuration();
974 CPPUNIT_ASSERT_EQUAL(0.75, fTransitionDuration);
976 // Slow
977 SdPage* pPage3 = xDocShRef->GetDoc()->GetSdPage(2, PageKind::Standard);
978 fTransitionDuration = pPage3->getTransitionDuration();
979 CPPUNIT_ASSERT_EQUAL(1.0, fTransitionDuration);
981 xDocShRef->DoClose();
984 void SdExportTest::testBulletsAsImage()
986 for (sal_Int32 nExportFormat : {ODP, PPTX, PPT})
988 ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/odp/BulletsAsImage.odp"), ODP);
989 const OString sFailedMessageBase = OStringLiteral("Failed on filter '") + aFileFormats[nExportFormat].pFilterName + "': ";
991 uno::Reference< lang::XComponent > xComponent = xDocShRef->GetModel();
992 uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY);
993 utl::MediaDescriptor aMediaDescriptor;
994 aMediaDescriptor["FilterName"] <<= OStringToOUString(OString(aFileFormats[nExportFormat].pFilterName), RTL_TEXTENCODING_UTF8);
996 utl::TempFile aTempFile;
997 aTempFile.EnableKillingFile();
998 xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
999 xComponent.set(xStorable, uno::UNO_QUERY);
1000 xComponent->dispose();
1002 xDocShRef = loadURL(aTempFile.GetURL(), nExportFormat);
1004 uno::Reference<beans::XPropertySet> xShape(getShapeFromPage(0, 0, xDocShRef));
1005 uno::Reference<text::XTextRange> const xParagraph(getParagraphFromShape(0, xShape));
1006 uno::Reference<beans::XPropertySet> xPropSet(xParagraph, uno::UNO_QUERY_THROW);
1008 uno::Reference<container::XIndexAccess> xLevels(xPropSet->getPropertyValue("NumberingRules"), uno::UNO_QUERY_THROW);
1009 uno::Sequence<beans::PropertyValue> aProperties;
1010 xLevels->getByIndex(0) >>= aProperties; // 1st level
1012 uno::Reference<awt::XBitmap> xBitmap;
1013 awt::Size aSize;
1014 sal_Int16 nNumberingType = -1;
1016 for (beans::PropertyValue const & rProperty : std::as_const(aProperties))
1018 if (rProperty.Name == "NumberingType")
1020 nNumberingType = rProperty.Value.get<sal_Int16>();
1022 else if (rProperty.Name == "GraphicBitmap")
1024 xBitmap = rProperty.Value.get<uno::Reference<awt::XBitmap>>();
1026 else if (rProperty.Name == "GraphicSize")
1028 aSize = rProperty.Value.get<awt::Size>();
1032 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), style::NumberingType::BITMAP, nNumberingType);
1034 // Graphic Bitmap
1035 const OString sFailed = sFailedMessageBase + "No bitmap for the bullets";
1036 CPPUNIT_ASSERT_MESSAGE(sFailed.getStr(), xBitmap.is());
1037 Graphic aGraphic(uno::Reference<graphic::XGraphic>(xBitmap, uno::UNO_QUERY));
1038 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), GraphicType::Bitmap, aGraphic.GetType());
1039 CPPUNIT_ASSERT_MESSAGE(sFailedMessageBase.getStr(), aGraphic.GetSizeBytes() > sal_uLong(0));
1041 if (nExportFormat == ODP || nExportFormat == PPT)
1043 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), 16L, aGraphic.GetSizePixel().Width());
1044 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), 16L, aGraphic.GetSizePixel().Height());
1046 else // FIXME: what happened here
1048 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), 64L, aGraphic.GetSizePixel().Width());
1049 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), 64L, aGraphic.GetSizePixel().Height());
1052 // Graphic Size
1053 if (nExportFormat == ODP)
1055 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), sal_Int32(500), aSize.Width);
1056 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), sal_Int32(500), aSize.Height);
1059 else if (nExportFormat == PPT) // seems like a conversion error
1061 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), sal_Int32(504), aSize.Width);
1062 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), sal_Int32(504), aSize.Height);
1064 else // FIXME: totally wrong
1066 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), sal_Int32(790), aSize.Width);
1067 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), sal_Int32(790), aSize.Height);
1070 xDocShRef->DoClose();
1074 void SdExportTest::testTdf113822()
1076 utl::TempFile tempFile;
1077 sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/tdf113822underline.pptx"), PPTX);
1079 // Was unable to export iterate container (tdf#99213).
1080 xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
1081 // Was unable to import iterate container (tdf#113822).
1082 xDocShRef = saveAndReload(xDocShRef.get(), ODP, &tempFile);
1084 xmlDocPtr pXmlDoc = parseExport(tempFile, "content.xml");
1086 // IterateContainer was created as ParallelTimeContainer before, so
1087 // the iterate type is not set too.
1088 assertXPath(pXmlDoc, "//anim:iterate", "iterate-type", "by-letter");
1089 // The target of the child animation nodes need to be in the iterate container.
1090 assertXPath(pXmlDoc, "//anim:iterate", "targetElement", "id1");
1091 assertXPath(pXmlDoc, "//anim:iterate/anim:set", "attributeName", "text-underline");
1092 assertXPath(pXmlDoc, "//anim:iterate/anim:set", "to", "solid");
1094 xDocShRef->DoClose();
1097 void SdExportTest::testTdf113818()
1099 utl::TempFile tempFile;
1100 sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/tdf113818-swivel.pptx"), PPTX);
1101 xDocShRef = saveAndReload(xDocShRef.get(), PPT);
1102 xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
1103 xDocShRef = saveAndReload(xDocShRef.get(), ODP, &tempFile);
1105 xmlDocPtr pXmlDoc = parseExport(tempFile, "content.xml");
1106 assertXPath(pXmlDoc, "//anim:animate[1]", "formula", "width*sin(2.5*pi*$)");
1107 assertXPath(pXmlDoc, "//anim:animate[1]", "values", "0;1");
1108 xDocShRef->DoClose();
1111 void SdExportTest::testTdf119629()
1113 utl::TempFile tempFile;
1114 sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/ppt/tdf119629.ppt"), PPT);
1115 xDocShRef = saveAndReload(xDocShRef.get(), PPT);
1116 xDocShRef = saveAndReload(xDocShRef.get(), ODP, &tempFile);
1118 xmlDocPtr pXmlDoc = parseExport(tempFile, "content.xml");
1120 // MSO's effect node type Click parallel node, with group node, after group node
1121 // were missing.
1122 assertXPath(pXmlDoc, "//draw:page"
1123 "/anim:par[@presentation:node-type='timing-root']"
1124 "/anim:seq[@presentation:node-type='main-sequence']"
1125 "/anim:par[@presentation:node-type='on-click']"
1126 "/anim:par[@presentation:node-type='with-previous']"
1127 "/anim:par[@presentation:node-type='on-click']"
1128 "/anim:animate[@anim:formula='width*sin(2.5*pi*$)']", 1);
1129 xDocShRef->DoClose();
1132 void SdExportTest::testTdf123557()
1134 utl::TempFile tempFile;
1135 sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/trigger.pptx"), PPTX);
1136 xDocShRef = saveAndReload(xDocShRef.get(), PPTX);
1137 xDocShRef = saveAndReload(xDocShRef.get(), ODP, &tempFile);
1138 xmlDocPtr pXmlDoc = parseExport(tempFile, "content.xml");
1140 // Contains 2 interactive sequences and 3 triggered effects.
1141 assertXPath(pXmlDoc, "//draw:page", 1);
1142 assertXPath(pXmlDoc, "//draw:page/anim:par", 1);
1143 assertXPath(pXmlDoc, "//draw:page"
1144 "/anim:par[@presentation:node-type='timing-root']"
1145 "/anim:seq[@presentation:node-type='interactive-sequence']", 2);
1146 assertXPath(pXmlDoc, "//draw:page"
1147 "/anim:par[@presentation:node-type='timing-root']"
1148 "/anim:seq[@presentation:node-type='interactive-sequence']"
1149 "/anim:par[@smil:begin]",3);
1150 xDocShRef->DoClose();
1153 void SdExportTest::testTdf126761()
1155 sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/ppt/tdf126761.ppt"), PPT);
1156 xDocShRef = saveAndReload( xDocShRef.get(), ODP );
1157 uno::Reference< beans::XPropertySet > xShape( getShapeFromPage( 0, 0, xDocShRef ) );
1159 // Get first paragraph of the text
1160 uno::Reference<text::XTextRange> const xParagraph( getParagraphFromShape( 0, xShape ) );
1162 // Get first run of the paragraph
1163 uno::Reference<text::XTextRange> xRun( getRunFromParagraph (0, xParagraph ) );
1164 uno::Reference< beans::XPropertySet > xPropSet( xRun, uno::UNO_QUERY_THROW );
1166 // Check character underline, to make sure it has been set correctly
1167 sal_uInt32 nCharUnderline;
1168 xPropSet->getPropertyValue( "CharUnderline" ) >>= nCharUnderline;
1169 CPPUNIT_ASSERT_EQUAL( sal_uInt32(1), nCharUnderline );
1171 xDocShRef->DoClose();
1174 CPPUNIT_TEST_SUITE_REGISTRATION(SdExportTest);
1176 CPPUNIT_PLUGIN_IMPLEMENT();
1178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */