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_XActiveDataSink" 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' Be sure that all variables are dimensioned:
32option explicit
33
34
35
36Sub RunTest()
37
38'*************************************************************************
39' INTERFACE:
40' com.sun.star.io.XActiveDataSink
41'*************************************************************************
42On Error Goto ErrHndl
43    Dim bOK As Boolean
44    Dim oIS As Object, oPipe As Object, oGetPipe As Object
45    Dim aData As Variant, aGetData As Variant
46    Dim bytesRead As Variant
47
48    ResetStreams()
49    Test.StartMethod("getInputStream()")
50    bOK = true
51    oIS = oObj.getInputStream()
52    bOK = bOK AND hasUnoInterfaces(oIS, "com.sun.star.io.XInputStream")
53    Test.MethodTested("getInputStream()", bOK)
54
55    Test.StartMethod("setInputStream()")
56    bOK = true
57    oPipe = createUnoService("com.sun.star.io.Pipe")
58    aData = Array(23, 65, 32, 119)
59    oPipe.writeBytes(aData)
60    oObj.setInputStream(oPipe)
61    oGetPipe = oObj.getInputStream()
62    aGetData = dimArray(ubound(aData())
63    bytesRead = oGetPipe.readBytes(aGetData(), ubound(aData()) + 1)
64    Out.Log("Reading bytes: " + bytesRead)
65
66    bOK = bOK AND cmpArrays(aData, aGetData)
67
68    Out.Log("Setting old input stream ...")
69    oObj.setInputStream(oIS)
70
71    Test.MethodTested("setInputStream()", bOK)
72Exit Sub
73ErrHndl:
74    Test.Exception()
75    bOK = false
76    resume next
77End Sub
78
79Function cmpArrays(arr1 As Variant, arr2 As Variant) As Boolean
80On Error Goto ErrHndl
81    Dim bRet As Boolean
82    Dim i As Integer
83
84    bRet = true
85    if (isNull(arr1) OR isNull(arr2)) then
86        bRet = false
87        Out.Log("One of arrays is null")
88    else
89        if (ubound(arr1()) &lt;&gt; ubound(arr2())) then
90            Out.Log("UBOUND of 1st array is " + ubound(arr1()) + _
91                "UBOUND of 2nd array is " + ubound(arr2()))
92            bRet = false
93        else
94            for i = 0 to ubound(arr1())
95                Out.Log("(" + i + "): " + arr1(i) + "-" + arr2(i))
96                bRet = bRet AND (arr1(i) = arr2(i))
97            next i
98        end if
99    end if
100
101    cmpArrays() = bRet
102exit Function
103ErrHndl:
104    Test.Exception()
105    cmpArrays() = false
106End Function
107</script:module>
108