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="ucb_XSimpleFileAccess" 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.ucb.XSimpleFileAccess 41cdf0e10cSrcweir'************************************************************************* 42cdf0e10cSrcweirOn Error Goto ErrHndl 43cdf0e10cSrcweir Dim bOK As Boolean 44cdf0e10cSrcweir Dim testDir As String 45cdf0e10cSrcweir Dim cSubFolder As String 46cdf0e10cSrcweir Dim cFile1 As String 47cdf0e10cSrcweir Dim cFile2 As String 48cdf0e10cSrcweir Dim cFile3 As String 49cdf0e10cSrcweir Dim oFC As Variant 50cdf0e10cSrcweir Dim oDT As Object 51cdf0e10cSrcweir Dim oOS As Object 52cdf0e10cSrcweir Dim oIS As Object 53cdf0e10cSrcweir Dim cFileName As String 54cdf0e10cSrcweir Dim cCrDate As String 55cdf0e10cSrcweir Dim cType As String 56cdf0e10cSrcweir Dim i As Integer 57cdf0e10cSrcweir Dim k As Integer 58cdf0e10cSrcweir Dim oIH As Object 59cdf0e10cSrcweir 60cdf0e10cSrcweir Dim Bytes(5) As Integer 61cdf0e10cSrcweir for i = 0 to 5 62cdf0e10cSrcweir Bytes(i) = i 63cdf0e10cSrcweir next i 64cdf0e10cSrcweir 65cdf0e10cSrcweir testDir = utils.Path2URL(cTestDocsDir + "XSimpleFileAccessBASIC") 66cdf0e10cSrcweir Out.Log("Test directory is '" + testDir + "'") 67cdf0e10cSrcweir cSubFolder = utils.getTempFileURL( + "/SubFolder") 68cdf0e10cSrcweir cFile1 = utils.Path2URL(testDir + "/File1.txt") 69cdf0e10cSrcweir cFile2 = utils.Path2URL(testDir + "/File2.txt") 70cdf0e10cSrcweir cFile3 = utils.Path2URL(cSubFolder + "/File3.txt") 71cdf0e10cSrcweir if FileExists(cFile3) then kill(cFile3) 72cdf0e10cSrcweir if (FileExists(cSubFolder)) then rmDir(cSubFolder) 73cdf0e10cSrcweir 74cdf0e10cSrcweir Out.Log("Test that files are in place...") 75cdf0e10cSrcweir bOK = true 76cdf0e10cSrcweir bOK = bOK AND FileExists(cFile1) 77cdf0e10cSrcweir bOK = bOK AND FileExists(cFile2) 78cdf0e10cSrcweir if (NOT bOK) then 79cdf0e10cSrcweir Out.Log("Can't find '" + cFile1 + "' and/or '" + cFile2 + "'") 80cdf0e10cSrcweir Exit Sub 81cdf0e10cSrcweir end if 82cdf0e10cSrcweir 83cdf0e10cSrcweir Test.StartMethod("createFolder()") 84cdf0e10cSrcweir bOK = true 85cdf0e10cSrcweir Out.Log("Creating subfolder '" + cSubFolder + "'") 86cdf0e10cSrcweir oObj.createFolder(cSubFolder) 87cdf0e10cSrcweir bOK = bOK AND FileExists(cSubFolder) 88cdf0e10cSrcweir Test.MethodTested("createFolder()", bOK) 89cdf0e10cSrcweir 90cdf0e10cSrcweir Test.StartMethod("isFolder()") 91cdf0e10cSrcweir bOK = true 92cdf0e10cSrcweir bOK = bOK AND oObj.isFolder(cSubFolder) 93cdf0e10cSrcweir bOK = bOK AND NOT oObj.isFolder(cFile1) 94cdf0e10cSrcweir Test.MethodTested("isFolder()", bOK) 95cdf0e10cSrcweir 96cdf0e10cSrcweir Test.StartMethod("getFolderContents()") 97cdf0e10cSrcweir bOK = true 98cdf0e10cSrcweir Out.Log("Getting content of folder '" + utils.Path2URL(cTestDocsDir) + "'") 99cdf0e10cSrcweir oFC = oObj.getFolderContents(utils.Path2URL(cTestDocsDir), False) 100cdf0e10cSrcweir ' Getting files amount (without folders) 101cdf0e10cSrcweir cFileName = Dir(utils.Path2URL(cTestDocsDir)) 102cdf0e10cSrcweir i = 0 103cdf0e10cSrcweir Out.Log("File list :") 104cdf0e10cSrcweir while (cFileName <> "") 105cdf0e10cSrcweir Out.Log(" " + cFileName) 106cdf0e10cSrcweir i = i + 1 107cdf0e10cSrcweir cFileName = Dir() 108cdf0e10cSrcweir wend 109cdf0e10cSrcweir 110cdf0e10cSrcweir bOK = bOK AND ubound(oFC) = i - 1 111cdf0e10cSrcweir if (bOK) then 112cdf0e10cSrcweir for k = 0 to i - 1 113cdf0e10cSrcweir bOK = bOK AND FileExists(oFC(k)) 114cdf0e10cSrcweir next k 115cdf0e10cSrcweir else 116cdf0e10cSrcweir Out.Log("Amount of files in list is wrong: " + (ubound(oFC) + 1) + "," + i) 117cdf0e10cSrcweir 118cdf0e10cSrcweir end if 119cdf0e10cSrcweir 120cdf0e10cSrcweir Test.MethodTested("getFolderContents()", bOK) 121cdf0e10cSrcweir 122cdf0e10cSrcweir Test.StartMethod("move()") 123cdf0e10cSrcweir bOK = true 124cdf0e10cSrcweir oObj.move(cFile2, cFile3) 125cdf0e10cSrcweir bOK = bOK AND FileExists(cFile3) AND NOT FileExists(cFile2) 126cdf0e10cSrcweir Test.MethodTested("move()", bOK) 127cdf0e10cSrcweir 128cdf0e10cSrcweir Test.StartMethod("copy()") 129cdf0e10cSrcweir bOK = true 130cdf0e10cSrcweir oObj.copy(cFile3, cFile2) 131cdf0e10cSrcweir bOK = bOK AND FileExists(cFile3) AND FileExists(cFile2) 132cdf0e10cSrcweir Test.MethodTested("copy()", bOK) 133cdf0e10cSrcweir 134cdf0e10cSrcweir Test.StartMethod("openFileWrite()") 135cdf0e10cSrcweir bOK = true 136cdf0e10cSrcweir 137cdf0e10cSrcweir Test.StartMethod("kill()") 138cdf0e10cSrcweir bOK = true 139cdf0e10cSrcweir oObj.kill(cFile3) 140cdf0e10cSrcweir bOK = bOK AND NOT FileExists(cFile3) 141cdf0e10cSrcweir Test.MethodTested("kill()", bOK) 142cdf0e10cSrcweir 143cdf0e10cSrcweir Test.StartMethod("exists()") 144cdf0e10cSrcweir bOK = true 145cdf0e10cSrcweir bOK = bOK AND oObj.exists(cFile1) = FileExists(cFile1) AND oObj.exists(cFile3) = FileExists(cFile3) 146cdf0e10cSrcweir Test.MethodTested("exists()", bOK) 147cdf0e10cSrcweir 148cdf0e10cSrcweir Out.Log("creating a new file '" + cFile3 + "'") 149cdf0e10cSrcweir oOS = oObj.openFileWrite(cFile3) 150cdf0e10cSrcweir bOK = bOK AND NOT isNULL(oOS) 151cdf0e10cSrcweir bOK = bOK AND FileExists(cFile3) 152cdf0e10cSrcweir if (bOK) then 153cdf0e10cSrcweir oOS.writeBytes(Bytes()) 154cdf0e10cSrcweir oOS.closeOutput() 155cdf0e10cSrcweir end if 156cdf0e10cSrcweir Test.MethodTested("openFileWrite()", bOK) 157cdf0e10cSrcweir 158cdf0e10cSrcweir Test.StartMethod("getSize()") 159cdf0e10cSrcweir bOK = true 160cdf0e10cSrcweir Out.Log("Actual: " + oObj.getSize(cFile3) + " Expected: " + (ubound(Bytes()) + 1)) 161cdf0e10cSrcweir bOK = bOK AND oObj.getSize(cFile3) = (ubound(Bytes()) + 1) 162cdf0e10cSrcweir Test.MethodTested("getSize()", bOK) 163cdf0e10cSrcweir 164cdf0e10cSrcweir Test.StartMethod("setReadOnly()") 165cdf0e10cSrcweir Test.StartMethod("isReadOnly()") 166cdf0e10cSrcweir bOK = true 167cdf0e10cSrcweir oObj.setReadOnly(cSubFolder, true) 168cdf0e10cSrcweir bOK = bOK AND oObj.isReadOnly(cSubFolder) 169cdf0e10cSrcweir oObj.setReadOnly(cSubFolder, false) 170cdf0e10cSrcweir bOK = bOK AND NOT oObj.isReadOnly(cSubFolder) 171cdf0e10cSrcweir Test.MethodTested("isReadOnly()", bOK) 172cdf0e10cSrcweir Test.MethodTested("setReadOnly()", bOK) 173cdf0e10cSrcweir 174cdf0e10cSrcweir Test.StartMethod("getContentType()") 175cdf0e10cSrcweir bOK = true 176cdf0e10cSrcweir cType = oObj.getContentType(cFile3) 177cdf0e10cSrcweir Out.Log("Content Type is '" + cType + "'") 178cdf0e10cSrcweir Test.MethodTested("getContentType()", bOK) 179cdf0e10cSrcweir 180cdf0e10cSrcweir Test.StartMethod("getDateTimeModified()") 181cdf0e10cSrcweir bOK = true 182cdf0e10cSrcweir oDT = oObj.getDateTimeModified(cFile3) 183cdf0e10cSrcweir cCrDate = Date() 184cdf0e10cSrcweir 185cdf0e10cSrcweir 186cdf0e10cSrcweir bOK = bOK AND Day(cCrDate) = oDT.Day 187cdf0e10cSrcweir bOK = bOK AND Month(cCrDate) = oDT.Month 188cdf0e10cSrcweir bOK = bOK AND Year(cCrDate) = oDT.Year 189cdf0e10cSrcweir 190cdf0e10cSrcweir if (NOT bOK) then 191cdf0e10cSrcweir Out.Log("FileDateTime returned '" + cCrDate + "'") 192cdf0e10cSrcweir Out.Log("getDateTimeModified returned '" + oDT.Day + "/" _ 193cdf0e10cSrcweir + oDT.Month + "/" _ 194cdf0e10cSrcweir + oDT.Year + " " _ 195cdf0e10cSrcweir + oDT.Hours + ":" _ 196cdf0e10cSrcweir + oDT.Minutes + ":" _ 197cdf0e10cSrcweir + oDT.Seconds + "'") 198cdf0e10cSrcweir end if 199cdf0e10cSrcweir Test.MethodTested("getDateTimeModified()", bOK) 200cdf0e10cSrcweir 201cdf0e10cSrcweir Test.StartMethod("openFileRead()") 202cdf0e10cSrcweir bOK = true 203cdf0e10cSrcweir oIS = oObj.openFileRead(cFile3) 204cdf0e10cSrcweir bOK = bOK AND NOT isNULL(oIS) 205cdf0e10cSrcweir Dim rData(10) As Integer 206cdf0e10cSrcweir Dim nRb As Integer 207cdf0e10cSrcweir nRb = oIS.readBytes(rData(), 100) 208cdf0e10cSrcweir bOK = bOK AND nRb = ubound(Bytes()) + 1 209cdf0e10cSrcweir if (NOT bOK) then 210cdf0e10cSrcweir Out.Log("Amount of read files is wrong") 211cdf0e10cSrcweir else 212cdf0e10cSrcweir for i = 0 to nRb - 1 213cdf0e10cSrcweir bOK = bOK AND Bytes(i) = rData(i) 214cdf0e10cSrcweir next i 215cdf0e10cSrcweir end if 216cdf0e10cSrcweir oIS.closeInput() 217cdf0e10cSrcweir Test.MethodTested("openFileRead()", bOK) 218cdf0e10cSrcweir 219cdf0e10cSrcweir Test.StartMethod("openFileReadWrite()") 220cdf0e10cSrcweir bOK = true 221cdf0e10cSrcweir oIS = oObj.openFileReadWrite(cFile3) 222cdf0e10cSrcweir bOK = bOK AND hasUnoInterfaces(oIS, "com.sun.star.io.XStream") 223cdf0e10cSrcweir Test.MethodTested("openFileReadWrite()", bOK) 224cdf0e10cSrcweir 225cdf0e10cSrcweir Test.StartMethod("setInteractionHandler()") 226cdf0e10cSrcweir bOK = true 227cdf0e10cSrcweir oIH = createUNOInterface("com.sun.star.sdb.InteractionHandler") 228cdf0e10cSrcweir oObj.setInteractionHandler(oIH) 229cdf0e10cSrcweir Test.MethodTested("setInteractionHandler()", bOK) 230cdf0e10cSrcweir 231cdf0e10cSrcweirExit Sub 232cdf0e10cSrcweirErrHndl: 233cdf0e10cSrcweir Test.Exception() 234cdf0e10cSrcweir bOK = false 235cdf0e10cSrcweir resume next 236cdf0e10cSrcweirEnd Sub 237cdf0e10cSrcweir</script:module> 238