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
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
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.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew 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     */
initialize(TestParameters Param, PrintWriter log)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.
99*e6b649b5SPedro Giffuni     * @param Param test parameters
100cdf0e10cSrcweir     * @param log writer to log information while testing
101cdf0e10cSrcweir     */
cleanup( TestParameters Param, PrintWriter log)102cdf0e10cSrcweir     protected void cleanup( TestParameters Param, PrintWriter log) {
103cdf0e10cSrcweir         log.println("disposing impress documents");
104170fb961SPedro Giffuni         util.DesktopTools.closeDoc(xImpressDoc);
105170fb961SPedro Giffuni         util.DesktopTools.closeDoc(xSecondDrawDoc);
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     /**
109cdf0e10cSrcweir     * Creating a Testenvironment for the interfaces to be tested.
110cdf0e10cSrcweir     * Creates two impress documents. After creating of the documents makes short
111cdf0e10cSrcweir     * wait to allow frames to be loaded. Retrieves the collection of the draw pages
112cdf0e10cSrcweir     * from the first document and takes one of them. Inserts some shapes to the
113cdf0e10cSrcweir     * retrieved draw page. Obtains a current controller from the first document
114cdf0e10cSrcweir     * using the interface <code>XModel</code>. The obtained controller is the
115cdf0e10cSrcweir     * instance of the service <code>com.sun.star.presentation.OutlineView</code>.
116cdf0e10cSrcweir     * Object relations created :
117cdf0e10cSrcweir     * <ul>
118cdf0e10cSrcweir     *  <li> <code>'FirstModel'</code> for
119cdf0e10cSrcweir     *      {@link ifc.frame._XController}(the interface <code>XModel</code> of
120cdf0e10cSrcweir     *      the first created document) </li>
121cdf0e10cSrcweir     *  <li> <code>'Frame'</code> for
122cdf0e10cSrcweir     *      {@link ifc.frame._XController}(the frame of the created
123cdf0e10cSrcweir     *      document) </li>
124cdf0e10cSrcweir     *  <li> <code>'SecondModel'</code> for
125cdf0e10cSrcweir     *      {@link ifc.frame._XController}(the interface <code>XModel</code> of
126cdf0e10cSrcweir     *      the second created document) </li>
127cdf0e10cSrcweir     *  <li> <code>'SecondController'</code> for
128cdf0e10cSrcweir     *      {@link ifc.frame._XController}(the current controller of the second
129cdf0e10cSrcweir     *      created document) </li>
130cdf0e10cSrcweir     * </ul>
131cdf0e10cSrcweir     * @see com.sun.star.frame.XModel
132cdf0e10cSrcweir     */
createTestEnvironment(TestParameters Param, PrintWriter log)133cdf0e10cSrcweir     protected synchronized TestEnvironment createTestEnvironment
134cdf0e10cSrcweir             (TestParameters Param, PrintWriter log) {
135cdf0e10cSrcweir 
136cdf0e10cSrcweir         log.println( "creating a test environment" );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         // get a soffice factory object
139cdf0e10cSrcweir         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         try {
142cdf0e10cSrcweir             log.println( "creating a impress document" );
143cdf0e10cSrcweir             xImpressDoc = SOF.createImpressDoc(null);
144cdf0e10cSrcweir             shortWait();
145cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
146cdf0e10cSrcweir             e.printStackTrace( log );
147cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
148cdf0e10cSrcweir         }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         XDrawPagesSupplier oDPS = (XDrawPagesSupplier)
151cdf0e10cSrcweir             UnoRuntime.queryInterface(XDrawPagesSupplier.class, xImpressDoc);
152cdf0e10cSrcweir         XDrawPages the_pages = oDPS.getDrawPages();
153cdf0e10cSrcweir         XIndexAccess oDPi = (XIndexAccess)
154cdf0e10cSrcweir             UnoRuntime.queryInterface(XIndexAccess.class,the_pages);
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         XModel aModel = (XModel)
157cdf0e10cSrcweir             UnoRuntime.queryInterface(XModel.class, xImpressDoc);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         XInterface oObj = aModel.getCurrentController();
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         //Change to Outline view
162cdf0e10cSrcweir         try {
163cdf0e10cSrcweir             String aSlotID = "slot:27010";
164cdf0e10cSrcweir             XDispatchProvider xDispProv = (XDispatchProvider)
165cdf0e10cSrcweir                 UnoRuntime.queryInterface( XDispatchProvider.class, oObj );
166cdf0e10cSrcweir             XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
167cdf0e10cSrcweir                 UnoRuntime.queryInterface(XURLTransformer.class,
168cdf0e10cSrcweir         ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
169cdf0e10cSrcweir             // Because it's an in/out parameter we must use an array of URL objects.
170cdf0e10cSrcweir             URL[] aParseURL = new URL[1];
171cdf0e10cSrcweir             aParseURL[0] = new URL();
172cdf0e10cSrcweir             aParseURL[0].Complete = aSlotID;
173cdf0e10cSrcweir             xParser.parseStrict(aParseURL);
174cdf0e10cSrcweir             URL aURL = aParseURL[0];
175cdf0e10cSrcweir             XDispatch xDispatcher = xDispProv.queryDispatch( aURL,"",0);
176cdf0e10cSrcweir             if( xDispatcher != null )
177cdf0e10cSrcweir                     xDispatcher.dispatch( aURL, null );
178cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
179cdf0e10cSrcweir             log.println("Couldn't change mode");
180cdf0e10cSrcweir         }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         try {
183cdf0e10cSrcweir             log.println( "creating a second impress document" );
184cdf0e10cSrcweir             xSecondDrawDoc = SOF.createImpressDoc(null);
185cdf0e10cSrcweir             shortWait();
186cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
187cdf0e10cSrcweir             e.printStackTrace( log );
188cdf0e10cSrcweir             throw new StatusException("Couldn't create document", e);
189cdf0e10cSrcweir         }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         XModel aModel2 = (XModel)
192cdf0e10cSrcweir             UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
193cdf0e10cSrcweir 
194cdf0e10cSrcweir         XWindow anotherWindow = (XWindow) UnoRuntime.queryInterface(
195cdf0e10cSrcweir                                 XWindow.class,aModel2.getCurrentController());
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         oObj = aModel.getCurrentController();
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 
200cdf0e10cSrcweir         log.println( "creating a new environment for impress view object" );
201cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment( oObj );
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         if (anotherWindow != null) {
204cdf0e10cSrcweir             tEnv.addObjRelation("XWindow.AnotherWindow", anotherWindow);
205cdf0e10cSrcweir         }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir          //Adding ObjRelations for XController
208cdf0e10cSrcweir         tEnv.addObjRelation("FirstModel", aModel);
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
211cdf0e10cSrcweir 
212cdf0e10cSrcweir         XFrame the_frame = the_Desk.getCurrentFrame();
213cdf0e10cSrcweir         tEnv.addObjRelation("Frame", the_frame);
214cdf0e10cSrcweir 
215cdf0e10cSrcweir          aModel = (XModel)
216cdf0e10cSrcweir             UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
217cdf0e10cSrcweir         //Adding ObjRelations for XController
218cdf0e10cSrcweir         tEnv.addObjRelation("SecondModel", aModel);
219cdf0e10cSrcweir 
220cdf0e10cSrcweir         XController secondController = aModel.getCurrentController();
221cdf0e10cSrcweir         tEnv.addObjRelation("SecondController", secondController);
222cdf0e10cSrcweir         tEnv.addObjRelation("XDispatchProvider.URL",
223cdf0e10cSrcweir                                     "slot:27069");
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         log.println("Implementation Name: " + utils.getImplName(oObj));
226cdf0e10cSrcweir 
227cdf0e10cSrcweir         return tEnv;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     } // finish method getTestEnvironment
230cdf0e10cSrcweir 
shortWait()231cdf0e10cSrcweir     private void shortWait() {
232cdf0e10cSrcweir         try {
233cdf0e10cSrcweir             Thread.sleep(5000) ;
234cdf0e10cSrcweir         } catch (InterruptedException e) {
235cdf0e10cSrcweir             System.out.println("While waiting :" + e) ;
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir     }
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 
240cdf0e10cSrcweir } // finish class SdUnoOutlineView
241cdf0e10cSrcweir 
242