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._sd; 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.DesktopTools; 33 import util.SOfficeFactory; 34 import util.utils; 35 36 import com.sun.star.awt.XWindow; 37 import com.sun.star.container.XIndexAccess; 38 import com.sun.star.drawing.XDrawPages; 39 import com.sun.star.drawing.XDrawPagesSupplier; 40 import com.sun.star.frame.XController; 41 import com.sun.star.frame.XDesktop; 42 import com.sun.star.frame.XDispatch; 43 import com.sun.star.frame.XDispatchProvider; 44 import com.sun.star.frame.XFrame; 45 import com.sun.star.frame.XModel; 46 import com.sun.star.lang.XComponent; 47 import com.sun.star.lang.XMultiServiceFactory; 48 import com.sun.star.uno.UnoRuntime; 49 import com.sun.star.uno.XInterface; 50 import com.sun.star.util.URL; 51 import com.sun.star.util.XURLTransformer; 52 /** 53 * Test for object which is represented by service 54 * <code>com.sun.star.present.OutlineView</code>. <p> 55 * Object implements the following interfaces : 56 * <ul> 57 * <li> <code>com::sun::star::lang::XComponent</code></li> 58 * <li> <code>com::sun::star::lang::XServiceInfo</code></li> 59 * <li> <code>com::sun::star::frame::XController</code></li> 60 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 61 * <li> <code>com::sun::star::presentation::OutlineView</code></li> 62 * <li> <code>com::sun::star::frame::XDispatchProvider</code></li> 63 * <li> <code>com::sun::star::awt::XWindow</code></li> 64 * </ul> 65 * @see com.sun.star.lang.XComponent 66 * @see com.sun.star.lang.XServiceInfo 67 * @see com.sun.star.frame.XController 68 * @see com.sun.star.beans.XPropertySet 69 * @see com.sun.star.presentation.OutlineView 70 * @see com.sun.star.awt.XWindow 71 * @see com.sun.star.frame.XDispatchProvider 72 * @see ifc.lang._XComponent 73 * @see ifc.lang._XServiceInfo 74 * @see ifc.frame._XController 75 * @see ifc.beans._XPropertySet 76 * @see ifc.awt._XWindow 77 * @see ifc.presentation._OutlineView 78 * @see ifc.frame._XDispatchProvider 79 */ 80 public class SdUnoOutlineView extends TestCase { 81 XDesktop the_Desk; 82 XComponent xImpressDoc; 83 XComponent xSecondDrawDoc; 84 85 /** 86 * Creates the instance of the service <code>com.sun.star.frame.Desktop</code>. 87 * @see com.sun.star.frame.Desktop 88 */ initialize(TestParameters Param, PrintWriter log)89 protected void initialize(TestParameters Param, PrintWriter log) { 90 the_Desk = (XDesktop) 91 UnoRuntime.queryInterface( 92 XDesktop.class, DesktopTools.createDesktop( 93 (XMultiServiceFactory)Param.getMSF()) ); 94 } 95 96 /** 97 * Called while disposing a <code>TestEnvironment</code>. 98 * Disposes Impress documents. 99 * @param Param test parameters 100 * @param log writer to log information while testing 101 */ cleanup( TestParameters Param, PrintWriter log)102 protected void cleanup( TestParameters Param, PrintWriter log) { 103 log.println("disposing impress documents"); 104 util.DesktopTools.closeDoc(xImpressDoc); 105 util.DesktopTools.closeDoc(xSecondDrawDoc); 106 } 107 108 /** 109 * Creating a Testenvironment for the interfaces to be tested. 110 * Creates two impress documents. After creating of the documents makes short 111 * wait to allow frames to be loaded. Retrieves the collection of the draw pages 112 * from the first document and takes one of them. Inserts some shapes to the 113 * retrieved draw page. Obtains a current controller from the first document 114 * using the interface <code>XModel</code>. The obtained controller is the 115 * instance of the service <code>com.sun.star.presentation.OutlineView</code>. 116 * Object relations created : 117 * <ul> 118 * <li> <code>'FirstModel'</code> for 119 * {@link ifc.frame._XController}(the interface <code>XModel</code> of 120 * the first created document) </li> 121 * <li> <code>'Frame'</code> for 122 * {@link ifc.frame._XController}(the frame of the created 123 * document) </li> 124 * <li> <code>'SecondModel'</code> for 125 * {@link ifc.frame._XController}(the interface <code>XModel</code> of 126 * the second created document) </li> 127 * <li> <code>'SecondController'</code> for 128 * {@link ifc.frame._XController}(the current controller of the second 129 * created document) </li> 130 * </ul> 131 * @see com.sun.star.frame.XModel 132 */ createTestEnvironment(TestParameters Param, PrintWriter log)133 protected synchronized TestEnvironment createTestEnvironment 134 (TestParameters Param, PrintWriter log) { 135 136 log.println( "creating a test environment" ); 137 138 // get a soffice factory object 139 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 140 141 try { 142 log.println( "creating a impress document" ); 143 xImpressDoc = SOF.createImpressDoc(null); 144 shortWait(); 145 } catch (com.sun.star.uno.Exception e) { 146 e.printStackTrace( log ); 147 throw new StatusException("Couldn't create document", e); 148 } 149 150 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 151 UnoRuntime.queryInterface(XDrawPagesSupplier.class, xImpressDoc); 152 XDrawPages the_pages = oDPS.getDrawPages(); 153 XIndexAccess oDPi = (XIndexAccess) 154 UnoRuntime.queryInterface(XIndexAccess.class,the_pages); 155 156 XModel aModel = (XModel) 157 UnoRuntime.queryInterface(XModel.class, xImpressDoc); 158 159 XInterface oObj = aModel.getCurrentController(); 160 161 //Change to Outline view 162 try { 163 String aSlotID = "slot:27010"; 164 XDispatchProvider xDispProv = (XDispatchProvider) 165 UnoRuntime.queryInterface( XDispatchProvider.class, oObj ); 166 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) 167 UnoRuntime.queryInterface(XURLTransformer.class, 168 ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer")); 169 // Because it's an in/out parameter we must use an array of URL objects. 170 URL[] aParseURL = new URL[1]; 171 aParseURL[0] = new URL(); 172 aParseURL[0].Complete = aSlotID; 173 xParser.parseStrict(aParseURL); 174 URL aURL = aParseURL[0]; 175 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0); 176 if( xDispatcher != null ) 177 xDispatcher.dispatch( aURL, null ); 178 } catch (com.sun.star.uno.Exception e) { 179 log.println("Couldn't change mode"); 180 } 181 182 try { 183 log.println( "creating a second impress document" ); 184 xSecondDrawDoc = SOF.createImpressDoc(null); 185 shortWait(); 186 } catch (com.sun.star.uno.Exception e) { 187 e.printStackTrace( log ); 188 throw new StatusException("Couldn't create document", e); 189 } 190 191 XModel aModel2 = (XModel) 192 UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 193 194 XWindow anotherWindow = (XWindow) UnoRuntime.queryInterface( 195 XWindow.class,aModel2.getCurrentController()); 196 197 oObj = aModel.getCurrentController(); 198 199 200 log.println( "creating a new environment for impress view object" ); 201 TestEnvironment tEnv = new TestEnvironment( oObj ); 202 203 if (anotherWindow != null) { 204 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow); 205 } 206 207 //Adding ObjRelations for XController 208 tEnv.addObjRelation("FirstModel", aModel); 209 210 tEnv.addObjRelation("XUserInputInterception.XModel", aModel); 211 212 XFrame the_frame = the_Desk.getCurrentFrame(); 213 tEnv.addObjRelation("Frame", the_frame); 214 215 aModel = (XModel) 216 UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 217 //Adding ObjRelations for XController 218 tEnv.addObjRelation("SecondModel", aModel); 219 220 XController secondController = aModel.getCurrentController(); 221 tEnv.addObjRelation("SecondController", secondController); 222 tEnv.addObjRelation("XDispatchProvider.URL", 223 "slot:27069"); 224 225 log.println("Implementation Name: " + utils.getImplName(oObj)); 226 227 return tEnv; 228 229 } // finish method getTestEnvironment 230 shortWait()231 private void shortWait() { 232 try { 233 Thread.sleep(5000) ; 234 } catch (InterruptedException e) { 235 System.out.println("While waiting :" + e) ; 236 } 237 } 238 239 240 } // finish class SdUnoOutlineView 241 242