1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._sd; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.InstCreator; 33 import util.SOfficeFactory; 34 import util.ShapeDsc; 35 36 import com.sun.star.container.XIndexAccess; 37 import com.sun.star.drawing.XDrawPage; 38 import com.sun.star.drawing.XDrawPages; 39 import com.sun.star.drawing.XDrawPagesSupplier; 40 import com.sun.star.drawing.XLayerSupplier; 41 import com.sun.star.drawing.XShapes; 42 import com.sun.star.lang.XComponent; 43 import com.sun.star.lang.XMultiServiceFactory; 44 import com.sun.star.uno.AnyConverter; 45 import com.sun.star.uno.Type; 46 import com.sun.star.uno.UnoRuntime; 47 import com.sun.star.uno.XInterface; 48 49 /** 50 * Test for object which is represented by service 51 * <code>com.sun.star.drawing.LayerManager</code>. <p> 52 * Object implements the following interfaces : 53 * <ul> 54 * <li> <code>com::sun::star::drawing::XLayerManager</code></li> 55 * <li> <code>com::sun::star::container::XNameAccess</code></li> 56 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 57 * <li> <code>com::sun::star::container::XElementAccess</code></li> 58 * </ul> 59 * @see com.sun.star.drawing.LayerManager 60 * @see com.sun.star.drawing.XLayerManager 61 * @see com.sun.star.container.XNameAccess 62 * @see com.sun.star.container.XIndexAccess 63 * @see com.sun.star.container.XElementAccess 64 * @see ifc.drawing._XLayerManager 65 * @see ifc.container._XNameAccess 66 * @see ifc.container._XIndexAccess 67 * @see ifc.container._XElementAccess 68 */ 69 public class SdLayerManager extends TestCase { 70 XComponent xDrawDoc; 71 72 /** 73 * Creates Drawing document. 74 */ initialize(TestParameters Param, PrintWriter log)75 protected void initialize(TestParameters Param, PrintWriter log) { 76 // get a soffice factory object 77 SOfficeFactory SOF = SOfficeFactory.getFactory( 78 (XMultiServiceFactory)Param.getMSF()); 79 80 try { 81 log.println("creating a draw document"); 82 xDrawDoc = SOF.createDrawDoc(null); 83 } catch (com.sun.star.uno.Exception e) { 84 // Some exception occures.FAILED 85 e.printStackTrace( log ); 86 throw new StatusException( "Couldn't create document", e ); 87 } 88 } 89 90 /** 91 * Disposes Drawing document. 92 */ cleanup( TestParameters Param, PrintWriter log)93 protected void cleanup( TestParameters Param, PrintWriter log) { 94 log.println("disposing xDrawDoc"); 95 util.DesktopTools.closeDoc(xDrawDoc); 96 } 97 98 /** 99 * Creating a Testenvironment for the interfaces to be tested. 100 * Retrieves the layer manager using the interface <code>XLayerSupplier</code>. 101 * The manager is the instance of the service 102 * <code>com.sun.star.drawing.LayerManager</code>. Creates a rectangle shape. 103 * Retrieves the collection of the draw pages and take one of them. 104 * <ul> 105 * <li> <code>'Shape'</code> for 106 * {@link ifc.drawing._XLayerManager}(the created shape)</li> 107 * <li> <code>'Shapes'</code> for 108 * {@link ifc.drawing._XLayerManager}(the shape collection of 109 * the retrived draw page)</li> 110 * </ul> 111 * @see com.sun.star.drawing.XLayerSupplier 112 * @see com.sun.star.drawing.LayerManager 113 */ createTestEnvironment( TestParameters Param, PrintWriter log)114 protected synchronized TestEnvironment createTestEnvironment( 115 TestParameters Param, PrintWriter log) { 116 117 // creation of testobject here 118 // first we write what we are intend to do to log file 119 log.println( "creating a test environment" ); 120 121 // create testobject here 122 XLayerSupplier oLS = (XLayerSupplier) 123 UnoRuntime.queryInterface(XLayerSupplier.class, xDrawDoc); 124 XInterface oObj = oLS.getLayerManager(); 125 126 log.println( "creating a new environment for XLayerManager object" ); 127 TestEnvironment tEnv = new TestEnvironment( oObj ); 128 129 ShapeDsc sDsc = new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle"); 130 log.println( "adding Shape as mod relation to environment" ); 131 tEnv.addObjRelation("Shape", new InstCreator(xDrawDoc, sDsc)); 132 133 134 // get the drawpage of drawing here 135 log.println( "getting Drawpage" ); 136 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 137 UnoRuntime.queryInterface(XDrawPagesSupplier.class,xDrawDoc); 138 XDrawPages oDPn = oDPS.getDrawPages(); 139 XIndexAccess oDPi = (XIndexAccess) 140 UnoRuntime.queryInterface(XIndexAccess.class,oDPn); 141 142 XDrawPage oDP = null; 143 try { 144 oDP = (XDrawPage) AnyConverter.toObject( 145 new Type(XDrawPage.class),oDPi.getByIndex(0)); 146 } catch (com.sun.star.lang.WrappedTargetException e) { 147 e.printStackTrace( log ); 148 throw new StatusException("Couldn't get by index", e); 149 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 150 e.printStackTrace( log ); 151 throw new StatusException("Couldn't get by index", e); 152 } catch (com.sun.star.lang.IllegalArgumentException e) { 153 e.printStackTrace( log ); 154 throw new StatusException("Couldn't get by index", e); 155 } 156 157 XShapes oShapes = (XShapes) 158 UnoRuntime.queryInterface(XShapes.class, oDP); 159 160 log.println( "adding Shapes as mod relation to environment" ); 161 tEnv.addObjRelation("Shapes", oShapes); 162 163 return tEnv; 164 } // finish method getTestEnvironment 165 166 } // finish class SdLayerManager 167 168