tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessiblePreviewCell.java
blobd645c407a3d1c084eef6f03c84f1ac944afb2368
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.container.XIndexAccess;
33 import com.sun.star.frame.XController;
34 import com.sun.star.frame.XDispatch;
35 import com.sun.star.frame.XDispatchProvider;
36 import com.sun.star.frame.XModel;
37 import com.sun.star.lang.DisposedException;
38 import com.sun.star.lang.XComponent;
39 import com.sun.star.sheet.XSpreadsheet;
40 import com.sun.star.sheet.XSpreadsheetDocument;
41 import com.sun.star.sheet.XSpreadsheets;
42 import com.sun.star.table.XCell;
43 import com.sun.star.uno.AnyConverter;
44 import com.sun.star.uno.Type;
45 import com.sun.star.uno.UnoRuntime;
46 import com.sun.star.uno.XInterface;
47 import com.sun.star.util.URL;
48 import com.sun.star.util.XURLTransformer;
50 /**
51 * Object implements the following interfaces:
52 * <ul>
53 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
54 * </li>
55 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
56 * </li>
57 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
58 * </code></li>
59 * <li><code>::com::sun::star::accessibility::XAccessibleValue</code>
60 * </li>
61 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
62 * </code></li>
63 * </ul>
64 * @see com.sun.star.accessibility.XAccessibleComponent
65 * @see com.sun.star.accessibility.XAccessibleContext
66 * @see com.sun.star.accessibility.XAccessibleSelection
67 * @see com.sun.star.accessibility.XAccessibleValue
68 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
69 * @see ifc.accessibility._XAccessibleEventBroadcaster
70 * @see ifc.accessibility._XAccessibleComponent
71 * @see ifc.accessibility._XAccessibleContext
72 * @see ifc.accessibility._XAccessibleSelection
73 * @see ifc.accessibility._XAccessibleTable
75 public class ScAccessiblePreviewCell extends TestCase {
76 private XSpreadsheetDocument xSheetDoc = null;
78 /**
79 * Creates a spreadsheet document.
81 @Override
82 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
83 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
84 log.println( "creating a Spreadsheet document" );
85 xSheetDoc = SOF.createCalcDoc(null);
88 /**
89 * Disposes a spreadsheet document.
91 @Override
92 protected void cleanup( TestParameters tParam, PrintWriter log ) {
93 log.println( " disposing xSheetDoc " );
94 XComponent oComp = UnoRuntime.queryInterface
95 (XComponent.class, xSheetDoc);
96 util.DesktopTools.closeDoc(oComp);
101 * Creating a TestEnvironment for the interfaces to be tested.
102 * Obtains the accessible object for a one of cell in preview mode.
104 @Override
105 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception {
106 XCell xCell = null;
108 log.println("Getting spreadsheet") ;
109 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
110 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
111 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
112 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
114 log.println("Getting a cell from sheet") ;
115 xCell = oSheet.getCellByPosition(0, 0);
117 xCell.setFormula("Value");
119 XModel xModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc);
121 XController xController = xModel.getCurrentController();
123 //switch to 'Print Preview' mode
124 XDispatchProvider xDispProv = UnoRuntime.queryInterface(XDispatchProvider.class, xController);
125 XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class,
126 Param.getMSF().createInstance("com.sun.star.util.URLTransformer"));
127 URL[] aParseURL = new URL[1];
128 aParseURL[0] = new URL();
129 aParseURL[0].Complete = ".uno:PrintPreview";
130 xParser.parseStrict(aParseURL);
131 URL aURL = aParseURL[0];
132 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
133 if(xDispatcher != null)
134 xDispatcher.dispatch( aURL, null );
136 XInterface oObj = null;
137 for (int i = 0;; ++i) {
138 Thread.sleep(500);
139 try {
140 XAccessible xRoot = AccessibilityTools.getAccessibleObject(
141 AccessibilityTools.getCurrentWindow(
142 xModel));
143 if (xRoot != null) {
144 oObj = AccessibilityTools.getAccessibleObjectForRole(
145 xRoot, AccessibleRole.TABLE_CELL, true);
146 if (oObj != null) {
147 break;
150 } catch (DisposedException e) {
151 log.println("Ignoring DisposedException");
153 if (i == 20) { // give up after 10 sec
154 throw new RuntimeException(
155 "Couldn't get AccessibleRole.TABLE_CELL object");
157 log.println("No TABLE_CELL found yet, retrying");
160 log.println("ImplementationName " + utils.getImplName(oObj));
162 TestEnvironment tEnv = new TestEnvironment( oObj );
164 tEnv.addObjRelation("EventProducer",
165 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
166 public void fireEvent() {
167 System.out.println("Fire Event");
171 return tEnv;