From dc7d399d7d1a2b098f5ce48b2ee4715f28a8334e Mon Sep 17 00:00:00 2001 From: Duna Oh Date: Thu, 3 Sep 2020 15:13:33 +0900 Subject: [PATCH] DSwaylandTizenAppinfo-test: add more test cases for better code coverage Change-Id: I776474f8eb2f06141b393b54397a942e7771547a --- src/DSWaylandServer/DSWaylandTizenAppinfo.cpp | 3 + tests/DSWaylandTizenAppinfo-test.cpp | 92 +++++++++++++++++++++++++++ tests/meson.build | 3 +- 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/src/DSWaylandServer/DSWaylandTizenAppinfo.cpp b/src/DSWaylandServer/DSWaylandTizenAppinfo.cpp index c78681d..852db56 100644 --- a/src/DSWaylandServer/DSWaylandTizenAppinfo.cpp +++ b/src/DSWaylandServer/DSWaylandTizenAppinfo.cpp @@ -63,6 +63,7 @@ void DSWaylandTizenAppinfoPrivate::tizen_launch_appinfo_destroy(Resource *resour { DSLOG_DBG("TizenAppinfoPriv", ""); } +/*LCOV_EXCL_START*/ void DSWaylandTizenAppinfoPrivate::tizen_launch_appinfo_register_pid(Resource *resource, uint32_t pid) { DSLOG_DBG("TizenAppinfoPriv", ""); @@ -75,6 +76,8 @@ void DSWaylandTizenAppinfoPrivate::tizen_launch_appinfo_set_appid(Resource *reso { DSLOG_DBG("TizenAppinfoPriv", ""); } +/*LCOV_EXCL_STOP*/ + void DSWaylandTizenAppinfoPrivate::tizen_launch_appinfo_get_base_output_resolution(Resource *resource, uint32_t pid) { DSLOG_DBG("TizenAppinfoPriv", ""); diff --git a/tests/DSWaylandTizenAppinfo-test.cpp b/tests/DSWaylandTizenAppinfo-test.cpp index 8589a32..b77fe57 100644 --- a/tests/DSWaylandTizenAppinfo-test.cpp +++ b/tests/DSWaylandTizenAppinfo-test.cpp @@ -22,7 +22,9 @@ */ #include "libds-tests.h" +#include #include "DSWaylandTizenAppinfo.h" +#include "DSTizenAppinfoMgr.h" using namespace display_server; @@ -52,6 +54,20 @@ TEST_F(DSWaylandTizenAppinfoTest, New_Appinfo) DSWaylandCompositor::releaseInstance(); } +TEST_F(DSWaylandTizenAppinfoTest, New_Appinfo_with_AppinfoMgr) +{ + DSWaylandCompositor *compositor = DSWaylandCompositor::getInstance(); + DSTizenAppinfoMgr *dsAppinfoMgr = DSTizenAppinfoMgr::getInstance(); + DSWaylandTizenAppinfo *tzAppinfo = new DSWaylandTizenAppinfo(compositor, dsAppinfoMgr); + EXPECT_TRUE(tzAppinfo != nullptr); + + if (tzAppinfo) + delete tzAppinfo; + + DSTizenAppinfoMgr::releaseInstance(); + DSWaylandCompositor::releaseInstance(); +} + TEST_F(DSWaylandTizenAppinfoTest, Initialize_Appinfo) { bool ret; @@ -67,3 +83,79 @@ TEST_F(DSWaylandTizenAppinfoTest, Initialize_Appinfo) DSWaylandCompositor::releaseInstance(); } + +static struct tizen_launch_appinfo *tz_appinfo = nullptr; + +static void +handle_global(void *data, struct wl_registry *registry, uint32_t name, + const char *interface, uint32_t version) +{ + struct TestClient *testClient = (struct TestClient *)data; + + if (strcmp(interface, "wl_compositor") == 0) { + testClient->compositor = (struct wl_compositor *)wl_registry_bind(registry, name, &wl_compositor_interface, 1); + if (!testClient->compositor) + DSLOG_ERR("TEST", "wl_registry_bind compositor fails."); + } + else if(strcmp(interface, "tizen_launch_appinfo") == 0) + { + const char * appId = "com.samsung.clocksetting"; + + tz_appinfo = (struct tizen_launch_appinfo *)wl_registry_bind(registry, name, &tizen_launch_appinfo_interface, 1); + + tizen_launch_appinfo_register_appid(tz_appinfo, appId); + tizen_launch_appinfo_set_pid(tz_appinfo, appId, 4077); + tizen_launch_appinfo_deregister_appid(tz_appinfo, appId); + } +} + +static void +handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) +{} + +static const struct wl_registry_listener registry_listener = { + handle_global, + handle_global_remove +}; +TEST_F(DSWaylandTizenAppinfoTest, testRequest_Appinfo) +{ + auto mockWaylandCompositor = std::make_unique(); + + Ecore_Timer *serverQuitTimer = nullptr; + double severQuitTime = 1.0; + auto serverQuitFunc = [](void *data) -> Eina_Bool { + MockWaylandCompositor *comp = (MockWaylandCompositor *)data; + + // quit server + comp->quit(); + // check the emitting the surfaceCreated + EXPECT_TRUE(tz_appinfo != nullptr); + + return EINA_FALSE; + }; + serverQuitTimer = ecore_timer_loop_add(severQuitTime, serverQuitFunc, mockWaylandCompositor.get()); + EXPECT_TRUE(serverQuitTimer != nullptr); + + // create the wayland client which creates the wl_surface. + std::future clientThread = std::async(std::launch::async, []() -> bool { + std::this_thread::sleep_for(std::chrono::milliseconds(40)); + auto testClient = std::make_shared(); + + testClient->display = wl_display_connect(NULL); + EXPECT_TRUE(testClient->display != nullptr); + + testClient->registry = wl_display_get_registry(testClient->display); + wl_registry_add_listener(testClient->registry, ®istry_listener, testClient.get()); + wl_display_dispatch(testClient->display); + wl_display_roundtrip(testClient->display); + EXPECT_TRUE(testClient->compositor != nullptr); + + wl_display_disconnect(testClient->display); + + return true; + } + ); + + mockWaylandCompositor->run(); + EXPECT_TRUE(clientThread.get()); // join(wait) and get the return value. +} diff --git a/tests/meson.build b/tests/meson.build index 16386aa..3331b77 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -66,11 +66,12 @@ gmock_dep = dependency('gmock', method : 'pkg-config') ecore_dep = dependency('ecore', method : 'pkg-config') wl_client_dep = dependency('wayland-client', method : 'pkg-config') wl_tbm_dep = dependency('wayland-tbm-client', method : 'pkg-config') +tizen_launch_client_dep = dependency('tizen-launch-client') executable( 'libds-tests', libds_tests_srcs, - dependencies : [libds_declared_dep, gmock_dep, ecore_dep, ecore_evas_dep, wl_client_dep, wl_tbm_dep], + dependencies : [libds_declared_dep, gmock_dep, ecore_dep, ecore_evas_dep, wl_client_dep, wl_tbm_dep, tizen_launch_client_dep], install_dir : libds_prefix_bindir, install : true ) -- 2.7.4