add test cases for ds_tizen_screen_rotation 35/278635/1
authorSooChan Lim <sc1.lim@samsung.com>
Fri, 22 Jul 2022 05:31:13 +0000 (14:31 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Fri, 22 Jul 2022 14:00:42 +0000 (23:00 +0900)
Change-Id: I35a3d6f5519d7c4f0f93d66bd71788415e8a83ef

packaging/libds-tizen.spec
tests/meson.build
tests/tc_screen_rotation.cpp [new file with mode: 0644]

index 0dfbbd8..70f06e5 100644 (file)
@@ -446,3 +446,4 @@ ninja -C builddir install
 %{_includedir}/libds-tizen/screen_rotation.h
 %{_libdir}/pkgconfig/libds-tizen-screen-rotation.pc
 %{_libdir}/libds-tizen-screen-rotation.so
+%{_bindir}/libds-tizen-screen-rotation-tests
index b375f18..43b227e 100644 (file)
@@ -146,3 +146,24 @@ executable('libds-tizen-renderer-tests',
   install_dir: libds_tizen_bindir,
   install : true
 )
+
+## screen-rotation tests
+tc_screen_rotation_files = [
+  'tc_main.cpp',
+  'tc_screen_rotation.cpp',
+]
+
+executable('libds-tizen-screen-rotation-tests',
+  [
+    tc_mock_files,
+    tc_screen_rotation_files
+  ],
+  dependencies: [
+    deps_test_common,
+    deps_libds_tizen_screen_rotation,
+    dependency('libdrm', required: true),
+    dependency('tizen-extension-client', required: true),
+  ],
+  install_dir: libds_tizen_bindir,
+  install : true
+)
diff --git a/tests/tc_screen_rotation.cpp b/tests/tc_screen_rotation.cpp
new file mode 100644 (file)
index 0000000..cb257fa
--- /dev/null
@@ -0,0 +1,390 @@
+#include "tc_main.h"
+#include "mockclient.h"
+#include "mockcompositor.h"
+#include <libds-tizen/screen_rotation.h>
+#include <tizen-extension-client-protocol.h>
+
+#define TIZEN_SCREEN_ROTATION_VERSION 1
+
+class MockScreenRotationCompositor : public MockCompositor
+{
+public:
+    MockScreenRotationCompositor()
+        : MockCompositor(&MockScreenRotationCompositor::TestSetup, this)
+    {
+        ds_inf("%s : this(%p)", __func__, this);
+
+        // initialize the flags to check
+        bSurfaceDestroyed = false;
+
+        bDestroyed = false;
+        bGetIgnoreOutputTransform = false;
+        bDestroyScreenRotationInfo = false;
+    }
+
+    ~MockScreenRotationCompositor()
+    {
+        ds_inf("%s : this(%p)", __func__, this);
+    }
+
+    static void TestSetup(void *data)
+    {
+        MockScreenRotationCompositor *mockComp =
+            static_cast<MockScreenRotationCompositor *>(data);
+        Compositor *comp = mockComp->compositor;
+
+        ds_inf("%s: mockComp(%p)", __func__, mockComp);
+
+        // new surface listener
+        mockComp->mNewSurfaceListener.notify =
+            MockScreenRotationCompositor::NewSurfaceCallback;
+        mockComp->mNewSurfaceListener.parent = mockComp;
+        ds_compositor_add_new_surface_listener(comp->compositor,
+                &mockComp->mNewSurfaceListener);
+
+        mockComp->mScreenRotation =
+            ds_tizen_screen_rotation_create(comp->display);
+
+        // destroy listener
+        mockComp->mDestroyListener.notify =
+            MockScreenRotationCompositor::DestroyCallback;
+        mockComp->mDestroyListener.parent = mockComp;
+        ds_tizen_screen_rotation_add_destroy_listener(mockComp->mScreenRotation,
+            &mockComp->mDestroyListener);
+
+        // add_ignore_output_transform listener
+        mockComp->mGetIgnoreOutputTransformListener.notify =
+            MockScreenRotationCompositor::GetIgnoreOutputTransformCallback;
+        mockComp->mGetIgnoreOutputTransformListener.parent = mockComp;
+        ds_tizen_screen_rotation_add_get_ignore_output_transform_info_listener(
+            mockComp->mScreenRotation,
+            &mockComp->mGetIgnoreOutputTransformListener);
+    }
+
+    static void NewSurfaceCallback(struct wl_listener *listener, void *data)
+    {
+        MockScreenRotationCompositor *mockComp =
+            reinterpret_cast<NewSurfaceListener *>(listener)->parent;
+        struct ds_surface *surface = static_cast<struct ds_surface *>(data);
+
+        ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface);
+
+        mockComp->mSurface = surface;
+
+        // del surface listener
+        mockComp->mDelSurfaceListener.notify =
+            MockScreenRotationCompositor::DelSurfaceCallback;
+        mockComp->mDelSurfaceListener.parent = mockComp;
+        ds_surface_add_destroy_listener(surface,
+            &mockComp->mDelSurfaceListener);
+    }
+
+    static void DelSurfaceCallback(struct wl_listener *listener, void *data)
+    {
+        MockScreenRotationCompositor *mockComp =
+            reinterpret_cast<DelSurfaceListener *>(listener)->parent;
+        struct ds_surface *surface = static_cast<struct ds_surface *>(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__);
+
+        MockScreenRotationCompositor *mockComp =
+            reinterpret_cast<DestroyListener *>(listener)->parent;
+
+        mockComp->bDestroyed = true;
+    }
+
+    static void GetIgnoreOutputTransformCallback(struct wl_listener *listener,
+        void *data)
+    {
+        ds_inf("%s", __func__);
+
+        MockScreenRotationCompositor *mockComp =
+            reinterpret_cast<GetIgnoreOutputTransformListener *>(listener)->parent;
+        struct ds_tizen_screen_rotation_info *info =
+            static_cast<struct ds_tizen_screen_rotation_info *>(data);
+
+        ds_inf("%s: mockComp(%p), info(%p)", __func__, mockComp, info);
+
+        mockComp->bGetIgnoreOutputTransform = true;
+
+        mockComp->mInfo = info;
+        mockComp->mSurface =
+            ds_tizen_screen_rotation_info_get_surface(mockComp->mInfo);
+
+        // info destroy listener
+        mockComp->mScreenRotationInfoDestroyListener.notify =
+            MockScreenRotationCompositor::ScreenRotationInfoDestroyCallback;
+        mockComp->mScreenRotationInfoDestroyListener.parent = mockComp;
+        ds_tizen_screen_rotation_info_add_destroy_listener(mockComp->mInfo,
+            &mockComp->mScreenRotationInfoDestroyListener);
+    }
+
+    static void ScreenRotationInfoDestroyCallback(struct wl_listener *listener,
+        void *data)
+    {
+        ds_inf("%s", __func__);
+
+        MockScreenRotationCompositor *mockComp =
+            reinterpret_cast<ScreenRotationInfoDestroyListener *>(listener)->parent;
+        struct ds_tizen_screen_rotation_info *info =
+            static_cast<struct ds_tizen_screen_rotation_info *>(data);
+
+        ds_inf("%s: mockComp(%p), info(%p)", __func__, mockComp, info);
+
+        if (mockComp->mInfo == info) {
+            ds_inf("%s: info is deleted.", __func__);
+            mockComp->bDestroyScreenRotationInfo = true;
+        }
+    }
+
+    void SendIgnoreOutputTransform(uint32_t ignore)
+    {
+        ds_inf("%s", __func__);
+
+        ds_tizen_screen_rotation_send_ignore_output_transform(mInfo, ignore);
+    }
+
+public:
+    bool bSurfaceDestroyed;
+    bool bDestroyed;
+    bool bGetIgnoreOutputTransform;
+    bool bDestroyScreenRotationInfo;
+
+private:
+    struct ds_tizen_screen_rotation_info *mInfo;
+    struct ds_surface *mSurface;
+
+    struct NewSurfaceListener : ::wl_listener {
+        MockScreenRotationCompositor *parent;
+    };
+    NewSurfaceListener mNewSurfaceListener;
+
+    struct DelSurfaceListener : ::wl_listener {
+        MockScreenRotationCompositor *parent;
+    };
+    DelSurfaceListener mDelSurfaceListener;
+
+    struct ds_tizen_screen_rotation *mScreenRotation;
+
+    struct DestroyListener : ::wl_listener {
+        MockScreenRotationCompositor *parent;
+    };
+    DestroyListener mDestroyListener;
+
+    struct GetIgnoreOutputTransformListener : ::wl_listener {
+        MockScreenRotationCompositor *parent;
+    };
+    GetIgnoreOutputTransformListener mGetIgnoreOutputTransformListener;
+
+    struct ScreenRotationInfoDestroyListener : ::wl_listener {
+        MockScreenRotationCompositor *parent;
+    };
+    ScreenRotationInfoDestroyListener mScreenRotationInfoDestroyListener;
+};
+
+class MockScreenRotationClient : public MockClient
+{
+public:
+    MockScreenRotationClient()
+        : bIgnoreOutputTransformEvent(false),
+          mIgnore(0),
+          compositor_res(nullptr),
+          screen_rotation_res(nullptr)
+    {}
+    MockScreenRotationClient(const struct wl_registry_listener *listener)
+        : MockClient(listener, this)
+    {
+        ds_inf("%s", __func__);
+
+        bIgnoreOutputTransformEvent = false;
+        mIgnore = 0;
+    }
+    ~MockScreenRotationClient()
+    {
+        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 SetTizenScreenRotation(struct tizen_screen_rotation *resource)
+    {
+        ds_inf("%s", __func__);
+
+        screen_rotation_res = resource;
+    }
+
+    struct tizen_screen_rotation *GetTizenScreenRotation()
+    {
+        ds_inf("%s", __func__);
+
+        return screen_rotation_res;
+    }
+
+public:
+    bool bIgnoreOutputTransformEvent;
+    uint32_t mIgnore;
+
+private:
+    struct wl_compositor *compositor_res;
+    struct tizen_screen_rotation *screen_rotation_res;
+};
+
+static void
+client_tizen_screen_rotation_cb_ignore_output_transform(void *data,
+    struct tizen_screen_rotation *screen_rotation_res,
+    struct wl_surface *surface_resource, uint32_t ignore)
+{
+    ds_inf("%s", __func__);
+
+    MockScreenRotationClient *client = static_cast<MockScreenRotationClient *>(data);
+
+    client->bIgnoreOutputTransformEvent = true;
+    client->mIgnore = ignore;
+}
+
+static const struct
+tizen_screen_rotation_listener screen_rotation_cb_listener = {
+    .ignore_output_transform = client_tizen_screen_rotation_cb_ignore_output_transform,
+};
+
+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__);
+
+    MockScreenRotationClient *client = static_cast<MockScreenRotationClient *>(data);
+    struct wl_compositor *compositor_res;
+    struct tizen_screen_rotation *screen_rotation_res;
+
+    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_screen_rotation")) {
+        screen_rotation_res = (struct tizen_screen_rotation *)wl_registry_bind(registry,
+            name, &tizen_screen_rotation_interface, TIZEN_SCREEN_ROTATION_VERSION);
+        if (screen_rotation_res == nullptr) {
+            ds_err("wl_registry_bind() failed. tizen_screen_rotation resource.");
+            return;
+        }
+        client->SetTizenScreenRotation(screen_rotation_res);
+
+        tizen_screen_rotation_add_listener(screen_rotation_res,
+            &screen_rotation_cb_listener, client);
+    }
+}
+
+static void
+client_registry_cb_global_remove(void *data, struct wl_registry *registry,
+    uint32_t name)
+{
+    ds_inf("%s", __func__);
+
+    MockScreenRotationClient *client = static_cast<MockScreenRotationClient *>(data);
+    struct wl_compositor *compositor_res = client->GetWlCompositor();
+    struct tizen_screen_rotation *screen_rotation_res = client->GetTizenScreenRotation();
+
+    tizen_screen_rotation_destroy(screen_rotation_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 ScreenRotationTest : public ::testing::Test
+{
+public:
+    void SetUp(void) override;
+    void TearDown(void) override;
+
+    MockScreenRotationCompositor *comp;
+    MockScreenRotationClient *client;
+    struct wl_compositor *compositor_res;
+    struct tizen_screen_rotation *screen_rotation_res;
+    struct wl_surface *surface_res;
+};
+
+void
+ScreenRotationTest::SetUp(void)
+{
+    //ds_log_init(DS_DBG, NULL);
+
+    ds_inf("%s", __func__);
+
+    comp = new MockScreenRotationCompositor();
+    client = new MockScreenRotationClient(&registry_listener);
+    compositor_res = client->GetWlCompositor();
+    screen_rotation_res = client->GetTizenScreenRotation();
+    surface_res = wl_compositor_create_surface(compositor_res);
+
+    client->RoundTrip();
+}
+
+void
+ScreenRotationTest::TearDown(void)
+{
+    ds_inf("%s", __func__);
+
+    wl_surface_destroy(surface_res);
+    client->RoundTrip();
+    EXPECT_TRUE(comp->bSurfaceDestroyed);
+
+    delete client;
+    delete comp;
+}
+
+TEST_F(ScreenRotationTest, Create_P)
+{
+    EXPECT_TRUE(true);
+}
+
+TEST_F(ScreenRotationTest, Req_TizenScreenRotationGetIgnoreOutputTransform)
+{
+    tizen_screen_rotation_get_ignore_output_transform(screen_rotation_res, surface_res);
+    client->RoundTrip();
+    EXPECT_TRUE(comp->bGetIgnoreOutputTransform);
+}
+
+TEST_F(ScreenRotationTest, Ev_TizenScreenRotationSurfaceRedraw)
+{
+    tizen_screen_rotation_get_ignore_output_transform(screen_rotation_res, surface_res);
+    client->RoundTrip();
+    EXPECT_TRUE(comp->bGetIgnoreOutputTransform);
+
+    comp->SendIgnoreOutputTransform(1);
+    comp->Process();
+
+    client->RoundTrip();
+    EXPECT_TRUE(client->bIgnoreOutputTransformEvent);
+    EXPECT_TRUE(client->mIgnore == 1);
+}