bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / DrawController_DrawView.java
blobfc5962395a5137c1d2af2f4e5d7db09a7cffbedc
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.Status;
25 import lib.StatusException;
26 import lib.TestCase;
27 import lib.TestEnvironment;
28 import lib.TestParameters;
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.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;
49 /**
50 * Test for object which is represented by service
51 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. <p>
52 * Object implements the following interfaces :
53 * <ul>
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>
61 * </ul>
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 DrawController_DrawView extends TestCase {
78 static XComponent xDrawDoc;
79 static XComponent xSecondDrawDoc;
81 /**
82 * Called while disposing a <code>TestEnvironment</code>.
83 * Disposes Impress documents.
84 * @param Param test parameters
85 * @param log writer to log information while testing
87 @Override
88 protected void cleanup( TestParameters Param, PrintWriter log) {
89 log.println("disposing impress documents");
90 util.DesktopTools.closeDoc(xDrawDoc);
91 util.DesktopTools.closeDoc(xSecondDrawDoc);
94 /**
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Creates two impress documents. After creating
97 * of the documents makes short
98 * wait to allow frames to be loaded. Retrieves
99 * the collection of the draw pages
100 * from the first document and takes one of them. Inserts some shapes to the
101 * retrieved draw page. Obtains a current controller from the first document
102 * using the interface <code>XModel</code>. The obtained controller is the
103 * instance of the service
104 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>.
105 * Object relations created :
106 * <ul>
107 * <li> <code>'Pages'</code> for
108 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw
109 * pages) </li>
110 * <li> <code>'FirstModel'</code> for
111 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
112 * the first created document) </li>
113 * <li> <code>'Frame'</code> for
114 * {@link ifc.frame._XController}(the frame of the created
115 * document) </li>
116 * <li> <code>'SecondModel'</code> for
117 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
118 * the second created document) </li>
119 * <li> <code>'SecondController'</code> for
120 * {@link ifc.frame._XController}(the current controller of the second
121 * created document) </li>
122 * <li> <code>'DrawPage'</code> for
123 * {@link ifc.drawing._DrawingDocumentDrawView}(the draw page which will
124 * be new current page) </li>
125 * </ul>
126 * @see com.sun.star.frame.XModel
127 * @see com.sun.star.drawing.DrawingDocumentDrawView
129 @Override
130 protected synchronized TestEnvironment createTestEnvironment
131 (TestParameters Param, PrintWriter log) {
133 log.println( "creating a test environment" );
135 // get a soffice factory object
136 SOfficeFactory SOF = SOfficeFactory.getFactory(
137 Param.getMSF());
139 try {
140 log.println( "creating two impress documents" );
141 xDrawDoc = SOF.createDrawDoc(null);
142 util.utils.pause(1000);
143 xSecondDrawDoc = SOF.createDrawDoc(null);
144 util.utils.pause(1000);
145 } catch (com.sun.star.uno.Exception e) {
146 e.printStackTrace( log );
147 throw new StatusException("Couldn't create document", e);
150 // get the drawpage of drawing here
151 log.println( "getting Drawpage" );
152 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
153 XDrawPages the_pages = oDPS.getDrawPages();
154 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class,the_pages);
156 XDrawPage oDrawPage = null;
157 try {
158 oDrawPage = (XDrawPage) AnyConverter.toObject(
159 new Type(XDrawPage.class),oDPi.getByIndex(0));
160 } catch (com.sun.star.lang.WrappedTargetException e) {
161 e.printStackTrace( log );
162 throw new StatusException("Couldn't get DrawPage", e);
163 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
164 e.printStackTrace( log );
165 throw new StatusException("Couldn't get DrawPage", e);
166 } catch (com.sun.star.lang.IllegalArgumentException e) {
167 e.printStackTrace( log );
168 throw new StatusException("Couldn't get DrawPage", e);
171 //put something on the drawpage
172 log.println( "inserting some Shapes" );
173 XShapes oShapes = UnoRuntime.queryInterface(XShapes.class, oDrawPage);
174 XShape shape1 = SOF.createShape(
175 xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse");
176 XShape shape2 = SOF.createShape(
177 xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle");
178 XShape shape3 = SOF.createShape(
179 xDrawDoc, 3000, 500, 5000, 1000, "Line");
180 oShapes.add(shape1);
181 oShapes.add(shape2);
182 oShapes.add(shape3);
183 util.utils.pause(1000);
185 XModel aModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc);
187 XInterface oObj = aModel.getCurrentController();
189 XModel aModel2 = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
190 XController aController2 = aModel2.getCurrentController();
192 XWindow anotherWindow = UnoRuntime.queryInterface(
193 XWindow.class, aController2);
195 log.println( "creating a new environment for impress view object" );
196 TestEnvironment tEnv = new TestEnvironment( oObj );
198 if (anotherWindow != null) {
199 tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow);
202 Object oShapeCol1 = null;
203 Object oShapeCol2 = null;
204 try {
205 oShapeCol1 = Param.getMSF().
206 createInstance("com.sun.star.drawing.ShapeCollection");
207 oShapeCol2 = Param.getMSF().
208 createInstance("com.sun.star.drawing.ShapeCollection");
209 } catch(com.sun.star.uno.Exception e) {
210 throw new StatusException(e, Status.failed("Couldn't create instance"));
213 XShapes xShapes1 = UnoRuntime.queryInterface(XShapes.class, oShapeCol1);
214 XShapes xShapes2 = UnoRuntime.queryInterface(XShapes.class, oShapeCol2);
215 xShapes1.add(shape2);
216 xShapes1.add(shape3);
217 xShapes2.add(shape1);
218 util.utils.pause(1000);
221 tEnv.addObjRelation("Selections", new Object[] {
222 oDrawPage, oShapeCol1, oShapeCol2});
223 tEnv.addObjRelation("Comparer", new Comparator<Object>() {
224 public int compare(Object o1, Object o2) {
225 XIndexAccess indAc1 = UnoRuntime.queryInterface(XIndexAccess.class, o1);
226 XIndexAccess indAc2 = UnoRuntime.queryInterface(XIndexAccess.class, o2);
227 if (indAc1 == null || indAc2 == null) return -1;
228 if (indAc1.getCount() == indAc2.getCount()) {
229 return 0;
231 return 1;
232 }});
236 tEnv.addObjRelation("Pages", the_pages);
238 //Adding ObjRelations for XController
239 tEnv.addObjRelation("FirstModel", aModel);
241 tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
243 XFrame the_frame = aController2.getFrame();
244 tEnv.addObjRelation("Frame", the_frame);
246 //Adding ObjRelations for XController
247 tEnv.addObjRelation("SecondModel", aModel2);
249 tEnv.addObjRelation("SecondController", aController2);
250 tEnv.addObjRelation("XDispatchProvider.URL",
251 "slot:27009");
253 //Adding relations for DrawingDocumentDrawView
254 XDrawPage new_page = the_pages.insertNewByIndex(1);
255 tEnv.addObjRelation("DrawPage", new_page);
257 log.println("Implementation Name: "+utils.getImplName(oObj));
259 XModifiable modify = UnoRuntime.queryInterface(XModifiable.class,xDrawDoc);
261 tEnv.addObjRelation("Modifiable",modify);
263 tEnv.addObjRelation("XComponent.DisposeThis", xDrawDoc);
265 return tEnv;
267 } // finish method getTestEnvironment