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="text_XText" 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'************************************************************************* 35' This Interface/Service test depends on the following GLOBAL variables, 36' which must be specified in the object creation: 37 38' - Global oCollection As Object [optional] 39' if this relation exists then the method "count" is called for check insert/remove 40' - Global oInstance As Object 41' Global aAddons() As Variant [optional] 42' if this relation exists, then additional methods are called before and after insert/removeTextContent() methods 43 44'************************************************************************* 45 46 47 48 49 50 51Sub RunTest() 52 53'************************************************************************* 54' INTERFACE: 55' com.sun.star.text.XText 56'************************************************************************* 57On Error Goto ErrHndl 58 Dim bOK As Boolean 59 Dim cText As String 60 Dim oCursor As Object 61 Dim i1 As Integer 62 Dim i2 As Integer 63 64 Test.StartMethod("insertTextContent()") 65 bOK = true 66 cText = ". Zeile : test_XText" 67 68 If IsObject(oCollection) and IsObject(oInstance) Then 69 oCursor = oObj.createTextCursor() 70 oCursor.gotoEnd(false) 71 i1 = count(oCollection) 72 Out.Log("Before inserting we have " + i1 + " elements.") 73 74' if isArray(aAddons) then 75' Out.Log("Calling beforeInsertTextContent() ...") 76' beforeInsertTextContent() 77' endif 78 79 oObj.insertTextContent(oCursor, oInstance, false) 80 81' if isArray(aAddons) then 82' Out.Log("Calling afterInsertTextContent() ...") 83' afterInsertTextContent() 84' endif 85 86 i2 = count(oCollection) 87 Out.Log("After inserting we have " + i2 + " elements.") 88 bOK = bOK AND i1 = i2 - 1 89 Test.MethodTested("insertTextContent()", bOK) 90 91 Test.StartMethod("removeTextContent()") 92 bOK = true 93 i1 = count(oCollection) 94 Out.Log("Before removing we have " + i1 + " elements.") 95 96' if (isArray(aAddons)) then 97' Out.Log("Calling beforeRemoveTextContent() ...") 98' beforeRemoveTextContent() 99' endif 100 101 oObj.removeTextContent(oInstance) 102 103' if (isArray(aAddons)) then 104' Out.Log("Calling afterRemoveTextContent() ...") 105' afterRemoveTextContent() 106' endif 107 108 i2 = count(oCollection) 109 Out.Log("After removing we have " + i2 + " elements.") 110 bOK = bOK AND i1 = i2 + 1 111 Test.MethodTested("removeTextContent()", bOK) 112 Else 113 oCursor = oObj.createTextCursor() 114 oCursor.gotoEnd(false) 115 oObj.insertTextContent(oCursor, oInstance, false) 116 Test.MethodTested("insertTextContent()", True) 117 Test.StartMethod("removeTextContent()") 118 oObj.removeTextContent(oInstance) 119 Test.MethodTested("removeTextContent()", True) 120 End If 121 122Exit Sub 123ErrHndl: 124 Test.Exception() 125 bOK = false 126 resume next 127End Sub 128 129Function count(container As Variant) As Integer 130 Dim iAmount As Integer 131 Dim oEnumeration As Object 132 133 if hasUnoInterfaces(container, "com.sun.star.container.XIndexAccess") then 134 iAmount = container.getCount() 135 elseif hasUnoInterfaces(container, "com.sun.star.container.XNameAccess") then 136 iAmount = ubound(container.getElementNames()) + 1 137 elseif hasUnoInterfaces(container, "com.sun.star.container.XEnumerationAccess") then 138 oEnumeration = container.createEnumeration() 139 iAmount = 0 140 while oEnumeration.hasMoreElements() 141 iAmount = iAmount + 1 142 oEnumeration.nextElement() 143 wend 144 end if 145 146 count() = iAmount 147End Function 148</script:module> 149