1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.system; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import lib.MultiMethodTest; 27cdf0e10cSrcweir import util.utils; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 30cdf0e10cSrcweir import com.sun.star.system.XSystemShellExecute; 31cdf0e10cSrcweir import com.sun.star.ucb.XSimpleFileAccess; 32cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 33cdf0e10cSrcweir 34cdf0e10cSrcweir 35cdf0e10cSrcweir /** 36cdf0e10cSrcweir * Testing <code>com.sun.star.system.XSystemShellExecute</code> 37cdf0e10cSrcweir * interface methods : 38cdf0e10cSrcweir * <ul> 39cdf0e10cSrcweir * <li><code> execute()</code></li> 40cdf0e10cSrcweir * </ul> <p> 41cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 42cdf0e10cSrcweir * @see com.sun.star.system.XSystemShellExecute 43cdf0e10cSrcweir */ 44cdf0e10cSrcweir public class _XSystemShellExecute extends MultiMethodTest { 45cdf0e10cSrcweir 46cdf0e10cSrcweir public XSystemShellExecute oObj = null; 47cdf0e10cSrcweir 48cdf0e10cSrcweir /** 49cdf0e10cSrcweir * Excecutes 'java SystemShellExecute SystemShellExecute.txt' command line. 50cdf0e10cSrcweir * <p>Has <b> OK </b> status if the method successfully returns 51cdf0e10cSrcweir * and file 'SystemShellExecute.txt' was created. <p> 52cdf0e10cSrcweir */ _execute()53cdf0e10cSrcweir public void _execute() { 54cdf0e10cSrcweir String cClassPath = System.getProperty("DOCPTH"); 55cdf0e10cSrcweir String cResFile = utils.getOfficeTempDirSys((XMultiServiceFactory)tParam.getMSF())+"SystemShellExecute.txt"; 56cdf0e10cSrcweir String cResURL = utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF())+"SystemShellExecute.txt"; 57cdf0e10cSrcweir String cArgs = "-classpath " + cClassPath + 58cdf0e10cSrcweir " SystemShellExecute " + cResFile; 59cdf0e10cSrcweir 60cdf0e10cSrcweir String jh = System.getProperty("java.home"); 61cdf0e10cSrcweir String fs = System.getProperty("file.separator"); 62cdf0e10cSrcweir String cmd = jh+fs+"bin"+fs+"java"; 63cdf0e10cSrcweir 64cdf0e10cSrcweir log.println("Executing : '"+cmd+" " + cArgs + "'"); 65cdf0e10cSrcweir try { 66cdf0e10cSrcweir oObj.execute(cmd, cArgs, 1); 67cdf0e10cSrcweir } catch (com.sun.star.system.SystemShellExecuteException e) { 68cdf0e10cSrcweir log.println("Exception during execute: " + e); 69cdf0e10cSrcweir log.println("This has been implemented due to security reasons"); 70cdf0e10cSrcweir tRes.tested("execute()", true); 71cdf0e10cSrcweir return; 72cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException e) { 73cdf0e10cSrcweir log.println("Exception during execute: " + e); 74cdf0e10cSrcweir tRes.tested("execute()", false); 75cdf0e10cSrcweir return; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir XSimpleFileAccess xFileAccess = null; 79cdf0e10cSrcweir try { 80cdf0e10cSrcweir XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF(); 81cdf0e10cSrcweir Object fa = xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess"); 82cdf0e10cSrcweir xFileAccess = (XSimpleFileAccess) 83cdf0e10cSrcweir UnoRuntime.queryInterface(XSimpleFileAccess.class, fa); 84cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 85cdf0e10cSrcweir log.println("Couldn't create SimpleFileAccess:" + e); 86cdf0e10cSrcweir tRes.tested("execute()", false); 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir log.println("Waiting while the file will be created or timeout "+ 90cdf0e10cSrcweir "reached ..."); 91cdf0e10cSrcweir boolean bExist = false; 92cdf0e10cSrcweir int i = 0; 93cdf0e10cSrcweir while (i < 20 && !bExist) { 94cdf0e10cSrcweir try { 95cdf0e10cSrcweir bExist = xFileAccess.exists(cResURL); 96cdf0e10cSrcweir } catch(com.sun.star.uno.Exception e) { 97cdf0e10cSrcweir log.println("Exception:" + e); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir shortWait(); 100cdf0e10cSrcweir i++; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir if (bExist) { 104cdf0e10cSrcweir log.println("The command was executed and file created in " + 105cdf0e10cSrcweir i + " sec."); 106cdf0e10cSrcweir } else { 107cdf0e10cSrcweir log.println("File was not created"); 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir tRes.tested("execute()", bExist); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir /** 114cdf0e10cSrcweir * Sleeps to allow StarOffice to react on <code> 115cdf0e10cSrcweir * reset</code> call. 116cdf0e10cSrcweir */ shortWait()117cdf0e10cSrcweir private void shortWait() { 118cdf0e10cSrcweir try { 119cdf0e10cSrcweir Thread.sleep(1000) ; 120cdf0e10cSrcweir } catch (InterruptedException e) { 121cdf0e10cSrcweir log.println("While waiting :" + e) ; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir } 124cdf0e10cSrcweir } // finish class _XSystemShellExecute 125cdf0e10cSrcweir 126cdf0e10cSrcweir 127