Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sal / workben / t_osl_joinProcess.cxx
blobd043c5e343b3ef065190fc596fe11e12863cbe79
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/types.h>
21 #include <cppunit/simpleheader.hxx>
22 #include <osl/process.h>
23 #include <rtl/ustring.hxx>
24 #include <unistd.h>
25 #include <signal.h>
27 #ifdef WNT
28 const rtl::OUString IMAGE_NAME("ojpx.exe");
29 #else
30 const rtl::OUString IMAGE_NAME("ojpx");
31 #endif
33 const rtl::OUString CWD(".");
35 class Test_osl_Process : public CppUnit::TestFixture
37 public:
39 /*-------------------------------------
40 Start a process and join with this
41 process specify a timeout so that
42 osl_joinProcessWithTimeout returns
43 osl_Process_E_TimedOut
44 -------------------------------------*/
46 void test_osl_joinProcessWithTimeout_timeout_failure()
48 oslProcess process;
49 oslSecurity security = osl_getCurrentSecurity();
50 oslProcessError osl_error = osl_executeProcess(
51 IMAGE_NAME.pData,
52 NULL,
54 osl_Process_NORMAL,
55 security,
56 CWD.pData,
57 NULL,
59 &process);
60 osl_freeSecurityHandle(security);
62 CPPUNIT_ASSERT_MESSAGE
64 "osl_createProcess failed",
65 osl_error == osl_Process_E_None
68 TimeValue timeout;
69 timeout.Seconds = 1;
70 timeout.Nanosec = 0;
72 osl_error = osl_joinProcessWithTimeout(process, &timeout);
74 CPPUNIT_ASSERT_MESSAGE
76 "osl_joinProcessWithTimeout returned without timeout failure",
77 osl_Process_E_TimedOut == osl_error
80 osl_error = osl_terminateProcess(process);
82 CPPUNIT_ASSERT_MESSAGE
84 "osl_terminateProcess failed",
85 osl_error == osl_Process_E_None
88 osl_freeProcessHandle(process);
91 /*-------------------------------------
92 Start a process and join with this
93 process specify a timeout so that
94 osl_joinProcessWithTimeout returns
95 osl_Process_E_None
96 -------------------------------------*/
98 void test_osl_joinProcessWithTimeout_without_timeout_failure()
100 oslProcess process;
101 oslSecurity security = osl_getCurrentSecurity();
102 oslProcessError osl_error = osl_executeProcess(
103 IMAGE_NAME.pData,
104 NULL,
106 osl_Process_NORMAL,
107 security,
108 CWD.pData,
109 NULL,
111 &process);
112 osl_freeSecurityHandle(security);
114 CPPUNIT_ASSERT_MESSAGE
116 "osl_createProcess failed",
117 osl_error == osl_Process_E_None
120 TimeValue timeout;
121 timeout.Seconds = 10;
122 timeout.Nanosec = 0;
124 osl_error = osl_joinProcessWithTimeout(process, &timeout);
126 CPPUNIT_ASSERT_MESSAGE
128 "osl_joinProcessWithTimeout returned with failure",
129 osl_Process_E_None == osl_error
132 osl_freeProcessHandle(process);
135 /*-------------------------------------
136 Start a process and join with this
137 process specify an infinite timeout
138 -------------------------------------*/
140 void test_osl_joinProcessWithTimeout_infinite()
142 oslProcess process;
143 oslSecurity security = osl_getCurrentSecurity();
144 oslProcessError osl_error = osl_executeProcess(
145 IMAGE_NAME.pData,
146 NULL,
148 osl_Process_NORMAL,
149 security,
150 CWD.pData,
151 NULL,
153 &process);
154 osl_freeSecurityHandle(security);
156 CPPUNIT_ASSERT_MESSAGE
158 "osl_createProcess failed",
159 osl_error == osl_Process_E_None
162 osl_error = osl_joinProcessWithTimeout(process, NULL);
164 CPPUNIT_ASSERT_MESSAGE
166 "osl_joinProcessWithTimeout returned with failure",
167 osl_Process_E_None == osl_error
170 osl_freeProcessHandle(process);
173 /*-------------------------------------
174 Start a process and join with this
175 process using osl_joinProcess
176 -------------------------------------*/
178 void test_osl_joinProcess()
180 oslProcess process;
181 oslSecurity security = osl_getCurrentSecurity();
182 oslProcessError osl_error = osl_executeProcess(
183 IMAGE_NAME.pData,
184 NULL,
186 osl_Process_NORMAL,
187 security,
188 CWD.pData,
189 NULL,
191 &process);
192 osl_freeSecurityHandle(security);
194 CPPUNIT_ASSERT_MESSAGE
196 "osl_createProcess failed",
197 osl_error == osl_Process_E_None
200 osl_error = osl_joinProcess(process);
202 CPPUNIT_ASSERT_MESSAGE
204 "osl_joinProcess returned with failure",
205 osl_Process_E_None == osl_error
208 osl_freeProcessHandle(process);
211 CPPUNIT_TEST_SUITE(Test_osl_Process);
212 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_timeout_failure);
213 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_without_timeout_failure);
214 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_infinite);
215 CPPUNIT_TEST(test_osl_joinProcess);
216 CPPUNIT_TEST_SUITE_END();
219 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test_osl_Process, "Test_osl_Process");
221 NOADDITIONAL;
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */