gtest: add the first code for TCT 74/169374/3
authorSangjin Lee <lsj119@samsung.com>
Tue, 6 Feb 2018 07:54:02 +0000 (16:54 +0900)
committerchangyeon lee <cyeon.lee@samsung.com>
Thu, 8 Feb 2018 07:06:56 +0000 (07:06 +0000)
Change-Id: I729a0773c2a367c021881e89ffa0634fa6616dbd

Makefile.am
configure.ac
packaging/libwayland-tbm.spec
protocol/wayland-tbm-test.xml [new file with mode: 0644]
utests/Makefile.am [new file with mode: 0644]
utests/src/ut_base.cpp [new file with mode: 0644]
utests/src/ut_base.h [new file with mode: 0644]
utests/src/ut_main.cpp [new file with mode: 0644]
utests/src/ut_wayland_tbm.cpp [new file with mode: 0644]

index 241a644..1c6b3c7 100644 (file)
@@ -1,6 +1,10 @@
 MAINTAINERCLEANFILES = Makefile.in
 
+if HAVE_UTEST
+SUBDIRS = src tool utests
+else
 SUBDIRS = src tool
+endif
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = \
index e34de7a..9a7c0a6 100644 (file)
@@ -8,8 +8,15 @@ AM_SILENT_RULES([yes])
 
 # Checks for programs.
 AC_PROG_CC
+AC_PROG_CXX
 AC_PROG_LIBTOOL
 
+AC_ARG_WITH(utests, AS_HELP_STRING([--with-utests=yes/no], [whether build/run unit tests or not]),
+                               [ utests="$withval" ],
+                               [ utests="no" ])
+
+AM_CONDITIONAL(HAVE_UTEST, test "x$utests" = "xyes")
+
 AC_PATH_PROG([wayland_scanner], [wayland-scanner])
 if test x$wayland_scanner = x; then
       AC_MSG_ERROR([wayland-scanner is needed to compile wayland-tbm])
@@ -25,6 +32,7 @@ AC_CONFIG_FILES([
     src/Makefile
     test/Makefile
     tool/Makefile
+    utests/Makefile
        wayland-tbm-server.pc
        wayland-tbm-client.pc
 ])
index a73ab96..ed63bf9 100644 (file)
@@ -1,3 +1,5 @@
+%define UTEST_PACKAGE 1
+
 Name:          libwayland-tbm
 Version:       0.3.2
 Release:       0
@@ -15,6 +17,7 @@ BuildRequires:  pkgconfig(wayland-server)
 BuildRequires:  pkgconfig(wayland-client)
 BuildRequires:  pkgconfig(libtbm)
 BuildRequires:  pkgconfig(dlog)
+BuildRequires:  gtest-devel
 
 %description
 Wayland TBM Protocol for TIZEN
@@ -46,6 +49,14 @@ Requires:   pkgconfig(libtbm)
 %description devel
 Development header files for use with Wayland protocol
 
+%if "%{UTEST_PACKAGE}" == "1"
+%package utests
+Summary:    Wayland TBM unit test package
+Group:         Graphics & UI Framework/Wayland Window System
+%description utests
+Test module for testing wayland-tbm APIs
+%endif
+
 %global TZ_SYS_RO_SHARE  %{?TZ_SYS_RO_SHARE:%TZ_SYS_RO_SHARE}%{!?TZ_SYS_RO_SHARE:/usr/share}
 
 %prep
@@ -53,7 +64,15 @@ Development header files for use with Wayland protocol
 cp %{SOURCE1001} .
 
 %build
-%reconfigure CFLAGS="${CFLAGS} -Wall -Werror" \
+UTEST="no"
+
+%if "%{UTEST_PACKAGE}" == "1"
+UTEST="yes"
+%endif
+
+%reconfigure --with-utests=${UTEST} \
+             CFLAGS="${CFLAGS} -Wall -Werror" \
+             CXXFLAGS="${CXXFLAGS} -Wall -Werror" \
              LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--as-needed"
 
 make %{?_smp_mflags}
