tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessibleDocumentPagePreview.java
blob6474f8d8456cf912d106fff1b3c3ec27caa19a28
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.AccessibilityTools;
27 import util.SOfficeFactory;
28 import util.utils;
30 import com.sun.star.accessibility.AccessibleRole;
31 import com.sun.star.accessibility.XAccessible;
32 import com.sun.star.awt.Rectangle;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.container.XIndexAccess;
35 import com.sun.star.frame.XController;
36 import com.sun.star.frame.XDesktop;
37 import com.sun.star.frame.XDispatch;
38 import com.sun.star.frame.XDispatchProvider;
39 import com.sun.star.frame.XModel;
40 import com.sun.star.lang.XComponent;
41 import com.sun.star.sheet.XSpreadsheet;
42 import com.sun.star.sheet.XSpreadsheetDocument;
43 import com.sun.star.sheet.XSpreadsheets;
44 import com.sun.star.table.XCell;
45 import com.sun.star.uno.AnyConverter;
46 import com.sun.star.uno.Type;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
49 import com.sun.star.util.URL;
50 import com.sun.star.util.XURLTransformer;
52 /**
53 * Test for object which is represented by accessible component of
54 * a spreadsheet page in 'Page Preview' mode.
56 * Object implements the following interfaces :
57 * <ul>
58 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code></li>
59 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code></li>
60 * </ul> <p>
62 * @see com.sun.star.accessibility.XAccessibleComponent
63 * @see com.sun.star.accessibility.XAccessibleContext
64 * @see ifc.accessibility._XAccessibleComponent
65 * @see ifc.accessibility._XAccessibleContext
67 public class ScAccessibleDocumentPagePreview extends TestCase {
69 private XSpreadsheetDocument xSpreadsheetDoc = null;
71 /**
72 * Called to create an instance of <code>TestEnvironment</code>
73 * with an object to test and related objects.
74 * Switches the document to Print Preview mode.
75 * Obtains accessible object for the page view.
77 * @param Param test parameters
78 * @param log writer to log information while testing
80 * @see TestEnvironment
81 * @see #getTestEnvironment
83 @Override
84 protected TestEnvironment createTestEnvironment(
85 TestParameters Param, PrintWriter log) throws Exception {
87 XInterface oObj = null;
89 // inserting some content to have non-empty page preview
90 XCell xCell = null;
91 try {
92 XSpreadsheets oSheets = xSpreadsheetDoc.getSheets() ;
93 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
94 XSpreadsheet oSheet = null;
95 oSheet = (XSpreadsheet) AnyConverter.toObject(
96 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(1));
97 xCell = oSheet.getCellByPosition(0, 0) ;
98 xCell.setFormula("ScAccessibleDocumentPagePreview - Page 2");
99 oSheet = (XSpreadsheet) AnyConverter.toObject(
100 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(2));
101 xCell = oSheet.getCellByPosition(0, 0) ;
102 xCell.setFormula("ScAccessibleDocumentPagePreview - Page 3");
104 oSheet = (XSpreadsheet) AnyConverter.toObject(
105 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
106 xCell = oSheet.getCellByPosition(0, 0) ;
107 xCell.setFormula("ScAccessibleDocumentPagePreview");
108 } catch(com.sun.star.lang.WrappedTargetException e) {
109 log.println("Exception creating document page preview :");
110 e.printStackTrace(log);
111 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
112 log.println("Exception creating document page preview :");
113 e.printStackTrace(log);
116 XModel aModel = UnoRuntime.queryInterface(XModel.class, xSpreadsheetDoc);
118 XController xController = aModel.getCurrentController();
120 // switching to 'Page Preview' mode
121 XDispatchProvider xDispProv = UnoRuntime.queryInterface(XDispatchProvider.class, xController);
122 XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class,
123 Param.getMSF().createInstance("com.sun.star.util.URLTransformer"));
124 // Because it's an in/out parameter we must use an array of URL objects.
125 URL[] aParseURL = new URL[1];
126 aParseURL[0] = new URL();
127 aParseURL[0].Complete = ".uno:PrintPreview";
128 xParser.parseStrict(aParseURL);
129 URL aURL = aParseURL[0];
130 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
131 if(xDispatcher != null)
132 xDispatcher.dispatch( aURL, null );
134 util.utils.shortWait();
136 XWindow xWindow = AccessibilityTools.getCurrentContainerWindow(aModel);
137 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
138 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
140 oObj = AccessibilityTools.getAccessibleObjectForRole
141 (xRoot, AccessibleRole.DOCUMENT, "");
143 log.println("ImplementationName " + utils.getImplName(oObj));
145 TestEnvironment tEnv = new TestEnvironment(oObj);
147 XDesktop desk = util.DesktopTools.createDesktop(Param.getMSF());
148 final XWindow win = desk.getCurrentFrame().getComponentWindow();
150 tEnv.addObjRelation("EventProducer",
151 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
152 public void fireEvent() {
153 Rectangle rec = win.getPosSize();
154 win.setPosSize(rec.X,rec.Y,rec.Height-10,rec.Width, com.sun.star.awt.PosSize.POSSIZE);
155 win.setPosSize(rec.X,rec.Y,rec.Height,rec.Width,com.sun.star.awt.PosSize.POSSIZE );
159 return tEnv;
164 * Called while disposing a <code>TestEnvironment</code>.
165 * Disposes calc document.
166 * @param Param test parameters
167 * @param log writer to log information while testing
169 @Override
170 protected void cleanup( TestParameters Param, PrintWriter log) {
171 log.println( " disposing xSheetDoc " );
172 XComponent oComp = UnoRuntime.queryInterface (XComponent.class, xSpreadsheetDoc) ;
173 util.DesktopTools.closeDoc(oComp);
177 * Called while the <code>TestCase</code> initialization. In the
178 * implementation does nothing. Subclasses can override to initialize
179 * objects shared among all <code>TestEnvironment</code>s.
181 * @param Param test parameters
182 * @param log writer to log information while testing
184 * @see #initializeTestCase
186 @Override
187 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
188 // get a soffice factory object
189 SOfficeFactory SOF = SOfficeFactory.getFactory( Param.getMSF());
191 log.println("creating a spreadsheetdocument");
192 String url = utils.getFullTestURL("calcshapes.sxc");
193 log.println("loading document "+url);
194 xSpreadsheetDoc = UnoRuntime.queryInterface(
195 XSpreadsheetDocument.class,SOF.loadDocument(url));
196 util.utils.waitForEventIdle(Param.getMSF());