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_XMarkableStream" 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.XMarkableStream 41*b1cdbd2cSJim Jagielski'************************************************************************* 42*b1cdbd2cSJim JagielskiOn Error Goto ErrHndl 43*b1cdbd2cSJim Jagielski Dim bOK As Boolean 44*b1cdbd2cSJim Jagielski Dim Bytes(20) As Integer 45*b1cdbd2cSJim Jagielski Dim rBytes(0) 46*b1cdbd2cSJim Jagielski Dim lastRByte As Integer 47*b1cdbd2cSJim Jagielski Dim i As Integer 48*b1cdbd2cSJim Jagielski Dim oOutStream As Object 49*b1cdbd2cSJim Jagielski Dim oInStream As Object 50*b1cdbd2cSJim Jagielski Dim iMark1 As Integer 51*b1cdbd2cSJim Jagielski Dim iMark2 As Integer 52*b1cdbd2cSJim Jagielski Dim iByte As Integer 53*b1cdbd2cSJim Jagielski Dim iBytes As Integer 54*b1cdbd2cSJim Jagielski Dim iByteAfterMark As Integer 55*b1cdbd2cSJim Jagielski Dim iByteAfterMark1 As Integer 56*b1cdbd2cSJim Jagielski Dim iByteAfterMark2 As Integer 57*b1cdbd2cSJim Jagielski Dim iOffset As Integer 58*b1cdbd2cSJim Jagielski Dim sFileStr As String 59*b1cdbd2cSJim Jagielski 60*b1cdbd2cSJim Jagielski if (cObjectName = "stm.MarkableInputStream" OR cObjectName = "stm.ObjectInputStream") then 61*b1cdbd2cSJim Jagielski 62*b1cdbd2cSJim Jagielski for i = 0 to ubound(Bytes()) 63*b1cdbd2cSJim Jagielski Bytes(i) = i * 2 64*b1cdbd2cSJim Jagielski next i 65*b1cdbd2cSJim Jagielski 66*b1cdbd2cSJim Jagielski Out.Log("First reset streams and write some bytes...") 67*b1cdbd2cSJim Jagielski oOutStream = getOutStream() 68*b1cdbd2cSJim Jagielski oOutStream.writeBytes(Bytes()) 69*b1cdbd2cSJim Jagielski ResetStreams() 70*b1cdbd2cSJim Jagielski 71*b1cdbd2cSJim Jagielski Test.StartMethod("createMark()") 72*b1cdbd2cSJim Jagielski bOK = true 73*b1cdbd2cSJim Jagielski Out.Log("Skip 3 bytes.") 74*b1cdbd2cSJim Jagielski oObj.skipBytes(3) 75*b1cdbd2cSJim Jagielski iMark1 = oObj.createMark() 76*b1cdbd2cSJim Jagielski Out.Log("Mark" + iMark1 + " was created.") 77*b1cdbd2cSJim Jagielski 78*b1cdbd2cSJim Jagielski oObj.readBytes(rBytes(), 1) 79*b1cdbd2cSJim Jagielski iByteAfterMark1 = rBytes(0) 80*b1cdbd2cSJim Jagielski Out.Log("Byte after Mark" + iMark1 + " is " + int(iByteAfterMark1)) 81*b1cdbd2cSJim Jagielski 82*b1cdbd2cSJim Jagielski Out.Log("Skip 5 bytes.") 83*b1cdbd2cSJim Jagielski oObj.skipBytes(5) 84*b1cdbd2cSJim Jagielski iMark2 = oObj.createMark() 85*b1cdbd2cSJim Jagielski Out.Log("Mark" + iMark2 + " was created.") 86*b1cdbd2cSJim Jagielski 87*b1cdbd2cSJim Jagielski oObj.readBytes(rBytes(), 1) 88*b1cdbd2cSJim Jagielski iByteAfterMark2 = rBytes(0) 89*b1cdbd2cSJim Jagielski Out.Log("Byte after Mark" + iMark2 + " is " + int(iByteAfterMark2)) 90*b1cdbd2cSJim Jagielski 91*b1cdbd2cSJim Jagielski Out.Log("Skip 7 bytes.") 92*b1cdbd2cSJim Jagielski oObj.skipBytes(7) 93*b1cdbd2cSJim Jagielski oObj.readBytes(rBytes(), 1) 94*b1cdbd2cSJim Jagielski lastRByte = rBytes(0) 95*b1cdbd2cSJim Jagielski 96*b1cdbd2cSJim Jagielski Out.Log("Jump to Mark" + iMark2) 97*b1cdbd2cSJim Jagielski oObj.jumpToMark(iMark2) 98*b1cdbd2cSJim Jagielski oObj.readBytes(rBytes(), 1) 99*b1cdbd2cSJim Jagielski iByteAfterMark = rBytes(0) 100*b1cdbd2cSJim Jagielski Out.Log("Byte after Mark" + iMark2 + " is " + int(iByteAfterMark) + ", expected " + int(iByteAfterMark2)) 101*b1cdbd2cSJim Jagielski bOK = bOK AND iByteAfterMark = iByteAfterMark2 102*b1cdbd2cSJim Jagielski 103*b1cdbd2cSJim Jagielski Out.Log("Jump to Mark" + iMark1) 104*b1cdbd2cSJim Jagielski oObj.jumpToMark(iMark1) 105*b1cdbd2cSJim Jagielski oObj.readBytes(rBytes(), 1) 106*b1cdbd2cSJim Jagielski iByteAfterMark = rBytes(0) 107*b1cdbd2cSJim Jagielski Out.Log("Byte after Mark" + iMark1 + " is " + int(iByteAfterMark) + ", expected " + int(iByteAfterMark1)) 108*b1cdbd2cSJim Jagielski bOK = bOK AND iByteAfterMark = iByteAfterMark1 109*b1cdbd2cSJim Jagielski 110*b1cdbd2cSJim Jagielski Test.MethodTested("createMark()", bOK) 111*b1cdbd2cSJim Jagielski Test.MethodTested("jumpToMark()", bOK) 112*b1cdbd2cSJim Jagielski 113*b1cdbd2cSJim Jagielski Test.StartMethod("offsetToMark()") 114*b1cdbd2cSJim Jagielski bOK = true 115*b1cdbd2cSJim Jagielski iOffset = oObj.offsetToMark(iMark2) 116*b1cdbd2cSJim Jagielski Out.Log("Offset from current position to Mark" + iMark2 + " is " + iOffset) 117*b1cdbd2cSJim Jagielski bOK = bOK AND iOffset = -5 118*b1cdbd2cSJim Jagielski Test.MethodTested("offsetToMark()", bOK) 119*b1cdbd2cSJim Jagielski 120*b1cdbd2cSJim Jagielski Test.StartMethod("deleteMark()") 121*b1cdbd2cSJim Jagielski bOK = true 122*b1cdbd2cSJim Jagielski Out.Log("Delete Mark" + iMark1) 123*b1cdbd2cSJim Jagielski oObj.deleteMark(iMark1) 124*b1cdbd2cSJim Jagielski On Error goto ErrHndl1 125*b1cdbd2cSJim Jagielski Out.Log("Trying to jump to deleted mark") 126*b1cdbd2cSJim Jagielski oObj.jumpToMark(iMark1) 127*b1cdbd2cSJim Jagielski Out.Log("No exception occured. FAILED") 128*b1cdbd2cSJim Jagielski bOK = false 129*b1cdbd2cSJim Jagielski goto Cont1 130*b1cdbd2cSJim Jagielski ErrHndl1: 131*b1cdbd2cSJim Jagielski Out.Log("Expected exception: " + error) 132*b1cdbd2cSJim Jagielski Cont1: 133*b1cdbd2cSJim Jagielski Test.MethodTested("deleteMark()", bOK) 134*b1cdbd2cSJim Jagielski 135*b1cdbd2cSJim Jagielski Test.StartMethod("jumpToFurthest()") 136*b1cdbd2cSJim Jagielski bOK = true 137*b1cdbd2cSJim Jagielski oObj.readBytes(rBytes(), 1) 138*b1cdbd2cSJim Jagielski iByte = rBytes(0) 139*b1cdbd2cSJim Jagielski Out.Log("Perform a reading operation from the current position. Byte " + int(iByte) + " was read.") 140*b1cdbd2cSJim Jagielski Out.Log("Changing position.") 141*b1cdbd2cSJim Jagielski oObj.jumpToMark(iMark2) 142*b1cdbd2cSJim Jagielski Out.Log("Changing position with jumpToFurthest()") 143*b1cdbd2cSJim Jagielski oObj.jumpToFurthest() 144*b1cdbd2cSJim Jagielski oObj.readBytes(rBytes(), 1) 145*b1cdbd2cSJim Jagielski Out.Log("From the current position byte " + int(rBytes(0)) + " was read. Expected byte is " + int(lastRByte) + 2) 146*b1cdbd2cSJim Jagielski bOK = bOK AND lastRByte + 2 = rBytes(0) 147*b1cdbd2cSJim Jagielski Test.MethodTested("jumpToFurthest()", bOK) 148*b1cdbd2cSJim Jagielski else 149*b1cdbd2cSJim Jagielski bOK = true 150*b1cdbd2cSJim Jagielski Out.Log("Write 3 bytes to stream") 151*b1cdbd2cSJim Jagielski ReDim Bytes(2) As Integer 152*b1cdbd2cSJim Jagielski for i = 0 to ubound(Bytes()) 153*b1cdbd2cSJim Jagielski Bytes(i) = i 154*b1cdbd2cSJim Jagielski next i 155*b1cdbd2cSJim Jagielski oObj.writeBytes(Bytes()) 156*b1cdbd2cSJim Jagielski Out.Log("Creating a Mark.") 157*b1cdbd2cSJim Jagielski iMark1 = oObj.createMark() 158*b1cdbd2cSJim Jagielski Out.Log("Write 4 bytes to stream") 159*b1cdbd2cSJim Jagielski ReDim Bytes(3) As Integer 160*b1cdbd2cSJim Jagielski for i = 0 to ubound(Bytes()) 161*b1cdbd2cSJim Jagielski Bytes(i) = i + 3 162*b1cdbd2cSJim Jagielski next i 163*b1cdbd2cSJim Jagielski oObj.writeBytes(Bytes()) 164*b1cdbd2cSJim Jagielski Out.Log("Creating a Mark.") 165*b1cdbd2cSJim Jagielski iMark2 = oObj.createMark() 166*b1cdbd2cSJim Jagielski 167*b1cdbd2cSJim Jagielski iOffset = oObj.offsetToMark(iMark1) 168*b1cdbd2cSJim Jagielski Out.Log("Offset from current position to Mark" + iMark1 + " is " + iOffset) 169*b1cdbd2cSJim Jagielski bOK = bOK AND iOffset = 4 170*b1cdbd2cSJim Jagielski Test.MethodTested("offsetToMark()", bOK) 171*b1cdbd2cSJim Jagielski 172*b1cdbd2cSJim Jagielski Out.Log("Write 5 bytes to stream") 173*b1cdbd2cSJim Jagielski ReDim Bytes(4) As Integer 174*b1cdbd2cSJim Jagielski for i = 0 to ubound(Bytes()) 175*b1cdbd2cSJim Jagielski Bytes(i) = i + 7 176*b1cdbd2cSJim Jagielski next i 177*b1cdbd2cSJim Jagielski oObj.writeBytes(Bytes()) 178*b1cdbd2cSJim Jagielski 179*b1cdbd2cSJim Jagielski Out.Log("Testing jumpToMark()") 180*b1cdbd2cSJim Jagielski Out.Log("Testing deleteMark()") 181*b1cdbd2cSJim Jagielski bOK = true 182*b1cdbd2cSJim Jagielski Out.Log("Deleting Mark1") 183*b1cdbd2cSJim Jagielski oObj.deleteMark(iMark2) 184*b1cdbd2cSJim Jagielski On Error goto ErrHndl2 185*b1cdbd2cSJim Jagielski Out.Log("Trying to jump to Mark1") 186*b1cdbd2cSJim Jagielski oObj.jumpToMark(iMark2) 187*b1cdbd2cSJim Jagielski Out.Log("No exception occured - FAILED") 188*b1cdbd2cSJim Jagielski bOK = false 189*b1cdbd2cSJim Jagielski goto Cont2 190*b1cdbd2cSJim Jagielski ErrHndl2: 191*b1cdbd2cSJim Jagielski Out.Log("Expected exception: " + error) 192*b1cdbd2cSJim Jagielski Cont2: 193*b1cdbd2cSJim Jagielski 194*b1cdbd2cSJim Jagielski Test.MethodTested("deleteMark()", bOK) 195*b1cdbd2cSJim Jagielski 196*b1cdbd2cSJim Jagielski bOK = true 197*b1cdbd2cSJim Jagielski 198*b1cdbd2cSJim Jagielski Out.Log("Jump to Mark0") 199*b1cdbd2cSJim Jagielski oObj.jumpToMark(iMark1) 200*b1cdbd2cSJim Jagielski Test.MethodTested("jumpToMark()", bOK) 201*b1cdbd2cSJim Jagielski Test.MethodTested("createMark()", bOK) 202*b1cdbd2cSJim Jagielski 203*b1cdbd2cSJim Jagielski bOK = true 204*b1cdbd2cSJim Jagielski Out.Log("Write 2 bytes to stream") 205*b1cdbd2cSJim Jagielski ReDim Bytes(1) As Integer 206*b1cdbd2cSJim Jagielski 207*b1cdbd2cSJim Jagielski for i = 0 to ubound(Bytes()) 208*b1cdbd2cSJim Jagielski Bytes(i) = i + 12 209*b1cdbd2cSJim Jagielski next i 210*b1cdbd2cSJim Jagielski 211*b1cdbd2cSJim Jagielski oObj.writeBytes(Bytes()) 212*b1cdbd2cSJim Jagielski Out.Log("Changing position") 213*b1cdbd2cSJim Jagielski oObj.jumpToMark(iMark1) 214*b1cdbd2cSJim Jagielski Out.Log("Changing position with jumpToFurthest()") 215*b1cdbd2cSJim Jagielski oObj.jumpToFurthest() 216*b1cdbd2cSJim Jagielski 217*b1cdbd2cSJim Jagielski Out.Log("Write 2 bytes to stream") 218*b1cdbd2cSJim Jagielski ReDim Bytes(1) As Integer 219*b1cdbd2cSJim Jagielski for i = 0 to ubound(Bytes()) 220*b1cdbd2cSJim Jagielski Bytes(i) = i + 14 221*b1cdbd2cSJim Jagielski next i 222*b1cdbd2cSJim Jagielski oObj.writeBytes(Bytes()) 223*b1cdbd2cSJim Jagielski 224*b1cdbd2cSJim Jagielski Out.Log("Comparing file with expected {0, 1, 2, 12, 13, 5, 6, 7, 8, 9, 10, 11, 14, 15}") 225*b1cdbd2cSJim Jagielski oInStream = getInStream() 226*b1cdbd2cSJim Jagielski iBytes = oInStream.readBytes(rBytes(), 20) 227*b1cdbd2cSJim Jagielski Out.Log("There are " + iBytes + " in stream:") 228*b1cdbd2cSJim Jagielski sFileStr = "" + int(rBytes(0)) 229*b1cdbd2cSJim Jagielski for i = 1 to ubound(rBytes()) 230*b1cdbd2cSJim Jagielski sFileStr = sFileStr + ", " + int(rBytes(i)) 231*b1cdbd2cSJim Jagielski next i 232*b1cdbd2cSJim Jagielski Out.Log("They are {" + sFileStr + "}") 233*b1cdbd2cSJim Jagielski bOK = bOK AND sFileStr = "0, 1, 2, 12, 13, 5, 6, 7, 8, 9, 10, 11, 14, 15" 234*b1cdbd2cSJim Jagielski 235*b1cdbd2cSJim Jagielski Test.MethodTested("jumpToFurthest()", bOK) 236*b1cdbd2cSJim Jagielski end if 237*b1cdbd2cSJim Jagielski 238*b1cdbd2cSJim Jagielski ResetStreams() 239*b1cdbd2cSJim Jagielski DisposeObj() 240*b1cdbd2cSJim Jagielski CreateObj() 241*b1cdbd2cSJim Jagielski 242*b1cdbd2cSJim JagielskiExit Sub 243*b1cdbd2cSJim JagielskiErrHndl: 244*b1cdbd2cSJim Jagielski Test.Exception() 245*b1cdbd2cSJim Jagielski bOK = false 246*b1cdbd2cSJim Jagielski resume next 247*b1cdbd2cSJim JagielskiEnd Sub 248*b1cdbd2cSJim Jagielski</script:module> 249