bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdUnoOutlineView.java
blob252863b168d03e6795f68d00130381834a4b0687
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
19 package mod._sd;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.DesktopTools;
28 import util.SOfficeFactory;
29 import util.utils;
31 import com.sun.star.awt.XWindow;
32 import com.sun.star.container.XIndexAccess;
33 import com.sun.star.drawing.XDrawPages;
34 import com.sun.star.drawing.XDrawPagesSupplier;
35 import com.sun.star.frame.XController;
36 import com.sun.star.frame.XDesktop;
37 import com.sun.star.frame.XDispatch;
38 import com.sun.star.frame.XDispatchProvider;
39 import com.sun.star.frame.XFrame;
40 import com.sun.star.frame.XModel;
41 import com.sun.star.lang.XComponent;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 import com.sun.star.util.URL;
45 import com.sun.star.util.XURLTransformer;
46 /**
47 * Test for object which is represented by service
48 * <code>com.sun.star.present.OutlineView</code>. <p>
49 * Object implements the following interfaces :
50 * <ul>
51 * <li> <code>com::sun::star::lang::XComponent</code></li>
52 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
53 * <li> <code>com::sun::star::frame::XController</code></li>
54 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
55 * <li> <code>com::sun::star::presentation::OutlineView</code></li>
56 * <li> <code>com::sun::star::frame::XDispatchProvider</code></li>
57 * <li> <code>com::sun::star::awt::XWindow</code></li>
58 * </ul>
59 * @see com.sun.star.lang.XComponent
60 * @see com.sun.star.lang.XServiceInfo
61 * @see com.sun.star.frame.XController
62 * @see com.sun.star.beans.XPropertySet
63 * @see com.sun.star.presentation.OutlineView
64 * @see com.sun.star.awt.XWindow
65 * @see com.sun.star.frame.XDispatchProvider
66 * @see ifc.lang._XComponent
67 * @see ifc.lang._XServiceInfo
68 * @see ifc.frame._XController
69 * @see ifc.beans._XPropertySet
70 * @see ifc.awt._XWindow
71 * @see ifc.presentation._OutlineView
72 * @see ifc.frame._XDispatchProvider
74 public class SdUnoOutlineView extends TestCase {
75 XDesktop the_Desk;
76 XComponent xImpressDoc;
77 XComponent xSecondDrawDoc;
79 /**
80 * Creates the instance of the service <code>com.sun.star.frame.Desktop</code>.
81 * @see com.sun.star.frame.Desktop
83 @Override
84 protected void initialize(TestParameters Param, PrintWriter log) {
85 the_Desk = UnoRuntime.queryInterface(
86 XDesktop.class, DesktopTools.createDesktop(
87 Param.getMSF()) );
90 /**
91 * Called while disposing a <code>TestEnvironment</code>.
92 * Disposes Impress documents.
93 * @param Param test parameters
94 * @param log writer to log information while testing
96 @Override
97 protected void cleanup( TestParameters Param, PrintWriter log) {
98 log.println("disposing impress documents");
99 util.DesktopTools.closeDoc(xImpressDoc);
100 util.DesktopTools.closeDoc(xSecondDrawDoc);
104 * Creating a Testenvironment for the interfaces to be tested.
105 * Creates two impress documents. After creating of the documents makes short
106 * wait to allow frames to be loaded. Retrieves the collection of the draw pages
107 * from the first document and takes one of them. Inserts some shapes to the
108 * retrieved draw page. Obtains a current controller from the first document
109 * using the interface <code>XModel</code>. The obtained controller is the
110 * instance of the service <code>com.sun.star.presentation.OutlineView</code>.
111 * Object relations created :
112 * <ul>
113 * <li> <code>'FirstModel'</code> for
114 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
115 * the first created document) </li>
116 * <li> <code>'Frame'</code> for
117 * {@link ifc.frame._XController}(the frame of the created
118 * document) </li>
119 * <li> <code>'SecondModel'</code> for
120 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
121 * the second created document) </li>
122 * <li> <code>'SecondController'</code> for
123 * {@link ifc.frame._XController}(the current controller of the second
124 * created document) </li>
125 * </ul>
126 * @see com.sun.star.frame.XModel
128 @Override
129 protected synchronized TestEnvironment createTestEnvironment
130 (TestParameters Param, PrintWriter log) {
132 log.println( "creating a test environment" );
134 // get a soffice factory object
135 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
137 try {
138 log.println( "creating a impress document" );
139 xImpressDoc = SOF.createImpressDoc(null);
140 util.utils.pause(5000);
141 } catch (com.sun.star.uno.Exception e) {
142 e.printStackTrace( log );
143 throw new StatusException("Couldn't create document", e);
146 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xImpressDoc);
147 XDrawPages the_pages = oDPS.getDrawPages();
148 UnoRuntime.queryInterface(XIndexAccess.class,the_pages);
150 XModel aModel = UnoRuntime.queryInterface(XModel.class, xImpressDoc);
152 XInterface oObj = aModel.getCurrentController();
154 //Change to Outline view
155 try {
156 String aSlotID = "slot:27010";
157 XDispatchProvider xDispProv = UnoRuntime.queryInterface( XDispatchProvider.class, oObj );
158 XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class,
159 Param.getMSF().createInstance("com.sun.star.util.URLTransformer"));
160 // Because it's an in/out parameter we must use an array of URL objects.
161 URL[] aParseURL = new URL[1];
162 aParseURL[0] = new URL();
163 aParseURL[0].Complete = aSlotID;
164 xParser.parseStrict(aParseURL);
165 URL aURL = aParseURL[0];
166 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
167 if( xDispatcher != null )
168 xDispatcher.dispatch( aURL, null );
169 } catch (com.sun.star.uno.Exception e) {
170 log.println("Couldn't change mode");
173 try {
174 log.println( "creating a second impress document" );
175 xSecondDrawDoc = SOF.createImpressDoc(null);
176 util.utils.pause(5000);
177 } catch (com.sun.star.uno.Exception e) {
178 e.printStackTrace( log );
179 throw new StatusException("Couldn't create document", e);
182 XModel aModel2 = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
184 XWindow anotherWindow = UnoRuntime.queryInterface(
185 XWindow.class,aModel2.getCurrentController());
187 oObj = aModel.getCurrentController();
190 log.println( "creating a new environment for impress view object" );
191 TestEnvironment tEnv = new TestEnvironment( oObj );
193 if (anotherWindow != null) {
194 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
197 //Adding ObjRelations for XController
198 tEnv.addObjRelation("FirstModel", aModel);
200 tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
202 XFrame the_frame = the_Desk.getCurrentFrame();
203 tEnv.addObjRelation("Frame", the_frame);
205 aModel = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
206 //Adding ObjRelations for XController
207 tEnv.addObjRelation("SecondModel", aModel);
209 XController secondController = aModel.getCurrentController();
210 tEnv.addObjRelation("SecondController", secondController);
211 tEnv.addObjRelation("XDispatchProvider.URL",
212 "slot:27069");
214 log.println("Implementation Name: " + utils.getImplName(oObj));
216 return tEnv;
218 } // finish method getTestEnvironment
221 } // finish class SdUnoOutlineView