Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / system / _XSystemShellExecute.java
blob6ef8da0c381f9a3d71eb2c2ca2e16a463d191ecb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSystemShellExecute.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.system;
33 import lib.MultiMethodTest;
34 import util.utils;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.system.XSystemShellExecute;
38 import com.sun.star.ucb.XSimpleFileAccess;
39 import com.sun.star.uno.UnoRuntime;
42 /**
43 * Testing <code>com.sun.star.system.XSystemShellExecute</code>
44 * interface methods :
45 * <ul>
46 * <li><code> execute()</code></li>
47 * </ul> <p>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * @see com.sun.star.system.XSystemShellExecute
51 public class _XSystemShellExecute extends MultiMethodTest {
53 public XSystemShellExecute oObj = null;
55 /**
56 * Excecutes 'java SystemShellExecute SystemShellExecute.txt' command line.
57 * <p>Has <b> OK </b> status if the method successfully returns
58 * and file 'SystemShellExecute.txt' was created. <p>
60 public void _execute() {
61 String cClassPath = System.getProperty("DOCPTH");
62 String cResFile = utils.getOfficeTempDirSys((XMultiServiceFactory)tParam.getMSF())+"SystemShellExecute.txt";
63 String cResURL = utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF())+"SystemShellExecute.txt";
64 String cArgs = "-classpath " + cClassPath +
65 " SystemShellExecute " + cResFile;
67 String jh = System.getProperty("java.home");
68 String fs = System.getProperty("file.separator");
69 String cmd = jh+fs+"bin"+fs+"java";
71 log.println("Executing : '"+cmd+" " + cArgs + "'");
72 try {
73 oObj.execute(cmd, cArgs, 1);
74 } catch (com.sun.star.system.SystemShellExecuteException e) {
75 log.println("Exception during execute: " + e);
76 log.println("This has been implemented due to security reasons");
77 tRes.tested("execute()", true);
78 return;
79 } catch (com.sun.star.lang.IllegalArgumentException e) {
80 log.println("Exception during execute: " + e);
81 tRes.tested("execute()", false);
82 return;
85 XSimpleFileAccess xFileAccess = null;
86 try {
87 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
88 Object fa = xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess");
89 xFileAccess = (XSimpleFileAccess)
90 UnoRuntime.queryInterface(XSimpleFileAccess.class, fa);
91 } catch (com.sun.star.uno.Exception e) {
92 log.println("Couldn't create SimpleFileAccess:" + e);
93 tRes.tested("execute()", false);
96 log.println("Waiting while the file will be created or timeout "+
97 "reached ...");
98 boolean bExist = false;
99 int i = 0;
100 while (i < 20 && !bExist) {
101 try {
102 bExist = xFileAccess.exists(cResURL);
103 } catch(com.sun.star.uno.Exception e) {
104 log.println("Exception:" + e);
106 shortWait();
107 i++;
110 if (bExist) {
111 log.println("The command was executed and file created in " +
112 i + " sec.");
113 } else {
114 log.println("File was not created");
117 tRes.tested("execute()", bExist);
121 * Sleeps to allow StarOffice to react on <code>
122 * reset</code> call.
124 private void shortWait() {
125 try {
126 Thread.sleep(1000) ;
127 } catch (InterruptedException e) {
128 log.println("While waiting :" + e) ;
131 } // finish class _XSystemShellExecute