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
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.AccessibilityTools
;
27 import util
.SOfficeFactory
;
30 import com
.sun
.star
.accessibility
.AccessibleRole
;
31 import com
.sun
.star
.accessibility
.XAccessible
;
32 import com
.sun
.star
.accessibility
.XAccessibleContext
;
33 import com
.sun
.star
.container
.XIndexAccess
;
34 import com
.sun
.star
.frame
.XController
;
35 import com
.sun
.star
.frame
.XDispatch
;
36 import com
.sun
.star
.frame
.XDispatchProvider
;
37 import com
.sun
.star
.frame
.XModel
;
38 import com
.sun
.star
.lang
.DisposedException
;
39 import com
.sun
.star
.lang
.XComponent
;
40 import com
.sun
.star
.sheet
.XSpreadsheet
;
41 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
42 import com
.sun
.star
.sheet
.XSpreadsheets
;
43 import com
.sun
.star
.table
.XCell
;
44 import com
.sun
.star
.uno
.AnyConverter
;
45 import com
.sun
.star
.uno
.Type
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.util
.URL
;
48 import com
.sun
.star
.util
.XURLTransformer
;
51 public class AccessibleEditableTextPara_PreviewCell
extends TestCase
{
52 XSpreadsheetDocument xSheetDoc
= null;
55 * Creates a spreadsheet document.
58 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
59 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
60 log
.println( "creating a Spreadsheet document" );
61 xSheetDoc
= SOF
.createCalcDoc(null);
65 * Disposes a spreadsheet document.
68 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
69 log
.println( " disposing xSheetDoc " );
70 XComponent oComp
= UnoRuntime
.queryInterface
71 (XComponent
.class, xSheetDoc
);
72 util
.DesktopTools
.closeDoc(oComp
);
77 * Creating a TestEnvironment for the interfaces to be tested.
78 * Obtains the accessible object for a one of cell in preview mode.
81 protected TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) throws Exception
{
85 log
.println("Getting spreadsheet") ;
86 XSpreadsheets oSheets
= xSheetDoc
.getSheets() ;
87 XIndexAccess oIndexSheets
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSheets
);
88 XSpreadsheet oSheet
= (XSpreadsheet
) AnyConverter
.toObject(
89 new Type(XSpreadsheet
.class),oIndexSheets
.getByIndex(0));
91 log
.println("Getting a cell from sheet") ;
92 xCell
= oSheet
.getCellByPosition(0, 0);
94 xCell
.setFormula("Value");
96 XModel xModel
= UnoRuntime
.queryInterface(XModel
.class, xSheetDoc
);
98 XController xController
= xModel
.getCurrentController();
100 //switch to 'Print Preview' mode
101 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface(XDispatchProvider
.class, xController
);
102 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
103 Param
.getMSF().createInstance("com.sun.star.util.URLTransformer"));
104 URL
[] aParseURL
= new URL
[1];
105 aParseURL
[0] = new URL();
106 aParseURL
[0].Complete
= ".uno:PrintPreview";
107 xParser
.parseStrict(aParseURL
);
108 URL aURL
= aParseURL
[0];
109 XDispatch xDispatcher
= xDispProv
.queryDispatch(aURL
, "", 0);
110 if(xDispatcher
!= null)
111 xDispatcher
.dispatch( aURL
, null );
113 XAccessibleContext oObj
= null;
114 for (int i
= 0;; ++i
) {
117 XAccessible xRoot
= AccessibilityTools
.getAccessibleObject(
118 AccessibilityTools
.getCurrentWindow(
121 AccessibilityTools
.getAccessibleObjectForRole(
122 xRoot
, AccessibleRole
.TABLE_CELL
, true);
123 xRoot
= AccessibilityTools
.SearchedAccessible
;
125 oObj
= AccessibilityTools
.getAccessibleObjectForRole(
126 xRoot
, AccessibleRole
.PARAGRAPH
);
132 } catch (DisposedException e
) {
133 log
.println("Ignoring DisposedException");
135 if (i
== 20) { // give up after 10 sec
136 throw new RuntimeException(
137 "Couldn't get AccessibleRoot.HEADER object");
139 log
.println("No TABLE_CELL/PARAGRAPH found yet, retrying");
142 log
.println("ImplementationName " + utils
.getImplName(oObj
));
143 log
.println("AccessibleName " + oObj
.getAccessibleName());
144 log
.println("Parent " + utils
.getImplName(oObj
.getAccessibleParent()));
146 TestEnvironment tEnv
= new TestEnvironment( oObj
);
148 tEnv
.addObjRelation("EditOnly", "AccessibleEditableTextPara_PreviewCell");
149 tEnv
.addObjRelation("Destroy", "AccessibleEditableTextPara_PreviewCell");
151 final XCell cell_to_change
= xCell
;
152 tEnv
.addObjRelation("EventProducer",
153 new ifc
.accessibility
._XAccessibleEventBroadcaster
.EventProducer(){
154 public void fireEvent() {
155 cell_to_change
.setFormula("NewString");