1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
31 import util
.ValueComparer
;
32 import util
.XInstCreator
;
34 import com
.sun
.star
.drawing
.XLayer
;
35 import com
.sun
.star
.drawing
.XLayerManager
;
36 import com
.sun
.star
.drawing
.XShape
;
37 import com
.sun
.star
.drawing
.XShapes
;
38 import com
.sun
.star
.uno
.XInterface
;
41 * Testing <code>com.sun.star.drawing.XLayerManager</code>
44 * <li><code> insertNewByIndex()</code></li>
45 * <li><code> remove()</code></li>
46 * <li><code> attachShapeToLayer()</code></li>
47 * <li><code> getLayerForShape()</code></li>
49 * This test needs the following object relations :
51 * <li> <code>'Shape'</code> (of type <code>util.XInstCreator</code>):
52 * instance creator which can create shapes.</li>
53 * <li> <code>'Shapes'</code>
54 * (of type <code>com.sun.star.drawing.XShapes</code>):
55 * The collection of shapes in the document. Is used
56 * to add new created shapes.</li>
58 * Test is <b> NOT </b> multithread compilant. <p>
59 * @see com.sun.star.drawing.XLayerManager
61 public class _XLayerManager
extends MultiMethodTest
{
63 public XLayerManager oObj
= null; // oObj filled by MultiMethodTest
64 XInstCreator shape
= null;
65 public XInterface oShape
= null;
66 public XLayer oL
= null;
69 * Inserts a new layer into collection. <p>
70 * Has <b> OK </b> status if the value returned is not null. <p>
72 public void _insertNewByIndex(){
73 log
.println("insertNewByName() ... ");
74 oL
= oObj
.insertNewByIndex(0);
75 tRes
.tested("insertNewByIndex()", oL
!= null);
79 * First a shape created and inserted into the document using
80 * relations retrieved. Attaches this shape to layer created before. <p>
81 * Has <b> OK </b> status if the method successfully returns
82 * and no exceptions were thrown. <p>
83 * The following method tests are to be completed successfully before :
85 * <li> <code> insertNewByIndex </code> : to have a layer attach to.</li>
88 public void _attachShapeToLayer() {
89 requiredMethod("insertNewByIndex()");
90 shape
= (XInstCreator
)tEnv
.getObjRelation("Shape");
91 oShape
= shape
.createInstance();
92 XShape oSh
= (XShape
) oShape
;
93 XShapes oShapes
= (XShapes
) tEnv
.getObjRelation("Shapes");
95 boolean result
= false;
97 log
.println("attachShapeToLayer() ... ");
99 oObj
.attachShapeToLayer((XShape
) oShape
,oL
);
102 tRes
.tested("attachShapeToLayer()", result
);
106 * Gets the layer for shape which was attached before. <p>
107 * Has <b> OK </b> status if the names of layer get and
108 * the layer attached before are equal. <p>
109 * The following method tests are to be completed successfully before :
111 * <li> <code> attachShapeToLayer() </code> </li>
114 public void _getLayerForShape() {
115 requiredMethod("attachShapeToLayer()");
116 log
.println("getLayerForShape() ... ");
118 XLayer Lay2
= oObj
.getLayerForShape((XShape
)oShape
);
123 Obj1
= Lay1
.getPropertyValue("Name");
124 Obj2
= Lay2
.getPropertyValue("Name");
125 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
126 e
.printStackTrace(log
);
127 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
128 e
.printStackTrace(log
);
131 tRes
.tested("getLayerForShape()",ValueComparer
.equalValue(Obj1
,Obj2
));
135 * Test removes the layer added before. Number of layers are get before
136 * and after removing.<p>
137 * Has <b> OK </b> status if number of layers decreases by one. <p>
138 * The following method tests are to be completed successfully before :
140 * <li> <code> getLayerForShape() </code> </li>
143 public void _remove () {
144 requiredMethod("getLayerForShape()");
145 boolean result
= true ;
146 // get the current thread's holder
147 log
.println("removing the Layer...");
149 int cntBefore
= oObj
.getCount();
153 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
154 e
.printStackTrace(log
);
158 int cntAfter
= oObj
.getCount();
160 result
= cntBefore
== cntAfter
+ 1;
162 tRes
.tested("remove()", result
);