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