sd: move png export tests to their own file

in preparation for a follow-up test for tdf#123973

Change-Id: Iadedff75c42fa24390602a6eb914027157b53029
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128979
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Xisco Fauli
2022-01-31 20:43:36 +01:00
parent 9266bc555f
commit 1a1e9f6b59
4 changed files with 296 additions and 167 deletions
+72
View File
@@ -0,0 +1,72 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#*************************************************************************
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#*************************************************************************
$(eval $(call gb_CppunitTest_CppunitTest,sd_png_export_tests))
$(eval $(call gb_CppunitTest_use_externals,sd_png_export_tests,\
boost_headers \
libxml2 \
))
$(eval $(call gb_CppunitTest_use_common_precompiled_header,sd_png_export_tests))
$(eval $(call gb_CppunitTest_add_exception_objects,sd_png_export_tests, \
sd/qa/unit/PNGExportTests \
))
$(eval $(call gb_CppunitTest_use_libraries,sd_png_export_tests, \
basegfx \
comphelper \
cppu \
cppuhelper \
drawinglayer \
editeng \
for \
forui \
i18nlangtag \
msfilter \
oox \
sal \
salhelper \
sax \
sd \
sfx \
sot \
svl \
svt \
svx \
svxcore \
test \
tl \
tk \
ucbhelper \
unotest \
utl \
vcl \
xo \
))
$(eval $(call gb_CppunitTest_set_include,sd_png_export_tests,\
-I$(SRCDIR)/sd/source/ui/inc \
-I$(SRCDIR)/sd/inc \
$$(INCLUDE) \
))
$(eval $(call gb_CppunitTest_use_sdk_api,sd_png_export_tests))
$(eval $(call gb_CppunitTest_use_ure,sd_png_export_tests))
$(eval $(call gb_CppunitTest_use_vcl,sd_png_export_tests))
$(eval $(call gb_CppunitTest_use_rdb,sd_png_export_tests,services))
$(eval $(call gb_CppunitTest_use_configuration,sd_png_export_tests))
# vim: set noet sw=4 ts=4:
+1
View File
@@ -46,6 +46,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sd,\
CppunitTest_sd_html_export_tests \
CppunitTest_sd_activex_controls_tests \
CppunitTest_sd_pdf_import_test \
CppunitTest_sd_png_export_tests \
CppunitTest_sd_filter_eppt \
))
endif
+223
View File
@@ -0,0 +1,223 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <config_poppler.h>
#include <memory>
#include <ostream>
#include <sdpage.hxx>
#include "sdmodeltestbase.hxx"
#include <com/sun/star/drawing/GraphicExportFilter.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <comphelper/propertyvalue.hxx>
#include <vcl/BitmapReadAccess.hxx>
#include <vcl/filter/PngImageReader.hxx>
class SdPNGExportTest : public SdModelTestBase
{
protected:
uno::Reference<lang::XComponent> mxComponent;
public:
virtual void setUp() override;
virtual void tearDown() override;
};
void SdPNGExportTest::setUp()
{
test::BootstrapFixture::setUp();
mxDesktop.set(frame::Desktop::create(mxComponentContext));
}
void SdPNGExportTest::tearDown()
{
if (mxComponent.is())
mxComponent->dispose();
test::BootstrapFixture::tearDown();
}
CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf113163)
{
mxComponent
= loadFromDesktop(m_directories.getURLFromSrc(u"/sd/qa/unit/data/pptx/tdf113163.pptx"));
uno::Reference<uno::XComponentContext> xContext = getComponentContext();
CPPUNIT_ASSERT(xContext.is());
uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
= drawing::GraphicExportFilter::create(xContext);
uno::Sequence<beans::PropertyValue> aFilterData{
comphelper::makePropertyValue("PixelWidth", sal_Int32(100)),
comphelper::makePropertyValue("PixelHeight", sal_Int32(100))
};
utl::TempFile aTempFile;
aTempFile.EnableKillingFile();
uno::Sequence<beans::PropertyValue> aDescriptor{
comphelper::makePropertyValue("URL", aTempFile.GetURL()),
comphelper::makePropertyValue("FilterName", OUString("PNG")),
comphelper::makePropertyValue("FilterData", aFilterData)
};
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<lang::XComponent> xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
uno::UNO_QUERY);
xGraphicExporter->setSourceDocument(xPage);
xGraphicExporter->filter(aDescriptor);
SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ);
vcl::PngImageReader aPNGReader(aFileStream);
BitmapEx aBMPEx = aPNGReader.read();
// make sure the bitmap is not empty and correct size (PNG export->import was successful)
Size aSize = aBMPEx.GetSizePixel();
CPPUNIT_ASSERT_EQUAL(Size(100, 100), aSize);
Bitmap aBMP = aBMPEx.GetBitmap();
{
Bitmap::ScopedReadAccess pReadAccess(aBMP);
for (tools::Long nX = 1; nX < aSize.Width() - 1; ++nX)
{
for (tools::Long nY = 1; nY < aSize.Height() - 1; ++nY)
{
// Check all pixels in the image are black
// Without the fix in place, this test would have failed with
// - Expected: 0
// - Actual : 16777215
const Color aColor = pReadAccess->GetColor(nX, nY);
CPPUNIT_ASSERT_EQUAL(COL_BLACK, aColor);
}
}
}
}
CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf93124)
{
mxComponent
= loadFromDesktop(m_directories.getURLFromSrc(u"/sd/qa/unit/data/ppt/tdf93124.ppt"));
uno::Reference<uno::XComponentContext> xContext = getComponentContext();
CPPUNIT_ASSERT(xContext.is());
uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
= drawing::GraphicExportFilter::create(xContext);
uno::Sequence<beans::PropertyValue> aFilterData{
comphelper::makePropertyValue("PixelWidth", sal_Int32(320)),
comphelper::makePropertyValue("PixelHeight", sal_Int32(180))
};
utl::TempFile aTempFile;
aTempFile.EnableKillingFile();
uno::Sequence<beans::PropertyValue> aDescriptor{
comphelper::makePropertyValue("URL", aTempFile.GetURL()),
comphelper::makePropertyValue("FilterName", OUString("PNG")),
comphelper::makePropertyValue("FilterData", aFilterData)
};
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<lang::XComponent> xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
uno::UNO_QUERY);
xGraphicExporter->setSourceDocument(xPage);
xGraphicExporter->filter(aDescriptor);
SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ);
vcl::PngImageReader aPNGReader(aFileStream);
BitmapEx aBMPEx = aPNGReader.read();
// make sure the bitmap is not empty and correct size (PNG export->import was successful)
CPPUNIT_ASSERT_EQUAL(Size(320, 180), aBMPEx.GetSizePixel());
Bitmap aBMP = aBMPEx.GetBitmap();
{
Bitmap::ScopedReadAccess pReadAccess(aBMP);
int nNonWhiteCount = 0;
// The word "Top" should be in rectangle 34,4 - 76,30. If text alignment is wrong, the rectangle will be white.
for (tools::Long nY = 4; nY < (4 + 26); ++nY)
{
for (tools::Long nX = 34; nX < (34 + 43); ++nX)
{
const Color aColor = pReadAccess->GetColor(nY, nX);
if ((aColor.GetRed() != 0xff) || (aColor.GetGreen() != 0xff)
|| (aColor.GetBlue() != 0xff))
++nNonWhiteCount;
}
}
CPPUNIT_ASSERT_MESSAGE("Tdf93124: vertical alignment of text is incorrect!",
nNonWhiteCount > 50);
}
}
CPPUNIT_TEST_FIXTURE(SdPNGExportTest, testTdf99729)
{
const OUString filenames[]
= { "/sd/qa/unit/data/odp/tdf99729-new.odp", "/sd/qa/unit/data/odp/tdf99729-legacy.odp" };
int nonwhitecounts[] = { 0, 0 };
for (size_t i = 0; i < SAL_N_ELEMENTS(filenames); ++i)
{
// 1st check for new behaviour - having AnchoredTextOverflowLegacy compatibility flag set to false in settings.xml
mxComponent = loadFromDesktop(m_directories.getURLFromSrc(filenames[i]),
"com.sun.star.presentation.PresentationDocument");
uno::Reference<uno::XComponentContext> xContext = getComponentContext();
CPPUNIT_ASSERT(xContext.is());
uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter
= drawing::GraphicExportFilter::create(xContext);
CPPUNIT_ASSERT(xGraphicExporter.is());
uno::Sequence<beans::PropertyValue> aFilterData{
comphelper::makePropertyValue("PixelWidth", sal_Int32(320)),
comphelper::makePropertyValue("PixelHeight", sal_Int32(240))
};
utl::TempFile aTempFile;
aTempFile.EnableKillingFile();
uno::Sequence<beans::PropertyValue> aDescriptor{
comphelper::makePropertyValue("URL", aTempFile.GetURL()),
comphelper::makePropertyValue("FilterName", OUString("PNG")),
comphelper::makePropertyValue("FilterData", aFilterData)
};
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<lang::XComponent> xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
uno::UNO_QUERY);
CPPUNIT_ASSERT(xPage.is());
xGraphicExporter->setSourceDocument(xPage);
xGraphicExporter->filter(aDescriptor);
SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ);
vcl::PngImageReader aPNGReader(aFileStream);
BitmapEx aBMPEx = aPNGReader.read();
Bitmap aBMP = aBMPEx.GetBitmap();
Bitmap::ScopedReadAccess pRead(aBMP);
for (tools::Long nX = 154; nX < (154 + 12); ++nX)
{
for (tools::Long nY = 16; nY < (16 + 96); ++nY)
{
const Color aColor = pRead->GetColor(nY, nX);
if ((aColor.GetRed() != 0xff) || (aColor.GetGreen() != 0xff)
|| (aColor.GetBlue() != 0xff))
++nonwhitecounts[i];
}
}
mxComponent->dispose();
}
// The numbers 1-9 should be above the Text Box in rectangle 154,16 - 170,112.
// If text alignment is wrong, the rectangle will be white.
CPPUNIT_ASSERT_MESSAGE("Tdf99729: vertical alignment of text is incorrect!",
nonwhitecounts[0] > 100); // it is 134 with cleartype disabled
// The numbers 1-9 should be below the Text Box -> rectangle 154,16 - 170,112 should be white.
CPPUNIT_ASSERT_EQUAL_MESSAGE("Tdf99729: legacy vertical alignment of text is incorrect!", 0,
nonwhitecounts[1]);
}
CPPUNIT_PLUGIN_IMPLEMENT();
-167
View File
@@ -37,7 +37,6 @@
#include <com/sun/star/document/XEventsSupplier.hpp>
#include <com/sun/star/presentation/ClickAction.hpp>
#include <com/sun/star/presentation/XPresentationSupplier.hpp>
#include <com/sun/star/drawing/GraphicExportFilter.hpp>
#include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
#include <com/sun/star/animations/XAnimate.hpp>
#include <com/sun/star/chart/XChartDocument.hpp>
@@ -57,7 +56,6 @@
#include <comphelper/propertyvalue.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <comphelper/lok.hxx>
#include <vcl/filter/PngImageReader.hxx>
#include <vcl/BitmapReadAccess.hxx>
#include <svx/svdograf.hxx>
#include <vcl/filter/PDFiumLibrary.hxx>
@@ -143,9 +141,6 @@ public:
void testTdf127129();
void testTdf93097();
void testTdf62255();
void testTdf113163();
void testTdf93124();
void testTdf99729();
void testTdf89927();
CPPUNIT_TEST_SUITE(SdImportTest);
@@ -211,9 +206,6 @@ public:
CPPUNIT_TEST(testTdf127129);
CPPUNIT_TEST(testTdf93097);
CPPUNIT_TEST(testTdf62255);
CPPUNIT_TEST(testTdf113163);
CPPUNIT_TEST(testTdf93124);
CPPUNIT_TEST(testTdf99729);
CPPUNIT_TEST(testTdf89927);
CPPUNIT_TEST_SUITE_END();
@@ -1744,165 +1736,6 @@ void SdImportTest::testTdf62255()
xDocShRef->DoClose();
}
void SdImportTest::testTdf113163()
{
sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc(u"/sd/qa/unit/data/pptx/tdf113163.pptx"), PPTX);
uno::Reference < uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
uno::Reference< drawing::XGraphicExportFilter > xGraphicExporter = drawing::GraphicExportFilter::create(xContext);
uno::Sequence< beans::PropertyValue > aFilterData{
comphelper::makePropertyValue("PixelWidth", sal_Int32(100)),
comphelper::makePropertyValue("PixelHeight", sal_Int32(100))
};
utl::TempFile aTempFile;
aTempFile.EnableKillingFile();
uno::Sequence< beans::PropertyValue > aDescriptor{
comphelper::makePropertyValue("URL", aTempFile.GetURL()),
comphelper::makePropertyValue("FilterName", OUString("PNG")),
comphelper::makePropertyValue("FilterData", aFilterData)
};
uno::Reference< lang::XComponent > xPage(getPage(0, xDocShRef), uno::UNO_QUERY);
xGraphicExporter->setSourceDocument(xPage);
xGraphicExporter->filter(aDescriptor);
SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ);
vcl::PngImageReader aPNGReader(aFileStream);
BitmapEx aBMPEx = aPNGReader.read();
// make sure the bitmap is not empty and correct size (PNG export->import was successful)
Size aSize = aBMPEx.GetSizePixel();
CPPUNIT_ASSERT_EQUAL(Size(100, 100), aSize);
Bitmap aBMP = aBMPEx.GetBitmap();
{
Bitmap::ScopedReadAccess pReadAccess(aBMP);
for (tools::Long nX = 1; nX < aSize.Width() - 1; ++nX)
{
for (tools::Long nY = 1; nY < aSize.Height() - 1; ++nY)
{
// Check all pixels in the image are black
// Without the fix in place, this test would have failed with
// - Expected: 0
// - Actual : 16777215
const Color aColor = pReadAccess->GetColor(nX, nY);
CPPUNIT_ASSERT_EQUAL(COL_BLACK, aColor);
}
}
}
xDocShRef->DoClose();
}
void SdImportTest::testTdf93124()
{
sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc(u"/sd/qa/unit/data/ppt/tdf93124.ppt"), PPT);
uno::Reference < uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
uno::Reference< drawing::XGraphicExportFilter > xGraphicExporter = drawing::GraphicExportFilter::create(xContext);
uno::Sequence< beans::PropertyValue > aFilterData{
comphelper::makePropertyValue("PixelWidth", sal_Int32(320)),
comphelper::makePropertyValue("PixelHeight", sal_Int32(180))
};
utl::TempFile aTempFile;
aTempFile.EnableKillingFile();
uno::Sequence< beans::PropertyValue > aDescriptor{
comphelper::makePropertyValue("URL", aTempFile.GetURL()),
comphelper::makePropertyValue("FilterName", OUString("PNG")),
comphelper::makePropertyValue("FilterData", aFilterData)
};
uno::Reference< lang::XComponent > xPage(getPage(0, xDocShRef), uno::UNO_QUERY);
xGraphicExporter->setSourceDocument(xPage);
xGraphicExporter->filter(aDescriptor);
SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ);
vcl::PngImageReader aPNGReader(aFileStream);
BitmapEx aBMPEx = aPNGReader.read();
// make sure the bitmap is not empty and correct size (PNG export->import was successful)
CPPUNIT_ASSERT_EQUAL(Size(320, 180), aBMPEx.GetSizePixel());
Bitmap aBMP = aBMPEx.GetBitmap();
{
Bitmap::ScopedReadAccess pReadAccess(aBMP);
int nNonWhiteCount = 0;
// The word "Top" should be in rectangle 34,4 - 76,30. If text alignment is wrong, the rectangle will be white.
for (tools::Long nY = 4; nY < (4 + 26); ++nY)
{
for (tools::Long nX = 34; nX < (34 + 43); ++nX)
{
const Color aColor = pReadAccess->GetColor(nY, nX);
if ((aColor.GetRed() != 0xff) || (aColor.GetGreen() != 0xff) || (aColor.GetBlue() != 0xff))
++nNonWhiteCount;
}
}
CPPUNIT_ASSERT_MESSAGE("Tdf93124: vertical alignment of text is incorrect!", nNonWhiteCount>50);
}
xDocShRef->DoClose();
}
void SdImportTest::testTdf99729()
{
const OUString filenames[] = { "/sd/qa/unit/data/odp/tdf99729-new.odp", "/sd/qa/unit/data/odp/tdf99729-legacy.odp" };
int nonwhitecounts[] = { 0, 0 };
for (size_t i = 0; i < SAL_N_ELEMENTS(filenames); ++i)
{
// 1st check for new behaviour - having AnchoredTextOverflowLegacy compatibility flag set to false in settings.xml
uno::Reference<lang::XComponent> xComponent
= loadFromDesktop(m_directories.getURLFromSrc(filenames[i]),
"com.sun.star.presentation.PresentationDocument");
uno::Reference<uno::XComponentContext> xContext = getComponentContext();
CPPUNIT_ASSERT(xContext.is());
uno::Reference< drawing::XGraphicExportFilter > xGraphicExporter = drawing::GraphicExportFilter::create(xContext);
CPPUNIT_ASSERT(xGraphicExporter.is());
uno::Sequence< beans::PropertyValue > aFilterData{
comphelper::makePropertyValue("PixelWidth", sal_Int32(320)),
comphelper::makePropertyValue("PixelHeight", sal_Int32(240))
};
utl::TempFile aTempFile;
aTempFile.EnableKillingFile();
uno::Sequence< beans::PropertyValue > aDescriptor{
comphelper::makePropertyValue("URL", aTempFile.GetURL()),
comphelper::makePropertyValue("FilterName", OUString("PNG")),
comphelper::makePropertyValue("FilterData", aFilterData)
};
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY);
uno::Reference<lang::XComponent> xPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
uno::UNO_QUERY);
CPPUNIT_ASSERT(xPage.is());
xGraphicExporter->setSourceDocument(xPage);
xGraphicExporter->filter(aDescriptor);
SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ);
vcl::PngImageReader aPNGReader(aFileStream);
BitmapEx aBMPEx = aPNGReader.read();
Bitmap aBMP = aBMPEx.GetBitmap();
Bitmap::ScopedReadAccess pRead(aBMP);
for (tools::Long nX = 154; nX < (154 + 12); ++nX)
{
for (tools::Long nY = 16; nY < (16 + 96); ++nY)
{
const Color aColor = pRead->GetColor(nY, nX);
if ((aColor.GetRed() != 0xff) || (aColor.GetGreen() != 0xff) || (aColor.GetBlue() != 0xff))
++nonwhitecounts[i];
}
}
xComponent->dispose();
}
// The numbers 1-9 should be above the Text Box in rectangle 154,16 - 170,112.
// If text alignment is wrong, the rectangle will be white.
CPPUNIT_ASSERT_MESSAGE("Tdf99729: vertical alignment of text is incorrect!", nonwhitecounts[0]>100); // it is 134 with cleartype disabled
// The numbers 1-9 should be below the Text Box -> rectangle 154,16 - 170,112 should be white.
CPPUNIT_ASSERT_EQUAL_MESSAGE("Tdf99729: legacy vertical alignment of text is incorrect!", 0, nonwhitecounts[1]);
}
void SdImportTest::testTdf89927()
{
sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc(u"/sd/qa/unit/data/pptx/tdf89927.pptx"), PPTX);