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