update dev300-m58
[ooovba.git] / sal / workben / t_osl_joinProcess.cxx
blob8c12b92e61f7d4da1ccd6cb04e428bf0e69afc4e
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: t_osl_joinProcess.cxx,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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
34 #include <cppunit/simpleheader.hxx>
35 #include <osl/process.h>
36 #include <rtl/ustring.hxx>
37 #include <unistd.h>
38 #include <signal.h>
40 #ifdef WNT
41 const rtl::OUString IMAGE_NAME = rtl::OUString::createFromAscii("ojpx.exe");
42 #else
43 const rtl::OUString IMAGE_NAME = rtl::OUString::createFromAscii("ojpx");
44 #endif
46 const rtl::OUString CWD = rtl::OUString::createFromAscii(".");
48 //------------------------------
49 //
50 //------------------------------
52 class Test_osl_Process : public CppUnit::TestFixture
54 public:
56 /*-------------------------------------
57 Start a process and join with this
58 process specify a timeout so that
59 osl_joinProcessWithTimeout returns
60 osl_Process_E_TimedOut
61 -------------------------------------*/
63 void test_osl_joinProcessWithTimeout_timeout_failure()
65 oslProcess process;
66 oslProcessError osl_error = osl_executeProcess(
67 IMAGE_NAME.pData,
68 NULL,
70 osl_Process_NORMAL,
71 osl_getCurrentSecurity(),
72 CWD.pData,
73 NULL,
75 &process);
77 CPPUNIT_ASSERT_MESSAGE
79 "osl_createProcess failed",
80 osl_error == osl_Process_E_None
83 TimeValue timeout;
84 timeout.Seconds = 1;
85 timeout.Nanosec = 0;
87 osl_error = osl_joinProcessWithTimeout(process, &timeout);
89 CPPUNIT_ASSERT_MESSAGE
91 "osl_joinProcessWithTimeout returned without timeout failure",
92 osl_Process_E_TimedOut == osl_error
93 );
95 osl_error = osl_terminateProcess(process);
97 CPPUNIT_ASSERT_MESSAGE
99 "osl_terminateProcess failed",
100 osl_error == osl_Process_E_None
103 osl_freeProcessHandle(process);
106 /*-------------------------------------
107 Start a process and join with this
108 process specify a timeout so that
109 osl_joinProcessWithTimeout returns
110 osl_Process_E_None
111 -------------------------------------*/
113 void test_osl_joinProcessWithTimeout_without_timeout_failure()
115 oslProcess process;
116 oslProcessError osl_error = osl_executeProcess(
117 IMAGE_NAME.pData,
118 NULL,
120 osl_Process_NORMAL,
121 osl_getCurrentSecurity(),
122 CWD.pData,
123 NULL,
125 &process);
127 CPPUNIT_ASSERT_MESSAGE
129 "osl_createProcess failed",
130 osl_error == osl_Process_E_None
133 TimeValue timeout;
134 timeout.Seconds = 10;
135 timeout.Nanosec = 0;
137 osl_error = osl_joinProcessWithTimeout(process, &timeout);
139 CPPUNIT_ASSERT_MESSAGE
141 "osl_joinProcessWithTimeout returned with failure",
142 osl_Process_E_None == osl_error
145 osl_freeProcessHandle(process);
148 /*-------------------------------------
149 Start a process and join with this
150 process specify an infinite timeout
151 -------------------------------------*/
153 void test_osl_joinProcessWithTimeout_infinite()
155 oslProcess process;
156 oslProcessError osl_error = osl_executeProcess(
157 IMAGE_NAME.pData,
158 NULL,
160 osl_Process_NORMAL,
161 osl_getCurrentSecurity(),
162 CWD.pData,
163 NULL,
165 &process);
167 CPPUNIT_ASSERT_MESSAGE
169 "osl_createProcess failed",
170 osl_error == osl_Process_E_None
173 osl_error = osl_joinProcessWithTimeout(process, NULL);
175 CPPUNIT_ASSERT_MESSAGE
177 "osl_joinProcessWithTimeout returned with failure",
178 osl_Process_E_None == osl_error
181 osl_freeProcessHandle(process);
184 /*-------------------------------------
185 Start a process and join with this
186 process using osl_joinProcess
187 -------------------------------------*/
189 void test_osl_joinProcess()
191 oslProcess process;
192 oslProcessError osl_error = osl_executeProcess(
193 IMAGE_NAME.pData,
194 NULL,
196 osl_Process_NORMAL,
197 osl_getCurrentSecurity(),
198 CWD.pData,
199 NULL,
201 &process);
203 CPPUNIT_ASSERT_MESSAGE
205 "osl_createProcess failed",
206 osl_error == osl_Process_E_None
209 osl_error = osl_joinProcess(process);
211 CPPUNIT_ASSERT_MESSAGE
213 "osl_joinProcess returned with failure",
214 osl_Process_E_None == osl_error
217 osl_freeProcessHandle(process);
220 CPPUNIT_TEST_SUITE(Test_osl_Process);
221 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_timeout_failure);
222 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_without_timeout_failure);
223 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_infinite);
224 CPPUNIT_TEST(test_osl_joinProcess);
225 CPPUNIT_TEST_SUITE_END();
228 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test_osl_Process, "Test_osl_Process");
230 NOADDITIONAL;