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: test_thread.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 "sal/config.h"
36 #include "cppunit/simpleheader.hxx"
37 #include "osl/conditn.hxx"
38 #include "osl/thread.hxx"
40 #include "sal/types.h"
44 osl::Condition global
;
46 class Thread
: public osl::Thread
{
48 explicit Thread(osl::Condition
& cond
): m_cond(cond
) {}
51 virtual void SAL_CALL
run() {}
53 virtual void SAL_CALL
onTerminated() {
55 CPPUNIT_ASSERT_EQUAL(osl::Condition::result_ok
, global
.wait());
58 osl::Condition
& m_cond
;
61 class Test
: public CppUnit::TestFixture
{
63 // Nondeterministic, best effort test that an osl::Thread can be destroyed
64 // (and in particular osl_destroyThread---indirectly---be called) before the
65 // corresponding thread has terminated:
67 for (int i
= 0; i
< 50; ++i
) {
70 CPPUNIT_ASSERT(t
.create());
71 // Make sure virtual Thread::run/onTerminated are called before
73 CPPUNIT_ASSERT_EQUAL(osl::Condition::result_ok
, c
.wait());
75 // Make sure Thread::~Thread is called before each spawned thread
78 // Give the spawned threads enough time to terminate:
79 TimeValue
const twentySeconds
= { 20, 0 };
80 osl::Thread::wait(twentySeconds
);
83 CPPUNIT_TEST_SUITE(Test
);
85 CPPUNIT_TEST_SUITE_END();
88 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test
, "alltests");