bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdUnoDrawView.java
blob84cebc5a7d6c15149870621fdb6fe5c5d2265da2
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.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;
51 /**
52 * Test for object which is represented by service
53 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. <p>
54 * Object implements the following interfaces :
55 * <ul>
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>
63 * </ul>
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 SdUnoDrawView extends TestCase {
80 static XDesktop the_Desk;
81 static XComponent xDrawDoc;
82 static XComponent xSecondDrawDoc;
84 /**
85 * Creates the instance of the service
86 * <code>com.sun.star.frame.Desktop</code>.
87 * @see com.sun.star.frame.Desktop
89 protected void initialize(TestParameters Param, PrintWriter log) {
90 the_Desk = UnoRuntime.queryInterface(
91 XDesktop.class, DesktopTools.createDesktop(
92 (XMultiServiceFactory)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 protected void cleanup( TestParameters Param, PrintWriter log) {
102 log.println("disposing draw documents");
103 util.DesktopTools.closeDoc(xDrawDoc);
104 util.DesktopTools.closeDoc(xSecondDrawDoc);
108 * Creating a Testenvironment for the interfaces to be tested.
109 * Creates two impress documents. After creating
110 * of the documents makes short
111 * wait to allow frames to be loaded. Retrieves
112 * the collection of the draw pages
113 * from the first document and takes one of them. Inserts some shapes to the
114 * retrieved draw page. Obtains a current controller from the first document
115 * using the interface <code>XModel</code>. The obtained controller is the
116 * instance of the service
117 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>.
118 * Object relations created :
119 * <ul>
120 * <li> <code>'Pages'</code> for
121 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw
122 * pages) </li>
123 * <li> <code>'FirstModel'</code> for
124 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
125 * the first created document) </li>
126 * <li> <code>'Frame'</code> for
127 * {@link ifc.frame._XController}(the frame of the created
128 * document) </li>
129 * <li> <code>'SecondModel'</code> for
130 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
131 * the second created document) </li>
132 * <li> <code>'SecondController'</code> for
133 * {@link ifc.frame._XController}(the current controller of the second
134 * created document) </li>
135 * <li> <code>'DrawPage'</code> for
136 * {@link ifc.drawing._DrawingDocumentDrawView}(the draw page which will
137 * be new current page) </li>
138 * </ul>
139 * @see com.sun.star.frame.XModel
140 * @see com.sun.star.drawing.DrawingDocumentDrawView
142 public synchronized lib.TestEnvironment createTestEnvironment
143 (TestParameters Param, PrintWriter log) {
145 log.println( "creating a test environment" );
147 // get a soffice factory object
148 SOfficeFactory SOF = SOfficeFactory.getFactory(
149 (XMultiServiceFactory)Param.getMSF());
151 try {
152 log.println( "creating two draw documents" );
153 xDrawDoc = SOF.createDrawDoc(null);
154 shortWait();
155 xSecondDrawDoc = SOF.createDrawDoc(null);
156 shortWait();
157 } catch (com.sun.star.uno.Exception e) {
158 e.printStackTrace( log );
159 throw new StatusException("Couldn't create document", e);
162 // get the drawpage of drawing here
163 log.println( "getting Drawpage" );
164 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
165 XDrawPages the_pages = oDPS.getDrawPages();
166 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class,the_pages);
168 XDrawPage oDrawPage = null;
169 try {
170 oDrawPage = (XDrawPage) AnyConverter.toObject(
171 new Type(XDrawPage.class),oDPi.getByIndex(0));
172 } catch (com.sun.star.lang.WrappedTargetException e) {
173 e.printStackTrace( log );
174 throw new StatusException("Couldn't get DrawPage", e);
175 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
176 e.printStackTrace( log );
177 throw new StatusException("Couldn't get DrawPage", e);
178 } catch (com.sun.star.lang.IllegalArgumentException e) {
179 e.printStackTrace( log );
180 throw new StatusException("Couldn't get DrawPage", e);
183 //put something on the drawpage
184 log.println( "inserting some Shapes" );
185 XShapes oShapes = UnoRuntime.queryInterface(XShapes.class, oDrawPage);
186 XShape shape1 = SOF.createShape(
187 xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse");
188 XShape shape2 = SOF.createShape(
189 xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle");
190 XShape shape3 = SOF.createShape(
191 xDrawDoc, 3000, 500, 5000, 1000, "Line");
192 oShapes.add(shape1);
193 oShapes.add(shape2);
194 oShapes.add(shape3);
195 shortWait();
197 XModel aModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc);
199 XInterface oObj = aModel.getCurrentController();
201 XModel aModel2 = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
203 XWindow anotherWindow = UnoRuntime.queryInterface(
204 XWindow.class,aModel2.getCurrentController());
206 log.println( "creating a new environment for impress view object" );
207 TestEnvironment tEnv = new TestEnvironment( oObj );
209 if (anotherWindow != null) {
210 tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow);
214 tEnv.addObjRelation("Selections", new Object[] {
215 shape1, shape2, shape3});
218 tEnv.addObjRelation("Pages", the_pages);
220 //Adding ObjRelations for XController
221 tEnv.addObjRelation("FirstModel", aModel);
223 tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
225 XFrame the_frame = the_Desk.getCurrentFrame();
226 tEnv.addObjRelation("Frame", the_frame);
228 aModel = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
229 //Adding ObjRelations for XController
230 tEnv.addObjRelation("SecondModel", aModel);
232 XController secondController = aModel.getCurrentController();
233 tEnv.addObjRelation("SecondController", secondController);
234 tEnv.addObjRelation("XDispatchProvider.URL",
235 "slot:27009");
237 //Adding relations for DrawingDocumentDrawView
238 XDrawPage new_page = the_pages.insertNewByIndex(1);
239 tEnv.addObjRelation("DrawPage", new_page);
241 log.println("Implementation Name: "+utils.getImplName(oObj));
243 XModifiable modify = UnoRuntime.queryInterface(XModifiable.class,xDrawDoc);
245 tEnv.addObjRelation("Modifiable",modify);
247 tEnv.addObjRelation("XComponent.DisposeThis", xDrawDoc);
249 tEnv.addObjRelation("Comparer", new Comparator<Object>() {
250 public int compare(Object o1, Object o2) {
251 XIndexAccess indAc1 = UnoRuntime.queryInterface(XIndexAccess.class, o1);
252 XIndexAccess indAc2 = UnoRuntime.queryInterface(XIndexAccess.class, o2);
253 if (indAc1 == null || indAc2 == null) return -1;
254 if (indAc1.getCount() == indAc2.getCount()) {
255 return 0;
257 return 1;
258 }});
261 return tEnv;
263 } // finish method getTestEnvironment
265 private void shortWait() {
266 try {
267 Thread.sleep(1000) ;
268 } catch (InterruptedException e) {
269 System.out.println("While waiting :" + e) ;
274 } // finish class SdUnoDrawView