1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 package ifc.drawing;
29 
30 import lib.MultiMethodTest;
31 import util.ValueComparer;
32 import util.XInstCreator;
33 
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;
39 
40 /**
41 * Testing <code>com.sun.star.drawing.XLayerManager</code>
42 * interface methods :
43 * <ul>
44 *  <li><code> insertNewByIndex()</code></li>
45 *  <li><code> remove()</code></li>
46 *  <li><code> attachShapeToLayer()</code></li>
47 *  <li><code> getLayerForShape()</code></li>
48 * </ul> <p>
49 * This test needs the following object relations :
50 * <ul>
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>
57 * <ul> <p>
58 * Test is <b> NOT </b> multithread compilant. <p>
59 * @see com.sun.star.drawing.XLayerManager
60 */
61 public class _XLayerManager extends MultiMethodTest {
62 
63     public XLayerManager oObj = null;                // oObj filled by MultiMethodTest
64     XInstCreator shape = null;
65     public XInterface oShape = null;
66     public XLayer oL = null;
67 
68     /**
69      * Inserts a new layer into collection. <p>
70      * Has <b> OK </b> status if the value returned is not null. <p>
71      */
72     public void _insertNewByIndex(){
73         log.println("insertNewByName() ... ");
74         oL = oObj.insertNewByIndex(0);
75         tRes.tested("insertNewByIndex()", oL != null);
76     }
77 
78     /**
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 :
84     * <ul>
85     *  <li> <code> insertNewByIndex </code> : to have a layer attach to.</li>
86     * </ul>
87     */
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");
94         oShapes.add(oSh);
95         boolean result = false;
96 
97         log.println("attachShapeToLayer() ... ");
98 
99         oObj.attachShapeToLayer((XShape) oShape,oL);
100         result = true;
101 
102         tRes.tested("attachShapeToLayer()", result);
103     }
104 
105     /**
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 :
110     * <ul>
111     *  <li> <code> attachShapeToLayer() </code>  </li>
112     * </ul>
113     */
114     public void _getLayerForShape() {
115         requiredMethod("attachShapeToLayer()");
116         log.println("getLayerForShape() ... ");
117         XLayer Lay1 = oL;
118         XLayer Lay2 = oObj.getLayerForShape((XShape)oShape);
119         Object Obj1 = null;
120         Object Obj2 = null;
121 
122         try {
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);
129         }
130 
131         tRes.tested("getLayerForShape()",ValueComparer.equalValue(Obj1,Obj2));
132     }
133 
134     /**
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 :
139     * <ul>
140     *  <li> <code> getLayerForShape() </code>  </li>
141     * </ul>
142     */
143     public void _remove () {
144         requiredMethod("getLayerForShape()");
145         boolean result = true ;
146         // get the current thread's holder
147         log.println("removing the Layer...");
148 
149         int cntBefore = oObj.getCount();
150 
151         try {
152             oObj.remove(oL);
153         } catch (com.sun.star.container.NoSuchElementException e) {
154             e.printStackTrace(log);
155             result = false;
156         }
157 
158         int cntAfter = oObj.getCount();
159 
160         result = cntBefore == cntAfter + 1;
161 
162         tRes.tested("remove()", result);
163     }
164 }
165 
166 
167