bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svtools / AccessibleTabBar.java
blob6dd4e547e8f13a90b7a2db92fb61b83a305e354b
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 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;
29 import com.sun.star.accessibility.AccessibleRole;
30 import com.sun.star.accessibility.XAccessible;
31 import com.sun.star.awt.PosSize;
32 import com.sun.star.awt.XWindow;
33 import com.sun.star.frame.XModel;
34 import com.sun.star.lang.XComponent;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
38 import com.sun.star.util.XCloseable;
41 public class AccessibleTabBar extends TestCase {
42 static XComponent xDoc;
44 /**
45 * Disposes the document, if exists, created in
46 * <code>createTestEnvironment</code> method.
48 protected void cleanup(TestParameters Param, PrintWriter log) {
49 log.println("disposing xCalcDoc");
51 if (xDoc != null) {
52 closeDoc(xDoc);
56 /**
57 * Creates a spreadsheet document. Then obtains an accessible object with
58 * the role <code>AccessibleRole.PAGETAB</code>.
59 * Object relations created :
60 * <ul>
61 * <li> <code>'EventProducer'</code> for
62 * {@link ifc.accessibility._XAccessibleEventBroadcaster}:
63 * </li>
64 * </ul>
66 * @param tParam test parameters
67 * @param log writer to log information while testing
69 * @see com.sun.star.awt.Toolkit
70 * @see com.sun.star.accessibility.AccessibleRole
71 * @see ifc.accessibility._XAccessibleEventBroadcaster
72 * @see com.sun.star.accessibility.XAccessibleEventBroadcaster
74 protected TestEnvironment createTestEnvironment(TestParameters tParam,
75 PrintWriter log) {
76 log.println("creating a test environment");
78 if (xDoc != null) {
79 closeDoc(xDoc);
82 XMultiServiceFactory msf = (XMultiServiceFactory) tParam.getMSF();
84 // get a soffice factory object
85 SOfficeFactory SOF = SOfficeFactory.getFactory(msf);
87 try {
88 log.println("creating a calc document");
89 xDoc = UnoRuntime.queryInterface(XComponent.class,
90 SOF.createCalcDoc(
91 null));
92 } catch (com.sun.star.uno.Exception e) {
93 // Some exception occurs.FAILED
94 e.printStackTrace(log);
95 throw new StatusException("Couldn't create document", e);
98 shortWait();
100 XInterface oObj = null;
102 AccessibilityTools at = new AccessibilityTools();
104 shortWait();
106 XWindow xWindow = UnoRuntime.queryInterface(XModel.class, xDoc).
107 getCurrentController().getFrame().getContainerWindow();
109 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
110 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
111 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
113 log.println("ImplementationName: " + util.utils.getImplName(oObj));
115 TestEnvironment tEnv = new TestEnvironment(oObj);
117 final XWindow aWin = xWindow;
119 tEnv.addObjRelation("EventProducer",
120 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
121 public void fireEvent() {
122 aWin.setPosSize(100,100, 500, 500, PosSize.POSSIZE);
126 return tEnv;
130 * Sleeps for 3 sec. to allow StarOffice to react on <code>
131 * reset</code> call.
133 private void shortWait() {
134 try {
135 Thread.sleep(5000);
136 } catch (InterruptedException e) {
137 System.out.println("While waiting :" + e);
141 protected void closeDoc(XComponent xDoc) {
142 XCloseable closer = UnoRuntime.queryInterface(
143 XCloseable.class, xDoc);
145 try {
146 closer.close(true);
147 } catch (com.sun.star.util.CloseVetoException e) {
148 log.println("Couldn't close document " + e.getMessage());
149 } catch (java.lang.NullPointerException e) {
150 log.println("Couldn't close document " + e.getMessage());