#include "DSWaylandCompositor.h"
#include "DSWaylandClient.h"
#include "DSWaylandSeat.h"
-#include "Ecore.h"
+#include "DSEventLoop.h"
+#include <chrono>
+#include <thread>
+#include <future>
+#include <mutex>
+#include <wayland-client-protocol.h>
+#include <Ecore.h>
using namespace display_server;
}
}
+class MockCompositor : public DSObject
+{
+public:
+ MockCompositor()
+ : surfaceCreated(false)
+ {
+ __compositor = std::make_shared<DSWaylandCompositor>(new DSObject);
+ __compositor->create();
+ __compositor->registerCallbackSurfaceCreated(this, std::bind(&MockCompositor::onSurfaceCreated, this, std::placeholders::_1));
+ }
+
+ ~MockCompositor() {}
+
+ void onSurfaceCreated(std::shared_ptr<DSWaylandSurface>) {
+ surfaceCreated = true;
+ }
+
+ void run() {
+ __eventLoop.run();
+ }
+
+ void quit() {
+ __eventLoop.quit();
+ }
+
+ bool surfaceCreated; // result of surfaceCreated
+
+private:
+ std::shared_ptr<DSWaylandCompositor> __compositor;
+ DSEventLoop __eventLoop;
+};
+
+struct TestClient
+{
+ struct wl_display *display;
+ struct wl_compositor *compositor;
+ struct wl_registry *registry;
+ struct wl_surface *surface;
+};
+
+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(DSWaylandCompositorTest, registerCallbackSurfaceCreated)
+{
+ auto mockCompositor = std::make_unique<MockCompositor>();
+
+ Ecore_Timer *serverQuitTimer = nullptr;
+ double severQuitTime = 1.0;
+ auto serverQuitFunc = [](void *data) -> Eina_Bool {
+ MockCompositor *comp = (MockCompositor *)data;
+
+ // quit server
+ comp->quit();
+ // check the emitting the surfaceCreated
+ EXPECT_TRUE(comp->surfaceCreated);
+
+ return EINA_FALSE;
+ };
+ serverQuitTimer = ecore_timer_loop_add(severQuitTime, serverQuitFunc, mockCompositor.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);
+
+ wl_display_disconnect(testClient->display);
+
+ return true;
+ }
+ );
+
+ mockCompositor->run();
+ EXPECT_TRUE(clientThread.get()); // join(wait) and get the return value.
+}
+
+
gmock_dep = dependency('gmock', method : 'pkg-config')
ecore_dep = dependency('ecore', method : 'pkg-config')
+wl_client_dep = dependency('wayland-client', method : 'pkg-config')
executable(
'libds-tests',
libds_tests_srcs,
- dependencies : [libds_static_declared_dep, gmock_dep, ecore_dep, ecore_evas_dep],
+ dependencies : [libds_static_declared_dep, gmock_dep, ecore_dep, ecore_evas_dep, wl_client_dep],
install_dir : libds_prefix_bindir,
install : true
)