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>
38 const rtl::OUString IMAGE_NAME
= rtl::OUString::createFromAscii("ojpx.exe");
40 const rtl::OUString IMAGE_NAME
= rtl::OUString::createFromAscii("ojpx");
43 const rtl::OUString CWD
= rtl::OUString::createFromAscii(".");
45 //------------------------------
47 //------------------------------
49 class Test_osl_Process
: public CppUnit::TestFixture
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()
63 oslProcessError osl_error
= osl_executeProcess(
68 osl_getCurrentSecurity(),
74 CPPUNIT_ASSERT_MESSAGE
76 "osl_createProcess failed",
77 osl_error
== osl_Process_E_None
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
108 -------------------------------------*/
110 void test_osl_joinProcessWithTimeout_without_timeout_failure()
113 oslProcessError osl_error
= osl_executeProcess(
118 osl_getCurrentSecurity(),
124 CPPUNIT_ASSERT_MESSAGE
126 "osl_createProcess failed",
127 osl_error
== osl_Process_E_None
131 timeout
.Seconds
= 10;
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()
153 oslProcessError osl_error
= osl_executeProcess(
158 osl_getCurrentSecurity(),
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()
189 oslProcessError osl_error
= osl_executeProcess(
194 osl_getCurrentSecurity(),
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");