Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessibleDocumentPagePreview.java
blob3cdcce98765f5491eb79d3923ba348bce1031715
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.sheet.XSpreadsheet;
44 import com.sun.star.sheet.XSpreadsheetDocument;
45 import com.sun.star.sheet.XSpreadsheets;
46 import com.sun.star.table.XCell;
47 import com.sun.star.uno.AnyConverter;
48 import com.sun.star.uno.Type;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
51 import com.sun.star.util.URL;
52 import com.sun.star.util.XURLTransformer;
54 /**
55 * Test for object which is represented by accessible component of
56 * a spreadsheet page in 'Page Preview' mode.
58 * Object implements the following interfaces :
59 * <ul>
60 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
61 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
62 * </ul> <p>
64 * @see com.sun.star.accessibility.XAccessibleComponent
65 * @see com.sun.star.accessibility.XAccessibleContext
66 * @see ifc.accessibility._XAccessibleComponent
67 * @see ifc.accessibility._XAccessibleContext
69 public class ScAccessibleDocumentPagePreview extends TestCase {
71 private XSpreadsheetDocument xSpreadsheetDoc = null;
73 /**
74 * Called to create an instance of <code>TestEnvironment</code>
75 * with an object to test and related objects.
76 * Switches the document to Print Preview mode.
77 * Obtains accessible object for the page view.
79 * @param Param test parameters
80 * @param log writer to log information while testing
82 * @see TestEnvironment
83 * @see #getTestEnvironment
85 @Override
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 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 throw new StatusException(e, Status.failed("Couldn't change mode"));
152 util.utils.shortWait();
154 XWindow xWindow = AccessibilityTools.getCurrentContainerWindow(aModel);
155 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
156 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
158 oObj = AccessibilityTools.getAccessibleObjectForRole
159 (xRoot, AccessibleRole.DOCUMENT, "");
161 log.println("ImplementationName " + utils.getImplName(oObj));
163 TestEnvironment tEnv = new TestEnvironment(oObj);
165 XDesktop desk = UnoRuntime.queryInterface(
166 XDesktop.class,util.DesktopTools.createDesktop(Param.getMSF()));
167 final XWindow win = desk.getCurrentFrame().getComponentWindow();
169 tEnv.addObjRelation("EventProducer",
170 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
171 public void fireEvent() {
172 Rectangle rec = win.getPosSize();
173 win.setPosSize(rec.X,rec.Y,rec.Height-10,rec.Width, com.sun.star.awt.PosSize.POSSIZE);
174 win.setPosSize(rec.X,rec.Y,rec.Height,rec.Width,com.sun.star.awt.PosSize.POSSIZE );
178 return tEnv;
183 * Called while disposing a <code>TestEnvironment</code>.
184 * Disposes calc document.
185 * @param Param test parameters
186 * @param log writer to log information while testing
188 @Override
189 protected void cleanup( TestParameters Param, PrintWriter log) {
190 log.println( " disposing xSheetDoc " );
191 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
192 util.DesktopTools.closeDoc(oComp);
196 * Called while the <code>TestCase</code> initialization. In the
197 * implementation does nothing. Subclasses can override to initialize
198 * objects shared among all <code>TestEnvironment</code>s.
200 * @param Param test parameters
201 * @param log writer to log information while testing
203 * @see #initializeTestCase
205 @Override
206 protected void initialize(TestParameters Param, PrintWriter log) {
207 // get a soffice factory object
208 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
210 try {
211 log.println("creating a spreadsheetdocument");
212 String url = utils.getFullTestURL("calcshapes.sxc");
213 log.println("loading document "+url);
214 xSpreadsheetDoc = UnoRuntime.queryInterface(
215 XSpreadsheetDocument.class,SOF.loadDocument(url));
216 util.utils.pause(500);
217 } catch (com.sun.star.uno.Exception e) {
218 e.printStackTrace( log );
219 throw new StatusException( "Couldn't create document ", e );