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