Showing the changes to test/common/WelsThreadPoolTest.cpp (1 of 15 files). Show all
Unified · Split
| @@ -0,0 +1,54 @@ | ||
| 1 | +#include <gtest/gtest.h> | |
| 2 | +#include <string.h> | |
| 3 | +#include <string> | |
| 4 | +#include <list> | |
| 5 | +#include <map> | |
| 6 | + | |
| 7 | +#include "typedefs.h" | |
| 8 | +#include "WelsThreadLib.h" | |
| 9 | +#include "WelsThreadPool.h" | |
| 10 | +#include "WelsTask.h" | |
| 11 | +#include "WelsThreadPoolTest.h" | |
| 12 | + | |
| 13 | +#define TEST_TASK_NUM 20 | |
| 14 | + | |
| 15 | +class CSimpleTask : public IWelsTask { | |
| 16 | + public: | |
| 17 | + static uint32_t id; | |
| 18 | + | |
| 19 | + CSimpleTask() { | |
| 20 | + m_uiID = id ++; | |
| 21 | + } | |
| 22 | + | |
| 23 | + virtual ~CSimpleTask() { | |
| 24 | + } | |
| 25 | + | |
| 26 | + virtual int32_t Execute() { | |
| 27 | + WelsSleep (300 - m_uiID); | |
| 28 | + //printf ("Task %d executing\n", m_uiID); | |
| 29 | + return cmResultSuccess; | |
| 30 | + } | |
| 31 | + | |
| 32 | + private: | |
| 33 | + uint32_t m_uiID; | |
| 34 | +}; | |
| 35 | + | |
| 36 | +uint32_t CSimpleTask::id = 0; | |
| 37 | + | |
| 38 | + | |
| 39 | +TEST (CThreadPoolTest, CThreadPoolTest) { | |
| 40 | + CSimpleTask tasks[TEST_TASK_NUM]; | |
| 41 | + CThreadPoolTest cThreadPoolTest; | |
| 42 | + CWelsThreadPool cThreadPool (&cThreadPoolTest); | |
| 43 | + | |
| 44 | + int32_t i; | |
| 45 | + | |
| 46 | + for (i = 0; i < TEST_TASK_NUM; i++) { | |
| 47 | + cThreadPool.QueueTask (&tasks[i]); | |
| 48 | + } | |
| 49 | + | |
| 50 | + while (cThreadPoolTest.GetTaskCount() < TEST_TASK_NUM) { | |
| 51 | + WelsSleep (1); | |
| 52 | + } | |
| 53 | +} | |
| 54 | + | |