[libtbm] Move unit tests from ws-testcase and change test framework 84/87684/3
authorKonstantin Drabeniuk <k.drabeniuk@samsung.com>
Fri, 9 Sep 2016 06:22:30 +0000 (09:22 +0300)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 19 Sep 2016 04:18:24 +0000 (21:18 -0700)
1) change unit testing framework (Check to gtest);
2) move unit test from the ws-testcase project to the project libtbm;

Change-Id: Ibad976c45030f02799c211b22db3e65534817233
Signed-off-by: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
16 files changed:
Makefile.am
configure.ac
packaging/libtbm.spec
ut/Makefile.am [new file with mode: 0644]
ut/src/main_tests.cpp [new file with mode: 0644]
ut/src/stubs.h [new file with mode: 0644]
ut/src/ut_tbm_bufmgr.cpp [new file with mode: 0644]
ut/src/ut_tbm_bufmgr.h [new file with mode: 0644]
ut/src/ut_tbm_bufmgr_backend.cpp [new file with mode: 0644]
ut/src/ut_tbm_surface.cpp [new file with mode: 0644]
ut/src/ut_tbm_surface_internal.cpp [new file with mode: 0644]
ut/src/ut_tbm_surface_queue.cpp [new file with mode: 0644]
ut/stubs/pthread_stubs.h [new file with mode: 0644]
ut/stubs/stdlib_stubs.cpp [new file with mode: 0644]
ut/stubs/stdlib_stubs.h [new file with mode: 0644]
ut/stubs/tbm_bufmgr_stubs.h [new file with mode: 0644]

index ceb4251d075cb2621126455bfb1dd86554ee3d4c..feda427314f594047fe176a2c0ca948a6241b7fc 100644 (file)
@@ -1,4 +1,9 @@
+
+if HAVE_UTEST
+SUBDIRS = src ut
+else
 SUBDIRS = src
+endif
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libtbm.pc
index 5fc20b91c5f7ba34c1d676c7afe8c7fcb4739a7e..ac0d46f6ad70bb4f58c46144bbba6e1574558fd7 100644 (file)
@@ -28,6 +28,7 @@ AM_CONFIG_HEADER([config.h])
 AC_DISABLE_STATIC
 AC_PROG_LIBTOOL
 AC_PROG_CC
+AC_PROG_CXX
 
 AC_HEADER_STDC
 AC_SYS_LARGEFILE
@@ -50,6 +51,12 @@ AC_ARG_WITH(bufmgr-module-path, AS_HELP_STRING([--with-bufmgr-module-path=PATH],
                                [ BUFMGR_MODULE_PATH="$withval" ],
                                [ BUFMGR_MODULE_PATH="${DEFAULT_BUFMGR_MODULE_PATH}" ])
 
+AC_ARG_WITH(utest, AS_HELP_STRING([--with-utest=yes/no], [whether build/run unit tests or not]),
+                               [ utest="$withval" ],
+                               [ utest="no" ])
+
+AM_CONDITIONAL(HAVE_UTEST, test "x$utest" = "xyes")
+
 #AC_DEFINE(BUFMGR_MODULE_DIR, "${BUFMGR_MODULE_PATH}", [Directory for the modules of tbm_bufmgr])
 AC_DEFINE_UNQUOTED(BUFMGR_MODULE_DIR, "${BUFMGR_MODULE_PATH}", [Directory for the modules of tbm_bufmgr])
 
@@ -103,7 +110,8 @@ AM_CONDITIONAL(HOST_CPU_X86_64, test "x$HOST_CPU_X86_64" = "xyes")
 AC_OUTPUT([
    src/Makefile
        Makefile
-       libtbm.pc])
+       libtbm.pc
+       ut/Makefile])
 
 echo ""
 echo "CFLAGS            : $CFLAGS"
index 4166cd2d9b484a34aae2c42a7f34c56a3f88cda0..3c513300bee0dfe76c97c5add6666ed421ac82fc 100644 (file)
@@ -1,5 +1,6 @@
 %bcond_with x
 %bcond_with wayland
+%bcond_with utest
 
 Name:           libtbm
 Version:        2.0.1
@@ -17,6 +18,10 @@ BuildRequires:  pkgconfig(capi-base-common)
 BuildRequires:  pkgconfig(libpng)
 BuildRequires:  pkgconfig(dlog)
 
+%if %{with utest}
+BuildRequires:  gtest-devel
+%endif
+
 %description
 Description: %{summary}
 
@@ -38,17 +43,26 @@ Development Files.
 cp %{SOURCE1001} .
 
 %build
+UTEST="no"
+
+%if %{with utest}
+UTEST="yes"
+%endif
 
 %if %{with wayland}
-%reconfigure --prefix=%{_prefix} --with-tbm-platform=WAYLAND \
+%reconfigure --prefix=%{_prefix} --with-tbm-platform=WAYLAND  --with-utest=${UTEST} \
             CFLAGS="${CFLAGS} -Wall -Werror" LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--as-needed"
 %else
-%reconfigure --prefix=%{_prefix} --with-tbm-platform=X11 \
+%reconfigure --prefix=%{_prefix} --with-tbm-platform=X11  --with-utest=${UTEST} \
             CFLAGS="${CFLAGS} -Wall -Werror" LDFLAGS="${LDFLAGS} -Wl,--hash-style=both -Wl,--as-needed"
 %endif
 
 make %{?_smp_mflags}
 
+%if %{with utest}
+make -C ut check
+%endif
+
 %install
 rm -rf %{buildroot}
 mkdir -p %{buildroot}/%{TZ_SYS_RO_SHARE}/license
@@ -97,6 +111,9 @@ rm -f %{_unitdir_user}/default.target.wants/tbm-drm-auth-user.path
 %{_unitdir}/tbm-drm-auth.service
 %{_unitdir_user}/tbm-drm-auth-user.path
 %{_unitdir_user}/tbm-drm-auth-user.service
+%if %{with utest}
+%{_bindir}/ut
+%endif
 
 %files devel
 %manifest %{name}.manifest
