1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_sal.hxx"
25 #include "sal/config.h"
26 
27 #include <cstdlib>
28 #include <iostream>
29 #include <limits>
30 
31 #include "boost/noncopyable.hpp"
32 #include "cppunit/TestAssert.h"
33 #include "cppunit/TestFixture.h"
34 #include "cppunit/extensions/HelperMacros.h"
35 #include "cppunit/plugin/TestPlugIn.h"
36 #include "osl/thread.hxx"
37 
38 namespace {
39 
40 class TestThread: public osl::Thread, private boost::noncopyable {
41 private:
42     virtual void SAL_CALL run();
43 };
44 
run()45 void TestThread::run() {
46 #if defined WNT
47     if (std::getenv("URE_TEST_SETTHREADNAME") != 0) {
48         // On Windows, setting thread names appears to only take effect when the
49         // process is being debugged, so attach a debugger now:
50         std::cout << "set: ";
51         std::cin.ignore(std::numeric_limits< int >::max(), '\n');
52     }
53 #endif
54     setName("TestThread");
55     if (std::getenv("URE_TEST_SETTHREADNAME") != 0) {
56         // On Linux, the thread name can now be observed with "ps -L"; on
57         // Windows with the Microsoft compiler, the thread name can now be
58         // observed in a debugger.
59         std::cout << "stop: ";
60         std::cin.ignore(std::numeric_limits< int >::max(), '\n');
61     }
62 }
63 
64 class Test: public CppUnit::TestFixture {
65 private:
66     CPPUNIT_TEST_SUITE(Test);
67     CPPUNIT_TEST(test);
68     CPPUNIT_TEST_SUITE_END();
69 
70     void test();
71 };
72 
test()73 void Test::test() {
74     TestThread t;
75     t.create();
76     t.join();
77 }
78 
79 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
80 
81 }
82 
83 CPPUNIT_PLUGIN_IMPLEMENT();
84