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