1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 19 package mod._sd; 20 21 import java.io.PrintWriter; 22 import java.util.Comparator; 23 24 import lib.TestCase; 25 import lib.TestEnvironment; 26 import lib.TestParameters; 27 import util.SOfficeFactory; 28 import util.utils; 29 30 import com.sun.star.awt.XWindow; 31 import com.sun.star.container.XIndexAccess; 32 import com.sun.star.drawing.XDrawPage; 33 import com.sun.star.drawing.XDrawPages; 34 import com.sun.star.drawing.XDrawPagesSupplier; 35 import com.sun.star.drawing.XShape; 36 import com.sun.star.drawing.XShapes; 37 import com.sun.star.frame.XController; 38 import com.sun.star.frame.XFrame; 39 import com.sun.star.frame.XModel; 40 import com.sun.star.lang.XComponent; 41 import com.sun.star.uno.AnyConverter; 42 import com.sun.star.uno.Type; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 import com.sun.star.util.XModifiable; 46 47 /** 48 * Test for object which is represented by service 49 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. <p> 50 * Object implements the following interfaces : 51 * <ul> 52 * <li> <code>com::sun::star::drawing::DrawingDocumentDrawView</code></li> 53 * <li> <code>com::sun::star::lang::XComponent</code></li> 54 * <li> <code>com::sun::star::lang::XServiceInfo</code></li> 55 * <li> <code>com::sun::star::frame::XController</code></li> 56 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 57 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li> 58 * <li> <code>com::sun::star::drawing::XDrawView</code></li> 59 * </ul> 60 * @see com.sun.star.drawing.DrawingDocumentDrawView 61 * @see com.sun.star.lang.XComponent 62 * @see com.sun.star.lang.XServiceInfo 63 * @see com.sun.star.frame.XController 64 * @see com.sun.star.beans.XPropertySet 65 * @see com.sun.star.view.XSelectionSupplier 66 * @see com.sun.star.drawing.XDrawView 67 * @see ifc.drawing._DrawingDocumentDrawView 68 * @see ifc.lang._XComponent 69 * @see ifc.lang._XServiceInfo 70 * @see ifc.frame._XController 71 * @see ifc.beans._XPropertySet 72 * @see ifc.view._XSelectionSupplier 73 * @see ifc.drawing._XDrawView 74 */ 75 public class DrawController_DrawView extends TestCase { 76 static XComponent xDrawDoc; 77 static XComponent xSecondDrawDoc; 78 79 /** 80 * Called while disposing a <code>TestEnvironment</code>. 81 * Disposes Impress documents. 82 * @param Param test parameters 83 * @param log writer to log information while testing 84 */ 85 @Override cleanup( TestParameters Param, PrintWriter log)86 protected void cleanup( TestParameters Param, PrintWriter log) { 87 log.println("disposing impress documents"); 88 util.DesktopTools.closeDoc(xDrawDoc); 89 util.DesktopTools.closeDoc(xSecondDrawDoc); 90 } 91 92 /** 93 * Creating a TestEnvironment for the interfaces to be tested. 94 * Creates two impress documents. After creating 95 * of the documents makes short 96 * wait to allow frames to be loaded. Retrieves 97 * the collection of the draw pages 98 * from the first document and takes one of them. Inserts some shapes to the 99 * retrieved draw page. Obtains a current controller from the first document 100 * using the interface <code>XModel</code>. The obtained controller is the 101 * instance of the service 102 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. 103 * Object relations created : 104 * <ul> 105 * <li> <code>'Pages'</code> for 106 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw 107 * pages) </li> 108 * <li> <code>'FirstModel'</code> for 109 * {@link ifc.frame._XController}(the interface <code>XModel</code> of 110 * the first created document) </li> 111 * <li> <code>'Frame'</code> for 112 * {@link ifc.frame._XController}(the frame of the created 113 * document) </li> 114 * <li> <code>'SecondModel'</code> for 115 * {@link ifc.frame._XController}(the interface <code>XModel</code> of 116 * the second created document) </li> 117 * <li> <code>'SecondController'</code> for 118 * {@link ifc.frame._XController}(the current controller of the second 119 * created document) </li> 120 * <li> <code>'DrawPage'</code> for 121 * {@link ifc.drawing._DrawingDocumentDrawView}(the draw page which will 122 * be new current page) </li> 123 * </ul> 124 * @see com.sun.star.frame.XModel 125 * @see com.sun.star.drawing.DrawingDocumentDrawView 126 */ 127 @Override createTestEnvironment(TestParameters Param, PrintWriter log)128 protected TestEnvironment createTestEnvironment 129 (TestParameters Param, PrintWriter log) throws Exception { 130 131 log.println( "creating a test environment" ); 132 133 // get a soffice factory object 134 SOfficeFactory SOF = SOfficeFactory.getFactory( 135 Param.getMSF()); 136 137 log.println( "creating two impress documents" ); 138 xDrawDoc = SOF.createDrawDoc(null); 139 util.utils.waitForEventIdle(Param.getMSF()); 140 xSecondDrawDoc = SOF.createDrawDoc(null); 141 util.utils.waitForEventIdle(Param.getMSF()); 142 143 // get the drawpage of drawing here 144 log.println( "getting Drawpage" ); 145 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc); 146 XDrawPages the_pages = oDPS.getDrawPages(); 147 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class,the_pages); 148 149 XDrawPage oDrawPage = (XDrawPage) AnyConverter.toObject( 150 new Type(XDrawPage.class),oDPi.getByIndex(0)); 151 152 //put something on the drawpage 153 log.println( "inserting some Shapes" ); 154 XShapes oShapes = UnoRuntime.queryInterface(XShapes.class, oDrawPage); 155 XShape shape1 = SOF.createShape( 156 xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse"); 157 XShape shape2 = SOF.createShape( 158 xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle"); 159 XShape shape3 = SOF.createShape( 160 xDrawDoc, 3000, 500, 5000, 1000, "Line"); 161 oShapes.add(shape1); 162 oShapes.add(shape2); 163 oShapes.add(shape3); 164 util.utils.waitForEventIdle(Param.getMSF()); 165 166 XModel aModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc); 167 168 XInterface oObj = aModel.getCurrentController(); 169 170 XModel aModel2 = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 171 XController aController2 = aModel2.getCurrentController(); 172 173 XWindow anotherWindow = UnoRuntime.queryInterface( 174 XWindow.class, aController2); 175 176 log.println( "creating a new environment for impress view object" ); 177 TestEnvironment tEnv = new TestEnvironment( oObj ); 178 179 if (anotherWindow != null) { 180 tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow); 181 } 182 183 Object oShapeCol1 = null; 184 Object oShapeCol2 = null; 185 oShapeCol1 = Param.getMSF(). 186 createInstance("com.sun.star.drawing.ShapeCollection"); 187 oShapeCol2 = Param.getMSF(). 188 createInstance("com.sun.star.drawing.ShapeCollection"); 189 190 XShapes xShapes1 = UnoRuntime.queryInterface(XShapes.class, oShapeCol1); 191 XShapes xShapes2 = UnoRuntime.queryInterface(XShapes.class, oShapeCol2); 192 xShapes1.add(shape2); 193 xShapes1.add(shape3); 194 xShapes2.add(shape1); 195 util.utils.waitForEventIdle(Param.getMSF()); 196 197 198 tEnv.addObjRelation("Selections", new Object[] { 199 oDrawPage, oShapeCol1, oShapeCol2}); 200 tEnv.addObjRelation("Comparer", new Comparator<Object>() { 201 public int compare(Object o1, Object o2) { 202 XIndexAccess indAc1 = UnoRuntime.queryInterface(XIndexAccess.class, o1); 203 XIndexAccess indAc2 = UnoRuntime.queryInterface(XIndexAccess.class, o2); 204 if (indAc1 == null || indAc2 == null) return -1; 205 if (indAc1.getCount() == indAc2.getCount()) { 206 return 0; 207 } 208 return 1; 209 }}); 210 211 212 213 tEnv.addObjRelation("Pages", the_pages); 214 215 //Adding ObjRelations for XController 216 tEnv.addObjRelation("FirstModel", aModel); 217 218 tEnv.addObjRelation("XUserInputInterception.XModel", aModel); 219 220 XFrame the_frame = aController2.getFrame(); 221 tEnv.addObjRelation("Frame", the_frame); 222 223 //Adding ObjRelations for XController 224 tEnv.addObjRelation("SecondModel", aModel2); 225 226 tEnv.addObjRelation("SecondController", aController2); 227 tEnv.addObjRelation("XDispatchProvider.URL", 228 "slot:27009"); 229 230 //Adding relations for DrawingDocumentDrawView 231 XDrawPage new_page = the_pages.insertNewByIndex(1); 232 tEnv.addObjRelation("DrawPage", new_page); 233 234 log.println("Implementation Name: "+utils.getImplName(oObj)); 235 236 XModifiable modify = UnoRuntime.queryInterface(XModifiable.class,xDrawDoc); 237 238 tEnv.addObjRelation("Modifiable",modify); 239 240 tEnv.addObjRelation("XComponent.DisposeThis", xDrawDoc); 241 242 return tEnv; 243 244 } // finish method getTestEnvironment 245 246 247 } 248 249