summaryrefslogtreecommitdiffstats
path: root/slideshow/test/testshape.cxx
blob: db7031070ba85bd4ed36f71b804b44a079475ebb (plain)
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
/* -*- 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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <sal/types.h>
#include <cppunit/TestAssert.h>

#include <cppuhelper/compbase.hxx>
#include <cppuhelper/basemutex.hxx>
#include <comphelper/make_shared_from_uno.hxx>

#include <basegfx/range/b2drange.hxx>

#include "tests.hxx"

namespace target = slideshow::internal;
using namespace ::com::sun::star;

// our test shape subject
typedef ::cppu::WeakComponentImplHelper< drawing::XShape > ShapeBase;

namespace {

class ImplTestShape : public TestShape,
                      private cppu::BaseMutex,
                      public ShapeBase
{
    typedef std::vector<std::pair<target::ViewLayerSharedPtr,bool> > ViewVector;
    ViewVector               maViewLayers;
    const basegfx::B2DRange  maRect;
    const double             mnPrio;
    sal_Int32                mnAnimated;
    mutable sal_Int32        mnNumUpdates;
    mutable sal_Int32        mnNumRenders;

public:
    ImplTestShape( const basegfx::B2DRange& rRect,
                   double                   nPrio ) :
        ShapeBase( m_aMutex ),
        maViewLayers(),
        maRect( rRect ),
        mnPrio( nPrio ),
        mnAnimated(0),
        mnNumUpdates(0),
        mnNumRenders(0)
    {}


private:
    // TestShape
    virtual std::vector<std::pair<target::ViewLayerSharedPtr,bool> > getViewLayers() const override
    {
        return maViewLayers;
    }
    virtual sal_Int32 getNumUpdates() const override
    {
        return mnNumUpdates;
    }
    virtual sal_Int32 getNumRenders() const override
    {
        return mnNumRenders;
    }

    // XShape
    virtual OUString SAL_CALL getShapeType(  ) override
    {
        CPPUNIT_ASSERT_MESSAGE( "TestShape::getShapeType: unexpected method call", false );
        return OUString();
    }

    virtual awt::Point SAL_CALL getPosition(  ) override
    {
        CPPUNIT_ASSERT_MESSAGE( "TestShape::getPosition: unexpected method call", false );
        return awt::Point();
    }

    virtual void SAL_CALL setPosition( const awt::Point& ) override
    {
        CPPUNIT_ASSERT_MESSAGE( "TestShape::setPosition: unexpected method call", false );
    }

    virtual awt::Size SAL_CALL getSize(  ) override
    {
        CPPUNIT_ASSERT_MESSAGE( "TestShape::getSize: unexpected method call", false );
        return awt::Size();
    }

    virtual void SAL_CALL setSize( const awt::Size& /*aSize*/ ) override
    {
        CPPUNIT_ASSERT_MESSAGE( "TestShape::setSize: unexpected method call", false );
    }


    // Shape
    virtual uno::Reference< drawing::XShape > getXShape() const override
    {
        return uno::Reference< drawing::XShape >( const_cast<ImplTestShape*>(this) );
    }
    virtual void addViewLayer( const target::ViewLayerSharedPtr& rNewLayer,
                               bool                              bRedrawLayer ) override
    {
        maViewLayers.push_back( std::make_pair(rNewLayer,bRedrawLayer) );
    }
    virtual bool removeViewLayer( const target::ViewLayerSharedPtr& rNewLayer ) override
    {
        if( std::none_of(
                maViewLayers.begin(),
                maViewLayers.end(),
                [&rNewLayer]
                ( const ViewVector::value_type& cp )
                { return cp.first == rNewLayer; } ) )
            throw std::exception();

        maViewLayers.erase(
            std::remove_if(
                maViewLayers.begin(),
                maViewLayers.end(),
                [&rNewLayer]
                ( const ViewVector::value_type& cp )
                { return cp.first == rNewLayer; } ) );
        return true;
    }
    virtual void clearAllViewLayers() override
    {
        maViewLayers.clear();
    }

    virtual bool update() const override
    {
        ++mnNumUpdates;
        return true;
    }
    virtual bool render() const override
    {
        ++mnNumRenders;
        return true;
    }
    virtual bool isContentChanged() const override
    {
        return true;
    }
    virtual ::basegfx::B2DRectangle getBounds() const override
    {
        return maRect;
    }
    virtual ::basegfx::B2DRectangle getDomBounds() const override
    {
        return maRect;
    }
    virtual ::basegfx::B2DRectangle getUpdateArea() const override
    {
        return maRect;
    }

    virtual bool isVisible() const override
    {
        return true;
    }
    virtual double getPriority() const override
    {
        return mnPrio;
    }
    virtual bool isBackgroundDetached() const override
    {
        return mnAnimated != 0;
    }

    // AnimatableShape
    virtual void enterAnimationMode() override
    {
        ++mnAnimated;
    }

    virtual void leaveAnimationMode() override
    {
        --mnAnimated;
    }
};

}

TestShapeSharedPtr createTestShape(const basegfx::B2DRange& rRect,
                                   double                   nPrio)
{
    return TestShapeSharedPtr(
        comphelper::make_shared_from_UNO(
            new ImplTestShape(rRect,nPrio)) );
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */