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.DrawTools; 37 import util.InstCreator; 38 import util.SOfficeFactory; 39 import util.utils; 40 41 import com.sun.star.awt.Point; 42 import com.sun.star.awt.Size; 43 import com.sun.star.beans.XPropertySet; 44 import com.sun.star.drawing.PolyPolygonBezierCoords; 45 import com.sun.star.drawing.PolygonFlags; 46 import com.sun.star.drawing.XShape; 47 import com.sun.star.lang.XComponent; 48 import com.sun.star.lang.XMultiServiceFactory; 49 import com.sun.star.style.XStyle; 50 import com.sun.star.uno.AnyConverter; 51 import com.sun.star.uno.Type; 52 import com.sun.star.uno.UnoRuntime; 53 import com.sun.star.uno.XInterface; 54 55 /** 56 * Test for object which is represented by service 57 * <code>com.sun.star.drawing.ClosedBezierShape</code>. <p> 58 * Object implements the following interfaces : 59 * <ul> 60 * <li> <code>com::sun::star::style::ParagraphProperties</code></li> 61 * <li> <code>com::sun::star::drawing::PolyPolygonBezierDescriptor</code></li> 62 * <li> <code>com::sun::star::drawing::LineProperties</code></li> 63 * <li> <code>com::sun::star::drawing::FillProperties</code></li> 64 * <li> <code>com::sun::star::drawing::ShadowProperties</code></li> 65 * <li> <code>com::sun::star::drawing::XGluePointsSupplier</code></li> 66 * <li> <code>com::sun::star::style::CharacterProperties</code></li> 67 * <li> <code>com::sun::star::drawing::RotationDescriptor</code></li> 68 * <li> <code>com::sun::star::text::XTextRange</code></li> 69 * <li> <code>com::sun::star::drawing::XShape</code></li> 70 * <li> <code>com::sun::star::lang::XComponent</code></li> 71 * <li> <code>com::sun::star::drawing::TextProperties</code></li> 72 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 73 * <li> <code>com::sun::star::text::XText</code></li> 74 * <li> <code>com::sun::star::drawing::XShapeDescriptor</code></li> 75 * <li> <code>com::sun::star::text::XSimpleText</code></li> 76 * <li> <code>com::sun::star::drawing::Shape</code></li> 77 * </ul> <p> 78 * 79 * The following files used by this test : 80 * <ul> 81 * <li><b> TransparencyChart.sxs </b> : to load predefined chart 82 * document where two 'automatic' transparency styles exists : 83 * 'Transparency 1' and 'Transparency 2'.</li> 84 * </ul> <p> 85 * 86 * This object test <b> is NOT </b> designed to be run in several 87 * threads concurently. 88 * 89 * @see com.sun.star.style.ParagraphProperties 90 * @see com.sun.star.drawing.PolyPolygonBezierDescriptor 91 * @see com.sun.star.drawing.LineProperties 92 * @see com.sun.star.drawing.FillProperties 93 * @see com.sun.star.drawing.ShadowProperties 94 * @see com.sun.star.drawing.XGluePointsSupplier 95 * @see com.sun.star.style.CharacterProperties 96 * @see com.sun.star.drawing.RotationDescriptor 97 * @see com.sun.star.text.XTextRange 98 * @see com.sun.star.drawing.XShape 99 * @see com.sun.star.lang.XComponent 100 * @see com.sun.star.drawing.TextProperties 101 * @see com.sun.star.beans.XPropertySet 102 * @see com.sun.star.text.XText 103 * @see com.sun.star.drawing.XShapeDescriptor 104 * @see com.sun.star.text.XSimpleText 105 * @see com.sun.star.drawing.Shape 106 * @see ifc.style._ParagraphProperties 107 * @see ifc.drawing._PolyPolygonBezierDescriptor 108 * @see ifc.drawing._LineProperties 109 * @see ifc.drawing._FillProperties 110 * @see ifc.drawing._ShadowProperties 111 * @see ifc.drawing._XGluePointsSupplier 112 * @see ifc.style._CharacterProperties 113 * @see ifc.drawing._RotationDescriptor 114 * @see ifc.text._XTextRange 115 * @see ifc.drawing._XShape 116 * @see ifc.lang._XComponent 117 * @see ifc.drawing._TextProperties 118 * @see ifc.beans._XPropertySet 119 * @see ifc.text._XText 120 * @see ifc.drawing._XShapeDescriptor 121 * @see ifc.text._XSimpleText 122 * @see ifc.drawing._Shape 123 */ 124 public class SvxShapePolyPolygonBezier extends TestCase { 125 126 static XComponent xDrawDoc; 127 128 /** 129 * in general this method creates a testdocument 130 * 131 * @param tParam class which contains additional test parameters 132 * @param log class to log the test state and result 133 * 134 * 135 * @see TestParameters 136 * * @see PrintWriter 137 * 138 */ 139 protected void initialize( TestParameters tParam, PrintWriter log ) { 140 // get a soffice factory object 141 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 142 143 try { 144 log.println( "creating a chartdocument" ); 145 xDrawDoc = SOF.loadDocument( 146 utils.getFullTestURL("SvxShape.sxd")); 147 } catch (com.sun.star.uno.Exception e) { 148 // Some exception occures.FAILED 149 e.printStackTrace( log ); 150 throw new StatusException( "Couldn't create document", e ); 151 } 152 } 153 154 /** 155 * in general this method disposes the testenvironment and document 156 * 157 * @param tParam class which contains additional test parameters 158 * @param log class to log the test state and result 159 * 160 * 161 * @see TestParameters 162 * * @see PrintWriter 163 * 164 */ 165 protected void cleanup( TestParameters tParam, PrintWriter log ) { 166 log.println( " disposing xDrawDoc " ); 167 util.DesktopTools.closeDoc(xDrawDoc); 168 } 169 170 171 /** 172 * * creating a Testenvironment for the interfaces to be tested 173 * 174 * @param tParam class which contains additional test parameters 175 * @param log class to log the test state and result 176 * 177 * @return Status class 178 * 179 * @see TestParameters 180 * * @see PrintWriter 181 */ 182 protected TestEnvironment createTestEnvironment 183 (TestParameters tParam, PrintWriter log) { 184 185 XInterface oObj = null; 186 XShape oShape = null; 187 188 // creation of testobject here 189 // first we write what we are intend to do to log file 190 log.println( "creating a test environment" ); 191 192 try { 193 194 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 195 196 XMultiServiceFactory xMSF = (XMultiServiceFactory) 197 UnoRuntime.queryInterface(XMultiServiceFactory.class, xDrawDoc) ; 198 199 XInterface oInst = (XInterface) xMSF.createInstance 200 ("com.sun.star.drawing.ClosedBezierShape") ; 201 oShape = (XShape) UnoRuntime.queryInterface 202 (XShape.class, oInst) ; 203 204 Point[] points = new Point[2]; 205 points[0] = new Point(); 206 points[0].X = 50; 207 points[0].Y = 50; 208 points[1] = new Point(); 209 points[1].X = 5000; 210 points[1].Y = 5000; 211 212 Point[][] the_points = new Point[1][2]; 213 the_points[0] = points; 214 215 PolygonFlags[] flags = new PolygonFlags[2]; 216 flags[0] = PolygonFlags.NORMAL; 217 flags[1] = PolygonFlags.NORMAL; 218 219 PolygonFlags[][] the_flags = new PolygonFlags[1][2]; 220 the_flags[0] = flags; 221 222 PolyPolygonBezierCoords coords = new PolyPolygonBezierCoords(); 223 coords.Coordinates=the_points; 224 coords.Flags = the_flags; 225 226 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape); 227 228 oShape.setSize(new Size(3000,3000)) ; 229 oShape.setPosition(new Point(4000,4000)) ; 230 231 oObj = oShape ; 232 233 XPropertySet shapeProps = (XPropertySet) UnoRuntime.queryInterface 234 (XPropertySet.class, oObj); 235 236 shapeProps.setPropertyValue("PolyPolygonBezier",coords); 237 238 //SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)tParam.getMSF()) ; 239 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line"); 240 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ; 241 } 242 catch (Exception e) { 243 log.println("Couldn't create instance"); 244 e.printStackTrace(log); 245 } 246 247 // test environment creation 248 249 TestEnvironment tEnv = new TestEnvironment(oObj); 250 251 log.println( "adding two styles as ObjRelation for ShapeDescriptor" ); 252 XPropertySet oShapeProps = (XPropertySet) 253 UnoRuntime.queryInterface(XPropertySet.class,oObj); 254 XStyle aStyle = null; 255 try { 256 aStyle = (XStyle) AnyConverter.toObject( 257 new Type(XStyle.class),oShapeProps.getPropertyValue("Style")); 258 } catch (Exception e) {} 259 tEnv.addObjRelation("Style1",aStyle); 260 oShapeProps = (XPropertySet) 261 UnoRuntime.queryInterface(XPropertySet.class,oShape); 262 try { 263 aStyle = (XStyle) AnyConverter.toObject( 264 new Type(XStyle.class),oShapeProps.getPropertyValue("Style")); 265 } catch (Exception e) {} 266 tEnv.addObjRelation("Style2",aStyle); 267 268 // adding relation for XText 269 util.DefaultDsc tDsc = new util.DefaultDsc 270 ("com.sun.star.text.XTextContent", 271 "com.sun.star.text.TextField.URL"); 272 log.println( " adding InstCreator object" ); 273 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) ); 274 275 return tEnv; 276 } // finish method getTestEnvironment 277 278 } // finish class SvxShapePolyPolygonBezier 279