Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleFooterView.java
blobd48ea8c730b85f234e979af5673fb35473c8d222
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package mod._sw;
20 import java.io.PrintWriter;
22 import lib.StatusException;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.AccessibilityTools;
27 import util.WriterTools;
28 import util.utils;
30 import com.sun.star.accessibility.AccessibleRole;
31 import com.sun.star.accessibility.XAccessible;
32 import com.sun.star.awt.XWindow;
33 import com.sun.star.beans.XPropertySet;
34 import com.sun.star.container.XNameAccess;
35 import com.sun.star.frame.XController;
36 import com.sun.star.frame.XModel;
37 import com.sun.star.style.XStyle;
38 import com.sun.star.style.XStyleFamiliesSupplier;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.uno.AnyConverter;
41 import com.sun.star.uno.Type;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 import com.sun.star.view.XViewSettingsSupplier;
46 /**
47 * Test of accessible object for a footer of a text document.<p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
51 * </ul>
52 * @see com.sun.star.accessibility.XAccessible
54 public class SwAccessibleFooterView extends TestCase {
56 XTextDocument xTextDoc = null;
58 /**
59 * Called to create an instance of <code>TestEnvironment</code>
60 * with an object to test and related objects. Obtains style
61 * <code>Standard</code> from style family <code>PageStyles</code>.
62 * Changes values of property <code>FooterIsOn</code> by <code>true</code>.
63 * Changes zoom value to 10%(footer must be in visible area of the document).
64 * Obtains accessible component for the footer.
66 * @param Param test parameters
67 * @param log writer to log information while testing
69 * @see TestEnvironment
70 * @see #getTestEnvironment
72 @Override
73 protected TestEnvironment createTestEnvironment(
74 TestParameters Param, PrintWriter log) {
76 XInterface oObj = null;
77 XNameAccess PageStyles = null;
78 XStyle StdStyle = null;
80 XStyleFamiliesSupplier StyleFam = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc);
81 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
83 // obtains style 'Standard' from style family 'PageStyles'
84 try {
85 PageStyles = (XNameAccess) AnyConverter.toObject(
86 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
87 StdStyle = (XStyle) AnyConverter.toObject(
88 new Type(XStyle.class),PageStyles.getByName("Standard"));
89 } catch ( com.sun.star.lang.WrappedTargetException e ) {
90 e.printStackTrace(log);
91 throw new StatusException("Error getting style by name!", e);
92 } catch ( com.sun.star.container.NoSuchElementException e ) {
93 e.printStackTrace(log);
94 throw new StatusException("Error, no such style name! ", e);
95 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
96 e.printStackTrace(log);
97 throw new StatusException("Error getting style by name!", e);
100 final XPropertySet PropSet = UnoRuntime.queryInterface( XPropertySet.class, StdStyle);
102 // changing/getting some properties
103 try {
104 log.println( "Switching on footer" );
105 PropSet.setPropertyValue("FooterIsOn", Boolean.TRUE);
107 //change zoom value to 10%
108 //footer should be in the vissible area of the document
109 XController xController = xTextDoc.getCurrentController();
110 XViewSettingsSupplier xViewSetSup = UnoRuntime.queryInterface(XViewSettingsSupplier.class,
111 xController);
112 XPropertySet xPropSet = xViewSetSup.getViewSettings();
113 xPropSet.setPropertyValue("ZoomValue", Short.valueOf("20"));
114 } catch ( com.sun.star.lang.WrappedTargetException e ) {
115 e.printStackTrace(log);
116 throw new StatusException("Couldn't set propertyValue...", e);
117 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
118 e.printStackTrace(log);
119 throw new StatusException("Couldn't set propertyValue...", e);
120 } catch ( com.sun.star.beans.PropertyVetoException e ) {
121 e.printStackTrace(log);
122 throw new StatusException("Couldn't set propertyValue...", e);
123 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
124 e.printStackTrace(log);
125 throw new StatusException("Couldn't set propertyValue...", e);
128 XModel aModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
130 XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
131 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
133 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.FOOTER);
135 log.println("ImplementationName " + utils.getImplName(oObj));
136 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
138 TestEnvironment tEnv = new TestEnvironment(oObj);
140 tEnv.addObjRelation("EventProducer",
141 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
142 public void fireEvent() {
143 try {
144 PropSet.setPropertyValue("FooterLeftMargin",
145 Integer.valueOf(1000));
146 } catch (com.sun.star.uno.Exception e) {
147 e.printStackTrace();
148 throw new StatusException("Cann't change footer.", e);
153 return tEnv;
158 * Called while disposing a <code>TestEnvironment</code>.
159 * Disposes text document.
160 * @param Param test parameters
161 * @param log writer to log information while testing
163 @Override
164 protected void cleanup( TestParameters Param, PrintWriter log) {
165 log.println("dispose text document");
166 util.DesktopTools.closeDoc(xTextDoc);
170 * Called while the <code>TestCase</code> initialization.
171 * Creates a text document.
173 * @param Param test parameters
174 * @param log writer to log information while testing
176 * @see #initializeTestCase
178 @Override
179 protected void initialize(TestParameters Param, PrintWriter log) {
180 log.println( "creating a text document" );
181 xTextDoc = WriterTools.createTextDoc(Param.getMSF());