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