1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/* -*- 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 <test/bootstrapfixture.hxx>

#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/graphic/GraphicType.hpp>
#include <com/sun/star/graphic/GraphicProvider.hpp>
#include <com/sun/star/graphic/XGraphicProvider.hpp>
#include <com/sun/star/awt/Size.hpp>

#include <comphelper/processfactory.hxx>
#include <comphelper/propertysequence.hxx>

namespace
{
using namespace css;

static OUString const gaDataUrl = "/vcl/qa/api/data/";

class XGraphicTest : public test::BootstrapFixture
{
public:
    XGraphicTest()
        : BootstrapFixture(true, false)
    {
    }

    OUString getFullUrl(const OUString& 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), 24);
    aBitmap.Erase(COL_LIGHTRED);

    return BitmapEx(aBitmap);
}

void XGraphicTest::testGraphic()
{
    Graphic aGraphic;
    uno::Reference<graphic::XGraphic> xGraphic = aGraphic.GetXGraphic();<--- Variable 'xGraphic' is assigned a value that is never used.
}

void XGraphicTest::testGraphicDescriptor()
{
    Graphic aGraphic(createBitmap());
    uno::Reference<graphic::XGraphic> xGraphic = aGraphic.GetXGraphic();
    uno::Reference<beans::XPropertySet> 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);<--- Uninitialized variable: bTransparent
    CPPUNIT_ASSERT_EQUAL(false, bTransparent);

    //[optional, property] boolean Alpha;
    bool bAlpha;
    CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Alpha") >>= bAlpha);<--- Uninitialized variable: bAlpha
    CPPUNIT_ASSERT_EQUAL(false, bAlpha);

    //[optional, property] boolean Animated;
    bool bAnimated;
    CPPUNIT_ASSERT(xGraphicDescriptor->getPropertyValue("Animated") >>= bAnimated);<--- Uninitialized variable: bAnimated
    CPPUNIT_ASSERT_EQUAL(false, bAnimated);
}

void XGraphicTest::testGraphicProvider()
{
    OUString aGraphicURL = getFullUrl("TestGraphic.png");

    { // Load lazy
        uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
        uno::Reference<graphic::XGraphicProvider> xGraphicProvider;
        xGraphicProvider.set(graphic::GraphicProvider::create(xContext), uno::UNO_SET_THROW);

        auto aMediaProperties(comphelper::InitPropertySequence({
            { "URL", uno::makeAny(aGraphicURL) },
            { "LazyRead", uno::makeAny(true) },
            { "LoadAsLink", uno::makeAny(false) },
        }));

        uno::Reference<graphic::XGraphic> xGraphic(
            xGraphicProvider->queryGraphic(aMediaProperties));
        CPPUNIT_ASSERT(xGraphic.is());
        Graphic aGraphic(xGraphic);
        CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());

        uno::Reference<beans::XPropertySet> 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);<--- Uninitialized variable: 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<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
        uno::Reference<graphic::XGraphicProvider> xGraphicProvider;
        xGraphicProvider.set(graphic::GraphicProvider::create(xContext), uno::UNO_SET_THROW);

        auto aMediaProperties(comphelper::InitPropertySequence({
            { "URL", uno::makeAny(aGraphicURL) },
            { "LazyRead", uno::makeAny(false) },
            { "LoadAsLink", uno::makeAny(true) },
        }));

        uno::Reference<graphic::XGraphic> xGraphic(
            xGraphicProvider->queryGraphic(aMediaProperties));
        CPPUNIT_ASSERT(xGraphic.is());
        Graphic aGraphic(xGraphic);
        CPPUNIT_ASSERT_EQUAL(true, aGraphic.isAvailable());

        uno::Reference<beans::XPropertySet> 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);<--- Uninitialized variable: 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<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
        uno::Reference<graphic::XGraphicProvider> xGraphicProvider;
        xGraphicProvider.set(graphic::GraphicProvider::create(xContext), uno::UNO_SET_THROW);

        auto aMediaProperties(comphelper::InitPropertySequence({
            { "URL", uno::makeAny(aGraphicURL) },
            { "LazyRead", uno::makeAny(true) },
            { "LoadAsLink", uno::makeAny(true) },
        }));

        uno::Reference<graphic::XGraphic> xGraphic(
            xGraphicProvider->queryGraphic(aMediaProperties));
        CPPUNIT_ASSERT(xGraphic.is());
        Graphic aGraphic(xGraphic);

        CPPUNIT_ASSERT_EQUAL(false, aGraphic.isAvailable());

        uno::Reference<beans::XPropertySet> 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);<--- Uninitialized variable: 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: */