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.SOfficeFactory; 37 38 import com.sun.star.container.XIndexAccess; 39 import com.sun.star.container.XNameAccess; 40 import com.sun.star.drawing.XLayer; 41 import com.sun.star.drawing.XLayerManager; 42 import com.sun.star.drawing.XLayerSupplier; 43 import com.sun.star.lang.XComponent; 44 import com.sun.star.lang.XMultiServiceFactory; 45 import com.sun.star.uno.AnyConverter; 46 import com.sun.star.uno.Type; 47 import com.sun.star.uno.UnoRuntime; 48 import com.sun.star.uno.XInterface; 49 50 /** 51 * Test for object which is represented by service 52 * <code>com.sun.star.drawing.Layer</code>. <p> 53 * Object implements the following interfaces : 54 * <ul> 55 * <li> <code>com::sun::star::drawing::Layer</code></li> 56 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 57 * </ul> 58 * @see com.sun.star.drawing.Layer 59 * @see com.sun.star.beans.XPropertySet 60 * @see ifc.drawing._Layer 61 * @see ifc.beans._XPropertySet 62 */ 63 public class SdLayer extends TestCase { 64 XComponent xDrawDoc; 65 66 /** 67 * Creates Drawing document. 68 */ 69 protected void initialize(TestParameters Param, PrintWriter log) { 70 // get a soffice factory object 71 SOfficeFactory SOF = SOfficeFactory.getFactory( 72 (XMultiServiceFactory)Param.getMSF()); 73 74 try { 75 log.println( "creating a draw document" ); 76 xDrawDoc = SOF.createDrawDoc(null); 77 } catch (com.sun.star.uno.Exception e) { 78 e.printStackTrace( log ); 79 throw new StatusException("Couldn't create document", e); 80 } 81 } 82 83 /** 84 * Disposes Drawing document. 85 */ 86 protected void cleanup( TestParameters Param, PrintWriter log) { 87 log.println("disposing xDrawDoc"); 88 util.DesktopTools.closeDoc(xDrawDoc);; 89 } 90 91 /** 92 * Creating a Testenvironment for the interfaces to be tested. 93 * Retrieves the layer manager from the document and takes one of the layer. 94 * The obtained layer is the instance of the service 95 * <code>com.sun.star.drawing.Layer</code>. 96 * @see com.sun.star.drawing.Layer 97 */ 98 protected synchronized TestEnvironment createTestEnvironment( 99 TestParameters Param, PrintWriter log) { 100 101 XInterface oObj = null; 102 XLayerManager oLM = null; 103 104 // creation of testobject here 105 // first we write what we are intend to do to log file 106 log.println( "creating a test environment" ); 107 108 // get the drawpage of drawing here 109 log.println( "getting LayerManager" ); 110 XLayerSupplier oLS = (XLayerSupplier) 111 UnoRuntime.queryInterface(XLayerSupplier.class, xDrawDoc); 112 XNameAccess oNA = oLS.getLayerManager(); 113 oLM = (XLayerManager) 114 UnoRuntime.queryInterface(XLayerManager.class, oNA); 115 XIndexAccess oIA = (XIndexAccess) 116 UnoRuntime.queryInterface(XIndexAccess.class,oLM); 117 log.println( "getting LayerManager" ); 118 try { 119 oObj = (XLayer) AnyConverter.toObject( 120 new Type(XLayer.class),oIA.getByIndex(0)); 121 } catch (com.sun.star.lang.WrappedTargetException e) { 122 e.printStackTrace( log ); 123 throw new StatusException("Couldn't get by index", e); 124 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 125 e.printStackTrace( log ); 126 throw new StatusException("Couldn't get by index", e); 127 } catch (com.sun.star.lang.IllegalArgumentException e) { 128 e.printStackTrace( log ); 129 throw new StatusException("Couldn't get by index", e); 130 } 131 132 log.println( "creating a new environment for drawpage object" ); 133 TestEnvironment tEnv = new TestEnvironment( oObj ); 134 135 return tEnv; 136 } // finish method createTestEnvironment 137 138 } // finish class SdLayer 139 140