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