| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 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/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 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 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <cstdlib> |
| 21 |
#include <iostream> |
| 22 |
#include <limits> |
| 23 |
|
| 24 |
#include <sal/types.h> |
| 25 |
#include <cppunit/TestFixture.h> |
| 26 |
#include <cppunit/extensions/HelperMacros.h> |
| 27 |
#include <osl/thread.hxx> |
| 28 |
|
| 29 |
namespace { |
| 30 |
|
| 31 |
class TestThread: public osl::Thread { |
| 32 |
private: |
| 33 |
virtual void SAL_CALL run() override; |
| 34 |
public: |
| 35 |
TestThread() = default; |
| 36 |
TestThread(const TestThread&) = delete; |
| 37 |
TestThread& operator=(const TestThread&) = delete; |
| 38 |
}; |
| 39 |
|
| 40 |
void TestThread::run() { |
| 41 |
#if defined(_WIN32) |
| 42 |
if (std::getenv("URE_TEST_SETTHREADNAME") != nullptr) { |
| 43 |
// On Windows, setting thread names appears to only take effect when the |
| 44 |
// process is being debugged, so attach a debugger now: |
| 45 |
std::cout << "set: "; |
| 46 |
std::cin.ignore(std::numeric_limits< std::streamsize >::max(), '\n'); |
| 47 |
} |
| 48 |
#endif |
| 49 |
setName("TestThread"); |
| 50 |
if (std::getenv("URE_TEST_SETTHREADNAME") != nullptr) { |
| 51 |
// On Linux, the thread name can now be observed with "ps -L"; on |
| 52 |
// Windows, the thread name can now be observed in a debugger. |
| 53 |
std::cout << "stop: "; |
| 54 |
std::cin.ignore(std::numeric_limits< std::streamsize >::max(), '\n'); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
class Test: public CppUnit::TestFixture { |
| 59 |
private: |
| 60 |
CPPUNIT_TEST_SUITE(Test); |
| 61 |
CPPUNIT_TEST(test); |
| 62 |
CPPUNIT_TEST_SUITE_END(); |
| 63 |
|
| 64 |
void test(); |
| 65 |
}; |
| 66 |
|
| 67 |
void Test::test() { |
| 68 |
TestThread t; |
| 69 |
t.create(); |
| 70 |
t.join(); |
| 71 |
} |
| 72 |
|
| 73 |
CPPUNIT_TEST_SUITE_REGISTRATION(Test); |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |