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/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 #include <cppunit/plugin/TestPlugIn.h>
24 #include "osl/conditn.hxx"
25 #include "osl/thread.hxx"
31 osl::Condition global
;
33 class Thread
: public osl::Thread
{
35 explicit Thread(osl::Condition
& cond
): m_cond(cond
) {}
38 virtual void SAL_CALL
run() {}
40 virtual void SAL_CALL
onTerminated() {
42 CPPUNIT_ASSERT_EQUAL(osl::Condition::result_ok
, global
.wait());
45 osl::Condition
& m_cond
;
48 class Test
: public CppUnit::TestFixture
{
50 // Nondeterministic, best effort test that an osl::Thread can be destroyed
51 // (and in particular osl_destroyThread---indirectly---be called) before the
52 // corresponding thread has terminated:
54 for (int i
= 0; i
< 50; ++i
) {
57 CPPUNIT_ASSERT(t
.create());
58 // Make sure virtual Thread::run/onTerminated are called before
60 CPPUNIT_ASSERT_EQUAL(osl::Condition::result_ok
, c
.wait());
62 // Make sure Thread::~Thread is called before each spawned thread
65 // Give the spawned threads enough time to terminate:
66 osl::Thread::wait(std::chrono::seconds(20));
69 CPPUNIT_TEST_SUITE(Test
);
71 CPPUNIT_TEST_SUITE_END();
74 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
78 CPPUNIT_PLUGIN_IMPLEMENT();
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */