bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svtools / AccessibleTabBarPageList.java
blob1bc50a7b093b0b29d3de0b00baf85bbb96fc1cdf
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._svtools;
20 import com.sun.star.drawing.XLayerManager;
21 import com.sun.star.drawing.XLayerSupplier;
22 import java.io.PrintWriter;
24 import lib.StatusException;
25 import lib.TestCase;
26 import lib.TestEnvironment;
27 import lib.TestParameters;
28 import util.AccessibilityTools;
29 import util.SOfficeFactory;
31 import com.sun.star.accessibility.AccessibleRole;
32 import com.sun.star.accessibility.XAccessible;
33 import com.sun.star.awt.XExtendedToolkit;
34 import com.sun.star.awt.XWindow;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 import com.sun.star.util.XCloseable;
42 /**
43 * Test for object that implements the following interfaces :
44 * <ul>
45 * <li><code>::com::sun::star::accessibility::XAccessibleComponent
46 * </code></li>
47 * <li><code>::com::sun::star::accessibility::XAccessibleContext
48 * </code></li>
49 * <li><code>::com::sun::star::accessibility::XAccessibleEventBroadcaster
50 * </code></li>
51 * <li>
52 * <code>::com::sun::star::accessibility::XAccessibleExtendedComponent
53 * </code></li>
54 * <li><code>::com::sun::star::accessibility::XAccessibleSelection
55 * </code></li>
56 * </ul> <p>
58 * @see com.sun.star.accessibility.XAccessibleSelection
59 * @see com.sun.star.accessibility.XAccessibleExtendedComponent
60 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
61 * @see com.sun.star.accessibility.XAccessibleContext
62 * @see com.sun.star.accessibility.XAccessibleComponent
63 * @see ifc.accessibility._XAccessibleSelection
64 * @see ifc.accessibility._XAccessibleComponent
65 * @see ifc.accessibility._XAccessibleExtendedComponent
66 * @see ifc.accessibility._XAccessibleEventBroadcaster
67 * @see ifc.accessibility._XAccessibleContext
69 public class AccessibleTabBarPageList extends TestCase {
70 static XComponent xDoc;
72 /**
73 * Disposes the document, if exists, created in
74 * <code>createTestEnvironment</code> method.
76 protected void cleanup(TestParameters Param, PrintWriter log) {
77 log.println("disposing xDoc");
79 if (xDoc != null) {
80 closeDoc();
84 /**
85 * Creates a spreadsheet document. Then obtains an accessible object with
86 * the role <code>AccessibleRole.PAGETABLIST</code>.
87 * Object relations created :
88 * <ul>
89 * <li> <code>'EventProducer'</code> for
90 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
91 * </li>
92 * </ul>
94 * @param tParam test parameters
95 * @param log writer to log information while testing
97 * @see com.sun.star.awt.Toolkit
98 * @see com.sun.star.accessibility.AccessibleRole
99 * @see ifc.accessibility._XAccessibleEventBroadcaster
100 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
102 protected TestEnvironment createTestEnvironment(TestParameters tParam,
103 PrintWriter log) {
104 log.println("creating a test environment");
106 if (xDoc != null) {
107 closeDoc();
110 // get a soffice factory object
111 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory) tParam.getMSF());
113 try {
114 log.println("creating a draw document");
115 xDoc = SOF.createDrawDoc(null);
116 } catch (com.sun.star.uno.Exception e) {
117 // Some exception occurs.FAILED
118 e.printStackTrace(log);
119 throw new StatusException("Couldn't create document", e);
122 shortWait();
124 XInterface oObj = null;
126 try {
127 oObj = (XInterface) ( (XMultiServiceFactory) tParam.getMSF())
128 .createInstance("com.sun.star.awt.Toolkit");
129 } catch (com.sun.star.uno.Exception e) {
130 log.println("Couldn't get toolkit");
131 e.printStackTrace(log);
132 throw new StatusException("Couldn't get toolkit", e);
135 XExtendedToolkit tk = UnoRuntime.queryInterface(
136 XExtendedToolkit.class, oObj);
138 AccessibilityTools at = new AccessibilityTools();
140 shortWait();
142 XWindow xWindow = UnoRuntime.queryInterface(XWindow.class,
143 tk.getActiveTopWindow());
145 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
147 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot,
148 AccessibleRole.PAGE_TAB_LIST);
150 log.println("ImplementationName: " + util.utils.getImplName(oObj));
152 TestEnvironment tEnv = new TestEnvironment(oObj);
154 tEnv.addObjRelation("XAccessibleSelection.multiSelection",
155 new Boolean(false));
157 tEnv.addObjRelation("XAccessibleSelection.OneAlwaysSelected",
158 new Boolean(true));
160 XLayerSupplier oLS = UnoRuntime.queryInterface(XLayerSupplier.class, xDoc);
161 XInterface oLM = oLS.getLayerManager();
162 final XLayerManager xLM = UnoRuntime.queryInterface(XLayerManager.class, oLM);
165 tEnv.addObjRelation("EventProducer",
166 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
167 public void fireEvent() {
168 xLM.insertNewByIndex(0);
172 return tEnv;
176 * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
177 * reset</code> call.
179 private void shortWait() {
180 try {
181 Thread.sleep(5000);
182 } catch (InterruptedException e) {
183 System.out.println("While waiting :" + e);
187 protected void closeDoc() {
188 XCloseable closer = UnoRuntime.queryInterface(
189 XCloseable.class, xDoc);
191 try {
192 closer.close(true);
193 } catch (com.sun.star.util.CloseVetoException e) {
194 log.println("Couldn't close document " + e.getMessage());
195 } catch (com.sun.star.lang.DisposedException e) {
196 log.println("Couldn't close document " + e.getMessage());