1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="accessibility_XAccessibleText" script:language="StarBasic"> 4*cdf0e10cSrcweir 5*cdf0e10cSrcweir 6*cdf0e10cSrcweir'************************************************************************* 7*cdf0e10cSrcweir' 8*cdf0e10cSrcweir' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9*cdf0e10cSrcweir' 10*cdf0e10cSrcweir' Copyright 2000, 2010 Oracle and/or its affiliates. 11*cdf0e10cSrcweir' 12*cdf0e10cSrcweir' OpenOffice.org - a multi-platform office productivity suite 13*cdf0e10cSrcweir' 14*cdf0e10cSrcweir' This file is part of OpenOffice.org. 15*cdf0e10cSrcweir' 16*cdf0e10cSrcweir' OpenOffice.org is free software: you can redistribute it and/or modify 17*cdf0e10cSrcweir' it under the terms of the GNU Lesser General Public License version 3 18*cdf0e10cSrcweir' only, as published by the Free Software Foundation. 19*cdf0e10cSrcweir' 20*cdf0e10cSrcweir' OpenOffice.org is distributed in the hope that it will be useful, 21*cdf0e10cSrcweir' but WITHOUT ANY WARRANTY; without even the implied warranty of 22*cdf0e10cSrcweir' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23*cdf0e10cSrcweir' GNU Lesser General Public License version 3 for more details 24*cdf0e10cSrcweir' (a copy is included in the LICENSE file that accompanied this code). 25*cdf0e10cSrcweir' 26*cdf0e10cSrcweir' You should have received a copy of the GNU Lesser General Public License 27*cdf0e10cSrcweir' version 3 along with OpenOffice.org. If not, see 28*cdf0e10cSrcweir' <http://www.openoffice.org/license.html> 29*cdf0e10cSrcweir' for a copy of the LGPLv3 License. 30*cdf0e10cSrcweir' 31*cdf0e10cSrcweir'************************************************************************* 32*cdf0e10cSrcweir'************************************************************************* 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir' Be sure that all variables are dimensioned: 37*cdf0e10cSrcweiroption explicit 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir'************************************************************************* 40*cdf0e10cSrcweir' This Interface/Service test depends on the following GLOBAL variables, 41*cdf0e10cSrcweir' which must be specified in the object creation: 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir' Global accText as String 44*cdf0e10cSrcweir' Global readOnly as Boolean 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir'************************************************************************* 47*cdf0e10cSrcweir 48*cdf0e10cSrcweirSub RunTest() 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir'************************************************************************* 51*cdf0e10cSrcweir' INTERFACE: 52*cdf0e10cSrcweir' com.sun.star.accessibility.XAccessibleText 53*cdf0e10cSrcweir'************************************************************************* 54*cdf0e10cSrcweirOn Error Goto ErrHndl 55*cdf0e10cSrcweir Dim bOK As Boolean 56*cdf0e10cSrcweir Dim chCount As Integer 57*cdf0e10cSrcweir Dim accTextSegment as new com.sun.star.accessibility.TextSegment 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir Test.StartMethod("getCharacterCount()") 60*cdf0e10cSrcweir bOK = true 61*cdf0e10cSrcweir chCount = oObj.getCharacterCount() 62*cdf0e10cSrcweir Out.Log("Character count: "+chCount) 63*cdf0e10cSrcweir bOK = bOK AND (len(accText) = chCount) 64*cdf0e10cSrcweir Test.MethodTested("getCharacterCount()",bOK) 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir Test.StartMethod("getCaretPosition()") 67*cdf0e10cSrcweir Test.StartMethod("setCaretPosition()") 68*cdf0e10cSrcweir bOK = true 69*cdf0e10cSrcweir Dim carPos As Integer 70*cdf0e10cSrcweir oObj.setCaretPosition(chCount - 1) 71*cdf0e10cSrcweir carPos = oObj.getCaretPosition() 72*cdf0e10cSrcweir if not readOnly then 73*cdf0e10cSrcweir Out.Log("getCaretPosition: " + carPos) 74*cdf0e10cSrcweir bOK = bOK AND (carPos = chCount - 1) 75*cdf0e10cSrcweir else 76*cdf0e10cSrcweir Out.Log("Object is read only and Caret position couldn't be set") 77*cdf0e10cSrcweir end if 78*cdf0e10cSrcweir Test.MethodTested("getCaretPosition()",bOK) 79*cdf0e10cSrcweir Test.MethodTested("setCaretPosition()",bOK) 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir Test.StartMethod("getCharacter()") 82*cdf0e10cSrcweir Dim i As Integer 83*cdf0e10cSrcweir bOK = true 84*cdf0e10cSrcweir for i = 0 to chCount-1 85*cdf0e10cSrcweir bOK = bOK AND (chr(oObj.getCharacter(i)) = _ 86*cdf0e10cSrcweir utils.getCharacter(i+1,accText)) 87*cdf0e10cSrcweir next i 88*cdf0e10cSrcweir Test.MethodTested("getCharacter()",bOK) 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir Test.StartMethod("getCharacterAttributes()") 91*cdf0e10cSrcweir Dim attrs() As Variant 92*cdf0e10cSrcweir Dim ReqAttrs(0) as String 93*cdf0e10cSrcweir bOK = true 94*cdf0e10cSrcweir attrs = oObj.getCharacterAttributes(chCount - 1, ReqAttrs()) 95*cdf0e10cSrcweir bOK = bOK AND NOT isNull(attrs) 96*cdf0e10cSrcweir Out.Log("Properties ubound: "+ubound(attrs)) 97*cdf0e10cSrcweir Test.MethodTested("getCharacterAttributes()",bOK) 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir Test.StartMethod("getCharacterBounds()") 100*cdf0e10cSrcweir Dim chBounds As new com.sun.star.awt.Rectangle 101*cdf0e10cSrcweir bOK = true 102*cdf0e10cSrcweir chBounds = oObj.getCharacterBounds(chCount - 1) 103*cdf0e10cSrcweir Out.Log("Character boundbox: "+chBounds.X+", "+chBounds.Y+", "+ _ 104*cdf0e10cSrcweir chBounds.Width+", "+chBounds.Height) 105*cdf0e10cSrcweir bOK = bOK AND NOT isNull(chBounds) 106*cdf0e10cSrcweir Test.MethodTested("getCharacterBounds()",bOK) 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir Test.StartMethod("getIndexAtPoint()") 109*cdf0e10cSrcweir Dim index As Integer 110*cdf0e10cSrcweir Dim point As new com.sun.star.awt.Point 111*cdf0e10cSrcweir bOK = true 112*cdf0e10cSrcweir point.X = chBounds.X + 1 113*cdf0e10cSrcweir point.Y = chBounds.Y + 1 114*cdf0e10cSrcweir index = oObj.getIndexAtPoint(point) 115*cdf0e10cSrcweir bOK = bOK AND (index = chCount -1) 116*cdf0e10cSrcweir Test.MethodTested("getIndexAtPoint()",bOK) 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir Test.StartMethod("getSelectedText()") 119*cdf0e10cSrcweir bOK = true 120*cdf0e10cSrcweir oObj.setSelection(0, chCount) 121*cdf0e10cSrcweir if not readOnly then 122*cdf0e10cSrcweir bOK = bOK AND (accText = oObj.getSelectedText()) 123*cdf0e10cSrcweir else 124*cdf0e10cSrcweir Out.Log("Object is unselectable") 125*cdf0e10cSrcweir end if 126*cdf0e10cSrcweir Test.MethodTested("getSelectedText()",bOK) 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir Test.StartMethod("getSelectionStart()") 129*cdf0e10cSrcweir bOK = true 130*cdf0e10cSrcweir oObj.setSelection(chCount-1,chCount) 131*cdf0e10cSrcweir if not readOnly then 132*cdf0e10cSrcweir bOK = bOK AND (oObj.getSelectionStart() = chCount -1) 133*cdf0e10cSrcweir else 134*cdf0e10cSrcweir Out.Log("Object is unselectable") 135*cdf0e10cSrcweir end if 136*cdf0e10cSrcweir Test.MethodTested("getSelectionStart()",bOK) 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir Test.StartMethod("getSelectionEnd()") 139*cdf0e10cSrcweir bOK = true 140*cdf0e10cSrcweir oObj.setSelection(0,chCount - 1) 141*cdf0e10cSrcweir if not readOnly then 142*cdf0e10cSrcweir bOK = bOK AND (oObj.getSelectionEnd() = chCount - 1) 143*cdf0e10cSrcweir else 144*cdf0e10cSrcweir Out.Log("Object is unselectable") 145*cdf0e10cSrcweir end if 146*cdf0e10cSrcweir Test.MethodTested("getSelectionEnd()",bOK) 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir Test.StartMethod("setSelection()") 149*cdf0e10cSrcweir bOK = true 150*cdf0e10cSrcweir if not readOnly then 151*cdf0e10cSrcweir bOK = bOK AND oObj.setSelection(0,chCount) 152*cdf0e10cSrcweir else 153*cdf0e10cSrcweir Out.Log("Object is unselectable") 154*cdf0e10cSrcweir end if 155*cdf0e10cSrcweir Test.MethodTested("setSelection()",bOK) 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir Test.StartMethod("getText()") 158*cdf0e10cSrcweir bOK = true 159*cdf0e10cSrcweir bOK = bOK AND (accText = oObj.getText()) 160*cdf0e10cSrcweir Test.MethodTested("getText()",bOK) 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir Test.StartMethod("getTextRange()") 163*cdf0e10cSrcweir bOK = true 164*cdf0e10cSrcweir bOK = bOK AND (accText = oObj.getTextRange(0,chCount)) 165*cdf0e10cSrcweir Test.MethodTested("getTextRange()",bOK) 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir Test.StartMethod("getTextAtIndex()") 168*cdf0e10cSrcweir bOK = true 169*cdf0e10cSrcweir accTextSegment = oObj.getTextAtIndex(chCount - 1, 4) 170*cdf0e10cSrcweir bOK = bOK AND (accText = accTextSegment.SegmentText) 171*cdf0e10cSrcweir Test.MethodTested("getTextAtIndex()",bOK) 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir Test.StartMethod("getTextBeforeIndex()") 174*cdf0e10cSrcweir bOK = true 175*cdf0e10cSrcweir accTextSegment = oObj.getTextBeforeIndex(1, 1) 176*cdf0e10cSrcweir bOK = bOK AND (accTextSegment.SegmentText = utils.getCharacter(1,accText)) 177*cdf0e10cSrcweir Test.MethodTested("getTextBeforeIndex()",bOK) 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir Test.StartMethod("getTextBehindIndex()") 180*cdf0e10cSrcweir bOK = true 181*cdf0e10cSrcweir accTextSegment = oObj.getTextBehindIndex(chCount-2,1) 182*cdf0e10cSrcweir bOK = bOK AND (accTextSegment.SegmentText = utils.getCharacter(chCount,accText)) 183*cdf0e10cSrcweir Test.MethodTested("getTextBehindIndex()",bOK) 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir Test.StartMethod("copyText()") 186*cdf0e10cSrcweir bOK = true 187*cdf0e10cSrcweir bOK = bOK AND oObj.copyText(0,chCount) 188*cdf0e10cSrcweir if readOnly then bOK = true 189*cdf0e10cSrcweir Test.MethodTested("copyText()",bOK) 190*cdf0e10cSrcweir 191*cdf0e10cSrcweirExit Sub 192*cdf0e10cSrcweirErrHndl: 193*cdf0e10cSrcweir Test.Exception() 194*cdf0e10cSrcweir bOK = false 195*cdf0e10cSrcweir resume next 196*cdf0e10cSrcweirEnd Sub 197*cdf0e10cSrcweir</script:module> 198