merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleTextFrameView.java
blob26939161e7b8b0f481eb0b78125729ea81362598
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: SwAccessibleTextFrameView.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.awt.XWindow;
46 import com.sun.star.beans.XPropertySet;
47 import com.sun.star.frame.XController;
48 import com.sun.star.frame.XModel;
49 import com.sun.star.lang.XMultiServiceFactory;
50 import com.sun.star.text.TextContentAnchorType;
51 import com.sun.star.text.XText;
52 import com.sun.star.text.XTextContent;
53 import com.sun.star.text.XTextCursor;
54 import com.sun.star.text.XTextDocument;
55 import com.sun.star.text.XTextFrame;
56 import com.sun.star.uno.UnoRuntime;
57 import com.sun.star.uno.XInterface;
58 import com.sun.star.view.XViewSettingsSupplier;
60 /**
61 * Test of accessible object for the text frame of a text document.<p>
62 * Object implements the following interfaces :
63 * <ul>
64 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
65 * </ul>
66 * @see com.sun.star.accessibility.XAccessible
68 public class SwAccessibleTextFrameView extends TestCase {
70 XTextDocument xTextDoc = null;
72 /**
73 * Called to create an instance of <code>TestEnvironment</code>
74 * with an object to test and related objects.
75 * Creates a frame and inserts it into document.
76 * Obtains accessible object for the inserted text frame.
78 * @param tParam test parameters
79 * @param log writer to log information while testing
81 * @see TestEnvironment
82 * @see #getTestEnvironment()
84 protected TestEnvironment createTestEnvironment(
85 TestParameters Param, PrintWriter log) {
87 XInterface oObj = null;
88 XTextFrame oFrame1 = null;
89 XPropertySet oPropSet = null;
90 XText oText = null;
91 XTextCursor oCursor = null;
93 // get a soffice factory object
94 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF() );
95 // creating Frames
96 log.println( "creating Frames" );
97 try {
98 oFrame1 = SOF.createTextFrame(xTextDoc, 500, 500);
99 oPropSet = (XPropertySet)UnoRuntime.queryInterface(
100 XPropertySet.class, oFrame1 );
101 oPropSet.setPropertyValue("AnchorType",
102 TextContentAnchorType.AS_CHARACTER);
103 oText = xTextDoc.getText();
104 oCursor = oText.createTextCursor();
106 log.println( "inserting Frame1" );
107 XTextContent the_content = (XTextContent)
108 UnoRuntime.queryInterface(XTextContent.class, oFrame1);
109 oText.insertTextContent(oCursor, the_content, true);
110 } catch (Exception e) {
111 e.printStackTrace(log);
112 throw new StatusException("Couldn't insert TextFrame", e);
115 XModel aModel = (XModel)
116 UnoRuntime.queryInterface(XModel.class, xTextDoc);
118 AccessibilityTools at = new AccessibilityTools();
120 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
121 XAccessible xRoot = at.getAccessibleObject(xWindow);
123 at.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT_FRAME);
125 oObj = at.SearchedContext;
127 log.println("ImplementationName " + utils.getImplName(oObj));
128 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
130 TestEnvironment tEnv = new TestEnvironment(oObj);
132 XController xController = xTextDoc.getCurrentController();
133 XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier)
134 UnoRuntime.queryInterface(XViewSettingsSupplier.class,
135 xController);
137 final XPropertySet PropSet = xViewSetSup.getViewSettings();
139 tEnv.addObjRelation("EventProducer",
140 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
141 public void fireEvent() {
142 try {
143 //change zoom value to 15%
144 PropSet.setPropertyValue("ZoomValue", new Short("15"));
145 //and back to 100%
146 PropSet.setPropertyValue("ZoomValue", new Short("100"));
147 } catch ( com.sun.star.lang.WrappedTargetException e ) {
149 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
151 } catch ( com.sun.star.beans.PropertyVetoException e ) {
153 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
160 return tEnv;
165 * Called while disposing a <code>TestEnvironment</code>.
166 * Disposes text document.
167 * @param tParam test parameters
168 * @param tEnv the environment to cleanup
169 * @param log writer to log information while testing
171 protected void cleanup( TestParameters Param, PrintWriter log) {
172 log.println("dispose text document");
173 util.DesktopTools.closeDoc(xTextDoc);
177 * Called while the <code>TestCase</code> initialization.
178 * Creates a text document.
180 * @param tParam test parameters
181 * @param log writer to log information while testing
183 * @see #initializeTestCase()
185 protected void initialize(TestParameters Param, PrintWriter log) {
186 log.println( "creating a text document" );
187 xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());