tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdUnoPresView.java
blobf8860c876fb60cf9f78917bba6f49bdd22ae37ad
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.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.DesktopTools;
28 import util.SOfficeFactory;
29 import util.utils;
31 import com.sun.star.awt.XWindow;
32 import com.sun.star.container.XIndexAccess;
33 import com.sun.star.drawing.XDrawPage;
34 import com.sun.star.drawing.XDrawPages;
35 import com.sun.star.drawing.XDrawPagesSupplier;
36 import com.sun.star.drawing.XShape;
37 import com.sun.star.drawing.XShapes;
38 import com.sun.star.frame.XController;
39 import com.sun.star.frame.XDesktop;
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 SdUnoPresView extends TestCase {
78 static XDesktop xDesktop;
79 static XComponent xImpressDoc;
80 static XComponent xSecondDrawDoc;
82 /**
83 * Creates the instance of the service <code>com.sun.star.frame.Desktop</code>.
84 * @see com.sun.star.frame.Desktop
86 @Override
87 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
88 xDesktop = DesktopTools.createDesktop(Param.getMSF());
91 /**
92 * Called while disposing a <code>TestEnvironment</code>.
93 * Disposes Impress documents.
94 * @param Param test parameters
95 * @param log writer to log information while testing
97 @Override
98 protected void cleanup( TestParameters Param, PrintWriter log) {
99 log.println("disposing impress documents");
100 util.DesktopTools.closeDoc(xImpressDoc);
101 util.DesktopTools.closeDoc(xSecondDrawDoc);
105 * Creating a Test environment for the interfaces to be tested.
106 * Creates two impress documents. After creating of the documents makes short
107 * wait to allow frames to be loaded. Retrieves the collection of the draw pages
108 * from the first document and takes one of them. Inserts some shapes to the
109 * retrieved draw page. Obtains a current controller from the first document
110 * using the interface <code>XModel</code>. The obtained controller is the
111 * instance of the service
112 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>.
113 * Object relations created :
114 * <ul>
115 * <li> <code>'First'</code> for
116 * {@link ifc.view._XSelectionSupplier}(the first created shape) </li>
117 * <li> <code>'Second'</code> for
118 * {@link ifc.view._XSelectionSupplier}(the second created shape) </li>
119 * <li> <code>'Pages'</code> for
120 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw
121 * pages) </li>
122 * <li> <code>'FirstModel'</code> for
123 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
124 * the first created document) </li>
125 * <li> <code>'Frame'</code> for
126 * {@link ifc.frame._XController}(the frame of the created
127 * document) </li>
128 * <li> <code>'SecondModel'</code> for
129 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
130 * the second created document) </li>
131 * <li> <code>'SecondController'</code> for
132 * {@link ifc.frame._XController}(the current controller of the second
133 * created document) </li>
134 * </ul>
135 * @see com.sun.star.frame.XModel
136 * @see com.sun.star.drawing.DrawingDocumentDrawView
138 @Override
139 protected TestEnvironment createTestEnvironment
140 (TestParameters Param, PrintWriter log) throws Exception {
142 log.println( "creating a test environment" );
144 // get a soffice factory object
145 SOfficeFactory SOF = SOfficeFactory.getFactory(
146 Param.getMSF());
148 log.println( "creating two impress documents" );
149 xImpressDoc = SOF.createImpressDoc(null);
150 xSecondDrawDoc = SOF.createImpressDoc(null);
151 util.utils.waitForEventIdle(Param.getMSF());
153 // get the drawpage of drawing here
154 log.println( "getting Drawpage" );
155 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xImpressDoc);
156 XDrawPages the_pages = oDPS.getDrawPages();
157 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class,the_pages);
159 XDrawPage oDrawPage = null;
160 XDrawPage secondDrawPage = null;
161 oDrawPage = (XDrawPage) AnyConverter.toObject(
162 new Type(XDrawPage.class),oDPi.getByIndex(0));
163 the_pages.insertNewByIndex(0);
164 the_pages.insertNewByIndex(0);
165 the_pages.insertNewByIndex(0);
166 the_pages.insertNewByIndex(0);
167 secondDrawPage = (XDrawPage) AnyConverter.toObject(
168 new Type(XDrawPage.class),oDPi.getByIndex(3));
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 xImpressDoc, 5000, 3500, 7500, 5000, "Rectangle");
175 oShapes.add(shape1);
177 oShapes = UnoRuntime.queryInterface(XShapes.class, secondDrawPage);
178 shape1 = SOF.createShape(
179 xImpressDoc, 3000, 4500, 15000, 1000, "Ellipse");
180 oShapes.add(shape1);
182 XModel aModel = UnoRuntime.queryInterface(XModel.class, xImpressDoc);
184 XInterface oObj = aModel.getCurrentController();
186 XModel aModel2 = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
188 XWindow anotherWindow = UnoRuntime.queryInterface(
189 XWindow.class,aModel2.getCurrentController());
191 log.println( "creating a new environment for impress view object" );
192 TestEnvironment tEnv = new TestEnvironment( oObj );
194 if (anotherWindow != null) {
195 tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow);
198 tEnv.addObjRelation("Selections", new Object[] {
199 oDrawPage, secondDrawPage});
201 tEnv.addObjRelation("Comparer", new Comparator<Object>() {
202 public int compare(Object o1, Object o2) {
203 XIndexAccess indAc1 = UnoRuntime.queryInterface(XIndexAccess.class, o1);
204 XIndexAccess indAc2 = UnoRuntime.queryInterface(XIndexAccess.class, o2);
205 if (indAc1 == null || indAc2 == null) return -1;
206 if (indAc1.getCount() == indAc2.getCount()) {
207 return 0;
209 return 1;
210 }});
212 tEnv.addObjRelation("FirstPage", oDrawPage);
213 tEnv.addObjRelation("SecondPage", secondDrawPage);
215 tEnv.addObjRelation("Pages", the_pages);
217 //Adding ObjRelations for XController
218 tEnv.addObjRelation("FirstModel", aModel);
220 tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
222 XFrame the_frame = xDesktop.getCurrentFrame();
223 tEnv.addObjRelation("Frame", the_frame);
225 aModel = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
226 //Adding ObjRelations for XController
227 tEnv.addObjRelation("SecondModel", aModel);
229 XController secondController = aModel.getCurrentController();
230 tEnv.addObjRelation("SecondController", secondController);
231 tEnv.addObjRelation("XDispatchProvider.URL",
232 "slot:27010");
234 log.println("Implementation Name: "+utils.getImplName(oObj));
236 XModifiable modify = UnoRuntime.queryInterface(XModifiable.class,xImpressDoc);
238 tEnv.addObjRelation("Modifiable",modify);
241 tEnv.addObjRelation("XComponent.DisposeThis", xImpressDoc);
243 return tEnv;
245 } // finish method getTestEnvironment
248 } // finish class SdUnoDrawView