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' Be sure that all variables are dimensioned:
37option explicit
38
39'*************************************************************************
40' This Interface/Service test depends on the following GLOBAL variables,
41' which must be specified in the object creation:
42
43'	Global multiSelection As Boolean
44
45'*************************************************************************
46
47
48
49
50
51
52Sub RunTest()
53
54'*************************************************************************
55' INTERFACE:
56' com.sun.star.accessibility.XAccessibleSelection
57'*************************************************************************
58On Error Goto ErrHndl
59    Dim bOK As Boolean, locRes As Boolean
60    Dim chCount As Long, selCount As Long
61    Dim i As Long, mCount As Integer
62
63    if multiSelection then
64        Out.Log("Object allows multiple selection!")
65    else
66        Out.Log("Object does not allow multiple selection!")
67    End If
68
69    chCount = oObj.getAccessibleChildCount()
70    selCount = oObj.getSelectedAccessibleChildCount()
71    Out.Log("Object has "+chCount+" child(ren), "+selCount+" of them selected.")
72    If (chCount &gt; 50) then
73        mCount = 50
74        Out.Log("Object has too many children. Testing only first 50.")
75    else
76        mCount = chCount
77    End If
78
79    clearSelection()
80
81    Test.StartMethod("selectAccessibleChild()")
82    bOK = true
83    if (mCount &gt; 0) then
84        i = mCount - 1
85        while (oObj.isAccessibleChildSelected(i) OR itemDisabled(oObj.getAccessibleChild(i))) AND (i &gt; 0)
86            i = i - 1
87        wend
88        if (i &gt;= 0) then
89            Out.Log("Selecting child #"+i+"...")
90            oObj.selectAccessibleChild(i)
91            wait(500)
92            locRes = oObj.isAccessibleChildSelected(i)
93            Out.Log("Child #"+i+" selected: "+locRes)
94            bOK = bOK AND locRes
95        End If
96    End If
97    clearSelection()
98    Test.MethodTested("selectAccessibleChild()",bOK)
99
100    Test.StartMethod("isAccessibleChildSelected()")
101    bOK = true
102    if (mCount &gt; 0) then
103        i = mCount - 1
104        while (oObj.isAccessibleChildSelected(i) OR itemDisabled(oObj.getAccessibleChild(i))) AND (i &gt; 0)
105            i = i - 1
106        wend
107        if (i &gt;= 0) then
108            Out.Log("Selecting child #"+i+"...")
109            oObj.selectAccessibleChild(i)
110            wait(500)
111            locRes = oObj.isAccessibleChildSelected(i)
112            Out.Log("Child #"+i+" selected: "+locRes)
113            bOK = bOK AND locRes
114        End If
115    End If
116    clearSelection()
117    Test.MethodTested("isAccessibleChildSelected()",bOK)
118
119    Test.StartMethod("clearAccessibleSelection()")
120    bOK = true
121    if (mCount &gt; 0) AND (multiSelection) then
122        oObj.selectAccessibleChild(chCount - 1)
123        wait(500)
124        oObj.clearAccessibleSelection()
125        wait(500)
126        bOK = bOK AND NOT oObj.isAccessibleChildSelected(mCount - 1)
127    else
128        Out.Log("Cannot clear all selection for this object!")
129    End If
130    Test.MethodTested("clearAccessibleSelection()",bOK)
131
132' ### The following property was not found in correspond IDL file! ###
133    Test.StartMethod("selectAllAccessibleChildren()")
134    bOK = true
135    i = 0
136    if ((mCount &gt; 0) AND multiSelection) then
137' ### The following property was not found in correspond IDL file! ###
138        oObj.selectAllAccessibleChildren()
139        wait(500)
140        while (i &lt; mCount)
141            bOK = bOK AND oObj.isAccessibleChildSelected(i)
142            i = i + 1
143        wend
144    else
145        Out.Log("Cannot select all children for this object!")
146    End If
147    clearSelection()
148    Test.MethodTested("selectAllAccessibleChildren()",bOK)
149
150    Test.StartMethod("getSelectedAccessibleChildCount()")
151    bOK = true
152    Out.Log("Selecting all...")
153    oObj.selectAllAccessibleChildren()
154    wait(500)
155    selCount = oObj.getSelectedAccessibleChildCount()
156    Out.Log("Selected "+selCount+" child(ren).")
157    If (multiSelection) then
158        bOK = bOK AND (selCount = chCount)
159    else
160        bOK = bOK AND (selCount = 1)
161    End If
162    clearSelection()
163    selCount = oObj.getSelectedAccessibleChildCount()
164    if (multiSelection) then
165        bOK = bOK AND (selCount = 0)
166    else
167        bOK = bOK AND (selCount = 1)
168    End If
169    Test.MethodTested("getSelectedAccessibleChildCount()",bOK)
170
171    Test.StartMethod("getSelectedAccessibleChild()")
172    Dim selAccChild As Object, accChild As Object
173    bOK = true
174    if (mCount &gt; 0) then
175        i = mCount - 1
176        while (oObj.isAccessibleChildSelected(i) OR itemDisabled(oObj.getAccessibleChild(i))) AND (i &gt; 0)
177            i = i - 1
178        wend
179        if (i &gt;= 0) then
180            Out.Log("Selecting child #"+i+"...")
181            oObj.selectAccessibleChild(i)
182            wait(500)
183            Out.Log("Child #"+i+" selected: "+oObj.isAccessibleChildSelected(i))
184            Out.Log("Now "+oObj.getSelectedAccessibleChildCount()+" child(ren) selected.")
185            selCount = oObj.getSelectedAccessibleChildCount()
186            if (selCount &gt; 0) then
187                selAccChild = oObj.getSelectedAccessibleChild(selCount-1)
188                accChild = oObj.getAccessibleChild(i)
189                bOK = bOK AND utils.at_equals(accChild,selAccChild)
190            else
191                Out.Log("There are no selected children. Test fails.")
192                bOK = false
193            End If
194        End If
195    End If
196    Test.MethodTested("getSelectedAccessibleChild()",bOK)
197
198    Test.StartMethod("deselectAccessibleChild()")
199    Dim newSelCount As Long
200	Dim isSelected as Boolean
201    bOK = true
202	oObj.selectAllAccessibleChildren()
203	wait(500)
204    selCount = oObj.getSelectedAccessibleChildCount()
205    Out.Log("There was "+selCount+" selected child(ren)")
206    Out.Log("Deselecting child...")
207	for i = 0 to mCount - 1
208		if oObj.isAccessibleChildSelected(i) then
209			isSelected = true
210		end if
211        oObj.deselectAccessibleChild(i)
212        wait(500)
213        newSelCount = oObj.getSelectedAccessibleChildCount()
214		Out.Log("selCount = " + selCount + " newSelCount = " + newSelCount)
215        if (multiSelection) then
216			if isSelected then
217				Out.Log("isSelected")
218	            bOK = bOK AND (selCount - 1 = newSelCount)
219			else
220	            bOK = bOK AND (selCount = newSelCount)
221			end if
222        else
223			Out.Log("is not multi")
224            bOK = bOK AND (newSelCount &lt;= 1)
225        End If
226		selCount = newSelCount
227	next
228    Test.MethodTested("deselectAccessibleChild()",bOK)
229
230Exit Sub
231ErrHndl:
232    Test.Exception()
233    bOK = false
234    resume next
235End Sub
236
237Sub clearSelection()
238    if NOT multiSelection then Exit Sub
239    Dim selCount As Long
240    selCount = oObj.getSelectedAccessibleChildCount()
241    if (selCount = 0) then Exit Sub
242    oObj.clearAccessibleSelection()
243    wait(500)
244    selCount = oObj.getSelectedAccessibleChildCount()
245    if selCount = 0 then
246        Out.Log("Deselect all: success")
247    else
248        Out.Log("Deselect all: error!. "+selCount+" child(ren) remains selected.")
249    End If
250End Sub
251
252Function itemDisabled(oChild As Object) As Boolean
253    if NOT hasUNOInterfaces(oChild,"com.sun.star.accessibility.XAccessibleContext") then
254        oChild = oChild.getAccessibleContext()
255    End If
256    itemDisabled = NOT oChild.getAccessibleStateSet().contains(21)
257End Function
258
259</script:module>
260