bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleTextFrameView.java
blob4692fa0e13d15d9427f63b8e8c13e73cb5fe592a
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.text.TextContentAnchorType;
38 import com.sun.star.text.XText;
39 import com.sun.star.text.XTextContent;
40 import com.sun.star.text.XTextCursor;
41 import com.sun.star.text.XTextDocument;
42 import com.sun.star.text.XTextFrame;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
45 import com.sun.star.view.XViewSettingsSupplier;
47 /**
48 * Test of accessible object for the text frame of a text document.<p>
49 * Object implements the following interfaces :
50 * <ul>
51 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
52 * </ul>
53 * @see com.sun.star.accessibility.XAccessible
55 public class SwAccessibleTextFrameView extends TestCase {
57 XTextDocument xTextDoc = null;
59 /**
60 * Called to create an instance of <code>TestEnvironment</code>
61 * with an object to test and related objects.
62 * Creates a frame and inserts it into document.
63 * Obtains accessible object for the inserted text frame.
65 * @param Param test parameters
66 * @param log writer to log information while testing
68 * @see TestEnvironment
69 * @see #getTestEnvironment
71 @Override
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.getFactory( 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 XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
105 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
107 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT_FRAME);
109 log.println("ImplementationName " + utils.getImplName(oObj));
110 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
112 TestEnvironment tEnv = new TestEnvironment(oObj);
114 XController xController = xTextDoc.getCurrentController();
115 XViewSettingsSupplier xViewSetSup = UnoRuntime.queryInterface(XViewSettingsSupplier.class,
116 xController);
118 final XPropertySet PropSet = xViewSetSup.getViewSettings();
120 tEnv.addObjRelation("EventProducer",
121 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
122 public void fireEvent() {
123 try {
124 //change zoom value to 15%
125 PropSet.setPropertyValue("ZoomValue", Short.valueOf("15"));
126 //and back to 100%
127 PropSet.setPropertyValue("ZoomValue", Short.valueOf("100"));
128 } catch ( com.sun.star.lang.WrappedTargetException e ) {
130 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
132 } catch ( com.sun.star.beans.PropertyVetoException e ) {
134 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
141 return tEnv;
146 * Called while disposing a <code>TestEnvironment</code>.
147 * Disposes text document.
148 * @param Param test parameters
149 * @param log writer to log information while testing
151 @Override
152 protected void cleanup( TestParameters Param, PrintWriter log) {
153 log.println("dispose text document");
154 util.DesktopTools.closeDoc(xTextDoc);
158 * Called while the <code>TestCase</code> initialization.
159 * Creates a text document.
161 * @param Param test parameters
162 * @param log writer to log information while testing
164 * @see #initializeTestCase
166 @Override
167 protected void initialize(TestParameters Param, PrintWriter log) {
168 log.println( "creating a text document" );
169 xTextDoc = WriterTools.createTextDoc(Param.getMSF());