bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / awt / _XScrollBar.java
blob106b67b7c7506feeba2ba0db48f5133a78c7d2e5
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.awt;
20 import com.sun.star.accessibility.XAccessible;
21 import com.sun.star.accessibility.XAccessibleComponent;
22 import com.sun.star.awt.Point;
23 import com.sun.star.awt.ScrollBarOrientation;
24 import com.sun.star.awt.XScrollBar;
25 import com.sun.star.lang.XMultiServiceFactory;
26 import com.sun.star.text.XTextDocument;
27 import com.sun.star.uno.UnoRuntime;
29 import java.awt.Robot;
30 import java.awt.event.InputEvent;
32 import lib.MultiMethodTest;
35 public class _XScrollBar extends MultiMethodTest {
36 public XScrollBar oObj;
37 public boolean adjusted = false;
38 com.sun.star.awt.XAdjustmentListener listener = new AdjustmentListener();
40 public void _addAdjustmentListener() {
41 util.FormTools.switchDesignOf((XMultiServiceFactory) tParam.getMSF(),
42 (XTextDocument) tEnv.getObjRelation("Document"));
43 shortWait();
44 oObj.addAdjustmentListener(listener);
45 adjustScrollBar();
47 boolean res = adjusted;
48 oObj.removeAdjustmentListener(listener);
49 adjusted = false;
50 adjustScrollBar();
51 res &= !adjusted;
52 tRes.tested("addAdjustmentListener()", res);
55 public void _removeAdjustmentListener() {
56 //this method is checked in addAjustmentListener
57 //so that method is requiered here and if it works
58 //this method is given OK too
59 requiredMethod("addAdjustmentListener()");
60 tRes.tested("removeAdjustmentListener()", true);
63 public void _setBlockIncrement() {
64 oObj.setBlockIncrement(15);
65 oObj.setBlockIncrement(5);
66 int bi = oObj.getBlockIncrement();
67 tRes.tested("setBlockIncrement()",bi==5);
70 public void _getBlockIncrement() {
71 //this method is checked in the corresponding set method
72 //so that method is requiered here and if it works
73 //this method is given OK too
74 requiredMethod("setBlockIncrement()");
75 tRes.tested("getBlockIncrement()", true);
78 public void _setLineIncrement() {
79 oObj.setLineIncrement(12);
80 oObj.setLineIncrement(2);
81 int li = oObj.getLineIncrement();
82 tRes.tested("setLineIncrement()",li==2);
85 public void _getLineIncrement() {
86 //this method is checked in the corresponding set method
87 //so that method is requiered here and if it works
88 //this method is given OK too
89 requiredMethod("setLineIncrement()");
90 tRes.tested("getLineIncrement()", true);
93 public void _setMaximum() {
94 oObj.setMaximum(490);
95 oObj.setMaximum(480);
96 int max = oObj.getMaximum();
97 tRes.tested("setMaximum()",max==480);
100 public void _getMaximum() {
101 //this method is checked in the corresponding set method
102 //so that method is requiered here and if it works
103 //this method is given OK too
104 requiredMethod("setMaximum()");
105 tRes.tested("getMaximum()", true);
108 public void _setOrientation() {
109 oObj.setOrientation(ScrollBarOrientation.HORIZONTAL);
110 oObj.setOrientation(ScrollBarOrientation.VERTICAL);
111 int ori = oObj.getOrientation();
112 tRes.tested("setOrientation()",ori==ScrollBarOrientation.VERTICAL);
115 public void _getOrientation() {
116 //this method is checked in the corresponding set method
117 //so that method is requiered here and if it works
118 //this method is given OK too
119 requiredMethod("setOrientation()");
120 tRes.tested("getOrientation()", true);
123 public void _setValue() {
124 oObj.setMaximum(600);
125 oObj.setValue(480);
126 oObj.setValue(520);
127 int val = oObj.getValue();
128 tRes.tested("setValue()",val==520);
131 public void _getValue() {
132 //this method is checked in the corresponding set method
133 //so that method is requiered here and if it works
134 //this method is given OK too
135 requiredMethod("setValue()");
136 tRes.tested("getValue()", true);
139 public void _setVisibleSize() {
140 oObj.setVisibleSize(700);
141 oObj.setVisibleSize(500);
142 int vs = oObj.getVisibleSize();
143 tRes.tested("setVisibleSize()",vs==500);
146 public void _getVisibleSize() {
147 //this method is checked in the corresponding set method
148 //so that method is requiered here and if it works
149 //this method is given OK too
150 requiredMethod("setVisibleSize()");
151 tRes.tested("getVisibleSize()", true);
154 public void _setValues() {
155 oObj.setValues(80, 200, 300);
156 oObj.setValues(70, 210, 500);
157 int val = oObj.getValue();
158 int vs = oObj.getVisibleSize();
159 int max = oObj.getMaximum();
160 tRes.tested("setValues()",((val==70) && (vs==210) && (max==500)));
163 private void adjustScrollBar() {
166 XScrollBar sc = UnoRuntime.queryInterface(
167 XScrollBar.class, tEnv.getTestObject());
169 sc.setValue(500);
171 shortWait();
173 XAccessible acc = UnoRuntime.queryInterface(
174 XAccessible.class, tEnv.getTestObject());
176 XAccessibleComponent aCom = UnoRuntime.queryInterface(
177 XAccessibleComponent.class,
178 acc.getAccessibleContext());
180 Point location = aCom.getLocationOnScreen();
181 //Point location = (Point) tEnv.getObjRelation("Location");
182 //XAccessibleComponent aCom = (XAccessibleComponent) tEnv.getObjRelation("Location");
183 //Point location = aCom.getLocationOnScreen();
184 try {
185 Robot rob = new Robot();
186 rob.mouseMove(location.X + 50, location.Y + 75);
187 rob.mousePress(InputEvent.BUTTON1_MASK);
188 rob.mouseRelease(InputEvent.BUTTON1_MASK);
189 } catch (java.awt.AWTException e) {
190 System.out.println("couldn't adjust scrollbar");
193 shortWait();
197 * Sleeps for 0.5 sec. to allow Office to react
199 private void shortWait() {
200 try {
201 Thread.sleep(500);
202 } catch (InterruptedException e) {
203 log.println("While waiting :" + e);
207 public class AdjustmentListener
208 implements com.sun.star.awt.XAdjustmentListener {
209 public void adjustmentValueChanged(com.sun.star.awt.AdjustmentEvent adjustmentEvent) {
210 System.out.println("Adjustment Value changed");
211 System.out.println("AdjustmentEvent: " + adjustmentEvent.Value);
212 adjusted = true;
215 public void disposing(com.sun.star.lang.EventObject eventObject) {
216 System.out.println("Listener disposed");