Modify unit test case
[apps/agl-service-windowmanager.git] / test / test.cpp
1 #include <iostream>
2 #include <gtest/gtest.h>
3 #include <memory>
4 #include "applist.hpp"
5 #include "wm_client.hpp"
6 #include "wm_error.hpp"
7
8 using std::cout;
9 using std::endl;
10 using std::string;
11
12 namespace
13 {
14
15 const string test1 = "testApp";
16 const string test2 = "testApp2";
17 const string test3 = "testApp3";
18 const string test_role1 = "testRole1";
19 const string test_role2 = "testRole2";
20 const string test_role3 = "testRole3";
21 const string test_area1 = "testArea1";
22 const string test_area2 = "testArea2";
23 const string test_area3 = "testArea3";
24 const string test1_errname = "testApp_false";
25 const string test_role_err = "testRole_false";
26 const string test_area_err = "testRole_false";
27
28 const unsigned test_surface1 = 1;
29 const unsigned test_surface2 = 2;
30 const unsigned test_surface3 = 3;
31 const unsigned test_layer = 1;
32
33 static wm::AppList app_list;
34
35 class dbtest : public ::testing::Test
36 {
37 public:
38   void SetUp() {}
39   void TearDown() {}
40   void createTestClient(){
41     app_list.addClient(test1, test_layer, test_surface1, test_role1);
42     app_list.addClient(test2, test_layer, test_surface2, test_role2);
43     app_list.addClient(test3, test_layer, test_surface3, test_role2);
44   }
45
46 protected:
47 };
48
49 TEST_F(dbtest, add_and_contains_client)
50 {
51   app_list.addClient(test1, test_layer, test_surface1, test_role1);
52   app_list.addClient(test2, test_layer, test_surface2, test_role2);
53   app_list.addClient(test3, test_layer, test_surface2, test_role2);
54   bool result = app_list.contains(test1);
55   EXPECT_EQ(true, result);
56   result = app_list.contains(test2);
57   EXPECT_EQ(true, result);
58   result = app_list.contains(test1_errname);
59   EXPECT_EQ(false, result);
60 }
61
62 TEST_F(dbtest, lookup_client)
63 {
64   auto test = app_list.lookUpClient(test1);
65   cout << "Check getting client object" << endl;
66   EXPECT_EQ(true, (test) ? true : false);
67   cout << "Check client name" << endl;
68   EXPECT_EQ(test1, test->appID());
69   cout << "Check exception throwing of out_of_range" << endl;
70   ASSERT_THROW(app_list.lookUpClient(test1_errname), std::out_of_range);
71   app_list.clientDump();
72 }
73
74 TEST_F(dbtest, get_app_id)
75 {
76   bool found = false;
77   string appid = app_list.getAppID(test_surface1, test_role1, &found);
78   EXPECT_EQ(true, found);
79   EXPECT_EQ(test1, appid);
80   appid = app_list.getAppID(test_surface2, test_role1, &found);
81   EXPECT_EQ(false, found);
82   EXPECT_EQ("", appid);
83 }
84
85 TEST_F(dbtest, remove_surface)
86 {
87   bool ret = app_list.contains(test1);
88   EXPECT_EQ(true, ret);
89   auto client = app_list.lookUpClient(test1);
90   unsigned surface = client->surfaceID(test_role1);
91   EXPECT_NE(0, surface);
92   app_list.removeSurface(test_surface1);
93   surface = client->surfaceID(test_role1);
94   EXPECT_EQ(0, surface);
95 }
96
97 TEST_F(dbtest, remove_client)
98 {
99   ASSERT_NO_THROW(app_list.removeClient(test1_errname));
100   ASSERT_NO_THROW(app_list.removeClient(test1));
101   EXPECT_EQ(2, app_list.countClient());
102 }
103
104 TEST_F(dbtest, cl_get_function)
105 {
106   bool ret = app_list.contains(test2);
107   EXPECT_EQ(true, ret);
108   auto client = app_list.lookUpClient(test2);
109   EXPECT_EQ(test2, client->appID());
110   EXPECT_EQ(test_surface2, client->surfaceID(test_role2));
111   EXPECT_EQ(test_layer, client->layerID());
112   EXPECT_EQ(test_role2, client->role(test_surface2));
113   unsigned layer2 = 1000;
114   client->registerLayer(layer2);
115   EXPECT_EQ(layer2, client->layerID());
116   unsigned surface_1000 = 1000;
117   client->addSurface(test_role3, surface_1000);
118   EXPECT_EQ(test_surface2, client->surfaceID(test_role2));
119   EXPECT_EQ(surface_1000, client->surfaceID(test_role3));
120 }
121
122 TEST_F(dbtest, cl_remove_function)
123 {
124   bool ret = app_list.contains(test2);
125   EXPECT_EQ(true, ret);
126   auto client = app_list.lookUpClient(test2);
127   EXPECT_EQ(false, client->removeSurfaceIfExist(test_surface1));
128   EXPECT_EQ(true, client->removeSurfaceIfExist(test_surface2));
129   EXPECT_EQ(false, client->removeRole(test_role1));
130   EXPECT_EQ(true, client->removeRole(test_role3));
131   app_list.removeClient(test2);
132   app_list.removeClient(test3);
133   app_list.clientDump();
134   this->createTestClient();
135 }
136
137 class reqtest : public ::testing::Test
138 {
139 public:
140   void SetUp() {}
141   void TearDown() {}
142
143 protected:
144 };
145
146 TEST_F(reqtest, currentRequestNumber)
147 {
148   EXPECT_EQ(1, app_list.currentRequestNumber());
149 }
150
151 TEST_F(reqtest, 3_allocate_sequence)
152 {
153   wm::WMRequest req1(test1, test_role1, test_area1, wm::Task::TASK_ALLOCATE);
154   wm::WMRequest req2(test2, test_role2, test_area2, wm::Task::TASK_RELEASE);
155   wm::WMRequest req3(test3, test_role3, test_area3, wm::Task::TASK_ALLOCATE);
156   unsigned seq1 = app_list.addAllocateRequest(req1);
157   unsigned seq2 = app_list.addAllocateRequest(req2);
158   unsigned seq3 = app_list.addAllocateRequest(req3);
159   bool found = false;
160   bool result = false;
161
162   unsigned current = app_list.currentRequestNumber();
163   EXPECT_EQ(1, current);
164   EXPECT_EQ(1, seq1);
165   EXPECT_EQ(2, seq2);
166   EXPECT_EQ(3, seq3);
167
168   auto trg = app_list.getRequest(seq1, &found);
169   EXPECT_EQ(true, found);
170
171   wm::WMError werr = app_list.setAction(seq1, trg.appid, trg.role, trg.area, wm::TaskVisible::VISIBLE);
172   wm::WMError werr_sub = app_list.setAction(seq1, test3, test_role1, test_area3, wm::TaskVisible::VISIBLE);
173   EXPECT_EQ(wm::WMError::SUCCESS, werr);
174   EXPECT_EQ(wm::WMError::SUCCESS, werr_sub);
175
176   app_list.reqDump();
177
178   result = app_list.setEndDrawFinished(current, test1, test_role1);
179   EXPECT_EQ(true, result);
180
181   result = app_list.endDrawFullfilled(current);
182   EXPECT_EQ(false, result);
183
184   result = app_list.setEndDrawFinished(current, test3, test_role1);
185   EXPECT_EQ(true, result);
186
187   app_list.reqDump();
188
189   result = app_list.endDrawFullfilled(current);
190   EXPECT_EQ(true, result);
191
192   auto actions = app_list.getActions(current, &found);
193   EXPECT_EQ(true, found);
194   EXPECT_EQ(test1, actions[0].appid);
195   EXPECT_EQ(test_role1, actions[0].role);
196   EXPECT_EQ(test_area1, actions[0].area);
197   EXPECT_EQ(test3, actions[1].appid);
198   EXPECT_EQ(test_role1, actions[1].role);
199   EXPECT_EQ(test_area3, actions[1].area);
200
201   app_list.removeRequest(current);
202   /* lookup_seq_err = app_list.lookUpAllocatingApp(test1);
203   EXPECT_EQ(0, lookup_seq_err); */
204
205   app_list.next();
206   unsigned next_seq = app_list.currentRequestNumber();
207   EXPECT_EQ(seq2, next_seq);
208   result = app_list.haveRequest();
209   EXPECT_EQ(true, result);
210
211   app_list.reqDump();
212 }
213
214 } // namespace
215
216 int main(int argc, char **argv)
217 {
218   ::testing::InitGoogleTest(&argc, argv);
219   return RUN_ALL_TESTS();
220 }