1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?> 2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="io_XMarkableStream" script:language="StarBasic"> 4cdf0e10cSrcweir 5cdf0e10cSrcweir 6cdf0e10cSrcweir'************************************************************************* 7cdf0e10cSrcweir' 8*3e6afcd2SAndrew Rist' Licensed to the Apache Software Foundation (ASF) under one 9*3e6afcd2SAndrew Rist' or more contributor license agreements. See the NOTICE file 10*3e6afcd2SAndrew Rist' distributed with this work for additional information 11*3e6afcd2SAndrew Rist' regarding copyright ownership. The ASF licenses this file 12*3e6afcd2SAndrew Rist' to you under the Apache License, Version 2.0 (the 13*3e6afcd2SAndrew Rist' "License"); you may not use this file except in compliance 14*3e6afcd2SAndrew Rist' with the License. You may obtain a copy of the License at 15*3e6afcd2SAndrew Rist' 16*3e6afcd2SAndrew Rist' http://www.apache.org/licenses/LICENSE-2.0 17*3e6afcd2SAndrew Rist' 18*3e6afcd2SAndrew Rist' Unless required by applicable law or agreed to in writing, 19*3e6afcd2SAndrew Rist' software distributed under the License is distributed on an 20*3e6afcd2SAndrew Rist' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21*3e6afcd2SAndrew Rist' KIND, either express or implied. See the License for the 22*3e6afcd2SAndrew Rist' specific language governing permissions and limitations 23*3e6afcd2SAndrew Rist' under the License. 24cdf0e10cSrcweir' 25cdf0e10cSrcweir'************************************************************************* 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir 29*3e6afcd2SAndrew Rist 30*3e6afcd2SAndrew Rist 31cdf0e10cSrcweir' Be sure that all variables are dimensioned: 32cdf0e10cSrcweiroption explicit 33cdf0e10cSrcweir 34cdf0e10cSrcweir 35cdf0e10cSrcweir 36cdf0e10cSrcweirSub RunTest() 37cdf0e10cSrcweir 38cdf0e10cSrcweir'************************************************************************* 39cdf0e10cSrcweir' INTERFACE: 40cdf0e10cSrcweir' com.sun.star.io.XMarkableStream 41cdf0e10cSrcweir'************************************************************************* 42cdf0e10cSrcweirOn Error Goto ErrHndl 43cdf0e10cSrcweir Dim bOK As Boolean 44cdf0e10cSrcweir Dim Bytes(20) As Integer 45cdf0e10cSrcweir Dim rBytes(0) 46cdf0e10cSrcweir Dim lastRByte As Integer 47cdf0e10cSrcweir Dim i As Integer 48cdf0e10cSrcweir Dim oOutStream As Object 49cdf0e10cSrcweir Dim oInStream As Object 50cdf0e10cSrcweir Dim iMark1 As Integer 51cdf0e10cSrcweir Dim iMark2 As Integer 52cdf0e10cSrcweir Dim iByte As Integer 53cdf0e10cSrcweir Dim iBytes As Integer 54cdf0e10cSrcweir Dim iByteAfterMark As Integer 55cdf0e10cSrcweir Dim iByteAfterMark1 As Integer 56cdf0e10cSrcweir Dim iByteAfterMark2 As Integer 57cdf0e10cSrcweir Dim iOffset As Integer 58cdf0e10cSrcweir Dim sFileStr As String 59cdf0e10cSrcweir 60cdf0e10cSrcweir if (cObjectName = "stm.MarkableInputStream" OR cObjectName = "stm.ObjectInputStream") then 61cdf0e10cSrcweir 62cdf0e10cSrcweir for i = 0 to ubound(Bytes()) 63cdf0e10cSrcweir Bytes(i) = i * 2 64cdf0e10cSrcweir next i 65cdf0e10cSrcweir 66cdf0e10cSrcweir Out.Log("First reset streams and write some bytes...") 67cdf0e10cSrcweir oOutStream = getOutStream() 68cdf0e10cSrcweir oOutStream.writeBytes(Bytes()) 69cdf0e10cSrcweir ResetStreams() 70cdf0e10cSrcweir 71cdf0e10cSrcweir Test.StartMethod("createMark()") 72cdf0e10cSrcweir bOK = true 73cdf0e10cSrcweir Out.Log("Skip 3 bytes.") 74cdf0e10cSrcweir oObj.skipBytes(3) 75cdf0e10cSrcweir iMark1 = oObj.createMark() 76cdf0e10cSrcweir Out.Log("Mark" + iMark1 + " was created.") 77cdf0e10cSrcweir 78cdf0e10cSrcweir oObj.readBytes(rBytes(), 1) 79cdf0e10cSrcweir iByteAfterMark1 = rBytes(0) 80cdf0e10cSrcweir Out.Log("Byte after Mark" + iMark1 + " is " + int(iByteAfterMark1)) 81cdf0e10cSrcweir 82cdf0e10cSrcweir Out.Log("Skip 5 bytes.") 83cdf0e10cSrcweir oObj.skipBytes(5) 84cdf0e10cSrcweir iMark2 = oObj.createMark() 85cdf0e10cSrcweir Out.Log("Mark" + iMark2 + " was created.") 86cdf0e10cSrcweir 87cdf0e10cSrcweir oObj.readBytes(rBytes(), 1) 88cdf0e10cSrcweir iByteAfterMark2 = rBytes(0) 89cdf0e10cSrcweir Out.Log("Byte after Mark" + iMark2 + " is " + int(iByteAfterMark2)) 90cdf0e10cSrcweir 91cdf0e10cSrcweir Out.Log("Skip 7 bytes.") 92cdf0e10cSrcweir oObj.skipBytes(7) 93cdf0e10cSrcweir oObj.readBytes(rBytes(), 1) 94cdf0e10cSrcweir lastRByte = rBytes(0) 95cdf0e10cSrcweir 96cdf0e10cSrcweir Out.Log("Jump to Mark" + iMark2) 97cdf0e10cSrcweir oObj.jumpToMark(iMark2) 98cdf0e10cSrcweir oObj.readBytes(rBytes(), 1) 99cdf0e10cSrcweir iByteAfterMark = rBytes(0) 100cdf0e10cSrcweir Out.Log("Byte after Mark" + iMark2 + " is " + int(iByteAfterMark) + ", expected " + int(iByteAfterMark2)) 101cdf0e10cSrcweir bOK = bOK AND iByteAfterMark = iByteAfterMark2 102cdf0e10cSrcweir 103cdf0e10cSrcweir Out.Log("Jump to Mark" + iMark1) 104cdf0e10cSrcweir oObj.jumpToMark(iMark1) 105cdf0e10cSrcweir oObj.readBytes(rBytes(), 1) 106cdf0e10cSrcweir iByteAfterMark = rBytes(0) 107cdf0e10cSrcweir Out.Log("Byte after Mark" + iMark1 + " is " + int(iByteAfterMark) + ", expected " + int(iByteAfterMark1)) 108cdf0e10cSrcweir bOK = bOK AND iByteAfterMark = iByteAfterMark1 109cdf0e10cSrcweir 110cdf0e10cSrcweir Test.MethodTested("createMark()", bOK) 111cdf0e10cSrcweir Test.MethodTested("jumpToMark()", bOK) 112cdf0e10cSrcweir 113cdf0e10cSrcweir Test.StartMethod("offsetToMark()") 114cdf0e10cSrcweir bOK = true 115cdf0e10cSrcweir iOffset = oObj.offsetToMark(iMark2) 116cdf0e10cSrcweir Out.Log("Offset from current position to Mark" + iMark2 + " is " + iOffset) 117cdf0e10cSrcweir bOK = bOK AND iOffset = -5 118cdf0e10cSrcweir Test.MethodTested("offsetToMark()", bOK) 119cdf0e10cSrcweir 120cdf0e10cSrcweir Test.StartMethod("deleteMark()") 121cdf0e10cSrcweir bOK = true 122cdf0e10cSrcweir Out.Log("Delete Mark" + iMark1) 123cdf0e10cSrcweir oObj.deleteMark(iMark1) 124cdf0e10cSrcweir On Error goto ErrHndl1 125cdf0e10cSrcweir Out.Log("Trying to jump to deleted mark") 126cdf0e10cSrcweir oObj.jumpToMark(iMark1) 127cdf0e10cSrcweir Out.Log("No exception occured. FAILED") 128cdf0e10cSrcweir bOK = false 129cdf0e10cSrcweir goto Cont1 130cdf0e10cSrcweir ErrHndl1: 131cdf0e10cSrcweir Out.Log("Expected exception: " + error) 132cdf0e10cSrcweir Cont1: 133cdf0e10cSrcweir Test.MethodTested("deleteMark()", bOK) 134cdf0e10cSrcweir 135cdf0e10cSrcweir Test.StartMethod("jumpToFurthest()") 136cdf0e10cSrcweir bOK = true 137cdf0e10cSrcweir oObj.readBytes(rBytes(), 1) 138cdf0e10cSrcweir iByte = rBytes(0) 139cdf0e10cSrcweir Out.Log("Perform a reading operation from the current position. Byte " + int(iByte) + " was read.") 140cdf0e10cSrcweir Out.Log("Changing position.") 141cdf0e10cSrcweir oObj.jumpToMark(iMark2) 142cdf0e10cSrcweir Out.Log("Changing position with jumpToFurthest()") 143cdf0e10cSrcweir oObj.jumpToFurthest() 144cdf0e10cSrcweir oObj.readBytes(rBytes(), 1) 145cdf0e10cSrcweir Out.Log("From the current position byte " + int(rBytes(0)) + " was read. Expected byte is " + int(lastRByte) + 2) 146cdf0e10cSrcweir bOK = bOK AND lastRByte + 2 = rBytes(0) 147cdf0e10cSrcweir Test.MethodTested("jumpToFurthest()", bOK) 148cdf0e10cSrcweir else 149cdf0e10cSrcweir bOK = true 150cdf0e10cSrcweir Out.Log("Write 3 bytes to stream") 151cdf0e10cSrcweir ReDim Bytes(2) As Integer 152cdf0e10cSrcweir for i = 0 to ubound(Bytes()) 153cdf0e10cSrcweir Bytes(i) = i 154cdf0e10cSrcweir next i 155cdf0e10cSrcweir oObj.writeBytes(Bytes()) 156cdf0e10cSrcweir Out.Log("Creating a Mark.") 157cdf0e10cSrcweir iMark1 = oObj.createMark() 158cdf0e10cSrcweir Out.Log("Write 4 bytes to stream") 159cdf0e10cSrcweir ReDim Bytes(3) As Integer 160cdf0e10cSrcweir for i = 0 to ubound(Bytes()) 161cdf0e10cSrcweir Bytes(i) = i + 3 162cdf0e10cSrcweir next i 163cdf0e10cSrcweir oObj.writeBytes(Bytes()) 164cdf0e10cSrcweir Out.Log("Creating a Mark.") 165cdf0e10cSrcweir iMark2 = oObj.createMark() 166cdf0e10cSrcweir 167cdf0e10cSrcweir iOffset = oObj.offsetToMark(iMark1) 168cdf0e10cSrcweir Out.Log("Offset from current position to Mark" + iMark1 + " is " + iOffset) 169cdf0e10cSrcweir bOK = bOK AND iOffset = 4 170cdf0e10cSrcweir Test.MethodTested("offsetToMark()", bOK) 171cdf0e10cSrcweir 172cdf0e10cSrcweir Out.Log("Write 5 bytes to stream") 173cdf0e10cSrcweir ReDim Bytes(4) As Integer 174cdf0e10cSrcweir for i = 0 to ubound(Bytes()) 175cdf0e10cSrcweir Bytes(i) = i + 7 176cdf0e10cSrcweir next i 177cdf0e10cSrcweir oObj.writeBytes(Bytes()) 178cdf0e10cSrcweir 179cdf0e10cSrcweir Out.Log("Testing jumpToMark()") 180cdf0e10cSrcweir Out.Log("Testing deleteMark()") 181cdf0e10cSrcweir bOK = true 182cdf0e10cSrcweir Out.Log("Deleting Mark1") 183cdf0e10cSrcweir oObj.deleteMark(iMark2) 184cdf0e10cSrcweir On Error goto ErrHndl2 185cdf0e10cSrcweir Out.Log("Trying to jump to Mark1") 186cdf0e10cSrcweir oObj.jumpToMark(iMark2) 187cdf0e10cSrcweir Out.Log("No exception occured - FAILED") 188cdf0e10cSrcweir bOK = false 189cdf0e10cSrcweir goto Cont2 190cdf0e10cSrcweir ErrHndl2: 191cdf0e10cSrcweir Out.Log("Expected exception: " + error) 192cdf0e10cSrcweir Cont2: 193cdf0e10cSrcweir 194cdf0e10cSrcweir Test.MethodTested("deleteMark()", bOK) 195cdf0e10cSrcweir 196cdf0e10cSrcweir bOK = true 197cdf0e10cSrcweir 198cdf0e10cSrcweir Out.Log("Jump to Mark0") 199cdf0e10cSrcweir oObj.jumpToMark(iMark1) 200cdf0e10cSrcweir Test.MethodTested("jumpToMark()", bOK) 201cdf0e10cSrcweir Test.MethodTested("createMark()", bOK) 202cdf0e10cSrcweir 203cdf0e10cSrcweir bOK = true 204cdf0e10cSrcweir Out.Log("Write 2 bytes to stream") 205cdf0e10cSrcweir ReDim Bytes(1) As Integer 206cdf0e10cSrcweir 207cdf0e10cSrcweir for i = 0 to ubound(Bytes()) 208cdf0e10cSrcweir Bytes(i) = i + 12 209cdf0e10cSrcweir next i 210cdf0e10cSrcweir 211cdf0e10cSrcweir oObj.writeBytes(Bytes()) 212cdf0e10cSrcweir Out.Log("Changing position") 213cdf0e10cSrcweir oObj.jumpToMark(iMark1) 214cdf0e10cSrcweir Out.Log("Changing position with jumpToFurthest()") 215cdf0e10cSrcweir oObj.jumpToFurthest() 216cdf0e10cSrcweir 217cdf0e10cSrcweir Out.Log("Write 2 bytes to stream") 218cdf0e10cSrcweir ReDim Bytes(1) As Integer 219cdf0e10cSrcweir for i = 0 to ubound(Bytes()) 220cdf0e10cSrcweir Bytes(i) = i + 14 221cdf0e10cSrcweir next i 222cdf0e10cSrcweir oObj.writeBytes(Bytes()) 223cdf0e10cSrcweir 224cdf0e10cSrcweir Out.Log("Comparing file with expected {0, 1, 2, 12, 13, 5, 6, 7, 8, 9, 10, 11, 14, 15}") 225cdf0e10cSrcweir oInStream = getInStream() 226cdf0e10cSrcweir iBytes = oInStream.readBytes(rBytes(), 20) 227cdf0e10cSrcweir Out.Log("There are " + iBytes + " in stream:") 228cdf0e10cSrcweir sFileStr = "" + int(rBytes(0)) 229cdf0e10cSrcweir for i = 1 to ubound(rBytes()) 230cdf0e10cSrcweir sFileStr = sFileStr + ", " + int(rBytes(i)) 231cdf0e10cSrcweir next i 232cdf0e10cSrcweir Out.Log("They are {" + sFileStr + "}") 233cdf0e10cSrcweir bOK = bOK AND sFileStr = "0, 1, 2, 12, 13, 5, 6, 7, 8, 9, 10, 11, 14, 15" 234cdf0e10cSrcweir 235cdf0e10cSrcweir Test.MethodTested("jumpToFurthest()", bOK) 236cdf0e10cSrcweir end if 237cdf0e10cSrcweir 238cdf0e10cSrcweir ResetStreams() 239cdf0e10cSrcweir DisposeObj() 240cdf0e10cSrcweir CreateObj() 241cdf0e10cSrcweir 242cdf0e10cSrcweirExit Sub 243cdf0e10cSrcweirErrHndl: 244cdf0e10cSrcweir Test.Exception() 245cdf0e10cSrcweir bOK = false 246cdf0e10cSrcweir resume next 247cdf0e10cSrcweirEnd Sub 248cdf0e10cSrcweir</script:module> 249