2 #include <gtest/gtest.h>
5 #include "wm_client.hpp"
6 #include "wm_error.hpp"
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";
28 const unsigned test_surface1 = 1;
29 const unsigned test_surface2 = 2;
30 const unsigned test_surface3 = 3;
31 const unsigned test_layer = 1;
33 static wm::AppList app_list;
35 class dbtest : public ::testing::Test
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);
49 TEST_F(dbtest, add_and_contains_client)
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_surface3, 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);
62 TEST_F(dbtest, lookup_client)
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();
74 TEST_F(dbtest, get_app_id)
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);
85 TEST_F(dbtest, remove_surface)
87 bool ret = app_list.contains(test1);
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);
97 TEST_F(dbtest, remove_client)
99 ASSERT_NO_THROW(app_list.removeClient(test1_errname));
100 ASSERT_NO_THROW(app_list.removeClient(test1));
101 EXPECT_EQ(2, app_list.countClient());
104 TEST_F(dbtest, cl_get_function)
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));
122 TEST_F(dbtest, cl_remove_function)
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();
137 class reqtest : public ::testing::Test
146 TEST_F(reqtest, currentRequestNumber)
148 EXPECT_EQ(1, app_list.currentRequestNumber());
151 TEST_F(reqtest, 3_allocate_sequence)
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.addRequest(req1);
157 unsigned seq2 = app_list.addRequest(req2);
158 unsigned seq3 = app_list.addRequest(req3);
162 unsigned current = app_list.currentRequestNumber();
163 EXPECT_EQ(1, current);
168 auto trg = app_list.getRequest(seq1, &found);
169 EXPECT_EQ(true, found);
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);
178 result = app_list.setEndDrawFinished(current, test1, test_role1);
179 EXPECT_EQ(true, result);
181 result = app_list.endDrawFullfilled(current);
182 EXPECT_EQ(false, result);
184 result = app_list.setEndDrawFinished(current, test3, test_role1);
185 EXPECT_EQ(true, result);
189 result = app_list.endDrawFullfilled(current);
190 EXPECT_EQ(true, result);
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);
201 app_list.removeRequest(current);
202 /* lookup_seq_err = app_list.lookUpAllocatingApp(test1);
203 EXPECT_EQ(0, lookup_seq_err); */
206 unsigned next_seq = app_list.currentRequestNumber();
207 EXPECT_EQ(seq2, next_seq);
208 result = app_list.haveRequest();
209 EXPECT_EQ(true, result);
216 int main(int argc, char **argv)
218 ::testing::InitGoogleTest(&argc, argv);
219 return RUN_ALL_TESTS();