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
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.DesktopTools
;
28 import util
.SOfficeFactory
;
31 import com
.sun
.star
.awt
.XWindow
;
32 import com
.sun
.star
.container
.XIndexAccess
;
33 import com
.sun
.star
.drawing
.XDrawPage
;
34 import com
.sun
.star
.drawing
.XDrawPages
;
35 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
36 import com
.sun
.star
.drawing
.XShape
;
37 import com
.sun
.star
.drawing
.XShapes
;
38 import com
.sun
.star
.frame
.XController
;
39 import com
.sun
.star
.frame
.XDesktop
;
40 import com
.sun
.star
.frame
.XFrame
;
41 import com
.sun
.star
.frame
.XModel
;
42 import com
.sun
.star
.lang
.XComponent
;
43 import com
.sun
.star
.uno
.AnyConverter
;
44 import com
.sun
.star
.uno
.Type
;
45 import com
.sun
.star
.uno
.UnoRuntime
;
46 import com
.sun
.star
.uno
.XInterface
;
47 import com
.sun
.star
.util
.XModifiable
;
50 * Test for object which is represented by service
51 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. <p>
52 * Object implements the following interfaces :
54 * <li> <code>com::sun::star::drawing::DrawingDocumentDrawView</code></li>
55 * <li> <code>com::sun::star::lang::XComponent</code></li>
56 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
57 * <li> <code>com::sun::star::frame::XController</code></li>
58 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
59 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
60 * <li> <code>com::sun::star::drawing::XDrawView</code></li>
62 * @see com.sun.star.drawing.DrawingDocumentDrawView
63 * @see com.sun.star.lang.XComponent
64 * @see com.sun.star.lang.XServiceInfo
65 * @see com.sun.star.frame.XController
66 * @see com.sun.star.beans.XPropertySet
67 * @see com.sun.star.view.XSelectionSupplier
68 * @see com.sun.star.drawing.XDrawView
69 * @see ifc.drawing._DrawingDocumentDrawView
70 * @see ifc.lang._XComponent
71 * @see ifc.lang._XServiceInfo
72 * @see ifc.frame._XController
73 * @see ifc.beans._XPropertySet
74 * @see ifc.view._XSelectionSupplier
75 * @see ifc.drawing._XDrawView
77 public class SdUnoPresView
extends TestCase
{
78 static XDesktop xDesktop
;
79 static XComponent xImpressDoc
;
80 static XComponent xSecondDrawDoc
;
83 * Creates the instance of the service <code>com.sun.star.frame.Desktop</code>.
84 * @see com.sun.star.frame.Desktop
87 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
88 xDesktop
= DesktopTools
.createDesktop(Param
.getMSF());
92 * Called while disposing a <code>TestEnvironment</code>.
93 * Disposes Impress documents.
94 * @param Param test parameters
95 * @param log writer to log information while testing
98 protected void cleanup( TestParameters Param
, PrintWriter log
) {
99 log
.println("disposing impress documents");
100 util
.DesktopTools
.closeDoc(xImpressDoc
);
101 util
.DesktopTools
.closeDoc(xSecondDrawDoc
);
105 * Creating a Test environment for the interfaces to be tested.
106 * Creates two impress documents. After creating of the documents makes short
107 * wait to allow frames to be loaded. Retrieves the collection of the draw pages
108 * from the first document and takes one of them. Inserts some shapes to the
109 * retrieved draw page. Obtains a current controller from the first document
110 * using the interface <code>XModel</code>. The obtained controller is the
111 * instance of the service
112 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>.
113 * Object relations created :
115 * <li> <code>'First'</code> for
116 * {@link ifc.view._XSelectionSupplier}(the first created shape) </li>
117 * <li> <code>'Second'</code> for
118 * {@link ifc.view._XSelectionSupplier}(the second created shape) </li>
119 * <li> <code>'Pages'</code> for
120 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw
122 * <li> <code>'FirstModel'</code> for
123 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
124 * the first created document) </li>
125 * <li> <code>'Frame'</code> for
126 * {@link ifc.frame._XController}(the frame of the created
128 * <li> <code>'SecondModel'</code> for
129 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
130 * the second created document) </li>
131 * <li> <code>'SecondController'</code> for
132 * {@link ifc.frame._XController}(the current controller of the second
133 * created document) </li>
135 * @see com.sun.star.frame.XModel
136 * @see com.sun.star.drawing.DrawingDocumentDrawView
139 protected TestEnvironment createTestEnvironment
140 (TestParameters Param
, PrintWriter log
) throws Exception
{
142 log
.println( "creating a test environment" );
144 // get a soffice factory object
145 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
148 log
.println( "creating two impress documents" );
149 xImpressDoc
= SOF
.createImpressDoc(null);
150 xSecondDrawDoc
= SOF
.createImpressDoc(null);
151 util
.utils
.waitForEventIdle(Param
.getMSF());
153 // get the drawpage of drawing here
154 log
.println( "getting Drawpage" );
155 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class, xImpressDoc
);
156 XDrawPages the_pages
= oDPS
.getDrawPages();
157 XIndexAccess oDPi
= UnoRuntime
.queryInterface(XIndexAccess
.class,the_pages
);
159 XDrawPage oDrawPage
= null;
160 XDrawPage secondDrawPage
= null;
161 oDrawPage
= (XDrawPage
) AnyConverter
.toObject(
162 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
163 the_pages
.insertNewByIndex(0);
164 the_pages
.insertNewByIndex(0);
165 the_pages
.insertNewByIndex(0);
166 the_pages
.insertNewByIndex(0);
167 secondDrawPage
= (XDrawPage
) AnyConverter
.toObject(
168 new Type(XDrawPage
.class),oDPi
.getByIndex(3));
170 //put something on the drawpage
171 log
.println( "inserting some Shapes" );
172 XShapes oShapes
= UnoRuntime
.queryInterface(XShapes
.class, oDrawPage
);
173 XShape shape1
= SOF
.createShape(
174 xImpressDoc
, 5000, 3500, 7500, 5000, "Rectangle");
177 oShapes
= UnoRuntime
.queryInterface(XShapes
.class, secondDrawPage
);
178 shape1
= SOF
.createShape(
179 xImpressDoc
, 3000, 4500, 15000, 1000, "Ellipse");
182 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xImpressDoc
);
184 XInterface oObj
= aModel
.getCurrentController();
186 XModel aModel2
= UnoRuntime
.queryInterface(XModel
.class, xSecondDrawDoc
);
188 XWindow anotherWindow
= UnoRuntime
.queryInterface(
189 XWindow
.class,aModel2
.getCurrentController());
191 log
.println( "creating a new environment for impress view object" );
192 TestEnvironment tEnv
= new TestEnvironment( oObj
);
194 if (anotherWindow
!= null) {
195 tEnv
.addObjRelation("XWindow.AnotherWindow",anotherWindow
);
198 tEnv
.addObjRelation("Selections", new Object
[] {
199 oDrawPage
, secondDrawPage
});
201 tEnv
.addObjRelation("Comparer", new Comparator
<Object
>() {
202 public int compare(Object o1
, Object o2
) {
203 XIndexAccess indAc1
= UnoRuntime
.queryInterface(XIndexAccess
.class, o1
);
204 XIndexAccess indAc2
= UnoRuntime
.queryInterface(XIndexAccess
.class, o2
);
205 if (indAc1
== null || indAc2
== null) return -1;
206 if (indAc1
.getCount() == indAc2
.getCount()) {
212 tEnv
.addObjRelation("FirstPage", oDrawPage
);
213 tEnv
.addObjRelation("SecondPage", secondDrawPage
);
215 tEnv
.addObjRelation("Pages", the_pages
);
217 //Adding ObjRelations for XController
218 tEnv
.addObjRelation("FirstModel", aModel
);
220 tEnv
.addObjRelation("XUserInputInterception.XModel", aModel
);
222 XFrame the_frame
= xDesktop
.getCurrentFrame();
223 tEnv
.addObjRelation("Frame", the_frame
);
225 aModel
= UnoRuntime
.queryInterface(XModel
.class, xSecondDrawDoc
);
226 //Adding ObjRelations for XController
227 tEnv
.addObjRelation("SecondModel", aModel
);
229 XController secondController
= aModel
.getCurrentController();
230 tEnv
.addObjRelation("SecondController", secondController
);
231 tEnv
.addObjRelation("XDispatchProvider.URL",
234 log
.println("Implementation Name: "+utils
.getImplName(oObj
));
236 XModifiable modify
= UnoRuntime
.queryInterface(XModifiable
.class,xImpressDoc
);
238 tEnv
.addObjRelation("Modifiable",modify
);
241 tEnv
.addObjRelation("XComponent.DisposeThis", xImpressDoc
);
245 } // finish method getTestEnvironment
248 } // finish class SdUnoDrawView