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._svx; 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.DefaultDsc; 37 import util.DrawTools; 38 import util.InstCreator; 39 import util.SOfficeFactory; 40 import util.utils; 41 42 import com.sun.star.beans.XPropertySet; 43 import com.sun.star.drawing.XShape; 44 import com.sun.star.lang.XComponent; 45 import com.sun.star.lang.XMultiServiceFactory; 46 import com.sun.star.style.XStyle; 47 import com.sun.star.uno.AnyConverter; 48 import com.sun.star.uno.Type; 49 import com.sun.star.uno.UnoRuntime; 50 import com.sun.star.uno.XInterface; 51 52 /** 53 * Test for object which is represented by service 54 * <code>com.sun.star.drawing.Shape</code>. <p> 55 * 56 * Object implements the following interfaces : 57 * <ul> 58 * <li> <code>com::sun::star::style::ParagraphProperties</code></li> 59 * <li> <code>com::sun::star::drawing::LineProperties</code></li> 60 * <li> <code>com::sun::star::drawing::FillProperties</code></li> 61 * <li> <code>com::sun::star::drawing::TextShape</code></li> 62 * <li> <code>com::sun::star::drawing::ShadowProperties</code></li> 63 * <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li> 64 * <li> <code>com::sun::star::style::CharacterProperties</code></li> 65 * <li> <code>com::sun::star::drawing::RotationDescriptor</code></li> 66 * <li> <code>com::sun::star::text::XTextRange</code></li> 67 * <li> <code>com::sun::star::drawing::XShape</code></li> 68 * <li> <code>com::sun::star::lang::XComponent</code></li> 69 * <li> <code>com::sun::star::drawing::TextProperties</code></li> 70 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 71 * <li> <code>com::sun::star::text::XText</code></li> 72 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li> 73 * <li> <code>com::sun::star::text::XSimpleText</code></li> 74 * <li> <code>com::sun::star::drawing::Shape</code></li> 75 * </ul> <p> 76 * 77 * The following files used by this test : 78 * <ul> 79 * <li><b> SvxShape.sxd </b> : this document is loaded for 80 * adding a shape tested to it. </li> 81 * </ul> <p> 82 * 83 * This object test <b> is NOT </b> designed to be run in several 84 * threads concurently. 85 * 86 * @see com.sun.star.style.ParagraphProperties 87 * @see com.sun.star.drawing.LineProperties 88 * @see com.sun.star.drawing.FillProperties 89 * @see com.sun.star.drawing.TextShape 90 * @see com.sun.star.drawing.ShadowProperties 91 * @see com.sun.star.drawing.XGluePointsSupplier 92 * @see com.sun.star.style.CharacterProperties 93 * @see com.sun.star.drawing.RotationDescriptor 94 * @see com.sun.star.text.XTextRange 95 * @see com.sun.star.drawing.XShape 96 * @see com.sun.star.lang.XComponent 97 * @see com.sun.star.drawing.TextProperties 98 * @see com.sun.star.beans.XPropertySet 99 * @see com.sun.star.text.XText 100 * @see com.sun.star.drawing.XShapeDescriptor 101 * @see com.sun.star.text.XSimpleText 102 * @see com.sun.star.drawing.Shape 103 * @see ifc.style._ParagraphProperties 104 * @see ifc.drawing._LineProperties 105 * @see ifc.drawing._FillProperties 106 * @see ifc.drawing._TextShape 107 * @see ifc.drawing._ShadowProperties 108 * @see ifc.drawing._XGluePointsSupplier 109 * @see ifc.style._CharacterProperties 110 * @see ifc.drawing._RotationDescriptor 111 * @see ifc.text._XTextRange 112 * @see ifc.drawing._XShape 113 * @see ifc.lang._XComponent 114 * @see ifc.drawing._TextProperties 115 * @see ifc.beans._XPropertySet 116 * @see ifc.text._XText 117 * @see ifc.drawing._XShapeDescriptor 118 * @see ifc.text._XSimpleText 119 * @see ifc.drawing._Shape 120 */ 121 public class SvxShape extends TestCase { 122 123 static XComponent xDrawDoc; 124 125 /** 126 * Loads a Draw document with name 'SvxShape.sxd' from test 127 * documents directory 128 */ 129 protected void initialize( TestParameters tParam, PrintWriter log ) { 130 131 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 132 133 try { 134 log.println( "creating a drawdoc" ); 135 xDrawDoc = SOF.loadDocument( 136 utils.getFullTestURL("SvxShape.sxd")); 137 } catch ( com.sun.star.uno.Exception e ) { 138 // Some exception occures.FAILED 139 e.printStackTrace( log ); 140 throw new StatusException( "Couldn't create document", e ); 141 } 142 } 143 144 /** 145 * Disposes the Draw document loaded before. 146 */ 147 protected void cleanup( TestParameters tParam, PrintWriter log ) { 148 log.println( " disposing xDrawDoc " ); 149 util.DesktopTools.closeDoc(xDrawDoc); 150 } 151 152 /** 153 * Creating a Testenvironment for the interfaces to be tested. 154 * Creates an instance of the service 155 * <code>com.sun.star.drawing.EllipseShape</code> as tested component 156 * and adds it to the document. 157 * Object relations created : 158 * <ul> 159 * <li> <code>'Style1', 'Style2'</code> for 160 * {@link ifc.drawing._Shape} : 161 * two values of 'Style' property. The first is taken 162 * from the shape tested, the second from another 163 * shape added to the draw page. </li> 164 * <li> <code>'XTEXTINFO'</code> for 165 * {@link ifc.text._XText} : 166 * creator which can create instnaces of 167 * <code>com.sun.star.text.TextField.URL</code> 168 * service. </li> 169 * </ul> 170 */ 171 protected TestEnvironment createTestEnvironment 172 (TestParameters tParam, PrintWriter log) { 173 174 XInterface oObj = null; 175 XShape oShape = null; 176 177 // creation of testobject here 178 // first we write what we are intend to do to log file 179 log.println( "creating a test environment" ); 180 181 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 182 oShape = SOF.createShape(xDrawDoc,3000,4500,15000,1000,"Text"); 183 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape); 184 oObj = oShape ; 185 186 187 // create test environment here 188 TestEnvironment tEnv = new TestEnvironment( oShape ); 189 190 // adding relations for Shape service 191 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Text"); 192 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape); 193 194 log.println( "adding two style as ObjRelation for ShapeDescriptor" ); 195 XPropertySet oShapeProps = (XPropertySet) 196 UnoRuntime.queryInterface(XPropertySet.class,oObj); 197 XStyle aStyle = null; 198 try { 199 aStyle = (XStyle) AnyConverter.toObject( 200 new Type(XStyle.class),oShapeProps.getPropertyValue("Style")); 201 } catch (com.sun.star.lang.WrappedTargetException e) { 202 } catch (com.sun.star.beans.UnknownPropertyException e) { 203 } catch (com.sun.star.lang.IllegalArgumentException e) { 204 } 205 tEnv.addObjRelation("Style1",aStyle); 206 207 oShapeProps = (XPropertySet) UnoRuntime.queryInterface 208 (XPropertySet.class,oShape); 209 try { 210 aStyle = (XStyle) AnyConverter.toObject( 211 new Type(XStyle.class),oShapeProps.getPropertyValue("Style")); 212 } catch (com.sun.star.lang.WrappedTargetException e) { 213 } catch (com.sun.star.beans.UnknownPropertyException e) { 214 } catch (com.sun.star.lang.IllegalArgumentException e) { 215 } 216 tEnv.addObjRelation("Style2",aStyle); 217 218 // adding relation for XText 219 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent", 220 "com.sun.star.text.TextField.URL"); 221 log.println( " adding InstCreator object" ); 222 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) ); 223 224 return tEnv; 225 } // finish method getTestEnvironment 226 227 } // finish class SvxShape 228