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_XAccessibleEditableText" 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 hasChangeableAttrs as boolean 44 45'************************************************************************* 46 47 48 49 50 51 52Sub RunTest() 53 54'************************************************************************* 55' INTERFACE: 56' com.sun.star.accessibility.XAccessibleEditableText 57'************************************************************************* 58On Error Goto ErrHndl 59 Dim bOK As Boolean, locRes As Boolean 60 Dim oldText As String, curText As String 61 Dim length As Integer, initialText As String 62 63 oldText = oObj.getText() 64 initialText = oldText 65 length = oObj.getCharacterCount() 66 Out.Log("Text: "+oldText) 67 Out.Log("Length: "+length) 68 69 70 Test.StartMethod("cutText()") 71 bOK = true 72 locRes = oObj.cutText(0,length) 73 curText = oObj.getText() 74 bOK = bOK AND (len(curText) = 0) AND locRes 75 Test.MethodTested("cutText()",bOK) 76 77 78 Test.StartMethod("pasteText()") 79 bOK = true 80 locRes = oObj.pasteText(0) 81 curText = oObj.getText() 82 bOK = bOK AND (len(curText) = length) AND locRes 83 Test.MethodTested("pasteText()",bOK) 84 85 86 Test.StartMethod("insertText()") 87 Dim insString As String 88 bOK = true 89 insString = "Inserted String" 90 locRes = oObj.insertText(insString,length) 91 curText = oObj.getText() 92 bOK = bOK AND (curText = oldText + insString) AND locRes 93 Test.MethodTested("insertText()",bOK) 94 95 96 Test.StartMethod("deleteText()") 97 bOK = true 98 locRes = oObj.deleteText(len(curText) - len(insString),len(curText)) 99 curText = oObj.getText() 100 bOK = bOK AND (curText = oldText) AND locRes 101 Test.MethodTested("deleteText()",bOK) 102 103 104 Test.StartMethod("replaceText()") 105 Dim replacement As String 106 Dim endIndex As Integer 107 bOK = true 108 oObj.setText(oldText+"(part of string to replace)") 109 endIndex = len(oObj.getText) 110 replacement = "Replacement string" 111 locRes = oObj.replaceText(len(oldText),endIndex,replacement) 112 curText = oObj.getText() 113 bOK = bOK AND (curText = oldText + replacement) AND locRes 114 Test.MethodTested("replaceText()",bOK) 115 116 117 Test.StartMethod("setAttributes()") 118 if hasChangeableAttrs then 119 Dim attrs As Variant, newAttrs As Variant 120 Dim i As Integer 121 bOK = true 122 length = oObj.getCharacterCount() 123 attrs = oObj.getCharacterAttributes(0) 124 for i=0 to ubound(attrs()) 125 if attrs(i).Name = "CharBackColor" then attrs(i).Value = RGB(120,205,40) 126 if attrs(i).Name = "CharHeight" then attrs(i).Value = 30 127 if attrs(i).Name = "CharColor" then attrs(i).Value = RGB(255,255,255) 128 next i 129 locRes = oObj.setAttributes(0,length,attrs) 130 bOK = bOK AND locRes 131 newAttrs = oObj.getCharacterAttributes(0) 132 bOK = bOK AND PropertyTester.equals(attrs,newAttrs) 133 else 134 Out.Log("Object has no changeable attributes.") 135 bOK = true 136 End If 137 Test.MethodTested("setAttributes()",bOK) 138 139 140 Test.StartMethod("setText()") 141 Dim newText As String 142 bOK = true 143 oldText = oObj.getText() 144 newText = "New string" 145 locRes = oObj.setText(newText) 146 curText = oObj.getText() 147 bOK = bOK AND (curText = newText) AND locRes 148 if locRes then 149 Out.Log("Test 1 passed OK.") 150 else 151 Out.Log("Test 1 failed.") 152 End If 153 newText = "" 154 locRes = oObj.setText(newText) 155 curText = oObj.getText() 156 bOK = bOK AND (newText = curText) AND locRes 157 if locRes then 158 Out.Log("Test 2 passed OK.") 159 else 160 Out.Log("Test 2 failed.") 161 End If 162 locRes = oObj.setText(oldText) 163 curText = oObj.getText() 164 bOK = bOK AND (curText = oldText) AND locRes 165 if locRes then 166 Out.Log("Test 3 passed OK.") 167 else 168 Out.Log("Test 3 failed.") 169 End If 170 Test.MethodTested("setText()",bOK) 171 172 out.dbg("Setting initial text: " + initialText ) 173 oObj.setText(initialText) 174 175Exit Sub 176ErrHndl: 177 Test.Exception() 178 bOK = false 179 resume next 180End Sub 181</script:module> 182