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