{
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)
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, ®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.
+}
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()
}
bool surfaceCreated; // result of surfaceCreated
+ bool surfaceCommitted; // result of surfaceCommitted
private:
DSWaylandCompositor *__waylandCompositor;
+ std::shared_ptr<DSWaylandSurface> __waylandSurface;
DSEventLoop __eventLoop;
};
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
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
)