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>HandoutMode</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_HandoutView
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>HandoutMode</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 for (int i
= 1; i
< 10; i
++){
170 the_pages
.insertNewByIndex(i
);
172 XIndexAccess oDPi
= UnoRuntime
.queryInterface(XIndexAccess
.class,the_pages
);
174 XDrawPage oDrawPage
= null;
176 oDrawPage
= (XDrawPage
) AnyConverter
.toObject(
177 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
178 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
179 e
.printStackTrace( log
);
180 throw new StatusException("Couldn't get DrawPage", e
);
181 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
182 e
.printStackTrace( log
);
183 throw new StatusException("Couldn't get DrawPage", e
);
184 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
185 e
.printStackTrace( log
);
186 throw new StatusException("Couldn't get DrawPage", e
);
189 //put something on the drawpage
190 log
.println( "inserting some Shapes" );
191 XShapes oShapes
= UnoRuntime
.queryInterface(XShapes
.class, oDrawPage
);
192 XShape shape1
= SOF
.createShape(
193 xDrawDoc
, 3000, 4500, 15000, 1000, "Ellipse");
194 XShape shape2
= SOF
.createShape(
195 xDrawDoc
, 5000, 3500, 7500, 5000, "Rectangle");
196 XShape shape3
= SOF
.createShape(
197 xDrawDoc
, 3000, 500, 5000, 1000, "Line");
203 log
.println("switch to HandoutView...");
205 utils
.dispatchURL(xMSF
, xDrawDoc
, ".uno:HandoutMode");
206 } catch (Exception e
){
207 e
.printStackTrace(log
);
208 throw new StatusException(Status
.failed(e
.toString()));
211 utils
.shortWait(500);
213 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xDrawDoc
);
215 XInterface oObj
= aModel
.getCurrentController();
217 log
.println("bring first document to front...");
218 DesktopTools
.bringWindowToFront(aModel
);
220 XModel aModel2
= UnoRuntime
.queryInterface(XModel
.class, xSecondDrawDoc
);
222 XWindow anotherWindow
= UnoRuntime
.queryInterface(
223 XWindow
.class,aModel2
.getCurrentController());
225 log
.println( "creating a new environment for impress view object" );
226 TestEnvironment tEnv
= new TestEnvironment( oObj
);
228 if (anotherWindow
!= null) {
229 tEnv
.addObjRelation("XWindow.AnotherWindow",anotherWindow
);
232 Object oShapeCol1
= null;
233 Object oShapeCol2
= null;
236 createInstance("com.sun.star.drawing.ShapeCollection");
238 createInstance("com.sun.star.drawing.ShapeCollection");
239 } catch(com
.sun
.star
.uno
.Exception e
) {
240 e
.printStackTrace(log
);
241 throw new StatusException(Status
.failed("Couldn't create instance"));
244 XShapes xShapes1
= UnoRuntime
.queryInterface(XShapes
.class, oShapeCol1
);
245 XShapes xShapes2
= UnoRuntime
.queryInterface(XShapes
.class, oShapeCol2
);
246 xShapes1
.add(shape2
);
247 xShapes1
.add(shape3
);
248 xShapes2
.add(shape1
);
251 tEnv
.addObjRelation("Selections", new Object
[] {
252 oDrawPage
, oShapeCol1
, oShapeCol2
});
253 tEnv
.addObjRelation("Comparer", new Comparator
<Object
>() {
254 public int compare(Object o1
, Object o2
) {
255 XIndexAccess indAc1
= UnoRuntime
.queryInterface(XIndexAccess
.class, o1
);
256 XIndexAccess indAc2
= UnoRuntime
.queryInterface(XIndexAccess
.class, o2
);
257 if (indAc1
== null || indAc2
== null) return -1;
258 if (indAc1
.getCount() == indAc2
.getCount()) {
266 tEnv
.addObjRelation("Pages", the_pages
);
268 //Adding ObjRelations for XController
269 tEnv
.addObjRelation("FirstModel", aModel
);
271 tEnv
.addObjRelation("XUserInputInterception.XModel", aModel
);
273 XFrame the_frame
= the_Desk
.getCurrentFrame();
274 tEnv
.addObjRelation("Frame", the_frame
);
276 aModel
= UnoRuntime
.queryInterface(XModel
.class, xSecondDrawDoc
);
277 //Adding ObjRelations for XController
278 tEnv
.addObjRelation("SecondModel", aModel
);
280 XController secondController
= aModel
.getCurrentController();
281 tEnv
.addObjRelation("SecondController", secondController
);
282 tEnv
.addObjRelation("XDispatchProvider.URL",
285 //Adding relations for DrawingDocumentDrawView
286 XDrawPage new_page
= the_pages
.insertNewByIndex(1);
287 tEnv
.addObjRelation("DrawPage", new_page
);
289 log
.println("Implementation Name: "+utils
.getImplName(oObj
));
291 XModifiable modify
= UnoRuntime
.queryInterface(XModifiable
.class,xDrawDoc
);
293 tEnv
.addObjRelation("Modifiable",modify
);
295 tEnv
.addObjRelation("XComponent.DisposeThis", xDrawDoc
);
300 } // finish method getTestEnvironment
302 private void shortWait() {
305 } catch (InterruptedException e
) {
306 System
.out
.println("While waiting :" + e
) ;