#include <tbm_bufmgr.h>
#include "ut.h"
-TEST_F(UtBoInit, tbm_bo_get_flags_success)
+/* tbm_bufmgr_init() */
+
+TEST_F(UtInit, BufmgrInitSuccessIniteTwice)
+{
+ tbm_bufmgr bufmgr2;
+ tbm_bo bo;
+
+ UtBufmgrInit();
+
+ bufmgr2 = tbm_bufmgr_init(-1);
+ tbm_bufmgr_deinit(bufmgr2);
+
+ ASSERT_TRUE(bufmgr2 != NULL);
+ ASSERT_TRUE(bufmgr == bufmgr2);
+
+ bo = tbm_bo_alloc(bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ ASSERT_NE(bo, NULL);
+}
+
+/* tbm_bo_alloc() */
+
+TEST_F(UtBufmgrInit, BoAllocFailNulbufmgr)
+{
+ tbm_bo bo;
+
+ bo = tbm_bo_alloc(NULL, 128 * 128, TBM_BO_DEFAULT);
+
+ ASSERT_EQ(bo, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoAllocFailSizeLessThenZero)
+{
+ tbm_bo bo;
+
+ bo = tbm_bo_alloc(bufmgr, -1, TBM_BO_DEFAULT);
+
+ ASSERT_EQ(bo, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoAllocFailNoValidBufmgr)
+{
+ tbm_bo bo;
+ int bufmgr;
+
+ bo = tbm_bo_alloc((tbm_bufmgr)&bufmgr, -1, TBM_BO_DEFAULT);
+
+ ASSERT_EQ(bo, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoAllocSuccess)
+{
+ tbm_bo ret_bo;
+
+ ret_bo = tbm_bo_alloc(bufmgr, 128 * 128, TBM_BO_DEFAULT);
+
+ ASSERT_NE(ret_bo, NULL);
+}
+
+/* tbm_bo_ref() */
+
+TEST(tbm_bo_ref, BoRefFailBufmgrWasNotInited)
+{
+ int bo;
+ tbm_bo ret_bo;
+
+ ret_bo = tbm_bo_ref((tbm_bo)&bo);
+
+ ASSERT_EQ(ret_bo, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoRefFailNullBo)
+{
+ tbm_bo ret_bo;
+
+ ret_bo = tbm_bo_ref(NULL);
+
+ ASSERT_EQ(ret_bo, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoRefFailNoValidBo)
+{
+ tbm_bo ret_bo;
+ int bo;
+
+ ret_bo = tbm_bo_ref((tbm_bo)&bo);
+
+ ASSERT_EQ(ret_bo, NULL);
+}
+
+TEST_F(UtBoInit, BoRefSuccess)
+{
+ tbm_bo ret_bo;
+
+ ret_bo = tbm_bo_ref(bo);
+
+ ASSERT_NE(ret_bo, NULL);
+}
+
+/* tbm_bo_unref() */
+
+TEST_F(UtBoInit, BoUnrefSuccess)
+{
+ tbm_bo ret_bo;
+
+ tbm_bo_unref(bo);
+
+ ret_bo = tbm_bo_ref(bo);
+
+ ASSERT_EQ(ret_bo, NULL);
+}
+
+/* tbm_bo_map() */
+
+TEST(tbm_bo_map, BoMapFailBufmgrWasNotInited)
+{
+ int bo;
+ tbm_bo_handle bo_handle;
+
+ bo_handle = tbm_bo_map((tbm_bo)&bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
+
+ ASSERT_EQ(bo_handle.ptr, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoMapFailNullBo)
+{
+ tbm_bo_handle bo_handle;
+
+ bo_handle = tbm_bo_map(NULL, TBM_DEVICE_CPU, TBM_OPTION_READ);
+
+ ASSERT_EQ(bo_handle.ptr, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoMapFailNoValidBo)
+{
+ tbm_bo_handle bo_handle;
+ int bo;
+
+ bo_handle = tbm_bo_map((tbm_bo)&bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
+
+ ASSERT_EQ(bo_handle.ptr, NULL);
+}
+
+TEST_F(UtBoInit, BoMapSuccess)
+{
+ tbm_bo_handle bo_handle;
+
+ bo_handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
+
+ ASSERT_NE(bo_handle.ptr, NULL);
+}
+
+/* tbm_bo_unmap() */
+
+TEST(tbm_bo_unmap, BoUnmapFailBufmgrWasNotInited)
+{
+ int bo;
+ int ret;
+
+ ret = tbm_bo_unmap((tbm_bo)&bo);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBufmgrInit, BoUnmapFailNullBo)
+{
+ int ret;
+
+ ret = tbm_bo_unmap(NULL);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBufmgrInit, BoUnmapFailNoValidBo)
+{
+ int ret;
+ int bo;
+
+ ret = tbm_bo_unmap((tbm_bo)&bo);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoUnmapFailUnmapWithoutMap)
+{
+ int ret;
+
+ ret = tbm_bo_unmap(bo);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoUnmapSuccess)
+{
+ int ret;
+ tbm_bo_handle bo_handle;
+
+ bo_handle = tbm_bo_map(bo, TBM_DEVICE_CPU, TBM_OPTION_READ);
+ ASSERT_NE(bo_handle.ptr, NULL);
+
+ ret = tbm_bo_unmap(bo);
+
+ ASSERT_NE(ret, 0);
+}
+
+/* tbm_bo_get_handle() */
+
+TEST(tbm_bo_get_handle, BoGetHandleFailBufmgrWasNotInited)
+{
+ int bo;
+ tbm_bo_handle bo_handle;
+
+ bo_handle = tbm_bo_get_handle((tbm_bo)&bo, TBM_DEVICE_DEFAULT);
+
+ ASSERT_EQ(bo_handle.ptr, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoGetHandleFailNullBo)
+{
+ tbm_bo_handle bo_handle;
+
+ bo_handle = tbm_bo_get_handle(NULL, TBM_DEVICE_DEFAULT);
+
+ ASSERT_EQ(bo_handle.ptr, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoGetHandleFailNoValidBo)
+{
+ tbm_bo_handle bo_handle;
+ int bo;
+
+ bo_handle = tbm_bo_get_handle((tbm_bo)&bo, TBM_DEVICE_DEFAULT);
+
+ ASSERT_EQ(bo_handle.ptr, NULL);
+}
+
+TEST_F(UtBoInit, BoGetHandleSuccess)
+{
+ tbm_bo_handle bo_handle;
+
+ bo_handle = tbm_bo_get_handle(bo, TBM_DEVICE_DEFAULT);
+
+ ASSERT_NE(bo_handle.ptr, NULL);
+}
+
+/* tbm_bo_export() */
+
+TEST(tbmBoExport, BoExportFailBufmgrWasNotInited)
+{
+ int bo;
+ tbm_key ret_key;
+
+ ret_key = tbm_bo_export((tbm_bo)&bo);
+
+ ASSERT_EQ(ret_key, 0);
+}
+
+TEST_F(UtBufmgrInit, BoExportFailNullBo)
+{
+ tbm_key ret_key;
+
+ if (!(bufmgr_capability == TBM_BUFMGR_CAPABILITY_SHARE_KEY))
+ return;
+
+ ret_key = tbm_bo_export(NULL);
+
+ ASSERT_EQ(ret_key, 0);
+}
+
+TEST_F(UtBufmgrInit, BoExportFailNoValidBo)
+{
+ tbm_key ret_key;
+ int bo;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_KEY))
+ return;
+
+ ret_key = tbm_bo_export((tbm_bo)&bo);
+
+ ASSERT_EQ(ret_key, 0);
+}
+
+TEST_F(UtBoInit, BoExportSuccess)
+{
+ tbm_key ret_key;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_KEY))
+ return;
+
+ ret_key = tbm_bo_export(bo);
+
+ ASSERT_NE(ret_key, NULL);
+}
+
+/* tbmBoExportfd() */
+
+TEST(tbmBoExportfd, BoExportFdFailBufmgrWasNotInited)
+{
+ int bo;
+ tbm_key ret_fd;
+
+ ret_fd = tbm_bo_export_fd((tbm_bo)&bo);
+
+ ASSERT_EQ(ret_fd, -1);
+}
+
+TEST_F(UtBufmgrInit, BoExportFdFailNullBo)
+{
+ tbm_key ret_fd;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_FD))
+ return;
+
+ ret_fd = tbm_bo_export_fd(NULL);
+
+ ASSERT_EQ(ret_fd, -1);
+}
+
+TEST_F(UtBufmgrInit, BoExportFdFailNoValidBo)
+{
+ tbm_key ret_fd;
+ int bo;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_FD))
+ return;
+
+ ret_fd = tbm_bo_export_fd((tbm_bo)&bo);
+
+ ASSERT_EQ(ret_fd, -1);
+}
+
+TEST_F(UtBoInit, BoExportFdSuccess)
+{
+ tbm_key ret_fd;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_FD))
+ return;
+
+ ret_fd = tbm_bo_export_fd(bo);
+
+ ASSERT_NE(ret_fd, -1);
+}
+
+/* tbm_bo_import() */
+
+TEST(tbmBoImport, BoImportFailBufmgrWasNotInited)
+{
+ int bufmgr;
+ tbm_bo ret_bo;
+
+ ret_bo = tbm_bo_import((tbm_bufmgr)&bufmgr, 20);
+
+ ASSERT_EQ(ret_bo, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoImportFailNullBufmgr)
+{
+ tbm_bo ret_bo;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_KEY))
+ return;
+
+ ret_bo = tbm_bo_import(NULL, 20);
+
+ ASSERT_EQ(ret_bo, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoImportFailNoValidBufmgr)
+{
+ tbm_bo ret_bo;
+ int bufmgr;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_KEY))
+ return;
+
+ ret_bo = tbm_bo_import((tbm_bufmgr)&bufmgr, 20);
+
+ ASSERT_EQ(ret_bo, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoImportFailNoValidKey)
+{
+ tbm_bo ret_bo;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_KEY))
+ return;
+
+ ret_bo = tbm_bo_import(bufmgr, 20);
+
+ ASSERT_EQ(ret_bo, NULL);
+}
+
+TEST_F(UtBoInit, BoImportSuccess)
+{
+ tbm_bo ret_bo;
+ tbm_key exported_bo_key;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_KEY))
+ return;
+
+ exported_bo_key = tbm_bo_export(bo);
+ ASSERT_NE(exported_bo_key, 0);
+
+ ret_bo = tbm_bo_import(bufmgr, exported_bo_key);
+
+ ASSERT_NE(ret_bo, NULL);
+}
+
+TEST_F(UtBoInit, BoImportSuccessWhenWeImportTwice)
+{
+ tbm_bo ret_bo_1;
+ tbm_bo ret_bo_2;
+ tbm_key exported_bo_key;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_KEY))
+ return;
+
+ exported_bo_key = tbm_bo_export(bo);
+ ASSERT_NE(exported_bo_key, 0);
+
+ ret_bo_1 = tbm_bo_import(bufmgr, exported_bo_key);
+ ASSERT_NE(ret_bo_1, NULL);
+
+ ret_bo_2 = tbm_bo_import(bufmgr, exported_bo_key);
+ ASSERT_NE(ret_bo_2, NULL);
+
+ ASSERT_EQ(ret_bo_1, ret_bo_2);
+}
+
+/* tbm_bo_import_fd() */
+
+TEST(tbmBoImportFd, BoImportFdFailBufmgrWasNotInited)
+{
+ int bufmgr;
+ tbm_bo ret_bo;
+
+ ret_bo = tbm_bo_import_fd((tbm_bufmgr)&bufmgr, 20);
+
+ ASSERT_EQ(ret_bo, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoImportFdFailNullBufmgr)
+{
+ tbm_bo ret_bo;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_FD))
+ return;
+
+ ret_bo = tbm_bo_import_fd(NULL, 20);
+
+ ASSERT_EQ(ret_bo, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoImportFdFailNoValidBufmgr)
+{
+ tbm_bo ret_bo;
+ int bufmgr;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_FD))
+ return;
+
+ ret_bo = tbm_bo_import_fd((tbm_bufmgr)&bufmgr, 20);
+
+ ASSERT_EQ(ret_bo, NULL);
+}
+
+TEST_F(UtBufmgrInit, BoImportFdFailNoValidFd)
+{
+ tbm_bo ret_bo;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_FD))
+ return;
+
+ ret_bo = tbm_bo_import_fd(bufmgr, 20);
+
+ ASSERT_EQ(ret_bo, NULL);
+}
+
+TEST_F(UtBoInit, BoImportFdSuccess)
+{
+ tbm_bo ret_bo;
+ tbm_key exported_bo_fd;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_FD))
+ return;
+
+ exported_bo_fd = tbm_bo_export_fd(bo);
+ ASSERT_NE(exported_bo_fd, 0);
+
+ ret_bo = tbm_bo_import_fd(bufmgr, exported_bo_fd);
+
+ ASSERT_NE(ret_bo, NULL);
+}
+
+TEST_F(UtBoInit, BoImportFdSuccessWhenWeImportTwice)
+{
+ tbm_bo ret_bo_1;
+ tbm_bo ret_bo_2;
+ tbm_key exported_bo_fd;
+
+ if (!(bufmgr_capability & TBM_BUFMGR_CAPABILITY_SHARE_FD))
+ return;
+
+ exported_bo_fd = tbm_bo_export_fd(bo);
+ ASSERT_NE(exported_bo_fd, 0);
+
+ ret_bo_1 = tbm_bo_import_fd(bufmgr, exported_bo_fd);
+ ASSERT_NE(ret_bo_1, NULL);
+
+ ret_bo_2 = tbm_bo_import_fd(bufmgr, exported_bo_fd);
+ ASSERT_NE(ret_bo_2, NULL);
+
+ ASSERT_EQ(ret_bo_1, ret_bo_2);
+}
+
+/* tbm_bo_size() */
+
+TEST(BoSize, BoSizeFailBufmgrWasNotInited)
+{
+ int bo;
+ int ret_size;
+
+ ret_size = tbm_bo_size((tbm_bo)&bo);
+
+ ASSERT_EQ(ret_size, 0);
+}
+
+TEST_F(UtBufmgrInit, BoSizeFailNullBo)
+{
+ int ret_size;
+
+ ret_size = tbm_bo_size(NULL);
+
+ ASSERT_EQ(ret_size, 0);
+}
+
+TEST_F(UtBufmgrInit, BoSizeFailNoValidBo)
+{
+ int bo;
+ int ret_size;
+
+ ret_size = tbm_bo_size((tbm_bo)&bo);
+
+ ASSERT_EQ(ret_size, 0);
+}
+
+TEST_F(UtBoInit, BoSizeSuccess)
+{
+ int ret_size;
+
+ ret_size = tbm_bo_size(bo);
+
+ ASSERT_EQ(ret_size, bo_size);
+}
+
+/* tbm_bo_locked() */
+
+TEST(BoLocked, BoLockedFailWhenBufmgrWasNotInited)
+{
+ int bo;
+ int ret;
+
+ ret = tbm_bo_locked((tbm_bo)&bo);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBufmgrInit, BoLockedFailNullBo)
+{
+ int ret;
+
+ ret = tbm_bo_locked(NULL);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBufmgrInit, BoLockedFailNoValidBo)
+{
+ int bo;
+ int ret;
+
+ ret = tbm_bo_locked((tbm_bo)&bo);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtInit, BoLockedOnce)
+{
+ tbm_bo_handle bo_handle1, bo_handle2;
+ tbm_bo bo;
+ int ret_locked;
+
+ setenv("BUFMGR_LOCK_TYPE", "once", 1);
+
+ UtBufmgrInit();
+
+ bo = tbm_bo_alloc(bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ ASSERT_NE(bo, NULL);
+
+ bo_handle1 = tbm_bo_map(bo, TBM_DEVICE_2D, TBM_OPTION_READ | TBM_OPTION_WRITE);
+ bo_handle2 = tbm_bo_map(bo, TBM_DEVICE_2D, TBM_OPTION_READ | TBM_OPTION_WRITE);
+ (void) bo_handle1;
+ (void) bo_handle2;
+
+ tbm_bo_unmap(bo);
+
+ ret_locked = tbm_bo_locked(bo);
+
+ tbm_bo_unmap(bo);
+
+ ASSERT_EQ(ret_locked, 0);
+}
+
+TEST_F(UtInit, BoLockedAlways)
+{
+ tbm_bo_handle bo_handle1, bo_handle2;
+ tbm_bo bo;
+ int ret_locked;
+
+ setenv("BUFMGR_LOCK_TYPE", "always", 1);
+
+ UtBufmgrInit();
+
+ bo = tbm_bo_alloc(bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ ASSERT_NE(bo, NULL);
+
+ bo_handle1 = tbm_bo_map(bo, TBM_DEVICE_2D, TBM_OPTION_READ | TBM_OPTION_WRITE);
+ bo_handle2 = tbm_bo_map(bo, TBM_DEVICE_2D, TBM_OPTION_READ | TBM_OPTION_WRITE);
+ (void) bo_handle1;
+ (void) bo_handle2;
+
+ tbm_bo_unmap(bo);
+
+ ret_locked = tbm_bo_locked(bo);
+
+ tbm_bo_unmap(bo);
+
+ ASSERT_EQ(ret_locked, 1);
+}
+
+TEST_F(UtInit, BoLockedNone)
+{
+ tbm_bo_handle bo_handle1;
+ tbm_bo bo;
+ int ret_locked;
+
+ setenv("BUFMGR_LOCK_TYPE", "none", 1);
+
+ UtBufmgrInit();
+
+ bo = tbm_bo_alloc(bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ ASSERT_NE(bo, NULL);
+
+ bo_handle1 = tbm_bo_map(bo, TBM_DEVICE_2D, TBM_OPTION_READ | TBM_OPTION_WRITE);
+ (void) bo_handle1;
+
+ ret_locked = tbm_bo_locked(bo);
+
+ tbm_bo_unmap(bo);
+
+ ASSERT_EQ(ret_locked, 0);
+}
+
+/* tbm_bo_swap() */
+
+TEST(BoSwap, BoSwapFailWhenBufmgrWasNotInited)
+{
+ int bo1, bo2;
+ int ret;
+
+ ret = tbm_bo_swap((tbm_bo)&bo1, (tbm_bo)&bo1);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBufmgrInit, BoSwapFailNullAll)
+{
+ int ret;
+
+ ret = tbm_bo_swap(NULL, NULL);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoSwapFailNoValidBo1)
+{
+ int bo1;
+ int ret;
+
+ ret = tbm_bo_swap((tbm_bo)&bo, bo);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoSwapFailNoValidBo2)
+{
+ int bo2;
+ int ret;
+
+ ret = tbm_bo_swap(bo, (tbm_bo)&bo2);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBufmgrInit, BoSwapFailWhenBosSizeAreDifferent)
+{
+ tbm_bo bo1, bo2;
+ int ret;
+ tbm_error_e error;
+
+ bo1 = tbm_bo_alloc(bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ ASSERT_NE(bo1, NULL);
+
+ bo2 = tbm_bo_alloc(bufmgr, 256 * 256, TBM_BO_DEFAULT);
+ ASSERT_NE(bo2, NULL);
+
+ ret = tbm_bo_swap(bo1, bo2);
+
+ error = tbm_get_last_error();
+
+ tbm_bo_unref(bo1);
+ tbm_bo_unref(bo2);
+
+ ASSERT_EQ(ret, 0);
+ ASSERT_EQ(error, TBM_BO_ERROR_SWAP_FAILED);
+}
+
+TEST_F(UtBufmgrInit, BoSwapSuccess)
+{
+ tbm_bo bo1, bo2;
+ int ret;
+
+ bo1 = tbm_bo_alloc(bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ ASSERT_NE(bo1, NULL);
+
+ bo2 = tbm_bo_alloc(bufmgr, 128 * 128, TBM_BO_DEFAULT);
+ ASSERT_NE(bo2, NULL);
+
+ ret = tbm_bo_swap(bo1, bo2);
+
+ tbm_bo_unref(bo1);
+ tbm_bo_unref(bo2);
+
+ ASSERT_TRUE(ret);
+}
+
+/* tbm_bo_add_user_data() */
+
+TEST(BoAddUserData, BoAddUserDataFailBufmgrWasNotInited)
+{
+ int bo;
+ int ret;
+
+ ret = tbm_bo_add_user_data((tbm_bo)&bo, 7878, NULL);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBufmgrInit, BoAddUserDataFailNullBo)
+{
+ int ret;
+
+ ret = tbm_bo_add_user_data(NULL, 4484, NULL);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoAddUserDataFailNoValidBo)
+{
+ int bo1;
+ int ret;
+
+ ret = tbm_bo_add_user_data((tbm_bo)&bo, 4887, NULL);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoAddUserDataSuccess)
+{
+ int bo1;
+ int ret;
+
+ ret = tbm_bo_add_user_data(bo, 4887, NULL);
+ ASSERT_NE(ret, 0);
+}
+
+TEST_F(UtBoInit, BoAddUserDataFailDataAlreadyExist)
+{
+ int bo1;
+ int ret;
+
+ ret = tbm_bo_add_user_data(bo, 4887, NULL);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_add_user_data(bo, 4887, NULL);
+ ASSERT_EQ(ret, 0);
+}
+
+/* tbm_bo_delete_user_data() */
+
+TEST(BoDeleteUserData, BoDeleteUserDataFailBufmgrWasNotInited)
+{
+ int bo;
+ int ret;
+
+ ret = tbm_bo_delete_user_data((tbm_bo)&bo, 7878);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBufmgrInit, BoDeleteUserDataFailNullBo)
+{
+ int ret;
+
+ ret = tbm_bo_delete_user_data(NULL, 4484);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoDeleteUserDataFailNoValidBo)
+{
+ int bo;
+ int ret;
+
+ ret = tbm_bo_delete_user_data((tbm_bo)&bo, 4887);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoDeleteUserDataFailDataListIsEmpty)
+{
+ int ret;
+
+ ret = tbm_bo_delete_user_data(bo, 4887);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoDeleteUserDataFailDataDonNotExist)
+{
+ int ret;
+ unsigned long key = 487879887;
+
+ ret = tbm_bo_add_user_data(bo, key, NULL);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_delete_user_data(bo, key + 10);
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoDeleteUserSuccess)
+{
+ int ret;
+ unsigned long key = 487879887;
+
+ ret = tbm_bo_add_user_data(bo, key, NULL);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_delete_user_data(bo, key);
+ ASSERT_NE(ret, 0);
+}
+
+/* tbm_bo_set_user_data() */
+
+TEST(BoSetUserData, BoSetUserDataFailBufmgrWasNotInited)
+{
+ int bo;
+ int ret;
+ int data;
+
+ ret = tbm_bo_set_user_data((tbm_bo)&bo, 7878, &data);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBufmgrInit, BoSetUserDataFailNullBo)
+{
+ int ret;
+ int data;
+
+ ret = tbm_bo_set_user_data(NULL, 787, &data);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoSetUserDataFailNoValidBo)
+{
+ int bo, data;
+ int ret;
+
+ ret = tbm_bo_set_user_data((tbm_bo)&bo, 4887, &data);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoSetUserDataFailDataListIsEmpty)
+{
+ int ret, data;
+
+ ret = tbm_bo_set_user_data(bo, 4887, &data);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoSetUserDataFailDataDonNotExist)
+{
+ int ret;
+ unsigned long key = 487879887;
+ int data;
+
+ ret = tbm_bo_add_user_data(bo, key, NULL);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_set_user_data(bo, key + 10, &data);
+ ASSERT_EQ(ret, 0);
+}
+
+static void
+ut_data_free(void *user_data)
+{
+ int *i = (int *)user_data;
+ *i = 1;
+}
+
+TEST_F(UtBoInit, BoSetUserDataSuccess)
+{
+ int ret;
+ unsigned long key = 487879887;
+ int data1 = 0;
+ int data2 = 0;
+
+ ret = tbm_bo_add_user_data(bo, key, ut_data_free);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_set_user_data(bo, key, &data1);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_set_user_data(bo, key, &data2);
+ tbm_bo_delete_user_data(bo, key);
+
+ ASSERT_NE(ret, 0);
+
+ ASSERT_EQ(data1, 1);
+}
+
+/* tbm_bo_get_user_data() */
+
+TEST(BoGetUserData, BoGetUserDataFailBufmgrWasNotInited)
+{
+ int bo;
+ int ret;
+ int *data;
+
+ ret = tbm_bo_get_user_data((tbm_bo)&bo, 7878, (void **)&data);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBufmgrInit, BoGetUserDataFailNullBo)
+{
+ int ret;
+ int *data;
+
+ ret = tbm_bo_get_user_data(NULL, 7878, (void **)&data);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoGetUserDataFailNoValidBo)
+{
+ int bo, *data;
+ int ret;
+
+ ret = tbm_bo_get_user_data((tbm_bo)&bo, 4887, (void **)&data);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoGetUserDataFailDataListIsEmpty)
+{
+ int *data;
+ int ret;
+
+ ret = tbm_bo_get_user_data((tbm_bo)&bo, 4887, (void **)&data);
+
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoGetUserDataFailDataDonNotExist)
+{
+ int ret;
+ unsigned long key = 487879887;
+ int *data;
+
+ ret = tbm_bo_add_user_data(bo, key, NULL);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_set_user_data(bo, key, &data);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_get_user_data((tbm_bo)&bo, key + 10, (void **)&data);
+ ASSERT_EQ(ret, 0);
+}
+
+TEST_F(UtBoInit, BoGetUserDataSuccess)
+{
+ int ret;
+ unsigned long key = 487879887;
+ int data = 0, *ret_data;
+
+ ret = tbm_bo_add_user_data(bo, key, NULL);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_set_user_data(bo, key, &data);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_get_user_data(bo, key, (void **)&ret_data);
+ ASSERT_NE(ret, 0);
+ ASSERT_TRUE(ret_data == &data);
+}
+
+TEST_F(UtBoInit, BoGetUserDataFailDataWasRemoved)
+{
+ int ret;
+ unsigned long key = 487879887;
+ int data = 0, *ret_data;
+
+ ret = tbm_bo_add_user_data(bo, key, NULL);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_set_user_data(bo, key, &data);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_delete_user_data(bo, key);
+ ASSERT_NE(ret, 0);
+
+ ret = tbm_bo_get_user_data(bo, key, (void **)&ret_data);
+ ASSERT_EQ(ret, 0);
+}
+
+/* tbm_bufmgr_get_capability() */
+
+TEST(BufmgrGetCapability, BufmgrGetCapabilityFailBufmgrWasNotInited)
+{
+ int bufmgr;
+ unsigned int capability;
+
+ capability = tbm_bufmgr_get_capability((tbm_bufmgr)&bufmgr);
+
+ ASSERT_EQ(capability, TBM_BUFMGR_CAPABILITY_NONE);
+}
+
+TEST_F(UtBufmgrInit, BufmgrGetCapabilityFailNullBufmgr)
+{
+ unsigned int capability;
+
+ capability = tbm_bufmgr_get_capability(NULL);
+
+ ASSERT_EQ(capability, TBM_BUFMGR_CAPABILITY_NONE);
+}
+
+TEST_F(UtBufmgrInit, BufmgrGetCapabilityFailNoValidbufmgr)
+{
+ int bufmgr;
+ unsigned int capability;
+
+ capability = tbm_bufmgr_get_capability((tbm_bufmgr)&bufmgr);
+
+ ASSERT_EQ(capability, TBM_BUFMGR_CAPABILITY_NONE);
+}
+
+TEST_F(UtBufmgrInit, BufmgrGetCapabilitySuccess)
+{
+ unsigned int capability;
+
+ capability = tbm_bufmgr_get_capability(bufmgr);
+
+ ASSERT_NE(capability, TBM_BUFMGR_CAPABILITY_NONE);
+}
+
+/* tbm_bo_get_flags() */
+
+TEST(BoGetFlags, BoGetFlagsFailBufmgrWasNotInited)
+{
+ int bo;
+ int flags;
+
+ flags = tbm_bo_get_flags((tbm_bo)&bo);
+
+ ASSERT_EQ(flags, 0);
+}
+
+TEST_F(UtBufmgrInit, BoGetFlagsFailNullBo)
+{
+ int flags;
+
+ flags = tbm_bo_get_flags(NULL);
+
+ ASSERT_EQ(flags, 0);
+}
+
+TEST_F(UtBufmgrInit, BoGetFlagsFailNoValidBo)
+{
+ int bo;
+ int flags;
+
+ flags = tbm_bo_get_flags((tbm_bo)&bo);
+
+ ASSERT_EQ(flags, 0);
+}
+
+TEST_F(UtBoInit, BoGetFlagsSuccess)
{
int actual_flags;