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