#include "tbm_stubs.h"
#include "stub_pthread.h"
-#include "tdm_list_stubs.h"
#include "stub_stdlib.h"
+#include "stub_tdm.h"
#include "tdm_buffer.c"
static void _init_test()
{
+ stub_tdm_init();
stub_pthread_init();
stub_tbm_init();
stub_stdlib_init();
+ tdm_debug_module = TDM_DEBUG_BUFFER;
}
/* tdm_buffer_list_get_first_entry */
ASSERT_TRUE(actual == expected);
}
+TEST(tdm_buffer_list_get_first_entry, success_list_is_empty)
+{
+ tbm_surface_h actual;
+ struct list_head buff_list;
+
+ _init_test();
+
+ LIST_INITHEAD(&buff_list);
+
+ actual = tdm_buffer_list_get_first_entry(&buff_list);
+
+ ASSERT_TRUE(actual == NULL);
+}
+
+TEST(tdm_buffer_list_get_first_entry, success)
+{
+ tbm_surface_h actual;
+ struct list_head buff_list;
+ tdm_buffer_info buf_info;
+ struct _tbm_surface buffer;
+
+ _init_test();
+
+ buf_info.buffer = &buffer;
+
+ LIST_INITHEAD(&buff_list);
+ LIST_ADD(&buf_info.link, &buff_list);
+
+ actual = tdm_buffer_list_get_first_entry(&buff_list);
+
+ ASSERT_TRUE(actual == &buffer);
+}
+
/* tdm_buffer_ref_backend */
TEST(tdm_buffer_ref_backend, work_flow_success_2)
/* tdm_buffer_get_info */
+TEST(tdm_buffer_get_info, work_flow_success_5)
+{
+ struct _tbm_surface buffer;
+ tdm_buffer_info *actual;
+
+ _init_test();
+
+ TBM_BO_GET_USER_DATA_NULL = 1;
+ tbm_surface_internal_set_user_data_error = 1;
+
+ actual = tdm_buffer_get_info(&buffer);
+
+ ASSERT_TRUE(actual == NULL);
+}
+
+TEST(tdm_buffer_get_info, work_flow_success_4)
+{
+ struct _tbm_surface buffer;
+ tdm_buffer_info *actual;
+
+ _init_test();
+
+ TBM_BO_GET_USER_DATA_NULL = 1;
+ tbm_surface_internal_add_user_data_error = 1;
+
+ actual = tdm_buffer_get_info(&buffer);
+
+ ASSERT_TRUE(actual == NULL);
+}
+
TEST(tdm_buffer_get_info, work_flow_success_3)
{
struct _tbm_surface buffer;
ASSERT_TRUE(actual != not_expected);
}
+
+/* tdm_buffer_remove_release_handler() */
+
+TEST(tdm_buffer_remove_release_handler, success)
+{
+ struct _tbm_surface buffer;
+ int user_data;
+ tdm_buffer_func_info *func_info_1;
+ tdm_buffer_func_info *func_info_2;
+ tdm_buffer_info buf_info;
+ tdm_buffer_func_info *func_info = NULL, *next = NULL;
+
+ _init_test();
+
+ func_info_1 = (tdm_buffer_func_info *)calloc(1, sizeof * func_info_1);
+ func_info_2 = (tdm_buffer_func_info *)calloc(1, sizeof * func_info_2);
+
+ func_info_1->release_func = stub_tdm_buffer_release_handler;
+ func_info_1->user_data = &user_data;
+
+ func_info_2->release_func = NULL;
+ func_info_2->user_data = NULL;
+
+ tbm_surface_internal_get_user_data_ret = &buf_info;
+
+ LIST_INITHEAD(&buf_info.release_funcs);
+ LIST_ADD(&func_info_1->link, &buf_info.release_funcs);
+ LIST_ADD(&func_info_2->link, &buf_info.release_funcs);
+
+ tdm_buffer_remove_release_handler(&buffer, stub_tdm_buffer_release_handler, &user_data);
+
+ ASSERT_EQ(FREE_CALLED, 1);
+ LIST_FOR_EACH_ENTRY_SAFE(func_info, next, &buf_info.release_funcs, link) {
+ if (func_info->release_func != stub_tdm_buffer_release_handler || func_info->user_data != &user_data)
+ continue;
+
+ ASSERT_TRUE(0);
+ }
+ free(func_info_2);
+}
+
+/* tdm_buffer_remove_release_handler_internal() */
+
+TEST(tdm_buffer_remove_release_handler_internal, success)
+{
+ struct _tbm_surface buffer;
+ tdm_buffer_func_info *func_info_1;
+ tdm_buffer_func_info *func_info_2;
+ tdm_buffer_info buf_info;
+
+ _init_test();
+
+ func_info_1 = (tdm_buffer_func_info *)calloc(1, sizeof * func_info_1);
+ func_info_2 = (tdm_buffer_func_info *)calloc(1, sizeof * func_info_2);
+
+ tbm_surface_internal_get_user_data_ret = &buf_info;
+
+ LIST_INITHEAD(&buf_info.release_funcs);
+ LIST_ADD(&func_info_1->link, &buf_info.release_funcs);
+ LIST_ADD(&func_info_2->link, &buf_info.release_funcs);
+
+ tdm_buffer_remove_release_handler_internal(&buffer);
+
+ ASSERT_EQ(FREE_CALLED, 1);
+ free(func_info_1);
+}
+
+/* tdm_buffer_unref_backend() */
+
+TEST(tdm_buffer_unref_backend, success_ref_count_is_3)
+{
+ struct _tbm_surface buffer;
+ tdm_buffer_info buf_info;
+
+ _init_test();
+
+ tbm_surface_internal_get_user_data_ret = &buf_info;
+ buf_info.backend_ref_count = 3;
+
+ tdm_buffer_unref_backend(&buffer);
+
+ ASSERT_EQ(buf_info.backend_ref_count, 2);
+}
+
+TEST(tdm_buffer_unref_backend, success)
+{
+ struct _tbm_surface buffer;
+ tdm_buffer_info buf_info;
+ tdm_buffer_func_info func_info;
+
+ _init_test();
+
+ tbm_surface_internal_get_user_data_ret = &buf_info;
+ buf_info.backend_ref_count = 1;
+ func_info.release_func = stub_tdm_buffer_release_handler;
+
+ LIST_INITHEAD(&buf_info.release_funcs);
+ LIST_ADD(&func_info.link, &buf_info.release_funcs);
+
+ tdm_buffer_unref_backend(&buffer);
+
+ ASSERT_EQ(stub_tdm_buffer_release_handler_count, 1);
+ ASSERT_EQ(tbm_surface_internal_ref_count, 1);
+ ASSERT_EQ(tbm_surface_internal_unref_count, 2);
+}
+
+/* tdm_buffer_add_destroy_handler() */
+
+TEST(tdm_buffer_add_destroy_handler, error_buffer_is_null)
+{
+ tdm_error error;
+
+ _init_test();
+
+ error = tdm_buffer_add_destroy_handler(NULL, stub_tdm_buffer_destroy_handler, NULL);
+
+ ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_buffer_add_destroy_handler, error_func_is_null)
+{
+ tdm_error error;
+ struct _tbm_surface buffer;
+
+ _init_test();
+
+ error = tdm_buffer_add_destroy_handler(&buffer, NULL, NULL);
+
+ ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_buffer_add_destroy_handler, error_buffer_get_info)
+{
+ tdm_error error;
+ struct _tbm_surface buffer;
+
+ _init_test();
+
+ tbm_surface_internal_get_user_data_ret = NULL;
+ tbm_surface_internal_add_user_data_error = 1;
+
+ error = tdm_buffer_add_destroy_handler(&buffer, stub_tdm_buffer_destroy_handler, NULL);
+
+ ASSERT_EQ(error, TDM_ERROR_OUT_OF_MEMORY);
+}
+
+TEST(tdm_buffer_add_destroy_handler, error_calloc)
+{
+ tdm_error error;
+ struct _tbm_surface buffer;
+ tdm_buffer_info buf_info;
+
+ _init_test();
+
+ tbm_surface_internal_get_user_data_ret = &buf_info;
+
+ CALLOC_ERROR = 1;
+
+ error = tdm_buffer_add_destroy_handler(&buffer, stub_tdm_buffer_destroy_handler, NULL);
+
+ ASSERT_EQ(error, TDM_ERROR_OUT_OF_MEMORY);
+}
+
+TEST(tdm_buffer_add_destroy_handler, success)
+{
+ tdm_error error;
+ struct _tbm_surface buffer;
+ tdm_buffer_info buf_info;
+ int user_data;
+ tdm_buffer_func_info *func_info = NULL, *f = NULL;
+
+ _init_test();
+
+ tbm_surface_internal_get_user_data_ret = &buf_info;
+
+ LIST_INITHEAD(&buf_info.destroy_funcs);
+
+ error = tdm_buffer_add_destroy_handler(&buffer, stub_tdm_buffer_destroy_handler, &user_data);
+
+ ASSERT_EQ(error, TDM_ERROR_NONE);
+ ASSERT_TRUE(!LIST_IS_EMPTY(&buf_info.destroy_funcs));
+ LIST_FOR_EACH_ENTRY(f, &buf_info.destroy_funcs, link) {
+ if (f->destroy_func != stub_tdm_buffer_destroy_handler || f->user_data != &user_data)
+ continue;
+ func_info = f;
+ }
+ ASSERT_TRUE(func_info);
+ free(func_info);
+}
+
+/* tdm_buffer_remove_release_handler() */
+
+TEST(tdm_buffer_remove_destroy_handler, success)
+{
+ struct _tbm_surface buffer;
+ int user_data;
+ tdm_buffer_func_info *func_info_1;
+ tdm_buffer_func_info *func_info_2;
+ tdm_buffer_info buf_info;
+ tdm_buffer_func_info *func_info = NULL, *next = NULL;
+
+ _init_test();
+
+ func_info_1 = (tdm_buffer_func_info *)calloc(1, sizeof * func_info_1);
+ func_info_2 = (tdm_buffer_func_info *)calloc(1, sizeof * func_info_2);
+
+ func_info_1->destroy_func = stub_tdm_buffer_destroy_handler;
+ func_info_1->user_data = &user_data;
+
+ func_info_2->release_func = NULL;
+ func_info_2->user_data = NULL;
+
+ tbm_surface_internal_get_user_data_ret = &buf_info;
+
+ LIST_INITHEAD(&buf_info.destroy_funcs);
+ LIST_ADD(&func_info_1->link, &buf_info.destroy_funcs);
+ LIST_ADD(&func_info_2->link, &buf_info.destroy_funcs);
+
+ tdm_buffer_remove_destroy_handler(&buffer, stub_tdm_buffer_destroy_handler, &user_data);
+
+ ASSERT_EQ(FREE_CALLED, 1);
+ LIST_FOR_EACH_ENTRY_SAFE(func_info, next, &buf_info.destroy_funcs, link) {
+ if (func_info->release_func != stub_tdm_buffer_destroy_handler || func_info->user_data != &user_data)
+ continue;
+
+ ASSERT_TRUE(0);
+ }
+ free(func_info_2);
+}