2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
22 import util
.ValueComparer
;
23 import util
.XInstCreator
;
25 import com
.sun
.star
.drawing
.XLayer
;
26 import com
.sun
.star
.drawing
.XLayerManager
;
27 import com
.sun
.star
.drawing
.XShape
;
28 import com
.sun
.star
.drawing
.XShapes
;
29 import com
.sun
.star
.uno
.XInterface
;
32 * Testing <code>com.sun.star.drawing.XLayerManager</code>
35 * <li><code> insertNewByIndex()</code></li>
36 * <li><code> remove()</code></li>
37 * <li><code> attachShapeToLayer()</code></li>
38 * <li><code> getLayerForShape()</code></li>
40 * This test needs the following object relations :
42 * <li> <code>'Shape'</code> (of type <code>util.XInstCreator</code>):
43 * instance creator which can create shapes.</li>
44 * <li> <code>'Shapes'</code>
45 * (of type <code>com.sun.star.drawing.XShapes</code>):
46 * The collection of shapes in the document. Is used
47 * to add new created shapes.</li>
49 * Test is <b> NOT </b> multithread compliant. <p>
50 * @see com.sun.star.drawing.XLayerManager
52 public class _XLayerManager
extends MultiMethodTest
{
54 public XLayerManager oObj
= null; // oObj filled by MultiMethodTest
55 XInstCreator shape
= null;
56 public XInterface oShape
= null;
57 public XLayer oL
= null;
60 * Inserts a new layer into collection. <p>
61 * Has <b> OK </b> status if the value returned is not null. <p>
63 public void _insertNewByIndex(){
64 log
.println("insertNewByName() ... ");
65 oL
= oObj
.insertNewByIndex(0);
66 tRes
.tested("insertNewByIndex()", oL
!= null);
70 * First a shape created and inserted into the document using
71 * relations retrieved. Attaches this shape to layer created before. <p>
72 * Has <b> OK </b> status if the method successfully returns
73 * and no exceptions were thrown. <p>
74 * The following method tests are to be completed successfully before :
76 * <li> <code> insertNewByIndex </code> : to have a layer attach to.</li>
79 public void _attachShapeToLayer() {
80 requiredMethod("insertNewByIndex()");
81 shape
= (XInstCreator
)tEnv
.getObjRelation("Shape");
82 oShape
= shape
.createInstance();
83 XShape oSh
= (XShape
) oShape
;
84 XShapes oShapes
= (XShapes
) tEnv
.getObjRelation("Shapes");
86 boolean result
= false;
88 log
.println("attachShapeToLayer() ... ");
90 oObj
.attachShapeToLayer((XShape
) oShape
,oL
);
93 tRes
.tested("attachShapeToLayer()", result
);
97 * Gets the layer for shape which was attached before. <p>
98 * Has <b> OK </b> status if the names of layer get and
99 * the layer attached before are equal. <p>
100 * The following method tests are to be completed successfully before :
102 * <li> <code> attachShapeToLayer() </code> </li>
105 public void _getLayerForShape() {
106 requiredMethod("attachShapeToLayer()");
107 log
.println("getLayerForShape() ... ");
109 XLayer Lay2
= oObj
.getLayerForShape((XShape
)oShape
);
114 Obj1
= Lay1
.getPropertyValue("Name");
115 Obj2
= Lay2
.getPropertyValue("Name");
116 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
117 e
.printStackTrace(log
);
118 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
119 e
.printStackTrace(log
);
122 tRes
.tested("getLayerForShape()",ValueComparer
.equalValue(Obj1
,Obj2
));
126 * Test removes the layer added before. Number of layers are get before
127 * and after removing.<p>
128 * Has <b> OK </b> status if number of layers decreases by one. <p>
129 * The following method tests are to be completed successfully before :
131 * <li> <code> getLayerForShape() </code> </li>
134 public void _remove () {
135 requiredMethod("getLayerForShape()");
136 boolean result
= true ;
137 // get the current thread's holder
138 log
.println("removing the Layer...");
140 int cntBefore
= oObj
.getCount();
144 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
145 e
.printStackTrace(log
);
149 int cntAfter
= oObj
.getCount();
151 result
= cntBefore
== cntAfter
+ 1;
153 tRes
.tested("remove()", result
);