bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleScrollBar.java
blob8e1f168044abe3446d5053e8f0972fb1fee9b379
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._toolkit;
20 import com.sun.star.accessibility.AccessibleRole;
21 import com.sun.star.accessibility.XAccessible;
22 import com.sun.star.accessibility.XAccessibleAction;
23 import com.sun.star.awt.XWindow;
24 import com.sun.star.frame.XDesktop;
25 import com.sun.star.frame.XModel;
26 import com.sun.star.lang.XComponent;
27 import com.sun.star.uno.UnoRuntime;
28 import com.sun.star.uno.XInterface;
30 import java.io.PrintWriter;
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
37 import util.AccessibilityTools;
38 import util.DesktopTools;
39 import util.SOfficeFactory;
42 /**
43 * Test for object that implements the following interfaces :
44 * <ul>
45 * <li><code>
46 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
47 * <li><code>
48 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
49 * </code></li>
50 * <li><code>
51 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
52 * <li><code>
53 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
54 * </code></li>
55 * <li><code>
56 * ::com::sun::star::accessibility::XAccessibleValue</code></li>
57 * <li><code>
58 * ::com::sun::star::accessibility::XAccessibleAction</code></li>
59 * </ul> <p>
61 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
62 * @see com.sun.star.accessibility.XAccessibleContext
63 * @see com.sun.star.accessibility.XAccessibleComponent
64 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
65 * @see com.sun.star.accessibility.XAccessibleValue
66 * @see com.sun.star.accessibility.XAccessibleAction
67 * @see ifc.accessibility._XAccessibleEventBroadcaster
68 * @see ifc.accessibility._XAccessibleContext
69 * @see ifc.accessibility._XAccessibleComponent
70 * @see ifc.accessibility._XAccessibleExtendedComponent
71 * @see ifc.accessibility._XAccessibleValue
72 * @see ifc.accessibility._XAccessibleAction
74 public class AccessibleScrollBar extends TestCase {
75 private static XComponent xDoc;
77 /**
78 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
80 @Override
81 protected void initialize(TestParameters Param, PrintWriter log) {
82 UnoRuntime.queryInterface(XDesktop.class,
83 DesktopTools.createDesktop(
84 Param.getMSF()));
87 /**
88 * Disposes the document, if exists, created in
89 * <code>createTestEnvironment</code> method.
91 @Override
92 protected void cleanup(TestParameters Param, PrintWriter log) {
93 log.println("disposing xTextDoc");
95 if (xDoc != null) {
96 closeDoc();
101 * Creates a text document.
102 * Then obtains an accessible object with
103 * the role <code>AccessibleRole.SCROLLBAR</code>.
104 * Object relations created :
105 * <ul>
106 * <li> <code>'EventProducer'</code> for
107 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
108 * grabs focus </li>
109 * </ul>
111 * @param tParam test parameters
112 * @param log writer to log information while testing
114 * @see com.sun.star.awt.Toolkit
115 * @see com.sun.star.accessibility.AccessibleRole
116 * @see ifc.accessibility._XAccessibleEventBroadcaster
117 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
119 @Override
120 protected TestEnvironment createTestEnvironment(TestParameters tParam,
121 PrintWriter log) {
122 log.println("creating a test environment");
124 if (xDoc != null) {
125 closeDoc();
128 // get a soffice factory object
129 SOfficeFactory SOF = SOfficeFactory.getFactory(
130 tParam.getMSF());
132 try {
133 log.println("creating a text document");
134 xDoc = SOF.createDrawDoc(null);
135 } catch (com.sun.star.uno.Exception e) {
136 // Some exception occurs.FAILED
137 e.printStackTrace(log);
138 throw new StatusException("Couldn't create document", e);
141 XModel aModel = UnoRuntime.queryInterface(XModel.class, xDoc);
143 XInterface oObj = null;
145 XWindow xWindow = AccessibilityTools.getCurrentWindow(
146 aModel);
148 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
150 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.SCROLL_BAR);
152 final XAccessibleAction act = UnoRuntime.queryInterface(
153 XAccessibleAction.class, oObj);
155 log.println("ImplementationName: " + util.utils.getImplName(oObj));
157 TestEnvironment tEnv = new TestEnvironment(oObj);
159 tEnv.addObjRelation("EventProducer",
160 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
161 public void fireEvent() {
162 try {
163 act.doAccessibleAction(1);
164 } catch (Exception e) {
169 return tEnv;
172 protected void closeDoc() {
173 util.DesktopTools.closeDoc(xDoc);