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