• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "WelsList.h"
9 #include "WelsTask.h"
10 #include "WelsThreadPoolTest.h"
11 
12 
TEST(CThreadPoolTest,CThreadPoolTest_List)13 TEST (CThreadPoolTest, CThreadPoolTest_List) {
14 
15   CWelsList<IWelsTask>* pTaskList;
16   pTaskList = new CWelsList<IWelsTask>();
17   ASSERT_TRUE(NULL != pTaskList);
18 
19   CThreadPoolTest cThreadPoolTest;
20   CThreadPoolTest cThreadPoolTest1;
21   CSimpleTask* aTasks[2] = {NULL, NULL};
22   IWelsTask* pCurTask;
23 
24   int32_t  i;
25   aTasks[0] = new CSimpleTask (&cThreadPoolTest);
26   aTasks[1] = new CSimpleTask (&cThreadPoolTest1);
27   pTaskList->push_back(aTasks[0]);
28   pTaskList->push_back(aTasks[1]);
29   EXPECT_TRUE(2 == pTaskList->size());
30 
31   pCurTask = pTaskList->begin();
32   EXPECT_TRUE(pCurTask->GetSink() == &cThreadPoolTest);
33   pCurTask->GetSink()->OnTaskExecuted();//cThreadPoolTest
34   pTaskList->pop_front();
35 
36   EXPECT_TRUE(1 == pTaskList->size());
37 
38   pCurTask = pTaskList->begin();
39   EXPECT_TRUE(pCurTask->GetSink() == &cThreadPoolTest1);
40   pCurTask->GetSink()->OnTaskExecuted();//cThreadPoolTest1
41   pTaskList->pop_front();
42 
43   pTaskList->push_back(aTasks[1]);
44   EXPECT_TRUE(1 == pTaskList->size());
45 
46   pCurTask = pTaskList->begin();
47   EXPECT_TRUE(pCurTask->GetSink() == &cThreadPoolTest1);
48   pCurTask->GetSink()->OnTaskExecuted();//cThreadPoolTest1
49   pTaskList->pop_front();
50 
51   EXPECT_TRUE(1 == cThreadPoolTest.GetTaskCount());
52   EXPECT_TRUE(2 == cThreadPoolTest1.GetTaskCount());
53 
54   EXPECT_TRUE(0 == pTaskList->size());
55   for (i = 0; i < 2; i++) {
56     delete aTasks[i];
57     aTasks[i] = NULL;
58   }
59 
60   aTasks[0] = new CSimpleTask (&cThreadPoolTest1);
61   aTasks[1] = new CSimpleTask (&cThreadPoolTest);
62   pTaskList->push_back(aTasks[0]);
63   pTaskList->push_back(aTasks[1]);
64   pCurTask = pTaskList->begin();
65   EXPECT_TRUE(pCurTask->GetSink() == &cThreadPoolTest1);
66   pCurTask->GetSink()->OnTaskExecuted();//cThreadPoolTest1:3
67   pTaskList->pop_front();
68   EXPECT_TRUE(1 == pTaskList->size());
69 
70   pTaskList->push_back(aTasks[0]);
71   EXPECT_TRUE(2 == pTaskList->size());
72 
73   pCurTask = pTaskList->begin();
74   EXPECT_TRUE(pCurTask->GetSink() == &cThreadPoolTest);
75   pCurTask->GetSink()->OnTaskExecuted();//cThreadPoolTest:2
76   pTaskList->pop_front();
77   pCurTask = pTaskList->begin();
78   EXPECT_TRUE(pCurTask->GetSink() == &cThreadPoolTest1);
79   pCurTask->GetSink()->OnTaskExecuted();//cThreadPoolTest1:4
80   pTaskList->pop_front();
81 
82   EXPECT_TRUE(2 == cThreadPoolTest.GetTaskCount());
83   EXPECT_TRUE(4 == cThreadPoolTest1.GetTaskCount());
84 
85   for (i = 0; i < 2; i++) {
86     delete aTasks[i];
87     aTasks[i] = NULL;
88   }
89   delete pTaskList;
90 }
91 
92 
93