From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- vcl/qa/api/XGraphicTest.cxx | 245 ++++++++++++++++++++++++++++++++++++++++ vcl/qa/api/data/TestGraphic.png | Bin 0 -> 81 bytes 2 files changed, 245 insertions(+) create mode 100644 vcl/qa/api/XGraphicTest.cxx create mode 100644 vcl/qa/api/data/TestGraphic.png (limited to 'vcl/qa/api') diff --git a/vcl/qa/api/XGraphicTest.cxx b/vcl/qa/api/XGraphicTest.cxx new file mode 100644 index 000000000..df05c05f9 --- /dev/null +++ b/vcl/qa/api/XGraphicTest.cxx @@ -0,0 +1,245 @@ +/* -*- 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 + +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include + +namespace +{ +using namespace css; + +constexpr OUStringLiteral gaDataUrl = u"/vcl/qa/api/data/"; + +class XGraphicTest : public test::BootstrapFixture +{ +public: + XGraphicTest() + : BootstrapFixture(true, false) + { + } + + OUString getFullUrl(std::u16string_view sFileName) + { + return m_directories.getURLFromSrc(gaDataUrl) + sFileName; + } + + void testGraphic(); + void testGraphicDescriptor(); + void testGraphicProvider(); + + CPPUNIT_TEST_SUITE(XGraphicTest); + CPPUNIT_TEST(testGraphic); + CPPUNIT_TEST(testGraphicDescriptor); + CPPUNIT_TEST(testGraphicProvider); + CPPUNIT_TEST_SUITE_END(); +}; + +BitmapEx createBitmap() +{ + Bitmap aBitmap(Size(100, 50), vcl::PixelFormat::N24_BPP); + aBitmap.Erase(COL_LIGHTRED); + + return BitmapEx(aBitmap); +} + +void XGraphicTest::testGraphic() +{ + Graphic aGraphic; + uno::Reference xGraphic = aGraphic.GetXGraphic(); +} + +void XGraphicTest::testGraphicDescriptor() +{ + Graphic aGraphic(createBitmap()); + uno::Reference xGraphic = aGraphic.GetXGraphic(); + uno::Reference xGraphicDescriptor(xGraphic, uno::UNO_QUERY_THROW); + + //[property] byte GraphicType; + sal_Int8 nType; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("GraphicType") >>= nType); + CPPUNIT_ASSERT_EQUAL(graphic::GraphicType::PIXEL, nType); + + //[property] string MimeType; + OUString sMimeType; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("MimeType") >>= sMimeType); + CPPUNIT_ASSERT_EQUAL(OUString("image/x-vclgraphic"), sMimeType); + + //[optional, property] ::com::sun::star::awt::Size SizePixel; + awt::Size aSizePixel; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("SizePixel") >>= aSizePixel); + CPPUNIT_ASSERT_EQUAL(sal_Int32(100), aSizePixel.Width); + CPPUNIT_ASSERT_EQUAL(sal_Int32(50), aSizePixel.Height); + + //[optional, property] ::com::sun::star::awt::Size Size100thMM; + awt::Size aSize100thMM; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Size100thMM") >>= aSize100thMM); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aSize100thMM.Width); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aSize100thMM.Height); + + //[optional, property] byte BitsPerPixel; + sal_Int8 nBitsPerPixel; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("BitsPerPixel") >>= nBitsPerPixel); + CPPUNIT_ASSERT_EQUAL(sal_Int8(24), nBitsPerPixel); + + //[optional, property] boolean Transparent; + bool bTransparent; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Transparent") >>= bTransparent); + CPPUNIT_ASSERT_EQUAL(false, bTransparent); + + //[optional, property] boolean Alpha; + bool bAlpha; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Alpha") >>= bAlpha); + CPPUNIT_ASSERT_EQUAL(false, bAlpha); + + //[optional, property] boolean Animated; + bool bAnimated; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Animated") >>= bAnimated); + CPPUNIT_ASSERT_EQUAL(false, bAnimated); +} + +void XGraphicTest::testGraphicProvider() +{ + OUString aGraphicURL = getFullUrl(u"TestGraphic.png"); + + { // Load lazy + uno::Reference xContext(comphelper::getProcessComponentContext()); + uno::Reference xGraphicProvider; + xGraphicProvider.set(graphic::GraphicProvider::create(xContext), uno::UNO_SET_THROW); + + auto aMediaProperties(comphelper::InitPropertySequence({ + { "URL", uno::Any(aGraphicURL) }, + { "LazyRead", uno::Any(true) }, + { "LoadAsLink", uno::Any(false) }, + })); + + uno::Reference xGraphic( + xGraphicProvider->queryGraphic(aMediaProperties)); + CPPUNIT_ASSERT(xGraphic.is()); + Graphic aGraphic(xGraphic); + CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable()); + + uno::Reference xGraphicDescriptor(xGraphic, uno::UNO_QUERY_THROW); + + sal_Int8 nType; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("GraphicType") >>= nType); + CPPUNIT_ASSERT_EQUAL(graphic::GraphicType::PIXEL, nType); + + awt::Size aSizePixel; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("SizePixel") >>= aSizePixel); + CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aSizePixel.Width); + CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aSizePixel.Height); + + bool bLinked; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Linked") >>= bLinked); + CPPUNIT_ASSERT_EQUAL(false, bLinked); + + OUString sOriginURL; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("OriginURL") >>= sOriginURL); + CPPUNIT_ASSERT_EQUAL(OUString(), sOriginURL); + + CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable()); + } + + { // Load as link + uno::Reference xContext(comphelper::getProcessComponentContext()); + uno::Reference xGraphicProvider; + xGraphicProvider.set(graphic::GraphicProvider::create(xContext), uno::UNO_SET_THROW); + + auto aMediaProperties(comphelper::InitPropertySequence({ + { "URL", uno::Any(aGraphicURL) }, + { "LazyRead", uno::Any(false) }, + { "LoadAsLink", uno::Any(true) }, + })); + + uno::Reference xGraphic( + xGraphicProvider->queryGraphic(aMediaProperties)); + CPPUNIT_ASSERT(xGraphic.is()); + Graphic aGraphic(xGraphic); + CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable()); + + uno::Reference xGraphicDescriptor(xGraphic, uno::UNO_QUERY_THROW); + + sal_Int8 nType; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("GraphicType") >>= nType); + CPPUNIT_ASSERT_EQUAL(graphic::GraphicType::PIXEL, nType); + + awt::Size aSizePixel; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("SizePixel") >>= aSizePixel); + CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aSizePixel.Width); + CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aSizePixel.Height); + + bool bLinked; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Linked") >>= bLinked); + CPPUNIT_ASSERT_EQUAL(true, bLinked); + + OUString sOriginURL; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("OriginURL") >>= sOriginURL); + CPPUNIT_ASSERT_EQUAL(aGraphicURL, sOriginURL); + } + + { // Load lazy and as link + uno::Reference xContext(comphelper::getProcessComponentContext()); + uno::Reference xGraphicProvider; + xGraphicProvider.set(graphic::GraphicProvider::create(xContext), uno::UNO_SET_THROW); + + auto aMediaProperties(comphelper::InitPropertySequence({ + { "URL", uno::Any(aGraphicURL) }, + { "LazyRead", uno::Any(true) }, + { "LoadAsLink", uno::Any(true) }, + })); + + uno::Reference xGraphic( + xGraphicProvider->queryGraphic(aMediaProperties)); + CPPUNIT_ASSERT(xGraphic.is()); + Graphic aGraphic(xGraphic); + + CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable()); + + uno::Reference xGraphicDescriptor(xGraphic, uno::UNO_QUERY_THROW); + + sal_Int8 nType; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("GraphicType") >>= nType); + CPPUNIT_ASSERT_EQUAL(graphic::GraphicType::PIXEL, nType); + + awt::Size aSizePixel; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("SizePixel") >>= aSizePixel); + CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aSizePixel.Width); + CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aSizePixel.Height); + + bool bLinked; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Linked") >>= bLinked); + CPPUNIT_ASSERT_EQUAL(true, bLinked); + + OUString sOriginURL; + CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("OriginURL") >>= sOriginURL); + CPPUNIT_ASSERT_EQUAL(aGraphicURL, sOriginURL); + + CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable()); + } +} + +} // namespace + +CPPUNIT_TEST_SUITE_REGISTRATION(XGraphicTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qa/api/data/TestGraphic.png b/vcl/qa/api/data/TestGraphic.png new file mode 100644 index 000000000..fe0c3c8ae Binary files /dev/null and b/vcl/qa/api/data/TestGraphic.png differ -- cgit v1.2.3