LCOV - code coverage report
Current view: top level - libreoffice/sal/qa/osl/setthreadname - test-setthreadname.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 18 88.9 %
Date: 2012-12-27 Functions: 13 15 86.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <cstdlib>
      21             : #include <iostream>
      22             : #include <limits>
      23             : 
      24             : #include <sal/types.h>
      25             : #include "boost/noncopyable.hpp"
      26             : #include "cppunit/TestAssert.h"
      27             : #include "cppunit/TestFixture.h"
      28             : #include "cppunit/extensions/HelperMacros.h"
      29             : #include "cppunit/plugin/TestPlugIn.h"
      30             : #include "osl/thread.hxx"
      31             : 
      32             : namespace {
      33             : 
      34           2 : class TestThread: public osl::Thread, private boost::noncopyable {
      35             : private:
      36             :     virtual void SAL_CALL run();
      37             : };
      38             : 
      39           1 : void TestThread::run() {
      40             : #if defined WNT
      41             :     if (std::getenv("URE_TEST_SETTHREADNAME") != 0) {
      42             :         // On Windows, setting thread names appears to only take effect when the
      43             :         // process is being debugged, so attach a debugger now:
      44             :         std::cout << "set: ";
      45             :         std::cin.ignore(std::numeric_limits< int >::max(), '\n');
      46             :     }
      47             : #endif
      48           1 :     setName("TestThread");
      49           1 :     if (std::getenv("URE_TEST_SETTHREADNAME") != 0) {
      50             :         // On Linux, the thread name can now be observed with "ps -L"; on
      51             :         // Windows with the Microsoft compiler, the thread name can now be
      52             :         // observed in a debugger.
      53           0 :         std::cout << "stop: ";
      54           0 :         std::cin.ignore(std::numeric_limits< int >::max(), '\n');
      55             :     }
      56           1 : }
      57             : 
      58           3 : class Test: public CppUnit::TestFixture {
      59             : private:
      60           2 :     CPPUNIT_TEST_SUITE(Test);
      61           1 :     CPPUNIT_TEST(test);
      62           2 :     CPPUNIT_TEST_SUITE_END();
      63             : 
      64             :     void test();
      65             : };
      66             : 
      67           1 : void Test::test() {
      68           1 :     TestThread t;
      69           1 :     t.create();
      70           1 :     t.join();
      71           1 : }
      72             : 
      73           1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
      74             : 
      75             : }
      76             : 
      77           4 : CPPUNIT_PLUGIN_IMPLEMENT();
      78             : 
      79             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10