update dev300-m58
[ooovba.git] / qadevOOo / tests / basic / ifc / ucb / XSimpleFileAccess / ucb_XSimpleFileAccess.xba
blob598f5e2c04f24b966572550cff6564bae5b0329c
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.
9 '
10 ' Copyright 2008 by Sun Microsystems, Inc.
12 ' OpenOffice.org - a multi-platform office productivity suite
14 ' $RCSfile: ucb_XSimpleFileAccess.xba,v $
16 ' $Revision: 1.3 $
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:
41 option explicit
45 Sub RunTest()
47 '*************************************************************************
48 ' INTERFACE:
49 ' com.sun.star.ucb.XSimpleFileAccess
50 '*************************************************************************
51 On Error Goto ErrHndl
52 Dim bOK As Boolean
53 Dim testDir As String
54 Dim cSubFolder As String
55 Dim cFile1 As String
56 Dim cFile2 As String
57 Dim cFile3 As String
58 Dim oFC As Variant
59 Dim oDT As Object
60 Dim oOS As Object
61 Dim oIS As Object
62 Dim cFileName As String
63 Dim cCrDate As String
64 Dim cType As String
65 Dim i As Integer
66 Dim k As Integer
67 Dim oIH As Object
69 Dim Bytes(5) As Integer
70 for i = 0 to 5
71 Bytes(i) = i
72 next i
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...")
84 bOK = true
85 bOK = bOK AND FileExists(cFile1)
86 bOK = bOK AND FileExists(cFile2)
87 if (NOT bOK) then
88 Out.Log("Can't find '" + cFile1 + "' and/or '" + cFile2 + "'")
89 Exit Sub
90 end if
92 Test.StartMethod("createFolder()")
93 bOK = true
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()")
100 bOK = true
101 bOK = bOK AND oObj.isFolder(cSubFolder)
102 bOK = bOK AND NOT oObj.isFolder(cFile1)
103 Test.MethodTested("isFolder()", bOK)
105 Test.StartMethod("getFolderContents()")
106 bOK = true
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))
111 i = 0
112 Out.Log("File list :")
113 while (cFileName &lt;&gt; "")
114 Out.Log(" " + cFileName)
115 i = i + 1
116 cFileName = Dir()
117 wend
119 bOK = bOK AND ubound(oFC) = i - 1
120 if (bOK) then
121 for k = 0 to i - 1
122 bOK = bOK AND FileExists(oFC(k))
123 next k
124 else
125 Out.Log("Amount of files in list is wrong: " + (ubound(oFC) + 1) + "," + i)
127 end if
129 Test.MethodTested("getFolderContents()", bOK)
131 Test.StartMethod("move()")
132 bOK = true
133 oObj.move(cFile2, cFile3)
134 bOK = bOK AND FileExists(cFile3) AND NOT FileExists(cFile2)
135 Test.MethodTested("move()", bOK)
137 Test.StartMethod("copy()")
138 bOK = true
139 oObj.copy(cFile3, cFile2)
140 bOK = bOK AND FileExists(cFile3) AND FileExists(cFile2)
141 Test.MethodTested("copy()", bOK)
143 Test.StartMethod("openFileWrite()")
144 bOK = true
146 Test.StartMethod("kill()")
147 bOK = true
148 oObj.kill(cFile3)
149 bOK = bOK AND NOT FileExists(cFile3)
150 Test.MethodTested("kill()", bOK)
152 Test.StartMethod("exists()")
153 bOK = true
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)
161 if (bOK) then
162 oOS.writeBytes(Bytes())
163 oOS.closeOutput()
164 end if
165 Test.MethodTested("openFileWrite()", bOK)
167 Test.StartMethod("getSize()")
168 bOK = true
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()")
175 bOK = true
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()")
184 bOK = true
185 cType = oObj.getContentType(cFile3)
186 Out.Log("Content Type is '" + cType + "'")
187 Test.MethodTested("getContentType()", bOK)
189 Test.StartMethod("getDateTimeModified()")
190 bOK = true
191 oDT = oObj.getDateTimeModified(cFile3)
192 cCrDate = Date()
195 bOK = bOK AND Day(cCrDate) = oDT.Day
196 bOK = bOK AND Month(cCrDate) = oDT.Month
197 bOK = bOK AND Year(cCrDate) = oDT.Year
199 if (NOT bOK) then
200 Out.Log("FileDateTime returned '" + cCrDate + "'")
201 Out.Log("getDateTimeModified returned '" + oDT.Day + "/" _
202 + oDT.Month + "/" _
203 + oDT.Year + " " _
204 + oDT.Hours + ":" _
205 + oDT.Minutes + ":" _
206 + oDT.Seconds + "'")
207 end if
208 Test.MethodTested("getDateTimeModified()", bOK)
210 Test.StartMethod("openFileRead()")
211 bOK = true
212 oIS = oObj.openFileRead(cFile3)
213 bOK = bOK AND NOT isNULL(oIS)
214 Dim rData(10) As Integer
215 Dim nRb As Integer
216 nRb = oIS.readBytes(rData(), 100)
217 bOK = bOK AND nRb = ubound(Bytes()) + 1
218 if (NOT bOK) then
219 Out.Log("Amount of read files is wrong")
220 else
221 for i = 0 to nRb - 1
222 bOK = bOK AND Bytes(i) = rData(i)
223 next i
224 end if
225 oIS.closeInput()
226 Test.MethodTested("openFileRead()", bOK)
228 Test.StartMethod("openFileReadWrite()")
229 bOK = true
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()")
235 bOK = true
236 oIH = createUNOInterface("com.sun.star.sdb.InteractionHandler")
237 oObj.setInteractionHandler(oIH)
238 Test.MethodTested("setInteractionHandler()", bOK)
240 Exit Sub
241 ErrHndl:
242 Test.Exception()
243 bOK = false
244 resume next
245 End Sub
246 </script:module>