187d2adbcSAndrew Rist /**************************************************************
287d2adbcSAndrew Rist  *
387d2adbcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
487d2adbcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
587d2adbcSAndrew Rist  * distributed with this work for additional information
687d2adbcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
787d2adbcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
887d2adbcSAndrew Rist  * "License"); you may not use this file except in compliance
987d2adbcSAndrew Rist  * with the License.  You may obtain a copy of the License at
1087d2adbcSAndrew Rist  *
1187d2adbcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1287d2adbcSAndrew Rist  *
1387d2adbcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1487d2adbcSAndrew Rist  * software distributed under the License is distributed on an
1587d2adbcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1687d2adbcSAndrew Rist  * KIND, either express or implied.  See the License for the
1787d2adbcSAndrew Rist  * specific language governing permissions and limitations
1887d2adbcSAndrew Rist  * under the License.
1987d2adbcSAndrew Rist  *
2087d2adbcSAndrew Rist  *************************************************************/
2187d2adbcSAndrew Rist 
2287d2adbcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sal.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <cstdlib>
28cdf0e10cSrcweir #include <iostream>
29cdf0e10cSrcweir #include <limits>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "boost/noncopyable.hpp"
32*90482c4bSDamjan Jovanovic #include "gtest/gtest.h"
33cdf0e10cSrcweir #include "osl/thread.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir class TestThread: public osl::Thread, private boost::noncopyable {
38cdf0e10cSrcweir private:
39cdf0e10cSrcweir     virtual void SAL_CALL run();
40cdf0e10cSrcweir };
41cdf0e10cSrcweir 
run()42cdf0e10cSrcweir void TestThread::run() {
43cdf0e10cSrcweir #if defined WNT
44cdf0e10cSrcweir     if (std::getenv("URE_TEST_SETTHREADNAME") != 0) {
45cdf0e10cSrcweir         // On Windows, setting thread names appears to only take effect when the
46cdf0e10cSrcweir         // process is being debugged, so attach a debugger now:
47cdf0e10cSrcweir         std::cout << "set: ";
48cdf0e10cSrcweir         std::cin.ignore(std::numeric_limits< int >::max(), '\n');
49cdf0e10cSrcweir     }
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir     setName("TestThread");
52cdf0e10cSrcweir     if (std::getenv("URE_TEST_SETTHREADNAME") != 0) {
53cdf0e10cSrcweir         // On Linux, the thread name can now be observed with "ps -L"; on
54cdf0e10cSrcweir         // Windows with the Microsoft compiler, the thread name can now be
55cdf0e10cSrcweir         // observed in a debugger.
56cdf0e10cSrcweir         std::cout << "stop: ";
57cdf0e10cSrcweir         std::cin.ignore(std::numeric_limits< int >::max(), '\n');
58cdf0e10cSrcweir     }
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
61*90482c4bSDamjan Jovanovic class Test: public ::testing::Test {
62cdf0e10cSrcweir };
63cdf0e10cSrcweir 
TEST_F(Test,test)64*90482c4bSDamjan Jovanovic TEST_F(Test, test) {
65cdf0e10cSrcweir     TestThread t;
66cdf0e10cSrcweir     t.create();
67cdf0e10cSrcweir     t.join();
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
main(int argc,char ** argv)73*90482c4bSDamjan Jovanovic int main(int argc, char **argv)
74*90482c4bSDamjan Jovanovic {
75*90482c4bSDamjan Jovanovic     ::testing::InitGoogleTest(&argc, argv);
76*90482c4bSDamjan Jovanovic     return RUN_ALL_TESTS();
77*90482c4bSDamjan Jovanovic }
78