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