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="sdb_XRowSetApproveBroadcaster" 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
37Dim iApproveCursorMove1 As Integer
38Dim iApproveCursorMove2 As Integer
39Dim iApproveRowChange1 As Integer
40Dim iApproveRowChange2 As Integer
41Dim iApproveRowSetChange1 As Integer
42Dim iApproveRowSetChange2 As Integer
43
44
45Sub RunTest()
46
47'*************************************************************************
48' INTERFACE:
49' com.sun.star.sdb.XRowSetApproveBroadcaster
50'*************************************************************************
51On Error Goto ErrHndl
52    Dim bOK As Boolean
53
54    Dim oListener1 As Object
55    Dim oListener2 As Object
56    Dim cOrigStr As String
57    Dim cPrevStr As String
58
59    oObj.first()
60    cOrigStr = oObj.getString(1)
61
62    Out.Log("Creating two XRowSetApproveListeners")
63    oListener1 = createUnoListener("CB1_", "com.sun.star.sdb.XRowSetApproveListener")
64    oListener2 = createUnoListener("CB2_", "com.sun.star.sdb.XRowSetApproveListener")
65
66    ResetCounters()
67
68    Test.StartMethod("addRowSetApproveListener()")
69    bOK = true
70    oObj.addRowSetApproveListener(oListener1)
71    oObj.addRowSetApproveListener(oListener2)
72
73    bOK = bOK AND Expected(0, 0, 0, 0, 0, 0)
74
75    Out.Log("Call oObj.execute() - change RowSet")
76    oObj.execute()
77    bOK = bOK AND Expected(0, 0, 0, 0, 1, 1)
78
79    ResetCounters()
80    Out.Log("Call oObj.next() - move cursor")
81    oObj.next()
82    bOK = bOK AND Expected(1, 1, 0, 0, 0, 0)
83
84    Out.Log("Call oObj.updateString() - updating RowSet")
85    oObj.first()
86    ResetCounters()
87    cPrevStr = oObj.getString(1)
88    Out.Log(cPrevStr)
89    oObj.updateString(1, cPrevStr + "+")
90    oObj.updateRow()
91    Out.Log(oObj.getString(1))
92    bOK = bOK AND Expected(0, 0, 1, 1, 0, 0)
93    bOK = bOK AND oObj.getString(1) = cPrevStr + "+"
94
95    Test.MethodTested("addRowSetApproveListener()", bOK)
96
97    ResetCounters()
98
99    Test.StartMethod("removeRowSetApproveListener()")
100    bOK = true
101    Out.Log("Removing only first listener")
102    oObj.removeRowSetApproveListener(oListener1)
103
104    bOK = bOK AND Expected(0, 0, 0, 0, 0, 0)
105
106    Out.Log("Call oObj.execute() - change RowSet")
107    oObj.execute()
108    bOK = bOK AND Expected(0, 0, 0, 0, 0, 1)
109
110    ResetCounters()
111    Out.Log("Call oObj.next() - move cursor")
112    oObj.next()
113    bOK = bOK AND Expected(0, 1, 0, 0, 0, 0)
114
115    ResetCounters()
116    Out.Log("Call oObj.updateString() - updating RowSet")
117    oObj.first()
118    cPrevStr = oObj.getString(1)
119    Out.Log(cPrevStr)
120    oObj.updateString(1, cPrevStr + "+")
121    oObj.updateRow()
122    Out.Log(oObj.getString(1))
123    bOK = bOK AND Expected(0, 0, 0, 1, 0, 0)
124    bOK = bOK AND oObj.getString(1) = cPrevStr + "+"
125
126    Test.MethodTested("removeRowSetApproveListener()", bOK)
127
128    Out.Log("Removing last listener")
129    oObj.removeRowSetApproveListener(oListener2)
130
131    Out.Log("Returning first row back...")
132    oObj.first()
133    oObj.updateString(1, cOrigStr)
134    oObj.updateRow()
135
136Exit Sub
137ErrHndl:
138    Test.Exception()
139    bOK = false
140    resume next
141End Sub
142Function CB1_approveCursorMove(oEvent As Object) As Boolean
143    Out.Log("callback function approveCursorMove() for Listener1 was called!")
144    iApproveCursorMove1 = iApproveCursorMove1 + 1
145    CB1_approveCursorMove() = true
146End Function
147
148Function CB2_approveCursorMove(oEvent As Object) As Boolean
149    Out.Log("callback function approveCursorMove() for Listener2 was called!")
150    iApproveCursorMove2 = iApproveCursorMove2 + 1
151    CB2_approveCursorMove() = true
152End Function
153
154Function CB1_approveRowChange(oEvent As Object) As Boolean
155    Out.Log("callback function approveRowChange() for Listener1 was called!")
156    iApproveRowChange1 = iApproveRowChange1 + 1
157    CB1_approveRowChange() = true
158End Function
159
160Function CB2_approveRowChange(oEvent As Object) As Boolean
161    Out.Log("callback function approveRowChange() for Listener2 was called!")
162    iApproveRowChange2 = iApproveRowChange2 + 1
163    CB2_approveRowChange() = true
164End Function
165
166Function CB1_approveRowSetChange(oEvent As Object) As Boolean
167    Out.Log("callback function approveRowSetChange() for Listener1 was called!")
168    iApproveRowSetChange1 = iApproveRowSetChange1 + 1
169    CB1_approveRowSetChange() = true
170End Function
171
172Function CB2_approveRowSetChange(oEvent As Object) As Boolean
173    Out.Log("callback function approveRowSetChange() for Listener2 was called!")
174    iApproveRowSetChange2 = iApproveRowSetChange2 + 1
175    CB2_approveRowSetChange() = true
176End Function
177
178Sub ResetCounters()
179    Out.Log("Reset counters...")
180    iApproveCursorMove1   = 0
181    iApproveCursorMove2   = 0
182    iApproveRowChange1    = 0
183    iApproveRowChange2    = 0
184    iApproveRowSetChange1 = 0
185    iApproveRowSetChange2 = 0
186End Sub
187
188Function Expected(iApprCursorMove1 As Integer, iApprCursorMove2 As Integer, _
189                  iApprRowChange1  As Integer, iApprRowChange2  As Integer, _
190                  iApprRowSetChange1 As Integer, iApprRowSetChange2 As Integer) As Boolean
191Dim bOK As Boolean
192    bOK = true
193
194    bOK = bOK AND Expected1("approveCursorMove()", 1, iApproveCursorMove1, iApprCursorMove1)
195    bOK = bOK AND Expected1("approveCursorMove()", 2, iApproveCursorMove2, iApprCursorMove2)
196    bOK = bOK AND Expected1("approveRowChange()",  1, iApproveRowChange1, iApprRowChange1)
197    bOK = bOK AND Expected1("approveRowChange()",  2, iApproveRowChange2, iApprRowChange2)
198    bOK = bOK AND Expected1("apprRowSetChange()",  1, iApproveRowSetChange1, iApprRowSetChange1)
199    bOK = bOK AND Expected1("apprRowSetChange()",  2, iApproveRowSetChange2, iApprRowSetChange2)
200    Expected() = bOK
201End Function
202
203Function Expected1(fname As String, ln As Integer, val1 As Integer, val2 As Integer) As Boolean
204    Dim bOK As Integer
205
206    bOK = true
207    if (val1 &lt;&gt; val2) then
208        Out.Log(fname + " of Listener" + ln + " was called " + val1 + " time(s), "_
209               + "but it should be called " + val2 + " time(s).")
210        bOK = false
211    end if
212    Expected1() = bOK
213End Function
214</script:module>
215