bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessibleDocumentPagePreview.java
blobab2bf0d685f34bc9f5a1347d556af9207a9a05b7
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._sc;
21 import java.io.PrintWriter;
23 import lib.Status;
24 import lib.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
28 import util.AccessibilityTools;
29 import util.SOfficeFactory;
30 import util.utils;
32 import com.sun.star.accessibility.AccessibleRole;
33 import com.sun.star.accessibility.XAccessible;
34 import com.sun.star.awt.Rectangle;
35 import com.sun.star.awt.XWindow;
36 import com.sun.star.container.XIndexAccess;
37 import com.sun.star.frame.XController;
38 import com.sun.star.frame.XDesktop;
39 import com.sun.star.frame.XDispatch;
40 import com.sun.star.frame.XDispatchProvider;
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.sheet.XSpreadsheet;
45 import com.sun.star.sheet.XSpreadsheetDocument;
46 import com.sun.star.sheet.XSpreadsheets;
47 import com.sun.star.table.XCell;
48 import com.sun.star.uno.AnyConverter;
49 import com.sun.star.uno.Type;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
52 import com.sun.star.util.URL;
53 import com.sun.star.util.XURLTransformer;
55 /**
56 * Test for object which is represented by accessible component of
57 * a spreadsheet page in 'Page Preview' mode.
59 * Object implements the following interfaces :
60 * <ul>
61 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
62 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
63 * </ul> <p>
65 * @see com.sun.star.accessibility.XAccessibleComponent
66 * @see com.sun.star.accessibility.XAccessibleContext
67 * @see ifc.accessibility._XAccessibleComponent
68 * @see ifc.accessibility._XAccessibleContext
70 public class ScAccessibleDocumentPagePreview extends TestCase {
72 private XSpreadsheetDocument xSpreadsheetDoc = null;
74 /**
75 * Called to create an instance of <code>TestEnvironment</code>
76 * with an object to test and related objects.
77 * Switches the document to Print Preview mode.
78 * Obtains accessible object for the page view.
80 * @param Param test parameters
81 * @param log writer to log information while testing
83 * @see TestEnvironment
84 * @see #getTestEnvironment
86 protected TestEnvironment createTestEnvironment(
87 TestParameters Param, PrintWriter log) {
89 XInterface oObj = null;
91 // inserting some content to have non-empty page preview
92 XCell xCell = null;
93 try {
94 XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ;
95 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
96 XSpreadsheet oSheet = null;
97 try {
98 oSheet = (XSpreadsheet) AnyConverter.toObject(
99 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(1));
100 } catch (com.sun.star.lang.IllegalArgumentException iae) {
101 throw new StatusException("couldn't get sheet",iae);
103 xCell = oSheet.getCellByPosition(0, 0) ;
104 xCell.setFormula("ScAccessibleDocumentPagePreview - Page 2");
105 try {
106 oSheet = (XSpreadsheet) AnyConverter.toObject(
107 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(2));
108 } catch (com.sun.star.lang.IllegalArgumentException iae) {
109 throw new StatusException("couldn't get sheet",iae);
111 xCell = oSheet.getCellByPosition(0, 0) ;
112 xCell.setFormula("ScAccessibleDocumentPagePreview - Page 3");
114 try {
115 oSheet = (XSpreadsheet) AnyConverter.toObject(
116 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
117 } catch (com.sun.star.lang.IllegalArgumentException iae) {
118 throw new StatusException("couldn't get sheet",iae);
120 xCell = oSheet.getCellByPosition(0, 0) ;
121 xCell.setFormula("ScAccessibleDocumentPagePreview");
122 } catch(com.sun.star.lang.WrappedTargetException e) {
123 log.println("Exception creating document page preview :");
124 e.printStackTrace(log);
125 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
126 log.println("Exception creating document page preview :");
127 e.printStackTrace(log);
130 XModel aModel = UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
132 XController xController = aModel.getCurrentController();
134 // switching to 'Page Preview' mode
135 try {
136 XDispatchProvider xDispProv = UnoRuntime.queryInterface(XDispatchProvider.class, xController);
137 XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class,
138 ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
139 // Because it's an in/out parameter we must use an array of URL objects.
140 URL[] aParseURL = new URL[1];
141 aParseURL[0] = new URL();
142 aParseURL[0].Complete = ".uno:PrintPreview";
143 xParser.parseStrict(aParseURL);
144 URL aURL = aParseURL[0];
145 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
146 if(xDispatcher != null)
147 xDispatcher.dispatch( aURL, null );
148 } catch (com.sun.star.uno.Exception e) {
149 log.println("Couldn't change mode");
150 throw new StatusException(Status.failed("Couldn't change mode"));
153 try {
154 Thread.sleep(500);
155 } catch (InterruptedException ex) {}
157 AccessibilityTools at = new AccessibilityTools();
159 XWindow xWindow = AccessibilityTools.getCurrentContainerWindow((XMultiServiceFactory)Param.getMSF(), aModel);
160 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
161 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
163 oObj = AccessibilityTools.getAccessibleObjectForRole
164 (xRoot, AccessibleRole.DOCUMENT, "");
166 log.println("ImplementationName " + utils.getImplName(oObj));
168 TestEnvironment tEnv = new TestEnvironment(oObj);
170 XDesktop desk = UnoRuntime.queryInterface(
171 XDesktop.class,util.DesktopTools.createDesktop((XMultiServiceFactory)Param.getMSF()));
172 final XWindow win = desk.getCurrentFrame().getComponentWindow();
174 tEnv.addObjRelation("EventProducer",
175 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
176 public void fireEvent() {
177 Rectangle rec = win.getPosSize();
178 win.setPosSize(rec.X,rec.Y,rec.Height-10,rec.Width, com.sun.star.awt.PosSize.POSSIZE);
179 win.setPosSize(rec.X,rec.Y,rec.Height,rec.Width,com.sun.star.awt.PosSize.POSSIZE );
183 return tEnv;
188 * Called while disposing a <code>TestEnvironment</code>.
189 * Disposes calc document.
190 * @param Param test parameters
191 * @param log writer to log information while testing
193 protected void cleanup( TestParameters Param, PrintWriter log) {
194 log.println( " disposing xSheetDoc " );
195 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
196 util.DesktopTools.closeDoc(oComp);
200 * Called while the <code>TestCase</code> initialization. In the
201 * implementation does nothing. Subclasses can override to initialize
202 * objects shared among all <code>TestEnvironment</code>s.
204 * @param Param test parameters
205 * @param log writer to log information while testing
207 * @see #initializeTestCase
209 protected void initialize(TestParameters Param, PrintWriter log) {
210 // get a soffice factory object
211 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
213 try {
214 log.println("creating a spreadsheetdocument");
215 String url = utils.getFullTestURL("calcshapes.sxc");
216 log.println("loading document "+url);
217 xSpreadsheetDoc = UnoRuntime.queryInterface(
218 XSpreadsheetDocument.class,SOF.loadDocument(url));
219 try {
220 Thread.sleep(500);
221 } catch (InterruptedException ex) {}
222 } catch (com.sun.star.uno.Exception e) {
223 e.printStackTrace( log );
224 throw new StatusException( "Couldn't create document ", e );