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