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' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9'
10' Copyright 2000, 2010 Oracle and/or its affiliates.
11'
12' OpenOffice.org - a multi-platform office productivity suite
13'
14' This file is part of OpenOffice.org.
15'
16' OpenOffice.org is free software: you can redistribute it and/or modify
17' it under the terms of the GNU Lesser General Public License version 3
18' only, as published by the Free Software Foundation.
19'
20' OpenOffice.org is distributed in the hope that it will be useful,
21' but WITHOUT ANY WARRANTY; without even the implied warranty of
22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23' GNU Lesser General Public License version 3 for more details
24' (a copy is included in the LICENSE file that accompanied this code).
25'
26' You should have received a copy of the GNU Lesser General Public License
27' version 3 along with OpenOffice.org.  If not, see
28' <http://www.openoffice.org/license.html>
29' for a copy of the LGPLv3 License.
30'
31'*************************************************************************
32*****
33'*************************************************************************
34
35
36
37' Be sure that all variables are dimensioned:
38option explicit
39
40'*************************************************************************
41' This Interface/Service test depends on the following GLOBAL variables,
42' which must be specified in the object creation:
43
44'	Global multiSelection As Boolean
45
46'*************************************************************************
47
48
49
50
51
52
53Sub RunTest()
54
55'*************************************************************************
56' INTERFACE:
57' com.sun.star.accessibility.XAccessibleSelection
58'*************************************************************************
59On Error Goto ErrHndl
60    Dim bOK As Boolean, locRes As Boolean
61    Dim chCount As Long, selCount As Long
62    Dim i As Long, mCount As Integer
63
64    if multiSelection then
65        Out.Log("Object allows multiple selection!")
66    else
67        Out.Log("Object does not allow multiple selection!")
68    End If
69
70    chCount = oObj.getAccessibleChildCount()
71    selCount = oObj.getSelectedAccessibleChildCount()
72    Out.Log("Object has "+chCount+" child(ren), "+selCount+" of them selected.")
73    If (chCount &gt; 50) then
74        mCount = 50
75        Out.Log("Object has too many children. Testing only first 50.")
76    else
77        mCount = chCount
78    End If
79
80    clearSelection()
81
82    Test.StartMethod("selectAccessibleChild()")
83    bOK = true
84    if (mCount &gt; 0) then
85        i = mCount - 1
86        while (oObj.isAccessibleChildSelected(i) OR itemDisabled(oObj.getAccessibleChild(i))) AND (i &gt; 0)
87            i = i - 1
88        wend
89        if (i &gt;= 0) then
90            Out.Log("Selecting child #"+i+"...")
91            oObj.selectAccessibleChild(i)
92            wait(500)
93            locRes = oObj.isAccessibleChildSelected(i)
94            Out.Log("Child #"+i+" selected: "+locRes)
95            bOK = bOK AND locRes
96        End If
97    End If
98    clearSelection()
99    Test.MethodTested("selectAccessibleChild()",bOK)
100
101    Test.StartMethod("isAccessibleChildSelected()")
102    bOK = true
103    if (mCount &gt; 0) then
104        i = mCount - 1
105        while (oObj.isAccessibleChildSelected(i) OR itemDisabled(oObj.getAccessibleChild(i))) AND (i &gt; 0)
106            i = i - 1
107        wend
108        if (i &gt;= 0) then
109            Out.Log("Selecting child #"+i+"...")
110            oObj.selectAccessibleChild(i)
111            wait(500)
112            locRes = oObj.isAccessibleChildSelected(i)
113            Out.Log("Child #"+i+" selected: "+locRes)
114            bOK = bOK AND locRes
115        End If
116    End If
117    clearSelection()
118    Test.MethodTested("isAccessibleChildSelected()",bOK)
119
120    Test.StartMethod("clearAccessibleSelection()")
121    bOK = true
122    if (mCount &gt; 0) AND (multiSelection) then
123        oObj.selectAccessibleChild(chCount - 1)
124        wait(500)
125        oObj.clearAccessibleSelection()
126        wait(500)
127        bOK = bOK AND NOT oObj.isAccessibleChildSelected(mCount - 1)
128    else
129        Out.Log("Cannot clear all selection for this object!")
130    End If
131    Test.MethodTested("clearAccessibleSelection()",bOK)
132
133' ### The following property was not found in correspond IDL file! ###
134    Test.StartMethod("selectAllAccessibleChildren()")
135    bOK = true
136    i = 0
137    if ((mCount &gt; 0) AND multiSelection) then
138' ### The following property was not found in correspond IDL file! ###
139        oObj.selectAllAccessibleChildren()
140        wait(500)
141        while (i &lt; mCount)
142            bOK = bOK AND oObj.isAccessibleChildSelected(i)
143            i = i + 1
144        wend
145    else
146        Out.Log("Cannot select all children for this object!")
147    End If
148    clearSelection()
149    Test.MethodTested("selectAllAccessibleChildren()",bOK)
150
151    Test.StartMethod("getSelectedAccessibleChildCount()")
152    bOK = true
153    Out.Log("Selecting all...")
154    oObj.selectAllAccessibleChildren()
155    wait(500)
156    selCount = oObj.getSelectedAccessibleChildCount()
157    Out.Log("Selected "+selCount+" child(ren).")
158    If (multiSelection) then
159        bOK = bOK AND (selCount = chCount)
160    else
161        bOK = bOK AND (selCount = 1)
162    End If
163    clearSelection()
164    selCount = oObj.getSelectedAccessibleChildCount()
165    if (multiSelection) then
166        bOK = bOK AND (selCount = 0)
167    else
168        bOK = bOK AND (selCount = 1)
169    End If
170    Test.MethodTested("getSelectedAccessibleChildCount()",bOK)
171
172    Test.StartMethod("getSelectedAccessibleChild()")
173    Dim selAccChild As Object, accChild As Object
174    bOK = true
175    if (mCount &gt; 0) then
176        i = mCount - 1
177        while (oObj.isAccessibleChildSelected(i) OR itemDisabled(oObj.getAccessibleChild(i))) AND (i &gt; 0)
178            i = i - 1
179        wend
180        if (i &gt;= 0) then
181            Out.Log("Selecting child #"+i+"...")
182            oObj.selectAccessibleChild(i)
183            wait(500)
184            Out.Log("Child #"+i+" selected: "+oObj.isAccessibleChildSelected(i))
185            Out.Log("Now "+oObj.getSelectedAccessibleChildCount()+" child(ren) selected.")
186            selCount = oObj.getSelectedAccessibleChildCount()
187            if (selCount &gt; 0) then
188                selAccChild = oObj.getSelectedAccessibleChild(selCount-1)
189                accChild = oObj.getAccessibleChild(i)
190                bOK = bOK AND utils.at_equals(accChild,selAccChild)
191            else
192                Out.Log("There are no selected children. Test fails.")
193                bOK = false
194            End If
195        End If
196    End If
197    Test.MethodTested("getSelectedAccessibleChild()",bOK)
198
199    Test.StartMethod("deselectAccessibleChild()")
200    Dim newSelCount As Long
201	Dim isSelected as Boolean
202    bOK = true
203	oObj.selectAllAccessibleChildren()
204	wait(500)
205    selCount = oObj.getSelectedAccessibleChildCount()
206    Out.Log("There was "+selCount+" selected child(ren)")
207    Out.Log("Deselecting child...")
208	for i = 0 to mCount - 1
209		if oObj.isAccessibleChildSelected(i) then
210			isSelected = true
211		end if
212        oObj.deselectAccessibleChild(i)
213        wait(500)
214        newSelCount = oObj.getSelectedAccessibleChildCount()
215		Out.Log("selCount = " + selCount + " newSelCount = " + newSelCount)
216        if (multiSelection) then
217			if isSelected then
218				Out.Log("isSelected")
219	            bOK = bOK AND (selCount - 1 = newSelCount)
220			else
221	            bOK = bOK AND (selCount = newSelCount)
222			end if
223        else
224			Out.Log("is not multi")
225            bOK = bOK AND (newSelCount &lt;= 1)
226        End If
227		selCount = newSelCount
228	next
229    Test.MethodTested("deselectAccessibleChild()",bOK)
230
231Exit Sub
232ErrHndl:
233    Test.Exception()
234    bOK = false
235    resume next
236End Sub
237
238Sub clearSelection()
239    if NOT multiSelection then Exit Sub
240    Dim selCount As Long
241    selCount = oObj.getSelectedAccessibleChildCount()
242    if (selCount = 0) then Exit Sub
243    oObj.clearAccessibleSelection()
244    wait(500)
245    selCount = oObj.getSelectedAccessibleChildCount()
246    if selCount = 0 then
247        Out.Log("Deselect all: success")
248    else
249        Out.Log("Deselect all: error!. "+selCount+" child(ren) remains selected.")
250    End If
251End Sub
252
253Function itemDisabled(oChild As Object) As Boolean
254    if NOT hasUNOInterfaces(oChild,"com.sun.star.accessibility.XAccessibleContext") then
255        oChild = oChild.getAccessibleContext()
256    End If
257    itemDisabled = NOT oChild.getAccessibleStateSet().contains(21)
258End Function
259
260</script:module>
261