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