1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "sal/config.h"
30 #include "sal/precppunit.hxx"
32 #include <cppunit/simpleheader.hxx>
33 #include <osl/process.h>
34 #include <rtl/ustring.hxx>
39 const rtl::OUString
IMAGE_NAME("ojpx.exe");
41 const rtl::OUString
IMAGE_NAME("ojpx");
44 const rtl::OUString
CWD(".");
46 class Test_osl_Process
: public CppUnit::TestFixture
50 /*-------------------------------------
51 Start a process and join with this
52 process specify a timeout so that
53 osl_joinProcessWithTimeout returns
54 osl_Process_E_TimedOut
55 -------------------------------------*/
57 void test_osl_joinProcessWithTimeout_timeout_failure()
60 oslProcessError osl_error
= osl_executeProcess(
65 osl_getCurrentSecurity(),
71 CPPUNIT_ASSERT_MESSAGE
73 "osl_createProcess failed",
74 osl_error
== osl_Process_E_None
81 osl_error
= osl_joinProcessWithTimeout(process
, &timeout
);
83 CPPUNIT_ASSERT_MESSAGE
85 "osl_joinProcessWithTimeout returned without timeout failure",
86 osl_Process_E_TimedOut
== osl_error
89 osl_error
= osl_terminateProcess(process
);
91 CPPUNIT_ASSERT_MESSAGE
93 "osl_terminateProcess failed",
94 osl_error
== osl_Process_E_None
97 osl_freeProcessHandle(process
);
100 /*-------------------------------------
101 Start a process and join with this
102 process specify a timeout so that
103 osl_joinProcessWithTimeout returns
105 -------------------------------------*/
107 void test_osl_joinProcessWithTimeout_without_timeout_failure()
110 oslProcessError osl_error
= osl_executeProcess(
115 osl_getCurrentSecurity(),
121 CPPUNIT_ASSERT_MESSAGE
123 "osl_createProcess failed",
124 osl_error
== osl_Process_E_None
128 timeout
.Seconds
= 10;
131 osl_error
= osl_joinProcessWithTimeout(process
, &timeout
);
133 CPPUNIT_ASSERT_MESSAGE
135 "osl_joinProcessWithTimeout returned with failure",
136 osl_Process_E_None
== osl_error
139 osl_freeProcessHandle(process
);
142 /*-------------------------------------
143 Start a process and join with this
144 process specify an infinite timeout
145 -------------------------------------*/
147 void test_osl_joinProcessWithTimeout_infinite()
150 oslProcessError osl_error
= osl_executeProcess(
155 osl_getCurrentSecurity(),
161 CPPUNIT_ASSERT_MESSAGE
163 "osl_createProcess failed",
164 osl_error
== osl_Process_E_None
167 osl_error
= osl_joinProcessWithTimeout(process
, NULL
);
169 CPPUNIT_ASSERT_MESSAGE
171 "osl_joinProcessWithTimeout returned with failure",
172 osl_Process_E_None
== osl_error
175 osl_freeProcessHandle(process
);
178 /*-------------------------------------
179 Start a process and join with this
180 process using osl_joinProcess
181 -------------------------------------*/
183 void test_osl_joinProcess()
186 oslProcessError osl_error
= osl_executeProcess(
191 osl_getCurrentSecurity(),
197 CPPUNIT_ASSERT_MESSAGE
199 "osl_createProcess failed",
200 osl_error
== osl_Process_E_None
203 osl_error
= osl_joinProcess(process
);
205 CPPUNIT_ASSERT_MESSAGE
207 "osl_joinProcess returned with failure",
208 osl_Process_E_None
== osl_error
211 osl_freeProcessHandle(process
);
214 CPPUNIT_TEST_SUITE(Test_osl_Process
);
215 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_timeout_failure
);
216 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_without_timeout_failure
);
217 CPPUNIT_TEST(test_osl_joinProcessWithTimeout_infinite
);
218 CPPUNIT_TEST(test_osl_joinProcess
);
219 CPPUNIT_TEST_SUITE_END();
222 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test_osl_Process
, "Test_osl_Process");
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */