Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / ScAccessibleSpreadsheet.java
blob9cb809ec022d2d7211752b6b58015b0a5a44217e
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.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.AccessibilityTools;
28 import util.SOfficeFactory;
29 import util.utils;
31 import com.sun.star.accessibility.AccessibleRole;
32 import com.sun.star.accessibility.XAccessible;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.container.XIndexAccess;
35 import com.sun.star.frame.XModel;
36 import com.sun.star.lang.XComponent;
37 import com.sun.star.sheet.XSpreadsheet;
38 import com.sun.star.sheet.XSpreadsheetDocument;
39 import com.sun.star.sheet.XSpreadsheets;
40 import com.sun.star.table.XCell;
41 import com.sun.star.uno.AnyConverter;
42 import com.sun.star.uno.Type;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
46 /**
47 * Test for accessible object of spreadsheet document.<p>
48 * Object implements the following interfaces:
49 * <ul>
50 * <li> <code>::com::sun::star::accessibility::XAccessibleComponent</code>
51 * </li>
52 * <li> <code>::com::sun::star::accessibility::XAccessibleContext</code>
53 * </li>
54 * <li> <code>::com::sun::star::accessibility::XAccessibleSelection
55 * </code></li>
56 * <li><code>::com::sun::star::accessibility::XAccessibleTable</code>
57 * </li>
58 * </ul>
59 * @see com.sun.star.accessibility.XAccessibleComponent
60 * @see com.sun.star.accessibility.XAccessibleContext
61 * @see com.sun.star.accessibility.XAccessibleSelection
62 * @see com.sun.star.accessibility.XAccessibleTable
63 * @see ifc.accessibility._XAccessibleComponent
64 * @see ifc.accessibility._XAccessibleContext
65 * @see ifc.accessibility._XAccessibleSelection
66 * @see ifc.accessibility._XAccessibleTable
68 public class ScAccessibleSpreadsheet extends TestCase {
69 private XSpreadsheetDocument xSheetDoc = null;
71 /**
72 * Creates a spreadsheet document.
74 @Override
75 protected void initialize( TestParameters tParam, PrintWriter log ) {
76 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
77 try {
78 log.println( "creating a Spreadsheet document" );
79 xSheetDoc = SOF.createCalcDoc(null);
80 } catch ( com.sun.star.uno.Exception e ) {
81 // Some exception occurs.FAILED
82 e.printStackTrace( log );
83 throw new StatusException( "Couldn't create document", e );
87 /**
88 * Disposes a spreadsheet document.
90 @Override
91 protected void cleanup( TestParameters tParam, PrintWriter log ) {
92 log.println( " disposing xSheetDoc " );
93 XComponent oComp = UnoRuntime.queryInterface
94 (XComponent.class, xSheetDoc);
95 util.DesktopTools.closeDoc(oComp);
99 /**
100 * Creating a Testenvironment for the interfaces to be tested.
101 * Obtains the accessible object for the spreadsheet.
103 @Override
104 public synchronized TestEnvironment createTestEnvironment
105 ( TestParameters Param, PrintWriter log )
106 throws StatusException {
108 XInterface oObj = null;
110 XModel xModel = UnoRuntime.queryInterface(XModel.class, xSheetDoc);
112 XWindow xWindow = AccessibilityTools.getCurrentWindow(xModel);
113 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
115 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE );
117 log.println("ImplementationName " + utils.getImplName(oObj));
119 TestEnvironment tEnv = new TestEnvironment( oObj );
121 // relation for XAccessibleEventBroadcaster
122 XCell xCell = null;
123 final String text = "Text for testing of the interface XAccessibleText";
124 try {
125 XSpreadsheets oSheets = xSheetDoc.getSheets() ;
126 XIndexAccess oIndexSheets = UnoRuntime.queryInterface(XIndexAccess.class, oSheets);
127 XSpreadsheet oSheet = (XSpreadsheet) AnyConverter.toObject(
128 new Type(XSpreadsheet.class),oIndexSheets.getByIndex(0));
129 xCell = oSheet.getCellByPosition(5, 5) ;
130 xCell.setFormula(text);
131 } catch(com.sun.star.lang.WrappedTargetException e) {
132 log.println("Exception creating accessible text :");
133 e.printStackTrace(log);
134 } catch(com.sun.star.lang.IndexOutOfBoundsException e) {
135 log.println("Exception creating accessible text :");
136 e.printStackTrace(log);
137 } catch(com.sun.star.lang.IllegalArgumentException e) {
138 log.println("Exception creating accessible text :");
139 e.printStackTrace(log);
142 final XCell fCell = xCell ;
144 tEnv.addObjRelation("EventProducer",
145 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
146 public void fireEvent() {
147 fCell.setFormula("firing event");
148 fCell.setFormula(text);
152 return tEnv;