Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / DrawController_NotesView.java
blobb1abd6070b67298b21b830c595961ac7566e4c06
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.Status;
25 import lib.StatusException;
26 import lib.TestCase;
27 import lib.TestEnvironment;
28 import lib.TestParameters;
29 import util.DesktopTools;
30 import util.SOfficeFactory;
31 import util.utils;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.container.XIndexAccess;
35 import com.sun.star.drawing.XDrawPage;
36 import com.sun.star.drawing.XDrawPages;
37 import com.sun.star.drawing.XDrawPagesSupplier;
38 import com.sun.star.drawing.XShape;
39 import com.sun.star.drawing.XShapes;
40 import com.sun.star.frame.XController;
41 import com.sun.star.frame.XDesktop;
42 import com.sun.star.frame.XFrame;
43 import com.sun.star.frame.XModel;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.uno.AnyConverter;
47 import com.sun.star.uno.Type;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 import com.sun.star.util.XModifiable;
52 /**
53 * Test for object which is represented by service
54 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>. <p>
55 * The view was switched to <b>NotesMode</b>. <p>
56 * Object implements the following interfaces :
57 * <ul>
58 * <li> <code>com::sun::star::drawing::DrawingDocumentDrawView</code></li>
59 * <li> <code>com::sun::star::lang::XComponent</code></li>
60 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
61 * <li> <code>com::sun::star::frame::XController</code></li>
62 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
63 * <li> <code>com::sun::star::view::XSelectionSupplier</code></li>
64 * <li> <code>com::sun::star::drawing::XDrawView</code></li>
65 * </ul>
66 * @see com.sun.star.drawing.DrawingDocumentDrawView
67 * @see com.sun.star.lang.XComponent
68 * @see com.sun.star.lang.XServiceInfo
69 * @see com.sun.star.frame.XController
70 * @see com.sun.star.beans.XPropertySet
71 * @see com.sun.star.view.XSelectionSupplier
72 * @see com.sun.star.drawing.XDrawView
73 * @see ifc.drawing._DrawingDocumentDrawView
74 * @see ifc.lang._XComponent
75 * @see ifc.lang._XServiceInfo
76 * @see ifc.frame._XController
77 * @see ifc.beans._XPropertySet
78 * @see ifc.view._XSelectionSupplier
79 * @see ifc.drawing._XDrawView
81 public class DrawController_NotesView extends TestCase {
82 static XDesktop the_Desk;
83 static XComponent xDrawDoc;
84 static XComponent xSecondDrawDoc;
86 /**
87 * Creates the instance of the service
88 * <code>com.sun.star.frame.Desktop</code>.
89 * @see com.sun.star.frame.Desktop
91 @Override
92 protected void initialize(TestParameters Param, PrintWriter log) {
93 the_Desk = UnoRuntime.queryInterface(
94 XDesktop.class, DesktopTools.createDesktop(
95 Param.getMSF()) );
98 /**
99 * Called while disposing a <code>TestEnvironment</code>.
100 * Disposes Impress documents.
101 * @param Param test parameters
102 * @param log writer to log information while testing
104 @Override
105 protected void cleanup( TestParameters Param, PrintWriter log) {
106 log.println("disposing impress documents");
107 util.DesktopTools.closeDoc(xDrawDoc);
108 util.DesktopTools.closeDoc(xSecondDrawDoc);
112 * Creating a Testenvironment for the interfaces to be tested.
113 * Creates two impress documents. After creating
114 * of the documents makes short
115 * wait to allow frames to be loaded. Retrieves
116 * the collection of the draw pages
117 * from the first document and takes one of them. Inserts some shapes to the
118 * retrieved draw page.
119 * Switch to the <b>NotesMode</b>.
120 * Obtains a current controller from the first document
121 * using the interface <code>XModel</code>. The obtained controller is the
122 * instance of the service
123 * <code>com.sun.star.drawing.DrawingDocumentDrawView</code>.
124 * Object relations created :
125 * <ul>
126 * <li> <code>'Pages'</code> for
127 * {@link ifc.drawing._XDrawView}(the retrieved collection of the draw
128 * pages) </li>
129 * <li> <code>'FirstModel'</code> for
130 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
131 * the first created document) </li>
132 * <li> <code>'Frame'</code> for
133 * {@link ifc.frame._XController}(the frame of the created
134 * document) </li>
135 * <li> <code>'SecondModel'</code> for
136 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
137 * the second created document) </li>
138 * <li> <code>'SecondController'</code> for
139 * {@link ifc.frame._XController}(the current controller of the second
140 * created document) </li>
141 * <li> <code>'DrawPage'</code> for
142 * {@link ifc.drawing._DrawingDocumentDrawView}(the draw page which will
143 * be new current page) </li>
144 * </ul>
145 * @see com.sun.star.frame.XModel
146 * @see com.sun.star.drawing.DrawingDocumentDrawView
148 @Override
149 protected synchronized TestEnvironment createTestEnvironment
150 (TestParameters Param, PrintWriter log) {
152 log.println( "creating a test environment" );
153 XMultiServiceFactory xMSF = Param.getMSF();
154 // get a soffice factory object
155 SOfficeFactory SOF = SOfficeFactory.getFactory(xMSF);
157 try {
158 log.println( "creating two impress documents" );
159 xSecondDrawDoc = SOF.createImpressDoc(null);
160 util.utils.pause(1000);
161 xDrawDoc = SOF.createImpressDoc(null);
162 util.utils.pause(1000);
163 } catch (com.sun.star.uno.Exception e) {
164 e.printStackTrace( log );
165 throw new StatusException("Couldn't create document", e);
168 // get the drawpage of drawing here
169 log.println( "getting Drawpage" );
170 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
171 XDrawPages the_pages = oDPS.getDrawPages();
172 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class,the_pages);
174 XDrawPage oDrawPage = null;
175 try {
176 oDrawPage = (XDrawPage) AnyConverter.toObject(
177 new Type(XDrawPage.class),oDPi.getByIndex(0));
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 xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse");
194 XShape shape2 = SOF.createShape(
195 xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle");
196 XShape shape3 = SOF.createShape(
197 xDrawDoc, 3000, 500, 5000, 1000, "Line");
198 oShapes.add(shape1);
199 oShapes.add(shape2);
200 oShapes.add(shape3);
201 util.utils.pause(1000);
203 log.println("switch to HandoutView...");
204 try{
205 utils.dispatchURL(xMSF, xDrawDoc, ".uno:NotesMode");
206 } catch (Exception e){
207 e.printStackTrace(log);
208 throw new StatusException(e, Status.failed(e.getMessage()));
211 utils.pause(500);
213 XModel aModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc);
215 XInterface oObj = aModel.getCurrentController();
217 log.println("bring first document to front...");
218 DesktopTools.bringWindowToFront(aModel);
220 XModel aModel2 = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
222 XWindow anotherWindow = UnoRuntime.queryInterface(
223 XWindow.class,aModel2.getCurrentController());
225 log.println( "creating a new environment for impress view object" );
226 TestEnvironment tEnv = new TestEnvironment( oObj );
228 if (anotherWindow != null) {
229 tEnv.addObjRelation("XWindow.AnotherWindow",anotherWindow);
232 Object oShapeCol1 = null;
233 Object oShapeCol2 = null;
234 try {
235 oShapeCol1 = xMSF.
236 createInstance("com.sun.star.drawing.ShapeCollection");
237 oShapeCol2 = xMSF.
238 createInstance("com.sun.star.drawing.ShapeCollection");
239 } catch(com.sun.star.uno.Exception e) {
240 throw new StatusException(e, Status.failed("Couldn't create instance"));
243 XShapes xShapes1 = UnoRuntime.queryInterface(XShapes.class, oShapeCol1);
244 XShapes xShapes2 = UnoRuntime.queryInterface(XShapes.class, oShapeCol2);
245 xShapes1.add(shape2);
246 xShapes1.add(shape3);
247 xShapes2.add(shape1);
248 util.utils.pause(1000);
250 tEnv.addObjRelation("Selections", new Object[] {
251 oDrawPage, oShapeCol1, oShapeCol2});
252 tEnv.addObjRelation("Comparer", new Comparator<Object>() {
253 public int compare(Object o1, Object o2) {
254 XIndexAccess indAc1 = UnoRuntime.queryInterface(XIndexAccess.class, o1);
255 XIndexAccess indAc2 = UnoRuntime.queryInterface(XIndexAccess.class, o2);
256 if (indAc1 == null || indAc2 == null) return -1;
257 if (indAc1.getCount() == indAc2.getCount()) {
258 return 0;
260 return 1;
261 }});
265 tEnv.addObjRelation("Pages", the_pages);
267 //Adding ObjRelations for XController
268 tEnv.addObjRelation("FirstModel", aModel);
270 tEnv.addObjRelation("XUserInputInterception.XModel", aModel);
272 XFrame the_frame = the_Desk.getCurrentFrame();
273 tEnv.addObjRelation("Frame", the_frame);
275 aModel = UnoRuntime.queryInterface(XModel.class, xSecondDrawDoc);
276 //Adding ObjRelations for XController
277 tEnv.addObjRelation("SecondModel", aModel);
279 XController secondController = aModel.getCurrentController();
280 tEnv.addObjRelation("SecondController", secondController);
281 tEnv.addObjRelation("XDispatchProvider.URL",
282 "slot:27009");
284 //Adding relations for DrawingDocumentDrawView
285 XDrawPage new_page = the_pages.insertNewByIndex(1);
286 tEnv.addObjRelation("DrawPage", new_page);
288 log.println("Implementation Name: "+utils.getImplName(oObj));
290 XModifiable modify = UnoRuntime.queryInterface(XModifiable.class,xDrawDoc);
292 tEnv.addObjRelation("Modifiable",modify);
294 tEnv.addObjRelation("XComponent.DisposeThis", xDrawDoc);
297 return tEnv;
299 } // finish method getTestEnvironment