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