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