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._sw; 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.SOfficeFactory; 33 34 import com.sun.star.drawing.XDrawPage; 35 import com.sun.star.drawing.XDrawPageSupplier; 36 import com.sun.star.drawing.XShape; 37 import com.sun.star.drawing.XShapes; 38 import com.sun.star.lang.XMultiServiceFactory; 39 import com.sun.star.text.XTextDocument; 40 import com.sun.star.uno.UnoRuntime; 41 import com.sun.star.uno.XInterface; 42 43 /** 44 * Test for object which is represented by service 45 * <code>com.sun.star.drawing.Shape</code>. <p> 46 * Object implements the following interfaces : 47 * <ul> 48 * <li> <code>com::sun::star::lang::XComponent</code></li> 49 * <li> <code>com::sun::star::drawing::XShape</code></li> 50 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li> 51 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 52 * <li> <code>com::sun::star::drawing::Shape</code></li> 53 * </ul> <p> 54 * This object test <b> is NOT </b> designed to be run in several 55 * threads concurently. 56 * @see com.sun.star.lang.XComponent 57 * @see com.sun.star.drawing.XShape 58 * @see com.sun.star.drawing.XShapeDescriptor 59 * @see com.sun.star.beans.XPropertySet 60 * @see com.sun.star.drawing.Shape 61 * @see ifc.lang._XComponent 62 * @see ifc.drawing._XShape 63 * @see ifc.drawing._XShapeDescriptor 64 * @see ifc.beans._XPropertySet 65 * @see ifc.drawing._Shape 66 */ 67 public class SwXShape extends TestCase { 68 XTextDocument xTextDoc; 69 SOfficeFactory SOF; 70 71 /** 72 * Creates text document. 73 */ initialize( TestParameters tParam, PrintWriter log )74 protected void initialize( TestParameters tParam, PrintWriter log ) { 75 SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 76 try { 77 log.println( "creating a textdocument" ); 78 xTextDoc = SOF.createTextDoc( null ); 79 } catch ( com.sun.star.uno.Exception e ) { 80 e.printStackTrace( log ); 81 throw new StatusException( "Couldn't create document", e ); 82 } 83 } 84 85 /** 86 * Disposes text document. 87 */ cleanup( TestParameters tParam, PrintWriter log )88 protected void cleanup( TestParameters tParam, PrintWriter log ) { 89 log.println( " disposing xTextDoc " ); 90 util.DesktopTools.closeDoc(xTextDoc); 91 } 92 93 /** 94 * Creating a Testenvironment for the interfaces to be tested. At first, 95 * DrawPage is gotten from text document using <code>XDrawPageSupplier</code> 96 * interface. Then shape (rectangle) is created and added to DrawPage 97 * obtained before, then returned as a test component. 98 */ createTestEnvironment( TestParameters tParam, PrintWriter log )99 public synchronized TestEnvironment createTestEnvironment( 100 TestParameters tParam, PrintWriter log ) throws StatusException { 101 XInterface oObj = null; 102 XDrawPage oDP = null; 103 XShapes oShapes = null; 104 105 log.println( "creating a test environment" ); 106 log.println( "getting Drawpage" ); 107 XDrawPageSupplier oDPS = (XDrawPageSupplier) 108 UnoRuntime.queryInterface(XDrawPageSupplier.class, xTextDoc); 109 oDP = oDPS.getDrawPage(); 110 111 log.println( "getting Shape" ); 112 oShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, oDP); 113 oObj = SOF.createShape(xTextDoc,5000,3500,7500,5000,"Rectangle"); 114 oShapes.add((XShape) oObj); 115 116 for ( int i = 0; i < 9; i++){ 117 XInterface oShape = SOF.createShape(xTextDoc, 118 5000 + 100*i,3500,7500,5000,"Rectangle"); 119 oShapes.add((XShape) oShape); 120 } 121 122 log.println( "creating a new environment for XShape object" ); 123 TestEnvironment tEnv = new TestEnvironment( oObj ); 124 125 return tEnv; 126 } // finish method getTestEnvironment 127 128 } // finish class SwXShape 129 130