diff --git a/ut/Makefile.am b/ut/Makefile.am
new file mode 100644 (file)
index 0000000..9a005cc
--- /dev/null
@@ -0,0 +1,28 @@
+bin_PROGRAMS = ut
+
+ut_SOURCES = \
+       src/main_tests.cpp \
+       src/ut_tbm_bufmgr.cpp \
+       src/ut_tbm_bufmgr_backend.cpp \
+       src/ut_tbm_surface.cpp \
+       src/ut_tbm_surface_queue.cpp \
+       src/ut_tbm_surface_internal.cpp \
+       stubs/stdlib_stubs.cpp
+
+ut_CXXFLAGS = \
+       ${CXXFLAGS} \
+       @LIBTBM_CFLAGS@ \
+       -I./stubs \
+       -I./src \
+       -I../src \
+       -fpermissive
+
+ut_LDFLAGS = \
+       ${LDFLAGS} \
+       @LIBTBM_LIBS@ \
+       -lgtest \
+       -ldl \
+       -pthread
+
+check:
+       ./ut
diff --git a/ut/src/main_tests.cpp b/ut/src/main_tests.cpp
new file mode 100644 (file)
index 0000000..8c6a682
--- /dev/null
@@ -0,0 +1,39 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+int main(int argc, char **argv)
+{
+       ::testing::InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
diff --git a/ut/src/stubs.h b/ut/src/stubs.h
new file mode 100644 (file)
index 0000000..3b15f7e
--- /dev/null
@@ -0,0 +1,139 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
+ *
+**************************************************************************/
+
+#ifndef _STUBS_H
+#define _STUBS_H
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "tbm_bufmgr_tgl.h"
+
+#define IOCTL_FD_ERROR_NONE 1
+#define IOCTL_FD_ERROR 2
+#define IOCTL_FD_GET 3
+
+FILE g_file;
+FILE g_error_file;
+int CALLOC_ERROR;
+int free_called;
+int DLOPEN_ERROR;
+
+int ut_fclose(FILE *stream)
+{
+       return 0;
+}
+
+FILE *ut_fopen(const char *filename, const char *mode)
+{
+       if (!filename || !mode) {
+               return NULL;
+       }
+
+       if (!strcmp(filename, "/proc/111/cmdline")) {
+               return NULL;
+       }
+
+       if (!strcmp(filename, "/proc/222/cmdline")) {
+               return &g_error_file;
+       }
+
+       return &g_file;
+}
+
+char *ut_fgets(char *str, int num, FILE *stream)
+{
+       if (!str || num < 1 || !stream) {
+               return NULL;
+       }
+
+       if (stream == &g_error_file) {
+               return NULL;
+       }
+
+       strncpy(str, "application", 255);
+
+       return "application";
+}
+
+int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+       return 0;
+}
+
+int dup2(int old_handle, int new_handle)
+{
+       if (old_handle == new_handle) {
+               return -1;
+       }
+       return 0;
+}
+
+int dup(int handle)
+{
+       if (1 == handle) {
+               return -1;
+       }
+       return 0;
+}
+
+int ioctl(int fd, unsigned long int request, ...)
+{
+       if (IOCTL_FD_ERROR == fd) {
+               return 1;
+       }
+
+       if (IOCTL_FD_GET == fd) {
+               va_list argList;
+               va_start(argList, request);
+               struct tgl_user_data *arg = va_arg(argList, struct tgl_user_data *);
+               arg->data1 = 1;
+               arg->locked = 1;
+               va_end(argList);
+       }
+
+       return 0;
+}
+
+void *ut_calloc(size_t nmemb, size_t size)
+{
+       if (CALLOC_ERROR) {
+               return NULL;
+       }
+
+       return calloc(nmemb, size);
+}
+
+void ut_free(void *ptr)
+{
+       free_called = 1;
+       free(ptr);
+}
+
+#endif /* _STUBS_H */
diff --git a/ut/src/ut_tbm_bufmgr.cpp b/ut/src/ut_tbm_bufmgr.cpp
new file mode 100644 (file)
index 0000000..46bf065
--- /dev/null
@@ -0,0 +1,1793 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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"
+
+#include "ut_tbm_bufmgr.h"
+
+#include "pthread_stubs.h"
+#include "stdlib_stubs.h"
+
+#define pthread_mutex_lock ut_pthread_mutex_lock
+#define pthread_mutex_unlock ut_pthread_mutex_unlock
+#define pthread_mutex_init ut_pthread_mutex_init
+#define calloc ut_calloc
+#define free ut_free
+
+#include "tbm_bufmgr.c"
+#include "tbm_bufmgr_stubs.h"
+
+static void _init_test()
+{
+       gBufMgr = NULL;
+       PTHREAD_MUTEX_INIT_ERROR = 0;
+       CALLOC_ERROR = 0;
+       FREE_CALLED = 0;
+       FREE_PTR = NULL;
+       FREE_TESTED_PTR = NULL;
+       free_called_for_tested_ptr = 0;
+       free_call_count = 0;
+       GETENV_ERROR = 0;
+       UT_TBM_ERROR = 0;
+       TBM_BO_ALLOC_ERROR = 0;
+       TBM_BO_IMPORT_ERROR = 0;
+       bo_ret_flags = TBM_BO_SCANOUT;
+}
+
+/* tbm_bufmgr_bind_native_display() */
+
+TEST(tbm_bufmgr_bind_native_display, work_flow_success_3)
+{
+       int expected = 1;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       int actual;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       backend.bufmgr_bind_native_display = ut_bufmgr_bind_native_display;
+
+       actual = tbm_bufmgr_bind_native_display(&bufmgr, NULL);
+
+       ASSERT_EQ(expected, actual);
+}
+
+TEST(tbm_bufmgr_bind_native_display, work_flow_success_2)
+{
+       int expected = 0;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       int actual;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       backend.bufmgr_bind_native_display = ut_bufmgr_bind_native_display;
+       UT_TBM_ERROR = 1;
+
+       actual = tbm_bufmgr_bind_native_display(&bufmgr, NULL);
+
+       ASSERT_EQ(expected, actual);
+}
+
+TEST(tbm_bufmgr_bind_native_display, work_flow_success_1)
+{
+       int expected = 1;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       int actual;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       backend.bufmgr_bind_native_display = NULL;
+
+       actual = tbm_bufmgr_bind_native_display(&bufmgr, NULL);
+
+       ASSERT_EQ(expected, actual);
+}
+
+TEST(tbm_bufmgr_bind_native_display, null_ptr_fail_1)
+{
+       int expected = 0;
+       int actual;
+
+       _init_test();
+
+       actual = tbm_bufmgr_bind_native_display(NULL, NULL);
+
+       ASSERT_EQ(expected, actual);
+}
+
+/* tbm_bo_get_flags() */
+
+TEST(tbm_bo_get_flags, work_flow_success_2)
+{
+       int expected_flags = 5;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual_flags;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.flags = expected_flags;
+
+       actual_flags = tbm_bo_get_flags(&bo);
+
+       ASSERT_EQ(actual_flags, expected_flags);
+}
+
+TEST(tbm_bo_get_flags, work_flow_success_1)
+{
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_get_flags(&bo);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_get_flags, null_ptr_fail_1)
+{
+       int expected = 0;
+       int actual;
+
+       _init_test();
+
+       actual = tbm_bo_get_flags(NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+
+/* tbm_bufmgr_get_capability() */
+
+TEST(tbm_bufmgr_get_capability, work_flow_success_3)
+{
+       unsigned int capability = TBM_BUFMGR_CAPABILITY_NONE;
+       unsigned int expected_capability = TBM_BUFMGR_CAPABILITY_SHARE_FD;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       backend.bo_import = NULL;
+       backend.bo_export = NULL;
+       backend.bo_import_fd = ut_bo_import_fd;
+       backend.bo_export_fd = ut_bo_export_fd;
+
+       capability = tbm_bufmgr_get_capability(&bufmgr);
+
+       ASSERT_EQ(capability, expected_capability);
+}
+
+TEST(tbm_bufmgr_get_capability, work_flow_success_2)
+{
+       unsigned int capability = TBM_BUFMGR_CAPABILITY_NONE;
+       unsigned int expected_capability = TBM_BUFMGR_CAPABILITY_SHARE_KEY;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       backend.bo_import = ut_bo_import;
+       backend.bo_export = ut_bo_export;
+       backend.bo_import_fd = NULL;
+       backend.bo_export_fd = NULL;
+
+       capability = tbm_bufmgr_get_capability(&bufmgr);
+
+       ASSERT_EQ(capability, expected_capability);
+}
+
+TEST(tbm_bufmgr_get_capability, work_flow_success_1)
+{
+       unsigned int capability = TBM_BUFMGR_CAPABILITY_SHARE_KEY;
+       unsigned int expected_capability = TBM_BUFMGR_CAPABILITY_NONE;
+
+       _init_test();
+
+       capability = tbm_bufmgr_get_capability(NULL);
+
+       ASSERT_EQ(capability, expected_capability);
+}
+
+/* tbm_get_last_error() */
+
+TEST(tbm_get_last_error, work_flow_success_1)
+{
+       tbm_last_error = TBM_BO_ERROR_GET_FD_FAILED;
+       tbm_error_e expected_error = tbm_last_error;
+
+       _init_test();
+
+       tbm_error_e error = tbm_get_last_error();
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_bo_delete_user_data() */
+
+TEST(tbm_bo_delete_user_data, work_flow_success_4)
+{
+       unsigned int key = 5;
+       int expected = 1;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int expected_data;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       LIST_INITHEAD(&bo.user_data_list);
+       tbm_user_data *user_data = calloc(1, sizeof(tbm_user_data));
+       user_data->data = &expected_data;
+       user_data->key = key;
+       user_data->free_func = NULL;
+       LIST_INITHEAD(&bo.user_data_list);
+       LIST_ADD(&user_data->item_link, &bo.user_data_list);
+       FREE_TESTED_PTR = user_data;
+
+       actual = tbm_bo_delete_user_data(&bo, key);
+
+       ASSERT_EQ(actual, expected);
+       ASSERT_EQ(free_called_for_tested_ptr, 1);
+}
+
+TEST(tbm_bo_delete_user_data, work_flow_success_3)
+{
+       unsigned int key = 5;
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int expected_data;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       LIST_INITHEAD(&bo.user_data_list);
+       tbm_user_data user_data;
+       user_data.data = &expected_data;
+       user_data.key = key - 1;
+       LIST_INITHEAD(&bo.user_data_list);
+       LIST_ADD(&user_data.item_link, &bo.user_data_list);
+
+       actual = tbm_bo_delete_user_data(&bo, key);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_delete_user_data, work_flow_success_2)
+{
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       LIST_INITHEAD(&bo.user_data_list);
+
+       actual = tbm_bo_delete_user_data(&bo, 1);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_delete_user_data, work_flow_success_1)
+{
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_delete_user_data(&bo, 1);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_delete_user_data, null_ptr_fail_1)
+{
+       int expected = 0;
+       int actual;
+
+       _init_test();
+
+       actual = tbm_bo_delete_user_data(NULL, 1);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_bo_get_user_data() */
+
+TEST(tbm_bo_get_user_data, work_flow_success_5)
+{
+       unsigned int key = 5;
+       void *data;
+       int expected = 1;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int expected_data;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       LIST_INITHEAD(&bo.user_data_list);
+       tbm_user_data user_data;
+       user_data.data = &expected_data;
+       user_data.key = key;
+       LIST_INITHEAD(&bo.user_data_list);
+       LIST_ADD(&user_data.item_link, &bo.user_data_list);
+
+       actual = tbm_bo_get_user_data(&bo, key, &data);
+
+       ASSERT_EQ(actual, expected);
+       ASSERT_TRUE(data == &expected_data);
+}
+
+TEST(tbm_bo_get_user_data, work_flow_success_4)
+{
+       unsigned int key = 5;
+       void *data;
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int expected_data;
+       tbm_user_data user_data;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       LIST_INITHEAD(&bo.user_data_list);
+       user_data.data = &expected_data;
+       user_data.key = key - 1;
+       LIST_INITHEAD(&bo.user_data_list);
+       LIST_ADD(&user_data.item_link, &bo.user_data_list);
+
+       actual = tbm_bo_get_user_data(&bo, key, &data);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_get_user_data, work_flow_success_3)
+{
+       void *data;
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       LIST_INITHEAD(&bo.user_data_list);
+
+       actual = tbm_bo_get_user_data(&bo, 1, &data);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_get_user_data, work_flow_success_2)
+{
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_get_user_data(&bo, 1, NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_get_user_data, work_flow_success_1)
+{
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_get_user_data(&bo, 1, NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_get_user_data, null_ptr_fail_1)
+{
+       int expected = 0;
+       int actual;
+
+       _init_test();
+
+       actual = tbm_bo_get_user_data(NULL, 1, NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_bo_set_user_data() */
+
+TEST(tbm_bo_set_user_data, work_flow_success_3)
+{
+       unsigned int key = 5;
+       int expected = 1;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int data, actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       tbm_user_data user_data;
+       user_data.data = NULL;
+       user_data.free_func = NULL;
+       user_data.key = key;
+       LIST_INITHEAD(&bo.user_data_list);
+       LIST_ADD(&user_data.item_link, &bo.user_data_list);
+
+       actual = tbm_bo_set_user_data(&bo, key, &data);
+
+       ASSERT_EQ(actual, expected);
+       ASSERT_TRUE(user_data.data == &data);
+}
+
+TEST(tbm_bo_set_user_data, work_flow_success_2)
+{
+       unsigned int key = 5;
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       tbm_user_data user_data;
+       user_data.key = key - 1;
+       LIST_INITHEAD(&bo.user_data_list);
+       LIST_ADD(&user_data.item_link, &bo.user_data_list);
+
+       actual = tbm_bo_set_user_data(&bo, key, NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_set_user_data, work_flow_success_1)
+{
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_set_user_data(&bo, 1, NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_set_user_data, null_ptr_fail_1)
+{
+       int expected = 0;
+       int actual;
+
+       _init_test();
+
+       actual = tbm_bo_set_user_data(NULL, 1, NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_bo_add_user_data() */
+
+TEST(tbm_bo_add_user_data, work_flow_success_4)
+{
+       tbm_user_data *data = NULL;
+       unsigned long key = 5;
+       int expected = 1;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       tbm_user_data user_data;
+       user_data.key = key - 1;
+       LIST_INITHEAD(&bo.user_data_list);
+       LIST_ADD(&user_data.item_link, &bo.user_data_list);
+
+       actual = tbm_bo_add_user_data(&bo, key, ut_tbm_data_free);
+
+       ASSERT_EQ(actual, expected);
+       data = user_data_lookup(&bo.user_data_list, key);
+       ASSERT_TRUE(data != NULL);
+       tbm_user_data copy_data = *data;
+       free(data);
+       ASSERT_EQ(copy_data.key, key);
+       ASSERT_TRUE(copy_data.free_func == ut_tbm_data_free);
+       ASSERT_TRUE(copy_data.data == NULL);
+}
+
+TEST(tbm_bo_add_user_data, work_flow_success_3)
+{
+       unsigned long key = 5;
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       tbm_user_data user_data;
+       user_data.key = key - 1;
+       LIST_INITHEAD(&bo.user_data_list);
+       LIST_ADD(&user_data.item_link, &bo.user_data_list);
+       CALLOC_ERROR = 1;
+
+       actual = tbm_bo_add_user_data(&bo, key, NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_add_user_data, work_flow_success_2)
+{
+       unsigned long key = 5;
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       tbm_user_data user_data;
+       user_data.key = key;
+       LIST_INITHEAD(&bo.user_data_list);
+       LIST_ADD(&user_data.item_link, &bo.user_data_list);
+
+       actual = tbm_bo_add_user_data(&bo, key, NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_add_user_data, work_flow_success_1)
+{
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_add_user_data(&bo, 1, NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_add_user_data, null_ptr_fail_1)
+{
+       int expected = 0;
+       int actual;
+
+       _init_test();
+
+       actual = tbm_bo_add_user_data(NULL, 1, NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_bo_locked() */
+
+TEST(tbm_bo_locked, work_flow_success_4)
+{
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.bufmgr = &bufmgr;
+       bufmgr.lock_type = LOCK_TRY_ONCE;
+       bo.lock_cnt = 0;
+
+       actual = tbm_bo_locked(&bo);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_locked, work_flow_success_3)
+{
+       int expected = 1;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.bufmgr = &bufmgr;
+       bufmgr.lock_type = LOCK_TRY_ONCE;
+       bo.lock_cnt = 10;
+
+       actual = tbm_bo_locked(&bo);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_locked, work_flow_success_2)
+{
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.bufmgr = &bufmgr;
+       bufmgr.lock_type = LOCK_TRY_NEVER;
+
+       actual = tbm_bo_locked(&bo);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_locked, work_flow_success_1)
+{
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_locked(&bo);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_locked, null_ptr_fail_1)
+{
+       int expected = 0;
+       int actual;
+
+       _init_test();
+
+       actual = tbm_bo_locked(NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_bo_swap() */
+
+TEST(tbm_bo_swap, work_flow_success_4)
+{
+       int priv1 = 10;
+       int priv2 = 20;
+       int expected = 1;
+       struct _tbm_bo bo1;
+       struct _tbm_bo bo2;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr bufmgr2;
+       struct _tbm_bufmgr_backend backend1;
+       struct _tbm_bufmgr_backend backend2;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo1.item_link, &bufmgr.bo_list);
+       LIST_ADD(&bo2.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bufmgr.backend = &backend1;
+       bufmgr2.backend = &backend2;
+       bo1.bufmgr = &bufmgr;
+       bo2.bufmgr = &bufmgr2;
+       backend1.bo_size = ut_bo_size;
+       backend2.bo_size = ut_bo2_size;
+       bo1.priv = &priv1;
+       bo2.priv = &priv2;
+
+       actual = tbm_bo_swap(&bo1, &bo2);
+
+       ASSERT_EQ(actual, expected);
+       ASSERT_TRUE(bo1.priv == &priv2);
+       ASSERT_TRUE(bo2.priv == &priv1);
+}
+
+TEST(tbm_bo_swap, work_flow_success_3)
+{
+       tbm_error_e expected_last_error = TBM_BO_ERROR_SWAP_FAILED;
+       int expected = 0;
+       struct _tbm_bo bo1;
+       struct _tbm_bo bo2;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr bufmgr2;
+       struct _tbm_bufmgr_backend backend1;
+       struct _tbm_bufmgr_backend backend2;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo1.item_link, &bufmgr.bo_list);
+       LIST_ADD(&bo2.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bufmgr.backend = &backend1;
+       bufmgr2.backend = &backend2;
+       bo1.bufmgr = &bufmgr;
+       bo2.bufmgr = &bufmgr2;
+       backend1.bo_size = ut_bo_size;
+       backend2.bo_size = ut_bo2_size;
+       bo2_size = 200;
+
+       actual = tbm_bo_swap(&bo1, &bo2);
+
+       ASSERT_EQ(actual, expected);
+       ASSERT_EQ(tbm_last_error, expected_last_error);
+}
+
+TEST(tbm_bo_swap, work_flow_success_2)
+{
+       int expected = 0;
+       struct _tbm_bo bo1;
+       struct _tbm_bo bo2;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo1.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_swap(&bo1, &bo2);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_swap, work_flow_success_1)
+{
+       int expected = 0;
+       struct _tbm_bo bo1;
+       struct _tbm_bo bo2;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo2.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_swap(&bo1, &bo2);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_swap, null_ptr_fail_2)
+{
+       int expected = 0;
+       struct _tbm_bo bo1;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_swap(&bo1, NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_swap, null_ptr_fail_1)
+{
+       int expected = 0;
+       struct _tbm_bo bo2;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_swap(NULL, &bo2);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_bo_unmap() */
+
+TEST(tbm_bo_unmap_null, work_flow_success_3)
+{
+       int not_expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       backend.bo_unmap = ut_bo_unmap;
+       bufmgr.lock_type = LOCK_TRY_NEVER;
+
+       actual = tbm_bo_unmap(&bo);
+
+       ASSERT_NE(actual, not_expected);
+}
+
+TEST(tbm_bo_unmap_null, work_flow_success_2)
+{
+       tbm_error_e expected_last_error = TBM_BO_ERROR_UNMAP_FAILED;
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       backend.bo_unmap = ut_bo_unmap;
+       UT_TBM_ERROR = 1;
+
+       actual = tbm_bo_unmap(&bo);
+
+       ASSERT_EQ(actual, expected);
+       ASSERT_EQ(tbm_last_error, expected_last_error);
+}
+
+TEST(tbm_bo_unmap_null, work_flow_success_1)
+{
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_unmap(&bo);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_unmap, null_ptr_fail_1)
+{
+       int expected = 0;
+       int actual;
+
+       _init_test();
+
+       actual = tbm_bo_unmap(NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_bo_map() */
+
+TEST(tbm_bo_map, work_flow_success_4)
+{
+       struct _tbm_bo bo;
+       bo.map_cnt = 5;
+       unsigned int expected_map_cnt = bo.map_cnt + 1;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       tbm_bo_handle handle;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bufmgr.lock_type = LOCK_TRY_NEVER;
+       bo.bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       backend.bo_map = ut_bo_map;
+
+       handle = tbm_bo_map(&bo, 1, 1);
+
+       ASSERT_TRUE(handle.ptr != NULL);
+       ASSERT_EQ(bo.map_cnt, expected_map_cnt);
+}
+
+TEST(tbm_bo_map, work_flow_success_3)
+{
+       tbm_error_e expected_last_error = TBM_BO_ERROR_MAP_FAILED;
+       tbm_bo_handle expected_handle;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       tbm_bo_handle handle;
+
+       _init_test();
+
+       expected_handle.ptr = NULL;
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bufmgr.lock_type = LOCK_TRY_NEVER;
+       bo.bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       backend.bo_map = ut_bo_map;
+       UT_TBM_ERROR = 1;
+
+       handle = tbm_bo_map(&bo, 1, 1);
+
+       ASSERT_TRUE(handle.ptr == expected_handle.ptr);
+       ASSERT_EQ(tbm_last_error, expected_last_error);
+}
+
+TEST(tbm_bo_map, work_flow_success_2)
+{
+       tbm_error_e expected_last_error = TBM_BO_ERROR_LOCK_FAILED;
+       tbm_bo_handle expected_handle;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       tbm_bo_handle handle;
+
+       _init_test();
+
+       expected_handle.ptr = NULL;
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bufmgr.lock_type = LOCK_TRY_NEVER + 546;
+       bo.bufmgr = &bufmgr;
+
+       handle = tbm_bo_map(&bo, 1, 1);
+
+       ASSERT_TRUE(handle.ptr == expected_handle.ptr);
+       ASSERT_EQ(tbm_last_error, expected_last_error);
+}
+
+TEST(tbm_bo_map, work_flow_success_1)
+{
+       tbm_bo_handle expected_handle;
+       expected_handle.ptr = NULL;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       tbm_bo_handle handle = tbm_bo_map(&bo, 1, 1);
+
+       ASSERT_TRUE(handle.ptr == expected_handle.ptr);
+}
+
+TEST(tbm_bo_map, null_ptr_fail_1)
+{
+       tbm_bo_handle expected_handle;
+       expected_handle.ptr = NULL;
+       tbm_bo_handle handle;
+
+       _init_test();
+
+       handle = tbm_bo_map(NULL, 1, 1);
+
+       ASSERT_TRUE(handle.ptr == expected_handle.ptr);
+}
+
+/* tbm_bo_get_handle() */
+
+TEST(tbm_bo_get_handle, work_flow_success_3)
+{
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       tbm_bo_handle handle;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       backend.bo_get_handle = ut_bo_get_handle;
+
+       handle = tbm_bo_get_handle(&bo, 1);
+
+       ASSERT_TRUE(handle.ptr != NULL);
+}
+
+TEST(tbm_bo_get_handle, work_flow_success_2)
+{
+       tbm_bo_handle expected_handle;
+       expected_handle.ptr = NULL;
+       tbm_error_e expected_last_result = TBM_BO_ERROR_GET_HANDLE_FAILED;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       backend.bo_get_handle = ut_bo_get_handle;
+       UT_TBM_ERROR = 1;
+
+       tbm_bo_handle handle = tbm_bo_get_handle(&bo, 1);
+
+       ASSERT_TRUE(handle.ptr == expected_handle.ptr);
+       ASSERT_EQ(tbm_last_error, expected_last_result);
+}
+
+TEST(tbm_bo_get_handle, work_flow_success_1)
+{
+       tbm_bo_handle expected_handle;
+       expected_handle.ptr = NULL;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       tbm_bo_handle handle;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       handle = tbm_bo_get_handle(&bo, 1);
+
+       ASSERT_TRUE(handle.ptr == expected_handle.ptr);
+}
+
+TEST(tbm_bo_get_handle, null_ptr_fail_1)
+{
+       tbm_bo_handle expected_handle;
+       expected_handle.ptr = NULL;
+       tbm_bo_handle handle;
+
+       _init_test();
+
+       handle = tbm_bo_get_handle(NULL, 1);
+
+       ASSERT_TRUE(handle.ptr == expected_handle.ptr);
+}
+
+/* tbm_bo_export_fd() */
+
+TEST(tbm_bo_export_fd, work_flow_success_3)
+{
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       int key;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       backend.bo_export_fd = ut_bo_export_fd;
+
+       key = tbm_bo_export_fd(&bo);
+
+       ASSERT_GE(key, 0);
+}
+
+TEST(tbm_bo_export_fd, work_flow_success_2)
+{
+       tbm_error_e expected_last_result = TBM_BO_ERROR_EXPORT_FD_FAILED;
+       int expected_key = -1;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       int key;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       backend.bo_export_fd = ut_bo_export_fd;
+       UT_TBM_ERROR = 1;
+
+       key = tbm_bo_export_fd(&bo);
+
+       ASSERT_EQ(key, expected_key);
+       ASSERT_EQ(tbm_last_error, expected_last_result);
+}
+
+TEST(tbm_bo_export_fd, work_flow_success_1)
+{
+       int expected_key = -1;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int key;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       key = tbm_bo_export_fd(&bo);
+
+       ASSERT_EQ(key, expected_key);
+}
+
+TEST(tbm_bo_export_fd, null_ptr_fail_1)
+{
+       int expected_key = -1;
+       int key;
+
+       _init_test();
+
+       key = tbm_bo_export_fd(NULL);
+
+       ASSERT_EQ(key, expected_key);
+}
+
+/* tbm_bo_export() */
+
+TEST(tbm_bo_export, work_flow_success_3)
+{
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       int key;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       backend.bo_export = ut_bo_export;
+
+       key = tbm_bo_export(&bo);
+
+       ASSERT_GT(key, 0);
+}
+
+TEST(tbm_bo_export, work_flow_success_2)
+{
+       tbm_error_e expected_last_result = TBM_BO_ERROR_EXPORT_FAILED;
+       int expected_key = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       int key;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       backend.bo_export = ut_bo_export;
+       UT_TBM_ERROR = 1;
+
+       key = tbm_bo_export(&bo);
+
+       ASSERT_EQ(key, expected_key);
+       ASSERT_EQ(tbm_last_error, expected_last_result);
+}
+
+TEST(tbm_bo_export, work_flow_success_1)
+{
+       int expected_key = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int key;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       key = tbm_bo_export(&bo);
+
+       ASSERT_EQ(key, expected_key);
+}
+
+TEST(tbm_bo_export, null_ptr_fail_1)
+{
+       int expected_key = 0;
+       int key;
+
+       _init_test();
+
+       key = tbm_bo_export(NULL);
+
+       ASSERT_EQ(key, expected_key);
+}
+
+/* tbm_bo_import_fd() */
+
+TEST(tbm_bo_import_fd, work_flow_success_5)
+{
+       int expected_flags = bo_ret_flags;
+       int expected_ref_cnt = 1;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       struct _tbm_bo *actual_bo;
+       struct _tbm_bo copy_bo;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       bufmgr.bo_cnt = 1;
+       backend.bo_import_fd = ut_bo_import_fd;
+       LIST_INITHEAD(&bufmgr.bo_list);
+       backend.bo_get_flags = ut_bo_get_flags;
+
+       actual_bo = tbm_bo_import_fd(&bufmgr, 1);
+
+       ASSERT_TRUE(actual_bo != NULL);
+       copy_bo = *actual_bo;
+       free(actual_bo);
+       ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
+       ASSERT_EQ(copy_bo.flags, expected_flags);
+       ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
+       ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
+}
+
+TEST(tbm_bo_import_fd, work_flow_success_4)
+{
+       int expected_flags = TBM_BO_DEFAULT;
+       int expected_ref_cnt = 1;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       struct _tbm_bo *actual_bo;
+       struct _tbm_bo copy_bo;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       bufmgr.bo_cnt = 1;
+       backend.bo_import_fd = ut_bo_import_fd;
+       LIST_INITHEAD(&bufmgr.bo_list);
+       backend.bo_get_flags = NULL;
+
+       actual_bo = tbm_bo_import_fd(&bufmgr, 1);
+
+       ASSERT_TRUE(actual_bo != NULL);
+       copy_bo = *actual_bo;
+       free(actual_bo);
+       ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
+       ASSERT_EQ(copy_bo.flags, expected_flags);
+       ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
+       ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
+}
+
+TEST(tbm_bo_import_fd, work_flow_success_3)
+{
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       struct _tbm_bo expected_bo;
+       int expected_ref_cnt;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       bufmgr.bo_cnt = 1;
+       backend.bo_import_fd = ut_bo_import_fd;
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&expected_bo.item_link, &bufmgr.bo_list);
+       expected_bo.priv = ret_bo;
+       expected_bo.ref_cnt = 10;
+       expected_ref_cnt = expected_bo.ref_cnt + 1;
+
+       struct _tbm_bo *actual_bo = tbm_bo_import_fd(&bufmgr, 1);
+
+       ASSERT_TRUE(actual_bo == &expected_bo);
+       ASSERT_EQ(actual_bo->ref_cnt, expected_ref_cnt);
+}
+
+TEST(tbm_bo_import_fd, work_flow_success_2)
+{
+       struct _tbm_bo *expected = NULL;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       bufmgr.bo_cnt = 1;
+       backend.bo_import_fd = ut_bo_import_fd;
+       TBM_BO_IMPORT_ERROR = 1;
+
+       actual = tbm_bo_import_fd(&bufmgr, 1);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+TEST(tbm_bo_import_fd, work_flow_success_1)
+{
+       struct _tbm_bo *expected = NULL;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       CALLOC_ERROR = 1;
+
+       actual = tbm_bo_import_fd(&bufmgr, 1);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+TEST(tbm_bo_import_fd, null_ptr_fail_1)
+{
+       struct _tbm_bo *expected = NULL;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       actual = tbm_bo_import_fd(NULL, 1);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+/* tbm_bo_import() */
+
+TEST(tbm_bo_import, work_flow_success_5)
+{
+       int expected_flags = bo_ret_flags;
+       int expected_ref_cnt = 1;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       struct _tbm_bo *actual_bo;
+       struct _tbm_bo copy_bo;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       bufmgr.bo_cnt = 1;
+       backend.bo_import = ut_bo_import;
+       LIST_INITHEAD(&bufmgr.bo_list);
+       backend.bo_get_flags = ut_bo_get_flags;
+
+       actual_bo = tbm_bo_import(&bufmgr, 1);
+
+       ASSERT_TRUE(actual_bo != NULL);
+       copy_bo = *actual_bo;
+       free(actual_bo);
+       ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
+       ASSERT_EQ(copy_bo.flags, expected_flags);
+       ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
+       ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
+}
+
+TEST(tbm_bo_import, work_flow_success_4)
+{
+       int expected_flags = TBM_BO_DEFAULT;
+       int expected_ref_cnt = 1;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       struct _tbm_bo *actual_bo;
+       struct _tbm_bo copy_bo;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       bufmgr.bo_cnt = 1;
+       backend.bo_import = ut_bo_import;
+       LIST_INITHEAD(&bufmgr.bo_list);
+       backend.bo_get_flags = NULL;
+
+       actual_bo = tbm_bo_import(&bufmgr, 1);
+
+       ASSERT_TRUE(actual_bo != NULL);
+       copy_bo = *actual_bo;
+       free(actual_bo);
+       ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
+       ASSERT_EQ(copy_bo.flags, expected_flags);
+       ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
+       ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
+}
+
+TEST(tbm_bo_import, work_flow_success_3)
+{
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       struct _tbm_bo expected_bo;
+       int expected_ref_cnt;
+       struct _tbm_bo *actual_bo;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       bufmgr.bo_cnt = 1;
+       backend.bo_import = ut_bo_import;
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&expected_bo.item_link, &bufmgr.bo_list);
+       expected_bo.priv = ret_bo;
+       expected_bo.ref_cnt = 10;
+       expected_ref_cnt = expected_bo.ref_cnt + 1;
+
+       actual_bo = tbm_bo_import(&bufmgr, 1);
+
+       ASSERT_TRUE(actual_bo == &expected_bo);
+       ASSERT_EQ(actual_bo->ref_cnt, expected_ref_cnt);
+}
+
+TEST(tbm_bo_import, work_flow_success_2)
+{
+       struct _tbm_bo *expected = NULL;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       bufmgr.bo_cnt = 1;
+       backend.bo_import = ut_bo_import;
+       TBM_BO_IMPORT_ERROR = 1;
+
+       actual = tbm_bo_import(&bufmgr, 1);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+TEST(tbm_bo_import, work_flow_success_1)
+{
+       struct _tbm_bo *expected = NULL;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       CALLOC_ERROR = 1;
+
+       actual = tbm_bo_import(&bufmgr, 1);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+TEST(tbm_bo_import, null_ptr_fail_1)
+{
+       struct _tbm_bo *expected = NULL;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       actual = tbm_bo_import(NULL, 1);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+/* tbm_bo_alloc() */
+
+TEST(tbm_bo_alloc, work_flow_success_3)
+{
+       int flags = 6;
+       int expected_ref_cnt = 1;
+       struct _tbm_bo *not_expected_bo = NULL;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       struct _tbm_bo *actual_bo;
+       struct _tbm_bo copy_bo;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       backend.bo_alloc = ut_bo_alloc;
+       LIST_INITHEAD(&bufmgr.bo_list);
+
+       actual_bo = tbm_bo_alloc(&bufmgr, 1, flags);
+
+       ASSERT_TRUE(actual_bo != not_expected_bo);
+       copy_bo = *actual_bo;
+       free(actual_bo);
+       ASSERT_EQ(copy_bo.flags, flags);
+       ASSERT_EQ(copy_bo.ref_cnt, expected_ref_cnt);
+       ASSERT_TRUE(copy_bo.priv == ret_bo);
+       ASSERT_TRUE(bufmgr.bo_list.next != &bufmgr.bo_list);
+       ASSERT_TRUE(bufmgr.bo_list.prev != &bufmgr.bo_list);
+}
+
+TEST(tbm_bo_alloc, work_flow_success_2)
+{
+       struct _tbm_bo *expected = NULL;
+       tbm_error_e expected_last_error = TBM_BO_ERROR_BO_ALLOC_FAILED;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       backend.bo_alloc = ut_bo_alloc;
+       TBM_BO_ALLOC_ERROR = 1;
+
+       actual = tbm_bo_alloc(&bufmgr, 1, 1);
+
+       ASSERT_TRUE(actual == expected);
+       ASSERT_EQ(tbm_last_error, expected_last_error);
+}
+
+TEST(tbm_bo_alloc, work_flow_success_1)
+{
+       struct _tbm_bo *expected = NULL;
+       struct _tbm_bufmgr bufmgr;
+       tbm_error_e expected_last_error;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       CALLOC_ERROR = 1;
+       expected_last_error = TBM_BO_ERROR_HEAP_ALLOC_FAILED;
+
+       actual = tbm_bo_alloc(&bufmgr, 1, 1);
+
+       ASSERT_TRUE(actual == expected);
+       ASSERT_EQ(tbm_last_error, expected_last_error);
+}
+
+TEST(tbm_bo_alloc, null_int_fail_1)
+{
+       struct _tbm_bo *expected = NULL;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       actual = tbm_bo_alloc(&bufmgr, 0, 1);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+TEST(tbm_bo_alloc, null_ptr_fail_1)
+{
+       struct _tbm_bo *expected = NULL;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       actual = tbm_bo_alloc(NULL, 1, 1);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+/* tbm_bo_unref() */
+
+TEST(tbm_bo_unref, work_flow_success_1)
+{
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int expected_ref_cnt;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.ref_cnt = 10;
+       expected_ref_cnt = bo.ref_cnt - 1;
+
+       tbm_bo_unref(&bo);
+
+       ASSERT_EQ(bo.ref_cnt, expected_ref_cnt);
+}
+
+/* tbm_bo_ref() */
+
+TEST(tbm_bo_ref, work_flow_success_3)
+{
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bo *expected;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       bo.ref_cnt = 1;
+       int expected_ref_cnt = bo.ref_cnt + 1;
+       expected = &bo;
+
+       actual = tbm_bo_ref(&bo);
+
+       ASSERT_TRUE(actual == expected);
+       ASSERT_EQ(bo.ref_cnt, expected_ref_cnt);
+}
+
+TEST(tbm_bo_ref, work_flow_success_2)
+{
+       struct _tbm_bo *expected = NULL;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_ref(&bo);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+TEST(tbm_bo_ref, work_flow_success_1)
+{
+       struct _tbm_bo *expected = NULL;
+       struct _tbm_bo *actual;
+
+       _init_test();
+
+       actual = tbm_bo_ref(NULL);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+/* tbm_bo_size() */
+
+TEST(tbm_bo_size, work_flow_success_3)
+{
+       int not_expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       LIST_ADD(&bo.item_link, &bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+       backend.bo_size = ut_bo_size;
+       bufmgr.backend = &backend;
+       bo.bufmgr = &bufmgr;
+
+       actual = tbm_bo_size(&bo);
+
+       ASSERT_TRUE(actual != not_expected);
+}
+
+TEST(tbm_bo_size, work_flow_success_2)
+{
+       int expected = 0;
+       struct _tbm_bo bo;
+       struct _tbm_bufmgr bufmgr;
+       int actual;
+
+       _init_test();
+
+       LIST_INITHEAD(&bufmgr.bo_list);
+       gBufMgr = &bufmgr;
+
+       actual = tbm_bo_size(&bo);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_bo_size, work_flow_success_1)
+{
+       int expected = 0;
+       int actual ;
+
+       _init_test();
+
+       actual = tbm_bo_size(NULL);
+
+       ASSERT_EQ(actual, expected);
+}
diff --git a/ut/src/ut_tbm_bufmgr.h b/ut/src/ut_tbm_bufmgr.h
new file mode 100644 (file)
index 0000000..beafcf2
--- /dev/null
@@ -0,0 +1,155 @@
+#ifndef _TBM_BUFMGR_H_
+#define _TBM_BUFMGR_H_
+
+#include <tbm_type.h>
+#include <stdint.h>
+
+/* tbm error base : this error base is same as TIZEN_ERROR_TBM in tizen_error.h */
+#ifndef TBM_ERROR_BASE
+#define TBM_ERROR_BASE                 -0x02830000
+#endif
+
+typedef struct _tbm_bufmgr *tbm_bufmgr;
+
+typedef struct _tbm_bo *tbm_bo;
+
+typedef uint32_t tbm_key;
+
+typedef int32_t tbm_fd;
+
+/* TBM_DEVICE_TYPE */
+
+#define TBM_DEVICE_DEFAULT   0
+#define TBM_DEVICE_CPU       1
+#define TBM_DEVICE_2D        2
+#define TBM_DEVICE_3D        3
+#define TBM_DEVICE_MM        4
+
+/* TBM_OPTION */
+
+#define TBM_OPTION_READ      (1 << 0)
+#define TBM_OPTION_WRITE     (1 << 1)
+#define TBM_OPTION_VENDOR    (0xffff0000)
+
+/* stub for union tbm_bo_handle */
+class tbm_bo_handle {
+public:
+       void *ptr;
+       int32_t s32;
+       uint32_t u32;
+       int64_t s64;
+       uint64_t u64;
+       tbm_bo_handle() {}
+       tbm_bo_handle(const uint64_t v)
+       {
+               if (v == 0) {
+                       ptr = NULL;
+               } else {
+                       ptr = &u64;
+               }
+               s32 = v;
+               u32 = v;
+               s64 = v;
+               u64 = v;
+       }
+};
+
+enum TBM_BO_FLAGS {
+       TBM_BO_DEFAULT = 0,                        /**< default memory: it depends on the backend         */
+       TBM_BO_SCANOUT = (1 << 0),         /**< scanout memory                                    */
+       TBM_BO_NONCACHABLE = (1 << 1), /**< non-cachable memory                               */
+       TBM_BO_WC = (1 << 2),              /**< write-combine memory                              */
+       TBM_BO_VENDOR = (0xffff0000), /**< vendor specific memory: it depends on the backend */
+};
+
+typedef enum {
+       TBM_ERROR_NONE = 0,                                             /**< Successful */
+       TBM_BO_ERROR_GET_FD_FAILED = TBM_ERROR_BASE | 0x0101,     /**< failed to get fd failed */
+       TBM_BO_ERROR_HEAP_ALLOC_FAILED = TBM_ERROR_BASE | 0x0102, /**< failed to allocate the heap memory */
+       TBM_BO_ERROR_LOAD_MODULE_FAILED = TBM_ERROR_BASE | 0x0103,/**< failed to load module*/
+       TBM_BO_ERROR_THREAD_INIT_FAILED = TBM_ERROR_BASE | 0x0104,/**< failed to initialize the pthread */
+       TBM_BO_ERROR_BO_ALLOC_FAILED = TBM_ERROR_BASE | 0x0105,   /**< failed to allocate tbm_bo */
+       TBM_BO_ERROR_INIT_STATE_FAILED = TBM_ERROR_BASE | 0x0106, /**< failed to initialize the state of tbm_bo */
+       TBM_BO_ERROR_IMPORT_FAILED = TBM_ERROR_BASE | 0x0107,     /**< failed to import the handle of tbm_bo */
+       TBM_BO_ERROR_IMPORT_FD_FAILED = TBM_ERROR_BASE | 0x0108,  /**< failed to import fd of tbm_bo */
+       TBM_BO_ERROR_EXPORT_FAILED = TBM_ERROR_BASE | 0x0109,     /**< failed to export the handle of the tbm_bo */
+       TBM_BO_ERROR_EXPORT_FD_FAILED = TBM_ERROR_BASE | 0x01010, /**< failed to export fd of tbm_bo */
+       TBM_BO_ERROR_GET_HANDLE_FAILED = TBM_ERROR_BASE | 0x0111, /**< failed to get the tbm_bo_handle */
+       TBM_BO_ERROR_LOCK_FAILED = TBM_ERROR_BASE | 0x0112,               /**< failed to lock the tbm_bo */
+       TBM_BO_ERROR_MAP_FAILED = TBM_ERROR_BASE | 0x0113,                /**< failed to map the tbm_bo to get the tbm_bo_handle */
+       TBM_BO_ERROR_UNMAP_FAILED = TBM_ERROR_BASE | 0x0114,      /**< failed to unmap the tbm_bo */
+       TBM_BO_ERROR_SWAP_FAILED = TBM_ERROR_BASE | 0x0115,               /**< failed to swap the tbm_bos */
+       TBM_BO_ERROR_DUP_FD_FAILED = TBM_ERROR_BASE | 0x0116,     /**< failed to duplicate fd */
+} tbm_error_e;
+
+enum TBM_BUFMGR_CAPABILITY {
+       TBM_BUFMGR_CAPABILITY_NONE = 0,                                 /**< Not Support capability*/
+       TBM_BUFMGR_CAPABILITY_SHARE_KEY = (1 << 0),             /**< Support sharing buffer by tbm key */
+       TBM_BUFMGR_CAPABILITY_SHARE_FD = (1 << 1),              /**< Support sharing buffer by tbm fd */
+};
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Functions for buffer manager */
+
+tbm_bufmgr tbm_bufmgr_init(int fd);
+
+void tbm_bufmgr_deinit(tbm_bufmgr bufmgr);
+
+/* Functions for bo */
+
+tbm_bo tbm_bo_alloc(tbm_bufmgr bufmgr, int size, int flags);
+
+tbm_bo tbm_bo_ref(tbm_bo bo);
+
+void tbm_bo_unref(tbm_bo bo);
+
+tbm_bo_handle tbm_bo_map(tbm_bo bo, int device, int opt);
+
+int tbm_bo_unmap(tbm_bo bo);
+
+tbm_bo_handle tbm_bo_get_handle(tbm_bo bo, int device);
+
+tbm_key tbm_bo_export(tbm_bo bo);
+
+tbm_fd tbm_bo_export_fd(tbm_bo bo);
+
+tbm_bo tbm_bo_import(tbm_bufmgr bufmgr, tbm_key key);
+
+tbm_bo tbm_bo_import_fd(tbm_bufmgr bufmgr, tbm_fd fd);
+
+int tbm_bo_size(tbm_bo bo);
+
+int tbm_bo_locked(tbm_bo bo);
+
+int tbm_bo_swap(tbm_bo bo1, tbm_bo bo2);
+
+typedef void (*tbm_data_free) (void *user_data);
+
+int tbm_bo_add_user_data(tbm_bo bo, unsigned long key,
+                        tbm_data_free data_free_func);
+
+int tbm_bo_delete_user_data(tbm_bo bo, unsigned long key);
+
+int tbm_bo_set_user_data(tbm_bo bo, unsigned long key, void *data);
+
+int tbm_bo_get_user_data(tbm_bo bo, unsigned long key, void **data);
+
+tbm_error_e tbm_get_last_error(void);
+
+unsigned int tbm_bufmgr_get_capability(tbm_bufmgr bufmgr);
+
+int tbm_bo_get_flags(tbm_bo bo);
+
+void tbm_bufmgr_debug_show(tbm_bufmgr bufmgr);
+
+void tbm_bufmgr_debug_trace(tbm_bufmgr bufmgr, int onoff);
+
+int tbm_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay);
+
+#ifdef __cplusplus
+}
+#endif
+#endif                                                 /* _TBM_BUFMGR_H_ */
diff --git a/ut/src/ut_tbm_bufmgr_backend.cpp b/ut/src/ut_tbm_bufmgr_backend.cpp
new file mode 100644 (file)
index 0000000..f3b75c1
--- /dev/null
@@ -0,0 +1,246 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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"
+
+#include "pthread_stubs.h"
+#include "stdlib_stubs.h"
+
+typedef struct _tbm_bufmgr_backend tbm_bufmgr_backend_s;
+typedef struct _tbm_bufmgr tbm_bufmgr_s;
+typedef struct _tbm_bo tbm_bo_s;
+
+#define pthread_mutex_lock ut_pthread_mutex_lock
+#define pthread_mutex_unlock ut_pthread_mutex_unlock
+#define pthread_mutex_init ut_pthread_mutex_init
+#define calloc ut_calloc
+#define free ut_free
+#define getenv ut_getenv
+
+#include "tbm_bufmgr_backend.c"
+
+static void _init_test()
+{
+       PTHREAD_MUTEX_INIT_ERROR = 0;
+       CALLOC_ERROR = 0;
+       FREE_CALLED = 0;
+       FREE_PTR = NULL;
+       FREE_TESTED_PTR = NULL;
+       free_called_for_tested_ptr = 0;
+       free_call_count = 0;
+       GETENV_ERROR = 0;
+}
+
+/* tbm_backend_is_display_server() */
+
+TEST(tbm_backend_is_display_server, work_flow_success_2)
+{
+       int error = 0;
+       int expected_error = 1;
+
+       _init_test();
+
+       error = tbm_backend_is_display_server();
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_backend_is_display_server, work_flow_success_1)
+{
+       int error = 1;
+       int expected_error = 0;
+
+       _init_test();
+
+       GETENV_ERROR = 1;
+
+       error = tbm_backend_is_display_server();
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_backend_get_bo_priv() */
+
+TEST(tbm_backend_get_bo_priv, work_flow_success_1)
+{
+       int priv;
+       void *actual_priv = NULL;
+       void *expected_priv = &priv;
+       tbm_bo_s bo;
+
+       _init_test();
+
+       bo.priv = &priv;
+
+       actual_priv = tbm_backend_get_bo_priv(&bo);
+
+       ASSERT_TRUE(actual_priv == expected_priv);
+}
+
+/* tbm_backend_set_bo_priv() */
+
+TEST(tbm_backend_set_bo_priv, work_flow_success_1)
+{
+       int priv;
+       tbm_bo_s bo;
+
+       _init_test();
+
+       tbm_backend_set_bo_priv(&bo, &priv);
+
+       ASSERT_TRUE(bo.priv == &priv);
+}
+
+/* tbm_backend_get_priv_from_bufmgr() */
+
+TEST(tbm_backend_get_priv_from_bufmgr, work_flow_success_1)
+{
+       int priv;
+       void *actual_priv = NULL;
+       void *expected_priv = &priv;
+       tbm_bufmgr_s bufmgr;
+       tbm_bufmgr_backend_s backend;
+
+       _init_test();
+
+       bufmgr.backend = &backend;
+       backend.priv = &priv;
+
+       actual_priv = tbm_backend_get_priv_from_bufmgr(&bufmgr);
+
+       ASSERT_TRUE(actual_priv == expected_priv);
+}
+
+/* tbm_backend_get_bufmgr_priv() */
+
+TEST(tbm_backend_get_bufmgr_priv, work_flow_success_1)
+{
+       int priv;
+       void *actual_priv = NULL;
+       void *expected_priv = &priv;
+       tbm_bo_s bo;
+       tbm_bufmgr_s bufmgr;
+       tbm_bufmgr_backend_s backend;
+
+       _init_test();
+
+       bo.bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       backend.priv = &priv;
+
+       actual_priv = tbm_backend_get_bufmgr_priv(&bo);
+
+       ASSERT_TRUE(actual_priv == expected_priv);
+}
+
+/* tbm_backend_init() */
+
+TEST(tbm_backend_init, work_flow_success_1)
+{
+       int error = 0;
+       int expected_error = 1;
+       tbm_bufmgr_s bufmgr;
+       tbm_bufmgr_backend_s backend;
+
+       _init_test();
+
+       error = tbm_backend_init(&bufmgr, &backend);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_TRUE(bufmgr.backend == &backend);
+}
+
+TEST(tbm_backend_init, null_ptr_fail_2)
+{
+       int error = 1;
+       int expected_error = 0;
+       tbm_bufmgr_s bufmgr;
+
+       _init_test();
+
+       error = tbm_backend_init(&bufmgr, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_backend_init, null_ptr_fail_1)
+{
+       int error = 1;
+       int expected_error = 0;
+       tbm_bufmgr_backend_s backend;
+
+       _init_test();
+
+       error = tbm_backend_init(NULL, &backend);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_backend_free() */
+
+TEST(tbm_backend_free, work_flow_success_1)
+{
+       tbm_bufmgr_backend backend = calloc(1, sizeof(*backend));
+
+       _init_test();
+
+       FREE_TESTED_PTR = backend;
+
+       tbm_backend_free(backend);
+
+       ASSERT_EQ(free_called_for_tested_ptr, 1);
+}
+
+/* tbm_backend_alloc() */
+
+TEST(tbm_backend_alloc, work_flow_success_2)
+{
+       tbm_bufmgr_backend backend = NULL;
+       tbm_bufmgr_backend not_expected_backend = NULL;
+
+       _init_test();
+
+       backend = tbm_backend_alloc();
+
+       ASSERT_TRUE(backend != not_expected_backend);
+       free(backend);
+}
+
+TEST(tbm_backend_alloc, work_flow_success_1)
+{
+       tbm_bufmgr_backend backend = (tbm_bufmgr_backend) 1;
+       tbm_bufmgr_backend expected_backend = NULL;
+
+       _init_test();
+
+       CALLOC_ERROR = 1;
+
+       backend = tbm_backend_alloc();
+
+       ASSERT_TRUE(backend == expected_backend);
+}
diff --git a/ut/src/ut_tbm_surface.cpp b/ut/src/ut_tbm_surface.cpp
new file mode 100644 (file)
index 0000000..df8e014
--- /dev/null
@@ -0,0 +1,507 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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"
+
+#include "pthread_stubs.h"
+#include "stdlib_stubs.h"
+
+/* HELPER FUNCTIONS */
+
+#include <stdint.h>
+#include "tbm_type.h"
+#include "tbm_surface.h"
+#include "tbm_bufmgr_int.h"
+
+static int TBM_SURFACE_ERROR = 0;
+static int TBM_SURFACE_VALID_ERROR = 0;
+struct _tbm_surface ut_ret_surface;
+static int ut_ret_width = 200;
+static int ut_ret_height = 100;
+static int ut_ret_format = 10;
+
+static int
+ut_tbm_surface_internal_query_supported_formats(uint32_t **formats, uint32_t *num)
+{
+       if (TBM_SURFACE_ERROR) {
+               return 0;
+       }
+
+       return 1;
+}
+
+static tbm_surface_h
+ut_tbm_surface_internal_create_with_flags(int width, int height,
+                                          int format, int flags)
+{
+       if (TBM_SURFACE_ERROR) {
+               return NULL;
+       }
+
+       return &ut_ret_surface;
+}
+
+static int
+ut_tbm_surface_is_valid(tbm_surface_h surface)
+{
+       if (TBM_SURFACE_VALID_ERROR) {
+               return 0;
+       }
+
+       return 1;
+}
+
+static void
+ut_tbm_surface_internal_destroy(tbm_surface_h surface)
+{
+}
+
+static int
+ut_tbm_surface_internal_get_info(tbm_surface_h surface, int opt,
+                                 tbm_surface_info_s *info, int map)
+{
+       if (TBM_SURFACE_ERROR) {
+               return 0;
+       }
+
+       return 1;
+}
+
+static void
+ut_tbm_surface_internal_unmap(tbm_surface_h surface)
+{
+}
+
+static unsigned int
+ut_tbm_surface_internal_get_width(tbm_surface_h surface)
+{
+       return ut_ret_width;
+}
+
+unsigned int
+ut_tbm_surface_internal_get_height(tbm_surface_h surface)
+{
+       return ut_ret_height;
+}
+
+static tbm_format
+ut_tbm_surface_internal_get_format(tbm_surface_h surface)
+{
+       return ut_ret_format;
+}
+
+#define pthread_mutex_lock ut_pthread_mutex_lock
+#define pthread_mutex_unlock ut_pthread_mutex_unlock
+#define pthread_mutex_init ut_pthread_mutex_init
+#define calloc ut_calloc
+#define free ut_free
+#define tbm_surface_internal_query_supported_formats \
+       ut_tbm_surface_internal_query_supported_formats
+#define tbm_surface_internal_create_with_flags \
+       ut_tbm_surface_internal_create_with_flags
+#define tbm_surface_internal_is_valid ut_tbm_surface_is_valid
+#define tbm_surface_internal_destroy ut_tbm_surface_internal_destroy
+#define tbm_surface_internal_get_info ut_tbm_surface_internal_get_info
+#define tbm_surface_internal_unmap ut_tbm_surface_internal_unmap
+#define tbm_surface_internal_get_width ut_tbm_surface_internal_get_width
+#define tbm_surface_internal_get_height ut_tbm_surface_internal_get_height
+#define tbm_surface_internal_get_format ut_tbm_surface_internal_get_format
+
+#include "tbm_surface.c"
+
+static void _init_test()
+{
+       PTHREAD_MUTEX_INIT_ERROR = 0;
+       CALLOC_ERROR = 0;
+       FREE_CALLED = 0;
+       FREE_PTR = NULL;
+       FREE_TESTED_PTR = NULL;
+       free_called_for_tested_ptr = 0;
+       free_call_count = 0;
+       GETENV_ERROR = 0;
+       TBM_SURFACE_ERROR = 0;
+       TBM_SURFACE_VALID_ERROR = 0;
+}
+
+/* tbm_surface_get_format */
+
+TEST(tbm_surface_get_format, work_flow_success_2)
+{
+       tbm_format format = 0;
+       struct _tbm_surface surface;
+
+       _init_test();
+
+       format = tbm_surface_get_format(&surface);
+
+       ASSERT_EQ(format, ut_ret_format);
+}
+
+TEST(tbm_surface_get_format, work_flow_success_1)
+{
+       tbm_format format = 0;
+       tbm_format expected_format = 0;
+       struct _tbm_surface surface;
+
+       _init_test();
+
+       TBM_SURFACE_VALID_ERROR = 1;
+
+       format = tbm_surface_get_format(&surface);
+
+       ASSERT_EQ(format, expected_format);
+}
+
+/* tbm_surface_get_height */
+
+TEST(tbm_surface_get_height, work_flow_success_1)
+{
+       int height = 0;
+       struct _tbm_surface surface;
+
+       _init_test();
+
+       height = tbm_surface_get_height(&surface);
+
+       ASSERT_EQ(height, ut_ret_height);
+}
+
+TEST(tbm_surface_get_height, null_ptr_fail_1)
+{
+       int error = TBM_SURFACE_ERROR_NONE;
+       int expected_error = TBM_SURFACE_ERROR_INVALID_PARAMETER;
+
+       _init_test();
+
+       TBM_SURFACE_VALID_ERROR = 1;
+
+       error = tbm_surface_get_height(NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_get_width() */
+
+TEST(tbm_surface_get_width, work_flow_success_1)
+{
+       int width = 0;
+       struct _tbm_surface surface;
+
+       _init_test();
+
+       width = tbm_surface_get_width(&surface);
+
+       ASSERT_EQ(width, ut_ret_width);
+}
+
+TEST(tbm_surface_get_width, null_ptr_fail_1)
+{
+       int error = TBM_SURFACE_ERROR_NONE;
+       int expected_error = TBM_SURFACE_ERROR_INVALID_PARAMETER;
+
+       _init_test();
+
+       TBM_SURFACE_VALID_ERROR = 1;
+
+       error = tbm_surface_get_width(NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_get_info() */
+
+TEST(tbm_surface_get_info, work_flow_success_2)
+{
+       int error = TBM_SURFACE_ERROR_INVALID_OPERATION;
+       int expected_error = TBM_SURFACE_ERROR_NONE;
+       struct _tbm_surface surface;
+       tbm_surface_info_s info;
+
+       _init_test();
+
+       error = tbm_surface_get_info(&surface, &info);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_get_info, work_flow_success_1)
+{
+       int error = TBM_SURFACE_ERROR_NONE;
+       int expected_error = TBM_SURFACE_ERROR_INVALID_OPERATION;
+       struct _tbm_surface surface;
+       tbm_surface_info_s info;
+
+       _init_test();
+
+       TBM_SURFACE_ERROR = 1;
+
+       error = tbm_surface_get_info(&surface, &info);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_get_info, null_ptr_fail_2)
+{
+       int error = TBM_SURFACE_ERROR_NONE;
+       int expected_error = TBM_SURFACE_ERROR_INVALID_PARAMETER;
+       struct _tbm_surface surface;
+
+       _init_test();
+
+       error = tbm_surface_get_info(&surface, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_get_info, null_ptr_fail_1)
+{
+       int error = TBM_SURFACE_ERROR_NONE;
+       int expected_error = TBM_SURFACE_ERROR_INVALID_PARAMETER;
+       tbm_surface_info_s info;
+
+       _init_test();
+
+       TBM_SURFACE_VALID_ERROR = 1;
+
+       error = tbm_surface_get_info(NULL, &info);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_unmap() */
+
+TEST(tbm_surface_unmap, work_flow_success_1)
+{
+       int error = TBM_SURFACE_ERROR_INVALID_PARAMETER;
+       int expected_error = TBM_SURFACE_ERROR_NONE;
+       struct _tbm_surface surface;
+
+       _init_test();
+
+       error = tbm_surface_unmap(&surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_unmap, null_ptr_fail_1)
+{
+       int error = TBM_SURFACE_ERROR_NONE;
+       int expected_error = TBM_SURFACE_ERROR_INVALID_PARAMETER;
+
+       _init_test();
+
+       TBM_SURFACE_VALID_ERROR = 1;
+
+       error = tbm_surface_unmap(NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_map() */
+
+TEST(tbm_surface_map, work_flow_success_2)
+{
+       int error = TBM_SURFACE_ERROR_INVALID_OPERATION;
+       int expected_error = TBM_SURFACE_ERROR_NONE;
+       struct _tbm_surface surface;
+       tbm_surface_info_s info;
+
+       _init_test();
+
+       error = tbm_surface_map(&surface, 1, &info);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_map, work_flow_success_1)
+{
+       int error = TBM_SURFACE_ERROR_NONE;
+       int expected_error = TBM_SURFACE_ERROR_INVALID_OPERATION;
+       struct _tbm_surface surface;
+       tbm_surface_info_s info;
+
+       _init_test();
+
+       TBM_SURFACE_ERROR = 1;
+
+       error = tbm_surface_map(&surface, 1, &info);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_map, null_ptr_fail_2)
+{
+       int error = TBM_SURFACE_ERROR_NONE;
+       int expected_error = TBM_SURFACE_ERROR_INVALID_PARAMETER;
+       struct _tbm_surface surface;
+
+       _init_test();
+
+       error = tbm_surface_map(&surface, 1, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_map, null_ptr_fail_1)
+{
+       int error = TBM_SURFACE_ERROR_NONE;
+       int expected_error = TBM_SURFACE_ERROR_INVALID_PARAMETER;
+       tbm_surface_info_s info;
+
+       _init_test();
+
+       TBM_SURFACE_VALID_ERROR = 1;
+
+       error = tbm_surface_map(NULL, 1, &info);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_destroy() */
+
+TEST(tbm_surface_destroy, work_flow_success_2)
+{
+       int error = TBM_SURFACE_ERROR_INVALID_PARAMETER;
+       int expected_error = TBM_SURFACE_ERROR_NONE;
+       struct _tbm_surface surface;
+
+       _init_test();
+
+       error = tbm_surface_destroy(&surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_destroy, work_flow_success_1)
+{
+       int error = TBM_SURFACE_ERROR_NONE;
+       int expected_error = TBM_SURFACE_ERROR_INVALID_PARAMETER;
+       struct _tbm_surface surface;
+
+       _init_test();
+
+       TBM_SURFACE_VALID_ERROR = 1;
+
+       error = tbm_surface_destroy(&surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_create() */
+
+TEST(tbm_surface_create, work_flow_success_4)
+{
+       tbm_surface_h actual = (tbm_surface_h) 1;
+       tbm_surface_h not_expected = NULL;
+       int width = 10;
+       int height = 10;
+       tbm_format format = 1;
+
+       _init_test();
+
+       actual = tbm_surface_create(width, height, format);
+
+       ASSERT_TRUE(actual != not_expected);
+}
+
+TEST(tbm_surface_create, work_flow_success_3)
+{
+       tbm_surface_h actual = (tbm_surface_h) 1;
+       tbm_surface_h expected = NULL;
+       int width = 10;
+       int height = 10;
+       tbm_format format = 1;
+
+       _init_test();
+
+       TBM_SURFACE_ERROR = 1;
+
+       actual = tbm_surface_create(width, height, format);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+TEST(tbm_surface_create, work_flow_success_2)
+{
+       tbm_surface_h actual = (tbm_surface_h) 1;
+       tbm_surface_h expected = NULL;
+       int width = 10;
+       int height = -10;
+       tbm_format format = 1;
+
+       _init_test();
+
+       actual = tbm_surface_create(width, height, format);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+TEST(tbm_surface_create, work_flow_success_1)
+{
+       tbm_surface_h actual = (tbm_surface_h) 1;
+       tbm_surface_h expected = NULL;
+       int width = -10;
+       int height = 10;
+       tbm_format format = 1;
+
+       _init_test();
+
+       actual = tbm_surface_create(width, height, format);
+
+       ASSERT_TRUE(actual == expected);
+}
+
+/* tbm_surface_query_formats() */
+
+TEST(tbm_surface_query_formats, work_flow_success_2)
+{
+       int error = TBM_SURFACE_ERROR_INVALID_OPERATION;
+       int expected_error = TBM_SURFACE_ERROR_NONE;
+       uint32_t *formats, num;
+
+       _init_test();
+
+       error = tbm_surface_query_formats(&formats, &num);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_query_formats, work_flow_success_1)
+{
+       int error = TBM_SURFACE_ERROR_NONE;
+       int expected_error = TBM_SURFACE_ERROR_INVALID_OPERATION;
+       uint32_t *formats, num;
+
+       _init_test();
+
+       TBM_SURFACE_ERROR = 1;
+
+       error = tbm_surface_query_formats(&formats, &num);
+
+       ASSERT_EQ(error, expected_error);
+}
diff --git a/ut/src/ut_tbm_surface_internal.cpp b/ut/src/ut_tbm_surface_internal.cpp
new file mode 100644 (file)
index 0000000..719e434
--- /dev/null
@@ -0,0 +1,2874 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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"
+
+#include "tbm_bufmgr_int.h"
+
+#include "pthread_stubs.h"
+#include "stdlib_stubs.h"
+
+/* HELPER FUNCTIONS */
+
+#include "tbm_bufmgr.h"
+
+static int UT_TBM_SURFACE_INTERNAL_ERROR = 0;
+static struct _tbm_bufmgr ut_ret_bufmgr;
+static int ut_tbm_bo_unmap_count = 0;
+static int ut_tbm_data_free_called = 0;
+
+static tbm_bufmgr ut_tbm_bufmgr_init(int fd)
+{
+       return &ut_ret_bufmgr;
+}
+
+static void ut_tbm_bufmgr_deinit(tbm_bufmgr bufmgr) {}
+
+static int ut_surface_supported_format(uint32_t **formats, uint32_t *num)
+{
+       if (UT_TBM_SURFACE_INTERNAL_ERROR) {
+               return 0;
+       }
+
+       return 1;
+}
+
+static tbm_bo_handle ut_tbm_bo_get_handle(tbm_bo bo, int device)
+{
+       tbm_bo_handle ut_ret_handle;
+       return ut_ret_handle;
+}
+
+static int ut_tbm_bo_unmap(tbm_bo bo)
+{
+       ut_tbm_bo_unmap_count++;
+}
+
+static void ut_tbm_data_free(void *user_data)
+{
+       ut_tbm_data_free_called = 1;
+}
+
+#define pthread_mutex_lock ut_pthread_mutex_lock
+#define pthread_mutex_unlock ut_pthread_mutex_unlock
+#define pthread_mutex_init ut_pthread_mutex_init
+#define calloc ut_calloc
+#define free ut_free
+#define tbm_bufmgr_init ut_tbm_bufmgr_init
+#define tbm_bufmgr_deinit ut_tbm_bufmgr_deinit
+#define tbm_bo_get_handle ut_tbm_bo_get_handle
+#define tbm_bo_unmap ut_tbm_bo_unmap
+
+#include "tbm_surface_internal.c"
+
+static void _init_test()
+{
+       g_surface_bufmgr = NULL;
+       PTHREAD_MUTEX_INIT_ERROR = 0;
+       CALLOC_ERROR = 0;
+       FREE_CALLED = 0;
+       FREE_PTR = NULL;
+       FREE_TESTED_PTR = NULL;
+       free_called_for_tested_ptr = 0;
+       free_call_count = 0;
+       GETENV_ERROR = 0;
+       UT_TBM_SURFACE_INTERNAL_ERROR = 0;
+       ut_tbm_bo_unmap_count = 0;
+       ut_tbm_data_free_called = 0;
+}
+
+/* tbm_surface_internal_delete_user_data() */
+
+TEST(tbm_surface_internal_delete_user_data, work_flow_success_4)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+       unsigned long key = 1;
+       int data;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       LIST_INITHEAD(&surface.user_data_list);
+
+       tbm_user_data *old_data = calloc(1, sizeof(*old_data));
+       old_data->data = &data;
+       old_data->free_func = ut_tbm_data_free;
+       old_data->key = key;
+       LIST_ADD(&old_data->item_link, &surface.user_data_list);
+       FREE_TESTED_PTR = old_data;
+
+       ret = tbm_surface_internal_delete_user_data(&surface, key);
+
+       ASSERT_EQ(ret, expected_ret);
+       ASSERT_EQ(free_called_for_tested_ptr, 1);
+       ASSERT_EQ(ut_tbm_data_free_called, 1);
+}
+
+TEST(tbm_surface_internal_delete_user_data, work_flow_success_3)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+       unsigned long key = 1;
+       tbm_user_data old_data;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       LIST_INITHEAD(&surface.user_data_list);
+
+       old_data.key = key + 1;
+       LIST_ADD(&old_data.item_link, &surface.user_data_list);
+
+       ret = tbm_surface_internal_delete_user_data(&surface, key);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_delete_user_data, work_flow_success_2)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       LIST_INITHEAD(&surface.user_data_list);
+
+       ret = tbm_surface_internal_delete_user_data(&surface, 1);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_delete_user_data, work_flow_success_1)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+
+       ret = tbm_surface_internal_delete_user_data(&surface, 1);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_delete_user_data, null_ptr_fail_1)
+{
+       int ret = 1;
+       int expected_ret = 0;
+
+       _init_test();
+
+       ret = tbm_surface_internal_delete_user_data(NULL, 1);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+/* tbm_surface_internal_get_user_data() */
+
+TEST(tbm_surface_internal_get_user_data, work_flow_success_4)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       unsigned long key = 1;
+       void *data;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+       int expected_data = 6;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       LIST_INITHEAD(&surface.user_data_list);
+
+       tbm_user_data old_data;
+       old_data.data = &expected_data;
+       old_data.key = key;
+       LIST_ADD(&old_data.item_link, &surface.user_data_list);
+
+       ret = tbm_surface_internal_get_user_data(&surface, key, &data);
+
+       ASSERT_EQ(ret, expected_ret);
+       ASSERT_TRUE(data == &expected_data);
+}
+
+TEST(tbm_surface_internal_get_user_data, work_flow_success_3)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       unsigned long key = 1;
+       void *data;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+       tbm_user_data old_data;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       LIST_INITHEAD(&surface.user_data_list);
+
+       old_data.key = key + 1;
+       LIST_ADD(&old_data.item_link, &surface.user_data_list);
+
+       ret = tbm_surface_internal_get_user_data(&surface, key, &data);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_user_data, work_flow_success_2)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       unsigned long key = 1;
+       void *data;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       LIST_INITHEAD(&surface.user_data_list);
+
+       ret = tbm_surface_internal_get_user_data(&surface, key, &data);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_user_data, work_flow_success_1)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       unsigned long key = 1;
+       void *data;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_INITHEAD(&surface.user_data_list);
+
+       ret = tbm_surface_internal_get_user_data(&surface, key, &data);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_user_data, null_ptr_fail_2)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       unsigned long key = 1;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       LIST_INITHEAD(&surface.user_data_list);
+
+       ret = tbm_surface_internal_get_user_data(&surface, key, NULL);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_user_data, null_ptr_fail_1)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       unsigned long key = 1;
+       void *data;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_user_data(NULL, key, &data);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+/* tbm_surface_internal_set_user_data() */
+
+TEST(tbm_surface_internal_set_user_data, work_flow_success_4)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       unsigned long key = 1;
+       int data;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+       tbm_user_data old_data;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       old_data.data = &data;
+       old_data.free_func = ut_tbm_data_free;
+       old_data.key = key;
+       LIST_INITHEAD(&surface.user_data_list);
+       LIST_ADD(&old_data.item_link, &surface.user_data_list);
+
+       ret = tbm_surface_internal_set_user_data(&surface, key, &data);
+
+       ASSERT_EQ(ret, expected_ret);
+       ASSERT_TRUE(old_data.data == &data);
+       ASSERT_EQ(ut_tbm_data_free_called, 1);
+}
+
+TEST(tbm_surface_internal_set_user_data, work_flow_success_3)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       unsigned long key = 1;
+       int data;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+       tbm_user_data old_data;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       old_data.data = NULL;
+       old_data.free_func = NULL;
+       old_data.key = key;
+       LIST_INITHEAD(&surface.user_data_list);
+       LIST_ADD(&old_data.item_link, &surface.user_data_list);
+
+       ret = tbm_surface_internal_set_user_data(&surface, key, &data);
+
+       ASSERT_EQ(ret, expected_ret);
+       ASSERT_TRUE(old_data.data == &data);
+}
+
+TEST(tbm_surface_internal_set_user_data, work_flow_success_2)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       unsigned long key = 1;
+       int data;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+       tbm_user_data old_data;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       old_data.key = key + 1;
+       LIST_INITHEAD(&surface.user_data_list);
+       LIST_ADD(&old_data.item_link, &surface.user_data_list);
+
+       ret = tbm_surface_internal_set_user_data(&surface, key, &data);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_set_user_data, work_flow_success_1)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       unsigned long key = 1;
+       int data;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+
+       ret = tbm_surface_internal_set_user_data(&surface, key, &data);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_set_user_data, null_ptr_fail_1)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       unsigned long key = 1;
+       int data;
+
+       _init_test();
+
+       ret = tbm_surface_internal_set_user_data(NULL, key, &data);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+/* tbm_surface_internal_add_user_data() */
+
+TEST(tbm_surface_internal_add_user_data, work_flow_success_4)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       unsigned long key = 1;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+       tbm_user_data data;
+       tbm_user_data *added_data;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       data.key = key + 1;
+       LIST_INITHEAD(&surface.user_data_list);
+       LIST_ADD(&data.item_link, &surface.user_data_list);
+
+       ret = tbm_surface_internal_add_user_data(&surface, key, ut_tbm_data_free);
+
+       ASSERT_EQ(ret, expected_ret);
+
+       added_data = user_data_lookup(&surface.user_data_list, key);
+
+       ASSERT_TRUE(added_data != NULL);
+
+       tbm_user_data copy_data = *added_data;
+       free(added_data);
+
+       ASSERT_EQ(copy_data.key, key);
+       ASSERT_TRUE(copy_data.free_func == ut_tbm_data_free);
+       ASSERT_TRUE(copy_data.data == NULL);
+}
+
+TEST(tbm_surface_internal_add_user_data, work_flow_success_3)
+{
+       int ret = 0;
+       int expected_ret = 0;
+       unsigned long key = 1;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+       tbm_user_data data;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       data.key = key + 1;
+       LIST_INITHEAD(&surface.user_data_list);
+       LIST_ADD(&data.item_link, &surface.user_data_list);
+       CALLOC_ERROR = 1;
+
+       ret = tbm_surface_internal_add_user_data(&surface, key, ut_tbm_data_free);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_add_user_data, work_flow_success_2)
+{
+       int ret = 0;
+       int expected_ret = 0;
+       unsigned long key = 1;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+       tbm_user_data data;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       data.key = key;
+       LIST_INITHEAD(&surface.user_data_list);
+       LIST_ADD(&data.item_link, &surface.user_data_list);
+
+       ret = tbm_surface_internal_add_user_data(&surface, key, ut_tbm_data_free);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_add_user_data, work_flow_success_1)
+{
+       int ret = 0;
+       int expected_ret = 0;
+       unsigned long key = 0;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+
+       ret = tbm_surface_internal_add_user_data(&surface, key, ut_tbm_data_free);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_add_user_data, null_ptr_fail_1)
+{
+       int ret = 0;
+       int expected_ret = 0;
+       unsigned long key = 0;
+
+       _init_test();
+
+       ret = tbm_surface_internal_add_user_data(NULL, key, ut_tbm_data_free);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+/* tbm_surface_internal_set_debug_pid() */
+
+TEST(tbm_surface_internal_set_debug_pid, work_flow_success_1)
+{
+       unsigned int pid = 20;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       tbm_surface_internal_set_debug_pid(&surface, pid);
+
+       ASSERT_EQ(pid, surface.debug_pid);
+}
+
+/* tbm_surface_internal_get_plane_bo_idx() */
+
+TEST(tbm_surface_internal_get_plane_bo_idx, work_flow_success_3)
+{
+       int actual = 1;
+       int plane_idx = 0;
+       int expected_bo_idx = 10;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       surface.planes_bo_idx[plane_idx] = expected_bo_idx;
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       actual = tbm_surface_internal_get_plane_bo_idx(&surface, plane_idx);
+
+       ASSERT_EQ(actual, expected_bo_idx);
+}
+
+TEST(tbm_surface_internal_get_plane_bo_idx, work_flow_success_2)
+{
+       int actual = 1;
+       int expected = 0;
+       int plane_idx = -1;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       actual = tbm_surface_internal_get_plane_bo_idx(&surface, plane_idx);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_surface_internal_get_plane_bo_idx, work_flow_success_1)
+{
+       int actual = 1;
+       int expected = 0;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+
+       actual = tbm_surface_internal_get_plane_bo_idx(&surface, 0);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_surface_internal_get_plane_bo_idx, null_ptr_fail_1)
+{
+       _init_test();
+       int actual = 1;
+       int expected = 0;
+
+       actual = tbm_surface_internal_get_plane_bo_idx(NULL, 0);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_surface_internal_get_format() */
+
+TEST(tbm_surface_internal_get_format, work_flow_success_2)
+{
+       unsigned int actual = 1;
+       int expected_format = 768;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       surface.info.format = expected_format;
+
+       actual = tbm_surface_internal_get_format(&surface);
+
+       ASSERT_EQ(actual, expected_format);
+}
+
+TEST(tbm_surface_internal_get_format, work_flow_success_1)
+{
+       unsigned int actual = 1;
+       unsigned int expected = 0;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+
+       actual = tbm_surface_internal_get_format(&surface);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_surface_internal_get_format, null_ptr_fail_1)
+{
+       unsigned int actual = 1;
+       unsigned int expected = 0;
+
+       _init_test();
+
+       actual = tbm_surface_internal_get_format(NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_surface_internal_get_height() */
+
+TEST(tbm_surface_internal_get_height, work_flow_success_2)
+{
+       unsigned int actual = 1;
+       int expected_height = 768;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       surface.info.height = expected_height;
+
+       actual = tbm_surface_internal_get_height(&surface);
+
+       ASSERT_EQ(actual, expected_height);
+}
+
+TEST(tbm_surface_internal_get_height, work_flow_success_1)
+{
+       unsigned int actual = 1;
+       unsigned int expected = 0;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+
+       actual = tbm_surface_internal_get_height(&surface);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_surface_internal_get_height, null_ptr_fail_1)
+{
+       unsigned int actual = 1;
+       unsigned int expected = 0;
+
+       _init_test();
+
+       actual = tbm_surface_internal_get_height(NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_surface_internal_get_width() */
+
+TEST(tbm_surface_internal_get_width, work_flow_success_2)
+{
+       unsigned int actual = 1;
+       int expected_width = 1024;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       surface.info.width = expected_width;
+
+       actual = tbm_surface_internal_get_width(&surface);
+
+       ASSERT_EQ(actual, expected_width);
+}
+
+TEST(tbm_surface_internal_get_width, work_flow_success_1)
+{
+       unsigned int actual = 1;
+       unsigned int expected = 0;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+
+       actual = tbm_surface_internal_get_width(&surface);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_surface_internal_get_width, null_ptr_fail_1)
+{
+       unsigned int actual = 1;
+       unsigned int expected = 0;
+
+       _init_test();
+
+       actual = tbm_surface_internal_get_width(NULL);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_surface_internal_unmap() */
+
+TEST(tbm_surface_internal_unmap, work_flow_success_1)
+{
+       struct _tbm_surface surface;
+       int count = 10;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       surface.num_bos = count;
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       tbm_surface_internal_unmap(&surface);
+
+       ASSERT_EQ(ut_tbm_bo_unmap_count, count);
+}
+
+/* tbm_surface_internal_get_info() */
+
+TEST(tbm_surface_internal_get_info, work_flow_success_2)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_surface_info_s info;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       surface.info.num_planes = 0;
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       uint32_t expected_width = 2;
+       uint32_t expected_height = 3;
+       uint32_t expected_format = 4;
+       uint32_t expected_bpp = 5;
+       uint32_t expected_size = 6;
+       surface.info.width = expected_width;
+       surface.info.height = expected_height;
+       surface.info.format = expected_format;
+       surface.info.bpp = expected_bpp;
+       surface.info.size = expected_size;
+       surface.info.num_planes = 0;
+       surface.num_bos = 1;
+
+       ret = tbm_surface_internal_get_info(&surface, 1, &info, 2);
+
+       ASSERT_EQ(ret, expected_ret);
+       ASSERT_EQ(info.width, expected_width);
+       ASSERT_EQ(info.height, expected_height);
+       ASSERT_EQ(info.format, expected_format);
+       ASSERT_EQ(info.bpp, expected_bpp);
+       ASSERT_EQ(info.size, expected_size);
+}
+
+TEST(tbm_surface_internal_get_info, work_flow_success_1)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       tbm_surface_info_s info;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+
+       ret = tbm_surface_internal_get_info(&surface, 1, &info, 1);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_info, null_ptr_fail_1)
+{
+       int ret = 1;
+       int expected_ret = 0;
+       tbm_surface_info_s info;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_info(NULL, 1, &info, 1);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+/* tbm_surface_internal_get_plane_data() */
+
+TEST(tbm_surface_internal_get_plane_data, work_flow_success_4)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       int plane_idx = 0;
+       uint32_t size = 0;
+       uint32_t offset = 0;
+       uint32_t pitch = 0;
+       uint32_t expected_size = 1024;
+       uint32_t expected_offset = 10;
+       uint32_t expected_pitch = 20;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       surface.info.planes[plane_idx].size = expected_size;
+       surface.info.planes[plane_idx].offset = expected_offset;
+       surface.info.planes[plane_idx].stride = expected_pitch;
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       surface.info.num_planes = 1;
+
+       ret = tbm_surface_internal_get_plane_data(&surface, plane_idx, &size,
+                                                                                         &offset, &pitch);
+
+       ASSERT_EQ(ret, expected_ret);
+       ASSERT_EQ(size, expected_size);
+       ASSERT_EQ(offset, expected_offset);
+       ASSERT_EQ(pitch, expected_pitch);
+}
+
+TEST(tbm_surface_internal_get_plane_data, work_flow_success_3)
+{
+       int ret = 0;
+       int expected_ret = 0;
+       int plane_idx = 3;
+       uint32_t size = 0;
+       uint32_t offset = 0;
+       uint32_t pitch = 0;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+       surface.info.num_planes = plane_idx - 1;
+
+       ret = tbm_surface_internal_get_plane_data(&surface, plane_idx, &size,
+                                                                                         &offset, &pitch);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_plane_data, work_flow_success_2)
+{
+       int ret = 0;
+       int expected_ret = 0;
+       int plane_idx = -1;
+       uint32_t size = 0;
+       uint32_t offset = 0;
+       uint32_t pitch = 0;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       ret = tbm_surface_internal_get_plane_data(&surface, plane_idx, &size,
+                                                                                         &offset, &pitch);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_plane_data, work_flow_success_1)
+{
+       int ret = 0;
+       int expected_ret = 0;
+       uint32_t size = 0;
+       uint32_t offset = 0;
+       uint32_t pitch = 0;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+
+       ret = tbm_surface_internal_get_plane_data(&surface, 1, &size,
+                                                                                         &offset, &pitch);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_plane_data, null_ptr_fail_1)
+{
+       int ret = 0;
+       int expected_ret = 0;
+       uint32_t size = 0;
+       uint32_t offset = 0;
+       uint32_t pitch = 0;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_plane_data(NULL, 1, &size, &offset, &pitch);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+/* tbm_surface_internal_get_size() */
+
+TEST(tbm_surface_internal_get_size, work_flow_success_2)
+{
+       int actual_size = 0;
+       int expected_size = 1024;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       surface.info.size = expected_size;
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       actual_size = tbm_surface_internal_get_size(&surface);
+
+       ASSERT_EQ(actual_size, expected_size);
+       ASSERT_EQ(actual_size, expected_size);
+}
+
+TEST(tbm_surface_internal_get_size, work_flow_success_1)
+{
+       int actual_size = 0;
+       int expected_size = 0;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+
+       actual_size = tbm_surface_internal_get_size(&surface);
+
+       ASSERT_EQ(actual_size, expected_size);
+}
+
+TEST(tbm_surface_internal_get_size, null_ptr_fail_1)
+{
+       int actual_size = 0;
+       int expected_size = 0;
+
+       _init_test();
+
+       actual_size = tbm_surface_internal_get_size(NULL);
+
+       ASSERT_EQ(actual_size, expected_size);
+}
+
+/* tbm_surface_internal_get_bo() */
+
+TEST(tbm_surface_internal_get_bo, work_flow_success_3)
+{
+       tbm_bo bo;
+       int bo_idx = 0;
+       struct _tbm_bo expected_bo;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       surface.bos[bo_idx] = &expected_bo;
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       bo = tbm_surface_internal_get_bo(&surface, bo_idx);
+
+       ASSERT_TRUE(bo == &expected_bo);
+}
+
+TEST(tbm_surface_internal_get_bo, work_flow_success_2)
+{
+       tbm_bo bo;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+
+       bo = tbm_surface_internal_get_bo(&surface, 1);
+
+       ASSERT_TRUE(bo == NULL);
+}
+
+TEST(tbm_surface_internal_get_bo, work_flow_success_1)
+{
+       tbm_bo bo;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       bo = tbm_surface_internal_get_bo(&surface, -1);
+
+       ASSERT_TRUE(bo == NULL);
+}
+
+TEST(tbm_surface_internal_get_bo, null_ptr_fail_1)
+{
+       tbm_bo bo;
+
+       _init_test();
+
+       bo = tbm_surface_internal_get_bo(NULL, 1);
+
+       ASSERT_TRUE(bo == NULL);
+}
+
+/* tbm_surface_internal_get_num_bos() */
+
+TEST(tbm_surface_internal_get_num_bos, work_flow_success_1)
+{
+       int actual_num = 0;
+       int expected_num = 5;
+       struct _tbm_surface surface;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       surface.num_bos = expected_num;
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       actual_num = tbm_surface_internal_get_num_bos(&surface);
+
+       ASSERT_EQ(actual_num, expected_num);
+}
+
+/* tbm_surface_internal_unref() */
+
+TEST(tbm_surface_internal_unref, work_flow_success_2)
+{
+       tbm_surface_h surface = calloc(1, sizeof(*surface));
+       surface->refcnt = 1;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_INITHEAD(&surface->user_data_list);
+       LIST_ADD(&surface->item_link, &bufmgr.surf_list);
+       surface->num_bos = 0;
+       FREE_TESTED_PTR = surface;
+       surface->bufmgr = &bufmgr;
+
+       tbm_surface_internal_unref(surface);
+
+       ASSERT_EQ(free_called_for_tested_ptr, 1);
+       ASSERT_TRUE(g_surface_bufmgr == NULL);
+}
+
+TEST(tbm_surface_internal_unref, work_flow_success_1)
+{
+       struct _tbm_surface surface;
+       int expected_refcnt = 9;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       surface.refcnt = expected_refcnt + 1;
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       tbm_surface_internal_unref(&surface);
+
+       ASSERT_EQ(expected_refcnt, surface.refcnt);
+}
+
+/* tbm_surface_internal_ref() */
+
+TEST(tbm_surface_internal_ref, work_flow_success_1)
+{
+       struct _tbm_surface surface;
+       int expected_refcnt = 10;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       surface.refcnt = expected_refcnt - 1;
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       tbm_surface_internal_ref(&surface);
+
+       ASSERT_EQ(expected_refcnt, surface.refcnt);
+}
+
+/* tbm_surface_internal_destroy() */
+
+TEST(tbm_surface_internal_destroy, work_flow_success_2)
+{
+       tbm_surface_h surface = calloc(1, sizeof(*surface));
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       surface->refcnt = 1;
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_INITHEAD(&surface->user_data_list);
+       LIST_ADD(&surface->item_link, &bufmgr.surf_list);
+       surface->num_bos = 0;
+       FREE_TESTED_PTR = surface;
+       surface->bufmgr = &bufmgr;
+
+       tbm_surface_internal_destroy(surface);
+
+       ASSERT_EQ(free_called_for_tested_ptr, 1);
+       ASSERT_TRUE(g_surface_bufmgr == NULL);
+}
+
+TEST(tbm_surface_internal_destroy, work_flow_success_1)
+{
+       struct _tbm_surface surface;
+       int expected_refcnt = 9;
+       struct _tbm_bufmgr bufmgr;
+
+       _init_test();
+
+       surface.refcnt = expected_refcnt + 1;
+       g_surface_bufmgr = &bufmgr;
+       LIST_INITHEAD(&bufmgr.surf_list);
+       LIST_ADD(&surface.item_link, &bufmgr.surf_list);
+
+       tbm_surface_internal_destroy(&surface);
+
+       ASSERT_EQ(expected_refcnt, surface.refcnt);
+}
+
+/* tbm_surface_internal_get_bpp() */
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_59)
+{
+       int ret = 0;
+       int expected_ret = 24;
+       tbm_format format = TBM_FORMAT_YVU444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_58)
+{
+       int ret = 0;
+       int expected_ret = 24;
+       tbm_format format = TBM_FORMAT_YUV444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_57)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_YVU422;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_56)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_YUV422;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_55)
+{
+       int ret = 0;
+       int expected_ret = 12;
+       tbm_format format = TBM_FORMAT_YVU420;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_54)
+{
+       int ret = 0;
+       int expected_ret = 12;
+       tbm_format format = TBM_FORMAT_YUV420;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_53)
+{
+       int ret = 0;
+       int expected_ret = 12;
+       tbm_format format = TBM_FORMAT_YVU411;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_52)
+{
+       int ret = 0;
+       int expected_ret = 12;
+       tbm_format format = TBM_FORMAT_YUV411;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_51)
+{
+       int ret = 0;
+       int expected_ret = 9;
+       tbm_format format = TBM_FORMAT_YVU410;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_50)
+{
+       int ret = 0;
+       int expected_ret = 9;
+       tbm_format format = TBM_FORMAT_YUV410;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_49)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_NV61;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_48)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_NV16;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_47)
+{
+       int ret = 0;
+       int expected_ret = 12;
+       tbm_format format = TBM_FORMAT_NV21;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_46)
+{
+       int ret = 0;
+       int expected_ret = 12;
+       tbm_format format = TBM_FORMAT_NV12MT;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_45)
+{
+       int ret = 0;
+       int expected_ret = 12;
+       tbm_format format = TBM_FORMAT_NV12;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_44)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_AYUV;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_43)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_VYUY;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_42)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_UYVY;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_41)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_YVYU;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_40)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_YUYV;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_39)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_BGRA1010102;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_38)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_RGBA1010102;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_37)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_ABGR2101010;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_36)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_ARGB2101010;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_35)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_BGRX1010102;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_34)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_RGBX1010102;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_33)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_XBGR2101010;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_32)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_XRGB2101010;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_31)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_BGRA8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_30)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_RGBA8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_29)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_ABGR8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_28)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_ARGB8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_27)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_BGRX8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_26)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_RGBX8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_25)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_XBGR8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_24)
+{
+       int ret = 0;
+       int expected_ret = 32;
+       tbm_format format = TBM_FORMAT_XRGB8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_23)
+{
+       int ret = 0;
+       int expected_ret = 24;
+       tbm_format format = TBM_FORMAT_BGR888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_22)
+{
+       int ret = 0;
+       int expected_ret = 24;
+       tbm_format format = TBM_FORMAT_RGB888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_21)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_BGR565;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_20)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_RGB565;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_19)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_BGRA5551;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_18)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_RGBA5551;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_17)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_ABGR1555;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_16)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_ARGB1555;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_15)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_BGRX5551;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_14)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_RGBX5551;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_13)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_XBGR1555;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_12)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_XRGB1555;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_11)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_BGRA4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_10)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_RGBA4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_9)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_ABGR4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_8)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_ARGB4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_7)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_BGRX4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_6)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_RGBX4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_5)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_XBGR4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_4)
+{
+       int ret = 0;
+       int expected_ret = 16;
+       tbm_format format = TBM_FORMAT_XRGB4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_3)
+{
+       int ret = 0;
+       int expected_ret = 8;
+       tbm_format format = TBM_FORMAT_BGR233;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_2)
+{
+       int ret = 0;
+       int expected_ret = 8;
+       tbm_format format = TBM_FORMAT_RGB332;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_bpp, work_flow_success_1)
+{
+       int ret = 0;
+       int expected_ret = 8;
+       tbm_format format = TBM_FORMAT_C8;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_bpp(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+/* tbm_surface_internal_get_num_planes() */
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_60)
+{
+       int ret = 0;
+       int expected_ret = 3;
+       tbm_format format = TBM_FORMAT_YVU444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_59)
+{
+       int ret = 0;
+       int expected_ret = 3;
+       tbm_format format = TBM_FORMAT_YUV444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_58)
+{
+       int ret = 0;
+       int expected_ret = 3;
+       tbm_format format = TBM_FORMAT_YVU422;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_57)
+{
+       int ret = 0;
+       int expected_ret = 3;
+       tbm_format format = TBM_FORMAT_YUV422;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_56)
+{
+       int ret = 0;
+       int expected_ret = 3;
+       tbm_format format = TBM_FORMAT_YVU420;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_55)
+{
+       int ret = 0;
+       int expected_ret = 3;
+       tbm_format format = TBM_FORMAT_YUV420;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_54)
+{
+       int ret = 0;
+       int expected_ret = 3;
+       tbm_format format = TBM_FORMAT_YVU411;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_53)
+{
+       int ret = 0;
+       int expected_ret = 3;
+       tbm_format format = TBM_FORMAT_YUV411;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_52)
+{
+       int ret = 0;
+       int expected_ret = 3;
+       tbm_format format = TBM_FORMAT_YVU410;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_51)
+{
+       int ret = 0;
+       int expected_ret = 3;
+       tbm_format format = TBM_FORMAT_YUV410;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_50)
+{
+       int ret = 0;
+       int expected_ret = 2;
+       tbm_format format = TBM_FORMAT_NV61;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_49)
+{
+       int ret = 0;
+       int expected_ret = 2;
+       tbm_format format = TBM_FORMAT_NV16;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_48)
+{
+       int ret = 0;
+       int expected_ret = 2;
+       tbm_format format = TBM_FORMAT_NV21;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_47)
+{
+       int ret = 0;
+       int expected_ret = 2;
+       tbm_format format = TBM_FORMAT_NV12MT;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_46)
+{
+       int ret = 0;
+       int expected_ret = 2;
+       tbm_format format = TBM_FORMAT_NV12;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_45)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_AYUV;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_44)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_VYUY;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_43)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_UYVY;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_42)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_YVYU;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_41)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_YUYV;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_40)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_BGRA1010102;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_39)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_RGBA1010102;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_38)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_ABGR2101010;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_37)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_ARGB2101010;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_36)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_BGRX1010102;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_35)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_RGBX1010102;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_34)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_XBGR2101010;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_33)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_XRGB2101010;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_32)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_BGRA8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_31)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_RGBA8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_30)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_ABGR8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_29)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_ABGR8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_28)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_ARGB8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_27)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_BGRX8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_26)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_RGBX8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_25)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_XBGR8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_24)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_XRGB8888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_23)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_BGR888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_22)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_RGB888;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_21)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_BGR565;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_20)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_RGB565;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_19)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_BGRA5551;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_18)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_RGBA5551;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_17)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_ABGR1555;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_16)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_ARGB1555;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_15)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_BGRX5551;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_14)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_RGBX5551;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_13)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_XBGR1555;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_12)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_XRGB1555;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_11)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_BGRA4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_10)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_RGBA4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_9)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_ABGR4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_8)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_ARGB4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_7)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_BGRX4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_6)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_RGBX4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_5)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_XBGR4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_4)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_XRGB4444;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_3)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_BGR233;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_2)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_RGB332;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tbm_surface_internal_get_num_planes, work_flow_success_1)
+{
+       int ret = 0;
+       int expected_ret = 1;
+       tbm_format format = TBM_FORMAT_C8;
+
+       _init_test();
+
+       ret = tbm_surface_internal_get_num_planes(format);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+/* tbm_surface_internal_query_supported_formats() */
+
+TEST(tbm_surface_internal_query_supported_formats, work_flow_success_3)
+{
+       int ret = 0;
+       int expecte_ret = 1;
+       uint32_t *formats, num;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       ut_ret_bufmgr.backend = &backend;
+       backend.surface_supported_format = ut_surface_supported_format;
+
+       ret = tbm_surface_internal_query_supported_formats(&formats, num);
+
+       ASSERT_EQ(ret, expecte_ret);
+}
+
+TEST(tbm_surface_internal_query_supported_formats, work_flow_success_2)
+{
+       int ret = 0;
+       int expecte_ret = 0;
+       uint32_t *formats, num;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       ut_ret_bufmgr.backend = &backend;
+       backend.surface_supported_format = ut_surface_supported_format;
+       UT_TBM_SURFACE_INTERNAL_ERROR = 1;
+
+       ret = tbm_surface_internal_query_supported_formats(&formats, num);
+
+       ASSERT_EQ(ret, expecte_ret);
+}
+
+TEST(tbm_surface_internal_query_supported_formats, work_flow_success_1)
+{
+       int ret = 0;
+       int expecte_ret = 0;
+       uint32_t *formats, num;
+       struct _tbm_bufmgr bufmgr;
+       struct _tbm_bufmgr_backend backend;
+
+       _init_test();
+
+       g_surface_bufmgr = &bufmgr;
+       bufmgr.backend = &backend;
+       ut_ret_bufmgr.backend = &backend;
+       backend.surface_supported_format = NULL;
+
+       ret = tbm_surface_internal_query_supported_formats(&formats, num);
+
+       ASSERT_EQ(ret, expecte_ret);
+}
diff --git a/ut/src/ut_tbm_surface_queue.cpp b/ut/src/ut_tbm_surface_queue.cpp
new file mode 100644 (file)
index 0000000..95fb461
--- /dev/null
@@ -0,0 +1,1657 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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"
+
+typedef struct _tbm_surface_queue tbm_surface_queue_s;
+typedef struct _tbm_surface tbm_surface_s;
+
+#include "pthread_stubs.h"
+#include "stdlib_stubs.h"
+
+#define pthread_mutex_lock ut_pthread_mutex_lock
+#define pthread_mutex_unlock ut_pthread_mutex_unlock
+#define pthread_mutex_init ut_pthread_mutex_init
+#define pthread_cond_signal ut_pthread_cond_signal
+#define pthread_cond_wait ut_pthread_cond_wait
+#define calloc ut_calloc
+#define free ut_free
+
+#include "tbm_surface_queue.c"
+
+/* HELPER FUNCTIONS */
+
+static void ut_tbm_surface_queue_notify_cb(tbm_surface_queue_h surface_queue,
+                                                                                  void *data) {}
+
+static tbm_surface_h ut_tbm_surface_alloc_cb(tbm_surface_queue_h surface_queue,
+                                                                                        void *data) {}
+
+static void ut_tbm_surface_free_cb(tbm_surface_queue_h surface_queue,
+                                                                  void *data, tbm_surface_h surface) {}
+
+static void ut_enqueue(tbm_surface_queue_h queue, queue_node *node) {}
+
+static queue_node *ut_dequeue(tbm_surface_queue_h queue)
+{
+       return NULL;
+}
+
+static void ut_release(tbm_surface_queue_h queue, queue_node *node) {}
+
+static queue_node *ut_acquire(tbm_surface_queue_h queue)
+{
+       return NULL;
+}
+
+static void _init_test()
+{
+       PTHREAD_MUTEX_INIT_ERROR = 0;
+       CALLOC_ERROR = 0;
+       FREE_CALLED = 0;
+       FREE_PTR = NULL;
+       FREE_TESTED_PTR = NULL;
+       free_called_for_tested_ptr = 0;
+       free_call_count = 0;
+       GETENV_ERROR = 0;
+}
+
+/* tbm_surface_queue_sequence_create */
+
+TEST(tbm_surface_queue_sequence_create, work_flow_success_6)
+{
+       tbm_surface_queue_h surface_queue = NULL;
+       int queue_size = 1000;
+       int width = 200;
+       int height = 100;
+       int format = 50;
+       int flags = 10;
+
+       _init_test();
+
+       surface_queue = tbm_surface_queue_sequence_create(queue_size, width, height,
+                                                                                        format, flags);
+
+       ASSERT_NE(surface_queue, NULL);
+       tbm_surface_queue_s copy_surface_queue = *surface_queue;
+       tbm_queue_default data = *((tbm_queue_default *) surface_queue->impl_data);
+       free(surface_queue->impl_data);
+       free(surface_queue);
+       ASSERT_EQ(queue_size, data.queue_size);
+       ASSERT_EQ(flags, data.flags);
+       ASSERT_EQ(queue_size, copy_surface_queue.queue_size);
+       ASSERT_EQ(width, copy_surface_queue.width);
+       ASSERT_EQ(height, copy_surface_queue.height);
+       ASSERT_EQ(format, copy_surface_queue.format);
+}
+
+TEST(tbm_surface_queue_sequence_create, work_flow_success_5)
+{
+       tbm_surface_queue_h surface_queue = NULL;
+       tbm_surface_queue_h expected_surface_queue = NULL;
+       int queue_size = 1000;
+       int width = 200;
+       int height = 100;
+       int format = 50;
+       int flags = 10;
+
+       _init_test();
+
+       CALLOC_ERROR = 1;
+
+       surface_queue = tbm_surface_queue_sequence_create(queue_size, width, height,
+                                                                                        format, flags);
+
+       ASSERT_EQ(surface_queue, expected_surface_queue);
+}
+
+TEST(tbm_surface_queue_sequence_create, work_flow_success_4)
+{
+       tbm_surface_queue_h surface_queue = NULL;
+       tbm_surface_queue_h expected_surface_queue = NULL;
+       int queue_size = 1000;
+       int width = 200;
+       int height = 100;
+       int format = 0;
+       int flags = 10;
+
+       _init_test();
+
+       surface_queue = tbm_surface_queue_sequence_create(queue_size, width, height,
+                                                                                        format, flags);
+
+       ASSERT_EQ(surface_queue, expected_surface_queue);
+}
+
+TEST(tbm_surface_queue_sequence_create, work_flow_success_3)
+{
+       tbm_surface_queue_h surface_queue = NULL;
+       tbm_surface_queue_h expected_surface_queue = NULL;
+       int queue_size = 1000;
+       int width = 200;
+       int height = 0;
+       int format = 50;
+       int flags = 10;
+
+       _init_test();
+
+       surface_queue = tbm_surface_queue_sequence_create(queue_size, width, height,
+                                                                                        format, flags);
+
+       ASSERT_EQ(surface_queue, expected_surface_queue);
+}
+
+TEST(tbm_surface_queue_sequence_create, work_flow_success_2)
+{
+       tbm_surface_queue_h surface_queue = NULL;
+       tbm_surface_queue_h expected_surface_queue = NULL;
+       int queue_size = 1000;
+       int width = 0;
+       int height = 100;
+       int format = 50;
+       int flags = 10;
+
+       _init_test();
+
+       surface_queue = tbm_surface_queue_sequence_create(queue_size, width, height,
+                                                                                        format, flags);
+
+       ASSERT_EQ(surface_queue, expected_surface_queue);
+}
+
+TEST(tbm_surface_queue_sequence_create, work_flow_success_1)
+{
+       tbm_surface_queue_h surface_queue = NULL;
+       tbm_surface_queue_h expected_surface_queue = NULL;
+       int queue_size = 0;
+       int width = 200;
+       int height = 100;
+       int format = 50;
+       int flags = 10;
+
+       _init_test();
+
+       surface_queue = tbm_surface_queue_sequence_create(queue_size, width, height,
+                                                                                        format, flags);
+
+       ASSERT_EQ(surface_queue, expected_surface_queue);
+}
+
+/* tbm_surface_queue_create() */
+
+TEST(tbm_surface_queue_create, work_flow_success_6)
+{
+       tbm_surface_queue_h surface_queue = NULL;
+       int queue_size = 1000;
+       int width = 200;
+       int height = 100;
+       int format = 50;
+       int flags = 10;
+
+       _init_test();
+
+       surface_queue = tbm_surface_queue_create(queue_size, width, height,
+                                                                                        format, flags);
+
+       ASSERT_NE(surface_queue, NULL);
+       tbm_surface_queue_s copy_surface_queue = *surface_queue;
+       tbm_queue_default data = *((tbm_queue_default *) surface_queue->impl_data);
+       free(surface_queue->impl_data);
+       free(surface_queue);
+       ASSERT_EQ(queue_size, data.queue_size);
+       ASSERT_EQ(flags, data.flags);
+       ASSERT_EQ(queue_size, copy_surface_queue.queue_size);
+       ASSERT_EQ(width, copy_surface_queue.width);
+       ASSERT_EQ(height, copy_surface_queue.height);
+       ASSERT_EQ(format, copy_surface_queue.format);
+}
+
+TEST(tbm_surface_queue_create, work_flow_success_5)
+{
+       tbm_surface_queue_h surface_queue = NULL;
+       tbm_surface_queue_h expected_surface_queue = NULL;
+       int queue_size = 1000;
+       int width = 200;
+       int height = 100;
+       int format = 50;
+       int flags = 10;
+
+       _init_test();
+
+       CALLOC_ERROR = 1;
+
+       surface_queue = tbm_surface_queue_create(queue_size, width, height,
+                                                                                        format, flags);
+
+       ASSERT_EQ(surface_queue, expected_surface_queue);
+}
+
+TEST(tbm_surface_queue_create, work_flow_success_4)
+{
+       tbm_surface_queue_h surface_queue = NULL;
+       tbm_surface_queue_h expected_surface_queue = NULL;
+       int queue_size = 1000;
+       int width = 200;
+       int height = 100;
+       int format = 0;
+       int flags = 10;
+
+       _init_test();
+
+       surface_queue = tbm_surface_queue_create(queue_size, width, height,
+                                                                                        format, flags);
+
+       ASSERT_EQ(surface_queue, expected_surface_queue);
+}
+
+TEST(tbm_surface_queue_create, work_flow_success_3)
+{
+       tbm_surface_queue_h surface_queue = NULL;
+       tbm_surface_queue_h expected_surface_queue = NULL;
+       int queue_size = 1000;
+       int width = 200;
+       int height = 0;
+       int format = 50;
+       int flags = 10;
+
+       _init_test();
+
+       surface_queue = tbm_surface_queue_create(queue_size, width, height,
+                                                                                        format, flags);
+
+       ASSERT_EQ(surface_queue, expected_surface_queue);
+}
+
+TEST(tbm_surface_queue_create, work_flow_success_2)
+{
+       tbm_surface_queue_h surface_queue = NULL;
+       tbm_surface_queue_h expected_surface_queue = NULL;
+       int queue_size = 1000;
+       int width = 0;
+       int height = 100;
+       int format = 50;
+       int flags = 10;
+
+       _init_test();
+
+       surface_queue = tbm_surface_queue_create(queue_size, width, height,
+                                                                                        format, flags);
+
+       ASSERT_EQ(surface_queue, expected_surface_queue);
+}
+
+TEST(tbm_surface_queue_create, work_flow_success_1)
+{
+       tbm_surface_queue_h surface_queue = NULL;
+       tbm_surface_queue_h expected_surface_queue = NULL;
+       int queue_size = 0;
+       int width = 200;
+       int height = 100;
+       int format = 50;
+       int flags = 10;
+
+       _init_test();
+
+       surface_queue = tbm_surface_queue_create(queue_size, width, height,
+                                                                                        format, flags);
+
+       ASSERT_EQ(surface_queue, expected_surface_queue);
+}
+
+/* tbm_surface_queue_flush() */
+
+TEST(tbm_surface_queue_flush, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface_queue;
+       LIST_INITHEAD(&surface_queue.list);
+       LIST_INITHEAD(&surface_queue.reset_noti);
+       surface_queue.impl = NULL;
+
+       _init_test();
+
+       error = tbm_surface_queue_flush(&surface_queue);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_flush, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+
+       _init_test();
+
+       error = tbm_surface_queue_flush(NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_queue_reset() */
+
+TEST(tbm_surface_queue_reset, work_flow_success_2)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface_queue;
+       int width, height, format;
+
+       _init_test();
+
+       width = 200;
+       height = 100;
+       format = 10;
+       surface_queue.width = 1;
+       surface_queue.height = 1;
+       surface_queue.format = 1;
+       LIST_INITHEAD(&surface_queue.list);
+       LIST_INITHEAD(&surface_queue.reset_noti);
+       surface_queue.impl = NULL;
+
+       error = tbm_surface_queue_reset(&surface_queue, width, height, format);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(width, surface_queue.width);
+       ASSERT_EQ(height, surface_queue.height);
+       ASSERT_EQ(format, surface_queue.format);
+}
+
+TEST(tbm_surface_queue_reset, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface_queue;
+       int width, height, format;
+
+       _init_test();
+
+       width = 200;
+       height = 100;
+       format = 10;
+       surface_queue.width = width;
+       surface_queue.height = height;
+       surface_queue.format = format;
+
+       error = tbm_surface_queue_reset(&surface_queue, width, height, format);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_reset, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+
+       _init_test();
+
+       error = tbm_surface_queue_reset(NULL, 0, 0, 0);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_queue_destroy() */
+
+TEST(tbm_surface_queue_destroy, work_flow_success_1)
+{
+       tbm_surface_queue_h surface_queue = calloc(1, sizeof(*surface_queue));
+       queue_notify *destory_item1;
+       queue_notify *destory_item2;
+       queue_notify *acquirable_item1;
+       queue_notify *acquirable_item2;
+       queue_notify *dequeuable_item1;
+       queue_notify *dequeuable_item2;
+       queue_notify *reset_item1;
+       queue_notify *reset_item2;
+
+       _init_test();
+
+       surface_queue->impl = NULL;
+       destory_item1 = calloc(1, sizeof(*destory_item1));
+       destory_item2 = calloc(1, sizeof(*destory_item2));
+       acquirable_item1 = calloc(1, sizeof(*acquirable_item1));
+       acquirable_item2 = calloc(1, sizeof(*acquirable_item2));
+       dequeuable_item1 = calloc(1, sizeof(*dequeuable_item1));
+       dequeuable_item2 = calloc(1, sizeof(*dequeuable_item2));
+       reset_item1 = calloc(1, sizeof(*reset_item1));
+       reset_item2 = calloc(1, sizeof(*reset_item2));
+       destory_item1->cb = ut_tbm_surface_queue_notify_cb;
+       destory_item2->cb = ut_tbm_surface_queue_notify_cb;
+       LIST_INITHEAD(&surface_queue->destory_noti);
+       LIST_INITHEAD(&surface_queue->list);
+       LIST_INITHEAD(&surface_queue->acquirable_noti);
+       LIST_INITHEAD(&surface_queue->dequeuable_noti);
+       LIST_INITHEAD(&surface_queue->reset_noti);
+       LIST_ADD(&destory_item1->link, &surface_queue->destory_noti);
+       LIST_ADD(&destory_item2->link, &surface_queue->destory_noti);
+       LIST_ADD(&dequeuable_item1->link, &surface_queue->dequeuable_noti);
+       LIST_ADD(&dequeuable_item2->link, &surface_queue->dequeuable_noti);
+       LIST_ADD(&acquirable_item1->link, &surface_queue->acquirable_noti);
+       LIST_ADD(&acquirable_item2->link, &surface_queue->acquirable_noti);
+       LIST_ADD(&reset_item1->link, &surface_queue->reset_noti);
+       LIST_ADD(&reset_item2->link, &surface_queue->reset_noti);
+
+       tbm_surface_queue_destroy(surface_queue);
+
+       ASSERT_GE(free_call_count, 9);
+}
+
+/* tbm_surface_queue_can_acquire() */
+
+TEST(tbm_surface_queue_can_acquire, work_flow_success_3)
+{
+       int actual = 0;
+       int expected = 1;
+       int wait = 0;
+       tbm_surface_queue_s surface_queue;
+       queue_node node;
+
+       _init_test();
+
+       _queue_init(&surface_queue.dirty_queue);
+       _queue_node_push_back(&surface_queue.dirty_queue, &node);
+
+       actual = tbm_surface_queue_can_acquire(&surface_queue, wait);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_surface_queue_can_acquire, work_flow_success_2)
+{
+       int actual = 1;
+       int expected = 0;
+       int wait = 0;
+       tbm_surface_queue_s surface_queue;
+
+       _init_test();
+
+       _queue_init(&surface_queue.dirty_queue);
+
+       actual = tbm_surface_queue_can_acquire(&surface_queue, wait);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_surface_queue_can_acquire, work_flow_success_1)
+{
+       int actual = 1;
+       int expected = 0;
+       int wait = 2;
+       tbm_surface_queue_s surface_queue;
+
+       _init_test();
+
+       _queue_init(&surface_queue.dirty_queue);
+       LIST_INITHEAD(&surface_queue.list);
+
+       actual = tbm_surface_queue_can_acquire(&surface_queue, wait);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_surface_queue_can_acquire, null_ptr_fail_1)
+{
+       int actual = 1;
+       int expected = 0;
+
+       _init_test();
+
+       actual = tbm_surface_queue_can_acquire(NULL, 0);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_surface_queue_acquire() */
+
+TEST(tbm_surface_queue_acquire, work_flow_success_4)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_s expected_surface;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s *surface;
+       queue_node node;
+
+       _init_test();
+
+       surface_queue.impl = NULL;
+       _queue_init(&surface_queue.dirty_queue);
+       node.surface = &expected_surface;
+       _queue_node_push_back(&surface_queue.dirty_queue, &node);
+
+       error = tbm_surface_queue_acquire(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_TRUE(surface == &expected_surface);
+}
+
+TEST(tbm_surface_queue_acquire, work_flow_success_3)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s *surface;
+       queue_node node;
+
+       _init_test();
+
+       surface_queue.impl = NULL;
+       _queue_init(&surface_queue.dirty_queue);
+       node.surface = NULL;
+       _queue_node_push_back(&surface_queue.dirty_queue, &node);
+
+       error = tbm_surface_queue_acquire(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_acquire, work_flow_success_2)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_EMPTY;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s *surface;
+
+       _init_test();
+
+       surface_queue.impl = NULL;
+       _queue_init(&surface_queue.dirty_queue);
+
+       error = tbm_surface_queue_acquire(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_acquire, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_EMPTY;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s *surface;
+       tbm_surface_queue_interface impl;
+
+       _init_test();
+
+       surface_queue.impl = &impl;
+       impl.acquire = ut_acquire;
+
+       error = tbm_surface_queue_acquire(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_acquire, null_ptr_fail_2)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_s surface_queue;
+
+       _init_test();
+
+       error = tbm_surface_queue_acquire(&surface_queue, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_acquire, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_s *surface;
+
+       _init_test();
+
+       error = tbm_surface_queue_acquire(NULL, &surface);
+
+       ASSERT_EQ(error, expected_error);
+
+}
+
+/* tbm_surface_queue_release() */
+
+TEST(tbm_surface_queue_release, work_flow_success_5)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s surface;
+       queue_node node;
+
+       _init_test();
+
+       _queue_init(&surface_queue.free_queue);
+       _queue_init(&surface_queue.dirty_queue);
+       LIST_INITHEAD(&surface_queue.list);
+       node.surface = &surface;
+       LIST_ADD(&node.link, &surface_queue.list);
+       surface_queue.impl = NULL;
+       LIST_INITHEAD(&surface_queue.dequeuable_noti);
+
+       error = tbm_surface_queue_release(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_release, work_flow_success_4)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s surface;
+       queue_node node;
+       tbm_surface_queue_interface impl;
+
+       _init_test();
+
+       _queue_init(&surface_queue.free_queue);
+       _queue_init(&surface_queue.dirty_queue);
+       LIST_INITHEAD(&surface_queue.list);
+       node.surface = &surface;
+       LIST_ADD(&node.link, &surface_queue.list);
+       surface_queue.impl = &impl;
+       impl.release = &ut_release;
+
+       error = tbm_surface_queue_release(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_release, work_flow_success_3)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s surface;
+       queue_node node;
+
+       _init_test();
+
+       _queue_init(&surface_queue.free_queue);
+       _queue_init(&surface_queue.dirty_queue);
+       LIST_INITHEAD(&surface_queue.list);
+       node.surface = &surface;
+       LIST_ADD(&node.item_link, &surface_queue.dirty_queue.head);
+
+       error = tbm_surface_queue_release(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_release, work_flow_success_2)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s surface;
+       queue_node node;
+
+       _init_test();
+
+       _queue_init(&surface_queue.free_queue);
+       _queue_init(&surface_queue.dirty_queue);
+       LIST_INITHEAD(&surface_queue.list);
+       node.surface = &surface;
+       LIST_ADD(&node.item_link, &surface_queue.free_queue.head);
+
+       error = tbm_surface_queue_release(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_release, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s surface;
+
+       _init_test();
+
+       _queue_init(&surface_queue.free_queue);
+       _queue_init(&surface_queue.dirty_queue);
+       LIST_INITHEAD(&surface_queue.list);
+
+       error = tbm_surface_queue_release(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_release, null_ptr_fail_2)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_s surface_queue;
+
+       _init_test();
+
+       error = tbm_surface_queue_release(&surface_queue, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_release, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_s surface;
+
+       _init_test();
+
+       error = tbm_surface_queue_release(NULL, &surface);
+
+       ASSERT_EQ(error, expected_error);
+
+}
+
+/* tbm_surface_queue_can_dequeue() */
+
+TEST(tbm_surface_queue_can_dequeue, work_flow_success_3)
+{
+       int actual = 0;
+       int expected = 1;
+       int wait = 0;
+       tbm_surface_queue_s surface_queue;
+       queue_node node;
+
+       _init_test();
+
+       LIST_INITHEAD(&surface_queue.free_queue.head);
+       surface_queue.free_queue.count = 0;
+       surface_queue.impl = NULL;
+       LIST_INITHEAD(&surface_queue.free_queue.head);
+       LIST_ADD(&node.item_link, &surface_queue.free_queue.head);
+
+       actual = tbm_surface_queue_can_dequeue(&surface_queue, wait);
+
+       ASSERT_EQ(actual, expected);
+}
+
+
+TEST(tbm_surface_queue_can_dequeue, work_flow_success_2)
+{
+       int actual = 1;
+       int expected = 0;
+       int wait = 0;
+       tbm_surface_queue_s surface_queue;
+
+       _init_test();
+
+       LIST_INITHEAD(&surface_queue.free_queue.head);
+       surface_queue.free_queue.count = 0;
+       surface_queue.impl = NULL;
+
+       actual = tbm_surface_queue_can_dequeue(&surface_queue, wait);
+
+       ASSERT_EQ(actual, expected);
+}
+
+
+TEST(tbm_surface_queue_can_dequeue, work_flow_success_1)
+{
+       int actual = 0;
+       int expected = 1;
+       int wait = 2;
+       tbm_surface_queue_s surface_queue;
+
+       _init_test();
+
+       LIST_INITHEAD(&surface_queue.free_queue.head);
+       surface_queue.free_queue.count = 0;
+       surface_queue.impl = NULL;
+
+       actual = tbm_surface_queue_can_dequeue(&surface_queue, wait);
+
+       ASSERT_EQ(actual, expected);
+}
+
+TEST(tbm_surface_queue_can_dequeue, null_ptr_fail_1)
+{
+       int actual = 1;
+       int expected = 0;
+
+       _init_test();
+
+       actual = tbm_surface_queue_can_dequeue(NULL, 0);
+
+       ASSERT_EQ(actual, expected);
+}
+
+/* tbm_surface_queue_dequeue() */
+
+TEST(tbm_surface_queue_dequeue, work_flow_success_3)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s *surface;
+       tbm_surface_s expected_surface;
+       queue_node node;
+
+       _init_test();
+
+       surface_queue.impl = NULL;
+       node.surface = &expected_surface;
+       LIST_INITHEAD(&surface_queue.free_queue.head);
+       LIST_ADD(&node.item_link, &surface_queue.free_queue.head);
+
+       error = tbm_surface_queue_dequeue(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_TRUE(surface == &expected_surface);
+}
+
+TEST(tbm_surface_queue_dequeue, work_flow_success_2)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s *surface;
+       queue_node node;
+
+       _init_test();
+
+       surface_queue.impl = NULL;
+       node.surface = NULL;
+       LIST_INITHEAD(&surface_queue.free_queue.head);
+       LIST_ADD(&node.item_link, &surface_queue.free_queue.head);
+
+       error = tbm_surface_queue_dequeue(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_dequeue, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_EMPTY;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s *surface;
+       tbm_surface_queue_interface impl;
+
+       _init_test();
+
+       surface_queue.impl = &impl;
+       impl.dequeue = ut_dequeue;
+
+       error = tbm_surface_queue_dequeue(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_dequeue, null_ptr_fail_2)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_s surface_queue;
+
+       _init_test();
+
+       error = tbm_surface_queue_dequeue(&surface_queue, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_dequeue, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_s *surface;
+
+       _init_test();
+
+       error = tbm_surface_queue_dequeue(NULL, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_queue_enqueue() */
+
+TEST(tbm_surface_queue_enqueue, work_flow_success_5)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s surface;
+       queue_node node;
+
+       _init_test();
+
+       node.surface = &surface;
+       LIST_INITHEAD(&surface_queue.free_queue.head);
+       LIST_INITHEAD(&surface_queue.dirty_queue.head);
+       LIST_INITHEAD(&surface_queue.list);
+       LIST_ADD(&node.link, &surface_queue.list);
+       tbm_surface_queue_interface impl;
+       surface_queue.impl = &impl;
+       impl.enqueue = ut_enqueue;
+       surface_queue.dirty_queue.count = 0;
+       LIST_INITHEAD(&surface_queue.dirty_queue.head);
+       LIST_INITHEAD(&surface_queue.acquirable_noti);
+
+       error = tbm_surface_queue_enqueue(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_enqueue, work_flow_success_4)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s surface;
+       queue_node node;
+
+       _init_test();
+
+       node.surface = &surface;
+       LIST_INITHEAD(&surface_queue.free_queue.head);
+       LIST_INITHEAD(&surface_queue.dirty_queue.head);
+       LIST_INITHEAD(&surface_queue.list);
+       LIST_ADD(&node.link, &surface_queue.list);
+       surface_queue.impl = NULL;
+       surface_queue.dirty_queue.count = 0;
+       LIST_INITHEAD(&surface_queue.dirty_queue.head);
+       LIST_INITHEAD(&surface_queue.acquirable_noti);
+
+       error = tbm_surface_queue_enqueue(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_enqueue, work_flow_success_3)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s surface;
+       queue_node node;
+
+       _init_test();
+
+       LIST_INITHEAD(&surface_queue.free_queue.head);
+       LIST_INITHEAD(&surface_queue.dirty_queue.head);
+       LIST_INITHEAD(&surface_queue.list);
+       LIST_ADD(&node.item_link, &surface_queue.dirty_queue.head);
+
+       error = tbm_surface_queue_enqueue(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_enqueue, work_flow_success_2)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s surface;
+       queue_node node;
+
+       _init_test();
+
+       LIST_INITHEAD(&surface_queue.free_queue.head);
+       LIST_INITHEAD(&surface_queue.dirty_queue.head);
+       LIST_INITHEAD(&surface_queue.list);
+       LIST_ADD(&node.item_link, &surface_queue.free_queue.head);
+
+       error = tbm_surface_queue_enqueue(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_enqueue, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_s surface_queue;
+       tbm_surface_s surface;
+
+       _init_test();
+
+       LIST_INITHEAD(&surface_queue.free_queue.head);
+       LIST_INITHEAD(&surface_queue.dirty_queue.head);
+       LIST_INITHEAD(&surface_queue.list);
+
+       error = tbm_surface_queue_enqueue(&surface_queue, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_enqueue, null_ptr_fail_2)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_SURFACE;
+       tbm_surface_queue_s surface_queue;
+
+       _init_test();
+
+       error = tbm_surface_queue_enqueue(&surface_queue, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tbm_surface_queue_enqueue, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_s surface;
+
+       _init_test();
+
+       error = tbm_surface_queue_enqueue(NULL, &surface);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_queue_remove_reset_cb() */
+
+TEST(tbm_surface_queue_remove_reset_cb, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface;
+       queue_notify *item;
+       int data;
+       queue_notify *find_item;
+       queue_notify *tmp;
+
+       _init_test();
+
+       item = (queue_notify *)calloc(1, sizeof(queue_notify));
+       FREE_TESTED_PTR = item;
+
+       LIST_INITHEAD(&item->link);
+       item->cb = ut_tbm_surface_queue_notify_cb;
+       item->data = &data;
+
+       LIST_INITHEAD(&surface.reset_noti);
+       LIST_ADDTAIL(&item->link, &surface.reset_noti);
+
+       find_item = NULL;
+
+       error = tbm_surface_queue_remove_reset_cb(&surface,
+                                                                                        ut_tbm_surface_queue_notify_cb,
+                                                                                        &data);
+
+       ASSERT_EQ(error, expected_error);
+       if (!LIST_IS_EMPTY(&surface.reset_noti)) {
+               LIST_FOR_EACH_ENTRY_SAFE(find_item, tmp, &surface.reset_noti, link) {
+                       if (find_item->data == &data)
+                               break;
+               }
+       }
+       ASSERT_TRUE(find_item == NULL);
+       ASSERT_EQ(free_called_for_tested_ptr, 1);
+}
+
+TEST(tbm_surface_queue_remove_reset_cb, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+
+       _init_test();
+
+       error = tbm_surface_queue_remove_reset_cb(NULL, NULL, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_queue_add_reset_cb() */
+
+TEST(tbm_surface_queue_add_reset_cb, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface;
+       int data;
+       queue_notify *item;
+       queue_notify *tmp;
+
+       _init_test();
+
+       LIST_INITHEAD(&surface.reset_noti);
+
+       error = tbm_surface_queue_add_reset_cb(&surface,
+                                                                                        ut_tbm_surface_queue_notify_cb,
+                                                                                        &data);
+
+       ASSERT_EQ(error, expected_error);
+       if (!LIST_IS_EMPTY(&surface.reset_noti)) {
+               LIST_FOR_EACH_ENTRY_SAFE(item, tmp, &surface.reset_noti, link) {
+                       if (item->data == &data && item->cb == ut_tbm_surface_queue_notify_cb)
+                               break;
+               }
+       }
+       ASSERT_TRUE(item != NULL);
+       free(item);
+}
+
+TEST(tbm_surface_queue_add_reset_cb, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+
+       _init_test();
+
+       error = tbm_surface_queue_add_reset_cb(NULL, NULL, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_queue_get_size() */
+
+TEST(tbm_surface_queue_get_size, work_flow_success_1)
+{
+       int size = 10;
+       int expected_size = 1000;
+       tbm_surface_queue_s surface;
+
+       _init_test();
+
+       surface.queue_size = expected_size;
+
+       size = tbm_surface_queue_get_size(&surface);
+
+       ASSERT_EQ(size, expected_size);
+}
+
+TEST(tbm_surface_queue_get_size, null_ptr_fail_1)
+{
+       int size = 10;
+       int expected_size = 0;
+
+       _init_test();
+
+       size = tbm_surface_queue_get_size(NULL);
+
+       ASSERT_EQ(size, expected_size);
+}
+
+/* tbm_surface_queue_get_format() */
+
+TEST(tbm_surface_queue_get_format, work_flow_success_1)
+{
+       int format = 10;
+       int expected_format = 20;
+       tbm_surface_queue_s surface;
+
+       _init_test();
+
+       surface.format = expected_format;
+
+       format = tbm_surface_queue_get_format(&surface);
+
+       ASSERT_EQ(format, expected_format);
+}
+
+TEST(tbm_surface_queue_get_format, null_ptr_fail_1)
+{
+       int format = 10;
+       int expected_format = 0;
+
+       _init_test();
+
+       format = tbm_surface_queue_get_format(NULL);
+
+       ASSERT_EQ(format, expected_format);
+}
+
+/* tbm_surface_queue_get_height() */
+
+TEST(tbm_surface_queue_get_height, work_flow_success_1)
+{
+       int height = 0;
+       int expected_height = 50;
+       tbm_surface_queue_s surface;
+
+       _init_test();
+
+       surface.height = expected_height;
+
+       height = tbm_surface_queue_get_height(&surface);
+
+       ASSERT_EQ(height, expected_height);
+}
+
+TEST(tbm_surface_queue_get_height, null_ptr_fail_1)
+{
+       int height = 10;
+       int expected_height = 0;
+
+       _init_test();
+
+       height = tbm_surface_queue_get_height(NULL);
+
+       ASSERT_EQ(height, expected_height);
+}
+
+/* tbm_surface_queue_get_width() */
+
+TEST(tbm_surface_queue_get_width, work_flow_success_1)
+{
+       int width = 0;
+       int expected_width = 50;
+       tbm_surface_queue_s surface;
+
+       _init_test();
+
+       surface.width = expected_width;
+
+       width = tbm_surface_queue_get_width(&surface);
+
+       ASSERT_EQ(width, expected_width);
+}
+
+TEST(tbm_surface_queue_get_width, null_ptr_fail_1)
+{
+       int width = 10;
+       int expected_width = 0;
+
+       _init_test();
+
+       width = tbm_surface_queue_get_width(NULL);
+
+       ASSERT_EQ(width, expected_width);
+}
+
+/* tbm_surface_queue_set_alloc_cb() */
+
+TEST(tbm_surface_queue_set_alloc_cb, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface;
+       int data;
+
+       _init_test();
+
+       error = tbm_surface_queue_set_alloc_cb(&surface, ut_tbm_surface_alloc_cb,
+                                                                                  ut_tbm_surface_free_cb, &data);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_TRUE(surface.alloc_cb == ut_tbm_surface_alloc_cb);
+       ASSERT_TRUE(surface.free_cb == ut_tbm_surface_free_cb);
+       ASSERT_TRUE(surface.alloc_cb_data == &data);
+}
+
+TEST(tbm_surface_queue_set_alloc_cb, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+
+       _init_test();
+
+       error = tbm_surface_queue_set_alloc_cb(NULL, NULL, NULL, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_queue_remove_acquirable_cb() */
+
+TEST(tbm_surface_queue_remove_acquirable_cb, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface;
+       int data;
+       queue_notify *item;
+       queue_notify *find_item;
+       queue_notify *tmp;
+
+       _init_test();
+
+       item = (queue_notify *)calloc(1, sizeof(queue_notify));
+       FREE_TESTED_PTR = item;
+
+       LIST_INITHEAD(&item->link);
+       item->cb = ut_tbm_surface_queue_notify_cb;
+       item->data = &data;
+
+       LIST_INITHEAD(&surface.acquirable_noti);
+       LIST_ADDTAIL(&item->link, &surface.acquirable_noti);
+
+       find_item = NULL;
+
+       error = tbm_surface_queue_remove_acquirable_cb(&surface,
+                                                                                        ut_tbm_surface_queue_notify_cb,
+                                                                                        &data);
+
+       ASSERT_EQ(error, expected_error);
+       if (!LIST_IS_EMPTY(&surface.acquirable_noti)) {
+               LIST_FOR_EACH_ENTRY_SAFE(find_item, tmp, &surface.acquirable_noti, link) {
+                       if (find_item->data == &data)
+                               break;
+               }
+       }
+       ASSERT_TRUE(find_item == NULL);
+       ASSERT_EQ(free_called_for_tested_ptr, 1);
+}
+
+TEST(tbm_surface_queue_remove_acquirable_cb, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+
+       _init_test();
+
+       error = tbm_surface_queue_remove_acquirable_cb(NULL, NULL, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_queue_add_acquirable_cb() */
+
+TEST(tbm_surface_queue_add_acquirable_cb, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface;
+       int data;
+       queue_notify *item;
+       queue_notify *tmp;
+       tbm_surface_queue_notify_cb cb;
+       tbm_surface_queue_notify_cb expected_cb;
+
+       _init_test();
+
+       LIST_INITHEAD(&surface.acquirable_noti);
+
+       error = tbm_surface_queue_add_acquirable_cb(&surface,
+                                                                                        ut_tbm_surface_queue_notify_cb,
+                                                                                        &data);
+
+       ASSERT_EQ(error, expected_error);
+       if (!LIST_IS_EMPTY(&surface.acquirable_noti)) {
+               LIST_FOR_EACH_ENTRY_SAFE(item, tmp, &surface.acquirable_noti, link) {
+                       if (item->data == &data)
+                               break;
+               }
+       }
+       ASSERT_TRUE(item != NULL);
+       cb = item->cb;
+       expected_cb = ut_tbm_surface_queue_notify_cb;
+       free(item);
+       ASSERT_TRUE(cb == expected_cb);
+}
+
+TEST(tbm_surface_queue_add_acquirable_cb, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+
+       _init_test();
+
+       error = tbm_surface_queue_add_acquirable_cb(NULL, NULL, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_queue_remove_dequeuable_cb() */
+
+TEST(tbm_surface_queue_remove_dequeuable_cb, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface;
+       int data;
+       queue_notify *item;
+       queue_notify *find_item;
+       queue_notify *tmp;
+
+       _init_test();
+
+       item = (queue_notify *)calloc(1, sizeof(queue_notify));
+       FREE_TESTED_PTR = item;
+
+       LIST_INITHEAD(&item->link);
+       item->cb = ut_tbm_surface_queue_notify_cb;
+       item->data = &data;
+
+       LIST_INITHEAD(&surface.dequeuable_noti);
+       LIST_ADDTAIL(&item->link, &surface.dequeuable_noti);
+
+       find_item = NULL;
+
+       error = tbm_surface_queue_remove_dequeuable_cb(&surface,
+                                                                                        ut_tbm_surface_queue_notify_cb,
+                                                                                        &data);
+
+       ASSERT_EQ(error, expected_error);
+       if (!LIST_IS_EMPTY(&surface.dequeuable_noti)) {
+               LIST_FOR_EACH_ENTRY_SAFE(find_item, tmp, &surface.dequeuable_noti, link) {
+                       if (find_item->data == &data)
+                               break;
+               }
+       }
+       ASSERT_TRUE(find_item == NULL);
+       ASSERT_EQ(free_called_for_tested_ptr, 1);
+}
+
+TEST(tbm_surface_queue_remove_dequeuable_cb, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+
+       _init_test();
+
+       error = tbm_surface_queue_remove_dequeuable_cb(NULL, NULL, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_queue_add_dequeuable_cb() */
+
+TEST(tbm_surface_queue_add_dequeuable_cb, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface;
+       int data;
+       queue_notify *item;
+       queue_notify *tmp;
+
+       _init_test();
+
+       LIST_INITHEAD(&surface.dequeuable_noti);
+
+       error = tbm_surface_queue_add_dequeuable_cb(&surface,
+                                                                                        ut_tbm_surface_queue_notify_cb,
+                                                                                        &data);
+
+       ASSERT_EQ(error, expected_error);
+       if (!LIST_IS_EMPTY(&surface.dequeuable_noti)) {
+               LIST_FOR_EACH_ENTRY_SAFE(item, tmp, &surface.dequeuable_noti, link) {
+                       if (item->data == &data)
+                               break;
+               }
+       }
+       ASSERT_TRUE(item != NULL);
+       tbm_surface_queue_notify_cb cb = item->cb;
+       tbm_surface_queue_notify_cb expected_cb = ut_tbm_surface_queue_notify_cb;
+       free(item);
+       ASSERT_TRUE(cb == expected_cb);
+}
+
+TEST(tbm_surface_queue_add_dequeuable_cb, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+
+       _init_test();
+
+       error = tbm_surface_queue_add_dequeuable_cb(NULL, NULL, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_queue_remove_destroy_cb() */
+
+TEST(tbm_surface_queue_remove_destroy_cb, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface;
+       int data;
+       queue_notify *item;
+       queue_notify *find_item;
+       queue_notify *tmp;
+
+       _init_test();
+
+       item = (queue_notify *)calloc(1, sizeof(queue_notify));
+       FREE_TESTED_PTR = item;
+
+       LIST_INITHEAD(&item->link);
+       item->cb = ut_tbm_surface_queue_notify_cb;
+       item->data = &data;
+
+       LIST_INITHEAD(&surface.destory_noti);
+       LIST_ADDTAIL(&item->link, &surface.destory_noti);
+
+       find_item = NULL;
+
+       error = tbm_surface_queue_remove_destroy_cb(&surface,
+                                                                                        ut_tbm_surface_queue_notify_cb,
+                                                                                        &data);
+
+       ASSERT_EQ(error, expected_error);
+       if (!LIST_IS_EMPTY(&surface.destory_noti)) {
+               LIST_FOR_EACH_ENTRY_SAFE(find_item, tmp, &surface.destory_noti, link) {
+                       if (find_item->data == &data)
+                               break;
+               }
+       }
+       ASSERT_TRUE(find_item == NULL);
+       ASSERT_EQ(free_called_for_tested_ptr, 1);
+}
+
+TEST(tbm_surface_queue_remove_destroy_cb, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+
+       _init_test();
+
+       error = tbm_surface_queue_remove_destroy_cb(NULL, NULL, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+/* tbm_surface_queue_add_destroy_cb() */
+
+TEST(tbm_surface_queue_add_destroy_cb, work_flow_success_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_s surface;
+       int data;
+       queue_notify *item;
+       queue_notify *tmp;
+       tbm_surface_queue_notify_cb cb;
+       tbm_surface_queue_notify_cb expected_cb;
+
+       _init_test();
+
+       LIST_INITHEAD(&surface.destory_noti);
+
+       error = tbm_surface_queue_add_destroy_cb(&surface,
+                                                                                        ut_tbm_surface_queue_notify_cb,
+                                                                                        &data);
+
+       ASSERT_EQ(error, expected_error);
+       if (!LIST_IS_EMPTY(&surface.destory_noti)) {
+               LIST_FOR_EACH_ENTRY_SAFE(item, tmp, &surface.destory_noti, link) {
+                       if (item->data == &data)
+                               break;
+               }
+       }
+       ASSERT_TRUE(item != NULL);
+       cb = item->cb;
+       expected_cb = ut_tbm_surface_queue_notify_cb;
+       free(item);
+       ASSERT_EQ(cb, expected_cb);
+}
+
+TEST(tbm_surface_queue_add_destroy_cb, null_ptr_fail_1)
+{
+       tbm_surface_queue_error_e error = TBM_SURFACE_QUEUE_ERROR_NONE;
+       tbm_surface_queue_error_e expected_error =
+                       TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE;
+
+       _init_test();
+
+       error = tbm_surface_queue_add_destroy_cb(NULL, NULL, NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
diff --git a/ut/stubs/pthread_stubs.h b/ut/stubs/pthread_stubs.h
new file mode 100644 (file)
index 0000000..2256a4d
--- /dev/null
@@ -0,0 +1,55 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
+ *
+**************************************************************************/
+
+#ifndef _PTHREAD_STUBS_H
+#define _PTHREAD_STUBS_H
+
+#include <pthread.h>
+#include <stdio.h>
+
+static int PTHREAD_MUTEX_INIT_ERROR;
+
+static int ut_pthread_mutex_lock(pthread_mutex_t * __mutex) {}
+
+static int ut_pthread_mutex_unlock(pthread_mutex_t * __mutex) {}
+
+static int ut_pthread_mutex_init(pthread_mutex_t * __mutex,
+                                                                const pthread_mutexattr_t * __mutexattr)
+{
+       if (PTHREAD_MUTEX_INIT_ERROR) {
+               return PTHREAD_MUTEX_INIT_ERROR;
+       }
+
+       return 0;
+}
+
+static int ut_pthread_cond_signal(pthread_cond_t *cond) {}
+
+static int ut_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) {}
+
+#endif /* _PTHREAD_STUBS_H */
diff --git a/ut/stubs/stdlib_stubs.cpp b/ut/stubs/stdlib_stubs.cpp
new file mode 100644 (file)
index 0000000..196e186
--- /dev/null
@@ -0,0 +1,66 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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 "stdlib_stubs.h"
+
+int CALLOC_ERROR = 0;
+int FREE_CALLED = 0;
+void *FREE_PTR = NULL;
+void *FREE_TESTED_PTR = 0;
+int free_called_for_tested_ptr = 0;
+int free_call_count = 0;
+int GETENV_ERROR = 0;
+
+void *ut_calloc(size_t nmemb, size_t size)
+{
+       if (CALLOC_ERROR) {
+               return NULL;
+       }
+
+       return calloc(nmemb, size);
+}
+
+void ut_free(void *ptr)
+{
+       if (FREE_TESTED_PTR == ptr) {
+               free_called_for_tested_ptr = 1;
+       }
+       FREE_PTR = ptr;
+       FREE_CALLED = 1;
+       free(ptr);
+       free_call_count++;
+}
+
+char *ut_getenv(const char *name)
+{
+       if (GETENV_ERROR) {
+               return NULL;
+       }
+
+       return "getenv";
+}
diff --git a/ut/stubs/stdlib_stubs.h b/ut/stubs/stdlib_stubs.h
new file mode 100644 (file)
index 0000000..096e449
--- /dev/null
@@ -0,0 +1,48 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
+ *
+**************************************************************************/
+
+#ifndef _STDLIB_STUBS_H
+#define _STDLIB_STUBS_H
+
+#include <stdlib.h>
+
+extern int CALLOC_ERROR;
+extern int FREE_CALLED;
+extern void *FREE_PTR;
+extern void *FREE_TESTED_PTR;
+extern int free_called_for_tested_ptr;
+extern int free_call_count;
+extern int GETENV_ERROR;
+
+void *ut_calloc(size_t nmemb, size_t size);
+
+void ut_free(void *ptr);
+
+char *ut_getenv(const char *name);
+
+#endif /* _STDLIB_STUBS_H */
diff --git a/ut/stubs/tbm_bufmgr_stubs.h b/ut/stubs/tbm_bufmgr_stubs.h
new file mode 100644 (file)
index 0000000..30d4cc9
--- /dev/null
@@ -0,0 +1,150 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@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, sub license, 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS 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.
+ *
+**************************************************************************/
+
+#ifndef TBM_BUFMGR_STUBS_H
+#define TBM_BUFMGR_STUBS_H
+
+#include <tbm_bufmgr.h>
+
+/* HELPER FUNCTIONS */
+
+static int bo_size = 100;
+static int bo2_size = 100;
+static void *ret_bo = "bo_alloc";
+static int UT_TBM_ERROR = 0;
+static int TBM_BO_ALLOC_ERROR = 0;
+static int TBM_BO_IMPORT_ERROR = 0;
+static int bo_ret_flags = TBM_BO_SCANOUT;
+
+static int ut_bo_size(tbm_bo bo)
+{
+       return bo_size;
+}
+
+static int ut_bo2_size(tbm_bo bo)
+{
+       return bo2_size;
+}
+
+static void *ut_bo_alloc(tbm_bo bo, int size, int flags)
+{
+       if (TBM_BO_ALLOC_ERROR) {
+               return NULL;
+       }
+
+       return ret_bo;
+}
+
+static void *ut_bo_import(tbm_bo bo, unsigned int key)
+{
+       if (TBM_BO_IMPORT_ERROR) {
+               return NULL;
+       }
+
+       return ret_bo;
+}
+
+static int ut_bo_get_flags(tbm_bo bo)
+{
+       return bo_ret_flags;
+}
+
+static void *ut_bo_import_fd(tbm_bo bo, tbm_fd fd)
+{
+       if (TBM_BO_IMPORT_ERROR) {
+               return NULL;
+       }
+
+       return ret_bo;
+}
+
+static unsigned int ut_bo_export(tbm_bo bo)
+{
+       if (UT_TBM_ERROR) {
+               return 0;
+       }
+
+       return 1;
+}
+
+static tbm_fd ut_bo_export_fd(tbm_bo bo)
+{
+       if (UT_TBM_ERROR) {
+               return -1;
+       }
+
+       return 1;
+}
+
+static tbm_bo_handle ut_bo_get_handle(tbm_bo bo, int device)
+{
+       tbm_bo_handle ret;
+
+       if (UT_TBM_ERROR) {
+               ret.ptr = NULL;
+       } else {
+               ret.ptr = (void *)12;
+       }
+
+       return ret;
+}
+
+static tbm_bo_handle ut_bo_map(tbm_bo bo, int device, int opt)
+{
+       tbm_bo_handle ret;
+
+       if (UT_TBM_ERROR) {
+               ret.ptr = NULL;
+       } else {
+               ret.ptr = (void *)12;
+       }
+
+       return ret;
+}
+
+static int ut_bo_unmap(tbm_bo bo)
+{
+       if (UT_TBM_ERROR) {
+               return 0;
+       }
+
+       return 1;
+}
+
+static void ut_tbm_data_free(void *user_data) {}
+
+static int ut_bufmgr_bind_native_display(tbm_bufmgr bufmgr, void *NativeDisplay)
+{
+       if (UT_TBM_ERROR) {
+               return 0;
+       }
+
+       return 1;
+}
+
+#endif /* TBM_BUFMGR_STUBS_H */