merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _basctl / AccessibleShape.java
blobe1ac2322eef4b8bf45851c3931dc2c4557248045
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleShape.java,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 package mod._basctl;
34 import com.sun.star.accessibility.AccessibleRole;
35 import com.sun.star.accessibility.XAccessible;
36 import com.sun.star.awt.PosSize;
37 import com.sun.star.awt.Rectangle;
38 import com.sun.star.awt.XExtendedToolkit;
39 import com.sun.star.awt.XWindow;
40 import com.sun.star.beans.PropertyValue;
41 import com.sun.star.frame.XDesktop;
42 import com.sun.star.frame.XDispatchHelper;
43 import com.sun.star.frame.XDispatchProvider;
44 import com.sun.star.frame.XFrame;
45 import com.sun.star.frame.XModel;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.text.XTextDocument;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
50 import java.io.PrintWriter;
51 import lib.StatusException;
52 import lib.TestCase;
53 import lib.TestEnvironment;
54 import lib.TestParameters;
55 import util.AccessibilityTools;
56 import util.DesktopTools;
57 import util.WriterTools;
58 import util.utils;
60 public class AccessibleShape extends TestCase {
62 XTextDocument xTextDoc = null;
63 XInterface oObj = null;
64 XWindow basicIDE = null;
66 protected void cleanup(TestParameters Param, PrintWriter log) {
67 log.println("Cleaning up");
68 DesktopTools.closeDoc(xTextDoc);
69 try {
70 XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF();
71 Object o = xMSF.createInstance("com.sun.star.frame.Desktop");
72 XDesktop xDesk = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, o);
73 DesktopTools.closeDoc(xDesk.getCurrentFrame());
74 } catch (Exception e) {
75 log.println("Couldn't close IDE");
79 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
80 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
81 log.println( "creating a test environment" );
82 String aURL=utils.getFullTestURL("basDialog.odt");
83 xTextDoc = WriterTools.loadTextDoc(xMSF,aURL);
84 XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xTextDoc);
85 XFrame xFrame = xModel.getCurrentController().getFrame();
86 XDispatchProvider xDPP = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class, xFrame);
88 log.println( "opening the basic dialog editor" );
89 try {
90 Object o = xMSF.createInstance("com.sun.star.frame.DispatchHelper");
91 XDispatchHelper xDPH = (XDispatchHelper) UnoRuntime.queryInterface(XDispatchHelper.class, o);
92 PropertyValue[] aArgs = new PropertyValue[4];
93 aArgs[0] = new PropertyValue();
94 aArgs[0].Name = "Document";
95 aArgs[0].Value = aURL;
96 aArgs[1] = new PropertyValue();
97 aArgs[1].Name = "LibName";
98 aArgs[1].Value = "basctl";
99 aArgs[2] = new PropertyValue();
100 aArgs[2].Name = "Name";
101 aArgs[2].Value = "Dialog1";
102 aArgs[3] = new PropertyValue();
103 aArgs[3].Name = "Type";
104 aArgs[3].Value = "Dialog";
105 xDPH.executeDispatch(xDPP, ".uno:BasicIDEAppear", "", 0, aArgs);
106 } catch (Exception e) {
107 throw new StatusException("Couldn't open Basic Dialog",e);
110 utils.shortWait(3000);
112 try {
113 oObj = (XInterface) ((XMultiServiceFactory)tParam.getMSF()).createInstance
114 ("com.sun.star.awt.Toolkit") ;
115 } catch (com.sun.star.uno.Exception e) {
116 log.println("Couldn't get toolkit");
117 e.printStackTrace(log);
118 throw new StatusException("Couldn't get toolkit", e );
122 XExtendedToolkit tk = (XExtendedToolkit)
123 UnoRuntime.queryInterface(XExtendedToolkit.class,oObj);
126 AccessibilityTools at = new AccessibilityTools();
128 basicIDE = (XWindow)
129 UnoRuntime.queryInterface(XWindow.class,tk.getActiveTopWindow());
131 XAccessible xRoot = at.getAccessibleObject(basicIDE);
133 at.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
135 oObj = at.getAccessibleObjectForRole(xRoot, AccessibleRole.SHAPE);
137 // create test environment here
138 TestEnvironment tEnv = new TestEnvironment( oObj );
140 log.println("Implementation Name: " + utils.getImplName(oObj));
142 tEnv.addObjRelation("Destroy", Boolean.TRUE);
144 final XExtendedToolkit subtk = tk;
146 tEnv.addObjRelation("EventProducer",
147 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
148 public void fireEvent() {
149 XWindow xWin = (XWindow) UnoRuntime.queryInterface(
150 XWindow.class, subtk.getActiveTopWindow());
151 Rectangle oldPosSize = xWin.getPosSize();
152 Rectangle newPosSize = new Rectangle();
153 newPosSize.Width = oldPosSize.Width/2;
154 newPosSize.Height = oldPosSize.Height/2;
155 newPosSize.X = oldPosSize.X + 20;
156 newPosSize.Y = oldPosSize.Y + 20;
157 xWin.setPosSize(newPosSize.X, newPosSize.Y, newPosSize.Width,
158 newPosSize.Height, PosSize.POSSIZE);
159 utils.shortWait(1000);
160 xWin.setPosSize(oldPosSize.X, oldPosSize.Y, oldPosSize.Width,
161 oldPosSize.Height, PosSize.POSSIZE);
165 return tEnv;