Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleFootnoteView.java
blobb487b62d196ecfab1b6681991a7937a976a20263
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.frame.XController;
35 import com.sun.star.frame.XModel;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.text.XFootnote;
38 import com.sun.star.text.XText;
39 import com.sun.star.text.XTextCursor;
40 import com.sun.star.text.XTextDocument;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 import com.sun.star.view.XViewSettingsSupplier;
45 public class SwAccessibleFootnoteView extends TestCase {
47 XTextDocument xTextDoc = null;
49 /**
50 * Called to create an instance of <code>TestEnvironment</code>
51 * with an object to test and related objects.
52 * Inserts the created footnote to the document.
53 * Changes zoom value to 10%(endnote must be in visible area of the document).
54 * Obtains accessible object for the inserted footnote.
56 * @param Param test parameters
57 * @param log writer to log information while testing
59 * @see TestEnvironment
60 * @see #getTestEnvironment
62 @Override
63 protected TestEnvironment createTestEnvironment(
64 TestParameters Param, PrintWriter log) {
66 XInterface oObj = null;
67 XFootnote oFootnote = null;
69 log.println( "Creating a test environment" );
70 // get a soffice factory object
71 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
72 log.println("creating a footnote");
74 try {
75 oFootnote = UnoRuntime.queryInterface(XFootnote.class,
76 msf.createInstance("com.sun.star.text.Footnote"));
77 } catch (com.sun.star.uno.Exception e) {
78 e.printStackTrace(log);
79 throw new StatusException("Couldn't create footnote", e);
82 XText oText = xTextDoc.getText();
83 XTextCursor oCursor = oText.createTextCursor();
85 log.println("inserting the footnote into text document");
86 try {
87 oText.insertTextContent(oCursor, oFootnote, false);
88 } catch (com.sun.star.lang.IllegalArgumentException e) {
89 e.printStackTrace(log);
90 throw new StatusException("Couldn't insert the footnote", e);
93 XController xController = xTextDoc.getCurrentController();
94 XViewSettingsSupplier xViewSetSup = UnoRuntime.queryInterface(XViewSettingsSupplier.class,
95 xController);
96 XPropertySet xPropSet = xViewSetSup.getViewSettings();
98 try {
99 //change zoom value to 10%
100 //footer should be in the vissible area of the document
101 xPropSet.setPropertyValue("ZoomValue", Short.valueOf("10"));
102 } catch ( com.sun.star.lang.WrappedTargetException e ) {
103 e.printStackTrace(log);
104 throw new StatusException("Couldn't set propertyValue...", e);
105 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
106 e.printStackTrace(log);
107 throw new StatusException("Couldn't set propertyValue...", e);
108 } catch ( com.sun.star.beans.PropertyVetoException e ) {
109 e.printStackTrace(log);
110 throw new StatusException("Couldn't set propertyValue...", e);
111 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
112 e.printStackTrace(log);
113 throw new StatusException("Couldn't set propertyValue...", e);
116 XModel aModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
118 XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
119 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
121 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.FOOTNOTE);
123 log.println("ImplementationName " + utils.getImplName(oObj));
124 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
126 TestEnvironment tEnv = new TestEnvironment(oObj);
128 final XPropertySet PropSet = xViewSetSup.getViewSettings();
130 tEnv.addObjRelation("EventProducer",
131 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
132 public void fireEvent() {
133 try {
134 //change zoom value to 130%
135 PropSet.setPropertyValue("ZoomValue", Short.valueOf("15"));
136 //and back to 10%
137 PropSet.setPropertyValue("ZoomValue", Short.valueOf("10"));
138 } catch ( com.sun.star.lang.WrappedTargetException e ) {
140 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
142 } catch ( com.sun.star.beans.PropertyVetoException e ) {
144 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
150 return tEnv;
155 * Called while disposing a <code>TestEnvironment</code>.
156 * Disposes text document.
157 * @param Param test parameters
158 * @param log writer to log information while testing
160 @Override
161 protected void cleanup( TestParameters Param, PrintWriter log) {
162 log.println("dispose text document");
163 util.DesktopTools.closeDoc(xTextDoc);
167 * Called while the <code>TestCase</code> initialization. In the
168 * implementation does nothing. Subclasses can override to initialize
169 * objects shared among all <code>TestEnvironment</code>s.
171 * @param Param test parameters
172 * @param log writer to log information while testing
174 * @see #initializeTestCase
176 @Override
177 protected void initialize(TestParameters Param, PrintWriter log) {
178 log.println( "creating a text document" );
179 xTextDoc = WriterTools.createTextDoc(Param.getMSF());