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="awt_XTextComponent" 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
41Dim bCB1_textChanged As Boolean
42Dim bCB2_textChanged As Boolean
43
44
45Sub RunTest()
46
47'*************************************************************************
48' INTERFACE:
49' com.sun.star.awt.XTextComponent
50'*************************************************************************
51On Error Goto ErrHndl
52    Dim bOK As Boolean
53    Dim oListener1 As Object, oListener2 As Object
54    Dim vSelection As new com.sun.star.awt.Selection
55    Dim vSelectionSelection As new com.sun.star.awt.Selection
56    Dim vGetSelection As  new com.sun.star.awt.Selection
57    Dim vInsertSelection As  new com.sun.star.awt.Selection
58    Dim cGetText As String
59    Dim len2set As Integer
60
61    Out.Log("create two com.sun.star.awt.XTextListener")
62    oListener1 = createUNOListener("CB1_", "com.sun.star.awt.XTextListener")
63    oListener2 = createUNOListener("CB2_", "com.sun.star.awt.XTextListener")
64
65    Test.StartMethod("setText()")
66    bOK = true
67    Dim cText As String
68    cText = "XTextComponent: setText()"
69    oObj.setText(cText)
70    Test.StartMethod("getText()")
71    bOK = bOK AND (cText = oObj.getText())
72    Test.MethodTested("setText()", bOK)
73    Test.MethodTested("getText()", bOK)
74
75    Test.StartMethod("insertText()")
76    bOK = true
77    oObj.setText("setSelection")
78    vInsertSelection.Min = 0
79    vInsertSelection.Max = 3
80    oObj.insertText(vInsertSelection,"new")
81    Out.Log("result of getText is: '" + oObj.getText() +"'. It sould be 'newSelection'")
82    bOK = bOK AND (oObj.getText() = "newSelection")
83    Test.MethodTested("insertText()", bOK)
84
85
86    Test.StartMethod("setSelection()")
87    bOK = true
88    vSelectionSelection.Min = 2
89    vSelectionSelection.Max = 3
90    oObj.setSelection(vSelectionSelection)
91    Test.StartMethod("getSelection()")
92    vGetSelection = oObj.getSelection()
93    bOK = bOK AND (vGetSelection.Min = vSelectionSelection.Min) AND _
94          (vGetSelection.Max = vSelectionSelection.Max)
95    Test.MethodTested("setSelection()", bOK)
96    Test.MethodTested("getSelection()", bOK)
97
98    Test.StartMethod("getSelectedText()")
99    bOK = true
100    oObj.setText("getSelectedText")
101    vSelectionSelection.Min = 0
102    vSelectionSelection.Max = 3
103    oObj.setSelection(vSelectionSelection)
104    Out.Log("result of getSelectedText is: '" + oObj.getSelectedText() +"'. It sould be 'get'")
105    bOK = bOK AND (oObj.getSelectedText() = "get")
106    Test.MethodTested("getSelectedText()", bOK)
107
108    Test.StartMethod("setEditable()")
109    bOK = true
110    oObj.setEditable(true)
111    Test.StartMethod("isEditable()")
112    bOK = bOK AND oObj.isEditable()
113    oObj.setEditable(false)
114    bOK = bOK AND NOT oObj.isEditable()
115    oObj.setEditable(true)
116    bOK = bOK AND oObj.isEditable()
117    Test.MethodTested("setEditable()", bOK)
118    Test.MethodTested("isEditable()", bOK)
119
120    Test.StartMethod("setMaxTextLen()")
121    bOK = true
122    if (oObj.getMaxTextLen = 12) then
123        len2set = 10
124    else
125        len2set = 12
126    endif
127    oObj.setMaxTextLen(len2set)
128    oObj.setText("0123456789ABCDE")
129    cGetText = oObj.getText()
130    Out.Log("result of Len(cGetText) is: '" + Len(cGetText) + "'. It sould be >'" + len2set+"' ")
131    bOK = bOK AND (Len(cGetText) > len2set)
132    Test.MethodTested("setMaxTextLen()", bOK)
133
134    Test.StartMethod("getMaxTextLen()")
135    bOK = true
136    if (oObj.getMaxTextLen = 12) then
137        len2set = 10
138    else
139        len2set = 12
140    endif
141    oObj.setMaxTextLen(len2set)
142    Out.Log("result of getMaxTextLen is: '" + oObj.getMaxTextLen() +"'. It sould be '"+len2set+"'")
143    bOK = bOK AND (oObj.getMaxTextLen() = len2set)
144    Test.MethodTested("getMaxTextLen()", bOK)
145
146    bCB1_textChanged = false
147    bCB2_textChanged = false
148
149    Test.StartMethod("addTextListener()")
150    bOK = true
151    oObj.addTextListener(oListener1)
152    oObj.addTextListener(oListener2)
153    oObj.setText("addTextListener")
154    Wait(500)
155    bOK = bOK AND bCB1_textChanged AND bCB2_textChanged
156    Test.MethodTested("addTextListener()", bOK)
157
158    bCB1_textChanged = false
159    bCB2_textChanged = false
160
161    Test.StartMethod("removeTextListener()")
162    bOK = true
163    oObj.removeTextListener(oListener1)
164    oObj.setText("removeTextListener")
165    Wait(500)
166    bOK = bOK AND NOT bCB1_textChanged AND bCB2_textChanged
167    oObj.removeTextListener(oListener2)
168    Test.MethodTested("removeTextListener()", bOK)
169
170Exit Sub
171ErrHndl:
172    Test.Exception()
173    bOK = false
174    resume next
175End Sub
176
177Sub CB1_disposing()
178End Sub
179
180Sub CB2_disposing()
181End Sub
182
183' Listener call backs for com.sun.star.awt.XTextListener
184Sub CB1_textChanged
185    Out.Log("CallBack for Listener1 textChanged was called.")
186    bCB1_textChanged = true
187End Sub
188Sub CB2_TextChanged
189    Out.Log("CallBack for Listener2 textChanged was called.")
190    bCB2_textChanged = true
191End Sub
192</script:module>
193