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