'************************************************************************* ' ' 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 ' ' 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 <> 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