@@ -89,4 +108,10 @@ rm -rf %{buildroot}
 %_libdir/pkgconfig/wayland-tbm*.pc
 %doc README TODO
 
+%if "%{UTEST_PACKAGE}" == "1"
+%files utests
+%defattr(-,root,root,-)
+%{_bindir}/wayland-tbm-utests
+%endif
+
 %changelog
diff --git a/protocol/wayland-tbm-test.xml b/protocol/wayland-tbm-test.xml
new file mode 100644 (file)
index 0000000..5d4e2eb
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="tbm_test">
+
+  <copyright>
+    Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+
+    Permission to use, copy, modify, distribute, and sell this
+    software and its documentation for any purpose is hereby granted
+    without fee, provided that\n the above copyright notice appear in
+    all copies and that both that copyright notice and this permission
+    notice appear in supporting documentation, and that the name of
+    the copyright holders not be used in advertising or publicity
+    pertaining to distribution of the software without specific,
+    written prior permission.  The copyright holders make no
+    representations about the suitability of this software for any
+    purpose.  It is provided "as is" without express or implied
+    warranty.
+
+    THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+    SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+    FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+    SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+    AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+    ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+    THIS SOFTWARE.
+  </copyright>
+
+  <interface name="wl_tbm_test" version="1">
+    <enum name="error">
+      <entry name="invalid_object" value="1"/>
+    </enum>
+
+    <request name="destroy" type="destructor"/>
+    <request name="create_surface">
+      <arg name="surface" type="new_id" interface="wl_tbm_test_surface"/>
+    </request>
+    <request name="set_active">
+      <arg name="surface" type="object" interface="wl_tbm_test_surface"/>
+    </request>
+    <event name="error">
+      <arg name="object_id" type="object" allow-null="true"/>
+      <arg name="code" type="uint" summary="0:success, non-zero:error"/>
+      <arg name="message" type="string" allow-null="true"/>
+    </event>
+  </interface>
+
+  <interface name="wl_tbm_test_surface" version="1">
+    <request name="destroy" type="destructor">
+    </request>
+    <request name="attach">
+      <arg name="buffer" type="object" interface="wl_buffer"/>
+    </request>
+  </interface>
+</protocol>
diff --git a/utests/Makefile.am b/utests/Makefile.am
new file mode 100644 (file)
index 0000000..3dc6317
--- /dev/null
@@ -0,0 +1,49 @@
+bin_PROGRAMS = wayland-tbm-utests
+
+wayland_tbm_utests_SOURCES = \
+       src/ut_main.cpp \
+       src/ut_base.cpp \
+       src/ut_wayland_tbm.cpp \
+       wayland-tbm-test-protocol.c
+
+nodist_include_HEADERS = \
+       wayland-tbm-test-server-protocol.h \
+       wayland-tbm-test-client-protocol.h
+
+wayland_tbm_utests_CXXFLAGS = \
+       $(CXXFLAGS) \
+       $(WL_TBM_COMMON_CFLAGS) \
+       $(WL_TBM_CLIENT_CFLAGS) \
+       $(WL_TBM_SERVER_CFLAGS) \
+       -I../src \
+       -I./src \
+       -I./ \
+       -I$(includedir)/gtest \
+       -fpermissive \
+       -rdynamic \
+       -DFAIL_ON_UNSUPPORTED
+
+# The flag -w is used, because there are many warnings in wayland-tbm sources.
+# Warnings occur because we build project with g++.
+# In C++ we need to use explicit types conversion.
+
+wayland_tbm_utests_LDFLAGS = \
+       ${LDFLAGS} \
+       $(WL_TBM_COMMON_LIBS) \
+       $(WL_TBM_CLIENT_LIBS) \
+       $(WL_TBM_SERVER_LIBS) \
+       $(top_builddir)/src/libwayland-tbm-client.la \
+       $(top_builddir)/src/libwayland-tbm-server.la \
+       -lgtest
+
+%-protocol.c : $(top_srcdir)/protocol/%.xml
+       $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(wayland_scanner) code < $< > $@
+
+%-server-protocol.h : $(top_srcdir)/protocol/%.xml
+       $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(wayland_scanner) server-header < $< > $@
+
+%-client-protocol.h : $(top_srcdir)/protocol/%.xml
+       $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(wayland_scanner) client-header < $< > $@
+
+check:
+       ./wayland-tbm-utests
\ No newline at end of file
diff --git a/utests/src/ut_base.cpp b/utests/src/ut_base.cpp
new file mode 100644 (file)
index 0000000..3aa9c0b
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+Copyright (C) 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact:
+      SooChan Lim <sc1.lim@samsung.com>,
+      Sangjin Lee <lsj119@samsung.com>,
+      Boram Park <boram1288.park@samsung.com>,
+      Changyeon Lee <cyeon.lee@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+*/
+#include "ut_base.h"
+#include "wayland-tbm-server.h"
+#include "wayland-tbm-test-server-protocol.h"
+
+typedef struct
+{
+       struct wl_display *wl_disp;
+       struct wayland_tbm_server *wl_tbm_server;
+       struct wl_global *wl_tbm_test;
+} wlt_server_t;
+
+typedef struct
+{
+       struct wl_resource *test;
+       struct wl_resource *buffer;
+       struct wl_listener buf_destroy_cb;
+} wlt_surface;
+
+wlt_server_t wlt_server;
+
+static void
+_res_wl_tbm_test_buffer_destroy(struct wl_listener *listener, void *data)
+{
+       wlt_surface *wlt_surf = wl_container_of(listener, wlt_surf, buf_destroy_cb);
+       wlt_surf->buffer = nullptr;
+}
+
+static void
+_res_wl_tbm_test_surface_destroy(struct wl_resource *res)
+{
+       wlt_surface *wlt_surf = (wlt_surface *)wl_resource_get_user_data(res);
+       if (wlt_surf->buffer)
+       {
+               wl_list_remove(&wlt_surf->buf_destroy_cb.link);
+       }
+       free(wlt_surf);
+}
+
+static void
+_wl_tbm_test_surface_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+       wl_resource_destroy(resource);
+}
+
+static void
+_wl_tbm_test_surface_attach(struct wl_client *client, struct wl_resource *resource, struct wl_resource *buffer)
+{
+       wlt_surface *wlt_surf = (wlt_surface *)wl_resource_get_user_data(resource);
+       tbm_surface_h tbm_buf;
+
+       if (wlt_surf->buffer == buffer)
+       {
+               wl_tbm_test_send_error(wlt_surf->test, resource, WL_TBM_TEST_ERROR_INVALID_OBJECT, "attach the same buffer");
+               return;
+       }
+
+       tbm_buf = wayland_tbm_server_get_surface(wlt_server.wl_tbm_server, buffer);
+       if (tbm_buf == nullptr)
+       {
+               wl_tbm_test_send_error(wlt_surf->test, resource, WL_TBM_TEST_ERROR_INVALID_OBJECT, "The buffer is invalid");
+               return;
+       }
+
+       if (wlt_surf->buffer)
+       {
+               wl_buffer_send_release(wlt_surf->buffer);
+               wl_list_remove(&wlt_surf->buf_destroy_cb.link);
+       }
+
+       wlt_surf->buffer = buffer;
+       wl_resource_add_destroy_listener(buffer, &wlt_surf->buf_destroy_cb);
+}
+
+static const struct wl_tbm_test_surface_interface wl_tbm_test_surface_impl = {
+       _wl_tbm_test_surface_destroy,
+       _wl_tbm_test_surface_attach};
+
+static void
+_res_wl_tbm_test_destroy(struct wl_resource *res)
+{
+}
+
+static void
+_wl_tbm_test_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+       wl_resource_destroy(resource);
+}
+
+static void
+_wl_tbm_test_create_surface(struct wl_client *client, struct wl_resource *resource, uint32_t surface)
+{
+       struct wl_resource *res;
+       wlt_surface *wlt_surf;
+
+       res = wl_resource_create(client, &wl_tbm_test_surface_interface, 1, surface);
+       if (!res)
+               exit(-1);
+
+       wlt_surf = (wlt_surface *)calloc(1, sizeof(wlt_surface));
+       if (!wlt_surf)
+               exit(-1);
+
+       wlt_surf->test = resource;
+       wlt_surf->buffer = (wl_resource *)nullptr;
+       wlt_surf->buf_destroy_cb.notify = _res_wl_tbm_test_buffer_destroy;
+
+       wl_resource_set_implementation(res, &wl_tbm_test_surface_impl, wlt_surf, _res_wl_tbm_test_surface_destroy);
+}
+
+static void
+_wl_tbm_test_set_active(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface)
+{
+}
+
+static const struct wl_tbm_test_interface wl_tbm_test_impl = {
+       _wl_tbm_test_destroy,
+       _wl_tbm_test_create_surface,
+       _wl_tbm_test_set_active};
+
+static void
+_wl_tbm_test_bind_cb(struct wl_client *client, void *data, uint32_t version, uint32_t id)
+{
+       struct wl_resource *res;
+
+       res = wl_resource_create(client, &wl_tbm_test_interface, version, id);
+       if (!res)
+               exit(-1);
+       wl_resource_set_implementation(res, &wl_tbm_test_impl, data, _res_wl_tbm_test_destroy);
+}
+
+int
+launch_server(void)
+{
+       int pid;
+
+       pid = fork();
+       if (pid != 0)
+               return pid;
+
+       wlt_server.wl_disp = wl_display_create();
+       if (!wlt_server.wl_disp)
+               exit(-1);
+
+       if (wl_display_add_socket(wlt_server.wl_disp, "ut_wayland_tbm"))
+               exit(-1);
+
+       wlt_server.wl_tbm_server = wayland_tbm_server_init(wlt_server.wl_disp, NULL, -1, 0);
+       if (!wlt_server.wl_tbm_server)
+               exit(-1);
+
+       wlt_server.wl_tbm_test = wl_global_create(wlt_server.wl_disp,
+                                                                                         &wl_tbm_test_interface,
+                                                                                         1,
+                                                                                         &wlt_server,
+                                                                                         _wl_tbm_test_bind_cb);
+       if (!wlt_server.wl_tbm_test)
+               exit(-1);
+
+       wl_display_run(wlt_server.wl_disp);
+
+       return pid;
+}
+
+void
+kill_server(int pid)
+{
+       kill(pid, SIGINT);
+}
\ No newline at end of file
diff --git a/utests/src/ut_base.h b/utests/src/ut_base.h
new file mode 100644 (file)
index 0000000..756d4ff
--- /dev/null
@@ -0,0 +1,6 @@
+#define WL_HIDE_DEPRECATED
+#include "gtest/gtest.h"
+
+extern int launch_server(void);
+extern void kill_server(int pid);
+
diff --git a/utests/src/ut_main.cpp b/utests/src/ut_main.cpp
new file mode 100644 (file)
index 0000000..79f8ccb
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+Copyright (C) 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact:
+      SooChan Lim <sc1.lim@samsung.com>,
+      Sangjin Lee <lsj119@samsung.com>,
+      Boram Park <boram1288.park@samsung.com>,
+      Changyeon Lee <cyeon.lee@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+*/
+
+#include "gtest/gtest.h"
+
+int main(int argc, char **argv)
+{
+       try {
+               ::testing::InitGoogleTest(&argc, argv);
+               ::testing::FLAGS_gtest_death_test_style = "fast";
+       } catch ( ... ) {
+               exit(EXIT_FAILURE);
+       }
+
+       return RUN_ALL_TESTS();
+}
\ No newline at end of file
diff --git a/utests/src/ut_wayland_tbm.cpp b/utests/src/ut_wayland_tbm.cpp
new file mode 100644 (file)
index 0000000..cf1a1f2
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+Copyright (C) 2015 Samsung Electronics co., Ltd. All Rights Reserved.
+
+Contact:
+      SooChan Lim <sc1.lim@samsung.com>,
+      Sangjin Lee <lsj119@samsung.com>,
+      Boram Park <boram1288.park@samsung.com>,
+      Changyeon Lee <cyeon.lee@samsung.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice (including the next
+paragraph) shall be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+*/
+#define WL_HIDE_DEPRECATED
+#include "gtest/gtest.h"
+#include "ut_base.h"
+#include "wayland-tbm-client.h"
+#include "wayland-tbm-test-client-protocol.h"
+#include <tbm_surface.h>
+
+class UtWlTbm : public ::testing::Test
+{
+  protected:
+       static void SetUpTestCase();
+       static void TearDownTestCase();
+       void SetUp();
+       void TearDown();
+       int CheckServerError();
+
+  public:
+       static int server_error;
+       static int server_pid;
+       static struct wl_display *wl_disp;
+       static struct wayland_tbm_client *wl_tbm_client;
+       static struct wl_tbm_test *wl_tbm_test;
+
+       static UtWlTbm *resolve(void *data) { return static_cast<UtWlTbm *>(data); }
+       static void wlt_test_error_cb(void *data, struct wl_tbm_test *wl_tbm_test, void *object, uint32_t code, const char *message);
+       static const struct wl_tbm_test_listener wlt_test_listener;
+
+       static void wlt_reg_handle_global_cb(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version);
+       static const struct wl_registry_listener wlt_reg_listener;
+
+       struct wl_tbm_test_surface *create_surface();
+};
+
+int UtWlTbm::server_error = 0;
+int UtWlTbm::server_pid = -1;
+struct wl_display *UtWlTbm::wl_disp = nullptr;
+struct wayland_tbm_client *UtWlTbm::wl_tbm_client = nullptr;
+struct wl_tbm_test *UtWlTbm::wl_tbm_test = nullptr;
+
+const struct wl_tbm_test_listener UtWlTbm::wlt_test_listener = {
+       UtWlTbm::wlt_test_error_cb};
+
+const struct wl_registry_listener UtWlTbm::wlt_reg_listener = {
+       UtWlTbm::wlt_reg_handle_global_cb};
+
+void UtWlTbm::wlt_test_error_cb(void *data,
+                                                               struct wl_tbm_test *wl_tbm_test,
+                                                               void *object, uint32_t code, const char *message)
+{
+       server_error = code;
+       printf("[ERROR: %p(id:%d), err:%d] %s\n", object, ((object) ? wl_proxy_get_id((struct wl_proxy *)object) : -1), code, message);
+}
+
+void UtWlTbm::wlt_reg_handle_global_cb(void *data,
+                                                                          struct wl_registry *registry, uint32_t name,
+                                                                          const char *interface, uint32_t version)
+{
+       if (!strcmp(interface, "wl_tbm_test"))
+       {
+               UtWlTbm::wl_tbm_test = (struct wl_tbm_test *)wl_registry_bind(registry, name, &wl_tbm_test_interface, version);
+               wl_tbm_test_add_listener(UtWlTbm::wl_tbm_test, &wlt_test_listener, data);
+       }
+}
+
+void UtWlTbm::SetUpTestCase()
+{
+       int cnt = 0;
+       struct wl_registry *wl_reg = nullptr;
+
+       server_pid = launch_server();
+       ASSERT_NE(server_pid, -1);
+       sleep(1);
+
+       do
+       {
+               wl_disp = wl_display_connect("ut_wayland_tbm");
+               if (wl_disp == nullptr)
+               {
+                       sleep(1);
+                       printf("Wait... connect to server\n");
+               }
+       } while (wl_disp == nullptr && cnt++ < 10);
+       ASSERT_NE(wl_disp, nullptr);
+
+       wl_tbm_client = wayland_tbm_client_init(wl_disp);
+       ASSERT_NE(wl_tbm_client, nullptr);
+
+       wl_reg = wl_display_get_registry(wl_disp);
+       wl_registry_add_listener(wl_reg, &UtWlTbm::wlt_reg_listener, nullptr);
+       wl_display_roundtrip(wl_disp);
+       wl_registry_destroy(wl_reg);
+}
+
+void UtWlTbm::TearDownTestCase()
+{
+       wayland_tbm_client_deinit(wl_tbm_client);
+       wl_tbm_client = nullptr;
+
+       wl_display_roundtrip(wl_disp);
+       wl_display_disconnect(wl_disp);
+
+       kill_server(server_pid);
+}
+
+void UtWlTbm::SetUp()
+{
+}
+
+void UtWlTbm::TearDown()
+{
+}
+
+int UtWlTbm::CheckServerError()
+{
+       server_error = 0;
+       wl_display_roundtrip(wl_disp);
+
+       return server_error;
+}
+
+struct wl_tbm_test_surface *
+create_surface()
+{
+       return wl_tbm_test_create_surface(UtWlTbm::wl_tbm_test);
+}
+
+TEST_F(UtWlTbm, GetBufMgr)
+{
+       void *bufmgr = nullptr;
+       ASSERT_NE(wl_tbm_client, nullptr);
+
+       bufmgr = wayland_tbm_client_get_bufmgr(wl_tbm_client);
+       ASSERT_NE(bufmgr, nullptr);
+}
+
+TEST_F(UtWlTbm, GetBufMgrFail)
+{
+       void *bufmgr = nullptr;
+
+       bufmgr = wayland_tbm_client_get_bufmgr(nullptr);
+       ASSERT_EQ(bufmgr, nullptr);
+}
+
+TEST_F(UtWlTbm, BufCreate)
+{
+       tbm_surface_h tbm_surf;
+       struct wl_buffer *wl_buf;
+       int ret;
+
+       tbm_surf = tbm_surface_create(100, 200, TBM_FORMAT_ARGB8888);
+       ASSERT_NE(tbm_surf, nullptr);
+
+       wl_buf = wayland_tbm_client_create_buffer(wl_tbm_client, tbm_surf);
+       wl_display_roundtrip(wl_disp);
+       ASSERT_NE(wl_buf, nullptr);
+
+       wayland_tbm_client_destroy_buffer(wl_tbm_client, wl_buf);
+       wl_display_roundtrip(wl_disp);
+       ret = tbm_surface_destroy(tbm_surf);
+       ASSERT_EQ(ret, TBM_SURFACE_ERROR_NONE);
+}
+
+TEST_F(UtWlTbm, BufAttach)
+{
+       tbm_surface_h tbm_surf;
+       struct wl_buffer *wl_buf;
+       struct wl_tbm_test_surface *wlt_surface;
+       int ret;
+
+       tbm_surf = tbm_surface_create(100, 200, TBM_FORMAT_ARGB8888);
+       ASSERT_NE(tbm_surf, nullptr);
+
+       wl_buf = wayland_tbm_client_create_buffer(wl_tbm_client, tbm_surf);
+       ASSERT_NE(wl_buf, nullptr);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       wlt_surface = wl_tbm_test_create_surface(wl_tbm_test);
+       ASSERT_NE(wlt_surface, nullptr);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       wl_tbm_test_surface_attach(wlt_surface, wl_buf);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       wayland_tbm_client_destroy_buffer(wl_tbm_client, wl_buf);
+       ASSERT_EQ(CheckServerError(), 0);
+
+       ret = tbm_surface_destroy(tbm_surf);
+       ASSERT_EQ(ret, TBM_SURFACE_ERROR_NONE);
+
+       wl_tbm_test_surface_destroy(wlt_surface);
+       ASSERT_EQ(CheckServerError(), 0);
+}
\ No newline at end of file