bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdUnoDrawView.java
blob7c12d3a1d75ae6e897ff828ff3ee7d4e41d2ecb3
1 /*
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 .
19 package mod._sd;
21 import java.io.PrintWriter;
22 import java.util.Comparator;
24 import lib.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
28 import util.DesktopTools;
29 import util.SOfficeFactory;
30 import util.utils;
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.uno.AnyConverter;
45 import com.sun.star.uno.Type;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 import com.sun.star.util.XModifiable;
50 /**
51 * Test for object which is represented by service
52 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. <p>
53 * Object implements the following interfaces :
54 * <ul>
55 * <li> <code>com::sun::star::drawing::DrawingDocumentDrawView</code></li>
56 * <li> <code>com::sun::star::lang::XComponent</code></li>
57 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
58 * <li> <code>com::sun::star::frame::XController</code></li>
59 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
60 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
61 * <li> <code>com::sun::star::drawing::XDrawView</code></li>
62 * </ul>
63 * @see com.sun.star.drawing.DrawingDocumentDrawView
64 * @see com.sun.star.lang.XComponent
65 * @see com.sun.star.lang.XServiceInfo
66 * @see com.sun.star.frame.XController
67 * @see com.sun.star.beans.XPropertySet
68 * @see com.sun.star.view.XSelectionSupplier
69 * @see com.sun.star.drawing.XDrawView
70 * @see ifc.drawing._DrawingDocumentDrawView
71 * @see ifc.lang._XComponent
72 * @see ifc.lang._XServiceInfo
73 * @see ifc.frame._XController
74 * @see ifc.beans._XPropertySet
75 * @see ifc.view._XSelectionSupplier
76 * @see ifc.drawing._XDrawView
78 public class SdUnoDrawView extends TestCase {
79 static XDesktop the_Desk;
80 static XComponent xDrawDoc;
81 static XComponent xSecondDrawDoc;
83 /**
84 * Creates the instance of the service
85 * <code>com.sun.star.frame.Desktop</code>.
86 * @see com.sun.star.frame.Desktop
88 @Override
89 protected void initialize(TestParameters Param, PrintWriter log) {
90 the_Desk = UnoRuntime.queryInterface(
91 XDesktop.class, DesktopTools.createDesktop(
92 Param.getMSF()) );
95 /**
96 * Called while disposing a <code>TestEnvironment</code>.
97 * Disposes Impress documents.
98 * @param Param test parameters
99 * @param log writer to log information while testing
101 @Override
102 protected void cleanup( TestParameters Param, PrintWriter log) {
103 log.println("disposing draw documents");
104 util.DesktopTools.closeDoc(xDrawDoc);
105 util.DesktopTools.closeDoc(xSecondDrawDoc);
109 * Creating a Testenvironment for the interfaces to be tested.
110 * Creates two impress documents. After creating
111 * of the documents makes short
112 * wait to allow frames to be loaded. Retrieves
113 * the collection of the draw pages
114 * from the first document and takes one of them. Inserts some shapes to the
115 * retrieved draw page. Obtains a current controller from the first document
116 * using the interface <code>XModel</code>. The obtained controller is the
117 * instance of the service
118 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>.
119 * Object relations created :
120 * <ul>
121 * <li> <code>'Pages'</code> for
122 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw
123 * pages) </li>
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
129 * document) </li>
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>
136 * <li> <code>'DrawPage'</code> for
137 * {@link ifc.drawing._DrawingDocumentDrawView}(the draw page which will
138 * be new current page) </li>
139 * </ul>
140 * @see com.sun.star.frame.XModel
141 * @see com.sun.star.drawing.DrawingDocumentDrawView
143 @Override
144 public synchronized lib.TestEnvironment createTestEnvironment
145 (TestParameters Param, PrintWriter log) {
147 log.println( "creating a test environment" );
149 // get a soffice factory object
150 SOfficeFactory SOF = SOfficeFactory.getFactory(
151 Param.getMSF());
153 try {
154 log.println( "creating two draw documents" );
155 xDrawDoc = SOF.createDrawDoc(null);
156 util.utils.pause(1000);
157 xSecondDrawDoc = SOF.createDrawDoc(null);
158 util.utils.pause(1000);
159 } catch (com.sun.star.uno.Exception e) {
160 e.printStackTrace( log );
161 throw new StatusException("Couldn't create document", e);
164 // get the drawpage of drawing here
165 log.println( "getting Drawpage" );
166 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
167 XDrawPages the_pages = oDPS.getDrawPages();
168 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class,the_pages);
170 XDrawPage oDrawPage = null;
171 try {
172 oDrawPage = (XDrawPage) AnyConverter.toObject(
173 new Type(XDrawPage.class),oDPi.getByIndex(0));
174 } catch (com.sun.star.lang.WrappedTargetException e) {
175 e.printStackTrace( log );
176 throw new StatusException("Couldn't get DrawPage", e);
177 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
178 e.printStackTrace( log );
179 throw new StatusException("Couldn't get DrawPage", e);
180 } catch (com.sun.star.lang.IllegalArgumentException e) {
181 e.printStackTrace( log );
182 throw new StatusException("Couldn't get DrawPage", e);
185 //put something on the drawpage
186 log.println( "inserting some Shapes" );
187 XShapes oShapes = UnoRuntime.queryInterface(XShapes.class, oDrawPage);
188 XShape shape1 = SOF.createShape(
189 xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse");
190 XShape shape2 = SOF.createShape(
191 xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle");
192 XShape shape3 = SOF.createShape(
193 xDrawDoc, 3000, 500, 5000, 1000, "Line");
194 oShapes.add(shape1);
195 oShapes.add(shape2);
196 oShapes.add(shape3);
197 util.utils.pause(1000);
199 XModel aModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc);
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);
216 tEnv.addObjRelation("Selections", new Object[] {
217 shape1, shape2, shape3});
220 tEnv.addObjRelation("Pages", the_pages);
222 //Adding ObjRelations for XController
223 tEnv.addObjRelation("FirstModel", aModel);
225 tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
227 XFrame the_frame = the_Desk.getCurrentFrame();
228 tEnv.addObjRelation("Frame", the_frame);
230 aModel = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
231 //Adding ObjRelations for XController
232 tEnv.addObjRelation("SecondModel", aModel);
234 XController secondController = aModel.getCurrentController();
235 tEnv.addObjRelation("SecondController", secondController);
236 tEnv.addObjRelation("XDispatchProvider.URL",
237 "slot:27009");
239 //Adding relations for DrawingDocumentDrawView
240 XDrawPage new_page = the_pages.insertNewByIndex(1);
241 tEnv.addObjRelation("DrawPage", new_page);
243 log.println("Implementation Name: "+utils.getImplName(oObj));
245 XModifiable modify = UnoRuntime.queryInterface(XModifiable.class,xDrawDoc);
247 tEnv.addObjRelation("Modifiable",modify);
249 tEnv.addObjRelation("XComponent.DisposeThis", xDrawDoc);
251 tEnv.addObjRelation("Comparer", new Comparator<Object>() {
252 public int compare(Object o1, Object o2) {
253 XIndexAccess indAc1 = UnoRuntime.queryInterface(XIndexAccess.class, o1);
254 XIndexAccess indAc2 = UnoRuntime.queryInterface(XIndexAccess.class, o2);
255 if (indAc1 == null || indAc2 == null) return -1;
256 if (indAc1.getCount() == indAc2.getCount()) {
257 return 0;
259 return 1;
260 }});
263 return tEnv;
265 } // finish method getTestEnvironment
268 } // finish class SdUnoDrawView