From c48f16b7afcad39462b454bdfbdbe412056c2619 Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Tue, 2 Apr 2019 11:32:42 -0400 Subject: sd: unit-test to check that PDF stream is shared among Graphic instances Change-Id: Iebd85e5e60c76e6d0756d15e1fa6107a3fcc837d Reviewed-on: https://gerrit.libreoffice.org/70162 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian --- sd/qa/unit/data/pdf/multipage.pdf | Bin 0 -> 9121 bytes sd/qa/unit/import-tests.cxx | 73 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 sd/qa/unit/data/pdf/multipage.pdf (limited to 'sd') diff --git a/sd/qa/unit/data/pdf/multipage.pdf b/sd/qa/unit/data/pdf/multipage.pdf new file mode 100644 index 000000000000..5cd8b4e4e569 Binary files /dev/null and b/sd/qa/unit/data/pdf/multipage.pdf differ diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx index c8fcc4584be3..327232ef9fa7 100644 --- a/sd/qa/unit/import-tests.cxx +++ b/sd/qa/unit/import-tests.cxx @@ -77,6 +77,7 @@ #include #include #include +#include #include #include #include @@ -132,9 +133,12 @@ public: void testTableBorderLineStyle(); void testBnc862510_6(); void testBnc862510_7(); -#if ENABLE_PDFIMPORT && defined(IMPORT_PDF_ELEMENTS) +#if ENABLE_PDFIMPORT + void testPDFImportShared(); +#if defined(IMPORT_PDF_ELEMENTS) void testPDFImport(); void testPDFImportSkipImages(); +#endif #endif void testBulletSuffix(); void testBnc910045(); @@ -212,9 +216,12 @@ public: CPPUNIT_TEST(testTableBorderLineStyle); CPPUNIT_TEST(testBnc862510_6); CPPUNIT_TEST(testBnc862510_7); -#if ENABLE_PDFIMPORT && defined(IMPORT_PDF_ELEMENTS) +#if ENABLE_PDFIMPORT + CPPUNIT_TEST(testPDFImportShared); +#if defined(IMPORT_PDF_ELEMENTS) CPPUNIT_TEST(testPDFImport); CPPUNIT_TEST(testPDFImportSkipImages); +#endif #endif CPPUNIT_TEST(testBulletSuffix); CPPUNIT_TEST(testBnc910045); @@ -1134,7 +1141,66 @@ void SdImportTest::testBnc862510_7() xDocShRef->DoClose(); } -#if ENABLE_PDFIMPORT && defined(IMPORT_PDF_ELEMENTS) +#if ENABLE_PDFIMPORT + +void SdImportTest::testPDFImportShared() +{ + comphelper::LibreOfficeKit::setActive(); + sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pdf/multipage.pdf"), PDF); + SdDrawDocument *pDoc = xDocShRef->GetDoc(); + CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != nullptr ); + + // This test is to verify that we share the PDF stream linked to each + // Graphic instance in the imported document. + // Since we import PDFs as images, we support attaching the original + // PDF with each image to allow for advanced editing. + // Here we iterate over all Graphic instances embedded in the pages + // and verify that they all point to the same object in memory. + std::vector>> aPdfSeqSharedPtrs; + std::vector> aGfxLinkSharedPtrs; + + for (int nPageIndex = 0; nPageIndex < pDoc->GetPageCount(); ++nPageIndex) + { + const SdrPage* pPage = GetPage(nPageIndex, xDocShRef); + if (pPage == nullptr) + break; + + for (size_t nObjIndex = 0; nObjIndex < pPage->GetObjCount(); ++nObjIndex) + { + SdrObject* pObject = pPage->GetObj(nObjIndex); + if (pObject == nullptr) + continue; + + SdrGrafObj* pSdrGrafObj = dynamic_cast(pObject); + if (pSdrGrafObj == nullptr) + continue; + + const GraphicObject& rGraphicObject = pSdrGrafObj->GetGraphicObject().GetGraphic(); + const Graphic& rGraphic = rGraphicObject.GetGraphic(); + aPdfSeqSharedPtrs.push_back(rGraphic.getPdfData()); + aGfxLinkSharedPtrs.push_back(rGraphic.GetSharedLink()); + } + } + + CPPUNIT_ASSERT_MESSAGE("Expected more than one page.", aPdfSeqSharedPtrs.size() > 1); + CPPUNIT_ASSERT_MESSAGE("Expected as many PDF streams as GfxLinks.", + aPdfSeqSharedPtrs.size() == aGfxLinkSharedPtrs.size()); + + const std::shared_ptr> pPdfSeq = aPdfSeqSharedPtrs[0]; + const std::shared_ptr pGfxLink = aGfxLinkSharedPtrs[0]; + for (size_t i = 0; i < aPdfSeqSharedPtrs.size(); ++i) + { + CPPUNIT_ASSERT_MESSAGE("Expected all PDF streams to be identical.", + aPdfSeqSharedPtrs[i].get() == pPdfSeq.get()); + CPPUNIT_ASSERT_MESSAGE("Expected all GfxLinks to be identical.", + aGfxLinkSharedPtrs[i].get() == pGfxLink.get()); + } + + xDocShRef->DoClose(); + comphelper::LibreOfficeKit::setActive(false); +} + +#if defined(IMPORT_PDF_ELEMENTS) void SdImportTest::testPDFImport() { @@ -1172,6 +1238,7 @@ void SdImportTest::testPDFImportSkipImages() xDocShRef->DoClose(); } +#endif #endif void SdImportTest::testBulletSuffix() -- cgit v1.2.3