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