bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdUnoSlideView.java
blob49d6abb33c2d6b58f7d90663acc874422d340c64
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 com.sun.star.drawing.XDrawPages;
22 import java.io.PrintWriter;
24 import lib.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
28 import util.DesktopTools;
29 import util.DrawTools;
30 import util.SOfficeFactory;
31 import util.utils;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.frame.XController;
35 import com.sun.star.frame.XDesktop;
36 import com.sun.star.frame.XDispatch;
37 import com.sun.star.frame.XDispatchProvider;
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.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 import com.sun.star.util.URL;
44 import com.sun.star.util.XURLTransformer;
46 public class SdUnoSlideView extends TestCase {
47 XDesktop the_Desk;
48 XComponent xImpressDoc;
49 XComponent xSecondDrawDoc;
51 /**
52 * Creates the instance of the service <code>com.sun.star.frame.Desktop</code>.
53 * @see com.sun.star.frame.Desktop
55 @Override
56 protected void initialize(TestParameters Param, PrintWriter log) {
57 the_Desk = UnoRuntime.queryInterface(
58 XDesktop.class, DesktopTools.createDesktop(
59 Param.getMSF()) );
62 /**
63 * Called while disposing a <code>TestEnvironment</code>.
64 * Disposes Impress documents.
65 * @param Param test parameters
66 * @param log writer to log information while testing
68 @Override
69 protected void cleanup( TestParameters Param, PrintWriter log) {
70 log.println("disposing impress documents");
71 util.DesktopTools.closeDoc(xImpressDoc);
72 util.DesktopTools.closeDoc(xSecondDrawDoc);
75 /**
76 * Creating a Testenvironment for the interfaces to be tested.
77 * Creates two impress documents. After creating of the documents makes short
78 * wait to allow frames to be loaded. Retrieves the collection of the draw pages
79 * from the first document and takes one of them. Inserts some shapes to the
80 * retrieved draw page. Obtains a current controller from the first document
81 * using the interface <code>XModel</code>. The obtained controller is the
82 * instance of the service <code>com.sun.star.presentation.OutlineView</code>.
83 * Object relations created :
84 * <ul>
85 * <li> <code>'FirstModel'</code> for
86 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
87 * the first created document) </li>
88 * <li> <code>'Frame'</code> for
89 * {@link ifc.frame._XController}(the frame of the created
90 * document) </li>
91 * <li> <code>'SecondModel'</code> for
92 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
93 * the second created document) </li>
94 * <li> <code>'SecondController'</code> for
95 * {@link ifc.frame._XController}(the current controller of the second
96 * created document) </li>
97 * </ul>
98 * @see com.sun.star.frame.XModel
100 @Override
101 protected synchronized TestEnvironment createTestEnvironment
102 (TestParameters Param, PrintWriter log) {
104 log.println( "creating a test environment" );
106 // get a soffice factory object
107 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
108 XDrawPages xDP = null;
109 try {
110 log.println( "creating a impress document" );
111 xImpressDoc = SOF.createImpressDoc(null);
112 util.utils.pause(1000);
113 xDP = DrawTools.getDrawPages(xImpressDoc);
114 xDP.insertNewByIndex(0);
115 xDP.insertNewByIndex(0);
116 } catch (com.sun.star.uno.Exception e) {
117 e.printStackTrace( log );
118 throw new StatusException("Couldn't create document", e);
121 XModel aModel = UnoRuntime.queryInterface(XModel.class, xImpressDoc);
123 XInterface oObj = aModel.getCurrentController();
125 //Change to Slide view
126 try {
127 String aSlotID = "slot:27011";
128 XDispatchProvider xDispProv = UnoRuntime.queryInterface( XDispatchProvider.class, oObj );
129 XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class,
130 Param.getMSF().createInstance("com.sun.star.util.URLTransformer"));
131 // Because it's an in/out parameter we must use an array of URL objects.
132 URL[] aParseURL = new URL[1];
133 aParseURL[0] = new URL();
134 aParseURL[0].Complete = aSlotID;
135 xParser.parseStrict(aParseURL);
136 URL aURL = aParseURL[0];
137 XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
138 if( xDispatcher != null )
139 xDispatcher.dispatch( aURL, null );
140 } catch (com.sun.star.uno.Exception e) {
141 log.println("Couldn't change to slide view");
144 try {
145 log.println( "creating a second impress document" );
146 xSecondDrawDoc = SOF.createImpressDoc(null);
147 util.utils.pause(1000);
148 } catch (com.sun.star.uno.Exception e) {
149 e.printStackTrace( log );
150 throw new StatusException("Couldn't create document", e);
153 XModel aModel2 = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
155 XWindow anotherWindow = UnoRuntime.queryInterface(
156 XWindow.class,aModel2.getCurrentController());
158 oObj = aModel.getCurrentController();
160 log.println( "creating a new environment for slide view object" );
161 TestEnvironment tEnv = new TestEnvironment( oObj );
163 if (anotherWindow != null) {
164 tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
167 //Adding ObjRelations for XController
168 tEnv.addObjRelation("FirstModel", aModel);
170 XFrame the_frame = the_Desk.getCurrentFrame();
171 tEnv.addObjRelation("Frame", the_frame);
173 //Adding ObjRelations for XController
174 tEnv.addObjRelation("SecondModel", aModel2);
176 XController secondController = aModel2.getCurrentController();
177 tEnv.addObjRelation("SecondController", secondController);
178 tEnv.addObjRelation("XDispatchProvider.URL",
179 "slot:27069");
181 tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
183 //creating obj-relation for the XSelectionSupplier
184 try {
185 Object[] selections =
186 new Object[]{xDP.getByIndex(0),xDP.getByIndex(1),xDP.getByIndex(2)};
187 tEnv.addObjRelation("Selections", selections);
188 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
189 e.printStackTrace(log);
190 } catch (com.sun.star.lang.WrappedTargetException e) {
191 e.printStackTrace(log);
193 log.println("Implementation Name: " + utils.getImplName(oObj));
195 return tEnv;
197 } // finish method getTestEnvironment
200 } // finish class SdUnoOutlineView