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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sal.hxx" 30 31 #include <cppunit/simpleheader.hxx> 32 #include <osl/process.h> 33 #include <rtl/ustring.hxx> 34 #include <unistd.h> 35 #include <signal.h> 36 37 #ifdef WNT 38 const rtl::OUString IMAGE_NAME = rtl::OUString::createFromAscii("ojpx.exe"); 39 #else 40 const rtl::OUString IMAGE_NAME = rtl::OUString::createFromAscii("ojpx"); 41 #endif 42 43 const rtl::OUString CWD = rtl::OUString::createFromAscii("."); 44 45 //------------------------------ 46 // 47 //------------------------------ 48 49 class Test_osl_Process : public CppUnit::TestFixture 50 { 51 public: 52 53 /*------------------------------------- 54 Start a process and join with this 55 process specify a timeout so that 56 osl_joinProcessWithTimeout returns 57 osl_Process_E_TimedOut 58 -------------------------------------*/ 59 60 void test_osl_joinProcessWithTimeout_timeout_failure() 61 { 62 oslProcess process; 63 oslProcessError osl_error = osl_executeProcess( 64 IMAGE_NAME.pData, 65 NULL, 66 0, 67 osl_Process_NORMAL, 68 osl_getCurrentSecurity(), 69 CWD.pData, 70 NULL, 71 0, 72 &process); 73 74 CPPUNIT_ASSERT_MESSAGE 75 ( 76 "osl_createProcess failed", 77 osl_error == osl_Process_E_None 78 ); 79 80 TimeValue timeout; 81 timeout.Seconds = 1; 82 timeout.Nanosec = 0; 83 84 osl_error = osl_joinProcessWithTimeout(process, &timeout); 85 86 CPPUNIT_ASSERT_MESSAGE 87 ( 88 "osl_joinProcessWithTimeout returned without timeout failure", 89 osl_Process_E_TimedOut == osl_error 90 ); 91 92 osl_error = osl_terminateProcess(process); 93 94 CPPUNIT_ASSERT_MESSAGE 95 ( 96 "osl_terminateProcess failed", 97 osl_error == osl_Process_E_None 98 ); 99 100 osl_freeProcessHandle(process); 101 } 102 103 /*------------------------------------- 104 Start a process and join with this 105 process specify a timeout so that 106 osl_joinProcessWithTimeout returns 107 osl_Process_E_None 108 -------------------------------------*/ 109 110 void test_osl_joinProcessWithTimeout_without_timeout_failure() 111 { 112 oslProcess process; 113 oslProcessError osl_error = osl_executeProcess( 114 IMAGE_NAME.pData, 115 NULL, 116 0, 117 osl_Process_NORMAL, 118 osl_getCurrentSecurity(), 119 CWD.pData, 120 NULL, 121 0, 122 &process); 123 124 CPPUNIT_ASSERT_MESSAGE 125 ( 126 "osl_createProcess failed", 127 osl_error == osl_Process_E_None 128 ); 129 130 TimeValue timeout; 131 timeout.Seconds = 10; 132 timeout.Nanosec = 0; 133 134 osl_error = osl_joinProcessWithTimeout(process, &timeout); 135 136 CPPUNIT_ASSERT_MESSAGE 137 ( 138 "osl_joinProcessWithTimeout returned with failure", 139 osl_Process_E_None == osl_error 140 ); 141 142 osl_freeProcessHandle(process); 143 } 144 145 /*------------------------------------- 146 Start a process and join with this 147 process specify an infinite timeout 148 -------------------------------------*/ 149 150 void test_osl_joinProcessWithTimeout_infinite() 151 { 152 oslProcess process; 153 oslProcessError osl_error = osl_executeProcess( 154 IMAGE_NAME.pData, 155 NULL, 156 0, 157 osl_Process_NORMAL, 158 osl_getCurrentSecurity(), 159 CWD.pData, 160 NULL, 161 0, 162 &process); 163 164 CPPUNIT_ASSERT_MESSAGE 165 ( 166 "osl_createProcess failed", 167 osl_error == osl_Process_E_None 168 ); 169 170 osl_error = osl_joinProcessWithTimeout(process, NULL); 171 172 CPPUNIT_ASSERT_MESSAGE 173 ( 174 "osl_joinProcessWithTimeout returned with failure", 175 osl_Process_E_None == osl_error 176 ); 177 178 osl_freeProcessHandle(process); 179 } 180 181 /*------------------------------------- 182 Start a process and join with this 183 process using osl_joinProcess 184 -------------------------------------*/ 185 186 void test_osl_joinProcess() 187 { 188 oslProcess process; 189 oslProcessError osl_error = osl_executeProcess( 190 IMAGE_NAME.pData, 191 NULL, 192 0, 193 osl_Process_NORMAL, 194 osl_getCurrentSecurity(), 195 CWD.pData, 196 NULL, 197 0, 198 &process); 199 200 CPPUNIT_ASSERT_MESSAGE 201 ( 202 "osl_createProcess failed", 203 osl_error == osl_Process_E_None 204 ); 205 206 osl_error = osl_joinProcess(process); 207 208 CPPUNIT_ASSERT_MESSAGE 209 ( 210 "osl_joinProcess returned with failure", 211 osl_Process_E_None == osl_error 212 ); 213 214 osl_freeProcessHandle(process); 215 } 216 217 CPPUNIT_TEST_SUITE(Test_osl_Process); 218 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_timeout_failure); 219 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_without_timeout_failure); 220 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_infinite); 221 CPPUNIT_TEST(test_osl_joinProcess); 222 CPPUNIT_TEST_SUITE_END(); 223 }; 224 225 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test_osl_Process, "Test_osl_Process"); 226 227 NOADDITIONAL; 228 229