1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.ucb;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir import lib.Status;
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
31cdf0e10cSrcweir import com.sun.star.task.XInteractionHandler;
32cdf0e10cSrcweir import com.sun.star.ucb.XSimpleFileAccess;
33cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
34cdf0e10cSrcweir import com.sun.star.util.DateTime;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir /**
37cdf0e10cSrcweir * Testing <code>com.sun.star.ucb.XSimpleFileAccess</code>
38cdf0e10cSrcweir * interface methods. <p>
39cdf0e10cSrcweir * The following predefined files needed to complete the test:
40cdf0e10cSrcweir * <ul>
41cdf0e10cSrcweir *  <li> <code>XSimpleFileAccess/XSimpleFileAccess.txt</code> :
42cdf0e10cSrcweir *   text file of length 17 and 2000 year created .</li>
43cdf0e10cSrcweir *  <li> <code>XSimpleFileAccess/XSimpleFileAccess2.txt</code> :
44cdf0e10cSrcweir *   text file for <code>openFileReadWrite</code> method test.</li>
45cdf0e10cSrcweir * <ul> <p>
46cdf0e10cSrcweir * This test needs the following object relations :
47cdf0e10cSrcweir * <ul>
48cdf0e10cSrcweir *  <li> <code>'InteractionHandler'</code>
49cdf0e10cSrcweir *  (of type <code>XInteractionHandler</code>)
50cdf0e10cSrcweir *  instance of <code>com.sun.star.sdb.InteractionHandler</code>
51cdf0e10cSrcweir *  </li>
52cdf0e10cSrcweir * </ul> <p>
53cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
54cdf0e10cSrcweir * @see com.sun.star.ucb.XSimpleFileAccess
55cdf0e10cSrcweir */
56cdf0e10cSrcweir public class _XSimpleFileAccess extends MultiMethodTest {
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     public static XSimpleFileAccess oObj = null;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     /**
61cdf0e10cSrcweir     * Copies <b>XSimpleFileAccess.txt</b> to a new file, checks
62cdf0e10cSrcweir     * if it was successfully copied and then deletes it. <p>
63cdf0e10cSrcweir     * Has <b> OK </b> status if after method call new copy of file
64cdf0e10cSrcweir     * exists and no exceptions were thrown. <p>
65cdf0e10cSrcweir     */
_copy()66cdf0e10cSrcweir     public void _copy() {
67cdf0e10cSrcweir         try {
68cdf0e10cSrcweir             String copiedFile = "";
69cdf0e10cSrcweir             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
70cdf0e10cSrcweir             String dirnameTo = util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) ;
71cdf0e10cSrcweir             String filename = dirname+"XSimpleFileAccess.txt";
72cdf0e10cSrcweir             copiedFile = dirnameTo + "XSimpleFileAccess_copy.txt";
73cdf0e10cSrcweir 
74cdf0e10cSrcweir             if (oObj.exists(copiedFile))
75cdf0e10cSrcweir                 oObj.kill(copiedFile);
76cdf0e10cSrcweir 
77cdf0e10cSrcweir             oObj.copy(filename,copiedFile);
78cdf0e10cSrcweir             tRes.tested("copy()",oObj.exists(copiedFile));
79cdf0e10cSrcweir             oObj.kill(copiedFile);
80cdf0e10cSrcweir         }
81cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
82*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'copy()'");
83cdf0e10cSrcweir             ex.printStackTrace(log);
84cdf0e10cSrcweir             tRes.tested("copy()",false);
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     } //EOF copy()
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     /**
90cdf0e10cSrcweir     * Copies <b>XSimpleFileAccess.txt</b> to a new file, tries to
91cdf0e10cSrcweir     * rename it, then checks
92cdf0e10cSrcweir     * if it was successfully renamed and then deletes it. <p>
93cdf0e10cSrcweir     * Has <b> OK </b> status if after method call new file
94cdf0e10cSrcweir     * exists and no exceptions were thrown. <p>
95cdf0e10cSrcweir     */
_move()96cdf0e10cSrcweir     public void _move() {
97cdf0e10cSrcweir         try {
98cdf0e10cSrcweir             String copiedFile = "";
99cdf0e10cSrcweir             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
100cdf0e10cSrcweir             String dirnameTo = util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) ;
101cdf0e10cSrcweir             String filename = dirname+"XSimpleFileAccess.txt";
102cdf0e10cSrcweir             copiedFile = dirnameTo + "XSimpleFileAccess_copy.txt";
103cdf0e10cSrcweir 
104cdf0e10cSrcweir             if (oObj.exists(copiedFile))
105cdf0e10cSrcweir                 oObj.kill(copiedFile);
106cdf0e10cSrcweir 
107cdf0e10cSrcweir             oObj.copy(filename,copiedFile);
108cdf0e10cSrcweir             filename = copiedFile;
109cdf0e10cSrcweir             copiedFile = dirnameTo + "XSimpleFileAccess_move.txt";
110cdf0e10cSrcweir             oObj.move(filename,copiedFile);
111cdf0e10cSrcweir             tRes.tested("move()",oObj.exists(copiedFile));
112cdf0e10cSrcweir             oObj.kill(copiedFile);
113cdf0e10cSrcweir         }
114cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
115*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'move()'");
116cdf0e10cSrcweir             ex.printStackTrace(log);
117cdf0e10cSrcweir             tRes.tested("move()",false);
118cdf0e10cSrcweir         }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     } //EOF move()
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     /**
123cdf0e10cSrcweir     * Copies <b>XSimpleFileAccess.txt</b> to a new file, deletes it
124cdf0e10cSrcweir     * and checks if it isn't exist. <p>
125cdf0e10cSrcweir     * Has <b> OK </b> status if after method call new copy of file
126cdf0e10cSrcweir     * doesn't exist and no exceptions were thrown. <p>
127cdf0e10cSrcweir     */
_kill()128cdf0e10cSrcweir     public void _kill() {
129cdf0e10cSrcweir         try {
130cdf0e10cSrcweir             String copiedFile = "";
131cdf0e10cSrcweir             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
132cdf0e10cSrcweir             String dirnameTo = util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) ;
133cdf0e10cSrcweir             String filename = dirname+"XSimpleFileAccess.txt";
134cdf0e10cSrcweir             copiedFile = dirnameTo + "XSimpleFileAccess_copy.txt";
135cdf0e10cSrcweir 
136cdf0e10cSrcweir             if (oObj.exists(copiedFile))
137cdf0e10cSrcweir                 oObj.kill(copiedFile);
138cdf0e10cSrcweir 
139cdf0e10cSrcweir             oObj.copy(filename,copiedFile);
140cdf0e10cSrcweir             oObj.kill(copiedFile);
141cdf0e10cSrcweir             tRes.tested("kill()",!oObj.exists(copiedFile));
142cdf0e10cSrcweir         }
143cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
144*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'kill()'");
145cdf0e10cSrcweir             ex.printStackTrace(log);
146cdf0e10cSrcweir             tRes.tested("kill()",false);
147cdf0e10cSrcweir         }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     } //EOF kill()
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     /**
152cdf0e10cSrcweir     * Tries to check if <b>XSimpleFileAccess</b> is folder. <p>
153cdf0e10cSrcweir     * Has <b>OK</b> status if the method returns <code>true</code>
154cdf0e10cSrcweir     */
_isFolder()155cdf0e10cSrcweir     public void _isFolder() {
156cdf0e10cSrcweir         try {
157cdf0e10cSrcweir             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
158cdf0e10cSrcweir             tRes.tested("isFolder()",oObj.isFolder(dirname));
159cdf0e10cSrcweir         }
160cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
161*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'isFolder()'");
162cdf0e10cSrcweir             ex.printStackTrace(log);
163cdf0e10cSrcweir             tRes.tested("isFolder()",false);
164cdf0e10cSrcweir         }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     } //EOF isFolder()
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     /**
169cdf0e10cSrcweir      * Copies <b>XSimpleFileAccess.txt</b> to a new file, sets
170cdf0e10cSrcweir      * 'READONLY' attribute and checks it. Second clears 'READONLY'
171cdf0e10cSrcweir      * attribute and checks it again. The copy of file is deleted
172cdf0e10cSrcweir      * finally.<p>
173cdf0e10cSrcweir      *
174cdf0e10cSrcweir      * Has <b> OK </b> status if in the first case method returns
175cdf0e10cSrcweir      * <code></code>, and in the second case - <code>false</code>
176cdf0e10cSrcweir      * and no exceptions were thrown. <p>
177cdf0e10cSrcweir      *
178cdf0e10cSrcweir      * The following method tests are to be completed successfully before :
179cdf0e10cSrcweir      * <ul>
180cdf0e10cSrcweir      *  <li> <code> setReadOnly </code> </li>
181cdf0e10cSrcweir      * </ul>
182cdf0e10cSrcweir      */
_isReadOnly()183cdf0e10cSrcweir     public void _isReadOnly() {
184cdf0e10cSrcweir         requiredMethod("setReadOnly()");
185cdf0e10cSrcweir         try {
186cdf0e10cSrcweir             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
187cdf0e10cSrcweir             String filename = dirname+"XSimpleFileAccess.txt";
188cdf0e10cSrcweir             boolean result = true;
189cdf0e10cSrcweir 
190cdf0e10cSrcweir             String dirnameTo = util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) ;
191cdf0e10cSrcweir             String readonlyCopy = dirnameTo + "XSimpleFileAccess_copy.txt" ;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir             if (oObj.exists(readonlyCopy))
194cdf0e10cSrcweir                 oObj.kill(readonlyCopy);
195cdf0e10cSrcweir 
196cdf0e10cSrcweir             oObj.copy(filename, readonlyCopy);
197cdf0e10cSrcweir 
198cdf0e10cSrcweir             oObj.setReadOnly(readonlyCopy, true);
199cdf0e10cSrcweir             result &= oObj.isReadOnly(readonlyCopy);
200cdf0e10cSrcweir             oObj.setReadOnly(readonlyCopy, false);
201cdf0e10cSrcweir             result &= !oObj.isReadOnly(readonlyCopy);
202cdf0e10cSrcweir 
203cdf0e10cSrcweir             oObj.kill(readonlyCopy);
204cdf0e10cSrcweir             tRes.tested("isReadOnly()",result);
205cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception ex) {
206*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'isReadOnly()'");
207cdf0e10cSrcweir             ex.printStackTrace(log);
208cdf0e10cSrcweir             tRes.tested("isReadOnly()",false);
209cdf0e10cSrcweir         }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     } //EOF isReadOnly()
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     /**
215cdf0e10cSrcweir      * Copies <b>XSimpleFileAccess.txt</b> to a new file, sets
216cdf0e10cSrcweir      * 'READONLY' attribute and checks it. Second clears 'READONLY'
217cdf0e10cSrcweir      * attribute and checks it again. The copy of file is deleted
218cdf0e10cSrcweir      * finally.<p>
219cdf0e10cSrcweir      *
220cdf0e10cSrcweir      * Has <b> OK </b> status if in the first case method returns
221cdf0e10cSrcweir      * <code></code>, and in the second case - <code>false</code>
222cdf0e10cSrcweir      * and no exceptions were thrown. <p>
223cdf0e10cSrcweir      *
224cdf0e10cSrcweir      * The following method tests are to be completed successfully before :
225cdf0e10cSrcweir      * <ul>
226cdf0e10cSrcweir      *  <li> <code> setReadOnly </code> </li>
227cdf0e10cSrcweir      * </ul>
228cdf0e10cSrcweir      */
_setReadOnly()229cdf0e10cSrcweir     public void _setReadOnly() {
230cdf0e10cSrcweir         boolean result = true ;
231cdf0e10cSrcweir 
232cdf0e10cSrcweir         try {
233cdf0e10cSrcweir             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
234cdf0e10cSrcweir             String filename = dirname+"XSimpleFileAccess.txt";
235cdf0e10cSrcweir 
236cdf0e10cSrcweir             String dirnameTo = util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) ;
237cdf0e10cSrcweir             String readonlyCopy = dirnameTo + "XSimpleFileAccess_copy.txt" ;
238cdf0e10cSrcweir 
239cdf0e10cSrcweir             if (oObj.exists(readonlyCopy))
240cdf0e10cSrcweir                 oObj.kill(readonlyCopy);
241cdf0e10cSrcweir 
242cdf0e10cSrcweir             oObj.copy(filename, readonlyCopy);
243cdf0e10cSrcweir 
244cdf0e10cSrcweir             oObj.setReadOnly(readonlyCopy, true);
245cdf0e10cSrcweir             result &= oObj.isReadOnly(readonlyCopy) ;
246cdf0e10cSrcweir             oObj.setReadOnly(readonlyCopy, false);
247cdf0e10cSrcweir             result &= !oObj.isReadOnly(readonlyCopy) ;
248cdf0e10cSrcweir             tRes.tested("setReadOnly()", result);
249cdf0e10cSrcweir 
250cdf0e10cSrcweir             oObj.kill(readonlyCopy);
251cdf0e10cSrcweir         }
252cdf0e10cSrcweir         catch (Exception ex) {
253*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'setReadOnly()'");
254cdf0e10cSrcweir             ex.printStackTrace(log);
255cdf0e10cSrcweir             tRes.tested("setReadOnly()",false);
256cdf0e10cSrcweir         }
257cdf0e10cSrcweir     } //EOF setReadOnly()
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     /**
260cdf0e10cSrcweir      * Creates folder and then checks if it was successfully created. <p>
261cdf0e10cSrcweir      * Has <b>OK</b> status if folder was created and no exceptions
262cdf0e10cSrcweir      * were thrown.
263cdf0e10cSrcweir      */
_createFolder()264cdf0e10cSrcweir     public void _createFolder() {
265cdf0e10cSrcweir         try {
266cdf0e10cSrcweir             String tmpdirname = util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) ;
267cdf0e10cSrcweir             String newFolder = tmpdirname+"SimpleSubFolder";
268cdf0e10cSrcweir 
269cdf0e10cSrcweir             if (oObj.exists(newFolder))
270cdf0e10cSrcweir                 oObj.kill(newFolder);
271cdf0e10cSrcweir 
272cdf0e10cSrcweir             oObj.createFolder(newFolder);
273cdf0e10cSrcweir             tRes.tested("createFolder()",oObj.isFolder(newFolder));
274cdf0e10cSrcweir             oObj.kill(newFolder);
275cdf0e10cSrcweir         }
276cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
277*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'createFolder()'");
278cdf0e10cSrcweir             ex.printStackTrace(log);
279cdf0e10cSrcweir             tRes.tested("createFolder()",false);
280cdf0e10cSrcweir         }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     } //EOF createFolder()
283cdf0e10cSrcweir 
284cdf0e10cSrcweir     /**
285cdf0e10cSrcweir     * Test calls the method and checks return value and that
286cdf0e10cSrcweir     * no exceptions were thrown. <b>XSimpleFileAccess.txt</b>
287cdf0e10cSrcweir     * file tested.<p>
288cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns <code>17</code>
289cdf0e10cSrcweir     * and no exceptions were thrown. <p>
290cdf0e10cSrcweir     */
_getSize()291cdf0e10cSrcweir     public void _getSize() {
292cdf0e10cSrcweir         try {
293cdf0e10cSrcweir             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
294cdf0e10cSrcweir             String filename = dirname+"XSimpleFileAccess.txt";
295cdf0e10cSrcweir             int fSize = oObj.getSize(filename);
296cdf0e10cSrcweir             tRes.tested("getSize()", fSize == 17 );
297cdf0e10cSrcweir         }
298cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
299*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'getSize()'");
300cdf0e10cSrcweir             ex.printStackTrace(log);
301cdf0e10cSrcweir             tRes.tested("getSize()",false);
302cdf0e10cSrcweir         }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir     } //EOF getSize()
305cdf0e10cSrcweir 
306cdf0e10cSrcweir     /**
307cdf0e10cSrcweir     * Test calls the method and checks return value and that
308cdf0e10cSrcweir     * no exceptions were thrown. <b>XSimpleFileAccess.txt</b>
309cdf0e10cSrcweir     * file tested.<p>
310cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns String
311cdf0e10cSrcweir     * <code>'application/vnd.sun.staroffice.fsys-file'</code>
312cdf0e10cSrcweir     * and no exceptions were thrown. <p>
313cdf0e10cSrcweir     */
_getContentType()314cdf0e10cSrcweir     public void _getContentType() {
315cdf0e10cSrcweir         try {
316cdf0e10cSrcweir             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
317cdf0e10cSrcweir             String filename = dirname+"XSimpleFileAccess.txt";
318cdf0e10cSrcweir             String fType = oObj.getContentType(filename);
319cdf0e10cSrcweir             tRes.tested("getContentType()",
320cdf0e10cSrcweir                 "application/vnd.sun.staroffice.fsys-file".equals(fType) );
321cdf0e10cSrcweir         }
322cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
323*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'getContentType()'");
324cdf0e10cSrcweir             ex.printStackTrace(log);
325cdf0e10cSrcweir             tRes.tested("getContentType()",false);
326cdf0e10cSrcweir         }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir     } //EOF getContentType()
329cdf0e10cSrcweir 
330cdf0e10cSrcweir     /**
331cdf0e10cSrcweir     * Test calls the method and checks return value and that
332cdf0e10cSrcweir     * no exceptions were thrown. <b>XSimpleFileAccess.txt</b>
333cdf0e10cSrcweir     * file tested.<p>
334cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns date with
335cdf0e10cSrcweir     * 2001 year and no exceptions were thrown. <p>
336cdf0e10cSrcweir     */
_getDateTimeModified()337cdf0e10cSrcweir     public void _getDateTimeModified() {
338cdf0e10cSrcweir         try {
339cdf0e10cSrcweir             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
340cdf0e10cSrcweir             String filename = dirname+"XSimpleFileAccess.txt";
341cdf0e10cSrcweir             DateTime fTime = oObj.getDateTimeModified(filename);
342cdf0e10cSrcweir 
343cdf0e10cSrcweir             java.io.File the_file = new java.io.File(filename);
344cdf0e10cSrcweir             long lastModified = the_file.lastModified();
345cdf0e10cSrcweir             java.util.Date lastMod = new java.util.Date(lastModified);
346cdf0e10cSrcweir 
347cdf0e10cSrcweir             //compare the dates gained by java with those gained by this method
348cdf0e10cSrcweir             boolean res = true;
349cdf0e10cSrcweir             boolean partResult = (fTime.Day == lastMod.getDay());
350cdf0e10cSrcweir             if (!partResult) {
351cdf0e10cSrcweir                 log.println("Wrong Day");
352cdf0e10cSrcweir                 log.println("Expected: "+lastMod.getDay());
353cdf0e10cSrcweir                 log.println("Gained: "+fTime.Day);
354cdf0e10cSrcweir                 log.println("------------------------------");
355cdf0e10cSrcweir             }
356cdf0e10cSrcweir             partResult = (fTime.Month == lastMod.getMonth());
357cdf0e10cSrcweir             if (!partResult) {
358cdf0e10cSrcweir                 log.println("Wrong Month");
359cdf0e10cSrcweir                 log.println("Expected: "+lastMod.getMonth());
360cdf0e10cSrcweir                 log.println("Gained: "+fTime.Month);
361cdf0e10cSrcweir                 log.println("------------------------------");
362cdf0e10cSrcweir             }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir             partResult = (fTime.Year == lastMod.getYear());
365cdf0e10cSrcweir             if (!partResult) {
366cdf0e10cSrcweir                 log.println("Wrong Year");
367cdf0e10cSrcweir                 log.println("Expected: "+lastMod.getYear());
368cdf0e10cSrcweir                 log.println("Gained: "+fTime.Year);
369cdf0e10cSrcweir                 log.println("------------------------------");
370cdf0e10cSrcweir             }
371cdf0e10cSrcweir 
372cdf0e10cSrcweir             tRes.tested("getDateTimeModified()", res);
373cdf0e10cSrcweir         }
374cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
375*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'getDateTimeModified()'");
376cdf0e10cSrcweir             ex.printStackTrace(log);
377cdf0e10cSrcweir             tRes.tested("getDateTimeModified()",false);
378cdf0e10cSrcweir         }
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     } //EOF getDateTimeModified()
381cdf0e10cSrcweir 
382cdf0e10cSrcweir     /**
383cdf0e10cSrcweir     * Test calls the method and checks return value and that
384cdf0e10cSrcweir     * no exceptions were thrown. <b>XSimpleFileAccess</b>
385cdf0e10cSrcweir     * directory used.<p>
386cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns non zero length
387cdf0e10cSrcweir     * array and no exceptions were thrown. <p>
388cdf0e10cSrcweir     */
_getFolderContents()389cdf0e10cSrcweir     public void _getFolderContents() {
390cdf0e10cSrcweir         try {
391cdf0e10cSrcweir             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
392cdf0e10cSrcweir             String[] cont = oObj.getFolderContents(dirname,false);
393cdf0e10cSrcweir             tRes.tested("getFolderContents()", cont.length>0);
394cdf0e10cSrcweir         }
395cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
396*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'getFolderContents()'");
397cdf0e10cSrcweir             ex.printStackTrace(log);
398cdf0e10cSrcweir             tRes.tested("getFolderContents()",false);
399cdf0e10cSrcweir         }
400cdf0e10cSrcweir 
401cdf0e10cSrcweir     } //EOF getFolderContents()
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     /**
404cdf0e10cSrcweir     * First it check file <b>XSimpleFileAccess.txt</b> for
405cdf0e10cSrcweir     * existence, second file <b>I_do_not_exists.txt</b> is checked
406cdf0e10cSrcweir     * for existence. <p>
407cdf0e10cSrcweir     * Has <b> OK </b> status if in the first case method returns
408cdf0e10cSrcweir     * <code>true</code> and in the second - <code>flase</code>
409cdf0e10cSrcweir     * and no exceptions were thrown. <p>
410cdf0e10cSrcweir     */
_exists()411cdf0e10cSrcweir     public void _exists() {
412cdf0e10cSrcweir         try {
413cdf0e10cSrcweir             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
414cdf0e10cSrcweir             String filename = dirname+"XSimpleFileAccess.txt";
415cdf0e10cSrcweir             String wrongname = dirname+"I_do_not_exists.txt";
416cdf0e10cSrcweir             tRes.tested("exists()",
417cdf0e10cSrcweir                 oObj.exists(filename) && !oObj.exists(wrongname));
418cdf0e10cSrcweir         }
419cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
420*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'exists()'");
421cdf0e10cSrcweir             ex.printStackTrace(log);
422cdf0e10cSrcweir             tRes.tested("exists()",false);
423cdf0e10cSrcweir         }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir     } //EOF exists()
426cdf0e10cSrcweir 
427cdf0e10cSrcweir     /**
428cdf0e10cSrcweir     * Test calls the method and checks return value and that
429cdf0e10cSrcweir     * no exceptions were thrown. <b>XSimpleFileAccess.txt</b>
430cdf0e10cSrcweir     * file used.<p>
431cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns not
432cdf0e10cSrcweir     * <code>null</code> value and no exceptions were thrown. <p>
433cdf0e10cSrcweir     */
_openFileRead()434cdf0e10cSrcweir     public void _openFileRead() {
435cdf0e10cSrcweir         try {
436cdf0e10cSrcweir             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
437cdf0e10cSrcweir             String filename = dirname+"XSimpleFileAccess.txt";
438cdf0e10cSrcweir             com.sun.star.io.XInputStream iStream = oObj.openFileRead(filename);
439cdf0e10cSrcweir             tRes.tested("openFileRead()", iStream != null);
440cdf0e10cSrcweir         }
441cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
442*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'openFileRead()'");
443cdf0e10cSrcweir             ex.printStackTrace(log);
444cdf0e10cSrcweir             tRes.tested("openFileRead()",false);
445cdf0e10cSrcweir         }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir     } //EOF openFileRead()
448cdf0e10cSrcweir 
449cdf0e10cSrcweir     /**
450cdf0e10cSrcweir     * Test calls the method and checks return value and that
451cdf0e10cSrcweir     * no exceptions were thrown. <b>XSimpleFileAccess.txt</b>
452cdf0e10cSrcweir     * file used.<p>
453cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns not
454cdf0e10cSrcweir     * <code>null</code> value and no exceptions were thrown. <p>
455cdf0e10cSrcweir     */
_openFileWrite()456cdf0e10cSrcweir     public void _openFileWrite() {
457cdf0e10cSrcweir         try {
458cdf0e10cSrcweir             String tmpdirname = util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) ;
459cdf0e10cSrcweir 
460cdf0e10cSrcweir             String copiedFile = tmpdirname+"XSimpleFileAccess_openWrite.txt";
461cdf0e10cSrcweir 
462cdf0e10cSrcweir             if (oObj.exists(copiedFile))
463cdf0e10cSrcweir                 oObj.kill(copiedFile);
464cdf0e10cSrcweir 
465cdf0e10cSrcweir             com.sun.star.io.XOutputStream oStream =
466cdf0e10cSrcweir                 oObj.openFileWrite(copiedFile);
467cdf0e10cSrcweir             tRes.tested("openFileWrite()", oStream != null);
468cdf0e10cSrcweir 
469cdf0e10cSrcweir             oStream.closeOutput();
470cdf0e10cSrcweir             oObj.kill(copiedFile);
471cdf0e10cSrcweir         }
472cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
473*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'openFileWrite()'");
474cdf0e10cSrcweir             ex.printStackTrace(log);
475cdf0e10cSrcweir             tRes.tested("openFileWrite()",false);
476cdf0e10cSrcweir         }
477cdf0e10cSrcweir 
478cdf0e10cSrcweir     } //EOF openFileWrite()
479cdf0e10cSrcweir 
480cdf0e10cSrcweir     /**
481cdf0e10cSrcweir     * Test calls the method and checks return value and that
482cdf0e10cSrcweir     * no exceptions were thrown. <b>XSimpleFileAccess2.txt</b>
483cdf0e10cSrcweir     * file used.<p>
484cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns not
485cdf0e10cSrcweir     * <code>null</code> value and no exceptions were thrown. <p>
486cdf0e10cSrcweir     */
_openFileReadWrite()487cdf0e10cSrcweir     public void _openFileReadWrite() {
488cdf0e10cSrcweir         try {
489cdf0e10cSrcweir             String dirnameTo = util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) ;
490cdf0e10cSrcweir             String copiedFile = dirnameTo + "XSimpleFileAccess2.txt" ;
491cdf0e10cSrcweir 
492cdf0e10cSrcweir             if (oObj.exists(copiedFile))
493cdf0e10cSrcweir                 oObj.kill(copiedFile);
494cdf0e10cSrcweir 
495cdf0e10cSrcweir             com.sun.star.io.XStream aStream =
496cdf0e10cSrcweir                 oObj.openFileReadWrite(copiedFile);
497cdf0e10cSrcweir             tRes.tested("openFileReadWrite()", aStream != null);
498cdf0e10cSrcweir 
499cdf0e10cSrcweir             aStream.getInputStream().closeInput();
500cdf0e10cSrcweir             aStream.getOutputStream().closeOutput();
501cdf0e10cSrcweir 
502cdf0e10cSrcweir             oObj.kill(copiedFile);
503cdf0e10cSrcweir         }
504cdf0e10cSrcweir         catch (com.sun.star.uno.Exception ex) {
505*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'openFileReadWrite()'");
506cdf0e10cSrcweir             ex.printStackTrace(log);
507cdf0e10cSrcweir             tRes.tested("openFileReadWrite()",false);
508cdf0e10cSrcweir         }
509cdf0e10cSrcweir 
510cdf0e10cSrcweir     } //EOF openFileReadWrite()
511cdf0e10cSrcweir 
512cdf0e10cSrcweir     /**
513cdf0e10cSrcweir     * Test calls the method and checks that no exceptions were thrown.
514cdf0e10cSrcweir     * Has <b> OK </b> status if no exceptions were thrown. <p>
515cdf0e10cSrcweir     */
_setInteractionHandler()516cdf0e10cSrcweir     public void _setInteractionHandler() {
517cdf0e10cSrcweir         XInteractionHandler handler = null;
518170fb961SPedro Giffuni         Object oHandler = tEnv.getObjRelation("InteractionHandler");
519cdf0e10cSrcweir 
520cdf0e10cSrcweir         if (oHandler == null)
521cdf0e10cSrcweir             throw new StatusException
522cdf0e10cSrcweir                 (Status.failed("Reelation InteractionHandler not found"));
523cdf0e10cSrcweir 
524cdf0e10cSrcweir         try {
525cdf0e10cSrcweir             handler = (XInteractionHandler)UnoRuntime.queryInterface
526cdf0e10cSrcweir                 (XInteractionHandler.class, oHandler);
527cdf0e10cSrcweir             oObj.setInteractionHandler(handler);
528cdf0e10cSrcweir             tRes.tested("setInteractionHandler()", true);
529cdf0e10cSrcweir         } catch (Exception ex) {
530*bb6af6bcSPedro Giffuni             log.println("Exception occurred while testing 'setInteractionHandler()'");
531cdf0e10cSrcweir             ex.printStackTrace(log);
532cdf0e10cSrcweir             tRes.tested("setInteractionHandler()", false);
533cdf0e10cSrcweir         }
534cdf0e10cSrcweir 
535cdf0e10cSrcweir     } //EOF setInteractionHandler()
536cdf0e10cSrcweir 
537cdf0e10cSrcweir }  // finish class _XSimpleFileAccess
538cdf0e10cSrcweir 
539