summaryrefslogtreecommitdiff
path: root/qadevOOo/tests/basic/ifc/sdb/XRowSetApproveBroadcaster/sdb_XRowSetApproveBroadcaster.xba
blob: ba32a84bb2b3ffacd74dd2b0ade9c3334dcfc734 (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
<?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="sdb_XRowSetApproveBroadcaster" 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.
'
'*************************************************************************
'*************************************************************************




Dim iApproveCursorMove1 As Integer
Dim iApproveCursorMove2 As Integer
Dim iApproveRowChange1 As Integer
Dim iApproveRowChange2 As Integer
Dim iApproveRowSetChange1 As Integer
Dim iApproveRowSetChange2 As Integer


Sub RunTest()

'*************************************************************************
' INTERFACE: 
' com.sun.star.sdb.XRowSetApproveBroadcaster
'*************************************************************************
On Error Goto ErrHndl
    Dim bOK As Boolean

    Dim oListener1 As Object
    Dim oListener2 As Object
    Dim cOrigStr As String
    Dim cPrevStr As String

    oObj.first()
    cOrigStr = oObj.getString(1)

    Out.Log("Creating two XRowSetApproveListeners")
    oListener1 = createUnoListener("CB1_", "com.sun.star.sdb.XRowSetApproveListener")
    oListener2 = createUnoListener("CB2_", "com.sun.star.sdb.XRowSetApproveListener")

    ResetCounters()

    Test.StartMethod("addRowSetApproveListener()")
    bOK = true
    oObj.addRowSetApproveListener(oListener1)
    oObj.addRowSetApproveListener(oListener2)

    bOK = bOK AND Expected(0, 0, 0, 0, 0, 0)

    Out.Log("Call oObj.execute() - change RowSet")
    oObj.execute()
    bOK = bOK AND Expected(0, 0, 0, 0, 1, 1)

    ResetCounters()
    Out.Log("Call oObj.next() - move cursor")
    oObj.next()
    bOK = bOK AND Expected(1, 1, 0, 0, 0, 0)

    Out.Log("Call oObj.updateString() - updating RowSet")
    oObj.first()
    ResetCounters()
    cPrevStr = oObj.getString(1)
    Out.Log(cPrevStr)
    oObj.updateString(1, cPrevStr + "+")
    oObj.updateRow()
    Out.Log(oObj.getString(1))
    bOK = bOK AND Expected(0, 0, 1, 1, 0, 0)
    bOK = bOK AND oObj.getString(1) = cPrevStr + "+"

    Test.MethodTested("addRowSetApproveListener()", bOK)

    ResetCounters()

    Test.StartMethod("removeRowSetApproveListener()")
    bOK = true
    Out.Log("Removing only first listener")
    oObj.removeRowSetApproveListener(oListener1)

    bOK = bOK AND Expected(0, 0, 0, 0, 0, 0)

    Out.Log("Call oObj.execute() - change RowSet")
    oObj.execute()
    bOK = bOK AND Expected(0, 0, 0, 0, 0, 1)

    ResetCounters()
    Out.Log("Call oObj.next() - move cursor")
    oObj.next()
    bOK = bOK AND Expected(0, 1, 0, 0, 0, 0)

    ResetCounters()
    Out.Log("Call oObj.updateString() - updating RowSet")
    oObj.first()
    cPrevStr = oObj.getString(1)
    Out.Log(cPrevStr)
    oObj.updateString(1, cPrevStr + "+")
    oObj.updateRow()
    Out.Log(oObj.getString(1))
    bOK = bOK AND Expected(0, 0, 0, 1, 0, 0)
    bOK = bOK AND oObj.getString(1) = cPrevStr + "+"

    Test.MethodTested("removeRowSetApproveListener()", bOK)

    Out.Log("Removing last listener")
    oObj.removeRowSetApproveListener(oListener2)

    Out.Log("Returning first row back...")
    oObj.first()
    oObj.updateString(1, cOrigStr)
    oObj.updateRow()

Exit Sub
ErrHndl:
    Test.Exception()
    bOK = false
    resume next
End Sub
Function CB1_approveCursorMove(oEvent As Object) As Boolean
    Out.Log("callback function approveCursorMove() for Listener1 was called!")
    iApproveCursorMove1 = iApproveCursorMove1 + 1
    CB1_approveCursorMove() = true
End Function

Function CB2_approveCursorMove(oEvent As Object) As Boolean
    Out.Log("callback function approveCursorMove() for Listener2 was called!")
    iApproveCursorMove2 = iApproveCursorMove2 + 1
    CB2_approveCursorMove() = true
End Function

Function CB1_approveRowChange(oEvent As Object) As Boolean
    Out.Log("callback function approveRowChange() for Listener1 was called!")
    iApproveRowChange1 = iApproveRowChange1 + 1
    CB1_approveRowChange() = true
End Function

Function CB2_approveRowChange(oEvent As Object) As Boolean
    Out.Log("callback function approveRowChange() for Listener2 was called!")
    iApproveRowChange2 = iApproveRowChange2 + 1
    CB2_approveRowChange() = true
End Function

Function CB1_approveRowSetChange(oEvent As Object) As Boolean
    Out.Log("callback function approveRowSetChange() for Listener1 was called!")
    iApproveRowSetChange1 = iApproveRowSetChange1 + 1
    CB1_approveRowSetChange() = true
End Function

Function CB2_approveRowSetChange(oEvent As Object) As Boolean
    Out.Log("callback function approveRowSetChange() for Listener2 was called!")
    iApproveRowSetChange2 = iApproveRowSetChange2 + 1
    CB2_approveRowSetChange() = true
End Function

Sub ResetCounters()
    Out.Log("Reset counters...")
    iApproveCursorMove1   = 0
    iApproveCursorMove2   = 0
    iApproveRowChange1    = 0
    iApproveRowChange2    = 0
    iApproveRowSetChange1 = 0
    iApproveRowSetChange2 = 0
End Sub

Function Expected(iApprCursorMove1 As Integer, iApprCursorMove2 As Integer, _
                  iApprRowChange1  As Integer, iApprRowChange2  As Integer, _
                  iApprRowSetChange1 As Integer, iApprRowSetChange2 As Integer) As Boolean
Dim bOK As Boolean
    bOK = true

    bOK = bOK AND Expected1("approveCursorMove()", 1, iApproveCursorMove1, iApprCursorMove1)
    bOK = bOK AND Expected1("approveCursorMove()", 2, iApproveCursorMove2, iApprCursorMove2)
    bOK = bOK AND Expected1("approveRowChange()",  1, iApproveRowChange1, iApprRowChange1)
    bOK = bOK AND Expected1("approveRowChange()",  2, iApproveRowChange2, iApprRowChange2)
    bOK = bOK AND Expected1("apprRowSetChange()",  1, iApproveRowSetChange1, iApprRowSetChange1)
    bOK = bOK AND Expected1("apprRowSetChange()",  2, iApproveRowSetChange2, iApprRowSetChange2)
    Expected() = bOK
End Function

Function Expected1(fname As String, ln As Integer, val1 As Integer, val2 As Integer) As Boolean
    Dim bOK As Integer

    bOK = true
    if (val1 &lt;&gt; val2) then
        Out.Log(fname + " of Listener" + ln + " was called " + val1 + " time(s), "_
               + "but it should be called " + val2 + " time(s).")
        bOK = false
    end if
    Expected1() = bOK
End Function
</script:module>