bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _basctl / AccessibleShape.java
blobe9abc115640c484b2557243590ef5a66df8eed9a
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 .
20 package mod._basctl;
22 import com.sun.star.accessibility.AccessibleRole;
23 import com.sun.star.accessibility.XAccessible;
24 import com.sun.star.awt.PosSize;
25 import com.sun.star.awt.Rectangle;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.beans.PropertyValue;
28 import com.sun.star.frame.XDesktop;
29 import com.sun.star.frame.XDispatchHelper;
30 import com.sun.star.frame.XDispatchProvider;
31 import com.sun.star.frame.XFrame;
32 import com.sun.star.frame.XModel;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
37 import java.io.PrintWriter;
38 import lib.StatusException;
39 import lib.TestCase;
40 import lib.TestEnvironment;
41 import lib.TestParameters;
42 import util.AccessibilityTools;
43 import util.DesktopTools;
44 import util.WriterTools;
45 import util.utils;
47 public class AccessibleShape extends TestCase {
49 XTextDocument xTextDoc = null;
50 XInterface oObj = null;
52 protected void cleanup(TestParameters Param, PrintWriter log) {
53 log.println("Cleaning up");
54 DesktopTools.closeDoc(xTextDoc);
55 try {
56 XMultiServiceFactory xMSF = (XMultiServiceFactory) Param.getMSF();
57 Object o = xMSF.createInstance("com.sun.star.frame.Desktop");
58 XDesktop xDesk = UnoRuntime.queryInterface(XDesktop.class, o);
59 DesktopTools.closeDoc(xDesk.getCurrentFrame());
60 } catch (Exception e) {
61 log.println("Couldn't close IDE");
65 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
66 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
67 log.println( "creating a test environment" );
68 String aURL=utils.getFullTestURL("basDialog.odt");
69 xTextDoc = WriterTools.loadTextDoc(xMSF,aURL);
70 XModel xModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
71 XFrame xFrame = xModel.getCurrentController().getFrame();
72 XDispatchProvider xDPP = UnoRuntime.queryInterface(XDispatchProvider.class, xFrame);
74 log.println( "opening the basic dialog editor" );
75 try {
76 Object o = xMSF.createInstance("com.sun.star.frame.DispatchHelper");
77 XDispatchHelper xDPH = UnoRuntime.queryInterface(XDispatchHelper.class, o);
78 PropertyValue[] aArgs = new PropertyValue[4];
79 aArgs[0] = new PropertyValue();
80 aArgs[0].Name = "Document";
81 aArgs[0].Value = aURL;
82 aArgs[1] = new PropertyValue();
83 aArgs[1].Name = "LibName";
84 aArgs[1].Value = "basctl";
85 aArgs[2] = new PropertyValue();
86 aArgs[2].Name = "Name";
87 aArgs[2].Value = "Dialog1";
88 aArgs[3] = new PropertyValue();
89 aArgs[3].Name = "Type";
90 aArgs[3].Value = "Dialog";
91 xDPH.executeDispatch(xDPP, ".uno:BasicIDEAppear", "", 0, aArgs);
92 } catch (Exception e) {
93 throw new StatusException("Couldn't open Basic Dialog",e);
96 utils.shortWait(3000);
98 try {
99 oObj = (XInterface) ((XMultiServiceFactory)tParam.getMSF()).createInstance
100 ("com.sun.star.awt.Toolkit") ;
101 } catch (com.sun.star.uno.Exception e) {
102 log.println("Couldn't get toolkit");
103 e.printStackTrace(log);
104 throw new StatusException("Couldn't get toolkit", e );
107 AccessibilityTools at = new AccessibilityTools();
109 final XWindow basicIDE = xFrame.getContainerWindow();
111 XAccessible xRoot = AccessibilityTools.getAccessibleObject(basicIDE);
113 AccessibilityTools.printAccessibleTree(log, xRoot, tParam.getBool(util.PropertyName.DEBUG_IS_ACTIVE));
115 oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.SHAPE);
117 // create test environment here
118 TestEnvironment tEnv = new TestEnvironment( oObj );
120 log.println("Implementation Name: " + utils.getImplName(oObj));
122 tEnv.addObjRelation("Destroy", Boolean.TRUE);
124 tEnv.addObjRelation("EventProducer",
125 new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
126 public void fireEvent() {
127 Rectangle oldPosSize = basicIDE.getPosSize();
128 Rectangle newPosSize = new Rectangle();
129 newPosSize.Width = oldPosSize.Width/2;
130 newPosSize.Height = oldPosSize.Height/2;
131 newPosSize.X = oldPosSize.X + 20;
132 newPosSize.Y = oldPosSize.Y + 20;
133 basicIDE.setPosSize(newPosSize.X, newPosSize.Y, newPosSize.Width,
134 newPosSize.Height, PosSize.POSSIZE);
135 utils.shortWait(1000);
136 basicIDE.setPosSize(oldPosSize.X, oldPosSize.Y, oldPosSize.Width,
137 oldPosSize.Height, PosSize.POSSIZE);
141 return tEnv;