1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="io_XActiveDataControl" script:language="StarBasic">
4cdf0e10cSrcweir
5cdf0e10cSrcweir
6cdf0e10cSrcweir'*************************************************************************
7cdf0e10cSrcweir'
8*3e6afcd2SAndrew Rist'  Licensed to the Apache Software Foundation (ASF) under one
9*3e6afcd2SAndrew Rist'  or more contributor license agreements.  See the NOTICE file
10*3e6afcd2SAndrew Rist'  distributed with this work for additional information
11*3e6afcd2SAndrew Rist'  regarding copyright ownership.  The ASF licenses this file
12*3e6afcd2SAndrew Rist'  to you under the Apache License, Version 2.0 (the
13*3e6afcd2SAndrew Rist'  "License"); you may not use this file except in compliance
14*3e6afcd2SAndrew Rist'  with the License.  You may obtain a copy of the License at
15*3e6afcd2SAndrew Rist'
16*3e6afcd2SAndrew Rist'    http://www.apache.org/licenses/LICENSE-2.0
17*3e6afcd2SAndrew Rist'
18*3e6afcd2SAndrew Rist'  Unless required by applicable law or agreed to in writing,
19*3e6afcd2SAndrew Rist'  software distributed under the License is distributed on an
20*3e6afcd2SAndrew Rist'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*3e6afcd2SAndrew Rist'  KIND, either express or implied.  See the License for the
22*3e6afcd2SAndrew Rist'  specific language governing permissions and limitations
23*3e6afcd2SAndrew Rist'  under the License.
24cdf0e10cSrcweir'
25cdf0e10cSrcweir'*************************************************************************
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29*3e6afcd2SAndrew Rist
30*3e6afcd2SAndrew Rist
31cdf0e10cSrcweir'*************************************************************************
32cdf0e10cSrcweir' This Interface/Service test depends on the following GLOBAL variables,
33cdf0e10cSrcweir' which must be specified in the object creation:
34cdf0e10cSrcweir
35cdf0e10cSrcweir'     - Global oPipe As Object
36cdf0e10cSrcweir'     - Global PumpOUTFileName As String
37cdf0e10cSrcweir
38cdf0e10cSrcweir'*************************************************************************
39cdf0e10cSrcweir
40cdf0e10cSrcweir
41cdf0e10cSrcweir
42cdf0e10cSrcweir
43cdf0e10cSrcweirDim oListener1 As Object
44cdf0e10cSrcweirDim oListener2 As Object
45cdf0e10cSrcweirDim CB1Started As Integer
46cdf0e10cSrcweirDim CB1Closed As Integer
47cdf0e10cSrcweirDim CB1Terminated As Integer
48cdf0e10cSrcweirDim CB1Error As Integer
49cdf0e10cSrcweirDim CB2Started As Integer
50cdf0e10cSrcweirDim CB2Closed As Integer
51cdf0e10cSrcweirDim CB2Terminated As Integer
52cdf0e10cSrcweirDim CB2Error As Integer
53cdf0e10cSrcweir
54cdf0e10cSrcweir
55cdf0e10cSrcweirSub RunTest()
56cdf0e10cSrcweir
57cdf0e10cSrcweir'*************************************************************************
58cdf0e10cSrcweir' INTERFACE:
59cdf0e10cSrcweir' com.sun.star.io.XActiveDataControl
60cdf0e10cSrcweir'*************************************************************************
61cdf0e10cSrcweirOn Error Goto ErrHndl
62cdf0e10cSrcweir    Dim bOK As Boolean
63cdf0e10cSrcweir    Dim iSize As Integer
64cdf0e10cSrcweir
65cdf0e10cSrcweir    oFileAcc = createUnoService("com.sun.star.ucb.SimpleFileAccess")
66cdf0e10cSrcweir
67cdf0e10cSrcweir    Dim aBytes(10) As Integer
68cdf0e10cSrcweir    for i = 0 to ubound(aBytes())
69cdf0e10cSrcweir        aBytes(i) = i * 3
70cdf0e10cSrcweir    next i
71cdf0e10cSrcweir
72cdf0e10cSrcweir    Test.StartMethod("start()")
73cdf0e10cSrcweir    Test.StartMethod("terminate()")
74cdf0e10cSrcweir    bOK = true
75cdf0e10cSrcweir
76cdf0e10cSrcweir    Out.Log("Writing some bytes to Pipe")
77cdf0e10cSrcweir
78cdf0e10cSrcweir    oPipe.writeBytes(aBytes())
79cdf0e10cSrcweir
80cdf0e10cSrcweir    Out.Log("The pump was not started yet. So, PumpOUT should be of zero size")
81cdf0e10cSrcweir    Out.Log("Terminating a pipe to have an opportunity to get a file size")
82cdf0e10cSrcweir    oObj.terminate()
83cdf0e10cSrcweir
84cdf0e10cSrcweir    iSize = oFileAcc.getSize(PumpOUTFileName)
85cdf0e10cSrcweir    Out.Log("Size of file is " &amp; iSize)
86cdf0e10cSrcweir    bOK = bOK AND iSize = 0
87cdf0e10cSrcweir    DisposeObj()
88cdf0e10cSrcweir    CreateObj()
89cdf0e10cSrcweir
90cdf0e10cSrcweir    Out.Log("Writing bytes again (because object was destroyed)")
91cdf0e10cSrcweir    oPipe.writeBytes(aBytes())
92cdf0e10cSrcweir    Out.Log("... and starting pump")
93cdf0e10cSrcweir    oObj.start()
94cdf0e10cSrcweir    wait(100)
95cdf0e10cSrcweir    Out.Log("Now PumpOUT should have size " &amp; ubound(aBytes()) + 1)
96cdf0e10cSrcweir    Out.Log("Terminating a pipe to have an opportunity to get a file size")
97cdf0e10cSrcweir    oObj.terminate()
98cdf0e10cSrcweir    iSize = oFileAcc.getSize(PumpOUTFileName)
99cdf0e10cSrcweir    Out.Log("Size of file is " &amp; iSize)
100cdf0e10cSrcweir    bOK = bOK AND iSize = ubound(aBytes()) + 1
101cdf0e10cSrcweir
102cdf0e10cSrcweir    Test.MethodTested("start()", bOK)
103cdf0e10cSrcweir    Test.MethodTested("terminate()", bOK)
104cdf0e10cSrcweir
105cdf0e10cSrcweir    DisposeObj()
106cdf0e10cSrcweir    CreateObj()
107cdf0e10cSrcweir    ResetCounters()
108cdf0e10cSrcweir
109cdf0e10cSrcweir    oListener1 = createUnoListener("CB1_", "com.sun.star.io.XStreamListener")
110cdf0e10cSrcweir    oListener2 = createUnoListener("CB2_", "com.sun.star.io.XStreamListener")
111cdf0e10cSrcweir
112cdf0e10cSrcweir    Test.StartMethod("addListener()")
113cdf0e10cSrcweir    bOK = true
114cdf0e10cSrcweir    Out.Log("adding two listeners")
115cdf0e10cSrcweir    oObj.addListener(oListener1)
116cdf0e10cSrcweir    oObj.addListener(oListener2)
117cdf0e10cSrcweir    oPipe.writeBytes(aBytes())
118cdf0e10cSrcweir    oObj.start()
119cdf0e10cSrcweir    wait(100) ' for listeners to change counters
120cdf0e10cSrcweir    bOK = CB1Started = 1 AND CB2Started = 1
121cdf0e10cSrcweir    Test.MethodTested("addListener()", bOK)
122cdf0e10cSrcweir
123cdf0e10cSrcweir    DisposeObj()
124cdf0e10cSrcweir    CreateObj()
125cdf0e10cSrcweir    ResetCounters()
126cdf0e10cSrcweir
127cdf0e10cSrcweir    Test.StartMethod("removeListener()")
128cdf0e10cSrcweir    bOK = true
129cdf0e10cSrcweir    Out.Log("adding two listeners")
130cdf0e10cSrcweir    oObj.addListener(oListener1)
131cdf0e10cSrcweir    oObj.addListener(oListener2)
132cdf0e10cSrcweir    Out.Log("Removing first listener...")
133cdf0e10cSrcweir    oObj.removeListener(oListener1)
134cdf0e10cSrcweir    oPipe.writeBytes(aBytes())
135cdf0e10cSrcweir    oObj.start()
136cdf0e10cSrcweir    wait(100)
137cdf0e10cSrcweir    bOK = CB1Started = 0 AND CB2Started = 1
138cdf0e10cSrcweir    Test.MethodTested("removeListener()", bOK)
139cdf0e10cSrcweir    DisposeObj()
140cdf0e10cSrcweir    CreateObj()
141cdf0e10cSrcweir
142cdf0e10cSrcweirExit Sub
143cdf0e10cSrcweirErrHndl:
144cdf0e10cSrcweir    Test.Exception()
145cdf0e10cSrcweir    bOK = false
146cdf0e10cSrcweir    resume next
147cdf0e10cSrcweirEnd Sub
148cdf0e10cSrcweir
149cdf0e10cSrcweirSub ResetCounters()
150cdf0e10cSrcweir    CB1Started = 0
151cdf0e10cSrcweir    CB1Closed = 0
152cdf0e10cSrcweir    CB1Terminated = 0
153cdf0e10cSrcweir    CB1Error = 0
154cdf0e10cSrcweir    CB2Started = 0
155cdf0e10cSrcweir    CB2Closed = 0
156cdf0e10cSrcweir    CB2Terminated = 0
157cdf0e10cSrcweir    CB2Error = 0
158cdf0e10cSrcweirEnd Sub
159cdf0e10cSrcweir
160cdf0e10cSrcweirSub CB1_Started()
161cdf0e10cSrcweir    Out.Log("CB1_Started called")
162cdf0e10cSrcweir    CB1Started = CB1Started + 1
163cdf0e10cSrcweirEnd Sub
164cdf0e10cSrcweir
165cdf0e10cSrcweirSub CB2_Started()
166cdf0e10cSrcweir    Out.Log("CB2_Started called")
167cdf0e10cSrcweir    CB2Started = CB2Started + 1
168cdf0e10cSrcweirEnd Sub
169cdf0e10cSrcweir
170cdf0e10cSrcweirSub CB1_Closed()
171cdf0e10cSrcweir    Out.Log("CB1_Closed called")
172cdf0e10cSrcweir    CB1Closed = CB1Closed + 1
173cdf0e10cSrcweirEnd Sub
174cdf0e10cSrcweir
175cdf0e10cSrcweirSub CB2_Closed()
176cdf0e10cSrcweir    Out.Log("CB2_Closed called")
177cdf0e10cSrcweir    CB2Closed = CB2Closed + 1
178cdf0e10cSrcweirEnd Sub
179cdf0e10cSrcweir
180cdf0e10cSrcweirSub CB1_Terminated()
181cdf0e10cSrcweir    Out.Log("CB1_Terminated called")
182cdf0e10cSrcweir    CB1Terminated = CB1Terminated + 1
183cdf0e10cSrcweirEnd Sub
184cdf0e10cSrcweir
185cdf0e10cSrcweirSub CB2_Terminated()
186cdf0e10cSrcweir    Out.Log("CB2_Terminated called")
187cdf0e10cSrcweir    CB2Terminated = CB2Terminated + 1
188cdf0e10cSrcweirEnd Sub
189cdf0e10cSrcweir
190cdf0e10cSrcweirSub CB1_Error(aError As Object)
191cdf0e10cSrcweir    Out.Log("CB1_Error called")
192cdf0e10cSrcweir    CB1Error = CB1Error + 1
193cdf0e10cSrcweirEnd Sub
194cdf0e10cSrcweir
195cdf0e10cSrcweirSub CB2_Error(aError As Object)
196cdf0e10cSrcweir    Out.Log("CB2_Error called")
197cdf0e10cSrcweir    CB2Error = CB2Error + 1
198cdf0e10cSrcweirEnd Sub
199cdf0e10cSrcweir</script:module>
200