xref: /AOO41X/main/qadevOOo/tests/java/mod/_sd/SdUnoSlideView.java (revision 170fb9610d1f656955e58ef1358c0d3219078b5e)
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     */
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.
71cdf0e10cSrcweir     * @param tParam test parameters
72cdf0e10cSrcweir     * @param tEnv the environment to cleanup
73cdf0e10cSrcweir     * @param log writer to log information while testing
74cdf0e10cSrcweir     */
75cdf0e10cSrcweir     protected void cleanup( TestParameters Param, PrintWriter log) {
76cdf0e10cSrcweir         log.println("disposing impress documents");
77*170fb961SPedro Giffuni         util.DesktopTools.closeDoc(xImpressDoc);
78*170fb961SPedro Giffuni         util.DesktopTools.closeDoc(xSecondDrawDoc);
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     /**
82cdf0e10cSrcweir     * Creating a Testenvironment for the interfaces to be tested.
83cdf0e10cSrcweir     * Creates two impress documents. After creating of the documents makes short
84cdf0e10cSrcweir     * wait to allow frames to be loaded. Retrieves the collection of the draw pages
85cdf0e10cSrcweir     * from the first document and takes one of them. Inserts some shapes to the
86cdf0e10cSrcweir     * retrieved draw page. Obtains a current controller from the first document
87cdf0e10cSrcweir     * using the interface <code>XModel</code>. The obtained controller is the
88cdf0e10cSrcweir     * instance of the service <code>com.sun.star.presentation.OutlineView</code>.
89cdf0e10cSrcweir     * Object relations created :
90cdf0e10cSrcweir     * <ul>
91cdf0e10cSrcweir     *  <li> <code>'FirstModel'</code> for
92cdf0e10cSrcweir     *      {@link ifc.frame._XController}(the interface <code>XModel</code> of
93cdf0e10cSrcweir     *      the first created document) </li>
94cdf0e10cSrcweir     *  <li> <code>'Frame'</code> for
95cdf0e10cSrcweir     *      {@link ifc.frame._XController}(the frame of the created
96cdf0e10cSrcweir     *      document) </li>
97cdf0e10cSrcweir     *  <li> <code>'SecondModel'</code> for
98cdf0e10cSrcweir     *      {@link ifc.frame._XController}(the interface <code>XModel</code> of
99cdf0e10cSrcweir     *      the second created document) </li>
100cdf0e10cSrcweir     *  <li> <code>'SecondController'</code> for
101cdf0e10cSrcweir     *      {@link ifc.frame._XController}(the current controller of the second
102cdf0e10cSrcweir     *      created document) </li>
103cdf0e10cSrcweir     * </ul>
104cdf0e10cSrcweir     * @see com.sun.star.frame.XModel
105cdf0e10cSrcweir     */
106cdf0e10cSrcweir     protected synchronized TestEnvironment createTestEnvironment
107cdf0e10cSrcweir             (TestParameters Param, PrintWriter log) {
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         log.println( "creating a test environment" );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         // get a soffice factory object
112cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
113cdf0e10cSrcweir         XDrawPages xDP = null;
114cdf0e10cSrcweir         try {
115cdf0e10cSrcweir             log.println( "creating a impress document" );
116cdf0e10cSrcweir             xImpressDoc = SOF.createImpressDoc(null);
117cdf0e10cSrcweir             shortWait();
118cdf0e10cSrcweir             xDP = DrawTools.getDrawPages(xImpressDoc);
119cdf0e10cSrcweir             xDP.insertNewByIndex(0);
120cdf0e10cSrcweir             xDP.insertNewByIndex(0);
121cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
122cdf0e10cSrcweir             e.printStackTrace( log );
123cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         XModel aModel = (XModel)
127cdf0e10cSrcweir             UnoRuntime.queryInterface(XModel.class, xImpressDoc);
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         XInterface oObj = aModel.getCurrentController();
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         //Change to Slide view
132cdf0e10cSrcweir         try {
133cdf0e10cSrcweir             String aSlotID = "slot:27011";
134cdf0e10cSrcweir             XDispatchProvider xDispProv = (XDispatchProvider)
135cdf0e10cSrcweir                 UnoRuntime.queryInterface( XDispatchProvider.class, oObj );
136cdf0e10cSrcweir             XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
137cdf0e10cSrcweir                 UnoRuntime.queryInterface(XURLTransformer.class,
138cdf0e10cSrcweir         ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
139cdf0e10cSrcweir             // Because it's an in/out parameter we must use an array of URL objects.
140cdf0e10cSrcweir             URL[] aParseURL = new URL[1];
141cdf0e10cSrcweir             aParseURL[0] = new URL();
142cdf0e10cSrcweir             aParseURL[0].Complete = aSlotID;
143cdf0e10cSrcweir             xParser.parseStrict(aParseURL);
144cdf0e10cSrcweir             URL aURL = aParseURL[0];
145cdf0e10cSrcweir             XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
146cdf0e10cSrcweir             if( xDispatcher != null )
147cdf0e10cSrcweir                     xDispatcher.dispatch( aURL, null );
148cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
149cdf0e10cSrcweir             log.println("Couldn't change to slide view");
150cdf0e10cSrcweir         }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         try {
153cdf0e10cSrcweir             log.println( "creating a second impress document" );
154cdf0e10cSrcweir             xSecondDrawDoc = SOF.createImpressDoc(null);
155cdf0e10cSrcweir             shortWait();
156cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
157cdf0e10cSrcweir             e.printStackTrace( log );
158cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
159cdf0e10cSrcweir         }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         XModel aModel2 = (XModel)
162cdf0e10cSrcweir             UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
163cdf0e10cSrcweir 
164cdf0e10cSrcweir         XWindow anotherWindow = (XWindow) UnoRuntime.queryInterface(
165cdf0e10cSrcweir                                 XWindow.class,aModel2.getCurrentController());
166cdf0e10cSrcweir 
167cdf0e10cSrcweir         oObj = aModel.getCurrentController();
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         log.println( "creating a new environment for slide view object" );
170cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment( oObj );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         if (anotherWindow != null) {
173cdf0e10cSrcweir             tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
174cdf0e10cSrcweir         }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir          //Adding ObjRelations for XController
177cdf0e10cSrcweir         tEnv.addObjRelation("FirstModel", aModel);
178cdf0e10cSrcweir 
179cdf0e10cSrcweir         XFrame the_frame = the_Desk.getCurrentFrame();
180cdf0e10cSrcweir         tEnv.addObjRelation("Frame", the_frame);
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         //Adding ObjRelations for XController
183cdf0e10cSrcweir         tEnv.addObjRelation("SecondModel", aModel2);
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         XController secondController = aModel2.getCurrentController();
186cdf0e10cSrcweir         tEnv.addObjRelation("SecondController", secondController);
187cdf0e10cSrcweir         tEnv.addObjRelation("XDispatchProvider.URL",
188cdf0e10cSrcweir                                     "slot:27069");
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
191cdf0e10cSrcweir 
192cdf0e10cSrcweir         //creating obj-relation for the XSelectionSupplier
193cdf0e10cSrcweir         try {
194cdf0e10cSrcweir             Object[] selections =
195cdf0e10cSrcweir                     new Object[]{xDP.getByIndex(0),xDP.getByIndex(1),xDP.getByIndex(2)};
196cdf0e10cSrcweir             tEnv.addObjRelation("Selections", selections);
197cdf0e10cSrcweir         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
198cdf0e10cSrcweir             e.printStackTrace(log);
199cdf0e10cSrcweir         }  catch (com.sun.star.lang.WrappedTargetException e) {
200cdf0e10cSrcweir             e.printStackTrace(log);
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir         log.println("Implementation Name: " + utils.getImplName(oObj));
203cdf0e10cSrcweir 
204cdf0e10cSrcweir         return tEnv;
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     } // finish method getTestEnvironment
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     private void shortWait() {
209cdf0e10cSrcweir         try {
210cdf0e10cSrcweir             Thread.sleep(1000) ;
211cdf0e10cSrcweir         } catch (InterruptedException e) {
212cdf0e10cSrcweir             System.out.println("While waiting :" + e) ;
213cdf0e10cSrcweir         }
214cdf0e10cSrcweir     }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 
217cdf0e10cSrcweir } // finish class SdUnoOutlineView
218cdf0e10cSrcweir 
219