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