bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / sheet / _XEnhancedMouseClickBroadcaster.java
blob47e5b73e54958e93c39040040342fca3fb627b44
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 ifc.sheet;
20 import com.sun.star.accessibility.AccessibleRole;
21 import com.sun.star.accessibility.XAccessible;
22 import com.sun.star.accessibility.XAccessibleComponent;
23 import com.sun.star.awt.Point;
24 import com.sun.star.awt.Rectangle;
25 import com.sun.star.awt.XEnhancedMouseClickHandler;
26 import com.sun.star.awt.XWindow;
27 import com.sun.star.frame.XModel;
28 import com.sun.star.lang.XMultiServiceFactory;
29 import com.sun.star.sheet.XEnhancedMouseClickBroadcaster;
30 import com.sun.star.uno.UnoRuntime;
31 import com.sun.star.uno.XInterface;
33 import lib.MultiMethodTest;
34 import util.AccessibilityTools;
35 import util.DesktopTools;
36 import java.awt.Robot;
37 import java.awt.event.InputEvent;
40 public class _XEnhancedMouseClickBroadcaster extends MultiMethodTest {
41 public XEnhancedMouseClickBroadcaster oObj;
42 protected boolean mousePressed = false;
43 protected boolean mouseReleased = false;
44 protected XEnhancedMouseClickHandler listener = new MyListener();
45 private XModel docModel = null;
47 public void before() {
48 docModel = UnoRuntime.queryInterface(
49 XModel.class,tEnv.getObjRelation("FirstModel"));
50 DesktopTools.bringWindowToFront(docModel);
53 public void _addEnhancedMouseClickHandler() {
54 oObj.addEnhancedMouseClickHandler(listener);
55 clickOnSheet();
57 //make sure that the listener is removed even if the test fails
58 if ((!mousePressed) || (!mouseReleased)) {
59 oObj.removeEnhancedMouseClickHandler(listener);
62 tRes.tested("addEnhancedMouseClickHandler()",
63 mousePressed && mouseReleased);
66 public void _removeEnhancedMouseClickHandler() {
67 requiredMethod("addEnhancedMouseClickHandler()");
68 mousePressed = false;
69 mouseReleased = false;
70 oObj.removeEnhancedMouseClickHandler(listener);
71 clickOnSheet();
72 tRes.tested("removeEnhancedMouseClickHandler()",
73 (!mousePressed) && (!mouseReleased));
76 protected boolean clickOnSheet() {
77 log.println("try to open contex menu...");
78 AccessibilityTools at = new AccessibilityTools();
80 XWindow xWindow = AccessibilityTools.getCurrentWindow((XMultiServiceFactory)tParam.getMSF(), docModel);
82 XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);
84 XInterface oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.PANEL);
86 XAccessibleComponent window = UnoRuntime.queryInterface(
87 XAccessibleComponent.class, oObj);
89 Point point = window.getLocationOnScreen();
90 Rectangle rect = window.getBounds();
92 log.println("klick mouse button...");
93 try {
94 Robot rob = new Robot();
95 int x = point.X + (rect.Width / 2)+50;
96 int y = point.Y + (rect.Height / 2)+50;
97 rob.mouseMove(x, y);
98 System.out.println("Press Button");
99 rob.mousePress(InputEvent.BUTTON3_MASK);
100 System.out.println("Release Button");
101 rob.mouseRelease(InputEvent.BUTTON3_MASK);
102 System.out.println("done");
103 System.out.println("warte");
104 shortWait();
105 System.out.println("Press Button");
106 rob.mousePress(InputEvent.BUTTON1_MASK);
107 System.out.println("Release Button");
108 rob.mouseRelease(InputEvent.BUTTON1_MASK);
109 System.out.println("done "+rob.getAutoDelay());
110 } catch (java.awt.AWTException e) {
111 log.println("couldn't press mouse button");
115 return true;
118 private void shortWait() {
119 try {
120 Thread.sleep(2000);
121 } catch (InterruptedException e) {
122 System.out.println("While waiting :" + e);
126 protected class MyListener implements XEnhancedMouseClickHandler {
127 public void disposing(
128 com.sun.star.lang.EventObject eventObject) {
131 public boolean mousePressed(
132 com.sun.star.awt.EnhancedMouseEvent enhancedMouseEvent) {
133 log.println("mousePressed");
134 mousePressed = true;
136 return true;
139 public boolean mouseReleased(
140 com.sun.star.awt.EnhancedMouseEvent enhancedMouseEvent) {
141 log.println("mouseReleased");
142 mouseReleased = true;
144 return true;