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