merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleHeaderView.java
blobbf4f8542496ca61a9b0f63ae0d59e2810d342065
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: SwAccessibleHeaderView.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.XModel;
48 import com.sun.star.lang.XMultiServiceFactory;
49 import com.sun.star.style.XStyle;
50 import com.sun.star.style.XStyleFamiliesSupplier;
51 import com.sun.star.text.XTextDocument;
52 import com.sun.star.uno.AnyConverter;
53 import com.sun.star.uno.Type;
54 import com.sun.star.uno.UnoRuntime;
55 import com.sun.star.uno.XInterface;
57 /**
58 * Test of accessible object for a header of a text document.<p>
59 * Object implements the following interfaces :
60 * <ul>
61 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
62 * </ul>
63 * @see com.sun.star.accessibility.XAccessible
65 public class SwAccessibleHeaderView extends TestCase {
67 XTextDocument xTextDoc = null;
69 /**
70 * Called to create an instance of <code>TestEnvironment</code>
71 * with an object to test and related objects. Obtains style
72 * <code>Standard</code> from style family <code>PageStyles</code>.
73 * Changes values of properties <code>HeaderIsOn</code> and
74 * <code>FooterIsOn</code> by <code>true</code>. Obtains accessible component
75 * for header.
77 * @param tParam test parameters
78 * @param log writer to log information while testing
80 * @see TestEnvironment
81 * @see #getTestEnvironment()
83 protected TestEnvironment createTestEnvironment(
84 TestParameters Param, PrintWriter log) {
86 XInterface oObj = null;
87 XNameAccess PageStyles = null;
88 XStyle StdStyle = null;
90 XStyleFamiliesSupplier StyleFam = (XStyleFamiliesSupplier)
91 UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc);
92 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
94 // obtains style 'Standatd' from style family 'PageStyles'
95 try {
96 PageStyles = (XNameAccess) AnyConverter.toObject(
97 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
98 StdStyle = (XStyle) AnyConverter.toObject(
99 new Type(XStyle.class),PageStyles.getByName("Standard"));
100 } catch ( com.sun.star.lang.WrappedTargetException e ) {
101 e.printStackTrace(log);
102 throw new StatusException("Error getting style by name!", e);
103 } catch ( com.sun.star.container.NoSuchElementException e ) {
104 e.printStackTrace(log);
105 throw new StatusException("Error, no such style name! ", e);
106 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
107 e.printStackTrace(log);
108 throw new StatusException("Error getting style by name!", e);
111 final XPropertySet PropSet = (XPropertySet)
112 UnoRuntime.queryInterface( XPropertySet.class, StdStyle);
114 // changing/getting some properties
115 try {
116 log.println( "Switching on header" );
117 PropSet.setPropertyValue("HeaderIsOn", new Boolean(true));
118 } catch ( com.sun.star.lang.WrappedTargetException e ) {
119 e.printStackTrace(log);
120 throw new StatusException("Couldn't set propertyValue...", e);
121 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
122 e.printStackTrace(log);
123 throw new StatusException("Couldn't set propertyValue...", e);
124 } catch ( com.sun.star.beans.PropertyVetoException e ) {
125 e.printStackTrace(log);
126 throw new StatusException("Couldn't set propertyValue...", e);
127 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
128 e.printStackTrace(log);
129 throw new StatusException("Couldn't set propertyValue...", e);
132 XModel aModel = (XModel)
133 UnoRuntime.queryInterface(XModel.class, xTextDoc);
135 AccessibilityTools at = new AccessibilityTools();
137 XWindow xWindow = at.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
138 XAccessible xRoot = at.getAccessibleObject(xWindow);
140 at.getAccessibleObjectForRole(xRoot, AccessibleRole.HEADER);
142 oObj = AccessibilityTools.SearchedContext;
144 log.println("ImplementationName " + utils.getImplName(oObj));
145 at.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
147 TestEnvironment tEnv = new TestEnvironment(oObj);
149 tEnv.addObjRelation("EventProducer",
150 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
151 public void fireEvent() {
152 try {
153 PropSet.setPropertyValue("HeaderLeftMargin",
154 new Integer(1000));
155 } catch (com.sun.star.uno.Exception e) {
156 e.printStackTrace();
157 throw new StatusException("Cann't change footer.", e);
162 return tEnv;
167 * Called while disposing a <code>TestEnvironment</code>.
168 * Disposes text document.
169 * @param tParam test parameters
170 * @param tEnv the environment to cleanup
171 * @param log writer to log information while testing
173 protected void cleanup( TestParameters Param, PrintWriter log) {
174 log.println("dispose text document");
175 util.DesktopTools.closeDoc(xTextDoc);
179 * Called while the <code>TestCase</code> initialization.
180 * Creates a text document.
182 * @param tParam test parameters
183 * @param log writer to log information while testing
185 * @see #initializeTestCase()
187 protected void initialize(TestParameters Param, PrintWriter log) {
188 log.println( "creating a text document" );
189 xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());