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="io_XActiveDataControl" 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'************************************************************************* 38' This Interface/Service test depends on the following GLOBAL variables, 39' which must be specified in the object creation: 40 41' - Global oPipe As Object 42' - Global PumpOUTFileName As String 43 44'************************************************************************* 45 46 47 48 49Dim oListener1 As Object 50Dim oListener2 As Object 51Dim CB1Started As Integer 52Dim CB1Closed As Integer 53Dim CB1Terminated As Integer 54Dim CB1Error As Integer 55Dim CB2Started As Integer 56Dim CB2Closed As Integer 57Dim CB2Terminated As Integer 58Dim CB2Error As Integer 59 60 61Sub RunTest() 62 63'************************************************************************* 64' INTERFACE: 65' com.sun.star.io.XActiveDataControl 66'************************************************************************* 67On Error Goto ErrHndl 68 Dim bOK As Boolean 69 Dim iSize As Integer 70 71 oFileAcc = createUnoService("com.sun.star.ucb.SimpleFileAccess") 72 73 Dim aBytes(10) As Integer 74 for i = 0 to ubound(aBytes()) 75 aBytes(i) = i * 3 76 next i 77 78 Test.StartMethod("start()") 79 Test.StartMethod("terminate()") 80 bOK = true 81 82 Out.Log("Writing some bytes to Pipe") 83 84 oPipe.writeBytes(aBytes()) 85 86 Out.Log("The pump was not started yet. So, PumpOUT should be of zero size") 87 Out.Log("Terminating a pipe to have an opportunity to get a file size") 88 oObj.terminate() 89 90 iSize = oFileAcc.getSize(PumpOUTFileName) 91 Out.Log("Size of file is " & iSize) 92 bOK = bOK AND iSize = 0 93 DisposeObj() 94 CreateObj() 95 96 Out.Log("Writing bytes again (because object was destroyed)") 97 oPipe.writeBytes(aBytes()) 98 Out.Log("... and starting pump") 99 oObj.start() 100 wait(100) 101 Out.Log("Now PumpOUT should have size " & ubound(aBytes()) + 1) 102 Out.Log("Terminating a pipe to have an opportunity to get a file size") 103 oObj.terminate() 104 iSize = oFileAcc.getSize(PumpOUTFileName) 105 Out.Log("Size of file is " & iSize) 106 bOK = bOK AND iSize = ubound(aBytes()) + 1 107 108 Test.MethodTested("start()", bOK) 109 Test.MethodTested("terminate()", bOK) 110 111 DisposeObj() 112 CreateObj() 113 ResetCounters() 114 115 oListener1 = createUnoListener("CB1_", "com.sun.star.io.XStreamListener") 116 oListener2 = createUnoListener("CB2_", "com.sun.star.io.XStreamListener") 117 118 Test.StartMethod("addListener()") 119 bOK = true 120 Out.Log("adding two listeners") 121 oObj.addListener(oListener1) 122 oObj.addListener(oListener2) 123 oPipe.writeBytes(aBytes()) 124 oObj.start() 125 wait(100) ' for listeners to change counters 126 bOK = CB1Started = 1 AND CB2Started = 1 127 Test.MethodTested("addListener()", bOK) 128 129 DisposeObj() 130 CreateObj() 131 ResetCounters() 132 133 Test.StartMethod("removeListener()") 134 bOK = true 135 Out.Log("adding two listeners") 136 oObj.addListener(oListener1) 137 oObj.addListener(oListener2) 138 Out.Log("Removing first listener...") 139 oObj.removeListener(oListener1) 140 oPipe.writeBytes(aBytes()) 141 oObj.start() 142 wait(100) 143 bOK = CB1Started = 0 AND CB2Started = 1 144 Test.MethodTested("removeListener()", bOK) 145 DisposeObj() 146 CreateObj() 147 148Exit Sub 149ErrHndl: 150 Test.Exception() 151 bOK = false 152 resume next 153End Sub 154 155Sub ResetCounters() 156 CB1Started = 0 157 CB1Closed = 0 158 CB1Terminated = 0 159 CB1Error = 0 160 CB2Started = 0 161 CB2Closed = 0 162 CB2Terminated = 0 163 CB2Error = 0 164End Sub 165 166Sub CB1_Started() 167 Out.Log("CB1_Started called") 168 CB1Started = CB1Started + 1 169End Sub 170 171Sub CB2_Started() 172 Out.Log("CB2_Started called") 173 CB2Started = CB2Started + 1 174End Sub 175 176Sub CB1_Closed() 177 Out.Log("CB1_Closed called") 178 CB1Closed = CB1Closed + 1 179End Sub 180 181Sub CB2_Closed() 182 Out.Log("CB2_Closed called") 183 CB2Closed = CB2Closed + 1 184End Sub 185 186Sub CB1_Terminated() 187 Out.Log("CB1_Terminated called") 188 CB1Terminated = CB1Terminated + 1 189End Sub 190 191Sub CB2_Terminated() 192 Out.Log("CB2_Terminated called") 193 CB2Terminated = CB2Terminated + 1 194End Sub 195 196Sub CB1_Error(aError As Object) 197 Out.Log("CB1_Error called") 198 CB1Error = CB1Error + 1 199End Sub 200 201Sub CB2_Error(aError As Object) 202 Out.Log("CB2_Error called") 203 CB2Error = CB2Error + 1 204End Sub 205</script:module> 206