From 5ccdb3a9e3de42970111f84d166e21c1dc55727c Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Sun, 10 Jul 2022 13:48:27 +0900 Subject: [PATCH] add indicator test cases Change-Id: I6c755aff6ca1764b73289b64991544b26bed08fb --- packaging/libds-tizen.spec | 1 + tests/meson.build | 26 +++ tests/tc_indicator.cpp | 505 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 532 insertions(+) create mode 100644 tests/tc_indicator.cpp diff --git a/packaging/libds-tizen.spec b/packaging/libds-tizen.spec index 34b918c..8935d5d 100644 --- a/packaging/libds-tizen.spec +++ b/packaging/libds-tizen.spec @@ -261,3 +261,4 @@ ninja -C builddir install %{_includedir}/libds-tizen/indicator.h %{_libdir}/pkgconfig/libds-tizen-indicator.pc %{_libdir}/libds-tizen-indicator.so +%{_bindir}/libds-tizen-indicator-tests diff --git a/tests/meson.build b/tests/meson.build index 1d8158c..8cff406 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -4,6 +4,12 @@ deps_test_common = [ dependency('wayland-client', required: true), ] +tc_mock_files = [ + 'mockclient.cpp', + 'mockcompositor.cpp' +] + +## allcoator_tbm tests tc_allocator_tbm_files = [ 'tc_main.cpp', 'tc_allocator_tbm.cpp', @@ -19,3 +25,23 @@ executable('libds-tizen-allocator-tbm-tests', install_dir: libds_tizen_bindir, install : true ) + +## indicator tests +tc_indicator_files = [ + 'tc_main.cpp', + 'tc_indicator.cpp', +] + +executable('libds-tizen-indicator-tests', + [ + tc_mock_files, + tc_indicator_files + ], + dependencies: [ + deps_test_common, + deps_libds_tizen_indicator, + dependency('libdrm', required: true), + ], + install_dir: libds_tizen_bindir, + install : true +) diff --git a/tests/tc_indicator.cpp b/tests/tc_indicator.cpp new file mode 100644 index 0000000..c589ef3 --- /dev/null +++ b/tests/tc_indicator.cpp @@ -0,0 +1,505 @@ +#include "tc_main.h" +#include "mockclient.h" +#include "mockcompositor.h" +#include +#include + +class MockIndicatorCompositor : public MockCompositor +{ +public: + MockIndicatorCompositor() + : MockCompositor(&MockIndicatorCompositor::TestSetup, this) + { + ds_inf("%s : this(%p)", __func__, this); + + // initialize the flags to check + bSurfaceDestroyed = false; + + bDestroyed = false; + + bStateOn = false; + bStateOff = false; + + bOpacityModeOpque = false; + bOpacityModeTranslucent = false; + bOpacityModeTransparent = false; + bOpacityModeBgTransparent = false; + + bVisibleTypeHidden = false; + bVisibleTypeShown = false; + } + + ~MockIndicatorCompositor() + { + ds_inf("%s : this(%p)", __func__, this); + } + + static void TestSetup(void *data) + { + MockIndicatorCompositor *mockComp = + static_cast(data); + Compositor *comp = mockComp->compositor; + + ds_inf("%s: mockComp(%p)", __func__, mockComp); + + // new surface listener + mockComp->mNewSurfaceListener.notify = + MockIndicatorCompositor::NewSurfaceCallback; + mockComp->mNewSurfaceListener.parent = mockComp; + ds_compositor_add_new_surface_listener(comp->compositor, + &mockComp->mNewSurfaceListener); + + mockComp->mIndicator = ds_tizen_indicator_create(comp->display); + + // destroy listener + mockComp->mDestroyListener.notify = + MockIndicatorCompositor::DestroyCallback; + mockComp->mDestroyListener.parent = mockComp; + ds_tizen_indicator_add_destroy_listener(mockComp->mIndicator, + &mockComp->mDestroyListener); + + // change_state listener + mockComp->mChangeStateListener.notify = + MockIndicatorCompositor::ChangeStateCallback; + mockComp->mChangeStateListener.parent = mockComp; + ds_tizen_indicator_add_change_state_listener(mockComp->mIndicator, + &mockComp->mChangeStateListener); + + // change_opacity_mode listener + mockComp->mChangeOpacityModeListener.notify = + MockIndicatorCompositor::ChangeOpacityModeCallback; + mockComp->mChangeOpacityModeListener.parent = mockComp; + ds_tizen_indicator_add_change_opacity_mode_listener( + mockComp->mIndicator, + &mockComp->mChangeOpacityModeListener); + + // change_visible_type listener + mockComp->mChangeVisibleTypeListener.notify = + MockIndicatorCompositor::ChangeVisibleTypeCallback; + mockComp->mChangeVisibleTypeListener.parent = mockComp; + ds_tizen_indicator_add_change_visible_type_listener( + mockComp->mIndicator, + &mockComp->mChangeVisibleTypeListener); + } + + static void NewSurfaceCallback(struct wl_listener *listener, void *data) + { + MockIndicatorCompositor *mockComp = + reinterpret_cast(listener)->parent; + struct ds_surface *surface = static_cast(data); + + ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface); + + mockComp->mSurface = surface; + + // del surface listener + mockComp->mDelSurfaceListener.notify = + MockIndicatorCompositor::DelSurfaceCallback; + mockComp->mDelSurfaceListener.parent = mockComp; + ds_surface_add_destroy_listener(surface, + &mockComp->mDelSurfaceListener); + } + + static void DelSurfaceCallback(struct wl_listener *listener, void *data) + { + MockIndicatorCompositor *mockComp = + reinterpret_cast(listener)->parent; + struct ds_surface *surface = static_cast(data); + + ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface); + + if (ds_surface_get_wl_resource(mockComp->mSurface) == + ds_surface_get_wl_resource(surface)) { + ds_inf("%s: surface is deleted.", __func__); + mockComp->bSurfaceDestroyed = true; + } + } + + static void DestroyCallback(struct wl_listener *listener, void *data) + { + ds_inf("%s", __func__); + + MockIndicatorCompositor *mockComp = + reinterpret_cast(listener)->parent; + + mockComp->bDestroyed = true; + } + + static void ChangeStateCallback(struct wl_listener *listener, void *data) + { + ds_inf("%s", __func__); + + MockIndicatorCompositor *mockComp = + reinterpret_cast(listener)->parent; + struct ds_surface *surface = static_cast(data); + enum ds_tizen_indicator_state state; + + ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface); + + state = ds_tizen_indicator_get_state(mockComp->mIndicator, + mockComp->mSurface); + + if (state == DS_TIZEN_INDICATOR_STATE_ON) + mockComp->bStateOn = true; + if (state == DS_TIZEN_INDICATOR_STATE_OFF) + mockComp->bStateOff = true; + } + + static void ChangeOpacityModeCallback(struct wl_listener *listener, + void *data) + { + ds_inf("%s", __func__); + + MockIndicatorCompositor *mockComp = + reinterpret_cast(listener)->parent; + struct ds_surface *surface = static_cast(data); + enum ds_tizen_indicator_opacity_mode opacity_mode; + + ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface); + + opacity_mode = ds_tizen_indicator_get_opacity_mode(mockComp->mIndicator, + mockComp->mSurface); + + if (opacity_mode == DS_TIZEN_INDICATOR_OPACITY_MODE_OPAQUE) + mockComp->bOpacityModeOpque = true; + if (opacity_mode == DS_TIZEN_INDICATOR_OPACITY_MODE_TRANSLUCENT) + mockComp->bOpacityModeTranslucent = true; + if (opacity_mode == DS_TIZEN_INDICATOR_OPACITY_MODE_TRANSPARENT) + mockComp->bOpacityModeTransparent = true; + if (opacity_mode == DS_TIZEN_INDICATOR_OPACITY_MODE_BG_TRANSPARENT) + mockComp->bOpacityModeBgTransparent = true; + } + + static void ChangeVisibleTypeCallback(struct wl_listener *listener, + void *data) + { + ds_inf("%s", __func__); + + MockIndicatorCompositor *mockComp = + reinterpret_cast(listener)->parent; + struct ds_surface *surface = static_cast(data); + enum ds_tizen_indicator_visible_type visible_type; + + ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface); + + visible_type = ds_tizen_indicator_get_visible_type(mockComp->mIndicator, + mockComp->mSurface); + + if (visible_type == DS_TIZEN_INDICATOR_VISIBLE_TYPE_HIDDEN) + mockComp->bVisibleTypeHidden = true; + if (visible_type == DS_TIZEN_INDICATOR_VISIBLE_TYPE_SHOWN) + mockComp->bVisibleTypeShown = true; + } + + void SendFlick() + { + ds_inf("%s", __func__); + + ds_tizen_indicator_send_flick(mIndicator, mSurface); + } + +public: + bool bSurfaceDestroyed; + bool bDestroyed; + bool bStateOn; + bool bStateOff; + bool bOpacityModeOpque; + bool bOpacityModeTranslucent; + bool bOpacityModeTransparent; + bool bOpacityModeBgTransparent; + bool bVisibleTypeHidden; + bool bVisibleTypeShown; + +private: + struct ds_surface *mSurface; + struct NewSurfaceListener : ::wl_listener { + MockIndicatorCompositor *parent; + }; + NewSurfaceListener mNewSurfaceListener; + struct DelSurfaceListener : ::wl_listener { + MockIndicatorCompositor *parent; + }; + NewSurfaceListener mDelSurfaceListener; + + struct ds_tizen_indicator *mIndicator; + struct DestroyListener : ::wl_listener { + MockIndicatorCompositor *parent; + }; + NewSurfaceListener mDestroyListener; + struct ChangeStateListener : ::wl_listener { + MockIndicatorCompositor *parent; + }; + NewSurfaceListener mChangeStateListener; + struct ChangeOpacityModeListener : ::wl_listener { + MockIndicatorCompositor *parent; + }; + NewSurfaceListener mChangeOpacityModeListener; + struct ChangeVisibleTypeListener : ::wl_listener { + MockIndicatorCompositor *parent; + }; + NewSurfaceListener mChangeVisibleTypeListener; +}; + +class MockIndicatorClient : public MockClient +{ +public: + MockIndicatorClient() + : bFlickEvent(false), + compositor_res(nullptr), + tizen_indicator(nullptr) + {} + MockIndicatorClient(const struct wl_registry_listener *listener) + : MockClient(listener, this) + { + ds_inf("%s", __func__); + + bFlickEvent = false; + } + ~MockIndicatorClient() + { + ds_inf("%s", __func__); + } + + void SetWlCompositor(struct wl_compositor *global_res) + { + ds_inf("%s", __func__); + + compositor_res = global_res; + } + + struct wl_compositor *GetWlCompositor() + { + ds_inf("%s", __func__); + + return compositor_res; + } + + void SetTizenIndicator(struct tizen_indicator *global_res) + { + ds_inf("%s", __func__); + + tizen_indicator = global_res; + } + + struct tizen_indicator *GetTizenIndicator() + { + ds_inf("%s", __func__); + + return tizen_indicator; + } + +public: + bool bFlickEvent; + +private: + struct wl_compositor *compositor_res; + struct tizen_indicator *tizen_indicator; +}; + +static void +client_tizen_indicator_cb_flick(void *data, struct tizen_indicator *indicator, + struct wl_surface *surface, int32_t type) +{ + ds_inf("%s", __func__); + + MockIndicatorClient *client = static_cast(data); + + client->bFlickEvent = true; +} + +static const struct tizen_indicator_listener indicator_cb_listener = { + .flick = client_tizen_indicator_cb_flick +}; + +static void +client_registry_cb_global(void *data, struct wl_registry *registry, + uint32_t name, const char *interface, uint32_t version) +{ + ds_inf("%s", __func__); + + MockIndicatorClient *client = static_cast(data); + struct wl_compositor *compositor_res; + struct tizen_indicator *tizen_indicator; + + if (!strcmp(interface, "wl_compositor")) { + compositor_res = (struct wl_compositor *)wl_registry_bind(registry, + name, &wl_compositor_interface, 1); + if (compositor_res == nullptr) { + ds_err("wl_registry_bind() failed. wl_compositor resource."); + return; + } + client->SetWlCompositor(compositor_res); + } else if (!strcmp(interface, "tizen_indicator")) { + tizen_indicator = (struct tizen_indicator *)wl_registry_bind(registry, + name, &tizen_indicator_interface, 1); + if (tizen_indicator == nullptr) { + ds_err("wl_registry_bind() failed. tizen_indicator resource."); + return; + } + client->SetTizenIndicator(tizen_indicator); + + tizen_indicator_add_listener(tizen_indicator, &indicator_cb_listener, + client); + } +} + +static void +client_registry_cb_global_remove(void *data, struct wl_registry *registry, + uint32_t name) +{ + ds_inf("%s", __func__); + + MockIndicatorClient *client = static_cast(data); + struct wl_compositor *compositor_res = client->GetWlCompositor(); + struct tizen_indicator *indicator_res = client->GetTizenIndicator(); + + tizen_indicator_destroy(indicator_res); + wl_compositor_destroy(compositor_res); +} + +static const struct wl_registry_listener registry_listener = { + .global = client_registry_cb_global, + .global_remove = client_registry_cb_global_remove +}; + +class IndicatorTest : public ::testing::Test +{ +public: + void SetUp(void) override; + void TearDown(void) override; + + MockIndicatorCompositor *comp; + MockIndicatorClient *client; + struct wl_compositor *compositor_res; + struct tizen_indicator *indicator_res; + struct wl_surface *surface_res; +}; + +void +IndicatorTest::SetUp(void) +{ + //ds_log_init(DS_DBG, NULL); + + ds_inf("%s", __func__); + + comp = new MockIndicatorCompositor(); + client = new MockIndicatorClient(®istry_listener); + compositor_res = client->GetWlCompositor(); + indicator_res = client->GetTizenIndicator(); + surface_res = wl_compositor_create_surface(compositor_res); + + client->RoundTrip(); +} + +void +IndicatorTest::TearDown(void) +{ + ds_inf("%s", __func__); + + wl_surface_destroy(surface_res); + client->RoundTrip(); + EXPECT_TRUE(comp->bSurfaceDestroyed); + + delete client; + delete comp; +} + + +TEST_F(IndicatorTest, Create_P) +{ + EXPECT_TRUE(true); +} + +TEST_F(IndicatorTest, Req_TizenIndicatorStateOn) +{ + tizen_indicator_set_state(indicator_res, surface_res, + TIZEN_INDICATOR_STATE_ON); + client->RoundTrip(); + EXPECT_TRUE(comp->bStateOn); + EXPECT_FALSE(comp->bStateOff); +} + +TEST_F(IndicatorTest, Req_TizenIndicatorStateOff) +{ + tizen_indicator_set_state(indicator_res, surface_res, + TIZEN_INDICATOR_STATE_OFF); + client->RoundTrip(); + EXPECT_FALSE(comp->bStateOn); + EXPECT_TRUE(comp->bStateOff); +} + +TEST_F(IndicatorTest, Req_TizenIndicatorOpacityModeOpaque) +{ + tizen_indicator_set_opacity_mode(indicator_res, surface_res, + TIZEN_INDICATOR_OPACITY_MODE_OPAQUE); + client->RoundTrip(); + EXPECT_TRUE(comp->bOpacityModeOpque); + EXPECT_FALSE(comp->bOpacityModeTranslucent); + EXPECT_FALSE(comp->bOpacityModeTransparent); + EXPECT_FALSE(comp->bOpacityModeBgTransparent); +} + +TEST_F(IndicatorTest, Req_TizenIndicatorOpacityModeTranslucent) +{ + tizen_indicator_set_opacity_mode(indicator_res, surface_res, + TIZEN_INDICATOR_OPACITY_MODE_TRANSLUCENT); + client->RoundTrip(); + EXPECT_FALSE(comp->bOpacityModeOpque); + EXPECT_TRUE(comp->bOpacityModeTranslucent); + EXPECT_FALSE(comp->bOpacityModeTransparent); + EXPECT_FALSE(comp->bOpacityModeBgTransparent); +} + +TEST_F(IndicatorTest, Req_TizenIndicatorOpacityModeTransparent) +{ + tizen_indicator_set_opacity_mode(indicator_res, surface_res, + TIZEN_INDICATOR_OPACITY_MODE_TRANSPARENT); + client->RoundTrip(); + EXPECT_FALSE(comp->bOpacityModeOpque); + EXPECT_FALSE(comp->bOpacityModeTranslucent); + EXPECT_TRUE(comp->bOpacityModeTransparent); + EXPECT_FALSE(comp->bOpacityModeBgTransparent); +} + +TEST_F(IndicatorTest, Req_TizenIndicatorOpacityModeBgTransparent) +{ + tizen_indicator_set_opacity_mode(indicator_res, surface_res, + TIZEN_INDICATOR_OPACITY_MODE_BG_TRANSPARENT); + client->RoundTrip(); + EXPECT_FALSE(comp->bOpacityModeOpque); + EXPECT_FALSE(comp->bOpacityModeTranslucent); + EXPECT_FALSE(comp->bOpacityModeTransparent); + EXPECT_TRUE(comp->bOpacityModeBgTransparent); +} + +TEST_F(IndicatorTest, Req_TizenIndicatorVisibleTypeHidden) +{ + tizen_indicator_set_visible_type(indicator_res, surface_res, + TIZEN_INDICATOR_VISIBLE_TYPE_HIDDEN); + client->RoundTrip(); + EXPECT_TRUE(comp->bVisibleTypeHidden); + EXPECT_FALSE(comp->bVisibleTypeShown); +} + +TEST_F(IndicatorTest, Req_TizenIndicatorVisibleTypeShown) +{ + tizen_indicator_set_visible_type(indicator_res, surface_res, + TIZEN_INDICATOR_VISIBLE_TYPE_SHOWN); + client->RoundTrip(); + EXPECT_FALSE(comp->bVisibleTypeHidden); + EXPECT_TRUE(comp->bVisibleTypeShown); +} + +TEST_F(IndicatorTest, Ev_TizenIndicatorFlick) +{ + tizen_indicator_set_state(indicator_res, surface_res, + TIZEN_INDICATOR_STATE_ON); + client->RoundTrip(); + EXPECT_TRUE(comp->bStateOn); + + comp->SendFlick(); + comp->Process(); + + client->RoundTrip(); + EXPECT_TRUE(client->bFlickEvent); +} -- 2.7.4