1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="accessibility_XAccessibleSelection" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31' Be sure that all variables are dimensioned:
32option explicit
33
34'*************************************************************************
35' This Interface/Service test depends on the following GLOBAL variables,
36' which must be specified in the object creation:
37
38'	Global multiSelection As Boolean
39
40'*************************************************************************
41
42
43
44
45
46
47Sub RunTest()
48
49'*************************************************************************
50' INTERFACE:
51' com.sun.star.accessibility.XAccessibleSelection
52'*************************************************************************
53On Error Goto ErrHndl
54    Dim bOK As Boolean, locRes As Boolean
55    Dim chCount As Long, selCount As Long
56    Dim i As Long, mCount As Integer
57
58    if multiSelection then
59        Out.Log("Object allows multiple selection!")
60    else
61        Out.Log("Object does not allow multiple selection!")
62    End If
63
64    chCount = oObj.getAccessibleChildCount()
65    selCount = oObj.getSelectedAccessibleChildCount()
66    Out.Log("Object has "+chCount+" child(ren), "+selCount+" of them selected.")
67    If (chCount &gt; 50) then
68        mCount = 50
69        Out.Log("Object has too many children. Testing only first 50.")
70    else
71        mCount = chCount
72    End If
73
74    clearSelection()
75
76    Test.StartMethod("selectAccessibleChild()")
77    bOK = true
78    if (mCount &gt; 0) then
79        i = mCount - 1
80        while (oObj.isAccessibleChildSelected(i) OR itemDisabled(oObj.getAccessibleChild(i))) AND (i &gt; 0)
81            i = i - 1
82        wend
83        if (i &gt;= 0) then
84            Out.Log("Selecting child #"+i+"...")
85            oObj.selectAccessibleChild(i)
86            wait(500)
87            locRes = oObj.isAccessibleChildSelected(i)
88            Out.Log("Child #"+i+" selected: "+locRes)
89            bOK = bOK AND locRes
90        End If
91    End If
92    clearSelection()
93    Test.MethodTested("selectAccessibleChild()",bOK)
94
95    Test.StartMethod("isAccessibleChildSelected()")
96    bOK = true
97    if (mCount &gt; 0) then
98        i = mCount - 1
99        while (oObj.isAccessibleChildSelected(i) OR itemDisabled(oObj.getAccessibleChild(i))) AND (i &gt; 0)
100            i = i - 1
101        wend
102        if (i &gt;= 0) then
103            Out.Log("Selecting child #"+i+"...")
104            oObj.selectAccessibleChild(i)
105            wait(500)
106            locRes = oObj.isAccessibleChildSelected(i)
107            Out.Log("Child #"+i+" selected: "+locRes)
108            bOK = bOK AND locRes
109        End If
110    End If
111    clearSelection()
112    Test.MethodTested("isAccessibleChildSelected()",bOK)
113
114    Test.StartMethod("clearAccessibleSelection()")
115    bOK = true
116    if (mCount &gt; 0) AND (multiSelection) then
117        oObj.selectAccessibleChild(chCount - 1)
118        wait(500)
119        oObj.clearAccessibleSelection()
120        wait(500)
121        bOK = bOK AND NOT oObj.isAccessibleChildSelected(mCount - 1)
122    else
123        Out.Log("Cannot clear all selection for this object!")
124    End If
125    Test.MethodTested("clearAccessibleSelection()",bOK)
126
127' ### The following property was not found in correspond IDL file! ###
128    Test.StartMethod("selectAllAccessibleChildren()")
129    bOK = true
130    i = 0
131    if ((mCount &gt; 0) AND multiSelection) then
132' ### The following property was not found in correspond IDL file! ###
133        oObj.selectAllAccessibleChildren()
134        wait(500)
135        while (i &lt; mCount)
136            bOK = bOK AND oObj.isAccessibleChildSelected(i)
137            i = i + 1
138        wend
139    else
140        Out.Log("Cannot select all children for this object!")
141    End If
142    clearSelection()
143    Test.MethodTested("selectAllAccessibleChildren()",bOK)
144
145    Test.StartMethod("getSelectedAccessibleChildCount()")
146    bOK = true
147    Out.Log("Selecting all...")
148    oObj.selectAllAccessibleChildren()
149    wait(500)
150    selCount = oObj.getSelectedAccessibleChildCount()
151    Out.Log("Selected "+selCount+" child(ren).")
152    If (multiSelection) then
153        bOK = bOK AND (selCount = chCount)
154    else
155        bOK = bOK AND (selCount = 1)
156    End If
157    clearSelection()
158    selCount = oObj.getSelectedAccessibleChildCount()
159    if (multiSelection) then
160        bOK = bOK AND (selCount = 0)
161    else
162        bOK = bOK AND (selCount = 1)
163    End If
164    Test.MethodTested("getSelectedAccessibleChildCount()",bOK)
165
166    Test.StartMethod("getSelectedAccessibleChild()")
167    Dim selAccChild As Object, accChild As Object
168    bOK = true
169    if (mCount &gt; 0) then
170        i = mCount - 1
171        while (oObj.isAccessibleChildSelected(i) OR itemDisabled(oObj.getAccessibleChild(i))) AND (i &gt; 0)
172            i = i - 1
173        wend
174        if (i &gt;= 0) then
175            Out.Log("Selecting child #"+i+"...")
176            oObj.selectAccessibleChild(i)
177            wait(500)
178            Out.Log("Child #"+i+" selected: "+oObj.isAccessibleChildSelected(i))
179            Out.Log("Now "+oObj.getSelectedAccessibleChildCount()+" child(ren) selected.")
180            selCount = oObj.getSelectedAccessibleChildCount()
181            if (selCount &gt; 0) then
182                selAccChild = oObj.getSelectedAccessibleChild(selCount-1)
183                accChild = oObj.getAccessibleChild(i)
184                bOK = bOK AND utils.at_equals(accChild,selAccChild)
185            else
186                Out.Log("There are no selected children. Test fails.")
187                bOK = false
188            End If
189        End If
190    End If
191    Test.MethodTested("getSelectedAccessibleChild()",bOK)
192
193    Test.StartMethod("deselectAccessibleChild()")
194    Dim newSelCount As Long
195	Dim isSelected as Boolean
196    bOK = true
197	oObj.selectAllAccessibleChildren()
198	wait(500)
199    selCount = oObj.getSelectedAccessibleChildCount()
200    Out.Log("There was "+selCount+" selected child(ren)")
201    Out.Log("Deselecting child...")
202	for i = 0 to mCount - 1
203		if oObj.isAccessibleChildSelected(i) then
204			isSelected = true
205		end if
206        oObj.deselectAccessibleChild(i)
207        wait(500)
208        newSelCount = oObj.getSelectedAccessibleChildCount()
209		Out.Log("selCount = " + selCount + " newSelCount = " + newSelCount)
210        if (multiSelection) then
211			if isSelected then
212				Out.Log("isSelected")
213	            bOK = bOK AND (selCount - 1 = newSelCount)
214			else
215	            bOK = bOK AND (selCount = newSelCount)
216			end if
217        else
218			Out.Log("is not multi")
219            bOK = bOK AND (newSelCount &lt;= 1)
220        End If
221		selCount = newSelCount
222	next
223    Test.MethodTested("deselectAccessibleChild()",bOK)
224
225Exit Sub
226ErrHndl:
227    Test.Exception()
228    bOK = false
229    resume next
230End Sub
231
232Sub clearSelection()
233    if NOT multiSelection then Exit Sub
234    Dim selCount As Long
235    selCount = oObj.getSelectedAccessibleChildCount()
236    if (selCount = 0) then Exit Sub
237    oObj.clearAccessibleSelection()
238    wait(500)
239    selCount = oObj.getSelectedAccessibleChildCount()
240    if selCount = 0 then
241        Out.Log("Deselect all: success")
242    else
243        Out.Log("Deselect all: error!. "+selCount+" child(ren) remains selected.")
244    End If
245End Sub
246
247Function itemDisabled(oChild As Object) As Boolean
248    if NOT hasUNOInterfaces(oChild,"com.sun.star.accessibility.XAccessibleContext") then
249        oChild = oChild.getAccessibleContext()
250    End If
251    itemDisabled = NOT oChild.getAccessibleStateSet().contains(21)
252End Function
253
254</script:module>
255