bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _toolkit / AccessibleScrollBar.java
blob321a9d6be4e57c7ff404b659f22319ff976b551a
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.lang.XMultiServiceFactory;
28 import com.sun.star.uno.UnoRuntime;
29 import com.sun.star.uno.XInterface;
31 import java.io.PrintWriter;
33 import lib.StatusException;
34 import lib.TestCase;
35 import lib.TestEnvironment;
36 import lib.TestParameters;
38 import util.AccessibilityTools;
39 import util.DesktopTools;
40 import util.SOfficeFactory;
43 /**
44 * Test for object that implements the following interfaces :
45 * <ul>
46 * <li><code>
47 * ::com::sun::star::accessibility::XAccessibleContext</code></li>
48 * <li><code>
49 * ::com::sun::star::accessibility::XAccessibleEventBroadcaster
50 * </code></li>
51 * <li><code>
52 * ::com::sun::star::accessibility::XAccessibleComponent</code></li>
53 * <li><code>
54 * ::com::sun::star::accessibility::XAccessibleExtendedComponent
55 * </code></li>
56 * <li><code>
57 * ::com::sun::star::accessibility::XAccessibleValue</code></li>
58 * <li><code>
59 * ::com::sun::star::accessibility::XAccessibleAction</code></li>
60 * </ul> <p>
62 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
63 * @see com.sun.star.accessibility.XAccessibleContext
64 * @see com.sun.star.accessibility.XAccessibleComponent
65 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
66 * @see com.sun.star.accessibility.XAccessibleValue
67 * @see com.sun.star.accessibility.XAccessibleAction
68 * @see ifc.accessibility._XAccessibleEventBroadcaster
69 * @see ifc.accessibility._XAccessibleContext
70 * @see ifc.accessibility._XAccessibleComponent
71 * @see ifc.accessibility._XAccessibleExtendedComponent
72 * @see ifc.accessibility._XAccessibleValue
73 * @see ifc.accessibility._XAccessibleAction
75 public class AccessibleScrollBar extends TestCase {
76 private static XComponent xDoc;
78 /**
79 * Creates the Desktop service (<code>com.sun.star.frame.Desktop</code>).
81 protected void initialize(TestParameters Param, PrintWriter log) {
82 UnoRuntime.queryInterface(XDesktop.class,
83 DesktopTools.createDesktop(
84 (XMultiServiceFactory) Param.getMSF()));
87 /**
88 * Disposes the document, if exists, created in
89 * <code>createTestEnvironment</code> method.
91 protected void cleanup(TestParameters Param, PrintWriter log) {
92 log.println("disposing xTextDoc");
94 if (xDoc != null) {
95 closeDoc();
99 /**
100 * Creates a text document.
101 * Then obtains an accessible object with
102 * the role <code>AccessibleRole.SCROLLBAR</code>.
103 * Object relations created :
104 * <ul>
105 * <li> <code>'EventProducer'</code> for
106 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
107 * grabs focus </li>
108 * </ul>
110 * @param tParam test parameters
111 * @param log writer to log information while testing
113 * @see com.sun.star.awt.Toolkit
114 * @see com.sun.star.accessibility.AccessibleRole
115 * @see ifc.accessibility._XAccessibleEventBroadcaster
116 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
118 protected TestEnvironment createTestEnvironment(TestParameters tParam,
119 PrintWriter log) {
120 log.println("creating a test environment");
122 if (xDoc != null) {
123 closeDoc();
126 // get a soffice factory object
127 SOfficeFactory SOF = SOfficeFactory.getFactory(
128 (XMultiServiceFactory) tParam.getMSF());
130 try {
131 log.println("creating a text document");
132 xDoc = SOF.createDrawDoc(null);
133 } catch (com.sun.star.uno.Exception e) {
134 // Some exception occurs.FAILED
135 e.printStackTrace(log);
136 throw new StatusException("Couldn't create document", e);
139 XModel aModel = UnoRuntime.queryInterface(XModel.class, xDoc);
141 XInterface oObj = null;
143 AccessibilityTools at = new AccessibilityTools();
145 XWindow xWindow = AccessibilityTools.getCurrentWindow(
146 (XMultiServiceFactory) tParam.getMSF(),
147 aModel);
149 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
151 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.SCROLL_BAR);
153 final XAccessibleAction act = UnoRuntime.queryInterface(
154 XAccessibleAction.class, oObj);
156 log.println("ImplementationName: " + util.utils.getImplName(oObj));
158 TestEnvironment tEnv = new TestEnvironment(oObj);
160 tEnv.addObjRelation("EventProducer",
161 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
162 public void fireEvent() {
163 try {
164 act.doAccessibleAction(1);
165 } catch (Exception e) {
170 return tEnv;
173 protected void closeDoc() {
174 util.DesktopTools.closeDoc(xDoc);