summaryrefslogtreecommitdiff
path: root/qadevOOo/tests/java/ifc/accessibility/_XAccessibleValue.java
blob: 201d5675ff0c7ebe0feca056e10b29b7856bd501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

package ifc.accessibility;


import lib.MultiMethodTest;
import lib.Status;
import lib.StatusException;

import com.sun.star.accessibility.XAccessibleValue;

/**
 * Testing <code>com.sun.star.accessibility.XAccessibleValue</code>
 * interface methods :
 * <ul>
 *  <li><code> getCurrentValue()</code></li>
 *  <li><code> setCurrentValue()</code></li>
 *  <li><code> getMaximumValue()</code></li>
 *  <li><code> getMinimumValue()</code></li>
 * </ul> <p>
 *
 * This test needs the following object relations :
 * <ul>
 *  <li> <code>'XAccessibleValue.anotherFromGroup'</code>
 *  (of type <code>XAccessibleValue</code>) <b> optional </b>:
 *   another component from the group(e.g. radio button group)</li>
 *  </ul><p>
 * @see com.sun.star.accessibility.XAccessibleValue
 */
public class _XAccessibleValue extends MultiMethodTest {

    public XAccessibleValue oObj = null;

    private double minVal = 0;
    private double maxVal = 0;
    private double curVal = 0;
    private Object val = null;
    XAccessibleValue anotherFromGroup = null;

    protected void before() {
        anotherFromGroup = (XAccessibleValue)tEnv.getObjRelation(
            "XAccessibleValue.anotherFromGroup");
    }

    /**
     * Gets current value and stores it as double. <p>
     *
     * Has <b> OK </b> status if the current value is between Min and Max
     * values. <p>
     *
     * The following method tests are to be executed before :
     * <ul>
     *  <li> <code> getMaximumValue </code> </li>
     *  <li> <code> getMinimumValue </code> </li>
     * </ul>
     */
    public void _getCurrentValue() {
        executeMethod("getMaximumValue()");
        executeMethod("getMinimumValue()");

        boolean result = true;

        double curVal ;
        val = oObj.getCurrentValue() ;
        if (util.utils.isVoid(val)) {
            val = new Integer(0);
            curVal = 0;
        } else  {
            curVal = getDoubleValue(val);
        }

        if (curVal < minVal || maxVal < curVal) {
            log.println("" + (curVal - minVal) + "," + (maxVal - curVal));
            log.println("Current value " + curVal + " is not in range ["
                + minVal + "," + maxVal + "]");
            result = false;
        }

        tRes.tested("getCurrentValue()", result) ;
    }

    /**
     * Performs testing for following cases :
     * <ul>
     *  <li> Creates new value in valid range and sets it. </li>
     *  <li> Sets maximum and minimum values. </li>
     *  <li> Sets Min - 1, and Max + 1 values </li>
     * </ul> <p>
     *
     * Has <b> OK </b> status if for the first case the value returned
     * is the same as was set and the method <code>setCurrentValue</code>
     * returns <code>true</code>.
     *
     * In the second if Max and Min values are set and method
     * <code>setCurrentValue</code> returns <code>true</code>.
     *
     * In the third case invalid values are truncated to Min and Max
     * values accordingly. <p>
     *
     * The following method tests are to be executed before :
     * <ul>
     *  <li> <code> getCurrentValue() </code> </li>
     * </ul>
     */
    public void _setCurrentValue() {
        executeMethod("getCurrentValue()");

        boolean result = true ;
        boolean partResult=true;
        String noMax = "com.sun.star.comp.toolkit.AccessibleScrollBar";
        String implName = util.utils.getImplName(oObj);

        if (tEnv.getObjRelation("ValueNotPersitent")!=null) {
            log.println("Excluded since it works like AccessibleAction");
            tRes.tested("setCurrentValue()",Status.skipped(true));
            return;
        }

        if (anotherFromGroup == null) {
            double newVal = curVal + 1;
            if (newVal > maxVal) newVal -= 2;
            if (newVal < minVal) newVal += 1;

            log.println("New value is " + newVal);

            Object setVal = getObjectValue(newVal, val.getClass());

            result &= oObj.setCurrentValue(setVal);

            if (!result) {
                log.println("The value can't be set");
                throw new StatusException(Status.skipped(true));
            }

            double resVal = getDoubleValue(oObj.getCurrentValue());
            log.println("Res value is " + resVal);

            result &= Math.abs(newVal - resVal) < 0.00001;

            log.println("Checking min/max values");
            result &= oObj.setCurrentValue(getObjectValue(minVal, val.getClass()));
            log.println("Setting to "+ getObjectValue(minVal, val.getClass()));
            resVal = getDoubleValue(oObj.getCurrentValue());
            log.println("Result min value is " + resVal);
            result &= Math.abs(minVal - resVal) < 0.00001;
            log.println("\t works: "+(Math.abs(minVal - resVal) < 0.00001));

            result &= oObj.setCurrentValue(getObjectValue(maxVal, val.getClass()));
            log.println("Setting to "+ getObjectValue(maxVal, val.getClass()));
            resVal = getDoubleValue(oObj.getCurrentValue());
            log.println("Result max value is " + resVal);
            partResult = Math.abs(maxVal - resVal) < 0.00001;

            if (implName.equals(noMax)) {
                log.println("If one sets the maximum value of a scroll bar with XScrollBar::setMaximum(),"+
                "then XScrollBar::getValue() returns the maximum value minus the visible size of"+
                "the thumb");
                //using abitrary Value, since we can't determine the resulting value
                partResult = resVal > 10;
            }

            result &=partResult;
            log.println("\t works: "+partResult);

            log.println("Checking truncating of min/max values");
            oObj.setCurrentValue(getObjectValue(minVal - 1, val.getClass()));
            log.println("Setting to "+ getObjectValue(minVal -1 , val.getClass()));
            resVal = getDoubleValue(oObj.getCurrentValue());
            log.println("Result min value is " + resVal);
            result &= Math.abs(minVal - resVal) < 0.00001;
            log.println("\t works: "+(Math.abs(minVal - resVal) < 0.00001));

            oObj.setCurrentValue(getObjectValue(maxVal + 1, val.getClass()));
            log.println("Setting to "+ getObjectValue(maxVal +1 , val.getClass()));
            resVal = getDoubleValue(oObj.getCurrentValue());
            log.println("Result max value is " + resVal);
            partResult = Math.abs(maxVal - resVal) < 0.00001;
            if (implName.equals(noMax)) {
                log.println("If one sets the maximum value of a scroll bar with XScrollBar::setMaximum(),"+
                "then XScrollBar::getValue() returns the maximum value minus the visible size of"+
                "the thumb");
                //using abitrary Value, since we can't determine the resulting value
                partResult = resVal > 10;
            }

            result &=partResult;
            log.println("\t works: "+partResult);
        } else {
            int curValBase = getIntegerValue(val);
            Object valAnotherFromGroup = anotherFromGroup.getCurrentValue();
            int curValAnother = getIntegerValue(valAnotherFromGroup);
            log.println("Current value of base component: " + curValBase);
            log.println("Current value of another component from group: " +
                curValAnother);
            log.println("Set value of base component to " + curValAnother);
            if (tEnv.getTestCase().getObjectName().equals("AccessibleRadioButton")) {
                anotherFromGroup.setCurrentValue(new Integer(curValBase));
            } else {
                oObj.setCurrentValue(valAnotherFromGroup);
            }
            log.println("Checking of values...");
            int newValBase = getIntegerValue(oObj.getCurrentValue());
            int newValAnother = getIntegerValue(
                anotherFromGroup.getCurrentValue());
            log.println("New value of base component: " + newValBase);
            log.println("Expected value of base component: " + curValAnother);
            log.println("New value of another component from group: " +
                newValAnother);
            log.println("Expected value of another component from group: " +
                curValBase);

            result = (newValBase == curValAnother) &&
                (newValAnother == curValBase);
        }

        tRes.tested("setCurrentValue()", result);
    }

