1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSystemShellExecute.java,v $
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 ************************************************************************/
33 import lib
.MultiMethodTest
;
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
;
43 * Testing <code>com.sun.star.system.XSystemShellExecute</code>
46 * <li><code> execute()</code></li>
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;
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
+ "'");
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);
79 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
80 log
.println("Exception during execute: " + e
);
81 tRes
.tested("execute()", false);
85 XSimpleFileAccess xFileAccess
= null;
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 "+
98 boolean bExist
= false;
100 while (i
< 20 && !bExist
) {
102 bExist
= xFileAccess
.exists(cResURL
);
103 } catch(com
.sun
.star
.uno
.Exception e
) {
104 log
.println("Exception:" + e
);
111 log
.println("The command was executed and file created in " +
114 log
.println("File was not created");
117 tRes
.tested("execute()", bExist
);
121 * Sleeps to allow StarOffice to react on <code>
124 private void shortWait() {
127 } catch (InterruptedException e
) {
128 log
.println("While waiting :" + e
) ;
131 } // finish class _XSystemShellExecute