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