Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / drawing / _XLayerManager.java
blob01337926fed6415397d323152d2f4bfefe89f8f4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XLayerManager.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.drawing;
33 import lib.MultiMethodTest;
34 import util.ValueComparer;
35 import util.XInstCreator;
37 import com.sun.star.drawing.XLayer;
38 import com.sun.star.drawing.XLayerManager;
39 import com.sun.star.drawing.XShape;
40 import com.sun.star.drawing.XShapes;
41 import com.sun.star.uno.XInterface;
43 /**
44 * Testing <code>com.sun.star.drawing.XLayerManager</code>
45 * interface methods :
46 * <ul>
47 * <li><code> insertNewByIndex()</code></li>
48 * <li><code> remove()</code></li>
49 * <li><code> attachShapeToLayer()</code></li>
50 * <li><code> getLayerForShape()</code></li>
51 * </ul> <p>
52 * This test needs the following object relations :
53 * <ul>
54 * <li> <code>'Shape'</code> (of type <code>util.XInstCreator</code>):
55 * instance creator which can create shapes.</li>
56 * <li> <code>'Shapes'</code>
57 * (of type <code>com.sun.star.drawing.XShapes</code>):
58 * The collection of shapes in the document. Is used
59 * to add new created shapes.</li>
60 * <ul> <p>
61 * Test is <b> NOT </b> multithread compilant. <p>
62 * @see com.sun.star.drawing.XLayerManager
64 public class _XLayerManager extends MultiMethodTest {
66 public XLayerManager oObj = null; // oObj filled by MultiMethodTest
67 XInstCreator shape = null;
68 public XInterface oShape = null;
69 public XLayer oL = null;
71 /**
72 * Inserts a new layer into collection. <p>
73 * Has <b> OK </b> status if the value returned is not null. <p>
75 public void _insertNewByIndex(){
76 log.println("insertNewByName() ... ");
77 oL = oObj.insertNewByIndex(0);
78 tRes.tested("insertNewByIndex()", oL != null);
81 /**
82 * First a shape created and inserted into the document using
83 * relations retrieved. Attaches this shape to layer created before. <p>
84 * Has <b> OK </b> status if the method successfully returns
85 * and no exceptions were thrown. <p>
86 * The following method tests are to be completed successfully before :
87 * <ul>
88 * <li> <code> insertNewByIndex </code> : to have a layer attach to.</li>
89 * </ul>
91 public void _attachShapeToLayer() {
92 requiredMethod("insertNewByIndex()");
93 shape = (XInstCreator)tEnv.getObjRelation("Shape");
94 oShape = shape.createInstance();
95 XShape oSh = (XShape) oShape;
96 XShapes oShapes = (XShapes) tEnv.getObjRelation("Shapes");
97 oShapes.add(oSh);
98 boolean result = false;
100 log.println("attachShapeToLayer() ... ");
102 oObj.attachShapeToLayer((XShape) oShape,oL);
103 result = true;
105 tRes.tested("attachShapeToLayer()", result);
109 * Gets the layer for shape which was attached before. <p>
110 * Has <b> OK </b> status if the names of layer get and
111 * the layer attached before are equal. <p>
112 * The following method tests are to be completed successfully before :
113 * <ul>
114 * <li> <code> attachShapeToLayer() </code> </li>
115 * </ul>
117 public void _getLayerForShape() {
118 requiredMethod("attachShapeToLayer()");
119 log.println("getLayerForShape() ... ");
120 XLayer Lay1 = oL;
121 XLayer Lay2 = oObj.getLayerForShape((XShape)oShape);
122 Object Obj1 = null;
123 Object Obj2 = null;
125 try {
126 Obj1 = Lay1.getPropertyValue("Name");
127 Obj2 = Lay2.getPropertyValue("Name");
128 } catch (com.sun.star.lang.WrappedTargetException e) {
129 e.printStackTrace(log);
130 } catch (com.sun.star.beans.UnknownPropertyException e) {
131 e.printStackTrace(log);
134 tRes.tested("getLayerForShape()",ValueComparer.equalValue(Obj1,Obj2));
138 * Test removes the layer added before. Number of layers are get before
139 * and after removing.<p>
140 * Has <b> OK </b> status if number of layers decreases by one. <p>
141 * The following method tests are to be completed successfully before :
142 * <ul>
143 * <li> <code> getLayerForShape() </code> </li>
144 * </ul>
146 public void _remove () {
147 requiredMethod("getLayerForShape()");
148 boolean result = true ;
149 // get the current thread's holder
150 log.println("removing the Layer...");
152 int cntBefore = oObj.getCount();
154 try {
155 oObj.remove(oL);
156 } catch (com.sun.star.container.NoSuchElementException e) {
157 e.printStackTrace(log);
158 result = false;
161 int cntAfter = oObj.getCount();
163 result = cntBefore == cntAfter + 1;
165 tRes.tested("remove()", result);