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 .
21 import java
.io
.PrintWriter
;
24 import lib
.StatusException
;
26 import lib
.TestEnvironment
;
27 import lib
.TestParameters
;
28 import util
.AccessibilityTools
;
29 import util
.SOfficeFactory
;
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
.container
.XIndexAccess
;
36 import com
.sun
.star
.frame
.XController
;
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
.DisposedException
;
41 import com
.sun
.star
.lang
.XComponent
;
42 import com
.sun
.star
.sheet
.XSpreadsheet
;
43 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
44 import com
.sun
.star
.sheet
.XSpreadsheets
;
45 import com
.sun
.star
.table
.XCell
;
46 import com
.sun
.star
.uno
.AnyConverter
;
47 import com
.sun
.star
.uno
.Type
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.util
.URL
;
50 import com
.sun
.star
.util
.XURLTransformer
;
53 public class AccessibleEditableTextPara_PreviewCell
extends TestCase
{
54 private XSpreadsheetDocument xSheetDoc
= null;
57 * Creates a spreadsheet document.
60 protected void initialize( TestParameters tParam
, PrintWriter log
) {
61 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
63 log
.println( "creating a Spreadsheet document" );
64 xSheetDoc
= SOF
.createCalcDoc(null);
65 } catch ( com
.sun
.star
.uno
.Exception e
) {
66 // Some exception occurs.FAILED
67 e
.printStackTrace( log
);
68 throw new StatusException( "Couldn't create document", e
);
73 * 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
);
85 * Creating a Testenvironment for the interfaces to be tested.
86 * Obtains the accessible object for a one of cell in preview mode.
89 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
94 log
.println("Getting spreadsheet") ;
95 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
96 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
97 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
98 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
100 log
.println("Getting a cell from sheet") ;
101 xCell
= oSheet
.getCellByPosition(0, 0);
102 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
103 e
.printStackTrace(log
);
104 throw new StatusException(
105 "Error getting cell object from spreadsheet document", e
);
106 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
107 e
.printStackTrace(log
);
108 throw new StatusException(
109 "Error getting cell object from spreadsheet document", e
);
110 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
111 e
.printStackTrace(log
);
112 throw new StatusException(
113 "Error getting cell object from spreadsheet document", e
);
116 xCell
.setFormula("Value");
118 XModel xModel
= UnoRuntime
.queryInterface(XModel
.class, xSheetDoc
);
120 XController xController
= xModel
.getCurrentController();
122 //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 );
135 } catch (com
.sun
.star
.uno
.Exception e
) {
136 log
.println("Couldn't change mode");
137 throw new StatusException(e
, Status
.failed("Couldn't change mode"));
140 XAccessibleContext oObj
= null;
141 for (int i
= 0;; ++i
) {
144 } catch (InterruptedException e
) {
145 throw new RuntimeException(e
);
148 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(
149 AccessibilityTools
.getCurrentWindow(
152 AccessibilityTools
.getAccessibleObjectForRole(
153 xRoot
, AccessibleRole
.TABLE_CELL
, true);
154 xRoot
= AccessibilityTools
.SearchedAccessible
;
156 oObj
= AccessibilityTools
.getAccessibleObjectForRole(
157 xRoot
, AccessibleRole
.PARAGRAPH
);
163 } catch (DisposedException e
) {
164 log
.println("Ignoring DisposedException");
166 if (i
== 20) { // give up after 10 sec
167 throw new RuntimeException(
168 "Couldn't get AccessibleRoot.HEADER object");
170 log
.println("No TABLE_CELL/PARAGRAPH found yet, retrying");
173 log
.println("ImplementationName " + utils
.getImplName(oObj
));
174 log
.println("AccessibleName " + oObj
.getAccessibleName());
175 log
.println("Parent " + utils
.getImplName(oObj
.getAccessibleParent()));
177 TestEnvironment tEnv
= new TestEnvironment( oObj
);
179 tEnv
.addObjRelation("EditOnly", "AccessibleEditableTextPara_PreviewCell");
180 tEnv
.addObjRelation("Destroy", "AccessibleEditableTextPara_PreviewCell");
182 final XCell cell_to_change
= xCell
;
183 tEnv
.addObjRelation("EventProducer",
184 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer(){
185 public void fireEvent() {
186 cell_to_change
.setFormula("NewString");