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