1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?>
2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="accessibility_XAccessibleEditableText" script:language="StarBasic">
4*b1cdbd2cSJim Jagielski
5*b1cdbd2cSJim Jagielski
6*b1cdbd2cSJim Jagielski'*************************************************************************
7*b1cdbd2cSJim Jagielski'
8*b1cdbd2cSJim Jagielski'  Licensed to the Apache Software Foundation (ASF) under one
9*b1cdbd2cSJim Jagielski'  or more contributor license agreements.  See the NOTICE file
10*b1cdbd2cSJim Jagielski'  distributed with this work for additional information
11*b1cdbd2cSJim Jagielski'  regarding copyright ownership.  The ASF licenses this file
12*b1cdbd2cSJim Jagielski'  to you under the Apache License, Version 2.0 (the
13*b1cdbd2cSJim Jagielski'  "License"); you may not use this file except in compliance
14*b1cdbd2cSJim Jagielski'  with the License.  You may obtain a copy of the License at
15*b1cdbd2cSJim Jagielski'
16*b1cdbd2cSJim Jagielski'    http://www.apache.org/licenses/LICENSE-2.0
17*b1cdbd2cSJim Jagielski'
18*b1cdbd2cSJim Jagielski'  Unless required by applicable law or agreed to in writing,
19*b1cdbd2cSJim Jagielski'  software distributed under the License is distributed on an
20*b1cdbd2cSJim Jagielski'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*b1cdbd2cSJim Jagielski'  KIND, either express or implied.  See the License for the
22*b1cdbd2cSJim Jagielski'  specific language governing permissions and limitations
23*b1cdbd2cSJim Jagielski'  under the License.
24*b1cdbd2cSJim Jagielski'
25*b1cdbd2cSJim Jagielski'*************************************************************************
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski
28*b1cdbd2cSJim Jagielski
29*b1cdbd2cSJim Jagielski
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim Jagielski' Be sure that all variables are dimensioned:
32*b1cdbd2cSJim Jagielskioption explicit
33*b1cdbd2cSJim Jagielski
34*b1cdbd2cSJim Jagielski'*************************************************************************
35*b1cdbd2cSJim Jagielski' This Interface/Service test depends on the following GLOBAL variables,
36*b1cdbd2cSJim Jagielski' which must be specified in the object creation:
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim Jagielski'	global hasChangeableAttrs as boolean
39*b1cdbd2cSJim Jagielski
40*b1cdbd2cSJim Jagielski'*************************************************************************
41*b1cdbd2cSJim Jagielski
42*b1cdbd2cSJim Jagielski
43*b1cdbd2cSJim Jagielski
44*b1cdbd2cSJim Jagielski
45*b1cdbd2cSJim Jagielski
46*b1cdbd2cSJim Jagielski
47*b1cdbd2cSJim JagielskiSub RunTest()
48*b1cdbd2cSJim Jagielski
49*b1cdbd2cSJim Jagielski'*************************************************************************
50*b1cdbd2cSJim Jagielski' INTERFACE:
51*b1cdbd2cSJim Jagielski' com.sun.star.accessibility.XAccessibleEditableText
52*b1cdbd2cSJim Jagielski'*************************************************************************
53*b1cdbd2cSJim JagielskiOn Error Goto ErrHndl
54*b1cdbd2cSJim Jagielski    Dim bOK As Boolean, locRes As Boolean
55*b1cdbd2cSJim Jagielski    Dim oldText As String, curText As String
56*b1cdbd2cSJim Jagielski    Dim length As Integer, initialText As String
57*b1cdbd2cSJim Jagielski
58*b1cdbd2cSJim Jagielski    oldText = oObj.getText()
59*b1cdbd2cSJim Jagielski    initialText = oldText
60*b1cdbd2cSJim Jagielski    length = oObj.getCharacterCount()
61*b1cdbd2cSJim Jagielski    Out.Log("Text: "+oldText)
62*b1cdbd2cSJim Jagielski    Out.Log("Length: "+length)
63*b1cdbd2cSJim Jagielski
64*b1cdbd2cSJim Jagielski
65*b1cdbd2cSJim Jagielski    Test.StartMethod("cutText()")
66*b1cdbd2cSJim Jagielski    bOK = true
67*b1cdbd2cSJim Jagielski    locRes = oObj.cutText(0,length)
68*b1cdbd2cSJim Jagielski    curText = oObj.getText()
69*b1cdbd2cSJim Jagielski    bOK = bOK AND (len(curText) = 0) AND locRes
70*b1cdbd2cSJim Jagielski    Test.MethodTested("cutText()",bOK)
71*b1cdbd2cSJim Jagielski
72*b1cdbd2cSJim Jagielski
73*b1cdbd2cSJim Jagielski    Test.StartMethod("pasteText()")
74*b1cdbd2cSJim Jagielski    bOK = true
75*b1cdbd2cSJim Jagielski    locRes = oObj.pasteText(0)
76*b1cdbd2cSJim Jagielski    curText = oObj.getText()
77*b1cdbd2cSJim Jagielski    bOK = bOK AND (len(curText) = length) AND locRes
78*b1cdbd2cSJim Jagielski    Test.MethodTested("pasteText()",bOK)
79*b1cdbd2cSJim Jagielski
80*b1cdbd2cSJim Jagielski
81*b1cdbd2cSJim Jagielski    Test.StartMethod("insertText()")
82*b1cdbd2cSJim Jagielski    Dim insString As String
83*b1cdbd2cSJim Jagielski    bOK = true
84*b1cdbd2cSJim Jagielski    insString = "Inserted String"
85*b1cdbd2cSJim Jagielski    locRes = oObj.insertText(insString,length)
86*b1cdbd2cSJim Jagielski    curText = oObj.getText()
87*b1cdbd2cSJim Jagielski    bOK = bOK AND (curText = oldText + insString) AND locRes
88*b1cdbd2cSJim Jagielski    Test.MethodTested("insertText()",bOK)
89*b1cdbd2cSJim Jagielski
90*b1cdbd2cSJim Jagielski
91*b1cdbd2cSJim Jagielski    Test.StartMethod("deleteText()")
92*b1cdbd2cSJim Jagielski    bOK = true
93*b1cdbd2cSJim Jagielski    locRes = oObj.deleteText(len(curText) - len(insString),len(curText))
94*b1cdbd2cSJim Jagielski    curText = oObj.getText()
95*b1cdbd2cSJim Jagielski    bOK = bOK AND (curText = oldText) AND locRes
96*b1cdbd2cSJim Jagielski    Test.MethodTested("deleteText()",bOK)
97*b1cdbd2cSJim Jagielski
98*b1cdbd2cSJim Jagielski
99*b1cdbd2cSJim Jagielski    Test.StartMethod("replaceText()")
100*b1cdbd2cSJim Jagielski    Dim replacement As String
101*b1cdbd2cSJim Jagielski    Dim endIndex As Integer
102*b1cdbd2cSJim Jagielski    bOK = true
103*b1cdbd2cSJim Jagielski    oObj.setText(oldText+"(part of string to replace)")
104*b1cdbd2cSJim Jagielski    endIndex = len(oObj.getText)
105*b1cdbd2cSJim Jagielski    replacement = "Replacement string"
106*b1cdbd2cSJim Jagielski    locRes = oObj.replaceText(len(oldText),endIndex,replacement)
107*b1cdbd2cSJim Jagielski    curText = oObj.getText()
108*b1cdbd2cSJim Jagielski    bOK = bOK AND (curText = oldText + replacement) AND locRes
109*b1cdbd2cSJim Jagielski    Test.MethodTested("replaceText()",bOK)
110*b1cdbd2cSJim Jagielski
111*b1cdbd2cSJim Jagielski
112*b1cdbd2cSJim Jagielski    Test.StartMethod("setAttributes()")
113*b1cdbd2cSJim Jagielski    if hasChangeableAttrs then
114*b1cdbd2cSJim Jagielski        Dim attrs As Variant, newAttrs As Variant
115*b1cdbd2cSJim Jagielski        Dim i As Integer
116*b1cdbd2cSJim Jagielski        bOK = true
117*b1cdbd2cSJim Jagielski        length = oObj.getCharacterCount()
118*b1cdbd2cSJim Jagielski        attrs = oObj.getCharacterAttributes(0)
119*b1cdbd2cSJim Jagielski        for i=0 to ubound(attrs())
120*b1cdbd2cSJim Jagielski            if attrs(i).Name = "CharBackColor" then attrs(i).Value = RGB(120,205,40)
121*b1cdbd2cSJim Jagielski            if attrs(i).Name = "CharHeight" then attrs(i).Value = 30
122*b1cdbd2cSJim Jagielski            if attrs(i).Name = "CharColor" then attrs(i).Value = RGB(255,255,255)
123*b1cdbd2cSJim Jagielski        next i
124*b1cdbd2cSJim Jagielski        locRes = oObj.setAttributes(0,length,attrs)
125*b1cdbd2cSJim Jagielski        bOK = bOK AND locRes
126*b1cdbd2cSJim Jagielski        newAttrs = oObj.getCharacterAttributes(0)
127*b1cdbd2cSJim Jagielski        bOK = bOK AND PropertyTester.equals(attrs,newAttrs)
128*b1cdbd2cSJim Jagielski    else
129*b1cdbd2cSJim Jagielski        Out.Log("Object has no changeable attributes.")
130*b1cdbd2cSJim Jagielski        bOK = true
131*b1cdbd2cSJim Jagielski    End If
132*b1cdbd2cSJim Jagielski    Test.MethodTested("setAttributes()",bOK)
133*b1cdbd2cSJim Jagielski
134*b1cdbd2cSJim Jagielski
135*b1cdbd2cSJim Jagielski    Test.StartMethod("setText()")
136*b1cdbd2cSJim Jagielski    Dim newText As String
137*b1cdbd2cSJim Jagielski    bOK = true
138*b1cdbd2cSJim Jagielski    oldText = oObj.getText()
139*b1cdbd2cSJim Jagielski    newText = "New string"
140*b1cdbd2cSJim Jagielski    locRes = oObj.setText(newText)
141*b1cdbd2cSJim Jagielski    curText = oObj.getText()
142*b1cdbd2cSJim Jagielski    bOK = bOK AND (curText = newText) AND locRes
143*b1cdbd2cSJim Jagielski    if locRes then
144*b1cdbd2cSJim Jagielski        Out.Log("Test 1 passed OK.")
145*b1cdbd2cSJim Jagielski    else
146*b1cdbd2cSJim Jagielski        Out.Log("Test 1 failed.")
147*b1cdbd2cSJim Jagielski    End If
148*b1cdbd2cSJim Jagielski    newText = ""
149*b1cdbd2cSJim Jagielski    locRes = oObj.setText(newText)
150*b1cdbd2cSJim Jagielski    curText = oObj.getText()
151*b1cdbd2cSJim Jagielski    bOK = bOK AND (newText = curText) AND locRes
152*b1cdbd2cSJim Jagielski    if locRes then
153*b1cdbd2cSJim Jagielski        Out.Log("Test 2 passed OK.")
154*b1cdbd2cSJim Jagielski    else
155*b1cdbd2cSJim Jagielski        Out.Log("Test 2 failed.")
156*b1cdbd2cSJim Jagielski    End If
157*b1cdbd2cSJim Jagielski    locRes = oObj.setText(oldText)
158*b1cdbd2cSJim Jagielski    curText = oObj.getText()
159*b1cdbd2cSJim Jagielski    bOK = bOK AND (curText = oldText) AND locRes
160*b1cdbd2cSJim Jagielski    if locRes then
161*b1cdbd2cSJim Jagielski        Out.Log("Test 3 passed OK.")
162*b1cdbd2cSJim Jagielski    else
163*b1cdbd2cSJim Jagielski        Out.Log("Test 3 failed.")
164*b1cdbd2cSJim Jagielski    End If
165*b1cdbd2cSJim Jagielski    Test.MethodTested("setText()",bOK)
166*b1cdbd2cSJim Jagielski
167*b1cdbd2cSJim Jagielski    out.dbg("Setting initial text: " + initialText )
168*b1cdbd2cSJim Jagielski    oObj.setText(initialText)
169*b1cdbd2cSJim Jagielski
170*b1cdbd2cSJim JagielskiExit Sub
171*b1cdbd2cSJim JagielskiErrHndl:
172*b1cdbd2cSJim Jagielski    Test.Exception()
173*b1cdbd2cSJim Jagielski    bOK = false
174*b1cdbd2cSJim Jagielski    resume next
175*b1cdbd2cSJim JagielskiEnd Sub
176*b1cdbd2cSJim Jagielski</script:module>
177