LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sal / qa / osl / setthreadname / test-setthreadname.cxx
blob9af8793eb1c25c6c05d934ad98c66a83ec0ca99c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <cstdlib>
21 #include <iostream>
22 #include <limits>
24 #include <sal/types.h>
25 #include <cppunit/TestAssert.h>
26 #include <cppunit/TestFixture.h>
27 #include <cppunit/extensions/HelperMacros.h>
28 #include <cppunit/plugin/TestPlugIn.h>
29 #include <osl/thread.hxx>
31 namespace {
33 class TestThread: public osl::Thread {
34 private:
35 virtual void SAL_CALL run() override;
36 public:
37 TestThread() = default;
38 TestThread(const TestThread&) = delete;
39 TestThread& operator=(const TestThread&) = delete;
42 void TestThread::run() {
43 #if defined(_WIN32)
44 if (std::getenv("URE_TEST_SETTHREADNAME") != nullptr) {
45 // On Windows, setting thread names appears to only take effect when the
46 // process is being debugged, so attach a debugger now:
47 std::cout << "set: ";
48 std::cin.ignore(std::numeric_limits< int >::max(), '\n');
50 #endif
51 setName("TestThread");
52 if (std::getenv("URE_TEST_SETTHREADNAME") != nullptr) {
53 // On Linux, the thread name can now be observed with "ps -L"; on
54 // Windows, the thread name can now be observed in a debugger.
55 std::cout << "stop: ";
56 std::cin.ignore(std::numeric_limits< int >::max(), '\n');
60 class Test: public CppUnit::TestFixture {
61 private:
62 CPPUNIT_TEST_SUITE(Test);
63 CPPUNIT_TEST(test);
64 CPPUNIT_TEST_SUITE_END();
66 void test();
69 void Test::test() {
70 TestThread t;
71 t.create();
72 t.join();
75 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
79 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */