Bump for 3.6-28
[LibreOffice.git] / sal / workben / t_osl_joinProcess.cxx
blob60914ee26ede85d27be13628288ab9ca7eab43d7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "sal/config.h"
30 #include "sal/precppunit.hxx"
32 #include <cppunit/simpleheader.hxx>
33 #include <osl/process.h>
34 #include <rtl/ustring.hxx>
35 #include <unistd.h>
36 #include <signal.h>
38 #ifdef WNT
39 const rtl::OUString IMAGE_NAME("ojpx.exe");
40 #else
41 const rtl::OUString IMAGE_NAME("ojpx");
42 #endif
44 const rtl::OUString CWD(".");
46 class Test_osl_Process : public CppUnit::TestFixture
48 public:
50 /*-------------------------------------
51 Start a process and join with this
52 process specify a timeout so that
53 osl_joinProcessWithTimeout returns
54 osl_Process_E_TimedOut
55 -------------------------------------*/
57 void test_osl_joinProcessWithTimeout_timeout_failure()
59 oslProcess process;
60 oslProcessError osl_error = osl_executeProcess(
61 IMAGE_NAME.pData,
62 NULL,
64 osl_Process_NORMAL,
65 osl_getCurrentSecurity(),
66 CWD.pData,
67 NULL,
69 &process);
71 CPPUNIT_ASSERT_MESSAGE
73 "osl_createProcess failed",
74 osl_error == osl_Process_E_None
77 TimeValue timeout;
78 timeout.Seconds = 1;
79 timeout.Nanosec = 0;
81 osl_error = osl_joinProcessWithTimeout(process, &timeout);
83 CPPUNIT_ASSERT_MESSAGE
85 "osl_joinProcessWithTimeout returned without timeout failure",
86 osl_Process_E_TimedOut == osl_error
89 osl_error = osl_terminateProcess(process);
91 CPPUNIT_ASSERT_MESSAGE
93 "osl_terminateProcess failed",
94 osl_error == osl_Process_E_None
97 osl_freeProcessHandle(process);
100 /*-------------------------------------
101 Start a process and join with this
102 process specify a timeout so that
103 osl_joinProcessWithTimeout returns
104 osl_Process_E_None
105 -------------------------------------*/
107 void test_osl_joinProcessWithTimeout_without_timeout_failure()
109 oslProcess process;
110 oslProcessError osl_error = osl_executeProcess(
111 IMAGE_NAME.pData,
112 NULL,
114 osl_Process_NORMAL,
115 osl_getCurrentSecurity(),
116 CWD.pData,
117 NULL,
119 &process);
121 CPPUNIT_ASSERT_MESSAGE
123 "osl_createProcess failed",
124 osl_error == osl_Process_E_None
127 TimeValue timeout;
128 timeout.Seconds = 10;
129 timeout.Nanosec = 0;
131 osl_error = osl_joinProcessWithTimeout(process, &timeout);
133 CPPUNIT_ASSERT_MESSAGE
135 "osl_joinProcessWithTimeout returned with failure",
136 osl_Process_E_None == osl_error
139 osl_freeProcessHandle(process);
142 /*-------------------------------------
143 Start a process and join with this
144 process specify an infinite timeout
145 -------------------------------------*/
147 void test_osl_joinProcessWithTimeout_infinite()
149 oslProcess process;
150 oslProcessError osl_error = osl_executeProcess(
151 IMAGE_NAME.pData,
152 NULL,
154 osl_Process_NORMAL,
155 osl_getCurrentSecurity(),
156 CWD.pData,
157 NULL,
159 &process);
161 CPPUNIT_ASSERT_MESSAGE
163 "osl_createProcess failed",
164 osl_error == osl_Process_E_None
167 osl_error = osl_joinProcessWithTimeout(process, NULL);
169 CPPUNIT_ASSERT_MESSAGE
171 "osl_joinProcessWithTimeout returned with failure",
172 osl_Process_E_None == osl_error
175 osl_freeProcessHandle(process);
178 /*-------------------------------------
179 Start a process and join with this
180 process using osl_joinProcess
181 -------------------------------------*/
183 void test_osl_joinProcess()
185 oslProcess process;
186 oslProcessError osl_error = osl_executeProcess(
187 IMAGE_NAME.pData,
188 NULL,
190 osl_Process_NORMAL,
191 osl_getCurrentSecurity(),
192 CWD.pData,
193 NULL,
195 &process);
197 CPPUNIT_ASSERT_MESSAGE
199 "osl_createProcess failed",
200 osl_error == osl_Process_E_None
203 osl_error = osl_joinProcess(process);
205 CPPUNIT_ASSERT_MESSAGE
207 "osl_joinProcess returned with failure",
208 osl_Process_E_None == osl_error
211 osl_freeProcessHandle(process);
214 CPPUNIT_TEST_SUITE(Test_osl_Process);
215 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_timeout_failure);
216 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_without_timeout_failure);
217 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_infinite);
218 CPPUNIT_TEST(test_osl_joinProcess);
219 CPPUNIT_TEST_SUITE_END();
222 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test_osl_Process, "Test_osl_Process");
224 NOADDITIONAL;
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */