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="container_XContainer" 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' This Interface/Service test depends on the following GLOBAL variables, 38' which must be specified in the object creation: 39 40' Global oElementToInsert As Object 41' Global oContainer As Object in case if the component tested does 42' not support XNameContainer 43 44'************************************************************************* 45 46Dim ElIns1 As Integer 47Dim ElIns2 As Integer 48Dim ElRem1 As Integer 49Dim ElRem2 As Integer 50Dim ElRep1 As Integer 51Dim ElRep2 As Integer 52 53 54Sub RunTest() 55 56'************************************************************************* 57' INTERFACE: 58' com.sun.star.container.XContainer 59'************************************************************************* 60On Error Goto ErrHndl 61 Dim bOK As Boolean 62 Dim oListener1 as Object 63 Dim oListener2 as Object 64 65 oListener1 = createUNOListener("CB1_", "com.sun.star.container.XContainerListener") 66 oListener2 = createUNOListener("CB2_", "com.sun.star.container.XContainerListener") 67 bOK = NOT isNULL(oListener1) AND NOT isNULL(oListener2) 68 Out.Log("Listeners creation : " + bOK) 69 70 Test.StartMethod("addContainerListener()") 71 bOK = true 72 oObj.addContainerListener(oListener1) 73 Out.Log("Listener1 was added") 74 oObj.addContainerListener(oListener2) 75 Out.Log("Listener2 was added") 76 77 insertElement() 78 79 Dim bInsOK As Boolean 80 bInsOK = ElIns1 >= 1 AND ElIns2 >= 1 81 Out.Log("... " + bInsOK) 82 bOK = bOK AND bInsOK 83 84 removeElement() 85 86 bRemOK = ElRem1 >= 1 AND ElRem2 >= 1 87 Out.Log("... " + bRemOK) 88 bOK = bOK AND bRemOK 89 90 Dim bNothingToReplace as Boolean 91 bNothingToReplace = replaceElement() 92 93 bRepOK = (ElRep1 >= 1 AND ElRep2 >= 1) OR bNothingToReplace 94 Out.Log("... " + bRepOK) 95 bOK = bOK AND bRepOK 96 97 Test.MethodTested("addContainerListener()", bOK) 98 99 100 Test.StartMethod("removeContainerListener()") 101 bOK = true 102 oObj.removeContainerListener(oListener1) 103 Out.Log("Listener1 was removed") 104 105 insertElement() 106 107 bInsOK = ElIns1 = 0 AND ElIns2 >= 1 108 Out.Log("... " + bInsOK) 109 bOK = bOK AND bInsOK 110 111 removeElement() 112 113 bRemOK = ElRem1 = 0 AND ElRem2 >= 1 114 Out.Log("... " + bRemOK) 115 bOK = bOK AND bRemOK 116 117 bNothingToReplace = replaceElement() 118 119 bRepOK = (ElRep1 = 0 AND ElRep2 >= 1) or bNothingToReplace 120 Out.Log("... " + bRepOK) 121 bOK = bOK AND bRepOK 122 Test.MethodTested("removeContainerListener()", bOK) 123 124 oObj.removeContainerListener(oListener2) 125 Out.Log("Listener2 was removed") 126 127Exit Sub 128ErrHndl: 129 Test.Exception() 130 bOK = false 131 resume next 132End Sub 133 134Sub insertElement() 135 Out.Log("Inserting element ... ") 136 ResetCounters() 137 if hasUnoInterfaces(oObj, "com.sun.star.container.XNameContainer") then 138 oObj.InsertByName(cIfcShortName, oElementToInsert) 139 elseif hasUnoInterfaces(oContainer, "com.sun.star.container.XNameContainer") then 140 oContainer.InsertByName(cIfcShortName, oElementToInsert) 141 elseif hasUnoInterfaces(oContainer, "com.sun.star.awt.XControlContainer") then 142 oContainer.addControl("NewControl", oElementToInsert) 143 else 144 Out.LOG("There is nothig to trigger the Listener!") 145 end if 146end Sub 147 148 149Sub removeElement() 150 Out.Log("Removing element ... ") 151 ResetCounters() 152 if hasUnoInterfaces(oObj, "com.sun.star.container.XNameContainer") then 153 oObj.RemoveByName(cIfcShortName) 154 elseif hasUnoInterfaces(oContainer, "com.sun.star.container.XNameContainer") then 155 oContainer.RemoveByName(cIfcShortName) 156 elseif hasUnoInterfaces(oContainer, "com.sun.star.awt.XControlContainer") then 157 oContainer.removeControl(oElementToInsert) 158 end if 159end Sub 160 161Function replaceElement() as Boolean 162 Out.Log("Replacing element ... ") 163 ResetCounters() 164 Dim bNothingToReplace as Boolean 165 bNothingToReplace = FALSE 166 Dim old As Variant 167 if hasUnoInterfaces(oObj, "com.sun.star.container.XIndexReplace") then 168 old = oObj.getByIndex(0) 169 oObj.ReplaceByIndex(0, oElementToInsert) 170 oObj.ReplaceByIndex(0, old) 171 elseif hasUnoInterfaces(oContainer, "com.sun.star.container.XIndexReplace") then 172 old = oContainer.getByIndex(0) 173 oContainer.ReplaceByIndex(0, oElementToInsert) 174 oContainer.ReplaceByIndex(0, old) 175 elseif (hasUnoInterfaces(oContainer, "com.sun.star.container.XNameAccess") and _ 176 hasUnoInterfaces(oContainer, "com.sun.star.container.XNameReplace")) then 177 Dim cNames() as String 178 cNames = oObj.getElementNames() 179 old = oContainer.getByName(cNames(0)) 180 oContainer.ReplaceByName(cNames(0), oElementToInsert) 181 oContainer.ReplaceByName(cNames(0), old) 182 elseif hasUnoInterfaces(oContainer, "com.sun.star.awt.XControlContainer") then 183 bNothingToReplace = TRUE 184 else 185 Out.LOG("There is nothig to trigger the Listener!") 186 end if 187 replaceElement() = bNothingToReplace 188end Function 189 190Sub CB1_elementInserted(ev As Object) 191 Out.Log("CB1 called: element was inserted") 192 ElIns1 = ElIns1 + 1 193End Sub 194 195Sub CB1_elementRemoved(ev As Object) 196 Out.Log("CB1 called: element was removed") 197 ElRem1 = ElRem1 + 1 198End Sub 199 200Sub CB1_elementReplaced(ev As Object) 201 Out.Log("CB1 called: element was replaced") 202 ElRep1 = ElRep1 + 1 203End Sub 204 205Sub CB2_elementInserted(ev As Object) 206 Out.Log("CB2 called: element was inserted") 207 ElIns2 = ElIns2 + 1 208End Sub 209 210Sub CB2_elementRemoved(ev As Object) 211 Out.Log("CB2 called: element was removed") 212 ElRem2 = ElRem2 + 1 213End Sub 214 215Sub CB2_elementReplaced(ev As Object) 216 Out.Log("CB2 called: element was replaced") 217 ElRep2 = ElRep2 + 1 218End Sub 219 220Sub ResetCounters() 221 ElIns1 = 0 222 ElIns2 = 0 223 ElRem1 = 0 224 ElRem2 = 0 225 ElRep1 = 0 226 ElRep2 = 0 227End Sub 228</script:module> 229