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_XAccessibleText" 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 accText as String
39'   Global readOnly as Boolean
40
41'*************************************************************************
42
43Sub RunTest()
44
45'*************************************************************************
46' INTERFACE:
47' com.sun.star.accessibility.XAccessibleText
48'*************************************************************************
49On Error Goto ErrHndl
50    Dim bOK As Boolean
51    Dim chCount As Integer
52    Dim accTextSegment as new com.sun.star.accessibility.TextSegment
53
54    Test.StartMethod("getCharacterCount()")
55    bOK = true
56    chCount = oObj.getCharacterCount()
57    Out.Log("Character count: "+chCount)
58    bOK = bOK AND (len(accText) = chCount)
59    Test.MethodTested("getCharacterCount()",bOK)
60
61    Test.StartMethod("getCaretPosition()")
62    Test.StartMethod("setCaretPosition()")
63    bOK = true
64    Dim carPos As Integer
65    oObj.setCaretPosition(chCount - 1)
66    carPos = oObj.getCaretPosition()
67    if not readOnly then
68        Out.Log("getCaretPosition: " + carPos)
69        bOK = bOK AND (carPos = chCount - 1)
70    else
71        Out.Log("Object is read only and Caret position couldn't be set")
72    end if
73    Test.MethodTested("getCaretPosition()",bOK)
74    Test.MethodTested("setCaretPosition()",bOK)
75
76    Test.StartMethod("getCharacter()")
77    Dim i As Integer
78    bOK = true
79    for i = 0 to chCount-1
80        bOK = bOK AND (chr(oObj.getCharacter(i)) = _
81                                                utils.getCharacter(i+1,accText))
82    next i
83    Test.MethodTested("getCharacter()",bOK)
84
85    Test.StartMethod("getCharacterAttributes()")
86    Dim attrs() As Variant
87    Dim ReqAttrs(0) as String
88    bOK = true
89    attrs = oObj.getCharacterAttributes(chCount - 1, ReqAttrs())
90    bOK = bOK AND NOT isNull(attrs)
91    Out.Log("Properties ubound: "+ubound(attrs))
92    Test.MethodTested("getCharacterAttributes()",bOK)
93
94    Test.StartMethod("getCharacterBounds()")
95    Dim chBounds As new com.sun.star.awt.Rectangle
96    bOK = true
97    chBounds = oObj.getCharacterBounds(chCount - 1)
98    Out.Log("Character boundbox: "+chBounds.X+", "+chBounds.Y+", "+ _
99    chBounds.Width+", "+chBounds.Height)
100    bOK = bOK AND NOT isNull(chBounds)
101    Test.MethodTested("getCharacterBounds()",bOK)
102
103    Test.StartMethod("getIndexAtPoint()")
104    Dim index As Integer
105    Dim point As new com.sun.star.awt.Point
106    bOK = true
107    point.X = chBounds.X + 1
108    point.Y = chBounds.Y + 1
109    index = oObj.getIndexAtPoint(point)
110    bOK = bOK AND (index = chCount -1)
111    Test.MethodTested("getIndexAtPoint()",bOK)
112
113    Test.StartMethod("getSelectedText()")
114    bOK = true
115    oObj.setSelection(0, chCount)
116    if not readOnly then
117        bOK = bOK AND (accText = oObj.getSelectedText())
118    else
119        Out.Log("Object is unselectable")
120    end if
121    Test.MethodTested("getSelectedText()",bOK)
122
123    Test.StartMethod("getSelectionStart()")
124    bOK = true
125    oObj.setSelection(chCount-1,chCount)
126    if not readOnly then
127        bOK = bOK AND (oObj.getSelectionStart() = chCount -1)
128    else
129        Out.Log("Object is unselectable")
130    end if
131    Test.MethodTested("getSelectionStart()",bOK)
132
133    Test.StartMethod("getSelectionEnd()")
134    bOK = true
135    oObj.setSelection(0,chCount - 1)
136    if not readOnly then
137        bOK = bOK AND (oObj.getSelectionEnd() = chCount - 1)
138    else
139        Out.Log("Object is unselectable")
140    end if
141    Test.MethodTested("getSelectionEnd()",bOK)
142
143    Test.StartMethod("setSelection()")
144    bOK = true
145    if not readOnly then
146        bOK = bOK AND oObj.setSelection(0,chCount)
147    else
148        Out.Log("Object is unselectable")
149    end if
150    Test.MethodTested("setSelection()",bOK)
151
152    Test.StartMethod("getText()")
153    bOK = true
154    bOK = bOK AND (accText = oObj.getText())
155    Test.MethodTested("getText()",bOK)
156
157    Test.StartMethod("getTextRange()")
158    bOK = true
159    bOK = bOK AND (accText = oObj.getTextRange(0,chCount))
160    Test.MethodTested("getTextRange()",bOK)
161
162    Test.StartMethod("getTextAtIndex()")
163    bOK = true
164    accTextSegment = oObj.getTextAtIndex(chCount - 1, 4)
165    bOK = bOK AND (accText = accTextSegment.SegmentText)
166    Test.MethodTested("getTextAtIndex()",bOK)
167
168    Test.StartMethod("getTextBeforeIndex()")
169    bOK = true
170    accTextSegment = oObj.getTextBeforeIndex(1, 1)
171    bOK = bOK AND (accTextSegment.SegmentText = utils.getCharacter(1,accText))
172    Test.MethodTested("getTextBeforeIndex()",bOK)
173
174    Test.StartMethod("getTextBehindIndex()")
175    bOK = true
176    accTextSegment = oObj.getTextBehindIndex(chCount-2,1)
177    bOK = bOK AND (accTextSegment.SegmentText = utils.getCharacter(chCount,accText))
178    Test.MethodTested("getTextBehindIndex()",bOK)
179
180    Test.StartMethod("copyText()")
181    bOK = true
182    bOK = bOK AND oObj.copyText(0,chCount)
183    if readOnly then bOK = true
184    Test.MethodTested("copyText()",bOK)
185
186Exit Sub
187ErrHndl:
188    Test.Exception()
189    bOK = false
190    resume next
191End Sub
192</script:module>
193