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