1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 const rtl::OUString
IMAGE_NAME("ojpx.exe");
30 const rtl::OUString
IMAGE_NAME("ojpx");
33 const rtl::OUString
CWD(".");
35 class Test_osl_Process
: public CppUnit::TestFixture
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()
49 oslSecurity security
= osl_getCurrentSecurity();
50 oslProcessError osl_error
= osl_executeProcess(
60 osl_freeSecurityHandle(security
);
62 CPPUNIT_ASSERT_MESSAGE
64 "osl_createProcess failed",
65 osl_error
== osl_Process_E_None
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
96 -------------------------------------*/
98 void test_osl_joinProcessWithTimeout_without_timeout_failure()
101 oslSecurity security
= osl_getCurrentSecurity();
102 oslProcessError osl_error
= osl_executeProcess(
112 osl_freeSecurityHandle(security
);
114 CPPUNIT_ASSERT_MESSAGE
116 "osl_createProcess failed",
117 osl_error
== osl_Process_E_None
121 timeout
.Seconds
= 10;
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()
143 oslSecurity security
= osl_getCurrentSecurity();
144 oslProcessError osl_error
= osl_executeProcess(
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()
181 oslSecurity security
= osl_getCurrentSecurity();
182 oslProcessError osl_error
= osl_executeProcess(
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");
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */