Bump version to 4.1-6
[LibreOffice.git] / sal / workben / t_osl_joinProcess.cxx
blob8f3497d5b5ec390c5744a4f21d9b2e6b7a2b84e8
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 oslProcessError osl_error = osl_executeProcess(
50 IMAGE_NAME.pData,
51 NULL,
53 osl_Process_NORMAL,
54 osl_getCurrentSecurity(),
55 CWD.pData,
56 NULL,
58 &process);
60 CPPUNIT_ASSERT_MESSAGE
62 "osl_createProcess failed",
63 osl_error == osl_Process_E_None
66 TimeValue timeout;
67 timeout.Seconds = 1;
68 timeout.Nanosec = 0;
70 osl_error = osl_joinProcessWithTimeout(process, &timeout);
72 CPPUNIT_ASSERT_MESSAGE
74 "osl_joinProcessWithTimeout returned without timeout failure",
75 osl_Process_E_TimedOut == osl_error
78 osl_error = osl_terminateProcess(process);
80 CPPUNIT_ASSERT_MESSAGE
82 "osl_terminateProcess failed",
83 osl_error == osl_Process_E_None
86 osl_freeProcessHandle(process);
89 /*-------------------------------------
90 Start a process and join with this
91 process specify a timeout so that
92 osl_joinProcessWithTimeout returns
93 osl_Process_E_None
94 -------------------------------------*/
96 void test_osl_joinProcessWithTimeout_without_timeout_failure()
98 oslProcess process;
99 oslProcessError osl_error = osl_executeProcess(
100 IMAGE_NAME.pData,
101 NULL,
103 osl_Process_NORMAL,
104 osl_getCurrentSecurity(),
105 CWD.pData,
106 NULL,
108 &process);
110 CPPUNIT_ASSERT_MESSAGE
112 "osl_createProcess failed",
113 osl_error == osl_Process_E_None
116 TimeValue timeout;
117 timeout.Seconds = 10;
118 timeout.Nanosec = 0;
120 osl_error = osl_joinProcessWithTimeout(process, &timeout);
122 CPPUNIT_ASSERT_MESSAGE
124 "osl_joinProcessWithTimeout returned with failure",
125 osl_Process_E_None == osl_error
128 osl_freeProcessHandle(process);
131 /*-------------------------------------
132 Start a process and join with this
133 process specify an infinite timeout
134 -------------------------------------*/
136 void test_osl_joinProcessWithTimeout_infinite()
138 oslProcess process;
139 oslProcessError osl_error = osl_executeProcess(
140 IMAGE_NAME.pData,
141 NULL,
143 osl_Process_NORMAL,
144 osl_getCurrentSecurity(),
145 CWD.pData,
146 NULL,
148 &process);
150 CPPUNIT_ASSERT_MESSAGE
152 "osl_createProcess failed",
153 osl_error == osl_Process_E_None
156 osl_error = osl_joinProcessWithTimeout(process, NULL);
158 CPPUNIT_ASSERT_MESSAGE
160 "osl_joinProcessWithTimeout returned with failure",
161 osl_Process_E_None == osl_error
164 osl_freeProcessHandle(process);
167 /*-------------------------------------
168 Start a process and join with this
169 process using osl_joinProcess
170 -------------------------------------*/
172 void test_osl_joinProcess()
174 oslProcess process;
175 oslProcessError osl_error = osl_executeProcess(
176 IMAGE_NAME.pData,
177 NULL,
179 osl_Process_NORMAL,
180 osl_getCurrentSecurity(),
181 CWD.pData,
182 NULL,
184 &process);
186 CPPUNIT_ASSERT_MESSAGE
188 "osl_createProcess failed",
189 osl_error == osl_Process_E_None
192 osl_error = osl_joinProcess(process);
194 CPPUNIT_ASSERT_MESSAGE
196 "osl_joinProcess returned with failure",
197 osl_Process_E_None == osl_error
200 osl_freeProcessHandle(process);
203 CPPUNIT_TEST_SUITE(Test_osl_Process);
204 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_timeout_failure);
205 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_without_timeout_failure);
206 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_infinite);
207 CPPUNIT_TEST(test_osl_joinProcess);
208 CPPUNIT_TEST_SUITE_END();
211 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test_osl_Process, "Test_osl_Process");
213 NOADDITIONAL;
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */