merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleFootnoteView.java
blob3efeea607aee4902958e0334a1f0900e89b4995a
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: SwAccessibleFootnoteView.java,v $
10 * $Revision: 1.8 $
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.WriterTools;
40 import util.utils;
42 import com.sun.star.accessibility.AccessibleRole;
43 import com.sun.star.accessibility.XAccessible;
44 import com.sun.star.awt.XWindow;
45 import com.sun.star.beans.XPropertySet;
46 import com.sun.star.frame.XController;
47 import com.sun.star.frame.XModel;
48 import com.sun.star.lang.XMultiServiceFactory;
49 import com.sun.star.text.XFootnote;
50 import com.sun.star.text.XText;
51 import com.sun.star.text.XTextCursor;
52 import com.sun.star.text.XTextDocument;
53 import com.sun.star.uno.UnoRuntime;
54 import com.sun.star.uno.XInterface;
55 import com.sun.star.view.XViewSettingsSupplier;
57 public class SwAccessibleFootnoteView extends TestCase {
59 XTextDocument xTextDoc = null;
61 /**
62 * Called to create an instance of <code>TestEnvironment</code>
63 * with an object to test and related objects.
64 * Inserts the created footnote to the document.
65 * Changes zoom value to 10%(endnote must be in vissible area of the document).
66 * Obtains accessible object for the inserted footnote.
68 * @param tParam test parameters
69 * @param log writer to log information while testing
71 * @see TestEnvironment
72 * @see #getTestEnvironment()
74 protected TestEnvironment createTestEnvironment(
75 TestParameters Param, PrintWriter log) {
77 XInterface oObj = null;
78 XFootnote oFootnote = null;
80 log.println( "Creating a test environment" );
81 // get a soffice factory object
82 XMultiServiceFactory msf = (XMultiServiceFactory)
83 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
84 log.println("creating a footnote");
86 try {
87 oFootnote = (XFootnote) UnoRuntime.queryInterface(XFootnote.class,
88 msf.createInstance("com.sun.star.text.Footnote"));
89 } catch (com.sun.star.uno.Exception e) {
90 e.printStackTrace(log);
91 throw new StatusException("Couldn't create footnote", e);
94 XText oText = xTextDoc.getText();
95 XTextCursor oCursor = oText.createTextCursor();
97 log.println("inserting the footnote into text document");
98 try {
99 oText.insertTextContent(oCursor, oFootnote, false);
100 } catch (com.sun.star.lang.IllegalArgumentException e) {
101 e.printStackTrace(log);
102 throw new StatusException("Couldn't insert the footnote", e);
105 XController xController = xTextDoc.getCurrentController();
106 XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier)
107 UnoRuntime.queryInterface(XViewSettingsSupplier.class,
108 xController);
109 XPropertySet xPropSet = xViewSetSup.getViewSettings();
111 try {
112 //change zoom value to 10%
113 //footer should be in the vissible area of the document
114 xPropSet.setPropertyValue("ZoomValue", new Short("10"));
115 } catch ( com.sun.star.lang.WrappedTargetException e ) {
116 e.printStackTrace(log);
117 throw new StatusException("Couldn't set propertyValue...", e);
118 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
119 e.printStackTrace(log);
120 throw new StatusException("Couldn't set propertyValue...", e);
121 } catch ( com.sun.star.beans.PropertyVetoException e ) {
122 e.printStackTrace(log);
123 throw new StatusException("Couldn't set propertyValue...", e);
124 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
125 e.printStackTrace(log);
126 throw new StatusException("Couldn't set propertyValue...", e);
129 XModel aModel = (XModel)
130 UnoRuntime.queryInterface(XModel.class, xTextDoc);
132 AccessibilityTools at = new AccessibilityTools();
134 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
135 XAccessible xRoot = at.getAccessibleObject(xWindow);
137 at.getAccessibleObjectForRole(xRoot, AccessibleRole.FOOTNOTE);
139 oObj = AccessibilityTools.SearchedContext;
141 log.println("ImplementationName " + utils.getImplName(oObj));
142 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
144 TestEnvironment tEnv = new TestEnvironment(oObj);
146 final XPropertySet PropSet = xViewSetSup.getViewSettings();
148 tEnv.addObjRelation("EventProducer",
149 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
150 public void fireEvent() {
151 try {
152 //change zoom value to 130%
153 PropSet.setPropertyValue("ZoomValue", new Short("15"));
154 //and back to 10%
155 PropSet.setPropertyValue("ZoomValue", new Short("10"));
156 } catch ( com.sun.star.lang.WrappedTargetException e ) {
158 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
160 } catch ( com.sun.star.beans.PropertyVetoException e ) {
162 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
168 return tEnv;
173 * Called while disposing a <code>TestEnvironment</code>.
174 * Disposes text document.
175 * @param tParam test parameters
176 * @param tEnv the environment to cleanup
177 * @param log writer to log information while testing
179 protected void cleanup( TestParameters Param, PrintWriter log) {
180 log.println("dispose text document");
181 util.DesktopTools.closeDoc(xTextDoc);
185 * Called while the <code>TestCase</code> initialization. In the
186 * implementation does nothing. Subclasses can override to initialize
187 * objects shared among all <code>TestEnvironment</code>s.
189 * @param tParam test parameters
190 * @param log writer to log information while testing
192 * @see #initializeTestCase()
194 protected void initialize(TestParameters Param, PrintWriter log) {
195 log.println( "creating a text document" );
196 xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());