tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdUnoDrawView.java
blobdd4e0298e1254cb671770515379936ce40fc033e
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 SdUnoDrawView extends TestCase {
78 static XDesktop xDesktop;
79 static XComponent xDrawDoc;
80 static XComponent xSecondDrawDoc;
82 /**
83 * Creates the instance of the service
84 * <code>com.sun.star.frame.Desktop</code>.
85 * @see com.sun.star.frame.Desktop
87 @Override
88 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
89 xDesktop = DesktopTools.createDesktop(Param.getMSF());
92 /**
93 * Called while disposing a <code>TestEnvironment</code>.
94 * Disposes Impress documents.
95 * @param Param test parameters
96 * @param log writer to log information while testing
98 @Override
99 protected void cleanup( TestParameters Param, PrintWriter log) {
100 log.println("disposing draw documents");
101 util.DesktopTools.closeDoc(xDrawDoc);
102 util.DesktopTools.closeDoc(xSecondDrawDoc);
106 * Creating a TestEnvironment for the interfaces to be tested.
107 * Creates two impress documents. After creating
108 * of the documents makes short
109 * wait to allow frames to be loaded. Retrieves
110 * 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>'Pages'</code> for
119 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw
120 * pages) </li>
121 * <li> <code>'FirstModel'</code> for
122 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
123 * the first created document) </li>
124 * <li> <code>'Frame'</code> for
125 * {@link ifc.frame._XController}(the frame of the created
126 * document) </li>
127 * <li> <code>'SecondModel'</code> for
128 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
129 * the second created document) </li>
130 * <li> <code>'SecondController'</code> for
131 * {@link ifc.frame._XController}(the current controller of the second
132 * created document) </li>
133 * <li> <code>'DrawPage'</code> for
134 * {@link ifc.drawing._DrawingDocumentDrawView}(the draw page which will
135 * be new current page) </li>
136 * </ul>
137 * @see com.sun.star.frame.XModel
138 * @see com.sun.star.drawing.DrawingDocumentDrawView
140 @Override
141 public lib.TestEnvironment createTestEnvironment
142 (TestParameters Param, PrintWriter log) throws Exception {
144 log.println( "creating a test environment" );
146 // get a soffice factory object
147 SOfficeFactory SOF = SOfficeFactory.getFactory(
148 Param.getMSF());
150 log.println( "creating two draw documents" );
151 xDrawDoc = SOF.createDrawDoc(null);
152 util.utils.waitForEventIdle(Param.getMSF());
153 xSecondDrawDoc = SOF.createDrawDoc(null);
154 util.utils.waitForEventIdle(Param.getMSF());
156 // get the drawpage of drawing here
157 log.println( "getting Drawpage" );
158 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
159 XDrawPages the_pages = oDPS.getDrawPages();
160 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class,the_pages);
162 XDrawPage oDrawPage = (XDrawPage) AnyConverter.toObject(
163 new Type(XDrawPage.class),oDPi.getByIndex(0));
165 //put something on the drawpage
166 log.println( "inserting some Shapes" );
167 XShapes oShapes = UnoRuntime.queryInterface(XShapes.class, oDrawPage);
168 XShape shape1 = SOF.createShape(
169 xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse");
170 XShape shape2 = SOF.createShape(
171 xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle");
172 XShape shape3 = SOF.createShape(
173 xDrawDoc, 3000, 500, 5000, 1000, "Line");
174 oShapes.add(shape1);
175 oShapes.add(shape2);
176 oShapes.add(shape3);
177 util.utils.waitForEventIdle(Param.getMSF());
179 XModel aModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc);
181 XInterface oObj = aModel.getCurrentController();
183 XModel aModel2 = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
185 XWindow anotherWindow = UnoRuntime.queryInterface(
186 XWindow.class,aModel2.getCurrentController());
188 log.println( "creating a new environment for impress view object" );
189 TestEnvironment tEnv = new TestEnvironment( oObj );
191 if (anotherWindow != null) {
192 tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow);
196 tEnv.addObjRelation("Selections", new Object[] {
197 shape1, shape2, shape3});
200 tEnv.addObjRelation("Pages", the_pages);
202 //Adding ObjRelations for XController
203 tEnv.addObjRelation("FirstModel", aModel);
205 tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
207 XFrame the_frame = xDesktop.getCurrentFrame();
208 tEnv.addObjRelation("Frame", the_frame);
210 aModel = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
211 //Adding ObjRelations for XController
212 tEnv.addObjRelation("SecondModel", aModel);
214 XController secondController = aModel.getCurrentController();
215 tEnv.addObjRelation("SecondController", secondController);
216 tEnv.addObjRelation("XDispatchProvider.URL",
217 ".uno:DrawingMode");
219 //Adding relations for DrawingDocumentDrawView
220 XDrawPage new_page = the_pages.insertNewByIndex(1);
221 tEnv.addObjRelation("DrawPage", new_page);
223 log.println("Implementation Name: "+utils.getImplName(oObj));
225 XModifiable modify = UnoRuntime.queryInterface(XModifiable.class,xDrawDoc);
227 tEnv.addObjRelation("Modifiable",modify);
229 tEnv.addObjRelation("XComponent.DisposeThis", xDrawDoc);
231 tEnv.addObjRelation("Comparer", new Comparator<Object>() {
232 public int compare(Object o1, Object o2) {
233 XIndexAccess indAc1 = UnoRuntime.queryInterface(XIndexAccess.class, o1);
234 XIndexAccess indAc2 = UnoRuntime.queryInterface(XIndexAccess.class, o2);
235 if (indAc1 == null || indAc2 == null) return -1;
236 if (indAc1.getCount() == indAc2.getCount()) {
237 return 0;
239 return 1;
240 }});
243 return tEnv;
245 } // finish method getTestEnvironment
248 } // finish class SdUnoDrawView