merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / ScAccessibleDocumentPagePreview.java
blob88ff4e265e76b54f3d249102810bfe7b6d2ed19b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ScAccessibleDocumentPagePreview.java,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._sc;
33 import java.io.PrintWriter;
35 import lib.Status;
36 import lib.StatusException;
37 import lib.TestCase;
38 import lib.TestEnvironment;
39 import lib.TestParameters;
40 import util.AccessibilityTools;
41 import util.SOfficeFactory;
42 import util.utils;
44 import com.sun.star.accessibility.AccessibleRole;
45 import com.sun.star.accessibility.XAccessible;
46 import com.sun.star.awt.Rectangle;
47 import com.sun.star.awt.XWindow;
48 import com.sun.star.container.XIndexAccess;
49 import com.sun.star.frame.XController;
50 import com.sun.star.frame.XDesktop;
51 import com.sun.star.frame.XDispatch;
52 import com.sun.star.frame.XDispatchProvider;
53 import com.sun.star.frame.XModel;
54 import com.sun.star.lang.XComponent;
55 import com.sun.star.lang.XMultiServiceFactory;
56 import com.sun.star.sheet.XSpreadsheet;
57 import com.sun.star.sheet.XSpreadsheetDocument;
58 import com.sun.star.sheet.XSpreadsheets;
59 import com.sun.star.table.XCell;
60 import com.sun.star.uno.AnyConverter;
61 import com.sun.star.uno.Type;
62 import com.sun.star.uno.UnoRuntime;
63 import com.sun.star.uno.XInterface;
64 import com.sun.star.util.URL;
65 import com.sun.star.util.XURLTransformer;
67 /**
68 * Test for object which is represented by accessible component of
69 * a spreadsheet page in 'Page Preview' mode.
71 * Object implements the following interfaces :
72 * <ul>
73 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
74 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
75 * </ul> <p>
77 * @see com.sun.star.accessibility.XAccessibleComponent
78 * @see com.sun.star.accessibility.XAccessibleContext
79 * @see ifc.n.star.accessibility._XAccessibleComponent
80 * @see ifc.n.star.accessibility._XAccessibleContext
82 public class ScAccessibleDocumentPagePreview extends TestCase {
84 static XSpreadsheetDocument xSpreadsheetDoc = null;
86 /**
87 * Called to create an instance of <code>TestEnvironment</code>
88 * with an object to test and related objects.
89 * Switchs the document to Print Preview mode.
90 * Obtains accissible object for the page view.
92 * @param tParam test parameters
93 * @param log writer to log information while testing
95 * @see TestEnvironment
96 * @see #getTestEnvironment()
98 protected TestEnvironment createTestEnvironment(
99 TestParameters Param, PrintWriter log) {
101 XInterface oObj = null;
103 // inserting some content to have non-empty page preview
104 XCell xCell = null;
105 try {
106 XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ;
107 XIndexAccess oIndexSheets = (XIndexAccess)
108 UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
109 XSpreadsheet oSheet = null;
110 try {
111 oSheet = (XSpreadsheet) AnyConverter.toObject(
112 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(1));
113 } catch (com.sun.star.lang.IllegalArgumentException iae) {
114 throw new StatusException("couldn't get sheet",iae);
116 xCell = oSheet.getCellByPosition(0, 0) ;
117 xCell.setFormula("ScAccessibleDocumentPagePreview - Page 2");
118 try {
119 oSheet = (XSpreadsheet) AnyConverter.toObject(
120 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(2));
121 } catch (com.sun.star.lang.IllegalArgumentException iae) {
122 throw new StatusException("couldn't get sheet",iae);
124 xCell = oSheet.getCellByPosition(0, 0) ;
125 xCell.setFormula("ScAccessibleDocumentPagePreview - Page 3");
127 try {
128 oSheet = (XSpreadsheet) AnyConverter.toObject(
129 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
130 } catch (com.sun.star.lang.IllegalArgumentException iae) {
131 throw new StatusException("couldn't get sheet",iae);
133 xCell = oSheet.getCellByPosition(0, 0) ;
134 xCell.setFormula("ScAccessibleDocumentPagePreview");
135 } catch(com.sun.star.lang.WrappedTargetException e) {
136 log.println("Exception ceating relation :");
137 e.printStackTrace(log);
138 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
139 log.println("Exception ceating relation :");
140 e.printStackTrace(log);
143 XModel aModel = (XModel)
144 UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
146 XController xController = aModel.getCurrentController();
148 // switching to 'Page Preview' mode
149 try {
150 XDispatchProvider xDispProv = (XDispatchProvider)
151 UnoRuntime.queryInterface(XDispatchProvider.class, xController);
152 XURLTransformer xParser = (com.sun.star.util.XURLTransformer)
153 UnoRuntime.queryInterface(XURLTransformer.class,
154 ((XMultiServiceFactory)Param.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
155 // Because it's an in/out parameter we must use an array of URL objects.
156 URL[] aParseURL = new URL[1];
157 aParseURL[0] = new URL();
158 aParseURL[0].Complete = ".uno:PrintPreview";
159 xParser.parseStrict(aParseURL);
160 URL aURL = aParseURL[0];
161 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
162 if(xDispatcher != null)
163 xDispatcher.dispatch( aURL, null );
164 } catch (com.sun.star.uno.Exception e) {
165 log.println("Couldn't change mode");
166 throw new StatusException(Status.failed("Couldn't change mode"));
169 try {
170 Thread.sleep(500);
171 } catch (InterruptedException ex) {}
173 AccessibilityTools at = new AccessibilityTools();
175 XWindow xWindow = at.getCurrentContainerWindow((XMultiServiceFactory)Param.getMSF(), aModel);
176 XAccessible xRoot = at.getAccessibleObject(xWindow);
177 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
179 oObj = at.getAccessibleObjectForRole
180 (xRoot, AccessibleRole.DOCUMENT, "");
182 log.println("ImplementationName " + utils.getImplName(oObj));
184 TestEnvironment tEnv = new TestEnvironment(oObj);
186 XDesktop desk = (XDesktop) UnoRuntime.queryInterface(
187 XDesktop.class,util.DesktopTools.createDesktop((XMultiServiceFactory)Param.getMSF()));
188 final XWindow win = desk.getCurrentFrame().getComponentWindow();
190 tEnv.addObjRelation("EventProducer",
191 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
192 public void fireEvent() {
193 Rectangle rec = win.getPosSize();
194 win.setPosSize(rec.X,rec.Y,rec.Height-10,rec.Width, com.sun.star.awt.PosSize.POSSIZE);
195 win.setPosSize(rec.X,rec.Y,rec.Height,rec.Width,com.sun.star.awt.PosSize.POSSIZE );
199 return tEnv;
204 * Called while disposing a <code>TestEnvironment</code>.
205 * Disposes calc document.
206 * @param tParam test parameters
207 * @param tEnv the environment to cleanup
208 * @param log writer to log information while testing
210 protected void cleanup( TestParameters Param, PrintWriter log) {
211 log.println( " disposing xSheetDoc " );
212 XComponent oComp = (XComponent)
213 UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
214 util.DesktopTools.closeDoc(oComp);
218 * Called while the <code>TestCase</code> initialization. In the
219 * implementation does nothing. Subclasses can override to initialize
220 * objects shared among all <code>TestEnvironment</code>s.
222 * @param tParam test parameters
223 * @param log writer to log information while testing
225 * @see #initializeTestCase()
227 protected void initialize(TestParameters Param, PrintWriter log) {
228 // get a soffice factory object
229 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
231 try {
232 log.println("creating a spreadsheetdocument");
233 String url = utils.getFullTestURL("calcshapes.sxc");
234 log.println("loading document "+url);
235 xSpreadsheetDoc = (XSpreadsheetDocument)UnoRuntime.queryInterface(
236 XSpreadsheetDocument.class,SOF.loadDocument(url));
237 try {
238 Thread.sleep(500);
239 } catch (InterruptedException ex) {}
240 } catch (com.sun.star.uno.Exception e) {
241 e.printStackTrace( log );
242 throw new StatusException( "Couldn't create document ", e );