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