Test: add registerCallbackSurfaceCommitted test on DSWaylandSurfaceTest 63/241663/1
authorSooChan Lim <sc1.lim@samsung.com>
Fri, 24 Jul 2020 02:32:12 +0000 (11:32 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 10:04:24 +0000 (19:04 +0900)
TEST_F(DSWaylandSurfaceTest, registerCallbackSurfaceCommitted)

Change-Id: I559d46b933962ed19e7075a3613dfec943d862a9

packaging/libds.spec
tests/DSWaylandSurface-test.cpp
tests/libds-mock.h
tests/libds-tests.h
tests/meson.build

index 5123402..9b432b6 100644 (file)
@@ -23,9 +23,11 @@ BuildRequires:  pkgconfig(ecore)
 BuildRequires:  pkgconfig(ecore-evas)
 BuildRequires:  pkgconfig(libinput)
 BuildRequires:  pkgconfig(libudev)
+
 # For samples and tests
 BuildRequires:  pkgconfig(wayland-client)
 BuildRequires:  pkgconfig(xkbcommon)
+BuildRequires:  pkgconfig(wayland-tbm-client)
 
 # for ignoring the libds.a
 %define _unpackaged_files_terminate_build 0
index e23a9f9..84d7f7b 100644 (file)
@@ -8,9 +8,35 @@ class DSWaylandSurfaceTest : public ::testing::Test
 {
 public:
        void SetUp(void) override
-       {}
+       {
+               setenv("XDG_RUNTIME_DIR", "/run", 1);
+       }
        void TearDown(void) override
-       {}
+       {
+               unsetenv("XDG_RUNTIME_DIR");
+       }
+};
+
+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.");
+       }
+}
+
+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(DSWaylandSurfaceTest, NewDSWaylandSurface)
@@ -40,3 +66,67 @@ TEST_F(DSWaylandSurfaceTest, NewDSWaylandSurfaceWithPrams)
                DSWaylandCompositor::releaseInstance();
        }
 }
+
+TEST_F(DSWaylandSurfaceTest, registerCallbackSurfaceCommitted)
+{
+       auto mockWaylandCompositor = std::make_unique<MockWaylandCompositor>();
+
+       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 surfaceCommitted
+               EXPECT_TRUE(comp->surfaceCommitted);
+
+               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<bool> clientThread = std::async(std::launch::async, []() -> bool {
+                       std::this_thread::sleep_for(std::chrono::milliseconds(40));
+                       auto testClient = std::make_shared<TestClient>();
+
+                       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, &registry_listener, testClient.get());
+                       wl_display_dispatch(testClient->display);
+                       wl_display_roundtrip(testClient->display);
+                       EXPECT_TRUE(testClient->compositor != nullptr);
+
+                       testClient->surface = wl_compositor_create_surface(testClient->compositor);
+                       EXPECT_TRUE(testClient->surface != nullptr);
+                       wl_display_roundtrip(testClient->display);
+
+                       testClient->tbm_client = wayland_tbm_client_init(testClient->display);
+                       EXPECT_TRUE(testClient->tbm_client != nullptr);
+                       testClient->tbmBuffer = tbm_surface_create(720, 1280, TBM_FORMAT_ARGB8888);
+                       EXPECT_TRUE(testClient->tbmBuffer != nullptr);
+                       testClient->buffer = wayland_tbm_client_create_buffer(testClient->tbm_client, testClient->tbmBuffer);
+                       EXPECT_TRUE(testClient->buffer != nullptr);
+
+                       wl_surface_attach(testClient->surface, testClient->buffer, 0, 0);
+                       wl_surface_damage(testClient->surface, 0, 0, 100, 100);
+                       wl_surface_commit(testClient->surface);
+
+                       wl_display_roundtrip(testClient->display);
+
+                       wayland_tbm_client_destroy_buffer(testClient->tbm_client, testClient->buffer);
+                       tbm_surface_destroy(testClient->tbmBuffer);
+                       wayland_tbm_client_deinit(testClient->tbm_client);
+
+                       wl_display_disconnect(testClient->display);
+
+                       return true;
+               }
+       );
+
+       mockWaylandCompositor->run();
+       EXPECT_TRUE(clientThread.get()); // join(wait) and get the return value.
+}
index 4554dd6..94a0c04 100644 (file)
@@ -55,9 +55,15 @@ public:
                DSWaylandCompositor::releaseInstance();
        }
 
-       void onSurfaceCreated(std::shared_ptr<DSWaylandSurface>)
+       void onSurfaceCreated(std::shared_ptr<DSWaylandSurface> waylandSurface)
        {
                surfaceCreated = true;
+               __waylandSurface = waylandSurface;
+               __waylandSurface->registerCallbackSurfaceCommitted(this, std::bind(&MockWaylandCompositor::onSurfaceCommitted, this, std::placeholders::_1));
+       }
+
+       void onSurfaceCommitted(std::shared_ptr<DSWaylandSurfaceCommitInfo> waylandSurfaceCommitInfo) {
+               surfaceCommitted = true;
        }
 
        void run()
@@ -71,9 +77,11 @@ public:
        }
 
        bool surfaceCreated; // result of surfaceCreated
+       bool surfaceCommitted; // result of surfaceCommitted
 
 private:
        DSWaylandCompositor *__waylandCompositor;
+       std::shared_ptr<DSWaylandSurface> __waylandSurface;
        DSEventLoop __eventLoop;
 };
 
@@ -86,6 +94,11 @@ struct TestClient
        struct wl_compositor *compositor;
        struct wl_registry *registry;
        struct wl_surface *surface;
+       struct wl_buffer *buffer;
+       struct wayland_tbm_client *tbm_client;
+       tbm_surface_h tbmBuffer;
+       int dx, dy, dw, dh; // damage x,y,w,h
+       int ax, ay; // attach x,y
 };
 
 #endif // UT_H
index 0a4656b..488e869 100644 (file)
@@ -36,6 +36,7 @@
 #include <future>
 #include <mutex>
 #include <wayland-client-protocol.h>
+#include <wayland-tbm-client.h>
 #include <Ecore.h>
 #include <gmock/gmock.h>
 
index ecb7e04..b09a5c6 100644 (file)
@@ -40,11 +40,12 @@ libds_tests_srcs = [
 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')
 
 executable(
        'libds-tests',
        libds_tests_srcs,
-       dependencies : [libds_static_declared_dep, gmock_dep, ecore_dep, ecore_evas_dep, wl_client_dep],
+       dependencies : [libds_static_declared_dep, gmock_dep, ecore_dep, ecore_evas_dep, wl_client_dep, wl_tbm_dep],
        install_dir : libds_prefix_bindir,
        install : true
        )