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