xref: /AOO41X/main/qadevOOo/tests/java/mod/_sd/SdUnoSlideView.java (revision 47148b3bc50811ceb41802e4cc50a5db21535900)
1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package mod._sd;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.drawing.XDrawPages;
27cdf0e10cSrcweir import java.io.PrintWriter;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir import lib.StatusException;
30cdf0e10cSrcweir import lib.TestCase;
31cdf0e10cSrcweir import lib.TestEnvironment;
32cdf0e10cSrcweir import lib.TestParameters;
33cdf0e10cSrcweir import util.DesktopTools;
34cdf0e10cSrcweir import util.DrawTools;
35cdf0e10cSrcweir import util.SOfficeFactory;
36cdf0e10cSrcweir import util.utils;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir import com.sun.star.awt.XWindow;
39cdf0e10cSrcweir import com.sun.star.frame.XController;
40cdf0e10cSrcweir import com.sun.star.frame.XDesktop;
41cdf0e10cSrcweir import com.sun.star.frame.XDispatch;
42cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider;
43cdf0e10cSrcweir import com.sun.star.frame.XFrame;
44cdf0e10cSrcweir import com.sun.star.frame.XModel;
45cdf0e10cSrcweir import com.sun.star.lang.XComponent;
46cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
47cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
48cdf0e10cSrcweir import com.sun.star.uno.XInterface;
49cdf0e10cSrcweir import com.sun.star.util.URL;
50cdf0e10cSrcweir import com.sun.star.util.XURLTransformer;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir public class SdUnoSlideView extends TestCase {
53cdf0e10cSrcweir     XDesktop the_Desk;
54cdf0e10cSrcweir     XComponent xImpressDoc;
55cdf0e10cSrcweir     XComponent xSecondDrawDoc;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     /**
58cdf0e10cSrcweir     * Creates the instance of the service <code>com.sun.star.frame.Desktop</code>.
59cdf0e10cSrcweir     * @see com.sun.star.frame.Desktop
60cdf0e10cSrcweir     */
initialize(TestParameters Param, PrintWriter log)61cdf0e10cSrcweir     protected void initialize(TestParameters Param, PrintWriter log) {
62cdf0e10cSrcweir         the_Desk = (XDesktop)
63cdf0e10cSrcweir             UnoRuntime.queryInterface(
64cdf0e10cSrcweir                 XDesktop.class, DesktopTools.createDesktop(
65cdf0e10cSrcweir                                     (XMultiServiceFactory)Param.getMSF()) );
66cdf0e10cSrcweir     }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     /**
69cdf0e10cSrcweir     * Called while disposing a <code>TestEnvironment</code>.
70cdf0e10cSrcweir     * Disposes Impress documents.
71*e6b649b5SPedro Giffuni     * @param Param test parameters
72cdf0e10cSrcweir     * @param log writer to log information while testing
73cdf0e10cSrcweir     */
cleanup( TestParameters Param, PrintWriter log)74cdf0e10cSrcweir     protected void cleanup( TestParameters Param, PrintWriter log) {
75cdf0e10cSrcweir         log.println("disposing impress documents");
76170fb961SPedro Giffuni         util.DesktopTools.closeDoc(xImpressDoc);
77170fb961SPedro Giffuni         util.DesktopTools.closeDoc(xSecondDrawDoc);
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     /**
81cdf0e10cSrcweir     * Creating a Testenvironment for the interfaces to be tested.
82cdf0e10cSrcweir     * Creates two impress documents. After creating of the documents makes short
83cdf0e10cSrcweir     * wait to allow frames to be loaded. Retrieves the collection of the draw pages
84cdf0e10cSrcweir     * from the first document and takes one of them. Inserts some shapes to the
85cdf0e10cSrcweir     * retrieved draw page. Obtains a current controller from the first document
86cdf0e10cSrcweir     * using the interface <code>XModel</code>. The obtained controller is the
87cdf0e10cSrcweir     * instance of the service <code>com.sun.star.presentation.OutlineView</code>.
88cdf0e10cSrcweir     * Object relations created :
89cdf0e10cSrcweir     * <ul>
90cdf0e10cSrcweir     *  <li> <code>'FirstModel'</code> for
91cdf0e10cSrcweir     *      {@link ifc.frame._XController}(the interface <code>XModel</code> of
92cdf0e10cSrcweir     *      the first created document) </li>
93cdf0e10cSrcweir     *  <li> <code>'Frame'</code> for
94cdf0e10cSrcweir     *      {@link ifc.frame._XController}(the frame of the created
95cdf0e10cSrcweir     *      document) </li>
96cdf0e10cSrcweir     *  <li> <code>'SecondModel'</code> for
97cdf0e10cSrcweir     *      {@link ifc.frame._XController}(the interface <code>XModel</code> of
98cdf0e10cSrcweir     *      the second created document) </li>
99cdf0e10cSrcweir     *  <li> <code>'SecondController'</code> for
100cdf0e10cSrcweir     *      {@link ifc.frame._XController}(the current controller of the second
101cdf0e10cSrcweir     *      created document) </li>
102cdf0e10cSrcweir     * </ul>
103cdf0e10cSrcweir     * @see com.sun.star.frame.XModel
104cdf0e10cSrcweir     */
createTestEnvironment(TestParameters Param, PrintWriter log)105cdf0e10cSrcweir     protected synchronized TestEnvironment createTestEnvironment
106cdf0e10cSrcweir             (TestParameters Param, PrintWriter log) {
107cdf0e10cSrcweir 
108cdf0e10cSrcweir         log.println( "creating a test environment" );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         // get a soffice factory object
111cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
112cdf0e10cSrcweir         XDrawPages xDP = null;
113cdf0e10cSrcweir         try {
114cdf0e10cSrcweir             log.println( "creating a impress document" );
115cdf0e10cSrcweir             xImpressDoc = SOF.createImpressDoc(null);
116cdf0e10cSrcweir             shortWait();
117cdf0e10cSrcweir             xDP = DrawTools.getDrawPages(xImpressDoc);
118cdf0e10cSrcweir             xDP.insertNewByIndex(0);
119cdf0e10cSrcweir             xDP.insertNewByIndex(0);
120cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
121cdf0e10cSrcweir             e.printStackTrace( log );
122cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
123cdf0e10cSrcweir         }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         XModel aModel = (XModel)
126cdf0e10cSrcweir             UnoRuntime.queryInterface(XModel.class, xImpressDoc);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         XInterface oObj = aModel.getCurrentController();
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         //Change to Slide view
131cdf0e10cSrcweir         try {
132cdf0e10cSrcweir             String aSlotID = "slot:27011";
133cdf0e10cSrcweir             XDispatchProvider xDispProv = (XDispatchProvider)
134cdf0e10cSrcweir                 UnoRuntime.queryInterface( XDispatchProvider.class, oObj );
135cdf0e10cSrcweir             XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
136cdf0e10cSrcweir                 UnoRuntime.queryInterface(XURLTransformer.class,
137cdf0e10cSrcweir         ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
138cdf0e10cSrcweir             // Because it's an in/out parameter we must use an array of URL objects.
139cdf0e10cSrcweir             URL[] aParseURL = new URL[1];
140cdf0e10cSrcweir             aParseURL[0] = new URL();
141cdf0e10cSrcweir             aParseURL[0].Complete = aSlotID;
142cdf0e10cSrcweir             xParser.parseStrict(aParseURL);
143cdf0e10cSrcweir             URL aURL = aParseURL[0];
144cdf0e10cSrcweir             XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
145cdf0e10cSrcweir             if( xDispatcher != null )
146cdf0e10cSrcweir                     xDispatcher.dispatch( aURL, null );
147cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
148cdf0e10cSrcweir             log.println("Couldn't change to slide view");
149cdf0e10cSrcweir         }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         try {
152cdf0e10cSrcweir             log.println( "creating a second impress document" );
153cdf0e10cSrcweir             xSecondDrawDoc = SOF.createImpressDoc(null);
154cdf0e10cSrcweir             shortWait();
155cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
156cdf0e10cSrcweir             e.printStackTrace( log );
157cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         XModel aModel2 = (XModel)
161cdf0e10cSrcweir             UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         XWindow anotherWindow = (XWindow) UnoRuntime.queryInterface(
164cdf0e10cSrcweir                                 XWindow.class,aModel2.getCurrentController());
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         oObj = aModel.getCurrentController();
167cdf0e10cSrcweir 
168cdf0e10cSrcweir         log.println( "creating a new environment for slide view object" );
169cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment( oObj );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         if (anotherWindow != null) {
172cdf0e10cSrcweir             tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
173cdf0e10cSrcweir         }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir          //Adding ObjRelations for XController
176cdf0e10cSrcweir         tEnv.addObjRelation("FirstModel", aModel);
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         XFrame the_frame = the_Desk.getCurrentFrame();
179cdf0e10cSrcweir         tEnv.addObjRelation("Frame", the_frame);
180cdf0e10cSrcweir 
181cdf0e10cSrcweir         //Adding ObjRelations for XController
182cdf0e10cSrcweir         tEnv.addObjRelation("SecondModel", aModel2);
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         XController secondController = aModel2.getCurrentController();
185cdf0e10cSrcweir         tEnv.addObjRelation("SecondController", secondController);
186cdf0e10cSrcweir         tEnv.addObjRelation("XDispatchProvider.URL",
187cdf0e10cSrcweir                                     "slot:27069");
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         //creating obj-relation for the XSelectionSupplier
192cdf0e10cSrcweir         try {
193cdf0e10cSrcweir             Object[] selections =
194cdf0e10cSrcweir                     new Object[]{xDP.getByIndex(0),xDP.getByIndex(1),xDP.getByIndex(2)};
195cdf0e10cSrcweir             tEnv.addObjRelation("Selections", selections);
196cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
197cdf0e10cSrcweir             e.printStackTrace(log);
198cdf0e10cSrcweir         }  catch (com.sun.star.lang.WrappedTargetException e) {
199cdf0e10cSrcweir             e.printStackTrace(log);
200cdf0e10cSrcweir         }
201cdf0e10cSrcweir         log.println("Implementation Name: " + utils.getImplName(oObj));
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         return tEnv;
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     } // finish method getTestEnvironment
206cdf0e10cSrcweir 
shortWait()207cdf0e10cSrcweir     private void shortWait() {
208cdf0e10cSrcweir         try {
209cdf0e10cSrcweir             Thread.sleep(1000) ;
210cdf0e10cSrcweir         } catch (InterruptedException e) {
211cdf0e10cSrcweir             System.out.println("While waiting :" + e) ;
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir     }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 
216cdf0e10cSrcweir } // finish class SdUnoOutlineView
217cdf0e10cSrcweir 
218