1 /*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2011 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org.  If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27 
28 #include "precompiled_sal.hxx"
29 #include "sal/config.h"
30 
31 #include <cstdlib>
32 #include <iostream>
33 #include <limits>
34 
35 #include "boost/noncopyable.hpp"
36 #include "cppunit/TestAssert.h"
37 #include "cppunit/TestFixture.h"
38 #include "cppunit/extensions/HelperMacros.h"
39 #include "cppunit/plugin/TestPlugIn.h"
40 #include "osl/thread.hxx"
41 
42 namespace {
43 
44 class TestThread: public osl::Thread, private boost::noncopyable {
45 private:
46     virtual void SAL_CALL run();
47 };
48 
49 void TestThread::run() {
50 #if defined WNT
51     if (std::getenv("URE_TEST_SETTHREADNAME") != 0) {
52         // On Windows, setting thread names appears to only take effect when the
53         // process is being debugged, so attach a debugger now:
54         std::cout << "set: ";
55         std::cin.ignore(std::numeric_limits< int >::max(), '\n');
56     }
57 #endif
58     setName("TestThread");
59     if (std::getenv("URE_TEST_SETTHREADNAME") != 0) {
60         // On Linux, the thread name can now be observed with "ps -L"; on
61         // Windows with the Microsoft compiler, the thread name can now be
62         // observed in a debugger.
63         std::cout << "stop: ";
64         std::cin.ignore(std::numeric_limits< int >::max(), '\n');
65     }
66 }
67 
68 class Test: public CppUnit::TestFixture {
69 private:
70     CPPUNIT_TEST_SUITE(Test);
71     CPPUNIT_TEST(test);
72     CPPUNIT_TEST_SUITE_END();
73 
74     void test();
75 };
76 
77 void Test::test() {
78     TestThread t;
79     t.create();
80     t.join();
81 }
82 
83 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
84 
85 }
86 
87 CPPUNIT_PLUGIN_IMPLEMENT();
88