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
;
24 import lib
.StatusException
;
26 import lib
.TestEnvironment
;
27 import lib
.TestParameters
;
28 import util
.DesktopTools
;
29 import util
.SOfficeFactory
;
32 import com
.sun
.star
.awt
.XWindow
;
33 import com
.sun
.star
.container
.XIndexAccess
;
34 import com
.sun
.star
.drawing
.XDrawPage
;
35 import com
.sun
.star
.drawing
.XDrawPages
;
36 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
37 import com
.sun
.star
.drawing
.XShape
;
38 import com
.sun
.star
.drawing
.XShapes
;
39 import com
.sun
.star
.frame
.XController
;
40 import com
.sun
.star
.frame
.XDesktop
;
41 import com
.sun
.star
.frame
.XFrame
;
42 import com
.sun
.star
.frame
.XModel
;
43 import com
.sun
.star
.lang
.XComponent
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.uno
.AnyConverter
;
46 import com
.sun
.star
.uno
.Type
;
47 import com
.sun
.star
.uno
.UnoRuntime
;
48 import com
.sun
.star
.uno
.XInterface
;
49 import com
.sun
.star
.util
.XModifiable
;
52 * Test for object which is represented by service
53 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. <p>
54 * Object implements the following interfaces :
56 * <li> <code>com::sun::star::drawing::DrawingDocumentDrawView</code></li>
57 * <li> <code>com::sun::star::lang::XComponent</code></li>
58 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
59 * <li> <code>com::sun::star::frame::XController</code></li>
60 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
61 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
62 * <li> <code>com::sun::star::drawing::XDrawView</code></li>
64 * @see com.sun.star.drawing.DrawingDocumentDrawView
65 * @see com.sun.star.lang.XComponent
66 * @see com.sun.star.lang.XServiceInfo
67 * @see com.sun.star.frame.XController
68 * @see com.sun.star.beans.XPropertySet
69 * @see com.sun.star.view.XSelectionSupplier
70 * @see com.sun.star.drawing.XDrawView
71 * @see ifc.drawing._DrawingDocumentDrawView
72 * @see ifc.lang._XComponent
73 * @see ifc.lang._XServiceInfo
74 * @see ifc.frame._XController
75 * @see ifc.beans._XPropertySet
76 * @see ifc.view._XSelectionSupplier
77 * @see ifc.drawing._XDrawView
79 public class SdUnoPresView
extends TestCase
{
80 static XDesktop the_Desk
;
81 static XComponent xImpressDoc
;
82 static XComponent xSecondDrawDoc
;
85 * Creates the instance of the service <code>com.sun.star.frame.Desktop</code>.
86 * @see com.sun.star.frame.Desktop
88 protected void initialize(TestParameters Param
, PrintWriter log
) {
89 the_Desk
= UnoRuntime
.queryInterface(
90 XDesktop
.class, DesktopTools
.createDesktop(
91 (XMultiServiceFactory
)Param
.getMSF()) );
95 * Called while disposing a <code>TestEnvironment</code>.
96 * Disposes Impress documents.
97 * @param Param test parameters
98 * @param log writer to log information while testing
100 protected void cleanup( TestParameters Param
, PrintWriter log
) {
101 log
.println("disposing impress documents");
102 util
.DesktopTools
.closeDoc(xImpressDoc
);
103 util
.DesktopTools
.closeDoc(xSecondDrawDoc
);
107 * Creating a Test environment for the interfaces to be tested.
108 * Creates two impress documents. After creating of the documents makes short
109 * wait to allow frames to be loaded. Retrieves the collection of the draw pages
110 * from the first document and takes one of them. Inserts some shapes to the
111 * retrieved draw page. Obtains a current controller from the first document
112 * using the interface <code>XModel</code>. The obtained controller is the
113 * instance of the service
114 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>.
115 * Object relations created :
117 * <li> <code>'First'</code> for
118 * {@link ifc.view._XSelectionSupplier}(the first created shape) </li>
119 * <li> <code>'Second'</code> for
120 * {@link ifc.view._XSelectionSupplier}(the second created shape) </li>
121 * <li> <code>'Pages'</code> for
122 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw
124 * <li> <code>'FirstModel'</code> for
125 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
126 * the first created document) </li>
127 * <li> <code>'Frame'</code> for
128 * {@link ifc.frame._XController}(the frame of the created
130 * <li> <code>'SecondModel'</code> for
131 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
132 * the second created document) </li>
133 * <li> <code>'SecondController'</code> for
134 * {@link ifc.frame._XController}(the current controller of the second
135 * created document) </li>
137 * @see com.sun.star.frame.XModel
138 * @see com.sun.star.drawing.DrawingDocumentDrawView
140 protected synchronized TestEnvironment createTestEnvironment
141 (TestParameters Param
, PrintWriter log
) {
143 log
.println( "creating a test environment" );
145 // get a soffice factory object
146 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
147 (XMultiServiceFactory
)Param
.getMSF());
150 log
.println( "creating two impress documents" );
151 xImpressDoc
= SOF
.createImpressDoc(null);
152 xSecondDrawDoc
= SOF
.createImpressDoc(null);
154 } catch (com
.sun
.star
.uno
.Exception e
) {
155 e
.printStackTrace( log
);
156 throw new StatusException("Couldn't create document", e
);
159 // get the drawpage of drawing here
160 log
.println( "getting Drawpage" );
161 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class, xImpressDoc
);
162 XDrawPages the_pages
= oDPS
.getDrawPages();
163 XIndexAccess oDPi
= UnoRuntime
.queryInterface(XIndexAccess
.class,the_pages
);
165 XDrawPage oDrawPage
= null;
166 XDrawPage secondDrawPage
= null;
168 oDrawPage
= (XDrawPage
) AnyConverter
.toObject(
169 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
170 the_pages
.insertNewByIndex(0);
171 the_pages
.insertNewByIndex(0);
172 the_pages
.insertNewByIndex(0);
173 the_pages
.insertNewByIndex(0);
174 secondDrawPage
= (XDrawPage
) AnyConverter
.toObject(
175 new Type(XDrawPage
.class),oDPi
.getByIndex(3));
176 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
177 e
.printStackTrace( log
);
178 throw new StatusException("Couldn't get DrawPage", e
);
179 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
180 e
.printStackTrace( log
);
181 throw new StatusException("Couldn't get DrawPage", e
);
182 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
183 e
.printStackTrace( log
);
184 throw new StatusException("Couldn't get DrawPage", e
);
187 //put something on the drawpage
188 log
.println( "inserting some Shapes" );
189 XShapes oShapes
= UnoRuntime
.queryInterface(XShapes
.class, oDrawPage
);
190 XShape shape1
= SOF
.createShape(
191 xImpressDoc
, 5000, 3500, 7500, 5000, "Rectangle");
194 oShapes
= UnoRuntime
.queryInterface(XShapes
.class, secondDrawPage
);
195 shape1
= SOF
.createShape(
196 xImpressDoc
, 3000, 4500, 15000, 1000, "Ellipse");
199 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xImpressDoc
);
201 XInterface oObj
= aModel
.getCurrentController();
203 XModel aModel2
= UnoRuntime
.queryInterface(XModel
.class, xSecondDrawDoc
);
205 XWindow anotherWindow
= UnoRuntime
.queryInterface(
206 XWindow
.class,aModel2
.getCurrentController());
208 log
.println( "creating a new environment for impress view object" );
209 TestEnvironment tEnv
= new TestEnvironment( oObj
);
211 if (anotherWindow
!= null) {
212 tEnv
.addObjRelation("XWindow.AnotherWindow",anotherWindow
);
215 tEnv
.addObjRelation("Selections", new Object
[] {
216 oDrawPage
, secondDrawPage
});
218 tEnv
.addObjRelation("Comparer", new Comparator
<Object
>() {
219 public int compare(Object o1
, Object o2
) {
220 XIndexAccess indAc1
= UnoRuntime
.queryInterface(XIndexAccess
.class, o1
);
221 XIndexAccess indAc2
= UnoRuntime
.queryInterface(XIndexAccess
.class, o2
);
222 if (indAc1
== null || indAc2
== null) return -1;
223 if (indAc1
.getCount() == indAc2
.getCount()) {
229 tEnv
.addObjRelation("FirstPage", oDrawPage
);
230 tEnv
.addObjRelation("SecondPage", secondDrawPage
);
232 //tEnv.addObjRelation("First", shape1);
233 //tEnv.addObjRelation("Second", shape2);
235 tEnv
.addObjRelation("Pages", the_pages
);
237 //Adding ObjRelations for XController
238 tEnv
.addObjRelation("FirstModel", aModel
);
240 tEnv
.addObjRelation("XUserInputInterception.XModel", aModel
);
242 XFrame the_frame
= the_Desk
.getCurrentFrame();
243 tEnv
.addObjRelation("Frame", the_frame
);
245 aModel
= UnoRuntime
.queryInterface(XModel
.class, xSecondDrawDoc
);
246 //Adding ObjRelations for XController
247 tEnv
.addObjRelation("SecondModel", aModel
);
249 XController secondController
= aModel
.getCurrentController();
250 tEnv
.addObjRelation("SecondController", secondController
);
251 tEnv
.addObjRelation("XDispatchProvider.URL",
254 log
.println("Implementation Name: "+utils
.getImplName(oObj
));
256 XModifiable modify
= UnoRuntime
.queryInterface(XModifiable
.class,xImpressDoc
);
258 tEnv
.addObjRelation("Modifiable",modify
);
261 tEnv
.addObjRelation("XComponent.DisposeThis", xImpressDoc
);
265 } // finish method getTestEnvironment
267 private void shortWait() {
270 } catch (InterruptedException e
) {
271 System
.out
.println("While waiting :" + e
) ;
276 } // finish class SdUnoDrawView