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_XRelativeTextContentInsert" 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
32
33Sub RunTest()
34
35'*************************************************************************
36' INTERFACE:
37' com.sun.star.text.XRelativeTextContentInsert
38'*************************************************************************
39On Error Goto ErrHndl
40    Dim bOK As Boolean
41    Dim oEnum As Object
42    Dim oCursor As Object
43    Dim oContent1 As Object
44    Dim oContent2 As Object
45    Dim bFound As Boolean
46    Dim oEl As Object
47
48    Test.StartMethod("insertTextContentBefore()")
49    bOK = true
50    oCursor = oObj.createTextCursor()
51    if (isNULL(oCursor)) then Out.Log("Can't create text cursor!")
52
53    Out.Log("First, mark all existant entries with 0")
54
55    oEnum = oObj.createEnumeration()
56    while (oEnum.hasMoreElements())
57        oEl = oEnum.NextElement()
58        if (oEl.supportsService("com.sun.star.text.Paragraph")) then
59            oEl.String = "0"
60        end if
61    wend
62
63    Out.Log("Inserting TextSection...")
64    oContent1 = oDoc.createInstance("com.sun.star.text.TextSection")
65    oObj.insertTextContent(oCursor, oContent1, false)
66
67    oEnum = oObj.createEnumeration()
68    while (oEnum.hasMoreElements())
69        oEl = oEnum.NextElement()
70        if (oEl.supportsService("com.sun.star.text.Paragraph")) then
71            if (oEl.String = "") then oEl.String = "1"
72        end if
73    wend
74
75    Out.Log("Mark new entry with 1")
76
77    oContent2 = oDoc.createInstance("com.sun.star.text.Paragraph")
78    oObj.insertTextContentBefore(oContent2, oContent1)
79
80    oEnum = oObj.createEnumeration()
81    while (oEnum.hasMoreElements())
82        oEl = oEnum.NextElement()
83        if (oEl.supportsService("com.sun.star.text.Paragraph")) then
84            if (oEl.String = "") then oEl.String = "2"
85        end if
86    wend
87
88    Out.Log("Mark new entry with 2")
89
90    Out.Log("Testing that content was inserted BEFORE. I.e. Label 2 before label 1")
91
92    oEnum = oObj.createEnumeration()
93    bFound = false
94    while (oEnum.hasMoreElements() AND NOT bFound)
95        oEl = oEnum.NextElement()
96        if (oEl.supportsService("com.sun.star.text.Paragraph")) then
97            bFound = oEl.String = "2"
98        end if
99    wend
100
101    oEl = oEnum.NextElement()
102    bOK = bOK AND oEl.String = "1"
103
104    Test.MethodTested("insertTextContentBefore()", bOK)
105
106
107    Test.StartMethod("insertTextContentAfter()")
108    bOK = true
109
110    Out.Log("Inserting TextSection...")
111    oContent1 = oDoc.createInstance("com.sun.star.text.TextSection")
112    oObj.insertTextContent(oCursor, oContent1, false)
113
114    oEnum = oObj.createEnumeration()
115    while (oEnum.hasMoreElements())
116        oEl = oEnum.NextElement()
117        if (oEl.supportsService("com.sun.star.text.Paragraph")) then
118            if (oEl.String = "") then oEl.String = "3"
119        end if
120    wend
121
122    Out.Log("Mark new entry with 3")
123
124    oContent2 = oDoc.createInstance("com.sun.star.text.Paragraph")
125    oObj.insertTextContentAfter(oContent2, oContent1)
126
127    oEnum = oObj.createEnumeration()
128    while (oEnum.hasMoreElements())
129        oEl = oEnum.NextElement()
130        if (oEl.supportsService("com.sun.star.text.Paragraph")) then
131            if (oEl.String = "") then oEl.String = "4"
132        end if
133    wend
134
135    Out.Log("Mark new entry with 4")
136
137    Out.Log("Testing that content was inserted AFTRER. I.e. Label 4 after label 3")
138
139    oEnum = oObj.createEnumeration()
140    bFound = false
141    while (oEnum.hasMoreElements() AND NOT bFound)
142        oEl = oEnum.NextElement()
143        if (oEl.supportsService("com.sun.star.text.Paragraph")) then
144            bFound = oEl.String = "3"
145        end if
146    wend
147
148    oEl = oEnum.NextElement()
149    bOK = bOK AND oEl.String = "4"
150
151    Test.MethodTested("insertTextContentAfter()", bOK)
152
153Exit Sub
154ErrHndl:
155    Test.Exception()
156    bOK = false
157    resume next
158End Sub
159</script:module>
160