#include #include #include #include "applist.hpp" #include "wm_client.hpp" #include "wm_error.hpp" using std::cout; using std::endl; using std::string; namespace { const string test1 = "testApp"; const string test2 = "testApp2"; const string test3 = "testApp3"; const string test_role1 = "testRole1"; const string test_role2 = "testRole2"; const string test_role3 = "testRole3"; const string test_area1 = "testArea1"; const string test_area2 = "testArea2"; const string test_area3 = "testArea3"; const string test1_errname = "testApp_false"; const string test_role_err = "testRole_false"; const string test_area_err = "testRole_false"; const unsigned test_surface1 = 1; const unsigned test_surface2 = 2; const unsigned test_surface3 = 3; const unsigned test_layer = 1; static wm::AppList app_list; class dbtest : public ::testing::Test { public: void SetUp() {} void TearDown() {} void createTestClient(){ app_list.addClient(test1, test_layer, test_surface1, test_role1); app_list.addClient(test2, test_layer, test_surface2, test_role2); app_list.addClient(test3, test_layer, test_surface3, test_role2); } protected: }; TEST_F(dbtest, add_and_contains_client) { app_list.addClient(test1, test_layer, test_surface1, test_role1); app_list.addClient(test2, test_layer, test_surface2, test_role2); app_list.addClient(test3, test_layer, test_surface3, test_role2); bool result = app_list.contains(test1); EXPECT_EQ(true, result); result = app_list.contains(test2); EXPECT_EQ(true, result); result = app_list.contains(test1_errname); EXPECT_EQ(false, result); } TEST_F(dbtest, lookup_client) { auto test = app_list.lookUpClient(test1); cout << "Check getting client object" << endl; EXPECT_EQ(true, (test) ? true : false); cout << "Check client name" << endl; EXPECT_EQ(test1, test->appID()); cout << "Check exception throwing of out_of_range" << endl; ASSERT_THROW(app_list.lookUpClient(test1_errname), std::out_of_range); app_list.clientDump(); } TEST_F(dbtest, get_app_id) { bool found = false; string appid = app_list.getAppID(test_surface1, test_role1, &found); EXPECT_EQ(true, found); EXPECT_EQ(test1, appid); appid = app_list.getAppID(test_surface2, test_role1, &found); EXPECT_EQ(false, found); EXPECT_EQ("", appid); } TEST_F(dbtest, remove_surface) { bool ret = app_list.contains(test1); EXPECT_EQ(true, ret); auto client = app_list.lookUpClient(test1); unsigned surface = client->surfaceID(test_role1); EXPECT_NE(0, surface); app_list.removeSurface(test_surface1); surface = client->surfaceID(test_role1); EXPECT_EQ(0, surface); } TEST_F(dbtest, remove_client) { ASSERT_NO_THROW(app_list.removeClient(test1_errname)); ASSERT_NO_THROW(app_list.removeClient(test1)); EXPECT_EQ(2, app_list.countClient()); } TEST_F(dbtest, cl_get_function) { bool ret = app_list.contains(test2); EXPECT_EQ(true, ret); auto client = app_list.lookUpClient(test2); EXPECT_EQ(test2, client->appID()); EXPECT_EQ(test_surface2, client->surfaceID(test_role2)); EXPECT_EQ(test_layer, client->layerID()); EXPECT_EQ(test_role2, client->role(test_surface2)); unsigned layer2 = 1000; client->registerLayer(layer2); EXPECT_EQ(layer2, client->layerID()); unsigned surface_1000 = 1000; client->addSurface(test_role3, surface_1000); EXPECT_EQ(test_surface2, client->surfaceID(test_role2)); EXPECT_EQ(surface_1000, client->surfaceID(test_role3)); } TEST_F(dbtest, cl_remove_function) { bool ret = app_list.contains(test2); EXPECT_EQ(true, ret); auto client = app_list.lookUpClient(test2); EXPECT_EQ(false, client->removeSurfaceIfExist(test_surface1)); EXPECT_EQ(true, client->removeSurfaceIfExist(test_surface2)); EXPECT_EQ(false, client->removeRole(test_role1)); EXPECT_EQ(true, client->removeRole(test_role3)); app_list.removeClient(test2); app_list.removeClient(test3); app_list.clientDump(); this->createTestClient(); } class reqtest : public ::testing::Test { public: void SetUp() {} void TearDown() {} protected: }; TEST_F(reqtest, currentRequestNumber) { EXPECT_EQ(1, app_list.currentRequestNumber()); } TEST_F(reqtest, 3_allocate_sequence) { wm::WMRequest req1(test1, test_role1, test_area1, wm::Task::TASK_ALLOCATE); wm::WMRequest req2(test2, test_role2, test_area2, wm::Task::TASK_RELEASE); wm::WMRequest req3(test3, test_role3, test_area3, wm::Task::TASK_ALLOCATE); unsigned seq1 = app_list.addRequest(req1); unsigned seq2 = app_list.addRequest(req2); unsigned seq3 = app_list.addRequest(req3); bool found = false; bool result = false; unsigned current = app_list.currentRequestNumber(); EXPECT_EQ(1, current); EXPECT_EQ(1, seq1); EXPECT_EQ(2, seq2); EXPECT_EQ(3, seq3); auto trg = app_list.getRequest(seq1, &found); EXPECT_EQ(true, found); wm::WMError werr = app_list.setAction(seq1, trg.appid, trg.role, trg.area, wm::TaskVisible::VISIBLE); wm::WMError werr_sub = app_list.setAction(seq1, test3, test_role1, test_area3, wm::TaskVisible::VISIBLE); EXPECT_EQ(wm::WMError::SUCCESS, werr); EXPECT_EQ(wm::WMError::SUCCESS, werr_sub); app_list.reqDump(); result = app_list.setEndDrawFinished(current, test1, test_role1); EXPECT_EQ(true, result); result = app_list.endDrawFullfilled(current); EXPECT_EQ(false, result); result = app_list.setEndDrawFinished(current, test3, test_role1); EXPECT_EQ(true, result); app_list.reqDump(); result = app_list.endDrawFullfilled(current); EXPECT_EQ(true, result); auto actions = app_list.getActions(current, &found); EXPECT_EQ(true, found); EXPECT_EQ(test1, actions[0].appid); EXPECT_EQ(test_role1, actions[0].role); EXPECT_EQ(test_area1, actions[0].area); EXPECT_EQ(test3, actions[1].appid); EXPECT_EQ(test_role1, actions[1].role); EXPECT_EQ(test_area3, actions[1].area); app_list.removeRequest(current); /* lookup_seq_err = app_list.lookUpAllocatingApp(test1); EXPECT_EQ(0, lookup_seq_err); */ app_list.next(); unsigned next_seq = app_list.currentRequestNumber(); EXPECT_EQ(seq2, next_seq); result = app_list.haveRequest(); EXPECT_EQ(true, result); app_list.reqDump(); } } // namespace int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }