summaryrefslogtreecommitdiff
path: root/slideshow/test/views.cxx
blob: e2fb6baebeaabcd0a2d7ebee8c3e71005ecd39f4 (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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: views.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-13 16:09:23 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#include <cppunit/simpleheader.hxx>
#include <cppuhelper/compbase1.hxx>
#include <comphelper/broadcasthelper.hxx>

#include "unoview.hxx"
#include "unoviewcontainer.hxx"
#include "shape.hxx"
#include "layermanager.hxx"
#include "com/sun/star/presentation/XSlideShowView.hpp"

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

namespace
{

class UnoViewContainerTest : public CppUnit::TestFixture
{
public:
    // our test view subject
    class TestUnoView : public target::UnoView
    {
        bool mbDisposed;

    public:
        TestUnoView() : mbDisposed( false )
        {
        }

        virtual ~TestUnoView()
        {
        }

        virtual ::cppcanvas::CanvasSharedPtr getCanvas() const
        {
            return ::cppcanvas::CanvasSharedPtr();
        }

        virtual ::cppcanvas::CustomSpriteSharedPtr createSprite( const ::basegfx::B2DSize& rSpriteSizePixel ) const
        {
            return ::cppcanvas::CustomSpriteSharedPtr();
        }

        virtual double getSpritePriority( double nSpritePrio ) const
        {
            return 0.0;
        }

        virtual void setPriority( double nPrio )
        {
        }

        virtual target::ViewLayerSharedPtr createViewLayer() const
        {
            return target::ViewLayerSharedPtr();
        }

        virtual void clear() const
        {
        }

        virtual bool isContentDestroyed() const
        {
            return true;
        }

        virtual bool updateScreen() const
        {
            return true;
        }

        virtual ::basegfx::B2DHomMatrix getTransformation() const
        {
            return ::basegfx::B2DHomMatrix();
        }

        virtual void setViewSize( const ::basegfx::B2DSize& )
        {
        }

        virtual void setClip( const ::basegfx::B2DPolyPolygon& rClip )
        {
        }

        virtual void setMouseCursor( sal_Int16 nPointerShape )
        {
        }

        virtual uno::Reference< presentation::XSlideShowView > getUnoView() const
        {
            return uno::Reference< presentation::XSlideShowView >();
        }

        virtual void _dispose()
        {
            mbDisposed = true;
        }

        bool isDisposed() { return mbDisposed; }
    };

    // our test shape subject
    typedef ::cppu::WeakComponentImplHelper1< drawing::XShape > ShapeBase;
    class TestShape : public target::Shape, public comphelper::OBaseMutex, public ShapeBase
    {
        const basegfx::B2DRectangle maRect;
        const double                mnPrio;

        virtual ::rtl::OUString SAL_CALL getShapeType(  ) throw (uno::RuntimeException)
        {
            return ::rtl::OUString();
        }

        virtual awt::Point SAL_CALL getPosition(  ) throw (uno::RuntimeException)
        {
            return awt::Point();
        }

        virtual void SAL_CALL setPosition( const awt::Point& aPosition ) throw (uno::RuntimeException)
        {
        }

        virtual awt::Size SAL_CALL getSize(  ) throw (uno::RuntimeException)
        {
            return awt::Size();
        }

        virtual void SAL_CALL setSize( const awt::Size& aSize ) throw (beans::PropertyVetoException, uno::RuntimeException)
        {
        }

    public:
        TestShape( const basegfx::B2DRectangle& rRect,
                   double                       nPrio ) :
            ShapeBase( m_aMutex ),
            maRect( rRect ),
            mnPrio( nPrio )
        {}

        virtual uno::Reference< drawing::XShape > getXShape() const
        {
            return uno::Reference< drawing::XShape >( const_cast<TestShape*>(this) );
        }

        virtual void addViewLayer( const target::ViewLayerSharedPtr&    rNewLayer,
                                   bool                                 bRedrawLayer )
        {
        }
        virtual bool removeViewLayer( const target::ViewLayerSharedPtr& rNewLayer )
        {
            return true;
        }
        virtual bool clearAllViewLayers()
        {
            return true;
        }

        virtual bool update() const
        {
            return true;
        }
        virtual bool render() const
        {
            return true;
        }
        virtual bool isUpdateNecessary() const
        {
            return true;
        }

        virtual ::basegfx::B2DRectangle getPosSize() const
        {
            return maRect;
        }
        virtual ::basegfx::B2DRectangle getDOMBounds() const
        {
            return maRect;
        }
        virtual ::basegfx::B2DRectangle getUpdateArea() const
        {
            return maRect;
        }

        virtual bool isVisible() const
        {
            return true;
        }
        virtual double getPriority() const
        {
            return mnPrio;
        }
        virtual bool isBackgroundDetached() const
        {
            return false;
        }
        virtual bool hasIntrinsicAnimation() const
        {
            return false;
        }
        virtual bool hasHyperlinks() const
        {
            return false;
        }
        virtual HyperLinkRegions getHyperlinkRegions() const
        {
            return HyperLinkRegions();
        }
    };

    void testContainer()
    {
        target::UnoViewContainer aContainer;

        boost::shared_ptr<TestUnoView> pView( new TestUnoView() );
        aContainer.addView( pView );

        CPPUNIT_ASSERT_MESSAGE( "Testing container size",
                                1 == std::distance( aContainer.begin(),
                                                    aContainer.end() ));
        aContainer.dispose();
        CPPUNIT_ASSERT_MESSAGE( "Testing dispose: container must be empty",
                                0 == std::distance( aContainer.begin(),
                                                    aContainer.end() ));
        CPPUNIT_ASSERT_MESSAGE( "Testing dispose: all elements must receive dispose",
                                pView->isDisposed() );
    }

    void testLayerManager()
    {
        basegfx::B2DRectangle aRect(0,0,1600,1200);
        const basegfx::B2DRectangle aRect2( aRect );
        target::LayerManager aLayerManager( aRect );
        boost::shared_ptr<TestUnoView> pView( new TestUnoView() );

        aRect.reset();

        CPPUNIT_ASSERT_MESSAGE( "Testing page bounds",
                                aRect2 == aLayerManager.getPageBounds());

        aLayerManager.addView( pView );
        CPPUNIT_ASSERT_EQUAL_MESSAGE( "Testing view removal",
                                      true,
                                      aLayerManager.removeView( pView ));

        boost::shared_ptr<TestShape> pShape( new TestShape(basegfx::B2DRectangle(10,10,100,100),
                                                           1.0) );
        aLayerManager.addShape( pShape );
        CPPUNIT_ASSERT_EQUAL_MESSAGE( "Testing shape removal",
                                      true,
                                      aLayerManager.removeShape( pShape ));
    }

    // hook up the test
    CPPUNIT_TEST_SUITE(UnoViewContainerTest);
    CPPUNIT_TEST(testContainer);
    CPPUNIT_TEST(testLayerManager);
    CPPUNIT_TEST_SUITE_END();

}; // class UnoViewContainerTest

// -----------------------------------------------------------------------------
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(UnoViewContainerTest, "UnoViewContainerTest");
} // namespace


// -----------------------------------------------------------------------------

// this macro creates an empty function, which will called by the RegisterAllFunctions()
// to let the user the possibility to also register some functions by hand.
NOADDITIONAL;