summaryrefslogtreecommitdiff
path: root/qadevOOo/tests/basic/ifc/container/XContainer/container_XContainer.xba
blob: 2dd3e397d408c77654ef40835d6aa9e85ae1ed39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?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">


'*************************************************************************
'
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
' 
' Copyright 2000, 2010 Oracle and/or its affiliates.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org.  If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 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>