1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.drawing;
25 
26 import lib.MultiMethodTest;
27 import util.ValueComparer;
28 import util.XInstCreator;
29 
30 import com.sun.star.drawing.XLayer;
31 import com.sun.star.drawing.XLayerManager;
32 import com.sun.star.drawing.XShape;
33 import com.sun.star.drawing.XShapes;
34 import com.sun.star.uno.XInterface;
35 
36 /**
37 * Testing <code>com.sun.star.drawing.XLayerManager</code>
38 * interface methods :
39 * <ul>
40 *  <li><code> insertNewByIndex()</code></li>
41 *  <li><code> remove()</code></li>
42 *  <li><code> attachShapeToLayer()</code></li>
43 *  <li><code> getLayerForShape()</code></li>
44 * </ul> <p>
45 * This test needs the following object relations :
46 * <ul>
47 *  <li> <code>'Shape'</code> (of type <code>util.XInstCreator</code>):
48 *   instance creator which can create shapes.</li>
49 *  <li> <code>'Shapes'</code>
50 *   (of type <code>com.sun.star.drawing.XShapes</code>):
51 *   The collection of shapes in the document. Is used
52 *   to add new created shapes.</li>
53 * <ul> <p>
54 * Test is <b> NOT </b> multithread compilant. <p>
55 * @see com.sun.star.drawing.XLayerManager
56 */
57 public class _XLayerManager extends MultiMethodTest {
58 
59     public XLayerManager oObj = null;                // oObj filled by MultiMethodTest
60     XInstCreator shape = null;
61     public XInterface oShape = null;
62     public XLayer oL = null;
63 
64     /**
65      * Inserts a new layer into collection. <p>
66      * Has <b> OK </b> status if the value returned is not null. <p>
67      */
_insertNewByIndex()68     public void _insertNewByIndex(){
69         log.println("insertNewByName() ... ");
70         oL = oObj.insertNewByIndex(0);
71         tRes.tested("insertNewByIndex()", oL != null);
72     }
73 
74     /**
75     * First a shape created and inserted into the document using
76     * relations retrieved. Attaches this shape to layer created before. <p>
77     * Has <b> OK </b> status if the method successfully returns
78     * and no exceptions were thrown. <p>
79     * The following method tests are to be completed successfully before :
80     * <ul>
81     *  <li> <code> insertNewByIndex </code> : to have a layer attach to.</li>
82     * </ul>
83     */
_attachShapeToLayer()84     public void _attachShapeToLayer() {
85         requiredMethod("insertNewByIndex()");
86         shape = (XInstCreator)tEnv.getObjRelation("Shape");
87         oShape = shape.createInstance();
88         XShape oSh = (XShape) oShape;
89         XShapes oShapes = (XShapes) tEnv.getObjRelation("Shapes");
90         oShapes.add(oSh);
91         boolean result = false;
92 
93         log.println("attachShapeToLayer() ... ");
94 
95         oObj.attachShapeToLayer((XShape) oShape,oL);
96         result = true;
97 
98         tRes.tested("attachShapeToLayer()", result);
99     }
100 
101     /**
102     * Gets the layer for shape which was attached before. <p>
103     * Has <b> OK </b> status if the names of layer get and
104     * the layer attached before are equal. <p>
105     * The following method tests are to be completed successfully before :
106     * <ul>
107     *  <li> <code> attachShapeToLayer() </code>  </li>
108     * </ul>
109     */
_getLayerForShape()110     public void _getLayerForShape() {
111         requiredMethod("attachShapeToLayer()");
112         log.println("getLayerForShape() ... ");
113         XLayer Lay1 = oL;
114         XLayer Lay2 = oObj.getLayerForShape((XShape)oShape);
115         Object Obj1 = null;
116         Object Obj2 = null;
117 
118         try {
119             Obj1 = Lay1.getPropertyValue("Name");
120             Obj2 = Lay2.getPropertyValue("Name");
121         } catch (com.sun.star.lang.WrappedTargetException e) {
122             e.printStackTrace(log);
123         } catch (com.sun.star.beans.UnknownPropertyException e) {
124             e.printStackTrace(log);
125         }
126 
127         tRes.tested("getLayerForShape()",ValueComparer.equalValue(Obj1,Obj2));
128     }
129 
130     /**
131     * Test removes the layer added before. Number of layers are get before
132     * and after removing.<p>
133     * Has <b> OK </b> status if number of layers decreases by one. <p>
134     * The following method tests are to be completed successfully before :
135     * <ul>
136     *  <li> <code> getLayerForShape() </code>  </li>
137     * </ul>
138     */
_remove()139     public void _remove () {
140         requiredMethod("getLayerForShape()");
141         boolean result = true ;
142         // get the current thread's holder
143         log.println("removing the Layer...");
144 
145         int cntBefore = oObj.getCount();
146 
147         try {
148             oObj.remove(oL);
149         } catch (com.sun.star.container.NoSuchElementException e) {
150             e.printStackTrace(log);
151             result = false;
152         }
153 
154         int cntAfter = oObj.getCount();
155 
156         result = cntBefore == cntAfter + 1;
157 
158         tRes.tested("remove()", result);
159     }
160 }
161 
162 
163