bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / DrawController_DrawView.java
blob81b644afe0ae9658401d44f1492b0b45f1113de4
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.lang.XMultiServiceFactory;
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 DrawController_DrawView extends TestCase {
79 static XComponent xDrawDoc;
80 static XComponent xSecondDrawDoc;
82 /**
83 * Called while disposing a <code>TestEnvironment</code>.
84 * Disposes Impress documents.
85 * @param Param test parameters
86 * @param log writer to log information while testing
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 protected synchronized TestEnvironment createTestEnvironment
130 (TestParameters Param, PrintWriter log) {
132 log.println( "creating a test environment" );
134 // get a soffice factory object
135 SOfficeFactory SOF = SOfficeFactory.getFactory(
136 (XMultiServiceFactory)Param.getMSF());
138 try {
139 log.println( "creating two impress documents" );
140 xDrawDoc = SOF.createDrawDoc(null);
141 shortWait();
142 xSecondDrawDoc = SOF.createDrawDoc(null);
143 shortWait();
144 } catch (com.sun.star.uno.Exception e) {
145 e.printStackTrace( log );
146 throw new StatusException("Couldn't create document", e);
149 // get the drawpage of drawing here
150 log.println( "getting Drawpage" );
151 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
152 XDrawPages the_pages = oDPS.getDrawPages();
153 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class,the_pages);
155 XDrawPage oDrawPage = null;
156 try {
157 oDrawPage = (XDrawPage) AnyConverter.toObject(
158 new Type(XDrawPage.class),oDPi.getByIndex(0));
159 } catch (com.sun.star.lang.WrappedTargetException e) {
160 e.printStackTrace( log );
161 throw new StatusException("Couldn't get DrawPage", e);
162 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
163 e.printStackTrace( log );
164 throw new StatusException("Couldn't get DrawPage", e);
165 } catch (com.sun.star.lang.IllegalArgumentException e) {
166 e.printStackTrace( log );
167 throw new StatusException("Couldn't get DrawPage", e);
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 xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse");
175 XShape shape2 = SOF.createShape(
176 xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle");
177 XShape shape3 = SOF.createShape(
178 xDrawDoc, 3000, 500, 5000, 1000, "Line");
179 oShapes.add(shape1);
180 oShapes.add(shape2);
181 oShapes.add(shape3);
182 shortWait();
184 XModel aModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc);
186 XInterface oObj = aModel.getCurrentController();
188 XModel aModel2 = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
189 XController aController2 = aModel2.getCurrentController();
191 XWindow anotherWindow = UnoRuntime.queryInterface(
192 XWindow.class, aController2);
194 log.println( "creating a new environment for impress view object" );
195 TestEnvironment tEnv = new TestEnvironment( oObj );
197 if (anotherWindow != null) {
198 tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow);
201 Object oShapeCol1 = null;
202 Object oShapeCol2 = null;
203 try {
204 oShapeCol1 = ((XMultiServiceFactory)Param.getMSF()).
205 createInstance("com.sun.star.drawing.ShapeCollection");
206 oShapeCol2 = ((XMultiServiceFactory)Param.getMSF()).
207 createInstance("com.sun.star.drawing.ShapeCollection");
208 } catch(com.sun.star.uno.Exception e) {
209 e.printStackTrace(log);
210 throw new StatusException(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 shortWait();
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
269 private void shortWait() {
270 try {
271 Thread.sleep(1000) ;
272 } catch (InterruptedException e) {
273 System.out.println("While waiting :" + e) ;