bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleEndnoteView.java
blobf94515e0be2e8165a85db1a3241e88c55962534f
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.XText;
38 import com.sun.star.text.XTextContent;
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 SwAccessibleEndnoteView 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 endnote 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 endnote.
56 * @param Param test parameters
57 * @param log writer to log information while testing
59 * @see TestEnvironment
60 * @see #getTestEnvironment
62 protected TestEnvironment createTestEnvironment(
63 TestParameters Param, PrintWriter log) {
65 XInterface oObj = null;
66 XInterface oEndnote = null;
68 log.println( "Creating a test environment" );
69 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
70 log.println("creating a endnote");
71 try {
72 oEndnote = UnoRuntime.queryInterface(XInterface.class,
73 msf.createInstance("com.sun.star.text.Endnote"));
74 } catch (com.sun.star.uno.Exception e) {
75 e.printStackTrace(log);
76 throw new StatusException("Couldn't create endnote", e);
79 XText oText = xTextDoc.getText();
80 XTextCursor oCursor = oText.createTextCursor();
82 log.println("inserting the footnote into text document");
83 XTextContent xTC = UnoRuntime.queryInterface(XTextContent.class, oEndnote);
84 try {
85 oText.insertTextContent(oCursor, xTC, false);
86 } catch (com.sun.star.lang.IllegalArgumentException e) {
87 e.printStackTrace(log);
88 throw new StatusException("Couldn't insert the endnote", e);
91 XController xController = xTextDoc.getCurrentController();
92 XViewSettingsSupplier xViewSetSup = UnoRuntime.queryInterface(XViewSettingsSupplier.class,
93 xController);
94 XPropertySet xPropSet = xViewSetSup.getViewSettings();
96 try {
97 //change zoom value to 10%
98 //footer should be in the vissible area of the document
99 xPropSet.setPropertyValue("ZoomValue", new Short("10"));
100 } catch ( com.sun.star.lang.WrappedTargetException e ) {
101 e.printStackTrace(log);
102 throw new StatusException("Couldn't set propertyValue...", e);
103 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
104 e.printStackTrace(log);
105 throw new StatusException("Couldn't set propertyValue...", e);
106 } catch ( com.sun.star.beans.PropertyVetoException e ) {
107 e.printStackTrace(log);
108 throw new StatusException("Couldn't set propertyValue...", e);
109 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
110 e.printStackTrace(log);
111 throw new StatusException("Couldn't set propertyValue...", e);
114 XModel aModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
116 AccessibilityTools at = new AccessibilityTools();
118 XWindow xWindow = AccessibilityTools.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
119 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
121 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.END_NOTE);
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", new Short("15"));
136 //and back to 10%
137 PropSet.setPropertyValue("ZoomValue", new Short("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 protected void cleanup( TestParameters Param, PrintWriter log) {
161 log.println("dispose text document");
162 util.DesktopTools.closeDoc(xTextDoc);
166 * Called while the <code>TestCase</code> initialization. In the
167 * implementation does nothing. Subclasses can override to initialize
168 * objects shared among all <code>TestEnvironment</code>s.
170 * @param Param test parameters
171 * @param log writer to log information while testing
173 * @see #initializeTestCase
175 protected void initialize(TestParameters Param, PrintWriter log) {
176 log.println( "creating a text document" );
177 xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());