bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _basctl / AccessibleShape.java
blobdaac55ca402f174304df2d5219d028c480b79b8a
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 @Override
53 protected void cleanup(TestParameters Param, PrintWriter log) {
54 log.println("Cleaning up");
55 DesktopTools.closeDoc(xTextDoc);
56 try {
57 XMultiServiceFactory xMSF = Param.getMSF();
58 Object o = xMSF.createInstance("com.sun.star.frame.Desktop");
59 XDesktop xDesk = UnoRuntime.queryInterface(XDesktop.class, o);
60 DesktopTools.closeDoc(xDesk.getCurrentFrame());
61 } catch (Exception e) {
62 log.println("Couldn't close IDE");
66 @Override
67 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
68 XMultiServiceFactory xMSF = tParam.getMSF();
69 log.println( "creating a test environment" );
70 String aURL=utils.getFullTestURL("basDialog.odt");
71 xTextDoc = WriterTools.loadTextDoc(xMSF,aURL);
72 XModel xModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);
73 XFrame xFrame = xModel.getCurrentController().getFrame();
74 XDispatchProvider xDPP = UnoRuntime.queryInterface(XDispatchProvider.class, xFrame);
76 log.println( "opening the basic dialog editor" );
77 try {
78 Object o = xMSF.createInstance("com.sun.star.frame.DispatchHelper");
79 XDispatchHelper xDPH = UnoRuntime.queryInterface(XDispatchHelper.class, o);
80 PropertyValue[] aArgs = new PropertyValue[4];
81 aArgs[0] = new PropertyValue();
82 aArgs[0].Name = "Document";
83 aArgs[0].Value = aURL;
84 aArgs[1] = new PropertyValue();
85 aArgs[1].Name = "LibName";
86 aArgs[1].Value = "basctl";
87 aArgs[2] = new PropertyValue();
88 aArgs[2].Name = "Name";
89 aArgs[2].Value = "Dialog1";
90 aArgs[3] = new PropertyValue();
91 aArgs[3].Name = "Type";
92 aArgs[3].Value = "Dialog";
93 xDPH.executeDispatch(xDPP, ".uno:BasicIDEAppear", "", 0, aArgs);
94 } catch (Exception e) {
95 throw new StatusException("Couldn't open Basic Dialog",e);
98 utils.pause(3000);
100 try {
101 oObj = (XInterface) tParam.getMSF().createInstance
102 ("com.sun.star.awt.Toolkit") ;
103 } catch (com.sun.star.uno.Exception e) {
104 log.println("Couldn't get toolkit");
105 e.printStackTrace(log);
106 throw new StatusException("Couldn't get toolkit", e );
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.pause(1000);
136 basicIDE.setPosSize(oldPosSize.X, oldPosSize.Y, oldPosSize.Width,
137 oldPosSize.Height, PosSize.POSSIZE);
141 return tEnv;