2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
22 import java
.util
.Comparator
;
25 import lib
.StatusException
;
27 import lib
.TestEnvironment
;
28 import lib
.TestParameters
;
29 import util
.DesktopTools
;
30 import util
.SOfficeFactory
;
33 import com
.sun
.star
.awt
.XWindow
;
34 import com
.sun
.star
.container
.XIndexAccess
;
35 import com
.sun
.star
.drawing
.XDrawPage
;
36 import com
.sun
.star
.drawing
.XDrawPages
;
37 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
38 import com
.sun
.star
.drawing
.XShape
;
39 import com
.sun
.star
.drawing
.XShapes
;
40 import com
.sun
.star
.frame
.XController
;
41 import com
.sun
.star
.frame
.XDesktop
;
42 import com
.sun
.star
.frame
.XFrame
;
43 import com
.sun
.star
.frame
.XModel
;
44 import com
.sun
.star
.lang
.XComponent
;
45 import com
.sun
.star
.lang
.XMultiServiceFactory
;
46 import com
.sun
.star
.uno
.AnyConverter
;
47 import com
.sun
.star
.uno
.Type
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.uno
.XInterface
;
50 import com
.sun
.star
.util
.XModifiable
;
53 * Test for object which is represented by service
54 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. <p>
55 * The view was switched to <b>OutlineMode</b>. <p>
56 * Object implements the following interfaces :
58 * <li> <code>com::sun::star::drawing::DrawingDocumentDrawView</code></li>
59 * <li> <code>com::sun::star::lang::XComponent</code></li>
60 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
61 * <li> <code>com::sun::star::frame::XController</code></li>
62 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
63 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
64 * <li> <code>com::sun::star::drawing::XDrawView</code></li>
66 * @see com.sun.star.drawing.DrawingDocumentDrawView
67 * @see com.sun.star.lang.XComponent
68 * @see com.sun.star.lang.XServiceInfo
69 * @see com.sun.star.frame.XController
70 * @see com.sun.star.beans.XPropertySet
71 * @see com.sun.star.view.XSelectionSupplier
72 * @see com.sun.star.drawing.XDrawView
73 * @see ifc.drawing._DrawingDocumentDrawView
74 * @see ifc.lang._XComponent
75 * @see ifc.lang._XServiceInfo
76 * @see ifc.frame._XController
77 * @see ifc.beans._XPropertySet
78 * @see ifc.view._XSelectionSupplier
79 * @see ifc.drawing._XDrawView
81 public class DrawController_OutlineView
extends TestCase
{
82 static XDesktop the_Desk
;
83 static XComponent xDrawDoc
;
84 static XComponent xSecondDrawDoc
;
87 * Creates the instance of the service
88 * <code>com.sun.star.frame.Desktop</code>.
89 * @see com.sun.star.frame.Desktop
91 protected void initialize(TestParameters Param
, PrintWriter log
) {
92 the_Desk
= UnoRuntime
.queryInterface(
93 XDesktop
.class, DesktopTools
.createDesktop(
94 (XMultiServiceFactory
)Param
.getMSF()) );
98 * Called while disposing a <code>TestEnvironment</code>.
99 * Disposes Impress documents.
100 * @param Param test parameters
101 * @param log writer to log information while testing
103 protected void cleanup( TestParameters Param
, PrintWriter log
) {
104 log
.println("disposing impress documents");
105 util
.DesktopTools
.closeDoc(xDrawDoc
);
106 util
.DesktopTools
.closeDoc(xSecondDrawDoc
);
110 * Creating a Testenvironment for the interfaces to be tested.
111 * Creates two impress documents. After creating
112 * of the documents makes short
113 * wait to allow frames to be loaded. Retrieves
114 * the collection of the draw pages
115 * from the first document and takes one of them. Inserts some shapes to the
116 * retrieved draw page.
117 * Switch to the <b>OutlineMode</b>.
118 * 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
121 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>.
122 * Object relations created :
124 * <li> <code>'Pages'</code> for
125 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw
127 * <li> <code>'FirstModel'</code> for
128 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
129 * the first created document) </li>
130 * <li> <code>'Frame'</code> for
131 * {@link ifc.frame._XController}(the frame of the created
133 * <li> <code>'SecondModel'</code> for
134 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
135 * the second created document) </li>
136 * <li> <code>'SecondController'</code> for
137 * {@link ifc.frame._XController}(the current controller of the second
138 * created document) </li>
139 * <li> <code>'DrawPage'</code> for
140 * {@link ifc.drawing._DrawingDocumentDrawView}(the draw page which will
141 * be new current page) </li>
143 * @see com.sun.star.frame.XModel
144 * @see com.sun.star.drawing.DrawingDocumentDrawView
146 protected synchronized TestEnvironment createTestEnvironment
147 (TestParameters Param
, PrintWriter log
) {
149 log
.println( "creating a test environment" );
150 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)Param
.getMSF();
151 // get a soffice factory object
152 SOfficeFactory SOF
= SOfficeFactory
.getFactory(xMSF
);
155 log
.println( "creating two impress documents" );
156 xSecondDrawDoc
= SOF
.createImpressDoc(null);
158 xDrawDoc
= SOF
.createImpressDoc(null);
160 } catch (com
.sun
.star
.uno
.Exception e
) {
161 e
.printStackTrace( log
);
162 throw new StatusException("Couldn't create document", e
);
165 // get the drawpage of drawing here
166 log
.println( "getting Drawpage" );
167 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class, xDrawDoc
);
168 XDrawPages the_pages
= oDPS
.getDrawPages();
169 XIndexAccess oDPi
= UnoRuntime
.queryInterface(XIndexAccess
.class,the_pages
);
171 XDrawPage oDrawPage
= null;
173 oDrawPage
= (XDrawPage
) AnyConverter
.toObject(
174 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
175 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
176 e
.printStackTrace( log
);
177 throw new StatusException("Couldn't get DrawPage", e
);
178 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
179 e
.printStackTrace( log
);
180 throw new StatusException("Couldn't get DrawPage", e
);
181 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
182 e
.printStackTrace( log
);
183 throw new StatusException("Couldn't get DrawPage", e
);
186 //put something on the drawpage
187 log
.println( "inserting some Shapes" );
188 XShapes oShapes
= UnoRuntime
.queryInterface(XShapes
.class, oDrawPage
);
189 XShape shape1
= SOF
.createShape(
190 xDrawDoc
, 3000, 4500, 15000, 1000, "Ellipse");
191 XShape shape2
= SOF
.createShape(
192 xDrawDoc
, 5000, 3500, 7500, 5000, "Rectangle");
193 XShape shape3
= SOF
.createShape(
194 xDrawDoc
, 3000, 500, 5000, 1000, "Line");
200 log
.println("switch to HandoutView...");
202 utils
.dispatchURL(xMSF
, xDrawDoc
, ".uno:OutlineMode");
203 } catch (Exception e
){
204 e
.printStackTrace(log
);
205 throw new StatusException(Status
.failed(e
.toString()));
208 utils
.shortWait(500);
210 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xDrawDoc
);
212 XInterface oObj
= aModel
.getCurrentController();
214 log
.println("bring first document to front...");
215 DesktopTools
.bringWindowToFront(aModel
);
217 XModel aModel2
= UnoRuntime
.queryInterface(XModel
.class, xSecondDrawDoc
);
219 XWindow anotherWindow
= UnoRuntime
.queryInterface(
220 XWindow
.class,aModel2
.getCurrentController());
222 log
.println( "creating a new environment for impress view object" );
223 TestEnvironment tEnv
= new TestEnvironment( oObj
);
225 if (anotherWindow
!= null) {
226 tEnv
.addObjRelation("XWindow.AnotherWindow",anotherWindow
);
229 Object oShapeCol1
= null;
230 Object oShapeCol2
= null;
233 createInstance("com.sun.star.drawing.ShapeCollection");
235 createInstance("com.sun.star.drawing.ShapeCollection");
236 } catch(com
.sun
.star
.uno
.Exception e
) {
237 e
.printStackTrace(log
);
238 throw new StatusException(Status
.failed("Couldn't create instance"));
241 XShapes xShapes1
= UnoRuntime
.queryInterface(XShapes
.class, oShapeCol1
);
242 XShapes xShapes2
= UnoRuntime
.queryInterface(XShapes
.class, oShapeCol2
);
243 xShapes1
.add(shape2
);
244 xShapes1
.add(shape3
);
245 xShapes2
.add(shape1
);
248 tEnv
.addObjRelation("Selections", new Object
[] {
249 oDrawPage
, oShapeCol1
, oShapeCol2
});
250 tEnv
.addObjRelation("Comparer", new Comparator
<Object
>() {
251 public int compare(Object o1
, Object o2
) {
252 XIndexAccess indAc1
= UnoRuntime
.queryInterface(XIndexAccess
.class, o1
);
253 XIndexAccess indAc2
= UnoRuntime
.queryInterface(XIndexAccess
.class, o2
);
254 if (indAc1
== null || indAc2
== null) return -1;
255 if (indAc1
.getCount() == indAc2
.getCount()) {
263 tEnv
.addObjRelation("Pages", the_pages
);
265 //Adding ObjRelations for XController
266 tEnv
.addObjRelation("FirstModel", aModel
);
268 tEnv
.addObjRelation("XUserInputInterception.XModel", aModel
);
270 XFrame the_frame
= the_Desk
.getCurrentFrame();
271 tEnv
.addObjRelation("Frame", the_frame
);
273 aModel
= UnoRuntime
.queryInterface(XModel
.class, xSecondDrawDoc
);
274 //Adding ObjRelations for XController
275 tEnv
.addObjRelation("SecondModel", aModel
);
277 XController secondController
= aModel
.getCurrentController();
278 tEnv
.addObjRelation("SecondController", secondController
);
279 tEnv
.addObjRelation("XDispatchProvider.URL",
282 //Adding relations for DrawingDocumentDrawView
283 XDrawPage new_page
= the_pages
.insertNewByIndex(1);
284 tEnv
.addObjRelation("DrawPage", new_page
);
286 log
.println("Implementation Name: "+utils
.getImplName(oObj
));
288 XModifiable modify
= UnoRuntime
.queryInterface(XModifiable
.class,xDrawDoc
);
290 tEnv
.addObjRelation("Modifiable",modify
);
292 tEnv
.addObjRelation("XComponent.DisposeThis", xDrawDoc
);
297 } // finish method getTestEnvironment
299 private void shortWait() {
302 } catch (InterruptedException e
) {
303 System
.out
.println("While waiting :" + e
) ;