--- /dev/null
+#include "tc_main.h"
+#include "mockclient.h"
+#include "mockcompositor.h"
+#include <libds-tizen/embedded_compositor.h>
+#include <libds/surface.h>
+#include <tizen-extension-client-protocol.h>
+
+#define TIZEN_EMBEDDED_COMPOSITOR_VERSION 1
+
+class MockEmbeddedCompositorCompositor : public MockCompositor
+{
+public:
+ MockEmbeddedCompositorCompositor()
+ : MockCompositor(&MockEmbeddedCompositorCompositor::TestSetup, this)
+ {
+ ds_inf("%s : this(%p)", __func__, this);
+
+ // initialize the flags to check
+ bSurfaceDestroyed = false;
+
+ bDestroyed = false;
+ }
+
+ ~MockEmbeddedCompositorCompositor()
+ {
+ ds_inf("%s : this(%p)", __func__, this);
+ }
+
+ static void TestSetup(void *data)
+ {
+ MockEmbeddedCompositorCompositor *mockComp =
+ static_cast<MockEmbeddedCompositorCompositor *>(data);
+ Compositor *comp = mockComp->compositor;
+
+ ds_inf("%s: mockComp(%p)", __func__, mockComp);
+
+ // new surface listener
+ mockComp->mNewSurfaceListener.notify =
+ MockEmbeddedCompositorCompositor::NewSurfaceCallback;
+ mockComp->mNewSurfaceListener.parent = mockComp;
+ ds_compositor_add_new_surface_listener(comp->compositor,
+ &mockComp->mNewSurfaceListener);
+
+ mockComp->mEmbeddedCompositor =
+ ds_tizen_embedded_compositor_create(comp->display);
+
+ // destroy listener
+ mockComp->mDestroyListener.notify =
+ MockEmbeddedCompositorCompositor::DestroyCallback;
+ mockComp->mDestroyListener.parent = mockComp;
+ ds_tizen_embedded_compositor_add_destroy_listener(mockComp->mEmbeddedCompositor,
+ &mockComp->mDestroyListener);
+ }
+
+ static void NewSurfaceCallback(struct wl_listener *listener, void *data)
+ {
+ MockEmbeddedCompositorCompositor *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 =
+ MockEmbeddedCompositorCompositor::DelSurfaceCallback;
+ mockComp->mDelSurfaceListener.parent = mockComp;
+ ds_surface_add_destroy_listener(surface,
+ &mockComp->mDelSurfaceListener);
+ }
+
+ static void DelSurfaceCallback(struct wl_listener *listener, void *data)
+ {
+ MockEmbeddedCompositorCompositor *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__);
+
+ MockEmbeddedCompositorCompositor *mockComp =
+ reinterpret_cast<DestroyListener *>(listener)->parent;
+
+ mockComp->bDestroyed = true;
+ }
+
+public:
+ bool bSurfaceDestroyed;
+ bool bDestroyed;
+
+private:
+ struct ds_surface *mSurface;
+
+ struct NewSurfaceListener : ::wl_listener {
+ MockEmbeddedCompositorCompositor *parent;
+ };
+ NewSurfaceListener mNewSurfaceListener;
+
+ struct DelSurfaceListener : ::wl_listener {
+ MockEmbeddedCompositorCompositor *parent;
+ };
+ DelSurfaceListener mDelSurfaceListener;
+
+ struct ds_tizen_embedded_compositor *mEmbeddedCompositor;
+
+ struct DestroyListener : ::wl_listener {
+ MockEmbeddedCompositorCompositor *parent;
+ };
+ DestroyListener mDestroyListener;
+};
+
+class MockEmbeddedCompositorClient : public MockClient
+{
+public:
+ MockEmbeddedCompositorClient()
+ : bSocketEvent(false),
+ socket_fd(-1),
+ compositor_res(nullptr),
+ tizen_embedded_compositor(nullptr)
+ {}
+ MockEmbeddedCompositorClient(const struct wl_registry_listener *listener)
+ : MockClient(listener, this)
+ {
+ ds_inf("%s", __func__);
+
+ bSocketEvent = false;
+ socket_fd = -1;
+ }
+ ~MockEmbeddedCompositorClient()
+ {
+ 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 SetTizenEmbeddedCompositor(struct tizen_embedded_compositor *global_res)
+ {
+ ds_inf("%s", __func__);
+
+ tizen_embedded_compositor = global_res;
+ }
+
+ struct tizen_embedded_compositor *GetTizenEmbeddedCompositor()
+ {
+ ds_inf("%s", __func__);
+
+ return tizen_embedded_compositor;
+ }
+
+public:
+ bool bSocketEvent;
+ int32_t socket_fd;
+
+private:
+ struct wl_compositor *compositor_res;
+ struct tizen_embedded_compositor *tizen_embedded_compositor;
+};
+
+static void
+client_tizen_embedded_compositor_cb_socket(void *data,
+ struct tizen_embedded_compositor *embedded_compositor, int32_t socket_fd)
+{
+ ds_inf("%s", __func__);
+
+ MockEmbeddedCompositorClient *client = static_cast<MockEmbeddedCompositorClient *>(data);
+
+ client->bSocketEvent = true;
+ client->socket_fd = socket_fd;
+}
+
+static const struct tizen_embedded_compositor_listener embedded_compositor_cb_listener = {
+ .socket = client_tizen_embedded_compositor_cb_socket,
+};
+
+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__);
+
+ MockEmbeddedCompositorClient *client = static_cast<MockEmbeddedCompositorClient *>(data);
+ struct wl_compositor *compositor_res;
+ struct tizen_embedded_compositor *embedded_compositor_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_embedded_compositor")) {
+ embedded_compositor_res = (struct tizen_embedded_compositor *)wl_registry_bind(registry,
+ name, &tizen_embedded_compositor_interface, TIZEN_EMBEDDED_COMPOSITOR_VERSION);
+ if (embedded_compositor_res == nullptr) {
+ ds_err("wl_registry_bind() failed. tizen_embedded_compositor resource.");
+ return;
+ }
+ client->SetTizenEmbeddedCompositor(embedded_compositor_res);
+
+ tizen_embedded_compositor_add_listener(embedded_compositor_res,
+ &embedded_compositor_cb_listener, client);
+ }
+}
+
+static void
+client_registry_cb_global_remove(void *data, struct wl_registry *registry,
+ uint32_t name)
+{
+ ds_inf("%s", __func__);
+
+ MockEmbeddedCompositorClient *client = static_cast<MockEmbeddedCompositorClient *>(data);
+ struct wl_compositor *compositor_res = client->GetWlCompositor();
+ struct tizen_embedded_compositor *embedded_compositor_res = client->GetTizenEmbeddedCompositor();
+
+ tizen_embedded_compositor_destroy(embedded_compositor_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 EmbeddedCompositorTest : public ::testing::Test
+{
+public:
+ void SetUp(void) override;
+ void TearDown(void) override;
+
+ MockEmbeddedCompositorCompositor *comp;
+ MockEmbeddedCompositorClient *client;
+ struct wl_compositor *compositor_res;
+ struct tizen_embedded_compositor *embedded_compositor_res;
+ struct wl_surface *surface_res;
+};
+
+void
+EmbeddedCompositorTest::SetUp(void)
+{
+ //ds_log_init(DS_DBG, NULL);
+
+ ds_inf("%s", __func__);
+
+ comp = new MockEmbeddedCompositorCompositor();
+ client = new MockEmbeddedCompositorClient(®istry_listener);
+ compositor_res = client->GetWlCompositor();
+ embedded_compositor_res = client->GetTizenEmbeddedCompositor();
+ surface_res = wl_compositor_create_surface(compositor_res);
+
+ client->RoundTrip();
+}
+
+void
+EmbeddedCompositorTest::TearDown(void)
+{
+ ds_inf("%s", __func__);
+
+ wl_surface_destroy(surface_res);
+ client->RoundTrip();
+ EXPECT_TRUE(comp->bSurfaceDestroyed);
+
+ delete client;
+ delete comp;
+}
+
+TEST_F(EmbeddedCompositorTest, Create_P)
+{
+ EXPECT_TRUE(true);
+}
+
+TEST_F(EmbeddedCompositorTest, Ev_GetSocket)
+{
+ tizen_embedded_compositor_get_socket(embedded_compositor_res);
+ client->RoundTrip();
+
+ comp->Process();
+ EXPECT_TRUE(client->bSocketEvent);
+ EXPECT_TRUE(client->socket_fd >= 0)
+ << "get socket_fd : " << client->socket_fd << std::endl;
+}