merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / awt / _XSpinValue.java
blobf24c6bfa2a6145364ab862093aac32444fbf58d5
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: _XSpinValue.java,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
31 package ifc.awt;
33 import com.sun.star.accessibility.XAccessible;
34 import com.sun.star.accessibility.XAccessibleComponent;
35 import com.sun.star.awt.Point;
36 import com.sun.star.awt.ScrollBarOrientation;
37 import com.sun.star.awt.XSpinValue;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.uno.UnoRuntime;
41 import java.awt.Robot;
42 import java.awt.event.InputEvent;
43 import lib.MultiMethodTest;
45 public class _XSpinValue extends MultiMethodTest {
47 public XSpinValue oObj;
48 public boolean adjusted = false;
49 com.sun.star.awt.XAdjustmentListener listener = new AdjustmentListener();
51 public void _addAdjustmentListener() {
52 util.FormTools.switchDesignOf((XMultiServiceFactory) tParam.getMSF(),
53 (XTextDocument) tEnv.getObjRelation("Document"));
54 shortWait();
55 oObj.addAdjustmentListener(listener);
56 adjustScrollBar();
58 boolean res = adjusted;
59 oObj.removeAdjustmentListener(listener);
60 adjusted = false;
61 adjustScrollBar();
62 res &= !adjusted;
63 tRes.tested("addAdjustmentListener()", res);
66 public void _removeAdjustmentListener() {
67 //this method is checked in addAjustmentListener
68 //so that method is requiered here and if it works
69 //this method is given OK too
70 requiredMethod("addAdjustmentListener()");
71 tRes.tested("removeAdjustmentListener()", true);
74 public void _setSpinIncrement() {
75 oObj.setSpinIncrement(15);
76 oObj.setSpinIncrement(5);
77 int bi = oObj.getSpinIncrement();
78 tRes.tested("setSpinIncrement()",bi==5);
81 public void _getSpinIncrement() {
82 //this method is checked in the corresponding set method
83 //so that method is requiered here and if it works
84 //this method is given OK too
85 requiredMethod("setSpinIncrement()");
86 tRes.tested("getSpinIncrement()", true);
90 public void _setMaximum() {
91 oObj.setMaximum(490);
92 oObj.setMaximum(480);
93 int max = oObj.getMaximum();
94 tRes.tested("setMaximum()",max==480);
97 public void _getMaximum() {
98 //this method is checked in the corresponding set method
99 //so that method is requiered here and if it works
100 //this method is given OK too
101 requiredMethod("setMaximum()");
102 tRes.tested("getMaximum()", true);
105 public void _setMinimum() {
106 oObj.setMinimum(90);
107 oObj.setMinimum(80);
108 int max = oObj.getMinimum();
109 tRes.tested("setMinimum()",max==80);
112 public void _getMinimum() {
113 //this method is checked in the corresponding set method
114 //so that method is requiered here and if it works
115 //this method is given OK too
116 requiredMethod("setMinimum()");
117 tRes.tested("getMinimum()", true);
120 public void _setOrientation() {
121 boolean res = true;
122 try {
123 oObj.setOrientation(ScrollBarOrientation.HORIZONTAL);
124 oObj.setOrientation(ScrollBarOrientation.VERTICAL);
125 } catch (com.sun.star.lang.NoSupportException e) {
126 log.println("Couldn't set Orientation");
128 int ori = oObj.getOrientation();
129 res &= (ori==ScrollBarOrientation.VERTICAL);
130 tRes.tested("setOrientation()",res );
133 public void _getOrientation() {
134 //this method is checked in the corresponding set method
135 //so that method is requiered here and if it works
136 //this method is given OK too
137 requiredMethod("setOrientation()");
138 tRes.tested("getOrientation()", true);
141 public void _setValue() {
142 oObj.setMaximum(600);
143 oObj.setValue(480);
144 oObj.setValue(520);
145 int val = oObj.getValue();
146 tRes.tested("setValue()",val==520);
149 public void _getValue() {
150 //this method is checked in the corresponding set method
151 //so that method is requiered here and if it works
152 //this method is given OK too
153 requiredMethod("setValue()");
154 tRes.tested("getValue()", true);
157 public void _setValues() {
158 oObj.setValues(80, 200, 180);
159 oObj.setValues(70, 210, 200);
160 int val = oObj.getValue();
161 int min = oObj.getMinimum();
162 int max = oObj.getMaximum();
163 tRes.tested("setValues()",((min==70) && (max==210) && (val==200)));
166 private void adjustScrollBar() {
169 XSpinValue sv = (XSpinValue) UnoRuntime.queryInterface(
170 XSpinValue.class, tEnv.getTestObject());
172 sv.setValue(500);
174 shortWait();
176 XAccessible acc = (XAccessible) UnoRuntime.queryInterface(
177 XAccessible.class, tEnv.getTestObject());
179 XAccessibleComponent aCom = (XAccessibleComponent) UnoRuntime.queryInterface(
180 XAccessibleComponent.class,
181 acc.getAccessibleContext());
183 Point location = aCom.getLocationOnScreen();
184 //Point location = (Point) tEnv.getObjRelation("Location");
185 //XAccessibleComponent aCom = (XAccessibleComponent) tEnv.getObjRelation("Location");
186 //Point location = aCom.getLocationOnScreen();
187 try {
188 Robot rob = new Robot();
189 rob.mouseMove(location.X + 20, location.Y + 10);
190 rob.mousePress(InputEvent.BUTTON1_MASK);
191 rob.mouseRelease(InputEvent.BUTTON1_MASK);
192 } catch (java.awt.AWTException e) {
193 System.out.println("couldn't adjust scrollbar");
196 shortWait();
200 * Sleeps for 0.5 sec. to allow Office to react
202 private void shortWait() {
203 try {
204 Thread.sleep(500);
205 } catch (InterruptedException e) {
206 log.println("While waiting :" + e);
210 public class AdjustmentListener
211 implements com.sun.star.awt.XAdjustmentListener {
212 public void adjustmentValueChanged(com.sun.star.awt.AdjustmentEvent adjustmentEvent) {
213 System.out.println("Adjustment Value changed");
214 System.out.println("AdjustmentEvent: " + adjustmentEvent.Value);
215 adjusted = true;
218 public void disposing(com.sun.star.lang.EventObject eventObject) {
219 System.out.println("Listener disposed");