1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="awt_XTextComponent" script:language="StarBasic">
4cdf0e10cSrcweir
5cdf0e10cSrcweir
6cdf0e10cSrcweir'*************************************************************************
7cdf0e10cSrcweir'
83709053cSAndrew Rist'  Licensed to the Apache Software Foundation (ASF) under one
93709053cSAndrew Rist'  or more contributor license agreements.  See the NOTICE file
103709053cSAndrew Rist'  distributed with this work for additional information
113709053cSAndrew Rist'  regarding copyright ownership.  The ASF licenses this file
123709053cSAndrew Rist'  to you under the Apache License, Version 2.0 (the
133709053cSAndrew Rist'  "License"); you may not use this file except in compliance
143709053cSAndrew Rist'  with the License.  You may obtain a copy of the License at
153709053cSAndrew Rist'
163709053cSAndrew Rist'    http://www.apache.org/licenses/LICENSE-2.0
173709053cSAndrew Rist'
183709053cSAndrew Rist'  Unless required by applicable law or agreed to in writing,
193709053cSAndrew Rist'  software distributed under the License is distributed on an
203709053cSAndrew Rist'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
213709053cSAndrew Rist'  KIND, either express or implied.  See the License for the
223709053cSAndrew Rist'  specific language governing permissions and limitations
233709053cSAndrew Rist'  under the License.
24cdf0e10cSrcweir'
25cdf0e10cSrcweir'*************************************************************************
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
293709053cSAndrew Rist
303709053cSAndrew Rist
31cdf0e10cSrcweir' Be sure that all variables are dimensioned:
32cdf0e10cSrcweiroption explicit
33cdf0e10cSrcweir
34cdf0e10cSrcweir
35cdf0e10cSrcweirDim bCB1_textChanged As Boolean
36cdf0e10cSrcweirDim bCB2_textChanged As Boolean
37cdf0e10cSrcweir
38cdf0e10cSrcweir
39cdf0e10cSrcweirSub RunTest()
40cdf0e10cSrcweir
41cdf0e10cSrcweir'*************************************************************************
42cdf0e10cSrcweir' INTERFACE:
43cdf0e10cSrcweir' com.sun.star.awt.XTextComponent
44cdf0e10cSrcweir'*************************************************************************
45cdf0e10cSrcweirOn Error Goto ErrHndl
46cdf0e10cSrcweir    Dim bOK As Boolean
47cdf0e10cSrcweir    Dim oListener1 As Object, oListener2 As Object
48cdf0e10cSrcweir    Dim vSelection As new com.sun.star.awt.Selection
49cdf0e10cSrcweir    Dim vSelectionSelection As new com.sun.star.awt.Selection
50cdf0e10cSrcweir    Dim vGetSelection As  new com.sun.star.awt.Selection
51cdf0e10cSrcweir    Dim vInsertSelection As  new com.sun.star.awt.Selection
52cdf0e10cSrcweir    Dim cGetText As String
53cdf0e10cSrcweir    Dim len2set As Integer
54cdf0e10cSrcweir
55cdf0e10cSrcweir    Out.Log("create two com.sun.star.awt.XTextListener")
56cdf0e10cSrcweir    oListener1 = createUNOListener("CB1_", "com.sun.star.awt.XTextListener")
57cdf0e10cSrcweir    oListener2 = createUNOListener("CB2_", "com.sun.star.awt.XTextListener")
58cdf0e10cSrcweir
59cdf0e10cSrcweir    Test.StartMethod("setText()")
60cdf0e10cSrcweir    bOK = true
61cdf0e10cSrcweir    Dim cText As String
62cdf0e10cSrcweir    cText = "XTextComponent: setText()"
63cdf0e10cSrcweir    oObj.setText(cText)
64cdf0e10cSrcweir    Test.StartMethod("getText()")
65cdf0e10cSrcweir    bOK = bOK AND (cText = oObj.getText())
66cdf0e10cSrcweir    Test.MethodTested("setText()", bOK)
67cdf0e10cSrcweir    Test.MethodTested("getText()", bOK)
68cdf0e10cSrcweir
69cdf0e10cSrcweir    Test.StartMethod("insertText()")
70cdf0e10cSrcweir    bOK = true
71cdf0e10cSrcweir    oObj.setText("setSelection")
72cdf0e10cSrcweir    vInsertSelection.Min = 0
73cdf0e10cSrcweir    vInsertSelection.Max = 3
74cdf0e10cSrcweir    oObj.insertText(vInsertSelection,"new")
75*30acf5e8Spfg    Out.Log("result of getText is: '" + oObj.getText() +"'. It should be 'newSelection'")
76cdf0e10cSrcweir    bOK = bOK AND (oObj.getText() = "newSelection")
77cdf0e10cSrcweir    Test.MethodTested("insertText()", bOK)
78cdf0e10cSrcweir
79cdf0e10cSrcweir
80cdf0e10cSrcweir    Test.StartMethod("setSelection()")
81cdf0e10cSrcweir    bOK = true
82cdf0e10cSrcweir    vSelectionSelection.Min = 2
83cdf0e10cSrcweir    vSelectionSelection.Max = 3
84cdf0e10cSrcweir    oObj.setSelection(vSelectionSelection)
85cdf0e10cSrcweir    Test.StartMethod("getSelection()")
86cdf0e10cSrcweir    vGetSelection = oObj.getSelection()
87cdf0e10cSrcweir    bOK = bOK AND (vGetSelection.Min = vSelectionSelection.Min) AND _
88cdf0e10cSrcweir          (vGetSelection.Max = vSelectionSelection.Max)
89cdf0e10cSrcweir    Test.MethodTested("setSelection()", bOK)
90cdf0e10cSrcweir    Test.MethodTested("getSelection()", bOK)
91cdf0e10cSrcweir
92cdf0e10cSrcweir    Test.StartMethod("getSelectedText()")
93cdf0e10cSrcweir    bOK = true
94cdf0e10cSrcweir    oObj.setText("getSelectedText")
95cdf0e10cSrcweir    vSelectionSelection.Min = 0
96cdf0e10cSrcweir    vSelectionSelection.Max = 3
97cdf0e10cSrcweir    oObj.setSelection(vSelectionSelection)
98*30acf5e8Spfg    Out.Log("result of getSelectedText is: '" + oObj.getSelectedText() +"'. It should be 'get'")
99cdf0e10cSrcweir    bOK = bOK AND (oObj.getSelectedText() = "get")
100cdf0e10cSrcweir    Test.MethodTested("getSelectedText()", bOK)
101cdf0e10cSrcweir
102cdf0e10cSrcweir    Test.StartMethod("setEditable()")
103cdf0e10cSrcweir    bOK = true
104cdf0e10cSrcweir    oObj.setEditable(true)
105cdf0e10cSrcweir    Test.StartMethod("isEditable()")
106cdf0e10cSrcweir    bOK = bOK AND oObj.isEditable()
107cdf0e10cSrcweir    oObj.setEditable(false)
108cdf0e10cSrcweir    bOK = bOK AND NOT oObj.isEditable()
109cdf0e10cSrcweir    oObj.setEditable(true)
110cdf0e10cSrcweir    bOK = bOK AND oObj.isEditable()
111cdf0e10cSrcweir    Test.MethodTested("setEditable()", bOK)
112cdf0e10cSrcweir    Test.MethodTested("isEditable()", bOK)
113cdf0e10cSrcweir
114cdf0e10cSrcweir    Test.StartMethod("setMaxTextLen()")
115cdf0e10cSrcweir    bOK = true
116cdf0e10cSrcweir    if (oObj.getMaxTextLen = 12) then
117cdf0e10cSrcweir        len2set = 10
118cdf0e10cSrcweir    else
119cdf0e10cSrcweir        len2set = 12
120cdf0e10cSrcweir    endif
121cdf0e10cSrcweir    oObj.setMaxTextLen(len2set)
122cdf0e10cSrcweir    oObj.setText("0123456789ABCDE")
123cdf0e10cSrcweir    cGetText = oObj.getText()
124*30acf5e8Spfg    Out.Log("result of Len(cGetText) is: '" + Len(cGetText) + "'. It should be >'" + len2set+"' ")
125cdf0e10cSrcweir    bOK = bOK AND (Len(cGetText) > len2set)
126cdf0e10cSrcweir    Test.MethodTested("setMaxTextLen()", bOK)
127cdf0e10cSrcweir
128cdf0e10cSrcweir    Test.StartMethod("getMaxTextLen()")
129cdf0e10cSrcweir    bOK = true
130cdf0e10cSrcweir    if (oObj.getMaxTextLen = 12) then
131cdf0e10cSrcweir        len2set = 10
132cdf0e10cSrcweir    else
133cdf0e10cSrcweir        len2set = 12
134cdf0e10cSrcweir    endif
135cdf0e10cSrcweir    oObj.setMaxTextLen(len2set)
136*30acf5e8Spfg    Out.Log("result of getMaxTextLen is: '" + oObj.getMaxTextLen() +"'. It should be '"+len2set+"'")
137cdf0e10cSrcweir    bOK = bOK AND (oObj.getMaxTextLen() = len2set)
138cdf0e10cSrcweir    Test.MethodTested("getMaxTextLen()", bOK)
139cdf0e10cSrcweir
140cdf0e10cSrcweir    bCB1_textChanged = false
141cdf0e10cSrcweir    bCB2_textChanged = false
142cdf0e10cSrcweir
143cdf0e10cSrcweir    Test.StartMethod("addTextListener()")
144cdf0e10cSrcweir    bOK = true
145cdf0e10cSrcweir    oObj.addTextListener(oListener1)
146cdf0e10cSrcweir    oObj.addTextListener(oListener2)
147cdf0e10cSrcweir    oObj.setText("addTextListener")
148cdf0e10cSrcweir    Wait(500)
149cdf0e10cSrcweir    bOK = bOK AND bCB1_textChanged AND bCB2_textChanged
150cdf0e10cSrcweir    Test.MethodTested("addTextListener()", bOK)
151cdf0e10cSrcweir
152cdf0e10cSrcweir    bCB1_textChanged = false
153cdf0e10cSrcweir    bCB2_textChanged = false
154cdf0e10cSrcweir
155cdf0e10cSrcweir    Test.StartMethod("removeTextListener()")
156cdf0e10cSrcweir    bOK = true
157cdf0e10cSrcweir    oObj.removeTextListener(oListener1)
158cdf0e10cSrcweir    oObj.setText("removeTextListener")
159cdf0e10cSrcweir    Wait(500)
160cdf0e10cSrcweir    bOK = bOK AND NOT bCB1_textChanged AND bCB2_textChanged
161cdf0e10cSrcweir    oObj.removeTextListener(oListener2)
162cdf0e10cSrcweir    Test.MethodTested("removeTextListener()", bOK)
163cdf0e10cSrcweir
164cdf0e10cSrcweirExit Sub
165cdf0e10cSrcweirErrHndl:
166cdf0e10cSrcweir    Test.Exception()
167cdf0e10cSrcweir    bOK = false
168cdf0e10cSrcweir    resume next
169cdf0e10cSrcweirEnd Sub
170cdf0e10cSrcweir
171cdf0e10cSrcweirSub CB1_disposing()
172cdf0e10cSrcweirEnd Sub
173cdf0e10cSrcweir
174cdf0e10cSrcweirSub CB2_disposing()
175cdf0e10cSrcweirEnd Sub
176cdf0e10cSrcweir
177cdf0e10cSrcweir' Listener call backs for com.sun.star.awt.XTextListener
178cdf0e10cSrcweirSub CB1_textChanged
179cdf0e10cSrcweir    Out.Log("CallBack for Listener1 textChanged was called.")
180cdf0e10cSrcweir    bCB1_textChanged = true
181cdf0e10cSrcweirEnd Sub
182cdf0e10cSrcweirSub CB2_TextChanged
183cdf0e10cSrcweir    Out.Log("CallBack for Listener2 textChanged was called.")
184cdf0e10cSrcweir    bCB2_textChanged = true
185cdf0e10cSrcweirEnd Sub
186cdf0e10cSrcweir</script:module>
187