bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleTextFrameView.java
blob2503d38ef4e2e31cfebe90a0e75b642eb2bf3262
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.SOfficeFactory;
28 import util.WriterTools;
29 import util.utils;
31 import com.sun.star.accessibility.AccessibleRole;
32 import com.sun.star.accessibility.XAccessible;
33 import com.sun.star.awt.XWindow;
34 import com.sun.star.beans.XPropertySet;
35 import com.sun.star.frame.XController;
36 import com.sun.star.frame.XModel;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.text.TextContentAnchorType;
39 import com.sun.star.text.XText;
40 import com.sun.star.text.XTextContent;
41 import com.sun.star.text.XTextCursor;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.text.XTextFrame;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 import com.sun.star.view.XViewSettingsSupplier;
48 /**
49 * Test of accessible object for the text frame of a text document.<p>
50 * Object implements the following interfaces :
51 * <ul>
52 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
53 * </ul>
54 * @see com.sun.star.accessibility.XAccessible
56 public class SwAccessibleTextFrameView extends TestCase {
58 XTextDocument xTextDoc = null;
60 /**
61 * Called to create an instance of <code>TestEnvironment</code>
62 * with an object to test and related objects.
63 * Creates a frame and inserts it into document.
64 * Obtains accessible object for the inserted text frame.
66 * @param Param test parameters
67 * @param log writer to log information while testing
69 * @see TestEnvironment
70 * @see #getTestEnvironment
72 protected TestEnvironment createTestEnvironment(
73 TestParameters Param, PrintWriter log) {
75 XInterface oObj = null;
76 XTextFrame oFrame1 = null;
77 XPropertySet oPropSet = null;
78 XText oText = null;
79 XTextCursor oCursor = null;
81 // get a soffice factory object
82 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF() );
83 // creating Frames
84 log.println( "creating Frames" );
85 try {
86 oFrame1 = SOfficeFactory.createTextFrame(xTextDoc, 500, 500);
87 oPropSet = UnoRuntime.queryInterface(
88 XPropertySet.class, oFrame1 );
89 oPropSet.setPropertyValue("AnchorType",
90 TextContentAnchorType.AS_CHARACTER);
91 oText = xTextDoc.getText();
92 oCursor = oText.createTextCursor();
94 log.println( "inserting Frame1" );
95 XTextContent the_content = UnoRuntime.queryInterface(XTextContent.class, oFrame1);
96 oText.insertTextContent(oCursor, the_content, true);
97 } catch (Exception e) {
98 e.printStackTrace(log);
99 throw new StatusException("Couldn't insert TextFrame", e);
102 XModel aModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
104 AccessibilityTools at = new AccessibilityTools();
106 XWindow xWindow = AccessibilityTools.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
107 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
109 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT_FRAME);
111 log.println("ImplementationName " + utils.getImplName(oObj));
112 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
114 TestEnvironment tEnv = new TestEnvironment(oObj);
116 XController xController = xTextDoc.getCurrentController();
117 XViewSettingsSupplier xViewSetSup = UnoRuntime.queryInterface(XViewSettingsSupplier.class,
118 xController);
120 final XPropertySet PropSet = xViewSetSup.getViewSettings();
122 tEnv.addObjRelation("EventProducer",
123 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
124 public void fireEvent() {
125 try {
126 //change zoom value to 15%
127 PropSet.setPropertyValue("ZoomValue", new Short("15"));
128 //and back to 100%
129 PropSet.setPropertyValue("ZoomValue", new Short("100"));
130 } catch ( com.sun.star.lang.WrappedTargetException e ) {
132 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
134 } catch ( com.sun.star.beans.PropertyVetoException e ) {
136 } catch ( com.sun.star.beans.UnknownPropertyException 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 protected void cleanup( TestParameters Param, PrintWriter log) {
154 log.println("dispose text document");
155 util.DesktopTools.closeDoc(xTextDoc);
159 * Called while the <code>TestCase</code> initialization.
160 * Creates a text document.
162 * @param Param test parameters
163 * @param log writer to log information while testing
165 * @see #initializeTestCase
167 protected void initialize(TestParameters Param, PrintWriter log) {
168 log.println( "creating a text document" );
169 xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());