    /**
     * Gets and stores maximal value. <p>
     *
     * Has <b> OK </b> status if non empty value returned and
     * Max value is greater than Min value.
     *
     * The following method tests are to be completed successfully before :
     * <ul>
     *  <li> <code> getMinimumValue() </code> : to compare with </li>
     * </ul>
     */
    public void _getMaximumValue() {
        requiredMethod("getMinimumValue()");

        boolean result = true ;

        Object val = oObj.getMaximumValue();
        if (util.utils.isVoid(val)) {
            maxVal = Double.MAX_VALUE ;
            result = false;
        } else {
            maxVal = getDoubleValue(val);
        }
        log.println("Max is " + val.getClass()+ " = " + maxVal);

        result &= maxVal >= minVal;

        tRes.tested("getMaximumValue()", result) ;
    }

    /**
     * Gets and stores minimal value. <p>
     *
     * Has <b> OK </b> status if non empty value returned. <p>
     *
     */
    public void _getMinimumValue() {
        boolean result = true ;

        Object val = oObj.getMinimumValue() ;
        if (util.utils.isVoid(val)) {
            minVal = - Double.MAX_VALUE ;
            result = false;
        } else {
            minVal = getDoubleValue(val);
        }
        log.println("Min is " + val.getClass()+ " = " + minVal);

        tRes.tested("getMinimumValue()", result) ;
    }

    private int getIntegerValue(Object val) {
        if (val instanceof Integer) {
            return ((Integer) val).intValue();
        } else {
            throw new StatusException
                (Status.failed("Unexpected value type: " + val.getClass()));
        }
    }

    private double getDoubleValue(Object val) {
        if (val instanceof Integer) {
            return ((Integer) val).doubleValue();
        }
        else if (val instanceof Short) {
            return ((Short) val).doubleValue();
        }
        else if (val instanceof Float) {
            return ((Float) val).doubleValue();
        }
        else if (val instanceof Double) {
            return ((Double) val).doubleValue();
        }
        else if (util.utils.isVoid(val)) {
            return Double.NaN;
        }
        else {
            throw new StatusException
                (Status.failed("Undetected value type: " + val.getClass()));
        }
    }

    private Object getObjectValue(double val, Class clazz) {
        if (clazz.equals(Integer.class)) {
            return new Integer((int)val);
        }
        else if (clazz.equals(Short.class)) {
            return new Short((short)val);
        }
        else if (clazz.equals(Float.class)) {
            return new Float((float)val);
        }
        else if (clazz.equals(Double.class)) {
            return new Double(val);
        }
        else {
            throw new StatusException
                (Status.failed("Unexpected class: " + clazz));
        }
    }

    /**
     * Disposes test environment.
     */
    protected void after() {
        disposeEnvironment();
    }
}