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