Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleHeaderView.java
blobb3a8297a41725f69fad275050abce222037cc1ec
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.XModel;
36 import com.sun.star.style.XStyle;
37 import com.sun.star.style.XStyleFamiliesSupplier;
38 import com.sun.star.text.XTextDocument;
39 import com.sun.star.uno.AnyConverter;
40 import com.sun.star.uno.Type;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
44 /**
45 * Test of accessible object for a header of a text document.<p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
49 * </ul>
50 * @see com.sun.star.accessibility.XAccessible
52 public class SwAccessibleHeaderView extends TestCase {
54 XTextDocument xTextDoc = null;
56 /**
57 * Called to create an instance of <code>TestEnvironment</code>
58 * with an object to test and related objects. Obtains style
59 * <code>Standard</code> from style family <code>PageStyles</code>.
60 * Changes values of properties <code>HeaderIsOn</code> and
61 * <code>FooterIsOn</code> by <code>true</code>. Obtains accessible component
62 * for header.
64 * @param Param test parameters
65 * @param log writer to log information while testing
67 * @see TestEnvironment
68 * @see #getTestEnvironment
70 @Override
71 protected TestEnvironment createTestEnvironment(
72 TestParameters Param, PrintWriter log) {
74 XInterface oObj = null;
75 XNameAccess PageStyles = null;
76 XStyle StdStyle = null;
78 XStyleFamiliesSupplier StyleFam = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDoc);
79 XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
81 // obtains style 'Standatd' from style family 'PageStyles'
82 try {
83 PageStyles = (XNameAccess) AnyConverter.toObject(
84 new Type(XNameAccess.class),StyleFamNames.getByName("PageStyles"));
85 StdStyle = (XStyle) AnyConverter.toObject(
86 new Type(XStyle.class),PageStyles.getByName("Standard"));
87 } catch ( com.sun.star.lang.WrappedTargetException e ) {
88 e.printStackTrace(log);
89 throw new StatusException("Error getting style by name!", e);
90 } catch ( com.sun.star.container.NoSuchElementException e ) {
91 e.printStackTrace(log);
92 throw new StatusException("Error, no such style name! ", e);
93 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
94 e.printStackTrace(log);
95 throw new StatusException("Error getting style by name!", e);
98 final XPropertySet PropSet = UnoRuntime.queryInterface( XPropertySet.class, StdStyle);
100 // changing/getting some properties
101 try {
102 log.println( "Switching on header" );
103 PropSet.setPropertyValue("HeaderIsOn", Boolean.TRUE);
104 } catch ( com.sun.star.lang.WrappedTargetException e ) {
105 e.printStackTrace(log);
106 throw new StatusException("Couldn't set propertyValue...", e);
107 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
108 e.printStackTrace(log);
109 throw new StatusException("Couldn't set propertyValue...", e);
110 } catch ( com.sun.star.beans.PropertyVetoException e ) {
111 e.printStackTrace(log);
112 throw new StatusException("Couldn't set propertyValue...", e);
113 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
114 e.printStackTrace(log);
115 throw new StatusException("Couldn't set propertyValue...", e);
118 XModel aModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
120 XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
121 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
123 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.HEADER);
125 log.println("ImplementationName " + utils.getImplName(oObj));
126 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
128 TestEnvironment tEnv = new TestEnvironment(oObj);
130 tEnv.addObjRelation("EventProducer",
131 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer(){
132 public void fireEvent() {
133 try {
134 PropSet.setPropertyValue("HeaderLeftMargin",
135 Integer.valueOf(1000));
136 } catch (com.sun.star.uno.Exception e) {
137 e.printStackTrace();
138 throw new StatusException("Cann't change footer.", e);
143 return tEnv;
148 * Called while disposing a <code>TestEnvironment</code>.
149 * Disposes text document.
150 * @param Param test parameters
151 * @param log writer to log information while testing
153 @Override
154 protected void cleanup( TestParameters Param, PrintWriter log) {
155 log.println("dispose text document");
156 util.DesktopTools.closeDoc(xTextDoc);
160 * Called while the <code>TestCase</code> initialization.
161 * Creates a text document.
163 * @param Param test parameters
164 * @param log writer to log information while testing
166 * @see #initializeTestCase
168 @Override
169 protected void initialize(TestParameters Param, PrintWriter log) {
170 log.println( "creating a text document" );
171 xTextDoc = WriterTools.createTextDoc(Param.getMSF());