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">
6 '*************************************************************************
8 ' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10 ' Copyright
2008 by Sun Microsystems, Inc.
12 ' OpenOffice.org - a multi-platform office productivity suite
14 ' $RCSfile: ucb_XSimpleFileAccess.xba,v $
18 ' This file is part of OpenOffice.org.
20 ' OpenOffice.org is free software: you can redistribute it and/or modify
21 ' it under the terms of the GNU Lesser General Public License version
3
22 ' only, as published by the Free Software Foundation.
24 ' OpenOffice.org is distributed in the hope that it will be useful,
25 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ' GNU Lesser General Public License version
3 for more details
28 ' (a copy is included in the LICENSE file that accompanied this code).
30 ' You should have received a copy of the GNU Lesser General Public License
31 ' version
3 along with OpenOffice.org. If not, see
32 '
<http://www.openoffice.org/license.html
>
33 ' for a copy of the LGPLv3 License.
35 '*************************************************************************
36 '*************************************************************************
40 ' Be sure that all variables are dimensioned:
47 '*************************************************************************
49 ' com.sun.star.ucb.XSimpleFileAccess
50 '*************************************************************************
54 Dim cSubFolder As String
62 Dim cFileName As String
69 Dim Bytes(
5) As Integer
74 testDir = utils.Path2URL(cTestDocsDir +
"XSimpleFileAccessBASIC")
75 Out.Log(
"Test directory is '" + testDir +
"'")
76 cSubFolder = utils.getTempFileURL( +
"/SubFolder")
77 cFile1 = utils.Path2URL(testDir +
"/File1.txt")
78 cFile2 = utils.Path2URL(testDir +
"/File2.txt")
79 cFile3 = utils.Path2URL(cSubFolder +
"/File3.txt")
80 if FileExists(cFile3) then kill(cFile3)
81 if (FileExists(cSubFolder)) then rmDir(cSubFolder)
83 Out.Log(
"Test that files are in place...")
85 bOK = bOK AND FileExists(cFile1)
86 bOK = bOK AND FileExists(cFile2)
88 Out.Log(
"Can't find '" + cFile1 +
"' and/or '" + cFile2 +
"'")
92 Test.StartMethod(
"createFolder()")
94 Out.Log(
"Creating subfolder '" + cSubFolder +
"'")
95 oObj.createFolder(cSubFolder)
96 bOK = bOK AND FileExists(cSubFolder)
97 Test.MethodTested(
"createFolder()", bOK)
99 Test.StartMethod(
"isFolder()")
101 bOK = bOK AND oObj.isFolder(cSubFolder)
102 bOK = bOK AND NOT oObj.isFolder(cFile1)
103 Test.MethodTested(
"isFolder()", bOK)
105 Test.StartMethod(
"getFolderContents()")
107 Out.Log(
"Getting content of folder '" + utils.Path2URL(cTestDocsDir) +
"'")
108 oFC = oObj.getFolderContents(utils.Path2URL(cTestDocsDir), False)
109 ' Getting files amount (without folders)
110 cFileName = Dir(utils.Path2URL(cTestDocsDir))
112 Out.Log(
"File list :")
113 while (cFileName
<> "")
114 Out.Log(
" " + cFileName)
119 bOK = bOK AND ubound(oFC) = i -
1
122 bOK = bOK AND FileExists(oFC(k))
125 Out.Log(
"Amount of files in list is wrong: " + (ubound(oFC) +
1) +
"," + i)
129 Test.MethodTested(
"getFolderContents()", bOK)
131 Test.StartMethod(
"move()")
133 oObj.move(cFile2, cFile3)
134 bOK = bOK AND FileExists(cFile3) AND NOT FileExists(cFile2)
135 Test.MethodTested(
"move()", bOK)
137 Test.StartMethod(
"copy()")
139 oObj.copy(cFile3, cFile2)
140 bOK = bOK AND FileExists(cFile3) AND FileExists(cFile2)
141 Test.MethodTested(
"copy()", bOK)
143 Test.StartMethod(
"openFileWrite()")
146 Test.StartMethod(
"kill()")
149 bOK = bOK AND NOT FileExists(cFile3)
150 Test.MethodTested(
"kill()", bOK)
152 Test.StartMethod(
"exists()")
154 bOK = bOK AND oObj.exists(cFile1) = FileExists(cFile1) AND oObj.exists(cFile3) = FileExists(cFile3)
155 Test.MethodTested(
"exists()", bOK)
157 Out.Log(
"creating a new file '" + cFile3 +
"'")
158 oOS = oObj.openFileWrite(cFile3)
159 bOK = bOK AND NOT isNULL(oOS)
160 bOK = bOK AND FileExists(cFile3)
162 oOS.writeBytes(Bytes())
165 Test.MethodTested(
"openFileWrite()", bOK)
167 Test.StartMethod(
"getSize()")
169 Out.Log(
"Actual: " + oObj.getSize(cFile3) +
" Expected: " + (ubound(Bytes()) +
1))
170 bOK = bOK AND oObj.getSize(cFile3) = (ubound(Bytes()) +
1)
171 Test.MethodTested(
"getSize()", bOK)
173 Test.StartMethod(
"setReadOnly()")
174 Test.StartMethod(
"isReadOnly()")
176 oObj.setReadOnly(cSubFolder, true)
177 bOK = bOK AND oObj.isReadOnly(cSubFolder)
178 oObj.setReadOnly(cSubFolder, false)
179 bOK = bOK AND NOT oObj.isReadOnly(cSubFolder)
180 Test.MethodTested(
"isReadOnly()", bOK)
181 Test.MethodTested(
"setReadOnly()", bOK)
183 Test.StartMethod(
"getContentType()")
185 cType = oObj.getContentType(cFile3)
186 Out.Log(
"Content Type is '" + cType +
"'")
187 Test.MethodTested(
"getContentType()", bOK)
189 Test.StartMethod(
"getDateTimeModified()")
191 oDT = oObj.getDateTimeModified(cFile3)
195 bOK = bOK AND Day(cCrDate) = oDT.Day
196 bOK = bOK AND Month(cCrDate) = oDT.Month
197 bOK = bOK AND Year(cCrDate) = oDT.Year
200 Out.Log(
"FileDateTime returned '" + cCrDate +
"'")
201 Out.Log(
"getDateTimeModified returned '" + oDT.Day +
"/" _
205 + oDT.Minutes +
":" _
208 Test.MethodTested(
"getDateTimeModified()", bOK)
210 Test.StartMethod(
"openFileRead()")
212 oIS = oObj.openFileRead(cFile3)
213 bOK = bOK AND NOT isNULL(oIS)
214 Dim rData(
10) As Integer
216 nRb = oIS.readBytes(rData(),
100)
217 bOK = bOK AND nRb = ubound(Bytes()) +
1
219 Out.Log(
"Amount of read files is wrong")
222 bOK = bOK AND Bytes(i) = rData(i)
226 Test.MethodTested(
"openFileRead()", bOK)
228 Test.StartMethod(
"openFileReadWrite()")
230 oIS = oObj.openFileReadWrite(cFile3)
231 bOK = bOK AND hasUnoInterfaces(oIS,
"com.sun.star.io.XStream")
232 Test.MethodTested(
"openFileReadWrite()", bOK)
234 Test.StartMethod(
"setInteractionHandler()")
236 oIH = createUNOInterface(
"com.sun.star.sdb.InteractionHandler")
237 oObj.setInteractionHandler(oIH)
238 Test.MethodTested(
"setInteractionHandler()", bOK)