Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwAccessibleTextGraphicObject.java
blob73a53f29981e341d093edf4cb9d365a359f84c2a
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.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 /**
46 * Test of accessible object for the graphic object of a text document.<p>
47 * Object implements the following interfaces :
48 * <ul>
49 * <li> <code>::com::sun::star::accessibility::XAccessible</code></li>
50 * </ul>
51 * @see com.sun.star.accessibility.XAccessible
53 public class SwAccessibleTextGraphicObject extends TestCase {
55 XTextDocument xTextDoc = null;
57 /**
58 * Called to create an instance of <code>TestEnvironment</code>
59 * with an object to test and related objects.
60 * Creates a graphic object and inserts it into the document.
61 * Obtains accessible object for graphic object.
63 * @param Param test parameters
64 * @param log writer to log information while testing
66 * @see TestEnvironment
67 * @see #getTestEnvironment
69 @Override
70 protected TestEnvironment createTestEnvironment(
71 TestParameters Param, PrintWriter log) {
73 XInterface oObj = null;
75 SOfficeFactory SOF = SOfficeFactory.getFactory(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 XWindow xWindow = AccessibilityTools.getCurrentWindow(aModel);
94 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
96 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.GRAPHIC);
98 log.println("ImplementationName " + utils.getImplName(oObj));
99 AccessibilityTools.printAccessibleTree(log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
101 TestEnvironment tEnv = new TestEnvironment(oObj);
103 XController xController = xTextDoc.getCurrentController();
104 XViewSettingsSupplier xViewSetSup = UnoRuntime.queryInterface(XViewSettingsSupplier.class,
105 xController);
107 final XPropertySet PropSet = xViewSetSup.getViewSettings();
109 tEnv.addObjRelation("EventProducer",
110 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
111 public void fireEvent() {
112 try {
113 //change zoom value to 15%
114 PropSet.setPropertyValue("ZoomValue", Short.valueOf("15"));
115 //and back to 100%
116 PropSet.setPropertyValue("ZoomValue", Short.valueOf("100"));
117 } catch ( com.sun.star.lang.WrappedTargetException e ) {
119 } catch ( com.sun.star.lang.IllegalArgumentException e ) {
121 } catch ( com.sun.star.beans.PropertyVetoException e ) {
123 } catch ( com.sun.star.beans.UnknownPropertyException e ) {
130 return tEnv;
136 * Called while disposing a <code>TestEnvironment</code>.
137 * Disposes text document.
138 * @param Param test parameters
139 * @param log writer to log information while testing
141 @Override
142 protected void cleanup( TestParameters Param, PrintWriter log) {
143 log.println("dispose text document");
144 util.DesktopTools.closeDoc(xTextDoc);
148 * Called while the <code>TestCase</code> initialization.
149 * Creates a text document.
151 * @param Param test parameters
152 * @param log writer to log information while testing
154 * @see #initializeTestCase
156 @Override
157 protected void initialize(TestParameters Param, PrintWriter log) {
158 log.println( "creating a text document" );
159 xTextDoc = WriterTools.createTextDoc(Param.getMSF());