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