tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / DrawController_OutlineView.java
blob85bea8bc5940acd1f063193d0362d03d420b7945
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.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 * The view was switched to <b>OutlineMode</b>. <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 DrawController_OutlineView extends TestCase {
80 static XDesktop xDesktop;
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 @Override
90 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
91 xDesktop = DesktopTools.createDesktop(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(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.
115 * Switch to the <b>OutlineMode</b>.
116 * Obtains a current controller from the first document
117 * using the interface <code>XModel</code>. The obtained controller is the
118 * instance of the service
119 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>.
120 * Object relations created :
121 * <ul>
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 * <li> <code>'DrawPage'</code> for
138 * {@link ifc.drawing._DrawingDocumentDrawView}(the draw page which will
139 * be new current page) </li>
140 * </ul>
141 * @see com.sun.star.frame.XModel
142 * @see com.sun.star.drawing.DrawingDocumentDrawView
144 @Override
145 protected TestEnvironment createTestEnvironment
146 (TestParameters Param, PrintWriter log) throws Exception {
148 log.println( "creating a test environment" );
149 XMultiServiceFactory xMSF = Param.getMSF();
150 // get a soffice factory object
151 SOfficeFactory SOF = SOfficeFactory.getFactory(xMSF);
153 log.println( "creating two impress documents" );
154 xSecondDrawDoc = SOF.createImpressDoc(null);
155 util.utils.waitForEventIdle(Param.getMSF());
156 xDrawDoc = SOF.createImpressDoc(null);
157 util.utils.waitForEventIdle(Param.getMSF());
159 // get the drawpage of drawing here
160 log.println( "getting Drawpage" );
161 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
162 XDrawPages the_pages = oDPS.getDrawPages();
163 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class,the_pages);
165 XDrawPage oDrawPage = (XDrawPage) AnyConverter.toObject(
166 new Type(XDrawPage.class),oDPi.getByIndex(0));
168 //put something on the drawpage
169 log.println( "inserting some Shapes" );
170 XShapes oShapes = UnoRuntime.queryInterface(XShapes.class, oDrawPage);
171 XShape shape1 = SOF.createShape(
172 xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse");
173 XShape shape2 = SOF.createShape(
174 xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle");
175 XShape shape3 = SOF.createShape(
176 xDrawDoc, 3000, 500, 5000, 1000, "Line");
177 oShapes.add(shape1);
178 oShapes.add(shape2);
179 oShapes.add(shape3);
180 util.utils.waitForEventIdle(Param.getMSF());
182 log.println("switch to HandoutView...");
183 utils.dispatchURL(xMSF, xDrawDoc, ".uno:OutlineMode");
185 util.utils.waitForEventIdle(Param.getMSF());
187 XModel aModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc);
189 XInterface oObj = aModel.getCurrentController();
191 log.println("bring first document to front...");
192 DesktopTools.bringWindowToFront(aModel);
194 XModel aModel2 = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
196 XWindow anotherWindow = UnoRuntime.queryInterface(
197 XWindow.class,aModel2.getCurrentController());
199 log.println( "creating a new environment for impress view object" );
200 TestEnvironment tEnv = new TestEnvironment( oObj );
202 if (anotherWindow != null) {
203 tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow);
206 Object oShapeCol1 = null;
207 Object oShapeCol2 = null;
208 oShapeCol1 = xMSF.
209 createInstance("com.sun.star.drawing.ShapeCollection");
210 oShapeCol2 = xMSF.
211 createInstance("com.sun.star.drawing.ShapeCollection");
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.waitForEventIdle(Param.getMSF());
220 tEnv.addObjRelation("Selections", new Object[] {
221 oDrawPage, oShapeCol1, oShapeCol2});
222 tEnv.addObjRelation("Comparer", new Comparator<Object>() {
223 public int compare(Object o1, Object o2) {
224 XIndexAccess indAc1 = UnoRuntime.queryInterface(XIndexAccess.class, o1);
225 XIndexAccess indAc2 = UnoRuntime.queryInterface(XIndexAccess.class, o2);
226 if (indAc1 == null || indAc2 == null) return -1;
227 if (indAc1.getCount() == indAc2.getCount()) {
228 return 0;
230 return 1;
231 }});
235 tEnv.addObjRelation("Pages", the_pages);
237 //Adding ObjRelations for XController
238 tEnv.addObjRelation("FirstModel", aModel);
240 tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
242 XFrame the_frame = xDesktop.getCurrentFrame();
243 tEnv.addObjRelation("Frame", the_frame);
245 aModel = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
246 //Adding ObjRelations for XController
247 tEnv.addObjRelation("SecondModel", aModel);
249 XController secondController = aModel.getCurrentController();
250 tEnv.addObjRelation("SecondController", secondController);
251 tEnv.addObjRelation("XDispatchProvider.URL",
252 "slot:27009");
254 //Adding relations for DrawingDocumentDrawView
255 XDrawPage new_page = the_pages.insertNewByIndex(1);
256 tEnv.addObjRelation("DrawPage", new_page);
258 log.println("Implementation Name: "+utils.getImplName(oObj));
260 XModifiable modify = UnoRuntime.queryInterface(XModifiable.class,xDrawDoc);
262 tEnv.addObjRelation("Modifiable",modify);
264 tEnv.addObjRelation("XComponent.DisposeThis", xDrawDoc);
267 return tEnv;
269 } // finish method getTestEnvironment