1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.ucb; 29 30 import lib.MultiMethodTest; 31 32 import com.sun.star.io.XInputStream; 33 import com.sun.star.lang.XMultiServiceFactory; 34 import com.sun.star.ucb.XSimpleFileAccess2; 35 36 /** 37 * Testing <code>com.sun.star.ucb.XSimpleFileAccess2</code> 38 * interface methods. <p> 39 * @see com.sun.star.ucb.XSimpleFileAccess2 40 */ 41 public class _XSimpleFileAccess2 extends MultiMethodTest { 42 43 public static XSimpleFileAccess2 oObj = null; 44 45 /** 46 * Writes <b>XSimpleFileAccess_new.txt</b> to disk, checks 47 * if it was successfully created and then deletes it. <p> 48 * Has <b> OK </b> status if after method call the file 49 * exists and no exceptions were thrown. <p> 50 */ 51 public void _writeFile() { 52 boolean result = true; 53 try { 54 String dirnameTo = util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) ; 55 String fileURL = dirnameTo + "XSimpleFileAccess_new.txt"; 56 String dirname = util.utils.getFullTestURL("XSimpleFileAccess"); 57 String filename = dirname+"XSimpleFileAccess.txt"; 58 XInputStream iStream = oObj.openFileRead(filename); 59 oObj.writeFile(fileURL,iStream); 60 shortWait(); 61 result = oObj.exists(fileURL); 62 oObj.kill(fileURL); 63 tRes.tested("writeFile()",result); 64 } 65 catch (com.sun.star.ucb.CommandAbortedException ex) { 66 log.println("CommandAbortedException occured while testing "+ 67 "'writeFile()'"); 68 ex.printStackTrace(log); 69 tRes.tested("writeFile()",false); 70 } 71 catch (com.sun.star.uno.Exception ex) { 72 log.println("Exception occured while testing 'writeFile()'"); 73 ex.printStackTrace(log); 74 tRes.tested("writeFile()",false); 75 } 76 77 } //EOF writeFile() 78 79 /** 80 * Sleeps for 1 sec. to allow StarOffice to react on <code> 81 * reset</code> call. 82 */ 83 private void shortWait() { 84 try { 85 Thread.sleep(1000) ; 86 } catch (InterruptedException e) { 87 log.println("While waiting :" + e) ; 88 } 89 } 90 91 } // finish class _XSimpleFileAccess 92 93