From 44aca184236466d9ceb9e67fc23f242cc036bfc3 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 24 Jul 2020 11:32:12 +0900 Subject: [PATCH] Test: add registerCallbackSurfaceCommitted test on DSWaylandSurfaceTest TEST_F(DSWaylandSurfaceTest, registerCallbackSurfaceCommitted) Change-Id: I559d46b933962ed19e7075a3613dfec943d862a9 --- packaging/libds.spec | 2 + tests/DSWaylandSurface-test.cpp | 94 ++++++++++++++++++++++++++++++++++++++++- tests/libds-mock.h | 15 ++++++- tests/libds-tests.h | 1 + tests/meson.build | 3 +- 5 files changed, 111 insertions(+), 4 deletions(-) diff --git a/packaging/libds.spec b/packaging/libds.spec index 5123402..9b432b6 100644 --- a/packaging/libds.spec +++ b/packaging/libds.spec @@ -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 diff --git a/tests/DSWaylandSurface-test.cpp b/tests/DSWaylandSurface-test.cpp index e23a9f9..84d7f7b 100644 --- a/tests/DSWaylandSurface-test.cpp +++ b/tests/DSWaylandSurface-test.cpp @@ -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(); + + 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 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); + + 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. +} diff --git a/tests/libds-mock.h b/tests/libds-mock.h index 4554dd6..94a0c04 100644 --- a/tests/libds-mock.h +++ b/tests/libds-mock.h @@ -55,9 +55,15 @@ public: DSWaylandCompositor::releaseInstance(); } - void onSurfaceCreated(std::shared_ptr) + void onSurfaceCreated(std::shared_ptr waylandSurface) { surfaceCreated = true; + __waylandSurface = waylandSurface; + __waylandSurface->registerCallbackSurfaceCommitted(this, std::bind(&MockWaylandCompositor::onSurfaceCommitted, this, std::placeholders::_1)); + } + + void onSurfaceCommitted(std::shared_ptr 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 __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 diff --git a/tests/libds-tests.h b/tests/libds-tests.h index 0a4656b..488e869 100644 --- a/tests/libds-tests.h +++ b/tests/libds-tests.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include diff --git a/tests/meson.build b/tests/meson.build index ecb7e04..b09a5c6 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -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 ) -- 2.7.4