| <?xml version="1.0" encoding="UTF-8"?> |
| <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> |
| <script:module xmlns:script="http://openoffice.org/2000/script" script:name="container_XContainer" script:language="StarBasic"> |
| |
| |
| '************************************************************************* |
| ' |
| ' Licensed to the Apache Software Foundation (ASF) under one |
| ' or more contributor license agreements. See the NOTICE file |
| ' distributed with this work for additional information |
| ' regarding copyright ownership. The ASF licenses this file |
| ' to you under the Apache License, Version 2.0 (the |
| ' "License"); you may not use this file except in compliance |
| ' with the License. You may obtain a copy of the License at |
| ' |
| ' http://www.apache.org/licenses/LICENSE-2.0 |
| ' |
| ' Unless required by applicable law or agreed to in writing, |
| ' software distributed under the License is distributed on an |
| ' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| ' KIND, either express or implied. See the License for the |
| ' specific language governing permissions and limitations |
| ' under the License. |
| ' |
| '************************************************************************* |
| |
| |
| |
| |
| |
| '************************************************************************* |
| ' This Interface/Service test depends on the following GLOBAL variables, |
| ' which must be specified in the object creation: |
| |
| ' Global oElementToInsert As Object |
| ' Global oContainer As Object in case if the component tested does |
| ' not support XNameContainer |
| |
| '************************************************************************* |
| |
| Dim ElIns1 As Integer |
| Dim ElIns2 As Integer |
| Dim ElRem1 As Integer |
| Dim ElRem2 As Integer |
| Dim ElRep1 As Integer |
| Dim ElRep2 As Integer |
| |
| |
| Sub RunTest() |
| |
| '************************************************************************* |
| ' INTERFACE: |
| ' com.sun.star.container.XContainer |
| '************************************************************************* |
| On Error Goto ErrHndl |
| Dim bOK As Boolean |
| Dim oListener1 as Object |
| Dim oListener2 as Object |
| |
| oListener1 = createUNOListener("CB1_", "com.sun.star.container.XContainerListener") |
| oListener2 = createUNOListener("CB2_", "com.sun.star.container.XContainerListener") |
| bOK = NOT isNULL(oListener1) AND NOT isNULL(oListener2) |
| Out.Log("Listeners creation : " + bOK) |
| |
| Test.StartMethod("addContainerListener()") |
| bOK = true |
| oObj.addContainerListener(oListener1) |
| Out.Log("Listener1 was added") |
| oObj.addContainerListener(oListener2) |
| Out.Log("Listener2 was added") |
| |
| insertElement() |
| |
| Dim bInsOK As Boolean |
| bInsOK = ElIns1 >= 1 AND ElIns2 >= 1 |
| Out.Log("... " + bInsOK) |
| bOK = bOK AND bInsOK |
| |
| removeElement() |
| |
| bRemOK = ElRem1 >= 1 AND ElRem2 >= 1 |
| Out.Log("... " + bRemOK) |
| bOK = bOK AND bRemOK |
| |
| Dim bNothingToReplace as Boolean |
| bNothingToReplace = replaceElement() |
| |
| bRepOK = (ElRep1 >= 1 AND ElRep2 >= 1) OR bNothingToReplace |
| Out.Log("... " + bRepOK) |
| bOK = bOK AND bRepOK |
| |
| Test.MethodTested("addContainerListener()", bOK) |
| |
| |
| Test.StartMethod("removeContainerListener()") |
| bOK = true |
| oObj.removeContainerListener(oListener1) |
| Out.Log("Listener1 was removed") |
| |
| insertElement() |
| |
| bInsOK = ElIns1 = 0 AND ElIns2 >= 1 |
| Out.Log("... " + bInsOK) |
| bOK = bOK AND bInsOK |
| |
| removeElement() |
| |
| bRemOK = ElRem1 = 0 AND ElRem2 >= 1 |
| Out.Log("... " + bRemOK) |
| bOK = bOK AND bRemOK |
| |
| bNothingToReplace = replaceElement() |
| |
| bRepOK = (ElRep1 = 0 AND ElRep2 >= 1) or bNothingToReplace |
| Out.Log("... " + bRepOK) |
| bOK = bOK AND bRepOK |
| Test.MethodTested("removeContainerListener()", bOK) |
| |
| oObj.removeContainerListener(oListener2) |
| Out.Log("Listener2 was removed") |
| |
| Exit Sub |
| ErrHndl: |
| Test.Exception() |
| bOK = false |
| resume next |
| End Sub |
| |
| Sub insertElement() |
| Out.Log("Inserting element ... ") |
| ResetCounters() |
| if hasUnoInterfaces(oObj, "com.sun.star.container.XNameContainer") then |
| oObj.InsertByName(cIfcShortName, oElementToInsert) |
| elseif hasUnoInterfaces(oContainer, "com.sun.star.container.XNameContainer") then |
| oContainer.InsertByName(cIfcShortName, oElementToInsert) |
| elseif hasUnoInterfaces(oContainer, "com.sun.star.awt.XControlContainer") then |
| oContainer.addControl("NewControl", oElementToInsert) |
| else |
| Out.LOG("There is nothig to trigger the Listener!") |
| end if |
| end Sub |
| |
| |
| Sub removeElement() |
| Out.Log("Removing element ... ") |
| ResetCounters() |
| if hasUnoInterfaces(oObj, "com.sun.star.container.XNameContainer") then |
| oObj.RemoveByName(cIfcShortName) |
| elseif hasUnoInterfaces(oContainer, "com.sun.star.container.XNameContainer") then |
| oContainer.RemoveByName(cIfcShortName) |
| elseif hasUnoInterfaces(oContainer, "com.sun.star.awt.XControlContainer") then |
| oContainer.removeControl(oElementToInsert) |
| end if |
| end Sub |
| |
| Function replaceElement() as Boolean |
| Out.Log("Replacing element ... ") |
| ResetCounters() |
| Dim bNothingToReplace as Boolean |
| bNothingToReplace = FALSE |
| Dim old As Variant |
| if hasUnoInterfaces(oObj, "com.sun.star.container.XIndexReplace") then |
| old = oObj.getByIndex(0) |
| oObj.ReplaceByIndex(0, oElementToInsert) |
| oObj.ReplaceByIndex(0, old) |
| elseif hasUnoInterfaces(oContainer, "com.sun.star.container.XIndexReplace") then |
| old = oContainer.getByIndex(0) |
| oContainer.ReplaceByIndex(0, oElementToInsert) |
| oContainer.ReplaceByIndex(0, old) |
| elseif (hasUnoInterfaces(oContainer, "com.sun.star.container.XNameAccess") and _ |
| hasUnoInterfaces(oContainer, "com.sun.star.container.XNameReplace")) then |
| Dim cNames() as String |
| cNames = oObj.getElementNames() |
| old = oContainer.getByName(cNames(0)) |
| oContainer.ReplaceByName(cNames(0), oElementToInsert) |
| oContainer.ReplaceByName(cNames(0), old) |
| elseif hasUnoInterfaces(oContainer, "com.sun.star.awt.XControlContainer") then |
| bNothingToReplace = TRUE |
| else |
| Out.LOG("There is nothig to trigger the Listener!") |
| end if |
| replaceElement() = bNothingToReplace |
| end Function |
| |
| Sub CB1_elementInserted(ev As Object) |
| Out.Log("CB1 called: element was inserted") |
| ElIns1 = ElIns1 + 1 |
| End Sub |
| |
| Sub CB1_elementRemoved(ev As Object) |
| Out.Log("CB1 called: element was removed") |
| ElRem1 = ElRem1 + 1 |
| End Sub |
| |
| Sub CB1_elementReplaced(ev As Object) |
| Out.Log("CB1 called: element was replaced") |
| ElRep1 = ElRep1 + 1 |
| End Sub |
| |
| Sub CB2_elementInserted(ev As Object) |
| Out.Log("CB2 called: element was inserted") |
| ElIns2 = ElIns2 + 1 |
| End Sub |
| |
| Sub CB2_elementRemoved(ev As Object) |
| Out.Log("CB2 called: element was removed") |
| ElRem2 = ElRem2 + 1 |
| End Sub |
| |
| Sub CB2_elementReplaced(ev As Object) |
| Out.Log("CB2 called: element was replaced") |
| ElRep2 = ElRep2 + 1 |
| End Sub |
| |
| Sub ResetCounters() |
| ElIns1 = 0 |
| ElIns2 = 0 |
| ElRem1 = 0 |
| ElRem2 = 0 |
| ElRep1 = 0 |
| ElRep2 = 0 |
| End Sub |
| </script:module> |