bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / AccessibleEditableTextPara_PreviewCell.java
blob26e9ff14449b616312584863d7892ea1ab632630
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.accessibility.XAccessibleContext;
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.XDispatch;
39 import com.sun.star.frame.XDispatchProvider;
40 import com.sun.star.frame.XModel;
41 import com.sun.star.lang.DisposedException;
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.util.URL;
52 import com.sun.star.util.XURLTransformer;
55 public class AccessibleEditableTextPara_PreviewCell extends TestCase {
56 private XSpreadsheetDocument xSheetDoc = null;
58 /**
59 * Creates a spreadsheet document.
61 protected void initialize( TestParameters tParam, PrintWriter log ) {
62 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF() );
63 try {
64 log.println( "creating a Spreadsheet document" );
65 xSheetDoc = SOF.createCalcDoc(null);
66 } catch ( com.sun.star.uno.Exception e ) {
67 // Some exception occurs.FAILED
68 e.printStackTrace( log );
69 throw new StatusException( "Couldn't create document", e );
73 /**
74 * Disposes a spreadsheet document.
76 protected void cleanup( TestParameters tParam, PrintWriter log ) {
77 log.println( " disposing xSheetDoc " );
78 XComponent oComp = UnoRuntime.queryInterface
79 (XComponent.class, xSheetDoc);
80 util.DesktopTools.closeDoc(oComp);
84 /**
85 * Creating a Testenvironment for the interfaces to be tested.
86 * Obtains the accessible object for a one of cell in preview mode.
88 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
90 XCell xCell = null;
92 try {
93 log.println("Getting spreadsheet") ;
94 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
95 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
96 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
97 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
99 log.println("Getting a cell from sheet") ;
100 xCell = oSheet.getCellByPosition(0, 0);
101 } catch (com.sun.star.lang.WrappedTargetException e) {
102 e.printStackTrace(log);
103 throw new StatusException(
104 "Error getting cell object from spreadsheet document", e);
105 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
106 e.printStackTrace(log);
107 throw new StatusException(
108 "Error getting cell object from spreadsheet document", e);
109 } catch (com.sun.star.lang.IllegalArgumentException e) {
110 e.printStackTrace(log);
111 throw new StatusException(
112 "Error getting cell object from spreadsheet document", e);
115 xCell.setFormula("Value");
117 XModel xModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc);
119 XController xController = xModel.getCurrentController();
121 //switch to 'Print Preview' mode
122 try {
123 XDispatchProvider xDispProv = UnoRuntime.queryInterface(XDispatchProvider.class, xController);
124 XURLTransformer xParser = UnoRuntime.queryInterface(XURLTransformer.class,
125 ( (XMultiServiceFactory) Param.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
126 URL[] aParseURL = new URL[1];
127 aParseURL[0] = new URL();
128 aParseURL[0].Complete = ".uno:PrintPreview";
129 xParser.parseStrict(aParseURL);
130 URL aURL = aParseURL[0];
131 XDispatch xDispatcher = xDispProv.queryDispatch(aURL, "", 0);
132 if(xDispatcher != null)
133 xDispatcher.dispatch( aURL, null );
134 } catch (com.sun.star.uno.Exception e) {
135 log.println("Couldn't change mode");
136 throw new StatusException(Status.failed("Couldn't change mode"));
139 XAccessibleContext oObj = null;
140 for (int i = 0;; ++i) {
141 try {
142 Thread.sleep(500);
143 } catch (InterruptedException e) {
144 throw new RuntimeException(e);
146 try {
147 XAccessible xRoot = AccessibilityTools.getAccessibleObject(
148 AccessibilityTools.getCurrentWindow(
149 (XMultiServiceFactory) Param.getMSF(), xModel));
150 if (xRoot != null) {
151 AccessibilityTools.getAccessibleObjectForRole(
152 xRoot, AccessibleRole.TABLE_CELL, true);
153 xRoot = AccessibilityTools.SearchedAccessible;
154 if (xRoot != null) {
155 oObj = AccessibilityTools.getAccessibleObjectForRole(
156 xRoot, AccessibleRole.PARAGRAPH);
157 if (oObj != null) {
158 break;
162 } catch (DisposedException e) {
163 log.println("Ignoring DisposedException");
165 if (i == 20) { // give up after 10 sec
166 throw new RuntimeException(
167 "Couldn't get AccessibleRoot.HEADER object");
169 log.println("No TABLE_CELL/PARAGRAPH found yet, retrying");
172 log.println("ImplementationName " + utils.getImplName(oObj));
173 log.println("AccessibleName " + oObj.getAccessibleName());
174 log.println("Parent " + utils.getImplName(oObj.getAccessibleParent()));
176 TestEnvironment tEnv = new TestEnvironment( oObj );
178 tEnv.addObjRelation("EditOnly", "AccessibleEditableTextPara_PreviewCell");
179 tEnv.addObjRelation("Destroy", "AccessibleEditableTextPara_PreviewCell");
181 final XCell cell_to_change = xCell;
182 tEnv.addObjRelation("EventProducer",
183 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
184 public void fireEvent() {
185 cell_to_change.setFormula("NewString");
189 return tEnv;