1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="sdb_XRowSetApproveBroadcaster" script:language="StarBasic">
4cdf0e10cSrcweir
5cdf0e10cSrcweir
6cdf0e10cSrcweir'*************************************************************************
7cdf0e10cSrcweir'
8*3709053cSAndrew Rist'  Licensed to the Apache Software Foundation (ASF) under one
9*3709053cSAndrew Rist'  or more contributor license agreements.  See the NOTICE file
10*3709053cSAndrew Rist'  distributed with this work for additional information
11*3709053cSAndrew Rist'  regarding copyright ownership.  The ASF licenses this file
12*3709053cSAndrew Rist'  to you under the Apache License, Version 2.0 (the
13*3709053cSAndrew Rist'  "License"); you may not use this file except in compliance
14*3709053cSAndrew Rist'  with the License.  You may obtain a copy of the License at
15*3709053cSAndrew Rist'
16*3709053cSAndrew Rist'    http://www.apache.org/licenses/LICENSE-2.0
17*3709053cSAndrew Rist'
18*3709053cSAndrew Rist'  Unless required by applicable law or agreed to in writing,
19*3709053cSAndrew Rist'  software distributed under the License is distributed on an
20*3709053cSAndrew Rist'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*3709053cSAndrew Rist'  KIND, either express or implied.  See the License for the
22*3709053cSAndrew Rist'  specific language governing permissions and limitations
23*3709053cSAndrew Rist'  under the License.
24cdf0e10cSrcweir'
25cdf0e10cSrcweir'*************************************************************************
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30*3709053cSAndrew Rist
31*3709053cSAndrew Rist
32cdf0e10cSrcweirDim iApproveCursorMove1 As Integer
33cdf0e10cSrcweirDim iApproveCursorMove2 As Integer
34cdf0e10cSrcweirDim iApproveRowChange1 As Integer
35cdf0e10cSrcweirDim iApproveRowChange2 As Integer
36cdf0e10cSrcweirDim iApproveRowSetChange1 As Integer
37cdf0e10cSrcweirDim iApproveRowSetChange2 As Integer
38cdf0e10cSrcweir
39cdf0e10cSrcweir
40cdf0e10cSrcweirSub RunTest()
41cdf0e10cSrcweir
42cdf0e10cSrcweir'*************************************************************************
43cdf0e10cSrcweir' INTERFACE:
44cdf0e10cSrcweir' com.sun.star.sdb.XRowSetApproveBroadcaster
45cdf0e10cSrcweir'*************************************************************************
46cdf0e10cSrcweirOn Error Goto ErrHndl
47cdf0e10cSrcweir    Dim bOK As Boolean
48cdf0e10cSrcweir
49cdf0e10cSrcweir    Dim oListener1 As Object
50cdf0e10cSrcweir    Dim oListener2 As Object
51cdf0e10cSrcweir    Dim cOrigStr As String
52cdf0e10cSrcweir    Dim cPrevStr As String
53cdf0e10cSrcweir
54cdf0e10cSrcweir    oObj.first()
55cdf0e10cSrcweir    cOrigStr = oObj.getString(1)
56cdf0e10cSrcweir
57cdf0e10cSrcweir    Out.Log("Creating two XRowSetApproveListeners")
58cdf0e10cSrcweir    oListener1 = createUnoListener("CB1_", "com.sun.star.sdb.XRowSetApproveListener")
59cdf0e10cSrcweir    oListener2 = createUnoListener("CB2_", "com.sun.star.sdb.XRowSetApproveListener")
60cdf0e10cSrcweir
61cdf0e10cSrcweir    ResetCounters()
62cdf0e10cSrcweir
63cdf0e10cSrcweir    Test.StartMethod("addRowSetApproveListener()")
64cdf0e10cSrcweir    bOK = true
65cdf0e10cSrcweir    oObj.addRowSetApproveListener(oListener1)
66cdf0e10cSrcweir    oObj.addRowSetApproveListener(oListener2)
67cdf0e10cSrcweir
68cdf0e10cSrcweir    bOK = bOK AND Expected(0, 0, 0, 0, 0, 0)
69cdf0e10cSrcweir
70cdf0e10cSrcweir    Out.Log("Call oObj.execute() - change RowSet")
71cdf0e10cSrcweir    oObj.execute()
72cdf0e10cSrcweir    bOK = bOK AND Expected(0, 0, 0, 0, 1, 1)
73cdf0e10cSrcweir
74cdf0e10cSrcweir    ResetCounters()
75cdf0e10cSrcweir    Out.Log("Call oObj.next() - move cursor")
76cdf0e10cSrcweir    oObj.next()
77cdf0e10cSrcweir    bOK = bOK AND Expected(1, 1, 0, 0, 0, 0)
78cdf0e10cSrcweir
79cdf0e10cSrcweir    Out.Log("Call oObj.updateString() - updating RowSet")
80cdf0e10cSrcweir    oObj.first()
81cdf0e10cSrcweir    ResetCounters()
82cdf0e10cSrcweir    cPrevStr = oObj.getString(1)
83cdf0e10cSrcweir    Out.Log(cPrevStr)
84cdf0e10cSrcweir    oObj.updateString(1, cPrevStr + "+")
85cdf0e10cSrcweir    oObj.updateRow()
86cdf0e10cSrcweir    Out.Log(oObj.getString(1))
87cdf0e10cSrcweir    bOK = bOK AND Expected(0, 0, 1, 1, 0, 0)
88cdf0e10cSrcweir    bOK = bOK AND oObj.getString(1) = cPrevStr + "+"
89cdf0e10cSrcweir
90cdf0e10cSrcweir    Test.MethodTested("addRowSetApproveListener()", bOK)
91cdf0e10cSrcweir
92cdf0e10cSrcweir    ResetCounters()
93cdf0e10cSrcweir
94cdf0e10cSrcweir    Test.StartMethod("removeRowSetApproveListener()")
95cdf0e10cSrcweir    bOK = true
96cdf0e10cSrcweir    Out.Log("Removing only first listener")
97cdf0e10cSrcweir    oObj.removeRowSetApproveListener(oListener1)
98cdf0e10cSrcweir
99cdf0e10cSrcweir    bOK = bOK AND Expected(0, 0, 0, 0, 0, 0)
100cdf0e10cSrcweir
101cdf0e10cSrcweir    Out.Log("Call oObj.execute() - change RowSet")
102cdf0e10cSrcweir    oObj.execute()
103cdf0e10cSrcweir    bOK = bOK AND Expected(0, 0, 0, 0, 0, 1)
104cdf0e10cSrcweir
105cdf0e10cSrcweir    ResetCounters()
106cdf0e10cSrcweir    Out.Log("Call oObj.next() - move cursor")
107cdf0e10cSrcweir    oObj.next()
108cdf0e10cSrcweir    bOK = bOK AND Expected(0, 1, 0, 0, 0, 0)
109cdf0e10cSrcweir
110cdf0e10cSrcweir    ResetCounters()
111cdf0e10cSrcweir    Out.Log("Call oObj.updateString() - updating RowSet")
112cdf0e10cSrcweir    oObj.first()
113cdf0e10cSrcweir    cPrevStr = oObj.getString(1)
114cdf0e10cSrcweir    Out.Log(cPrevStr)
115cdf0e10cSrcweir    oObj.updateString(1, cPrevStr + "+")
116cdf0e10cSrcweir    oObj.updateRow()
117cdf0e10cSrcweir    Out.Log(oObj.getString(1))
118cdf0e10cSrcweir    bOK = bOK AND Expected(0, 0, 0, 1, 0, 0)
119cdf0e10cSrcweir    bOK = bOK AND oObj.getString(1) = cPrevStr + "+"
120cdf0e10cSrcweir
121cdf0e10cSrcweir    Test.MethodTested("removeRowSetApproveListener()", bOK)
122cdf0e10cSrcweir
123cdf0e10cSrcweir    Out.Log("Removing last listener")
124cdf0e10cSrcweir    oObj.removeRowSetApproveListener(oListener2)
125cdf0e10cSrcweir
126cdf0e10cSrcweir    Out.Log("Returning first row back...")
127cdf0e10cSrcweir    oObj.first()
128cdf0e10cSrcweir    oObj.updateString(1, cOrigStr)
129cdf0e10cSrcweir    oObj.updateRow()
130cdf0e10cSrcweir
131cdf0e10cSrcweirExit Sub
132cdf0e10cSrcweirErrHndl:
133cdf0e10cSrcweir    Test.Exception()
134cdf0e10cSrcweir    bOK = false
135cdf0e10cSrcweir    resume next
136cdf0e10cSrcweirEnd Sub
137cdf0e10cSrcweirFunction CB1_approveCursorMove(oEvent As Object) As Boolean
138cdf0e10cSrcweir    Out.Log("callback function approveCursorMove() for Listener1 was called!")
139cdf0e10cSrcweir    iApproveCursorMove1 = iApproveCursorMove1 + 1
140cdf0e10cSrcweir    CB1_approveCursorMove() = true
141cdf0e10cSrcweirEnd Function
142cdf0e10cSrcweir
143cdf0e10cSrcweirFunction CB2_approveCursorMove(oEvent As Object) As Boolean
144cdf0e10cSrcweir    Out.Log("callback function approveCursorMove() for Listener2 was called!")
145cdf0e10cSrcweir    iApproveCursorMove2 = iApproveCursorMove2 + 1
146cdf0e10cSrcweir    CB2_approveCursorMove() = true
147cdf0e10cSrcweirEnd Function
148cdf0e10cSrcweir
149cdf0e10cSrcweirFunction CB1_approveRowChange(oEvent As Object) As Boolean
150cdf0e10cSrcweir    Out.Log("callback function approveRowChange() for Listener1 was called!")
151cdf0e10cSrcweir    iApproveRowChange1 = iApproveRowChange1 + 1
152cdf0e10cSrcweir    CB1_approveRowChange() = true
153cdf0e10cSrcweirEnd Function
154cdf0e10cSrcweir
155cdf0e10cSrcweirFunction CB2_approveRowChange(oEvent As Object) As Boolean
156cdf0e10cSrcweir    Out.Log("callback function approveRowChange() for Listener2 was called!")
157cdf0e10cSrcweir    iApproveRowChange2 = iApproveRowChange2 + 1
158cdf0e10cSrcweir    CB2_approveRowChange() = true
159cdf0e10cSrcweirEnd Function
160cdf0e10cSrcweir
161cdf0e10cSrcweirFunction CB1_approveRowSetChange(oEvent As Object) As Boolean
162cdf0e10cSrcweir    Out.Log("callback function approveRowSetChange() for Listener1 was called!")
163cdf0e10cSrcweir    iApproveRowSetChange1 = iApproveRowSetChange1 + 1
164cdf0e10cSrcweir    CB1_approveRowSetChange() = true
165cdf0e10cSrcweirEnd Function
166cdf0e10cSrcweir
167cdf0e10cSrcweirFunction CB2_approveRowSetChange(oEvent As Object) As Boolean
168cdf0e10cSrcweir    Out.Log("callback function approveRowSetChange() for Listener2 was called!")
169cdf0e10cSrcweir    iApproveRowSetChange2 = iApproveRowSetChange2 + 1
170cdf0e10cSrcweir    CB2_approveRowSetChange() = true
171cdf0e10cSrcweirEnd Function
172cdf0e10cSrcweir
173cdf0e10cSrcweirSub ResetCounters()
174cdf0e10cSrcweir    Out.Log("Reset counters...")
175cdf0e10cSrcweir    iApproveCursorMove1   = 0
176cdf0e10cSrcweir    iApproveCursorMove2   = 0
177cdf0e10cSrcweir    iApproveRowChange1    = 0
178cdf0e10cSrcweir    iApproveRowChange2    = 0
179cdf0e10cSrcweir    iApproveRowSetChange1 = 0
180cdf0e10cSrcweir    iApproveRowSetChange2 = 0
181cdf0e10cSrcweirEnd Sub
182cdf0e10cSrcweir
183cdf0e10cSrcweirFunction Expected(iApprCursorMove1 As Integer, iApprCursorMove2 As Integer, _
184cdf0e10cSrcweir                  iApprRowChange1  As Integer, iApprRowChange2  As Integer, _
185cdf0e10cSrcweir                  iApprRowSetChange1 As Integer, iApprRowSetChange2 As Integer) As Boolean
186cdf0e10cSrcweirDim bOK As Boolean
187cdf0e10cSrcweir    bOK = true
188cdf0e10cSrcweir
189cdf0e10cSrcweir    bOK = bOK AND Expected1("approveCursorMove()", 1, iApproveCursorMove1, iApprCursorMove1)
190cdf0e10cSrcweir    bOK = bOK AND Expected1("approveCursorMove()", 2, iApproveCursorMove2, iApprCursorMove2)
191cdf0e10cSrcweir    bOK = bOK AND Expected1("approveRowChange()",  1, iApproveRowChange1, iApprRowChange1)
192cdf0e10cSrcweir    bOK = bOK AND Expected1("approveRowChange()",  2, iApproveRowChange2, iApprRowChange2)
193cdf0e10cSrcweir    bOK = bOK AND Expected1("apprRowSetChange()",  1, iApproveRowSetChange1, iApprRowSetChange1)
194cdf0e10cSrcweir    bOK = bOK AND Expected1("apprRowSetChange()",  2, iApproveRowSetChange2, iApprRowSetChange2)
195cdf0e10cSrcweir    Expected() = bOK
196cdf0e10cSrcweirEnd Function
197cdf0e10cSrcweir
198cdf0e10cSrcweirFunction Expected1(fname As String, ln As Integer, val1 As Integer, val2 As Integer) As Boolean
199cdf0e10cSrcweir    Dim bOK As Integer
200cdf0e10cSrcweir
201cdf0e10cSrcweir    bOK = true
202cdf0e10cSrcweir    if (val1 &lt;&gt; val2) then
203cdf0e10cSrcweir        Out.Log(fname + " of Listener" + ln + " was called " + val1 + " time(s), "_
204cdf0e10cSrcweir               + "but it should be called " + val2 + " time(s).")
205cdf0e10cSrcweir        bOK = false
206cdf0e10cSrcweir    end if
207cdf0e10cSrcweir    Expected1() = bOK
208cdf0e10cSrcweirEnd Function
209cdf0e10cSrcweir</script:module>
210