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_XDataInputStream" 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
38Sub RunTest()
39
40'*************************************************************************
41' INTERFACE:
42' com.sun.star.io.XDataInputStream
43'*************************************************************************
44On Error Goto ErrHndl
45    Dim bOK As Boolean
46    Dim DataTypes(10) As String
47    Dim Data(10) As Variant
48    Dim oTypeConvertor As Object
49
50    bOK = true
51
52    oTypeConvertor = createUnoService("com.sun.star.script.Converter")
53
54    DataTypes(0) = "byte"
55    Data(0) = 65
56    DataTypes(1) = "boolean"
57    Data(1) = true
58    DataTypes(2) = "double"
59    Data(2) = 10.567
60    DataTypes(3) = "long"
61    Data(3) = 12345678
62    DataTypes(4) = "char"
63    Data(4) = oTypeConvertor.convertToSimpleType(89, com.sun.star.uno.TypeClass.CHAR)
64    DataTypes(5) = "short"
65    Data(5) = 233
66    DataTypes(6) = "UTF"
67    Data(6) = "UTF String"
68    DataTypes(7) = "float"
69    Data(7) = -233.15
70    DataTypes(8) = "Hyper"
71    Data(8) = 98765432123456
72
73    Out.Log("Writing data first... ")
74
75    oOutStream = getOutStream()
76
77    for i = 0 to ubound(Data())
78        select case DataTypes(i)
79            case "boolean"
80                oOutStream.writeBoolean(Data(i))
81            case "byte"
82                oOutStream.writeByte(Data(i))
83            case "char"
84                oOutStream.writeChar(Data(i))
85            case "short"
86                oOutStream.writeShort(Data(i))
87            case "long"
88                oOutStream.writeLong(Data(i))
89            case "Hyper"
90                oOutStream.writeHyper(Data(i))
91            case "float"
92                oOutStream.writeFloat(Data(i))
93            case "double"
94                oOutStream.writeDouble(Data(i))
95            case "UTF"
96                oOutStream.writeUTF(Data(i))
97        end select
98    next i
99
100    Out.Log("then reading and comparering... ")
101
102    ResetStreams()
103
104    for i = 0 to ubound(Data())
105        select case DataTypes(i)
106            case "boolean"
107                Dim bVar As Boolean
108                bVar = oObj.readBoolean()
109                Out.Log("Expected boolean '" &amp; Data(i) &amp; "', actual is '" &amp; bVar &amp; "'")
110                bOK = bOK AND Data(i) = bVar
111                Test.MethodTested("readBoolean()", bOK)
112            case "byte"
113                Dim iByteVar As Integer
114                iByteVar = oObj.readByte()
115                Out.Log("Expected byte '" &amp; int(Data(i)) &amp; "', actual is '" &amp; int(iByteVar) &amp; "'")
116                bOK = bOK AND Data(i) = iByteVar
117                Test.MethodTested("readByte()", bOK)
118            case "char"
119                Dim cCharVar As Integer
120                cCharVar = oObj.readChar()
121                Out.Log("Expected char '" &amp; chr(Data(i)) &amp; "', actual is '" &amp; chr(cCharVar) &amp; "'")
122                bOK = bOK AND Data(i) = cCharVar
123                Test.MethodTested("readChar()", bOK)
124            case "short"
125                Dim iShortVar As Integer
126                iShortVar = oObj.readShort()
127                Out.Log("Expected short '" &amp; int(Data(i)) &amp; "', actual is '" &amp; int(iShortVar) &amp; "'")
128                bOK = bOK AND Data(i) = iShortVar
129                Test.MethodTested("readShort()", bOK)
130            case "long"
131                Dim iLongVar As Long
132                iLongVar = oObj.readLong()
133                Out.Log("Expected long '" &amp; Data(i) &amp; "', actual is '" &amp; iLongVar &amp; "'")
134                bOK = bOK AND Data(i) = iLongVar
135                Test.MethodTested("readLong()", bOK)
136            case "Hyper"
137                Dim iHyperVar As Variant
138                iHyperVar = oObj.readHyper()
139                Out.Log("Expected hyper '" &amp; Data(i) &amp; "', actual is '" &amp; iHyperVar &amp; "'")
140                bOK = bOK AND Data(i) = iHyperVar
141                Test.MethodTested("readHyper()", bOK)
142            case "float"
143                Dim dFloatVar As Double
144                dFloatVar = oObj.readFloat()
145                Out.Log("Expected float '" &amp; Data(i) &amp; "', actual is '" &amp; dFloatVar &amp; "'")
146                bOK = bOK AND (abs(Data(i) - dFloatVar) &lt; 0.00001)
147                Test.MethodTested("readFloat()", bOK)
148            case "double"
149                Dim dDoubleVar As Double
150                dDoubleVar = oObj.readDouble()
151                Out.Log("Expected double '" &amp; Data(i) &amp; "', actual is '" &amp; dDoubleVar &amp; "'")
152                bOK = bOK AND Data(i) = dDoubleVar
153                Test.MethodTested("readDouble()", bOK)
154            case "UTF"
155                Dim cUTFVar As String
156                cUTFVar = oObj.readUTF()
157                Out.Log("Expected UTF '" &amp; Data(i) &amp; "', actual is '" &amp; cUTFVar &amp; "'")
158                bOK = bOK AND Data(i) = cUTFVar
159                Test.MethodTested("readUTF()", bOK)
160        end select
161    next i
162
163    ResetStreams()
164Exit Sub
165ErrHndl:
166    Test.Exception()
167    bOK = false
168    resume next
169End Sub
170</script:module>
171