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