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