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