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._sc; 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.ShapeDsc; 40 41 import com.sun.star.drawing.XDrawPage; 42 import com.sun.star.drawing.XDrawPages; 43 import com.sun.star.drawing.XDrawPagesSupplier; 44 import com.sun.star.drawing.XShape; 45 import com.sun.star.lang.XComponent; 46 import com.sun.star.lang.XMultiServiceFactory; 47 import com.sun.star.sheet.XSpreadsheetDocument; 48 import com.sun.star.uno.AnyConverter; 49 import com.sun.star.uno.Type; 50 import com.sun.star.uno.UnoRuntime; 51 import com.sun.star.uno.XInterface; 52 53 public class ScDrawPageObj extends TestCase { 54 55 static XSpreadsheetDocument xDoc = null; 56 57 /** 58 * Creates a new Draw document. 59 */ 60 protected void initialize( TestParameters tParam, PrintWriter log ) { 61 // get a soffice factory object 62 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 63 64 try { 65 log.println( "creating a sheetdocument" ); 66 xDoc = SOF.createCalcDoc(null); 67 } catch (com.sun.star.uno.Exception e) { 68 // Some exception occures.FAILED 69 e.printStackTrace( log ); 70 throw new StatusException( "Couldn't create document", e ); 71 } 72 } 73 74 /** 75 * Disposes the Draw document created before 76 */ 77 protected void cleanup( TestParameters tParam, PrintWriter log ) { 78 log.println( " disposing xSheetDoc " ); 79 XComponent xComp = (XComponent) 80 UnoRuntime.queryInterface(XComponent.class, xDoc); 81 util.DesktopTools.closeDoc(xComp); 82 } 83 84 85 /** 86 * Creating a Testenvironment for the interfaces to be tested. 87 * From the Calc document created a collection of its draw 88 * pages is obtained. Two new pages are inserted. And one 89 * page is obtained as a testing component. A shape is added 90 * to this page. <p> 91 * 92 * Object relations created : 93 * <ul> 94 * <li> <code>'DrawPage'</code> for 95 * {@link ifc.drawing._XShapeGrouper} : 96 * the draw page tested. </li> 97 * <li> <code>'Shape'</code> for 98 * {@link ifc.drawing._XShapes} : 99 * the creator which can create instances of 100 * <code>com.sun.star.drawing.Line</code> service </li> 101 * </ul> 102 */ 103 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 104 105 XInterface oObj = null; 106 XShape oShape = null ; 107 XDrawPages oDP = null; 108 109 XComponent xComp = (XComponent) 110 UnoRuntime.queryInterface(XComponent.class, xDoc); 111 112 // creation of testobject here 113 // first we write what we are intend to do to log file 114 log.println( "creating a test environment" ); 115 try { 116 log.println( "getting Drawpages" ); 117 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 118 UnoRuntime.queryInterface(XDrawPagesSupplier.class,xDoc); 119 oDP = (XDrawPages) oDPS.getDrawPages(); 120 oDP.insertNewByIndex(1); 121 oDP.insertNewByIndex(2); 122 oObj = (XDrawPage) AnyConverter.toObject( 123 new Type(XDrawPage.class),oDP.getByIndex(0)); 124 125 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 126 127 oShape = SOF.createShape(xComp,5000,3500,7500,5000,"Rectangle"); 128 DrawTools.getShapes((XDrawPage) oObj).add(oShape); 129 XShape oShape1 = SOF.createShape(xComp, 130 5000,5500,5000,5000,"Rectangle"); 131 DrawTools.getShapes((XDrawPage) oObj).add(oShape1); 132 } catch (com.sun.star.lang.WrappedTargetException e) { 133 log.println("Couldn't create insance"); 134 e.printStackTrace(log); 135 throw new StatusException("Can't create enviroment", e) ; 136 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 137 log.println("Couldn't create insance"); 138 e.printStackTrace(log); 139 throw new StatusException("Can't create enviroment", e) ; 140 } catch (com.sun.star.lang.IllegalArgumentException e) { 141 log.println("Couldn't create insance"); 142 e.printStackTrace(log); 143 throw new StatusException("Can't create enviroment", e) ; 144 } 145 146 // create test environment here 147 TestEnvironment tEnv = new TestEnvironment( oObj ); 148 149 // relation for XShapes interface 150 ShapeDsc sDsc = new ShapeDsc(5000,3500,7500,10000,"Line"); 151 tEnv.addObjRelation("Shape", new InstCreator(xDoc, sDsc)) ; 152 153 log.println("ImplementationName: "+util.utils.getImplName(oObj)); 154 155 // adding relation for XShapeGrouper 156 tEnv.addObjRelation("DrawPage", oObj); 157 158 return tEnv; 159 } // finish method getTestEnvironment 160 161 } 162 163