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