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