merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleTableCellView.java
blob4ee1a377fe2c12ef0c1773b7b20068c5bf6e32ea
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwAccessibleTableCellView.java,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package mod._sw;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
38 import util.AccessibilityTools;
39 import util.SOfficeFactory;
40 import util.WriterTools;
41 import util.utils;
43 import com.sun.star.accessibility.AccessibleRole;
44 import com.sun.star.accessibility.XAccessible;
45 import com.sun.star.accessibility.XAccessibleSelection;
46 import com.sun.star.awt.XWindow;
47 import com.sun.star.frame.XModel;
48 import com.sun.star.lang.XMultiServiceFactory;
49 import com.sun.star.text.XTextDocument;
50 import com.sun.star.text.XTextTable;
51 import com.sun.star.uno.UnoRuntime;
52 import com.sun.star.uno.XInterface;
55 /**
56 * Test of accessible object for the table cell of a text document.<p>
57 * Object implements the following interfaces :
58 * <ul>
59 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
60 * </ul>
61 * @see com.sun.star.accessibility.XAccessible
63 public class SwAccessibleTableCellView extends TestCase {
64 XTextDocument xTextDoc = null;
66 /**
67 * Called to create an instance of <code>TestEnvironment</code>
68 * with an object to test and related objects.
69 * Creates a text table and inserts it to document. Then obtains accessible
70 * object for one of table cell.
72 * @param tParam test parameters
73 * @param log writer to log information while testing
75 * @see TestEnvironment
76 * @see #getTestEnvironment()
78 protected TestEnvironment createTestEnvironment(TestParameters Param,
79 PrintWriter log) {
80 XInterface oObj = null;
81 XTextTable oTable = null;
83 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) Param.getMSF());
85 try {
86 oTable = SOF.createTextTable(xTextDoc);
87 } catch (com.sun.star.uno.Exception e) {
88 e.printStackTrace(log);
89 throw new StatusException("Couldn't create TextTable : " +
90 e.getMessage(), e);
93 try {
94 SOF.insertTextContent(xTextDoc, oTable);
95 } catch (com.sun.star.lang.IllegalArgumentException e) {
96 e.printStackTrace(log);
97 throw new StatusException("Couldn't insert text content :" +
98 e.getMessage(), e);
101 XModel aModel = (XModel) UnoRuntime.queryInterface(XModel.class,
102 xTextDoc);
104 AccessibilityTools at = new AccessibilityTools();
106 XWindow xWindow = at.getCurrentWindow( (XMultiServiceFactory) Param.getMSF(), aModel);
107 XAccessible xRoot = at.getAccessibleObject(xWindow);
109 at.getAccessibleObjectForRole(xRoot, AccessibleRole.TABLE_CELL);
111 oObj = at.SearchedContext;
113 log.println("ImplementationName " + utils.getImplName(oObj));
115 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
116 TestEnvironment tEnv = new TestEnvironment(oObj);
118 final XAccessibleSelection accSel = (XAccessibleSelection) UnoRuntime.queryInterface(
119 XAccessibleSelection.class,
120 at.SearchedContext.getAccessibleParent());
122 tEnv.addObjRelation("EventProducer",
123 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
124 public void fireEvent() {
125 accSel.selectAllAccessibleChildren();
129 return tEnv;
133 * Called while disposing a <code>TestEnvironment</code>.
134 * Disposes text document.
135 * @param tParam test parameters
136 * @param tEnv the environment to cleanup
137 * @param log writer to log information while testing
139 protected void cleanup(TestParameters Param, PrintWriter log) {
140 log.println("dispose text document");
141 util.DesktopTools.closeDoc(xTextDoc);
145 * Called while the <code>TestCase</code> initialization.
146 * Creates a text document.
148 * @param tParam test parameters
149 * @param log writer to log information while testing
151 * @see #initializeTestCase()
153 protected void initialize(TestParameters Param, PrintWriter log) {
154 log.println("creating a text document");
155 xTextDoc = WriterTools.createTextDoc( (XMultiServiceFactory) Param.getMSF());