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 */ 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 tParam test parameters 100 * @param tEnv the environment to cleanup 101 * @param log writer to log information while testing 102 */ 103 protected void cleanup( TestParameters Param, PrintWriter log) { 104 log.println("disposing impress documents"); 105 util.DesktopTools.closeDoc(xImpressDoc);; 106 util.DesktopTools.closeDoc(xSecondDrawDoc);; 107 } 108 109 /** 110 * Creating a Testenvironment for the interfaces to be tested. 111 * Creates two impress documents. After creating of the documents makes short 112 * wait to allow frames to be loaded. Retrieves the collection of the draw pages 113 * from the first document and takes one of them. Inserts some shapes to the 114 * retrieved draw page. Obtains a current controller from the first document 115 * using the interface <code>XModel</code>. The obtained controller is the 116 * instance of the service <code>com.sun.star.presentation.OutlineView</code>. 117 * Object relations created : 118 * <ul> 119 * <li> <code>'FirstModel'</code> for 120 * {@link ifc.frame._XController}(the interface <code>XModel</code> of 121 * the first created document) </li> 122 * <li> <code>'Frame'</code> for 123 * {@link ifc.frame._XController}(the frame of the created 124 * document) </li> 125 * <li> <code>'SecondModel'</code> for 126 * {@link ifc.frame._XController}(the interface <code>XModel</code> of 127 * the second created document) </li> 128 * <li> <code>'SecondController'</code> for 129 * {@link ifc.frame._XController}(the current controller of the second 130 * created document) </li> 131 * </ul> 132 * @see com.sun.star.frame.XModel 133 */ 134 protected synchronized TestEnvironment createTestEnvironment 135 (TestParameters Param, PrintWriter log) { 136 137 log.println( "creating a test environment" ); 138 139 // get a soffice factory object 140 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF()); 141 142 try { 143 log.println( "creating a impress document" ); 144 xImpressDoc = SOF.createImpressDoc(null); 145 shortWait(); 146 } catch (com.sun.star.uno.Exception e) { 147 e.printStackTrace( log ); 148 throw new StatusException("Couldn't create document", e); 149 } 150 151 XDrawPagesSupplier oDPS = (XDrawPagesSupplier) 152 UnoRuntime.queryInterface(XDrawPagesSupplier.class, xImpressDoc); 153 XDrawPages the_pages = oDPS.getDrawPages(); 154 XIndexAccess oDPi = (XIndexAccess) 155 UnoRuntime.queryInterface(XIndexAccess.class,the_pages); 156 157 XModel aModel = (XModel) 158 UnoRuntime.queryInterface(XModel.class, xImpressDoc); 159 160 XInterface oObj = aModel.getCurrentController(); 161 162 //Change to Outline view 163 try { 164 String aSlotID = "slot:27010"; 165 XDispatchProvider xDispProv = (XDispatchProvider) 166 UnoRuntime.queryInterface( XDispatchProvider.class, oObj ); 167 XURLTransformer xParser = (com.sun.star.util.XURLTransformer) 168 UnoRuntime.queryInterface(XURLTransformer.class, 169 ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer")); 170 // Because it's an in/out parameter we must use an array of URL objects. 171 URL[] aParseURL = new URL[1]; 172 aParseURL[0] = new URL(); 173 aParseURL[0].Complete = aSlotID; 174 xParser.parseStrict(aParseURL); 175 URL aURL = aParseURL[0]; 176 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0); 177 if( xDispatcher != null ) 178 xDispatcher.dispatch( aURL, null ); 179 } catch (com.sun.star.uno.Exception e) { 180 log.println("Couldn't change mode"); 181 } 182 183 try { 184 log.println( "creating a second impress document" ); 185 xSecondDrawDoc = SOF.createImpressDoc(null); 186 shortWait(); 187 } catch (com.sun.star.uno.Exception e) { 188 e.printStackTrace( log ); 189 throw new StatusException("Couldn't create document", e); 190 } 191 192 XModel aModel2 = (XModel) 193 UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 194 195 XWindow anotherWindow = (XWindow) UnoRuntime.queryInterface( 196 XWindow.class,aModel2.getCurrentController()); 197 198 oObj = aModel.getCurrentController(); 199 200 201 log.println( "creating a new environment for impress view object" ); 202 TestEnvironment tEnv = new TestEnvironment( oObj ); 203 204 if (anotherWindow != null) { 205 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow); 206 } 207 208 //Adding ObjRelations for XController 209 tEnv.addObjRelation("FirstModel", aModel); 210 211 tEnv.addObjRelation("XUserInputInterception.XModel", aModel); 212 213 XFrame the_frame = the_Desk.getCurrentFrame(); 214 tEnv.addObjRelation("Frame", the_frame); 215 216 aModel = (XModel) 217 UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc); 218 //Adding ObjRelations for XController 219 tEnv.addObjRelation("SecondModel", aModel); 220 221 XController secondController = aModel.getCurrentController(); 222 tEnv.addObjRelation("SecondController", secondController); 223 tEnv.addObjRelation("XDispatchProvider.URL", 224 "slot:27069"); 225 226 log.println("Implementation Name: " + utils.getImplName(oObj)); 227 228 return tEnv; 229 230 } // finish method getTestEnvironment 231 232 private void shortWait() { 233 try { 234 Thread.sleep(5000) ; 235 } catch (InterruptedException e) { 236 System.out.println("While waiting :" + e) ; 237 } 238 } 239 240 241 } // finish class SdUnoOutlineView 242 243