bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleTextGraphicObject.java
blobee63c3dd0e458c20b9424996cc98ccba93e70101
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.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.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 import com.sun.star.view.XViewSettingsSupplier;
46 /**
47 * Test of accessible object for the graphic object of a text document.<p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
51 * </ul>
52 * @see com.sun.star.accessibility.XAccessible
54 public class SwAccessibleTextGraphicObject extends TestCase {
56 XTextDocument xTextDoc = null;
58 /**
59 * Called to create an instance of <code>TestEnvironment</code>
60 * with an object to test and related objects.
61 * Creates a graphic object and inserts it into the document.
62 * Obtains accessible object for graphic object.
64 * @param Param test parameters
65 * @param log writer to log information while testing
67 * @see TestEnvironment
68 * @see #getTestEnvironment
70 protected TestEnvironment createTestEnvironment(
71 TestParameters Param, PrintWriter log) {
73 XInterface oObj = null;
75 SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory)Param.getMSF());
76 Object oGraphObj = SOF.createInstance(
77 xTextDoc, "com.sun.star.text.GraphicObject");
79 XText the_text = xTextDoc.getText();
80 XTextCursor the_cursor = the_text.createTextCursor();
81 XTextContent the_content = UnoRuntime.queryInterface(XTextContent.class, oGraphObj);
83 log.println( "inserting graphic" );
84 try {
85 the_text.insertTextContent(the_cursor, the_content, true);
86 } catch (com.sun.star.lang.IllegalArgumentException e) {
87 e.printStackTrace();
88 throw new StatusException("Couldn't insert Content", e);
91 XModel aModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
93 AccessibilityTools at = new AccessibilityTools();
95 XWindow xWindow = AccessibilityTools.getCurrentWindow((XMultiServiceFactory)Param.getMSF(), aModel);
96 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
98 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.GRAPHIC);
100 log.println("ImplementationName " + utils.getImplName(oObj));
101 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
103 TestEnvironment tEnv = new TestEnvironment(oObj);
105 XController xController = xTextDoc.getCurrentController();
106 XViewSettingsSupplier xViewSetSup = UnoRuntime.queryInterface(XViewSettingsSupplier.class,
107 xController);
109 final XPropertySet PropSet = xViewSetSup.getViewSettings();
111 tEnv.addObjRelation("EventProducer",
112 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
113 public void fireEvent() {
114 try {
115 //change zoom value to 15%
116 PropSet.setPropertyValue("ZoomValue", new Short("15"));
117 //and back to 100%
118 PropSet.setPropertyValue("ZoomValue", new Short("100"));
119 } catch ( com.sun.star.lang.WrappedTargetException e ) {
121 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
123 } catch ( com.sun.star.beans.PropertyVetoException e ) {
125 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
132 return tEnv;
138 * Called while disposing a <code>TestEnvironment</code>.
139 * Disposes text document.
140 * @param Param test parameters
141 * @param log writer to log information while testing
143 protected void cleanup( TestParameters Param, PrintWriter log) {
144 log.println("dispose text document");
145 util.DesktopTools.closeDoc(xTextDoc);
149 * Called while the <code>TestCase</code> initialization.
150 * Creates a text document.
152 * @param Param test parameters
153 * @param log writer to log information while testing
155 * @see #initializeTestCase
157 protected void initialize(TestParameters Param, PrintWriter log) {
158 log.println( "creating a text document" );
159 xTextDoc = WriterTools.createTextDoc((XMultiServiceFactory)Param.getMSF());