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