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 mod._sd; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.InstCreator; 37 import util.SOfficeFactory; 38 import util.ShapeDsc; 39 40 import com.sun.star.container.XIndexAccess; 41 import com.sun.star.drawing.XDrawPage; 42 import com.sun.star.drawing.XDrawPages; 43 import com.sun.star.drawing.XDrawPagesSupplier; 44 import com.sun.star.drawing.XLayerSupplier; 45 import com.sun.star.drawing.XShapes; 46 import com.sun.star.lang.XComponent; 47 import com.sun.star.lang.XMultiServiceFactory; 48 import com.sun.star.uno.AnyConverter; 49 import com.sun.star.uno.Type; 50 import com.sun.star.uno.UnoRuntime; 51 import com.sun.star.uno.XInterface; 52 53 /** 54 * Test for object which is represented by service 55 * <code>com.sun.star.drawing.LayerManager</code>. <p> 56 * Object implements the following interfaces : 57 * <ul> 58 * <li> <code>com::sun::star::drawing::XLayerManager</code></li> 59 * <li> <code>com::sun::star::container::XNameAccess</code></li> 60 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 61 * <li> <code>com::sun::star::container::XElementAccess</code></li> 62 * </ul> 63 * @see com.sun.star.drawing.LayerManager 64 * @see com.sun.star.drawing.XLayerManager 65 * @see com.sun.star.container.XNameAccess 66 * @see com.sun.star.container.XIndexAccess 67 * @see com.sun.star.container.XElementAccess 68 * @see ifc.drawing._XLayerManager 69 * @see ifc.container._XNameAccess 70 * @see ifc.container._XIndexAccess 71 * @see ifc.container._XElementAccess 72 */ 73 public class SdLayerManager extends TestCase { 74 XComponent xDrawDoc; 75 76 /** 77 * Creates Drawing document. 78 */ 79 protected void initialize(TestParameters Param, PrintWriter log) { 80 // get a soffice factory object 81 SOfficeFactory SOF = SOfficeFactory.getFactory( 82 (XMultiServiceFactory)Param.getMSF()); 83 84 try { 85 log.println("creating a draw document"); 86 xDrawDoc = SOF.createDrawDoc(null); 87 } catch (com.sun.star.uno.Exception e) { 88 // Some exception occures.FAILED 89 e.printStackTrace( log ); 90 throw new StatusException( "Couldn't create document", e ); 91 } 92 } 93 94 /** 95 * Disposes Drawing document. 96 */ 97 protected void cleanup( TestParameters Param, PrintWriter log) { 98 log.println("disposing xDrawDoc"); 99 util.DesktopTools.closeDoc(xDrawDoc);; 100 } 101 102 /** 103 * Creating a Testenvironment for the interfaces to be tested. 104 * Retrieves the layer manager using the interface <code>XLayerSupplier</code>. 105 * The manager is the instance of the service 106 * <code>com.sun.star.drawing.LayerManager</code>. Creates a rectangle shape. 107 * Retrieves the collection of the draw pages and take one of them. 108 * <ul> 109 * <li> <code>'Shape'</code> for 110 * {@link ifc.drawing._XLayerManager}(the created shape)</li> 111 * <li> <code>'Shapes'</code> for 112 * {@link ifc.drawing._XLayerManager}(the shape collection of 113 * the retrived draw page)</li> 114 * </ul> 115 * @see com.sun.star.drawing.XLayerSupplier 116 * @see com.sun.star.drawing.LayerManager 117 */ 118 protected synchronized TestEnvironment createTestEnvironment( 119 TestParameters Param, PrintWriter log) { 120 121 // creation of testobject here 122 // first we write what we are intend to do to log file 123 log.println( "creating a test environment" ); 124 125 // create testobject here 126 XLayerSupplier oLS = (XLayerSupplier) 127 UnoRuntime.queryInterface(XLayerSupplier.class, xDrawDoc); 128 XInterface oObj = oLS.getLayerManager(); 129 130 log.println( "creating a new environment for XLayerManager object" ); 131 TestEnvironment tEnv = new TestEnvironment( oObj ); 132 133 ShapeDsc sDsc = new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle"); 134 log.println( "adding Shape as mod relation to environment" ); 135 tEnv.addObjRelation("Shape", new InstCreator(xDrawDoc, sDsc)); 136 137 138 // get the drawpage of drawing here 139 log.println( "getting Drawpage" ); 140 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 141 UnoRuntime.queryInterface(XDrawPagesSupplier.class,xDrawDoc); 142 XDrawPages oDPn = oDPS.getDrawPages(); 143 XIndexAccess oDPi = (XIndexAccess) 144 UnoRuntime.queryInterface(XIndexAccess.class,oDPn); 145 146 XDrawPage oDP = null; 147 try { 148 oDP = (XDrawPage) AnyConverter.toObject( 149 new Type(XDrawPage.class),oDPi.getByIndex(0)); 150 } catch (com.sun.star.lang.WrappedTargetException e) { 151 e.printStackTrace( log ); 152 throw new StatusException("Couldn't get by index", e); 153 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 154 e.printStackTrace( log ); 155 throw new StatusException("Couldn't get by index", e); 156 } catch (com.sun.star.lang.IllegalArgumentException e) { 157 e.printStackTrace( log ); 158 throw new StatusException("Couldn't get by index", e); 159 } 160 161 XShapes oShapes = (XShapes) 162 UnoRuntime.queryInterface(XShapes.class, oDP); 163 164 log.println( "adding Shapes as mod relation to environment" ); 165 tEnv.addObjRelation("Shapes", oShapes); 166 167 return tEnv; 168 } // finish method getTestEnvironment 169 170 } // finish class SdLayerManager 171 172