1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew 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.InstCreator; 33cdf0e10cSrcweir import util.SOfficeFactory; 34cdf0e10cSrcweir import util.ShapeDsc; 35cdf0e10cSrcweir 36cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 37cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 38cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage; 39cdf0e10cSrcweir import com.sun.star.drawing.XDrawPages; 40cdf0e10cSrcweir import com.sun.star.drawing.XDrawPagesSupplier; 41cdf0e10cSrcweir import com.sun.star.drawing.XShape; 42cdf0e10cSrcweir import com.sun.star.drawing.XShapeGrouper; 43cdf0e10cSrcweir import com.sun.star.drawing.XShapes; 44cdf0e10cSrcweir import com.sun.star.lang.XComponent; 45cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 46cdf0e10cSrcweir import com.sun.star.style.XStyle; 47cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 48cdf0e10cSrcweir import com.sun.star.uno.Type; 49cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 50cdf0e10cSrcweir import com.sun.star.uno.XInterface; 51cdf0e10cSrcweir 52cdf0e10cSrcweir /** 53cdf0e10cSrcweir * 54cdf0e10cSrcweir * initial description 55cdf0e10cSrcweir * @see com.sun.star.drawing._XDrawPage 56cdf0e10cSrcweir * 57cdf0e10cSrcweir */ 58cdf0e10cSrcweir 59cdf0e10cSrcweir public class SvxShapeGroup extends TestCase { 60cdf0e10cSrcweir 61cdf0e10cSrcweir static XComponent xDrawDoc; 62cdf0e10cSrcweir 63cdf0e10cSrcweir /** 64cdf0e10cSrcweir * in general this method initializes the document 65cdf0e10cSrcweir */ 66cdf0e10cSrcweir 67cdf0e10cSrcweir protected void initialize(TestParameters Param, PrintWriter log) { 68cdf0e10cSrcweir 69cdf0e10cSrcweir // get a soffice factory object 70cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 71cdf0e10cSrcweir 72cdf0e10cSrcweir try { 73cdf0e10cSrcweir log.println( "creating a draw document" ); 74*170fb961SPedro Giffuni xDrawDoc = SOF.createDrawDoc(null); 75cdf0e10cSrcweir } catch ( Exception e ) { 76cdf0e10cSrcweir // Some exception occures.FAILED 77cdf0e10cSrcweir e.printStackTrace( log ); 78cdf0e10cSrcweir throw new StatusException( "Couldn't create document", e ); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir /** 84cdf0e10cSrcweir * in general this method disposes the document 85cdf0e10cSrcweir */ 86cdf0e10cSrcweir 87cdf0e10cSrcweir protected void cleanup( TestParameters Param, PrintWriter log) { 88cdf0e10cSrcweir 89cdf0e10cSrcweir log.println("disposing xDrawDoc"); 90cdf0e10cSrcweir util.DesktopTools.closeDoc(xDrawDoc); 91cdf0e10cSrcweir 92cdf0e10cSrcweir } 93cdf0e10cSrcweir 94cdf0e10cSrcweir /** 95cdf0e10cSrcweir * creating a Testenvironment for the interfaces to be tested 96cdf0e10cSrcweir */ 97cdf0e10cSrcweir public synchronized TestEnvironment createTestEnvironment 98cdf0e10cSrcweir (TestParameters Param, PrintWriter log ) { 99cdf0e10cSrcweir 100cdf0e10cSrcweir XInterface oObj = null; 101cdf0e10cSrcweir XShapes oShapes = null; 102cdf0e10cSrcweir 103cdf0e10cSrcweir // creation of testobject here 104cdf0e10cSrcweir // first we write what we are intend to do to log file 105cdf0e10cSrcweir log.println( "creating a test environment" ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 108cdf0e10cSrcweir 109cdf0e10cSrcweir // get the drawpage of drawing here 110cdf0e10cSrcweir try { 111cdf0e10cSrcweir log.println( "getting Drawpage" ); 112cdf0e10cSrcweir XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 113cdf0e10cSrcweir UnoRuntime.queryInterface(XDrawPagesSupplier.class,xDrawDoc); 114cdf0e10cSrcweir XDrawPages oDPn = oDPS.getDrawPages(); 115cdf0e10cSrcweir XIndexAccess oDPi = (XIndexAccess) 116cdf0e10cSrcweir UnoRuntime.queryInterface(XIndexAccess.class,oDPn); 117cdf0e10cSrcweir oObj = (XDrawPage) AnyConverter.toObject( 118cdf0e10cSrcweir new Type(XDrawPage.class),oDPi.getByIndex(0)); 119cdf0e10cSrcweir } catch ( Exception e ) { 120cdf0e10cSrcweir // Some exception occures.FAILED 121cdf0e10cSrcweir e.printStackTrace( log ); 122cdf0e10cSrcweir throw new StatusException( "Couldn't get DrawPage", e ); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir if (oObj == null) { 126cdf0e10cSrcweir System.out.println("**************************"); 127cdf0e10cSrcweir System.out.println(" XDrawPage is NULL"); 128cdf0e10cSrcweir System.out.println("**************************"); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir //put something on the drawpage 132cdf0e10cSrcweir log.println( "inserting some Shapes" ); 133cdf0e10cSrcweir oShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class,oObj); 134cdf0e10cSrcweir XShape Shape1 = SOF.createShape(xDrawDoc, 135cdf0e10cSrcweir 3000,4500,15000,1000,"Ellipse"); 136cdf0e10cSrcweir oShapes.add(SOF.createShape(xDrawDoc, 137cdf0e10cSrcweir 2000,1500,1000,1000,"Line")); 138cdf0e10cSrcweir oShapes.add(Shape1); 139cdf0e10cSrcweir XShape Shape2 = SOF.createShape(xDrawDoc, 140cdf0e10cSrcweir 5000,3500,7500,5000,"Rectangle"); 141cdf0e10cSrcweir oShapes.add(Shape2); 142cdf0e10cSrcweir 143cdf0e10cSrcweir log.println( "adding two style as ObjRelation for ShapeDescriptor" ); 144cdf0e10cSrcweir XPropertySet oShapeProps = (XPropertySet) 145cdf0e10cSrcweir UnoRuntime.queryInterface(XPropertySet.class,Shape1); 146cdf0e10cSrcweir XStyle aStyle1 = null; 147cdf0e10cSrcweir try { 148cdf0e10cSrcweir aStyle1 = (XStyle) AnyConverter.toObject( 149cdf0e10cSrcweir new Type(XStyle.class),oShapeProps.getPropertyValue("Style")); 150cdf0e10cSrcweir } catch (Exception e) {} 151cdf0e10cSrcweir oShapeProps = (XPropertySet) 152cdf0e10cSrcweir UnoRuntime.queryInterface(XPropertySet.class,Shape2); 153cdf0e10cSrcweir XStyle aStyle2 = null; 154cdf0e10cSrcweir try { 155cdf0e10cSrcweir aStyle2 = (XStyle) AnyConverter.toObject( 156cdf0e10cSrcweir new Type(XStyle.class),oShapeProps.getPropertyValue("Style")); 157cdf0e10cSrcweir } catch (Exception e) {} 158cdf0e10cSrcweir 159cdf0e10cSrcweir 160cdf0e10cSrcweir //get the XShapeGrouper 161cdf0e10cSrcweir try{ 162cdf0e10cSrcweir log.println("get XShapeGroup"); 163cdf0e10cSrcweir XShapeGrouper oSG = (XShapeGrouper)UnoRuntime.queryInterface 164cdf0e10cSrcweir (XShapeGrouper.class, oObj); 165cdf0e10cSrcweir oObj = oSG.group(oShapes); 166cdf0e10cSrcweir } catch ( Exception e) { 167cdf0e10cSrcweir e.printStackTrace( log ); 168cdf0e10cSrcweir throw new StatusException(" Couldn't get XShapeGroup: ", e); 169cdf0e10cSrcweir } 170cdf0e10cSrcweir 171cdf0e10cSrcweir log.println( "creating a new environment for drawpage object" ); 172cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment( oObj ); 173cdf0e10cSrcweir 174cdf0e10cSrcweir ShapeDsc sDsc = new ShapeDsc(5000,3500,7500,10000,"Rectangle"); 175cdf0e10cSrcweir log.println( "adding Shape as mod relation to environment" ); 176cdf0e10cSrcweir tEnv.addObjRelation("Shape", new InstCreator( xDrawDoc, sDsc)); 177cdf0e10cSrcweir //tEnv.addObjRelation("DrawPage", oObj); 178cdf0e10cSrcweir //tEnv.addObjRelation("MasterPageSupplier",oGroup); 179cdf0e10cSrcweir 180cdf0e10cSrcweir tEnv.addObjRelation("Style1",aStyle1); 181cdf0e10cSrcweir tEnv.addObjRelation("Style2",aStyle2); 182cdf0e10cSrcweir for (int i=0;i<6;i++) { 183cdf0e10cSrcweir Shape2 = SOF.createShape(xDrawDoc, 184cdf0e10cSrcweir 5000+100*i,3500+100*i,7500+100*i,5000+100*i,"Rectangle"); 185cdf0e10cSrcweir oShapes.add(Shape2); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir return tEnv; 188cdf0e10cSrcweir } // finish method createTestEnvironment 189cdf0e10cSrcweir 190cdf0e10cSrcweir } // finish class SvxShapeGroup 191cdf0e10cSrcweir 192