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