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 "gtest/gtest.h"
33 #include "osl/thread.hxx"
34 
35 namespace {
36 
37 class TestThread: public osl::Thread, private boost::noncopyable {
38 private:
39     virtual void SAL_CALL run();
40 };
41 
run()42 void TestThread::run() {
43 #if defined WNT
44     if (std::getenv("URE_TEST_SETTHREADNAME") != 0) {
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');
49     }
50 #endif
51     setName("TestThread");
52     if (std::getenv("URE_TEST_SETTHREADNAME") != 0) {
53         // On Linux, the thread name can now be observed with "ps -L"; on
54         // Windows with the Microsoft compiler, the thread name can now be
55         // observed in a debugger.
56         std::cout << "stop: ";
57         std::cin.ignore(std::numeric_limits< int >::max(), '\n');
58     }
59 }
60 
61 class Test: public ::testing::Test {
62 };
63 
TEST_F(Test,test)64 TEST_F(Test, test) {
65     TestThread t;
66     t.create();
67     t.join();
68 }
69 
70 
71 }
72 
main(int argc,char ** argv)73 int main(int argc, char **argv)
74 {
75     ::testing::InitGoogleTest(&argc, argv);
76     return RUN_ALL_TESTS();
77 }
78