1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="io_XDataInputStream" script:language="StarBasic">
4cdf0e10cSrcweir
5cdf0e10cSrcweir
6cdf0e10cSrcweir'*************************************************************************
7cdf0e10cSrcweir'
8*3e6afcd2SAndrew Rist'  Licensed to the Apache Software Foundation (ASF) under one
9*3e6afcd2SAndrew Rist'  or more contributor license agreements.  See the NOTICE file
10*3e6afcd2SAndrew Rist'  distributed with this work for additional information
11*3e6afcd2SAndrew Rist'  regarding copyright ownership.  The ASF licenses this file
12*3e6afcd2SAndrew Rist'  to you under the Apache License, Version 2.0 (the
13*3e6afcd2SAndrew Rist'  "License"); you may not use this file except in compliance
14*3e6afcd2SAndrew Rist'  with the License.  You may obtain a copy of the License at
15*3e6afcd2SAndrew Rist'
16*3e6afcd2SAndrew Rist'    http://www.apache.org/licenses/LICENSE-2.0
17*3e6afcd2SAndrew Rist'
18*3e6afcd2SAndrew Rist'  Unless required by applicable law or agreed to in writing,
19*3e6afcd2SAndrew Rist'  software distributed under the License is distributed on an
20*3e6afcd2SAndrew Rist'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*3e6afcd2SAndrew Rist'  KIND, either express or implied.  See the License for the
22*3e6afcd2SAndrew Rist'  specific language governing permissions and limitations
23*3e6afcd2SAndrew Rist'  under the License.
24cdf0e10cSrcweir'
25cdf0e10cSrcweir'*************************************************************************
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir
31*3e6afcd2SAndrew Rist
32*3e6afcd2SAndrew Rist
33cdf0e10cSrcweirSub RunTest()
34cdf0e10cSrcweir
35cdf0e10cSrcweir'*************************************************************************
36cdf0e10cSrcweir' INTERFACE:
37cdf0e10cSrcweir' com.sun.star.io.XDataInputStream
38cdf0e10cSrcweir'*************************************************************************
39cdf0e10cSrcweirOn Error Goto ErrHndl
40cdf0e10cSrcweir    Dim bOK As Boolean
41cdf0e10cSrcweir    Dim DataTypes(10) As String
42cdf0e10cSrcweir    Dim Data(10) As Variant
43cdf0e10cSrcweir    Dim oTypeConvertor As Object
44cdf0e10cSrcweir
45cdf0e10cSrcweir    bOK = true
46cdf0e10cSrcweir
47cdf0e10cSrcweir    oTypeConvertor = createUnoService("com.sun.star.script.Converter")
48cdf0e10cSrcweir
49cdf0e10cSrcweir    DataTypes(0) = "byte"
50cdf0e10cSrcweir    Data(0) = 65
51cdf0e10cSrcweir    DataTypes(1) = "boolean"
52cdf0e10cSrcweir    Data(1) = true
53cdf0e10cSrcweir    DataTypes(2) = "double"
54cdf0e10cSrcweir    Data(2) = 10.567
55cdf0e10cSrcweir    DataTypes(3) = "long"
56cdf0e10cSrcweir    Data(3) = 12345678
57cdf0e10cSrcweir    DataTypes(4) = "char"
58cdf0e10cSrcweir    Data(4) = oTypeConvertor.convertToSimpleType(89, com.sun.star.uno.TypeClass.CHAR)
59cdf0e10cSrcweir    DataTypes(5) = "short"
60cdf0e10cSrcweir    Data(5) = 233
61cdf0e10cSrcweir    DataTypes(6) = "UTF"
62cdf0e10cSrcweir    Data(6) = "UTF String"
63cdf0e10cSrcweir    DataTypes(7) = "float"
64cdf0e10cSrcweir    Data(7) = -233.15
65cdf0e10cSrcweir    DataTypes(8) = "Hyper"
66cdf0e10cSrcweir    Data(8) = 98765432123456
67cdf0e10cSrcweir
68cdf0e10cSrcweir    Out.Log("Writing data first... ")
69cdf0e10cSrcweir
70cdf0e10cSrcweir    oOutStream = getOutStream()
71cdf0e10cSrcweir
72cdf0e10cSrcweir    for i = 0 to ubound(Data())
73cdf0e10cSrcweir        select case DataTypes(i)
74cdf0e10cSrcweir            case "boolean"
75cdf0e10cSrcweir                oOutStream.writeBoolean(Data(i))
76cdf0e10cSrcweir            case "byte"
77cdf0e10cSrcweir                oOutStream.writeByte(Data(i))
78cdf0e10cSrcweir            case "char"
79cdf0e10cSrcweir                oOutStream.writeChar(Data(i))
80cdf0e10cSrcweir            case "short"
81cdf0e10cSrcweir                oOutStream.writeShort(Data(i))
82cdf0e10cSrcweir            case "long"
83cdf0e10cSrcweir                oOutStream.writeLong(Data(i))
84cdf0e10cSrcweir            case "Hyper"
85cdf0e10cSrcweir                oOutStream.writeHyper(Data(i))
86cdf0e10cSrcweir            case "float"
87cdf0e10cSrcweir                oOutStream.writeFloat(Data(i))
88cdf0e10cSrcweir            case "double"
89cdf0e10cSrcweir                oOutStream.writeDouble(Data(i))
90cdf0e10cSrcweir            case "UTF"
91cdf0e10cSrcweir                oOutStream.writeUTF(Data(i))
92cdf0e10cSrcweir        end select
93cdf0e10cSrcweir    next i
94cdf0e10cSrcweir
95cdf0e10cSrcweir    Out.Log("then reading and comparering... ")
96cdf0e10cSrcweir
97cdf0e10cSrcweir    ResetStreams()
98cdf0e10cSrcweir
99cdf0e10cSrcweir    for i = 0 to ubound(Data())
100cdf0e10cSrcweir        select case DataTypes(i)
101cdf0e10cSrcweir            case "boolean"
102cdf0e10cSrcweir                Dim bVar As Boolean
103cdf0e10cSrcweir                bVar = oObj.readBoolean()
104cdf0e10cSrcweir                Out.Log("Expected boolean '" &amp; Data(i) &amp; "', actual is '" &amp; bVar &amp; "'")
105cdf0e10cSrcweir                bOK = bOK AND Data(i) = bVar
106cdf0e10cSrcweir                Test.MethodTested("readBoolean()", bOK)
107cdf0e10cSrcweir            case "byte"
108cdf0e10cSrcweir                Dim iByteVar As Integer
109cdf0e10cSrcweir                iByteVar = oObj.readByte()
110cdf0e10cSrcweir                Out.Log("Expected byte '" &amp; int(Data(i)) &amp; "', actual is '" &amp; int(iByteVar) &amp; "'")
111cdf0e10cSrcweir                bOK = bOK AND Data(i) = iByteVar
112cdf0e10cSrcweir                Test.MethodTested("readByte()", bOK)
113cdf0e10cSrcweir            case "char"
114cdf0e10cSrcweir                Dim cCharVar As Integer
115cdf0e10cSrcweir                cCharVar = oObj.readChar()
116cdf0e10cSrcweir                Out.Log("Expected char '" &amp; chr(Data(i)) &amp; "', actual is '" &amp; chr(cCharVar) &amp; "'")
117cdf0e10cSrcweir                bOK = bOK AND Data(i) = cCharVar
118cdf0e10cSrcweir                Test.MethodTested("readChar()", bOK)
119cdf0e10cSrcweir            case "short"
120cdf0e10cSrcweir                Dim iShortVar As Integer
121cdf0e10cSrcweir                iShortVar = oObj.readShort()
122cdf0e10cSrcweir                Out.Log("Expected short '" &amp; int(Data(i)) &amp; "', actual is '" &amp; int(iShortVar) &amp; "'")
123cdf0e10cSrcweir                bOK = bOK AND Data(i) = iShortVar
124cdf0e10cSrcweir                Test.MethodTested("readShort()", bOK)
125cdf0e10cSrcweir            case "long"
126cdf0e10cSrcweir                Dim iLongVar As Long
127cdf0e10cSrcweir                iLongVar = oObj.readLong()
128cdf0e10cSrcweir                Out.Log("Expected long '" &amp; Data(i) &amp; "', actual is '" &amp; iLongVar &amp; "'")
129cdf0e10cSrcweir                bOK = bOK AND Data(i) = iLongVar
130cdf0e10cSrcweir                Test.MethodTested("readLong()", bOK)
131cdf0e10cSrcweir            case "Hyper"
132cdf0e10cSrcweir                Dim iHyperVar As Variant
133cdf0e10cSrcweir                iHyperVar = oObj.readHyper()
134cdf0e10cSrcweir                Out.Log("Expected hyper '" &amp; Data(i) &amp; "', actual is '" &amp; iHyperVar &amp; "'")
135cdf0e10cSrcweir                bOK = bOK AND Data(i) = iHyperVar
136cdf0e10cSrcweir                Test.MethodTested("readHyper()", bOK)
137cdf0e10cSrcweir            case "float"
138cdf0e10cSrcweir                Dim dFloatVar As Double
139cdf0e10cSrcweir                dFloatVar = oObj.readFloat()
140cdf0e10cSrcweir                Out.Log("Expected float '" &amp; Data(i) &amp; "', actual is '" &amp; dFloatVar &amp; "'")
141cdf0e10cSrcweir                bOK = bOK AND (abs(Data(i) - dFloatVar) &lt; 0.00001)
142cdf0e10cSrcweir                Test.MethodTested("readFloat()", bOK)
143cdf0e10cSrcweir            case "double"
144cdf0e10cSrcweir                Dim dDoubleVar As Double
145cdf0e10cSrcweir                dDoubleVar = oObj.readDouble()
146cdf0e10cSrcweir                Out.Log("Expected double '" &amp; Data(i) &amp; "', actual is '" &amp; dDoubleVar &amp; "'")
147cdf0e10cSrcweir                bOK = bOK AND Data(i) = dDoubleVar
148cdf0e10cSrcweir                Test.MethodTested("readDouble()", bOK)
149cdf0e10cSrcweir            case "UTF"
150cdf0e10cSrcweir                Dim cUTFVar As String
151cdf0e10cSrcweir                cUTFVar = oObj.readUTF()
152cdf0e10cSrcweir                Out.Log("Expected UTF '" &amp; Data(i) &amp; "', actual is '" &amp; cUTFVar &amp; "'")
153cdf0e10cSrcweir                bOK = bOK AND Data(i) = cUTFVar
154cdf0e10cSrcweir                Test.MethodTested("readUTF()", bOK)
155cdf0e10cSrcweir        end select
156cdf0e10cSrcweir    next i
157cdf0e10cSrcweir
158cdf0e10cSrcweir    ResetStreams()
159cdf0e10cSrcweirExit Sub
160cdf0e10cSrcweirErrHndl:
161cdf0e10cSrcweir    Test.Exception()
162cdf0e10cSrcweir    bOK = false
163cdf0e10cSrcweir    resume next
164cdf0e10cSrcweirEnd Sub
165cdf0e10cSrcweir</script:module>
166