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' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9'
10' Copyright 2000, 2010 Oracle and/or its affiliates.
11'
12' OpenOffice.org - a multi-platform office productivity suite
13'
14' This file is part of OpenOffice.org.
15'
16' OpenOffice.org is free software: you can redistribute it and/or modify
17' it under the terms of the GNU Lesser General Public License version 3
18' only, as published by the Free Software Foundation.
19'
20' OpenOffice.org is distributed in the hope that it will be useful,
21' but WITHOUT ANY WARRANTY; without even the implied warranty of
22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23' GNU Lesser General Public License version 3 for more details
24' (a copy is included in the LICENSE file that accompanied this code).
25'
26' You should have received a copy of the GNU Lesser General Public License
27' version 3 along with OpenOffice.org.  If not, see
28' <http://www.openoffice.org/license.html>
29' for a copy of the LGPLv3 License.
30'
31'*************************************************************************
32'*************************************************************************
33
34
35
36' Be sure that all variables are dimensioned:
37option explicit
38
39
40
41Sub RunTest()
42
43'*************************************************************************
44' INTERFACE:
45' com.sun.star.io.XDataOutputStream
46'*************************************************************************
47On Error Goto ErrHndl
48    Dim bOK As Boolean
49    Dim DataTypes(10) As String
50    Dim Data(10) As Variant
51    Dim oTypeConvertor As Object
52    Dim i As Integer
53    Dim oInputStream As Object
54
55    bOK = true
56
57    oTypeConvertor = createUnoService("com.sun.star.script.Converter")
58
59    DataTypes(0) = "byte"
60    Data(0) = 65
61    DataTypes(1) = "boolean"
62    Data(1) = true
63    DataTypes(2) = "double"
64    Data(2) = 10.567
65    DataTypes(3) = "long"
66    Data(3) = 12345678
67    DataTypes(4) = "char"
68    Data(4) = oTypeConvertor.convertToSimpleType(89, com.sun.star.uno.TypeClass.CHAR)
69    DataTypes(5) = "short"
70    Data(5) = 233
71    DataTypes(6) = "UTF"
72    Data(6) = "UTF String"
73    DataTypes(7) = "float"
74    Data(7) = -233.15
75    DataTypes(8) = "Hyper"
76    Data(8) = 98765432123456
77
78    Out.Log("Writing data first... ")
79
80    for i = 0 to ubound(Data())
81        select case DataTypes(i)
82            case "boolean"
83                oObj.writeBoolean(Data(i))
84            case "byte"
85                oObj.writeByte(Data(i))
86            case "char"
87                oObj.writeChar(Data(i))
88            case "short"
89                oObj.writeShort(Data(i))
90            case "long"
91                oObj.writeLong(Data(i))
92            case "Hyper"
93                oObj.writeHyper(Data(i))
94            case "float"
95                oObj.writeFloat(Data(i))
96            case "double"
97                oObj.writeDouble(Data(i))
98            case "UTF"
99                oObj.writeUTF(Data(i))
100        end select
101    next i
102
103    Out.Log("then reading and comparering... ")
104
105    oInputStream = getInStream()
106
107    for i = 0 to ubound(Data())
108        select case DataTypes(i)
109            case "boolean"
110                Dim bVar As Boolean
111                bVar = oInputStream.readBoolean()
112                Out.Log("Expected boolean '" + Data(i) + "', actual is '" + bVar + "'")
113                bOK = bOK AND Data(i) = bVar
114                Test.MethodTested("writeBoolean()", bOK)
115            case "byte"
116                Dim iByteVar As Integer
117                iByteVar = oInputStream.readByte()
118                Out.Log("Expected byte '" + int(Data(i)) + "', actual is '" + int(iByteVar) + "'")
119                bOK = bOK AND Data(i) = iByteVar
120                Test.MethodTested("writeByte()", bOK)
121            case "char"
122                Dim cCharVar As Integer
123                cCharVar = oInputStream.readChar()
124                Out.Log("Expected char '" + chr(Data(i)) + "', actual is '" + chr(cCharVar) + "'")
125                bOK = bOK AND Data(i) = cCharVar
126                Test.MethodTested("writeChar()", bOK)
127            case "short"
128                Dim iShortVar As Integer
129                iShortVar = oInputStream.readShort()
130                Out.Log("Expected short '" + int(Data(i)) + "', actual is '" + int(iShortVar) + "'")
131                bOK = bOK AND Data(i) = iShortVar
132                Test.MethodTested("writeShort()", bOK)
133            case "long"
134                Dim iLongVar As Long
135                iLongVar = oInputStream.readLong()
136                Out.Log("Expected long '" + Data(i) + "', actual is '" + iLongVar + "'")
137                bOK = bOK AND Data(i) = iLongVar
138                Test.MethodTested("writeLong()", bOK)
139            case "Hyper"
140                Dim iHyperVar As Variant
141                iHyperVar = oInputStream.readHyper()
142                Out.Log("Expected hyper '" + Data(i) + "', actual is '" + iHyperVar + "'")
143                bOK = bOK AND Data(i) = iHyperVar
144                Test.MethodTested("writeHyper()", bOK)
145            case "float"
146                Dim dFloatVar As Double
147                dFloatVar = oInputStream.readFloat()
148                Out.Log("Expected float '" + Data(i) + "', actual is '" + dFloatVar + "'")
149                bOK = bOK AND (abs(Data(i) - dFloatVar) &lt; 0.00001)
150                Test.MethodTested("writeFloat()", bOK)
151            case "double"
152                Dim dDoubleVar As Double
153                dDoubleVar = oInputStream.readDouble()
154                Out.Log("Expected double '" + Data(i) + "', actual is '" + dDoubleVar + "'")
155                bOK = bOK AND Data(i) = dDoubleVar
156                Test.MethodTested("writeDouble()", bOK)
157            case "UTF"
158                Dim cUTFVar As Variant
159                cUTFVar = oInputStream.readUTF()
160                Out.Log("Expected UTF '" + Data(i) + "', actual is '" + cUTFVar + "'")
161                bOK = bOK AND Data(i) = cUTFVar
162                Test.MethodTested("writeUTF()", bOK)
163        end select
164    next i
165
166    ResetStreams()
167Exit Sub
168ErrHndl:
169    Test.Exception()
170    bOK = false
171    resume next
172End Sub
173</script:module>
174