merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleFooterView.java
bloba4433afa60a3b6d59a564d48a896dea75b0b3f91
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: SwAccessibleFooterView.java,v $
10 * $Revision: 1.10 $
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.container.XNameAccess;
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.style.XStyle;
51 import com.sun.star.style.XStyleFamiliesSupplier;
52 import com.sun.star.text.XTextDocument;
53 import com.sun.star.uno.AnyConverter;
54 import com.sun.star.uno.Type;
55 import com.sun.star.uno.UnoRuntime;
56 import com.sun.star.uno.XInterface;
57 import com.sun.star.view.XViewSettingsSupplier;
59 /**
60 * Test of accessible object for a footer of a text document.<p>
61 * Object implements the following interfaces :
62 * <ul>
63 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
64 * </ul>
65 * @see com.sun.star.accessibility.XAccessible
67 public class SwAccessibleFooterView extends TestCase {
69 XTextDocument xTextDoc = null;
71 /**
72 * Called to create an instance of <code>TestEnvironment</code>
73 * with an object to test and related objects. Obtains style
74 * <code>Standard</code> from style family <code>PageStyles</code>.
75 * Changes values of property <code>FooterIsOn</code> by <code>true</code>.
76 * Changes zoom value to 10%(footer must be in vissible area of the document).
77 * Obtains accessible component for the footer.
79 * @param tParam test parameters
80 * @param log writer to log information while testing
82 * @see TestEnvironment
83 * @see #getTestEnvironment()
85 protected TestEnvironment createTestEnvironment(
86 TestParameters Param, PrintWriter log) {
88 XInterface oObj = null;
89 XNameAccess PageStyles = null;
90 XStyle StdStyle = null;
92 XStyleFamiliesSupplier StyleFam = (XStyleFamiliesSupplier)
93 UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc);
94 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
96 // obtains style 'Standard' from style family 'PageStyles'
97 try {
98 PageStyles = (XNameAccess) AnyConverter.toObject(
99 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
100 StdStyle = (XStyle) AnyConverter.toObject(
101 new Type(XStyle.class),PageStyles.getByName("Standard"));
102 } catch ( com.sun.star.lang.WrappedTargetException e ) {
103 e.printStackTrace(log);
104 throw new StatusException("Error getting style by name!", e);
105 } catch ( com.sun.star.container.NoSuchElementException e ) {
106 e.printStackTrace(log);
107 throw new StatusException("Error, no such style name! ", e);
108 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
109 e.printStackTrace(log);
110 throw new StatusException("Error getting style by name!", e);
113 final XPropertySet PropSet = (XPropertySet)
114 UnoRuntime.queryInterface( XPropertySet.class, StdStyle);
116 // changing/getting some properties
117 try {
118 log.println( "Switching on footer" );
119 PropSet.setPropertyValue("FooterIsOn", new Boolean(true));
121 //change zoom value to 10%
122 //footer should be in the vissible area of the document
123 XController xController = xTextDoc.getCurrentController();
124 XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier)
125 UnoRuntime.queryInterface(XViewSettingsSupplier.class,
126 xController);
127 XPropertySet xPropSet = xViewSetSup.getViewSettings();
128 xPropSet.setPropertyValue("ZoomValue", new Short("20"));
129 } catch ( com.sun.star.lang.WrappedTargetException e ) {
130 e.printStackTrace(log);
131 throw new StatusException("Couldn't set propertyValue...", e);
132 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
133 e.printStackTrace(log);
134 throw new StatusException("Couldn't set propertyValue...", e);
135 } catch ( com.sun.star.beans.PropertyVetoException e ) {
136 e.printStackTrace(log);
137 throw new StatusException("Couldn't set propertyValue...", e);
138 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
139 e.printStackTrace(log);
140 throw new StatusException("Couldn't set propertyValue...", e);
143 XModel aModel = (XModel)
144 UnoRuntime.queryInterface(XModel.class, xTextDoc);
146 AccessibilityTools at = new AccessibilityTools();
148 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
149 XAccessible xRoot = at.getAccessibleObject(xWindow);
151 at.getAccessibleObjectForRole(xRoot, AccessibleRole.FOOTER);
153 oObj = AccessibilityTools.SearchedContext;
155 log.println("ImplementationName " + utils.getImplName(oObj));
156 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
158 TestEnvironment tEnv = new TestEnvironment(oObj);
160 tEnv.addObjRelation("EventProducer",
161 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
162 public void fireEvent() {
163 try {
164 PropSet.setPropertyValue("FooterLeftMargin",
165 new Integer(1000));
166 } catch (com.sun.star.uno.Exception e) {
167 e.printStackTrace();
168 throw new StatusException("Cann't change footer.", e);
173 return tEnv;
178 * Called while disposing a <code>TestEnvironment</code>.
179 * Disposes text document.
180 * @param tParam test parameters
181 * @param tEnv the environment to cleanup
182 * @param log writer to log information while testing
184 protected void cleanup( TestParameters Param, PrintWriter log) {
185 log.println("dispose text document");
186 util.DesktopTools.closeDoc(xTextDoc);
190 * Called while the <code>TestCase</code> initialization.
191 * Creates a text document.
193 * @param tParam test parameters
194 * @param log writer to log information while testing
196 * @see #initializeTestCase()
198 protected void initialize(TestParameters Param, PrintWriter log) {
199 log.println( "creating a text document" );
200 xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());