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