blob: f6bb21c603bfa8b626a5319f83741684881cc771 [file] [log] [blame]
<?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">
'*************************************************************************
'
' 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.
'
'*************************************************************************
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>