bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdUnoPresView.java
blob788a1763061132050f7113c05b0deba25ce9c514
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 SdUnoPresView extends TestCase {
79 static XDesktop the_Desk;
80 static XComponent xImpressDoc;
81 static XComponent xSecondDrawDoc;
83 /**
84 * Creates the instance of the service <code>com.sun.star.frame.Desktop</code>.
85 * @see com.sun.star.frame.Desktop
87 @Override
88 protected void initialize(TestParameters Param, PrintWriter log) {
89 the_Desk = UnoRuntime.queryInterface(
90 XDesktop.class, DesktopTools.createDesktop(
91 Param.getMSF()) );
94 /**
95 * Called while disposing a <code>TestEnvironment</code>.
96 * Disposes Impress documents.
97 * @param Param test parameters
98 * @param log writer to log information while testing
100 @Override
101 protected void cleanup( TestParameters Param, PrintWriter log) {
102 log.println("disposing impress documents");
103 util.DesktopTools.closeDoc(xImpressDoc);
104 util.DesktopTools.closeDoc(xSecondDrawDoc);
108 * Creating a Test environment for the interfaces to be tested.
109 * Creates two impress documents. After creating of the documents makes short
110 * wait to allow frames to be loaded. Retrieves the collection of the draw pages
111 * from the first document and takes one of them. Inserts some shapes to the
112 * retrieved draw page. Obtains a current controller from the first document
113 * using the interface <code>XModel</code>. The obtained controller is the
114 * instance of the service
115 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>.
116 * Object relations created :
117 * <ul>
118 * <li> <code>'First'</code> for
119 * {@link ifc.view._XSelectionSupplier}(the first created shape) </li>
120 * <li> <code>'Second'</code> for
121 * {@link ifc.view._XSelectionSupplier}(the second created shape) </li>
122 * <li> <code>'Pages'</code> for
123 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw
124 * pages) </li>
125 * <li> <code>'FirstModel'</code> for
126 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
127 * the first created document) </li>
128 * <li> <code>'Frame'</code> for
129 * {@link ifc.frame._XController}(the frame of the created
130 * document) </li>
131 * <li> <code>'SecondModel'</code> for
132 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
133 * the second created document) </li>
134 * <li> <code>'SecondController'</code> for
135 * {@link ifc.frame._XController}(the current controller of the second
136 * created document) </li>
137 * </ul>
138 * @see com.sun.star.frame.XModel
139 * @see com.sun.star.drawing.DrawingDocumentDrawView
141 @Override
142 protected synchronized 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 Param.getMSF());
151 try {
152 log.println( "creating two impress documents" );
153 xImpressDoc = SOF.createImpressDoc(null);
154 xSecondDrawDoc = SOF.createImpressDoc(null);
155 util.utils.pause(5000);
156 } catch (com.sun.star.uno.Exception e) {
157 e.printStackTrace( log );
158 throw new StatusException("Couldn't create document", e);
161 // get the drawpage of drawing here
162 log.println( "getting Drawpage" );
163 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xImpressDoc);
164 XDrawPages the_pages = oDPS.getDrawPages();
165 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class,the_pages);
167 XDrawPage oDrawPage = null;
168 XDrawPage secondDrawPage = null;
169 try {
170 oDrawPage = (XDrawPage) AnyConverter.toObject(
171 new Type(XDrawPage.class),oDPi.getByIndex(0));
172 the_pages.insertNewByIndex(0);
173 the_pages.insertNewByIndex(0);
174 the_pages.insertNewByIndex(0);
175 the_pages.insertNewByIndex(0);
176 secondDrawPage = (XDrawPage) AnyConverter.toObject(
177 new Type(XDrawPage.class),oDPi.getByIndex(3));
178 } catch (com.sun.star.lang.WrappedTargetException e) {
179 e.printStackTrace( log );
180 throw new StatusException("Couldn't get DrawPage", e);
181 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
182 e.printStackTrace( log );
183 throw new StatusException("Couldn't get DrawPage", e);
184 } catch (com.sun.star.lang.IllegalArgumentException e) {
185 e.printStackTrace( log );
186 throw new StatusException("Couldn't get DrawPage", e);
189 //put something on the drawpage
190 log.println( "inserting some Shapes" );
191 XShapes oShapes = UnoRuntime.queryInterface(XShapes.class, oDrawPage);
192 XShape shape1 = SOF.createShape(
193 xImpressDoc, 5000, 3500, 7500, 5000, "Rectangle");
194 oShapes.add(shape1);
196 oShapes = UnoRuntime.queryInterface(XShapes.class, secondDrawPage);
197 shape1 = SOF.createShape(
198 xImpressDoc, 3000, 4500, 15000, 1000, "Ellipse");
199 oShapes.add(shape1);
201 XModel aModel = UnoRuntime.queryInterface(XModel.class, xImpressDoc);
203 XInterface oObj = aModel.getCurrentController();
205 XModel aModel2 = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
207 XWindow anotherWindow = UnoRuntime.queryInterface(
208 XWindow.class,aModel2.getCurrentController());
210 log.println( "creating a new environment for impress view object" );
211 TestEnvironment tEnv = new TestEnvironment( oObj );
213 if (anotherWindow != null) {
214 tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow);
217 tEnv.addObjRelation("Selections", new Object[] {
218 oDrawPage, secondDrawPage});
220 tEnv.addObjRelation("Comparer", new Comparator<Object>() {
221 public int compare(Object o1, Object o2) {
222 XIndexAccess indAc1 = UnoRuntime.queryInterface(XIndexAccess.class, o1);
223 XIndexAccess indAc2 = UnoRuntime.queryInterface(XIndexAccess.class, o2);
224 if (indAc1 == null || indAc2 == null) return -1;
225 if (indAc1.getCount() == indAc2.getCount()) {
226 return 0;
228 return 1;
229 }});
231 tEnv.addObjRelation("FirstPage", oDrawPage);
232 tEnv.addObjRelation("SecondPage", secondDrawPage);
234 tEnv.addObjRelation("Pages", the_pages);
236 //Adding ObjRelations for XController
237 tEnv.addObjRelation("FirstModel", aModel);
239 tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
241 XFrame the_frame = the_Desk.getCurrentFrame();
242 tEnv.addObjRelation("Frame", the_frame);
244 aModel = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
245 //Adding ObjRelations for XController
246 tEnv.addObjRelation("SecondModel", aModel);
248 XController secondController = aModel.getCurrentController();
249 tEnv.addObjRelation("SecondController", secondController);
250 tEnv.addObjRelation("XDispatchProvider.URL",
251 "slot:27010");
253 log.println("Implementation Name: "+utils.getImplName(oObj));
255 XModifiable modify = UnoRuntime.queryInterface(XModifiable.class,xImpressDoc);
257 tEnv.addObjRelation("Modifiable",modify);
260 tEnv.addObjRelation("XComponent.DisposeThis", xImpressDoc);
262 return tEnv;
264 } // finish method getTestEnvironment
267 } // finish class SdUnoDrawView