test_tc_thread_pool.cpp 943 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "util/tc_timer.h"
  2. #include "util/tc_logger.h"
  3. #include "util/tc_common.h"
  4. #include "util/tc_thread_pool.h"
  5. #include "gtest/gtest.h"
  6. #include <iostream>
  7. #include <vector>
  8. using namespace std;
  9. using namespace tars;
  10. class UtilThreadPollTest : public testing::Test
  11. {
  12. public:
  13. //添加日志
  14. static void SetUpTestCase()
  15. {
  16. }
  17. static void TearDownTestCase()
  18. {
  19. }
  20. virtual void SetUp() //TEST跑之前会执行SetUp
  21. {
  22. }
  23. virtual void TearDown() //TEST跑完之后会执行TearDown
  24. {
  25. }
  26. };
  27. class TestClass
  28. {
  29. public:
  30. ~TestClass()
  31. {
  32. // LOG_CONSOLE_DEBUG << endl;
  33. }
  34. void test(int i)
  35. {
  36. _data.push_back(i);
  37. }
  38. vector<int> _data;
  39. };
  40. TEST_F(UtilThreadPollTest, testDecontructor)
  41. {
  42. TC_ThreadPool tpool;
  43. tpool.init(5);
  44. shared_ptr<TestClass> tPtr = std::make_shared<TestClass>();
  45. for(int i = 0; i < 5; i++)
  46. {
  47. tpool.exec(std::bind(&TestClass::test, tPtr.get(), std::placeholders::_1), i);
  48. }
  49. tpool.stop();
  50. }