1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.ucb;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.io.XInputStream;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.ucb.XSimpleFileAccess2;
31 
32 /**
33 * Testing <code>com.sun.star.ucb.XSimpleFileAccess2</code>
34 * interface methods. <p>
35 * @see com.sun.star.ucb.XSimpleFileAccess2
36 */
37 public class _XSimpleFileAccess2 extends MultiMethodTest {
38 
39     public static XSimpleFileAccess2 oObj = null;
40 
41     /**
42     * Writes <b>XSimpleFileAccess_new.txt</b> to disk, checks
43     * if it was successfully created and then deletes it. <p>
44     * Has <b> OK </b> status if after method call the file
45     * exists and no exceptions were thrown. <p>
46     */
_writeFile()47     public void _writeFile() {
48         boolean result = true;
49         try {
50             String dirnameTo = util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) ;
51             String fileURL = dirnameTo + "XSimpleFileAccess_new.txt";
52             String dirname = util.utils.getFullTestURL("XSimpleFileAccess");
53             String filename = dirname+"XSimpleFileAccess.txt";
54             XInputStream iStream = oObj.openFileRead(filename);
55             oObj.writeFile(fileURL,iStream);
56             shortWait();
57             result = oObj.exists(fileURL);
58             oObj.kill(fileURL);
59             tRes.tested("writeFile()",result);
60         }
61         catch (com.sun.star.ucb.CommandAbortedException ex) {
62             log.println("CommandAbortedException occurred while testing "+
63                 "'writeFile()'");
64             ex.printStackTrace(log);
65             tRes.tested("writeFile()",false);
66         }
67         catch (com.sun.star.uno.Exception ex) {
68             log.println("Exception occurred while testing 'writeFile()'");
69             ex.printStackTrace(log);
70             tRes.tested("writeFile()",false);
71         }
72 
73     } //EOF writeFile()
74 
75     /**
76     * Sleeps for 1 sec. to allow StarOffice to react on <code>
77     * reset</code> call.
78     */
shortWait()79     private void shortWait() {
80         try {
81             Thread.sleep(1000) ;
82         } catch (InterruptedException e) {
83             log.println("While waiting :" + e) ;
84         }
85     }
86 
87 }  // finish class _XSimpleFileAccess
88 
89