calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / qa / api / XGraphicTest.cxx
blobdf05c05f9f4c28f8eeab0da74ecf03df3123d1e4
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 <sal/config.h>
12 #include <string_view>
14 #include <test/bootstrapfixture.hxx>
16 #include <com/sun/star/graphic/XGraphic.hpp>
17 #include <com/sun/star/graphic/GraphicType.hpp>
18 #include <com/sun/star/graphic/GraphicProvider.hpp>
19 #include <com/sun/star/graphic/XGraphicProvider.hpp>
20 #include <com/sun/star/awt/Size.hpp>
22 #include <comphelper/processfactory.hxx>
23 #include <comphelper/propertysequence.hxx>
25 namespace
27 using namespace css;
29 constexpr OUStringLiteral gaDataUrl = u"/vcl/qa/api/data/";
31 class XGraphicTest : public test::BootstrapFixture
33 public:
34 XGraphicTest()
35 : BootstrapFixture(true, false)
39 OUString getFullUrl(std::u16string_view sFileName)
41 return m_directories.getURLFromSrc(gaDataUrl) + sFileName;
44 void testGraphic();
45 void testGraphicDescriptor();
46 void testGraphicProvider();
48 CPPUNIT_TEST_SUITE(XGraphicTest);
49 CPPUNIT_TEST(testGraphic);
50 CPPUNIT_TEST(testGraphicDescriptor);
51 CPPUNIT_TEST(testGraphicProvider);
52 CPPUNIT_TEST_SUITE_END();
55 BitmapEx createBitmap()
57 Bitmap aBitmap(Size(100, 50), vcl::PixelFormat::N24_BPP);
58 aBitmap.Erase(COL_LIGHTRED);
60 return BitmapEx(aBitmap);
63 void XGraphicTest::testGraphic()
65 Graphic aGraphic;
66 uno::Reference<graphic::XGraphic> xGraphic = aGraphic.GetXGraphic();
69 void XGraphicTest::testGraphicDescriptor()
71 Graphic aGraphic(createBitmap());
72 uno::Reference<graphic::XGraphic> xGraphic = aGraphic.GetXGraphic();
73 uno::Reference<beans::XPropertySet> xGraphicDescriptor(xGraphic, uno::UNO_QUERY_THROW);
75 //[property] byte GraphicType;
76 sal_Int8 nType;
77 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("GraphicType") >>= nType);
78 CPPUNIT_ASSERT_EQUAL(graphic::GraphicType::PIXEL, nType);
80 //[property] string MimeType;
81 OUString sMimeType;
82 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("MimeType") >>= sMimeType);
83 CPPUNIT_ASSERT_EQUAL(OUString("image/x-vclgraphic"), sMimeType);
85 //[optional, property] ::com::sun::star::awt::Size SizePixel;
86 awt::Size aSizePixel;
87 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("SizePixel") >>= aSizePixel);
88 CPPUNIT_ASSERT_EQUAL(sal_Int32(100), aSizePixel.Width);
89 CPPUNIT_ASSERT_EQUAL(sal_Int32(50), aSizePixel.Height);
91 //[optional, property] ::com::sun::star::awt::Size Size100thMM;
92 awt::Size aSize100thMM;
93 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Size100thMM") >>= aSize100thMM);
94 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aSize100thMM.Width);
95 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aSize100thMM.Height);
97 //[optional, property] byte BitsPerPixel;
98 sal_Int8 nBitsPerPixel;
99 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("BitsPerPixel") >>= nBitsPerPixel);
100 CPPUNIT_ASSERT_EQUAL(sal_Int8(24), nBitsPerPixel);
102 //[optional, property] boolean Transparent;
103 bool bTransparent;
104 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Transparent") >>= bTransparent);
105 CPPUNIT_ASSERT_EQUAL(false, bTransparent);
107 //[optional, property] boolean Alpha;
108 bool bAlpha;
109 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Alpha") >>= bAlpha);
110 CPPUNIT_ASSERT_EQUAL(false, bAlpha);
112 //[optional, property] boolean Animated;
113 bool bAnimated;
114 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Animated") >>= bAnimated);
115 CPPUNIT_ASSERT_EQUAL(false, bAnimated);
118 void XGraphicTest::testGraphicProvider()
120 OUString aGraphicURL = getFullUrl(u"TestGraphic.png");
122 { // Load lazy
123 uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
124 uno::Reference<graphic::XGraphicProvider> xGraphicProvider;
125 xGraphicProvider.set(graphic::GraphicProvider::create(xContext), uno::UNO_SET_THROW);
127 auto aMediaProperties(comphelper::InitPropertySequence({
128 { "URL", uno::Any(aGraphicURL) },
129 { "LazyRead", uno::Any(true) },
130 { "LoadAsLink", uno::Any(false) },
131 }));
133 uno::Reference<graphic::XGraphic> xGraphic(
134 xGraphicProvider->queryGraphic(aMediaProperties));
135 CPPUNIT_ASSERT(xGraphic.is());
136 Graphic aGraphic(xGraphic);
137 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
139 uno::Reference<beans::XPropertySet> xGraphicDescriptor(xGraphic, uno::UNO_QUERY_THROW);
141 sal_Int8 nType;
142 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("GraphicType") >>= nType);
143 CPPUNIT_ASSERT_EQUAL(graphic::GraphicType::PIXEL, nType);
145 awt::Size aSizePixel;
146 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("SizePixel") >>= aSizePixel);
147 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aSizePixel.Width);
148 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aSizePixel.Height);
150 bool bLinked;
151 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Linked") >>= bLinked);
152 CPPUNIT_ASSERT_EQUAL(false, bLinked);
154 OUString sOriginURL;
155 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("OriginURL") >>= sOriginURL);
156 CPPUNIT_ASSERT_EQUAL(OUString(), sOriginURL);
158 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
161 { // Load as link
162 uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
163 uno::Reference<graphic::XGraphicProvider> xGraphicProvider;
164 xGraphicProvider.set(graphic::GraphicProvider::create(xContext), uno::UNO_SET_THROW);
166 auto aMediaProperties(comphelper::InitPropertySequence({
167 { "URL", uno::Any(aGraphicURL) },
168 { "LazyRead", uno::Any(false) },
169 { "LoadAsLink", uno::Any(true) },
170 }));
172 uno::Reference<graphic::XGraphic> xGraphic(
173 xGraphicProvider->queryGraphic(aMediaProperties));
174 CPPUNIT_ASSERT(xGraphic.is());
175 Graphic aGraphic(xGraphic);
176 CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());
178 uno::Reference<beans::XPropertySet> xGraphicDescriptor(xGraphic, uno::UNO_QUERY_THROW);
180 sal_Int8 nType;
181 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("GraphicType") >>= nType);
182 CPPUNIT_ASSERT_EQUAL(graphic::GraphicType::PIXEL, nType);
184 awt::Size aSizePixel;
185 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("SizePixel") >>= aSizePixel);
186 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aSizePixel.Width);
187 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aSizePixel.Height);
189 bool bLinked;
190 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Linked") >>= bLinked);
191 CPPUNIT_ASSERT_EQUAL(true, bLinked);
193 OUString sOriginURL;
194 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("OriginURL") >>= sOriginURL);
195 CPPUNIT_ASSERT_EQUAL(aGraphicURL, sOriginURL);
198 { // Load lazy and as link
199 uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
200 uno::Reference<graphic::XGraphicProvider> xGraphicProvider;
201 xGraphicProvider.set(graphic::GraphicProvider::create(xContext), uno::UNO_SET_THROW);
203 auto aMediaProperties(comphelper::InitPropertySequence({
204 { "URL", uno::Any(aGraphicURL) },
205 { "LazyRead", uno::Any(true) },
206 { "LoadAsLink", uno::Any(true) },
207 }));
209 uno::Reference<graphic::XGraphic> xGraphic(
210 xGraphicProvider->queryGraphic(aMediaProperties));
211 CPPUNIT_ASSERT(xGraphic.is());
212 Graphic aGraphic(xGraphic);
214 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
216 uno::Reference<beans::XPropertySet> xGraphicDescriptor(xGraphic, uno::UNO_QUERY_THROW);
218 sal_Int8 nType;
219 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("GraphicType") >>= nType);
220 CPPUNIT_ASSERT_EQUAL(graphic::GraphicType::PIXEL, nType);
222 awt::Size aSizePixel;
223 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("SizePixel") >>= aSizePixel);
224 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aSizePixel.Width);
225 CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aSizePixel.Height);
227 bool bLinked;
228 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Linked") >>= bLinked);
229 CPPUNIT_ASSERT_EQUAL(true, bLinked);
231 OUString sOriginURL;
232 CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("OriginURL") >>= sOriginURL);
233 CPPUNIT_ASSERT_EQUAL(aGraphicURL, sOriginURL);
235 CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());
239 } // namespace
241 CPPUNIT_TEST_SUITE_REGISTRATION(XGraphicTest);
243 CPPUNIT_PLUGIN_IMPLEMENT();
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */