merged tag ooo/DEV300_m102
[LibreOffice.git] / sal / workben / t_osl_joinProcess.cxx
blob1c6f366505f8bf61b21764bdd4defa4225db67a9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sal.hxx"
31 #include <cppunit/simpleheader.hxx>
32 #include <osl/process.h>
33 #include <rtl/ustring.hxx>
34 #include <unistd.h>
35 #include <signal.h>
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
43 const rtl::OUString CWD = rtl::OUString::createFromAscii(".");
45 //------------------------------
47 //------------------------------
49 class Test_osl_Process : public CppUnit::TestFixture
51 public:
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 -------------------------------------*/
60 void test_osl_joinProcessWithTimeout_timeout_failure()
62 oslProcess process;
63 oslProcessError osl_error = osl_executeProcess(
64 IMAGE_NAME.pData,
65 NULL,
67 osl_Process_NORMAL,
68 osl_getCurrentSecurity(),
69 CWD.pData,
70 NULL,
72 &process);
74 CPPUNIT_ASSERT_MESSAGE
76 "osl_createProcess failed",
77 osl_error == osl_Process_E_None
80 TimeValue timeout;
81 timeout.Seconds = 1;
82 timeout.Nanosec = 0;
84 osl_error = osl_joinProcessWithTimeout(process, &timeout);
86 CPPUNIT_ASSERT_MESSAGE
88 "osl_joinProcessWithTimeout returned without timeout failure",
89 osl_Process_E_TimedOut == osl_error
92 osl_error = osl_terminateProcess(process);
94 CPPUNIT_ASSERT_MESSAGE
96 "osl_terminateProcess failed",
97 osl_error == osl_Process_E_None
100 osl_freeProcessHandle(process);
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 -------------------------------------*/
110 void test_osl_joinProcessWithTimeout_without_timeout_failure()
112 oslProcess process;
113 oslProcessError osl_error = osl_executeProcess(
114 IMAGE_NAME.pData,
115 NULL,
117 osl_Process_NORMAL,
118 osl_getCurrentSecurity(),
119 CWD.pData,
120 NULL,
122 &process);
124 CPPUNIT_ASSERT_MESSAGE
126 "osl_createProcess failed",
127 osl_error == osl_Process_E_None
130 TimeValue timeout;
131 timeout.Seconds = 10;
132 timeout.Nanosec = 0;
134 osl_error = osl_joinProcessWithTimeout(process, &timeout);
136 CPPUNIT_ASSERT_MESSAGE
138 "osl_joinProcessWithTimeout returned with failure",
139 osl_Process_E_None == osl_error
142 osl_freeProcessHandle(process);
145 /*-------------------------------------
146 Start a process and join with this
147 process specify an infinite timeout
148 -------------------------------------*/
150 void test_osl_joinProcessWithTimeout_infinite()
152 oslProcess process;
153 oslProcessError osl_error = osl_executeProcess(
154 IMAGE_NAME.pData,
155 NULL,
157 osl_Process_NORMAL,
158 osl_getCurrentSecurity(),
159 CWD.pData,
160 NULL,
162 &process);
164 CPPUNIT_ASSERT_MESSAGE
166 "osl_createProcess failed",
167 osl_error == osl_Process_E_None
170 osl_error = osl_joinProcessWithTimeout(process, NULL);
172 CPPUNIT_ASSERT_MESSAGE
174 "osl_joinProcessWithTimeout returned with failure",
175 osl_Process_E_None == osl_error
178 osl_freeProcessHandle(process);
181 /*-------------------------------------
182 Start a process and join with this
183 process using osl_joinProcess
184 -------------------------------------*/
186 void test_osl_joinProcess()
188 oslProcess process;
189 oslProcessError osl_error = osl_executeProcess(
190 IMAGE_NAME.pData,
191 NULL,
193 osl_Process_NORMAL,
194 osl_getCurrentSecurity(),
195 CWD.pData,
196 NULL,
198 &process);
200 CPPUNIT_ASSERT_MESSAGE
202 "osl_createProcess failed",
203 osl_error == osl_Process_E_None
206 osl_error = osl_joinProcess(process);
208 CPPUNIT_ASSERT_MESSAGE
210 "osl_joinProcess returned with failure",
211 osl_Process_E_None == osl_error
214 osl_freeProcessHandle(process);
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();
225 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test_osl_Process, "Test_osl_Process");
227 NOADDITIONAL;