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