Lumiera  0.pre.03
»edit your freedom«
thread-wrapper-self-recognition-test.cpp
Go to the documentation of this file.
1 /*
2  ThreadWrapperSelfRecognitionTest(Test) - detect when code is running within a thread
3 
4  Copyright (C) Lumiera.org
5  2017, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/thread.hpp"
30 
31 using test::Test;
32 
33 
34 
35 namespace lib {
36 namespace test {
37 
38 
39  /******************************************************/
47  {
48 
49  virtual void
50  run (Arg)
51  {
52  ThreadJoinable<bool> testThread{"Thread self detection"
53  ,[&]{
54  return testThread.invokedWithinThread();
55  }};
56 
57  CHECK (not testThread.invokedWithinThread());
58  CHECK (testThread.join().get<bool>());
59  }
60  };
61 
62 
63 
65  LAUNCHER (ThreadWrapperSelfRecognitionTest_test, "function common");
66 
67 
68 
69 }} // namespace lib::test
Variant of the standard case, requiring to wait and join() on the termination of this thread...
Definition: thread.hpp:676
bool invokedWithinThread() const
detect if the currently executing code runs within this thread
Definition: thread.cpp:74
Definition: run.hpp:49
Implementation namespace for support and library code.
Abstract Base Class for all testcases.
Definition: run.hpp:62
Simple test class runner.
Convenience front-end to simplify and codify basic thread handling.