simple thread
simple_thread_test_utils.hpp
1 #ifndef __SIMPLE_THREAD_TEST_UTILS__
2 #define __SIMPLE_THREAD_TEST_UTILS__
3 
4 #include <iostream>
5 #include <sstream>
6 #include <string>
7 #include <mutex>
8 #include "sthread"
9 
10 namespace stt { // simple thread test
11 namespace detail {
12 
13 std::unique_lock<std::mutex> log_lock();
14 
15 inline void log() {
16  std::cout << std::endl << std::flush;
17 }
18 
19 template <typename T, typename... As>
20 inline void log(T&& t, As&&... as) {
21  std::cout << t;
22  log(std::forward<As>(as)...);
23 }
24 
25 }
26 
27 template <typename... As>
28 inline void log(const char* func, As&&... as) {
29  auto lk = detail::log_lock();
30  detail::log("[", func, "] ", std::forward<As>(as)...);
31 }
32 
33 
34 template <typename CONTEXT_WRAPPER_T>
35 struct test_runner {
36  test_runner() { }
37 
38  inline void run() {
39  std::stringstream ss;
40  std::string test_str = ss.str();
41  test();
42  }
43 
44 protected:
45  /*
46  * @brief user test implementation
47  */
48  virtual void test() = 0;
49 };
50 
51 }
52 
53 #endif
Definition: simple_thread_test_utils.hpp:35