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)
5  2017, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/thread.hpp"
21 
22 using test::Test;
23 
24 
25 
26 namespace lib {
27 namespace test {
28 
29 
30  /******************************************************/
38  {
39 
40  virtual void
41  run (Arg)
42  {
43  ThreadJoinable<bool> testThread{"Thread self detection"
44  ,[&]{
45  return testThread.invokedWithinThread();
46  }};
47 
48  CHECK (not testThread.invokedWithinThread());
49  CHECK (testThread.join().get<bool>());
50  }
51  };
52 
53 
54 
56  LAUNCHER (ThreadWrapperSelfRecognitionTest_test, "function common");
57 
58 
59 
60 }} // namespace lib::test
Variant of the standard case, requiring to wait and join() on the termination of this thread...
Definition: thread.hpp:668
bool invokedWithinThread() const
detect if the currently executing code runs within this thread
Definition: thread.cpp:65
Definition: run.hpp:40
Implementation namespace for support and library code.
Abstract Base Class for all testcases.
Definition: run.hpp:53
Simplistic test class runner.
Convenience front-end to simplify and codify basic thread handling.