1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: t_osl_joinProcess.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sal.hxx"
34 #include <cppunit/simpleheader.hxx>
35 #include <osl/process.h>
36 #include <rtl/ustring.hxx>
41 const rtl::OUString IMAGE_NAME
= rtl::OUString::createFromAscii("ojpx.exe");
43 const rtl::OUString IMAGE_NAME
= rtl::OUString::createFromAscii("ojpx");
46 const rtl::OUString CWD
= rtl::OUString::createFromAscii(".");
48 //------------------------------
50 //------------------------------
52 class Test_osl_Process
: public CppUnit::TestFixture
56 /*-------------------------------------
57 Start a process and join with this
58 process specify a timeout so that
59 osl_joinProcessWithTimeout returns
60 osl_Process_E_TimedOut
61 -------------------------------------*/
63 void test_osl_joinProcessWithTimeout_timeout_failure()
66 oslProcessError osl_error
= osl_executeProcess(
71 osl_getCurrentSecurity(),
77 CPPUNIT_ASSERT_MESSAGE
79 "osl_createProcess failed",
80 osl_error
== osl_Process_E_None
87 osl_error
= osl_joinProcessWithTimeout(process
, &timeout
);
89 CPPUNIT_ASSERT_MESSAGE
91 "osl_joinProcessWithTimeout returned without timeout failure",
92 osl_Process_E_TimedOut
== osl_error
95 osl_error
= osl_terminateProcess(process
);
97 CPPUNIT_ASSERT_MESSAGE
99 "osl_terminateProcess failed",
100 osl_error
== osl_Process_E_None
103 osl_freeProcessHandle(process
);
106 /*-------------------------------------
107 Start a process and join with this
108 process specify a timeout so that
109 osl_joinProcessWithTimeout returns
111 -------------------------------------*/
113 void test_osl_joinProcessWithTimeout_without_timeout_failure()
116 oslProcessError osl_error
= osl_executeProcess(
121 osl_getCurrentSecurity(),
127 CPPUNIT_ASSERT_MESSAGE
129 "osl_createProcess failed",
130 osl_error
== osl_Process_E_None
134 timeout
.Seconds
= 10;
137 osl_error
= osl_joinProcessWithTimeout(process
, &timeout
);
139 CPPUNIT_ASSERT_MESSAGE
141 "osl_joinProcessWithTimeout returned with failure",
142 osl_Process_E_None
== osl_error
145 osl_freeProcessHandle(process
);
148 /*-------------------------------------
149 Start a process and join with this
150 process specify an infinite timeout
151 -------------------------------------*/
153 void test_osl_joinProcessWithTimeout_infinite()
156 oslProcessError osl_error
= osl_executeProcess(
161 osl_getCurrentSecurity(),
167 CPPUNIT_ASSERT_MESSAGE
169 "osl_createProcess failed",
170 osl_error
== osl_Process_E_None
173 osl_error
= osl_joinProcessWithTimeout(process
, NULL
);
175 CPPUNIT_ASSERT_MESSAGE
177 "osl_joinProcessWithTimeout returned with failure",
178 osl_Process_E_None
== osl_error
181 osl_freeProcessHandle(process
);
184 /*-------------------------------------
185 Start a process and join with this
186 process using osl_joinProcess
187 -------------------------------------*/
189 void test_osl_joinProcess()
192 oslProcessError osl_error
= osl_executeProcess(
197 osl_getCurrentSecurity(),
203 CPPUNIT_ASSERT_MESSAGE
205 "osl_createProcess failed",
206 osl_error
== osl_Process_E_None
209 osl_error
= osl_joinProcess(process
);
211 CPPUNIT_ASSERT_MESSAGE
213 "osl_joinProcess returned with failure",
214 osl_Process_E_None
== osl_error
217 osl_freeProcessHandle(process
);
220 CPPUNIT_TEST_SUITE(Test_osl_Process
);
221 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_timeout_failure
);
222 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_without_timeout_failure
);
223 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_infinite
);
224 CPPUNIT_TEST(test_osl_joinProcess
);
225 CPPUNIT_TEST_SUITE_END();
228 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test_osl_Process
, "Test_osl_Process");