ut: improve code coverage for tdm_display.c 27/158227/2
authorKonstantin Drabeniuk <k.drabeniuk@samsung.com>
Thu, 8 Dec 2016 15:43:34 +0000 (17:43 +0200)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 30 Oct 2017 11:15:14 +0000 (11:15 +0000)
Change-Id: Ice4662e9b5a5bababb2e4bc7f0df6ab3227dd82b
Signed-off-by: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
Signed-off-by: SooChan Lim <sc1.lim@samsung.com>
13 files changed:
ut/src/ut_tdm_backend.cpp
ut/src/ut_tdm_display.cpp
ut/stubs/stub_backend.cpp
ut/stubs/stub_backend.h
ut/stubs/stub_tdm.h
ut/stubs/stub_tdm_buffer.h
ut/stubs/stub_tdm_event_loop.h
ut/stubs/stub_tdm_helper.h
ut/stubs/stub_tdm_thread.h
ut/stubs/stub_unistd.cpp
ut/stubs/stub_unistd.h
ut/stubs/tbm_stubs.cpp
ut/stubs/tbm_stubs.h

index 019dd3c..6366f69 100644 (file)
@@ -138,6 +138,7 @@ TEST(tdm_backend_register_func_layer, work_flow_success_1)
        _init_test();
 
        dpy.module_data = &module;
+       module.abi_version = 0x00010005;
 
        error = tdm_backend_register_func_layer(&dpy, &func_layer);
 
index e1d9184..61cab96 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "tbm_stubs.h"
 #include "stub_pthread.h"
-#include "tdm_list_stubs.h"
 #include "stub_stdlib.h"
 #include "stub_backend.h"
 #include "stub_tdm_pp.h"
 #include "stub_tdm_event_loop.h"
 #include "stub_tdm_buffer.h"
 #include "stub_unistd.h"
+#include "stub_tdm_thread.h"
+#include "stub_tdm.h"
+#include "stub_tdm_buffer.h"
+#include "stub_tdm_helper.h"
+#include "tdm_list.h"
 
 #include "tdm_display.c"
 
 static void _init_test()
 {
+       stub_tdm_helper_init();
+       stub_tdm_buffer_init();
+       stub_tdm_init();
+       stub_unistd_init();
+       stub_tdm_thread_init();
        stub_pthread_init();
        stub_tdm_event_loop_init();
        stub_tdm_thread_init();
@@ -52,6 +61,9 @@ static void _init_test()
        stub_backend_init();
        stub_tbm_init();
        stub_stdlib_init();
+       tdm_debug_module = TDM_DEBUG_THREAD | TDM_DEBUG_BUFFER;
+       tdm_debug_dump = TDM_DUMP_FLAG_LAYER;
+       tdm_dump_enable = 1;
 }
 
 static void ut_tdm_output_vblank_handler(tdm_output *output,
@@ -267,18 +279,24 @@ TEST(tdm_layer_unset_buffer_queue, work_flow_success_3)
        tdm_private_layer layer;
        tdm_private_output private_output;
        tdm_private_display private_display;
+       struct _tbm_surface waiting_buffer;
+       struct _tbm_surface showing_buffer;
 
        _init_test();
 
        layer.private_output = &private_output;
        private_output.private_display = &private_display;
-       layer.waiting_buffer = NULL;
-       layer.showing_buffer = NULL;
+       layer.waiting_buffer = &waiting_buffer;
+       layer.showing_buffer = &showing_buffer;
        private_display.func_layer.layer_unset_buffer = layer_unset_buffer;
 
        error = tdm_layer_unset_buffer_queue(&layer);
 
        ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 2);
+       ASSERT_EQ(tbm_surface_queue_release_count, 2);
+       ASSERT_TRUE(layer.waiting_buffer == NULL);
+       ASSERT_TRUE(layer.showing_buffer == NULL);
 }
 
 TEST(tdm_layer_unset_buffer_queue, work_flow_success_2)
@@ -346,6 +364,7 @@ TEST(tdm_layer_set_buffer_queue, work_flow_success_3)
        tdm_private_layer layer;
        tdm_private_output private_output;
        tdm_private_display private_display;
+       struct _tbm_surface waiting_buffer;
 
        _init_test();
 
@@ -353,11 +372,14 @@ TEST(tdm_layer_set_buffer_queue, work_flow_success_3)
        private_output.private_display = &private_display;
        private_display.func_layer.layer_set_buffer = layer_set_buffer;
        layer.buffer_queue = NULL;
-       layer.waiting_buffer = NULL;
+       layer.waiting_buffer = &waiting_buffer;
 
        error = tdm_layer_set_buffer_queue(&layer, &buffer_queue);
 
        ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 1);
+       ASSERT_EQ(tbm_surface_queue_release_count, 1);
+       ASSERT_TRUE(layer.waiting_buffer == NULL);
 }
 
 TEST(tdm_layer_set_buffer_queue, work_flow_success_2)
@@ -439,18 +461,21 @@ TEST(tdm_layer_unset_buffer, work_flow_success_3)
        tdm_private_layer layer;
        tdm_private_output private_output;
        tdm_private_display private_display;
+       struct _tbm_surface waiting_buffer;
+       struct _tbm_surface showing_buffer;
 
        _init_test();
 
        layer.private_output = &private_output;
        private_output.private_display = &private_display;
-       layer.waiting_buffer = NULL;
-       layer.showing_buffer = NULL;
+       layer.waiting_buffer = &waiting_buffer;
+       layer.showing_buffer = &showing_buffer;
        private_display.func_layer.layer_unset_buffer = layer_unset_buffer;
 
        error = tdm_layer_unset_buffer(&layer);
 
        ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 2);
 }
 
 TEST(tdm_layer_unset_buffer, work_flow_success_2)
@@ -518,12 +543,14 @@ TEST(tdm_layer_set_buffer, work_flow_success_3)
        tdm_private_layer layer;
        tdm_private_output private_output;
        tdm_private_display private_display;
+       struct _tbm_surface waiting_buffer;
 
        _init_test();
 
+       layer.caps.capabilities = TDM_LAYER_CAPABILITY_GRAPHIC;
        layer.private_output = &private_output;
        private_output.private_display = &private_display;
-       layer.waiting_buffer = NULL;
+       layer.waiting_buffer = &waiting_buffer;
        private_display.func_layer.layer_set_buffer = layer_set_buffer;
 
        error = tdm_layer_set_buffer(&layer, &buffer);
@@ -706,6 +733,8 @@ TEST(tdm_layer_set_info, work_flow_success_3)
 
        _init_test();
 
+       layer.usable = 1;
+       info.src_config.format = 0;
        layer.private_output = &private_output;
        private_output.private_display = &private_display;
        private_display.func_layer.layer_set_info = layer_set_info;
@@ -726,6 +755,7 @@ TEST(tdm_layer_set_info, work_flow_success_2)
 
        _init_test();
 
+       info.src_config.format = 1;
        layer.private_output = &private_output;
        private_output.private_display = &private_display;
        private_display.func_layer.layer_set_info = layer_set_info;
@@ -1319,73 +1349,199 @@ TEST(tdm_output_get_dpms, null_ptr_fail_1)
 
 /* tdm_output_set_dpms() */
 
-TEST(tdm_output_set_dpms, work_flow_success_3)
+TEST(tdm_output_set_dpms, error_output_is_null)
 {
-       tdm_error error = TDM_ERROR_INVALID_PARAMETER;
-       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_error error = TDM_ERROR_NONE;
+       tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER;
        tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF;
+
+       _init_test();
+
+       error = tdm_output_set_dpms(NULL, dpms_value);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_output_set_dpms, success_dpms_is_already_set)
+{
+       tdm_error error;
+       tdm_output_dpms dpms_value = (tdm_output_dpms)10;
        tdm_private_output output;
        tdm_private_display private_display;
 
        _init_test();
 
+       output.current_dpms_value = TDM_OUTPUT_DPMS_OFF;
+
        output.private_display = &private_display;
-       private_display.func_output.output_set_dpms = output_set_dpms;
-       output.dpms_changed_timer = 1;
 
        error = tdm_output_set_dpms(&output, dpms_value);
 
-       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(error, TDM_ERROR_NONE);
 }
 
-TEST(tdm_output_set_dpms, work_flow_success_2)
+TEST(tdm_output_set_dpms, error_event_loop_add_timer_handler_error)
 {
-       tdm_error error = TDM_ERROR_NONE;
-       tdm_error not_expected_error = TDM_ERROR_NONE;
-       tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_ON;
+       tdm_error error;
+       tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF;
+       tdm_private_output output;
+       tdm_private_display private_display;
+
+       _init_test();
+
+       LIST_INITHEAD(&output.change_handler_list_sub);
+
+       stub_tdm_event_loop_add_timer_handler_error = 1;
+       output.dpms_changed_timer = NULL;
+       output.current_dpms_value = TDM_OUTPUT_DPMS_ON;
+       output.private_display = &private_display;
+
+       error = tdm_output_set_dpms(&output, dpms_value);
+
+       ASSERT_EQ(error, TDM_ERROR_OUT_OF_MEMORY);
+}
+
+TEST(tdm_output_set_dpms, success_output_set_dpms_is_null)
+{
+       tdm_error error;
+       tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF;
+       tdm_private_output output;
+       tdm_private_display private_display;
+       tdm_func_output func_output;
+
+       _init_test();
+
+       LIST_INITHEAD(&output.change_handler_list_sub);
+
+       output.dpms_changed_timer = NULL;
+       output.current_dpms_value = TDM_OUTPUT_DPMS_ON;
+       output.private_display = &private_display;
+
+       func_output.output_set_dpms = NULL;
+
+       private_display.func_output = func_output;
+
+       error = tdm_output_set_dpms(&output, dpms_value);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+}
+
+TEST(tdm_output_set_dpms, error_output_set_dpms)
+{
+       tdm_error error;
+       tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF;
        tdm_private_output output;
        tdm_private_display private_display;
+       tdm_func_output func_output;
 
        _init_test();
 
+       LIST_INITHEAD(&output.change_handler_list_sub);
+
+       output.dpms_changed_timer = NULL;
+       output.current_dpms_value = TDM_OUTPUT_DPMS_ON;
        output.private_display = &private_display;
-       private_display.func_output.output_set_dpms = output_set_dpms;
+
+       func_output.output_set_dpms = output_set_dpms;
+       func_output.output_set_dpms_handler = NULL;
+
+       private_display.func_output = func_output;
+
        OUTPUT_SET_DPMS_ERROR = 1;
 
        error = tdm_output_set_dpms(&output, dpms_value);
 
-       ASSERT_NE(error, not_expected_error);
+       ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED);
 }
 
-TEST(tdm_output_set_dpms, work_flow_success_1)
+TEST(tdm_output_set_dpms, error_output_set_dpms_handler_is_null)
 {
-       tdm_error error = TDM_ERROR_NONE;
-       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_error error;
        tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF;
        tdm_private_output output;
        tdm_private_display private_display;
+       tdm_func_output func_output;
+       tdm_private_change_handler change_handler;
 
        _init_test();
 
+       stub_tdm_event_loop_source_timer_update_error = 1;
+
+       LIST_INITHEAD(&output.change_handler_list_sub);
+       LIST_INITHEAD(&output.change_handler_list_main);
+       LIST_ADD(&change_handler.link, &output.change_handler_list_sub);
+
+       output.dpms_changed_timer = NULL;
+       output.current_dpms_value = TDM_OUTPUT_DPMS_ON;
        output.private_display = &private_display;
-       private_display.func_output.output_set_dpms = NULL;
+
+       func_output.output_set_dpms = output_set_dpms;
+       func_output.output_set_dpms_handler = NULL;
+
+       private_display.func_output = func_output;
 
        error = tdm_output_set_dpms(&output, dpms_value);
 
-       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED);
 }
 
-TEST(tdm_output_set_dpms, null_ptr_fail_1)
+TEST(tdm_output_set_dpms, success_output_set_dpms_handler_is_null)
 {
-       tdm_error error = TDM_ERROR_NONE;
-       tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER;
+       tdm_error error;
        tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF;
+       tdm_private_output output;
+       tdm_private_display private_display;
+       tdm_func_output func_output;
+       tdm_private_change_handler change_handler;
 
        _init_test();
 
-       error = tdm_output_set_dpms(NULL, dpms_value);
+       LIST_INITHEAD(&output.change_handler_list_sub);
+       LIST_INITHEAD(&output.change_handler_list_main);
+       LIST_ADD(&change_handler.link, &output.change_handler_list_sub);
 
-       ASSERT_EQ(error, expected_error);
+       output.dpms_changed_timer = NULL;
+       output.current_dpms_value = TDM_OUTPUT_DPMS_ON;
+       output.private_display = &private_display;
+
+       func_output.output_set_dpms = output_set_dpms;
+       func_output.output_set_dpms_handler = NULL;
+
+       private_display.func_output = func_output;
+
+       error = tdm_output_set_dpms(&output, dpms_value);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+}
+
+TEST(tdm_output_set_dpms, success_output_set_dpms_handler_is_not_null)
+{
+       tdm_error error;
+       tdm_output_dpms dpms_value = TDM_OUTPUT_DPMS_OFF;
+       tdm_private_output output;
+       tdm_private_display private_display;
+       tdm_func_output func_output;
+
+       _init_test();
+
+       stub_tdm_event_loop_source_timer_update_error = 1;
+
+       LIST_INITHEAD(&output.change_handler_list_sub);
+       LIST_INITHEAD(&output.change_handler_list_main);
+
+       output.dpms_changed_timer = NULL;
+       output.current_dpms_value = TDM_OUTPUT_DPMS_ON;
+       output.private_display = &private_display;
+       output.regist_dpms_cb = 0;
+
+       func_output.output_set_dpms = output_set_dpms;
+       func_output.output_set_dpms_handler = output_set_dpms_handler;
+
+       private_display.func_output = func_output;
+
+       error = tdm_output_set_dpms(&output, dpms_value);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
 }
 
 /* tdm_output_get_mode() */
@@ -1527,6 +1683,8 @@ TEST(tdm_output_commit, work_flow_success_7)
 
        _init_test();
 
+       LIST_INITHEAD(&output.commit_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_commit = NULL;
        output.current_dpms_value = TDM_OUTPUT_DPMS_OFF;
@@ -1545,6 +1703,8 @@ TEST(tdm_output_commit, work_flow_success_6)
 
        _init_test();
 
+       LIST_INITHEAD(&output.commit_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_commit = output_commit;
        private_display.func_output.output_set_commit_handler =
@@ -1566,6 +1726,8 @@ TEST(tdm_output_commit, work_flow_success_5)
 
        _init_test();
 
+       LIST_INITHEAD(&output.commit_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_commit = output_commit;
        private_display.func_output.output_set_commit_handler =
@@ -1587,6 +1749,8 @@ TEST(tdm_output_commit, work_flow_success_4)
 
        _init_test();
 
+       LIST_INITHEAD(&output.commit_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_commit = output_commit;
        private_display.func_output.output_set_commit_handler =
@@ -1609,6 +1773,8 @@ TEST(tdm_output_commit, work_flow_success_3)
 
        _init_test();
 
+       LIST_INITHEAD(&output.commit_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_commit = output_commit;
        OUTPUT_COMMIT_ERROR = 1;
@@ -1630,6 +1796,8 @@ TEST(tdm_output_commit, work_flow_success_2)
 
        _init_test();
 
+       LIST_INITHEAD(&output.commit_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_commit = output_commit;
        CALLOC_ERROR = 1;
@@ -1649,6 +1817,8 @@ TEST(tdm_output_commit, work_flow_success_1)
 
        _init_test();
 
+       LIST_INITHEAD(&output.commit_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_commit = NULL;
        output.current_dpms_value = TDM_OUTPUT_DPMS_ON;
@@ -1682,6 +1852,8 @@ TEST(tdm_output_wait_vblank, work_flow_success_7)
 
        _init_test();
 
+       LIST_INITHEAD(&output.vblank_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_wait_vblank = NULL;
        output.current_dpms_value = TDM_OUTPUT_DPMS_STANDBY;
@@ -1701,6 +1873,8 @@ TEST(tdm_output_wait_vblank, work_flow_success_6)
 
        _init_test();
 
+       LIST_INITHEAD(&output.vblank_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_wait_vblank = output_wait_vblank;
        private_display.func_output.output_set_vblank_handler =
@@ -1723,6 +1897,8 @@ TEST(tdm_output_wait_vblank, work_flow_success_5)
 
        _init_test();
 
+       LIST_INITHEAD(&output.vblank_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_wait_vblank = output_wait_vblank;
        private_display.func_output.output_set_vblank_handler =
@@ -1745,6 +1921,8 @@ TEST(tdm_output_wait_vblank, work_flow_success_4)
 
        _init_test();
 
+       LIST_INITHEAD(&output.vblank_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_wait_vblank = output_wait_vblank;
        private_display.func_output.output_set_vblank_handler =
@@ -1768,6 +1946,8 @@ TEST(tdm_output_wait_vblank, work_flow_success_3)
 
        _init_test();
 
+       LIST_INITHEAD(&output.vblank_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_wait_vblank = output_wait_vblank;
        OUTPUT_WAIT_VBLANK_ERROR = 1;
@@ -1788,6 +1968,8 @@ TEST(tdm_output_wait_vblank, work_flow_success_2)
 
        _init_test();
 
+       LIST_INITHEAD(&output.vblank_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_wait_vblank = output_wait_vblank;
        CALLOC_ERROR = 1;
@@ -1808,6 +1990,8 @@ TEST(tdm_output_wait_vblank, work_flow_success_1)
 
        _init_test();
 
+       LIST_INITHEAD(&output.vblank_handler_list);
+
        output.private_display = &private_display;
        private_display.func_output.output_wait_vblank = NULL;
        output.current_dpms_value = TDM_OUTPUT_DPMS_ON;
@@ -2429,17 +2613,42 @@ TEST(tdm_output_get_available_properties, null_ptr_fail_1)
 
 /* tdm_output_get_layer() */
 
-TEST(tdm_output_get_layer, work_flow_success_1)
+TEST(tdm_output_get_layer, success_get_layer)
+{
+       tdm_error error = TDM_ERROR_INVALID_PARAMETER;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_output output;
+       tdm_private_layer private_layer;
+       tdm_layer *layer;
+
+       _init_test();
+
+       private_layer.index = 15;
+
+       LIST_INITHEAD(&output.layer_list);
+       LIST_ADD(&private_layer.link, &output.layer_list);
+
+       layer = tdm_output_get_layer(&output, 15, &error);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_TRUE(layer == &private_layer);
+}
+
+TEST(tdm_output_get_layer, success_list_is_empty)
 {
        tdm_error error = TDM_ERROR_INVALID_PARAMETER;
        tdm_error expected_error = TDM_ERROR_NONE;
        tdm_private_output output;
+       tdm_layer *layer;
 
        _init_test();
 
-       tdm_output_get_layer(&output, 1, &error);
+       LIST_INITHEAD(&output.layer_list);
+
+       layer = tdm_output_get_layer(&output, 1, &error);
 
        ASSERT_EQ(error, expected_error);
+       ASSERT_TRUE(layer == NULL);
 }
 
 TEST(tdm_output_get_layer, null_ptr_fail_1)
@@ -2456,6 +2665,27 @@ TEST(tdm_output_get_layer, null_ptr_fail_1)
 
 /* tdm_output_get_layer_count() */
 
+TEST(tdm_output_get_layer_count, work_flow_success_2)
+{
+       tdm_error error = TDM_ERROR_INVALID_PARAMETER;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       int count;
+       tdm_private_output output;
+       tdm_private_layer private_layer_1;
+       tdm_private_layer private_layer_2;
+
+       _init_test();
+
+       LIST_INITHEAD(&output.layer_list);
+       LIST_ADD(&private_layer_1.link, &output.layer_list);
+       LIST_ADD(&private_layer_2.link, &output.layer_list);
+
+       error = tdm_output_get_layer_count(&output, &count);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(count, 2);
+}
+
 TEST(tdm_output_get_layer_count, work_flow_success_1)
 {
        tdm_error error = TDM_ERROR_INVALID_PARAMETER;
@@ -2465,9 +2695,12 @@ TEST(tdm_output_get_layer_count, work_flow_success_1)
 
        _init_test();
 
+       LIST_INITHEAD(&output.layer_list);
+
        error = tdm_output_get_layer_count(&output, &count);
 
        ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(count, 0);
 }
 
 TEST(tdm_output_get_layer_count, null_ptr_fail_2)
@@ -2684,42 +2917,64 @@ TEST(tdm_display_create_pp, null_ptr_fail_1)
 
 /* tdm_display_handle_events() */
 
-TEST(tdm_display_handle_events, work_flow_success_4)
+TEST(tdm_display_handle_events, success_thread_handle_cb)
 {
        tdm_error error = TDM_ERROR_OPERATION_FAILED;
-       tdm_error expected_error = TDM_ERROR_NONE;
        struct _tdm_private_display dpy;
-       tdm_private_loop private_loop;
 
        _init_test();
 
-       dpy.private_loop = &private_loop;
-       private_loop.private_thread = NULL;
+       stub_tdm_thread_is_run = 1;
 
        error = tdm_display_handle_events(&dpy);
 
-       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(error, TDM_ERROR_NONE);
 }
 
-TEST(tdm_display_handle_events, work_flow_success_3)
+TEST(tdm_display_handle_events, error_thread_handle_cb)
 {
-       tdm_error error = TDM_ERROR_NONE;
-       tdm_error not_expected_error = TDM_ERROR_NONE;
+       tdm_error error = TDM_ERROR_OPERATION_FAILED;
        struct _tdm_private_display dpy;
-       tdm_private_loop private_loop;
 
        _init_test();
 
-       dpy.private_loop = &private_loop;
-       private_loop.private_thread = NULL;
-       TDM_EVENT_LOOP_DISPATCH_ERROR = 1;
+       stub_tdm_thread_is_run = 1;
+       TDM_THREAD_HANDLE_ERROR = 1;
 
        error = tdm_display_handle_events(&dpy);
 
-       ASSERT_NE(error, not_expected_error);
+       ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED);
 }
 
-TEST(tdm_display_handle_events, work_flow_success_2)
+TEST(tdm_display_handle_events, error_poll)
+{
+       tdm_error error = TDM_ERROR_OPERATION_FAILED;
+       struct _tdm_private_display dpy;
+
+       _init_test();
+
+       stub_poll_error = 1;
+
+       error = tdm_display_handle_events(&dpy);
+
+       ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED);
+}
+
+TEST(tdm_display_handle_events, success_poll_eagain)
+{
+       tdm_error error = TDM_ERROR_OPERATION_FAILED;
+       struct _tdm_private_display dpy;
+
+       _init_test();
+
+       stub_poll_eagain = 1;
+
+       error = tdm_display_handle_events(&dpy);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+}
+
+TEST(tdm_display_handle_events, work_flow_success_4)
 {
        tdm_error error = TDM_ERROR_OPERATION_FAILED;
        tdm_error expected_error = TDM_ERROR_NONE;
@@ -2728,14 +2983,26 @@ TEST(tdm_display_handle_events, work_flow_success_2)
 
        _init_test();
 
-       dpy.private_loop = &private_loop;
-       private_loop.private_thread = (tdm_private_thread *) 1;
-
        error = tdm_display_handle_events(&dpy);
 
        ASSERT_EQ(error, expected_error);
 }
 
+TEST(tdm_display_handle_events, work_flow_success_3)
+{
+       tdm_error error = TDM_ERROR_NONE;
+       tdm_error not_expected_error = TDM_ERROR_NONE;
+       struct _tdm_private_display dpy;
+
+       _init_test();
+
+       TDM_EVENT_LOOP_DISPATCH_ERROR = 1;
+
+       error = tdm_display_handle_events(&dpy);
+
+       ASSERT_NE(error, not_expected_error);
+}
+
 TEST(tdm_display_handle_events, null_ptr_fail_1)
 {
        tdm_error error = TDM_ERROR_NONE;
@@ -2750,19 +3017,32 @@ TEST(tdm_display_handle_events, null_ptr_fail_1)
 
 /* tdm_display_get_fd() */
 
+TEST(tdm_display_get_fd, success_thread_is_running)
+{
+       tdm_error error;
+       int fd;
+       struct _tdm_private_display dpy;
+
+       _init_test();
+
+       stub_tdm_thread_is_run = 1;
+       stub_tdm_thread_ret_fd = 5;
+
+       error = tdm_display_get_fd(&dpy, &fd);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+       ASSERT_EQ(fd, stub_tdm_thread_ret_fd);
+}
+
 TEST(tdm_display_get_fd, work_flow_success_1)
 {
        tdm_error error = TDM_ERROR_OPERATION_FAILED;
        tdm_error expected_error = TDM_ERROR_NONE;
        int fd;
        struct _tdm_private_display dpy;
-       tdm_private_loop private_loop;
 
        _init_test();
 
-       dpy.private_loop = &private_loop;
-       private_loop.private_thread = NULL;
-
        error = tdm_display_get_fd(&dpy, &fd);
 
        ASSERT_EQ(error, expected_error);
@@ -2796,6 +3076,29 @@ TEST(tdm_display_get_fd, null_ptr_fail_1)
 
 /* tdm_display_get_output() */
 
+TEST(tdm_display_get_output, success_get_output)
+{
+       tdm_error error = TDM_ERROR_OPERATION_FAILED;
+       tdm_error expected_error;
+       struct _tdm_private_display dpy;
+       tdm_output *ret_output;
+       tdm_private_output output;
+
+       _init_test();
+
+       output.index = 20;
+
+       LIST_INITHEAD(&dpy.output_list);
+       LIST_ADD(&output.link, &dpy.output_list);
+
+       ret_output = tdm_display_get_output(&dpy, output.index, &error);
+
+       expected_error = TDM_ERROR_NONE;
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(ret_output, &output);
+}
+
 TEST(tdm_display_get_output, work_flow_success_1)
 {
        tdm_error error = TDM_ERROR_OPERATION_FAILED;
@@ -2804,6 +3107,8 @@ TEST(tdm_display_get_output, work_flow_success_1)
 
        _init_test();
 
+       LIST_INITHEAD(&dpy.output_list);
+
        tdm_display_get_output(&dpy, 1, &error);
 
        expected_error = TDM_ERROR_NONE;
@@ -2826,6 +3131,29 @@ TEST(tdm_display_get_output, null_ptr_fail_1)
 
 /* tdm_display_get_output_count() */
 
+TEST(tdm_display_get_output_count, work_flow_success_2)
+{
+       tdm_error error = TDM_ERROR_OPERATION_FAILED;
+       tdm_error expected_error;
+       struct _tdm_private_display dpy;
+       int count;
+       tdm_private_output output_1;
+       tdm_private_output output_2;
+
+       _init_test();
+
+       LIST_INITHEAD(&dpy.output_list);
+       LIST_ADD(&output_1.link, &dpy.output_list);
+       LIST_ADD(&output_2.link, &dpy.output_list);
+
+       error = tdm_display_get_output_count(&dpy, &count);
+
+       expected_error = TDM_ERROR_NONE;
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(count, 2);
+}
+
 TEST(tdm_display_get_output_count, work_flow_success_1)
 {
        tdm_error error = TDM_ERROR_OPERATION_FAILED;
@@ -2835,11 +3163,14 @@ TEST(tdm_display_get_output_count, work_flow_success_1)
 
        _init_test();
 
+       LIST_INITHEAD(&dpy.output_list);
+
        error = tdm_display_get_output_count(&dpy, &count);
 
        expected_error = TDM_ERROR_NONE;
 
        ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(count, 0);
 }
 
 TEST(tdm_display_get_output_count, null_ptr_fail_2)
@@ -3378,3 +3709,1000 @@ TEST(tdm_display_get_capabilities, null_ptr_fail_1)
 
        ASSERT_EQ(error, expected_error);
 }
+
+/* tdm_display_get_capture_available_size() */
+
+TEST(tdm_display_get_capture_available_size, error_dpy_is_null)
+{
+       tdm_error error = TDM_ERROR_NONE;
+
+       _init_test();
+
+       error = tdm_display_get_capture_available_size(NULL, NULL, NULL, NULL, NULL, NULL);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_display_get_capture_available_size, error_no_capability)
+{
+       tdm_error error = TDM_ERROR_NONE;
+       tdm_private_display display;
+
+       _init_test();
+
+       display.capabilities = TDM_DISPLAY_CAPABILITY_PP;
+
+       error = tdm_display_get_capture_available_size(&display, NULL, NULL, NULL, NULL, NULL);
+
+       ASSERT_EQ(error, TDM_ERROR_NO_CAPABILITY);
+}
+
+TEST(tdm_display_get_capture_available_size, success_get_capture_available_size)
+{
+       tdm_error error = TDM_ERROR_NONE;
+       tdm_private_display display;
+       int min_w, min_h, max_w, max_h, preferred_align;
+
+       _init_test();
+
+       display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE;
+
+       display.caps_capture.min_w = 200;
+       display.caps_capture.min_h = 300;
+       display.caps_capture.max_w = 1080;
+       display.caps_capture.max_h = 1920;
+       display.caps_capture.preferred_align = 100;
+
+       error = tdm_display_get_capture_available_size(&display, &min_w,
+                                                                                                  &min_h, &max_w, &max_h,
+                                                                                                  &preferred_align);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+       ASSERT_EQ(display.caps_capture.min_w, min_w);
+       ASSERT_EQ(display.caps_capture.min_h, min_h);
+       ASSERT_EQ(display.caps_capture.max_w, max_w);
+       ASSERT_EQ(display.caps_capture.max_h, max_h);
+       ASSERT_EQ(display.caps_capture.preferred_align, preferred_align);
+}
+
+/* tdm_display_get_capture_available_size() */
+
+TEST(tdm_display_get_max_layer_count, error_dpy_is_null)
+{
+       tdm_error error = TDM_ERROR_NONE;
+       int max_count;
+
+       _init_test();
+
+       error = tdm_display_get_max_layer_count(NULL, &max_count);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_display_get_max_layer_count, error_max_count_is_null)
+{
+       tdm_error error = TDM_ERROR_NONE;
+       tdm_private_display display;
+
+       _init_test();
+
+       error = tdm_display_get_max_layer_count(&display, NULL);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_display_get_max_layer_count, success_get_max_layer_count)
+{
+       tdm_error error = TDM_ERROR_NONE;
+       tdm_private_display display;
+       int max_count;
+
+       _init_test();
+
+       display.caps_display.max_layer_count = 100;
+
+       error = tdm_display_get_max_layer_count(&display, &max_count);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+       ASSERT_EQ(display.caps_display.max_layer_count, max_count);
+}
+
+/* tdm_display_get_backend_info() */
+
+TEST(tdm_display_get_backend_info, error_dpy_is_null)
+{
+       tdm_error error;
+
+       _init_test();
+
+       error = tdm_display_get_backend_info(NULL, NULL, NULL, NULL, NULL);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_display_get_backend_info, success_get_backend_info)
+{
+       tdm_error error;
+       tdm_private_display display;
+       tdm_backend_module module_data;
+       const char *name;
+       const char *vendor;
+       int major;
+       int minor;
+
+       _init_test();
+
+       display.module_data = &module_data;
+
+       module_data.name = "name";
+       module_data.vendor = "vendor";
+       module_data.abi_version = 0xFFFFFFFF;
+
+       error = tdm_display_get_backend_info(&display, &name, &vendor, &major, &minor);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+       ASSERT_TRUE(name == module_data.name);
+       ASSERT_TRUE(vendor == module_data.vendor);
+       ASSERT_EQ(major, TDM_BACKEND_GET_ABI_MAJOR(module_data.abi_version));
+       ASSERT_EQ(minor, TDM_BACKEND_GET_ABI_MINOR(module_data.abi_version));
+}
+
+/* tdm_output_get_capabilities() */
+
+TEST(tdm_output_get_capabilities, error_output_is_null)
+{
+       tdm_error error;
+       tdm_output_capability capabilities;
+
+       _init_test();
+
+       error = tdm_output_get_capabilities(NULL, &capabilities);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_output_get_capabilities, error_capabilities_is_null)
+{
+       tdm_error error;
+       tdm_private_output output;
+
+       _init_test();
+
+       error = tdm_output_get_capabilities(&output, NULL);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_output_get_capabilities, success_get_capabilities)
+{
+       tdm_error error;
+       tdm_private_output output;
+       tdm_output_capability capabilities;
+
+       _init_test();
+
+       output.caps.capabilities = TDM_OUTPUT_CAPABILITY_ASYNC_DPMS;
+
+       error = tdm_output_get_capabilities(&output, &capabilities);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+       ASSERT_EQ(capabilities, output.caps.capabilities);
+}
+
+/* tdm_output_cb_status() */
+
+TEST(tdm_output_cb_status, success_no_in_display_thread)
+{
+       tdm_private_output private_output;
+       tdm_private_display private_display;
+       tdm_thread_cb_output_status *output_status;
+       tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_CONNECTED;
+
+       _init_test();
+
+       private_output.private_display = &private_display;
+       private_output.stamp = 15.25;
+
+       LIST_INITHEAD(&private_output.change_handler_list_sub);
+
+       tdm_output_cb_status(&private_output, status, &private_output);
+
+       output_status = (tdm_thread_cb_output_status *)stub_tdm_thread_send_cb_buff;
+
+       ASSERT_EQ(output_status->base.type, TDM_THREAD_CB_OUTPUT_STATUS);
+       ASSERT_EQ(output_status->base.length, sizeof * output_status);
+       ASSERT_EQ(output_status->output_stamp, private_output.stamp);
+       ASSERT_EQ(output_status->status, status);
+       ASSERT_TRUE(output_status->user_data == &private_output);
+}
+
+TEST(tdm_output_cb_status, success_in_display_thread)
+{
+       tdm_private_output private_output;
+       tdm_private_display private_display;
+       tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_CONNECTED;
+       tdm_private_change_handler change_handler;
+
+       _init_test();
+
+       stub_tdm_thread_display_thread = 1;
+       private_output.private_display = &private_display;
+       private_output.stamp = 15.25;
+
+       change_handler.func = stub_tdm_output_change_handler_cb;
+
+       LIST_INITHEAD(&private_output.change_handler_list_main);
+       LIST_ADD(&change_handler.link, &private_output.change_handler_list_main);
+
+       tdm_output_cb_status(&private_output, status, &private_output);
+
+       ASSERT_TRUE(stub_tdm_output_change_handler_count);
+}
+
+/* tdm_output_add_change_handler() */
+
+TEST(tdm_output_add_change_handler, error_output_is_null)
+{
+       tdm_error error;
+
+       _init_test();
+
+       error = tdm_output_add_change_handler(NULL, stub_tdm_output_change_handler_cb,
+                                                                                 NULL);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_output_add_change_handler, error_func_is_null)
+{
+       tdm_error error;
+       tdm_private_output output;
+
+       _init_test();
+
+       error = tdm_output_add_change_handler(&output, NULL, NULL);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_output_add_change_handler, error_calloc)
+{
+       tdm_error error;
+       tdm_private_output output;
+
+       _init_test();
+
+       CALLOC_ERROR = 1;
+
+       error = tdm_output_add_change_handler(&output, stub_tdm_output_change_handler_cb,
+                                                                                 NULL);
+
+       ASSERT_EQ(error, TDM_ERROR_OUT_OF_MEMORY);
+}
+
+TEST(tdm_output_add_change_handler, success_no_in_display_thread)
+{
+       tdm_error error;
+       tdm_private_output output;
+       int user_data = 10;
+       tdm_private_change_handler *h = NULL, *handler = NULL;
+
+       _init_test();
+
+       LIST_INITHEAD(&output.change_handler_list_main);
+       LIST_INITHEAD(&output.change_handler_list_sub);
+
+       stub_syscall_return_value = 21615;
+
+       error = tdm_output_add_change_handler(&output, stub_tdm_output_change_handler_cb,
+                                                                                 &user_data);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+       ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_main));
+       ASSERT_TRUE(!LIST_IS_EMPTY(&output.change_handler_list_sub));
+       LIST_FOR_EACH_ENTRY(h, &output.change_handler_list_sub, link) {
+               if (h->func == stub_tdm_output_change_handler_cb || h->user_data == &user_data) {
+                       handler = h;
+                       break;
+               }
+       }
+       ASSERT_TRUE(handler);
+       ASSERT_TRUE(handler->private_output == &output);
+       ASSERT_EQ(handler->owner_tid, stub_syscall_return_value);
+       free(handler);
+}
+
+TEST(tdm_output_add_change_handler, success_in_display_thread)
+{
+       tdm_error error;
+       tdm_private_output output;
+       int user_data = 10;
+       tdm_private_change_handler *h = NULL, *handler = NULL;
+
+       _init_test();
+
+       LIST_INITHEAD(&output.change_handler_list_main);
+       LIST_INITHEAD(&output.change_handler_list_sub);
+
+       stub_tdm_thread_display_thread = 1;
+       stub_syscall_return_value = 21615;
+
+       error = tdm_output_add_change_handler(&output, stub_tdm_output_change_handler_cb,
+                                                                                 &user_data);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+       ASSERT_TRUE(!LIST_IS_EMPTY(&output.change_handler_list_main));
+       ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_sub));
+       LIST_FOR_EACH_ENTRY(h, &output.change_handler_list_main, link) {
+               if (h->func == stub_tdm_output_change_handler_cb || h->user_data == &user_data) {
+                       handler = h;
+                       break;
+               }
+       }
+       ASSERT_TRUE(handler);
+       ASSERT_TRUE(handler->private_output == &output);
+       ASSERT_EQ(handler->owner_tid, stub_syscall_return_value);
+       free(handler);
+}
+
+/* tdm_output_remove_change_handler */
+
+TEST(tdm_output_remove_change_handler, success_list_main)
+{
+       tdm_private_output output;
+       int user_data = 10;
+       tdm_private_change_handler *change_handler;
+
+       _init_test();
+
+       LIST_INITHEAD(&output.change_handler_list_main);
+       LIST_INITHEAD(&output.change_handler_list_sub);
+
+       change_handler = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler));
+
+       change_handler->func = stub_tdm_output_change_handler_cb;
+       change_handler->user_data = &user_data;
+
+       LIST_ADD(&change_handler->link, &output.change_handler_list_main);
+
+       tdm_output_remove_change_handler(&output, stub_tdm_output_change_handler_cb,
+                                                                                 &user_data);
+
+       ASSERT_EQ(FREE_CALLED, 1);
+       ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_main));
+}
+
+TEST(tdm_output_remove_change_handler, success_list_sub)
+{
+       tdm_private_output output;
+       int user_data = 10;
+       tdm_private_change_handler *change_handler;
+
+       _init_test();
+
+       LIST_INITHEAD(&output.change_handler_list_main);
+       LIST_INITHEAD(&output.change_handler_list_sub);
+
+       change_handler = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler));
+
+       change_handler->func = stub_tdm_output_change_handler_cb;
+       change_handler->user_data = &user_data;
+
+       LIST_ADD(&change_handler->link, &output.change_handler_list_sub);
+
+       tdm_output_remove_change_handler(&output, stub_tdm_output_change_handler_cb,
+                                                                                 &user_data);
+
+       ASSERT_EQ(FREE_CALLED, 1);
+       ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_sub));
+}
+
+TEST(tdm_output_remove_change_handler, success_list_main_2)
+{
+       tdm_private_output output;
+       int user_data = 10;
+       tdm_private_change_handler *change_handler;
+       tdm_private_change_handler *change_handler_2;
+       tdm_private_change_handler *h = NULL, *handler = NULL;
+
+       _init_test();
+
+       LIST_INITHEAD(&output.change_handler_list_main);
+       LIST_INITHEAD(&output.change_handler_list_sub);
+
+       change_handler = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler));
+
+       change_handler->func = NULL;
+       change_handler->user_data = NULL;
+
+       change_handler_2 = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler));
+
+       change_handler_2->func = stub_tdm_output_change_handler_cb;
+       change_handler_2->user_data = &user_data;
+
+       LIST_ADD(&change_handler_2->link, &output.change_handler_list_main);
+       LIST_ADD(&change_handler->link, &output.change_handler_list_main);
+
+       tdm_output_remove_change_handler(&output, stub_tdm_output_change_handler_cb,
+                                                                                 &user_data);
+
+       ASSERT_EQ(FREE_CALLED, 1);
+       ASSERT_TRUE(!LIST_IS_EMPTY(&output.change_handler_list_main));
+       LIST_FOR_EACH_ENTRY(h, &output.change_handler_list_main, link) {
+               if (h->func == NULL || h->user_data == NULL) {
+                       handler = h;
+                       break;
+               }
+       }
+       ASSERT_TRUE(handler);
+       LIST_DEL(&handler->link);
+       free(handler);
+       ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_main));
+}
+
+TEST(tdm_output_remove_change_handler, success_list_sub_2)
+{
+       tdm_private_output output;
+       int user_data = 10;
+       tdm_private_change_handler *change_handler;
+       tdm_private_change_handler *change_handler_2;
+       tdm_private_change_handler *h = NULL, *handler = NULL;
+
+       _init_test();
+
+       LIST_INITHEAD(&output.change_handler_list_main);
+       LIST_INITHEAD(&output.change_handler_list_sub);
+
+       change_handler = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler));
+
+       change_handler->func = NULL;
+       change_handler->user_data = NULL;
+
+       change_handler_2 = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler));
+
+       change_handler_2->func = stub_tdm_output_change_handler_cb;
+       change_handler_2->user_data = &user_data;
+
+       LIST_ADD(&change_handler_2->link, &output.change_handler_list_sub);
+       LIST_ADD(&change_handler->link, &output.change_handler_list_sub);
+
+       tdm_output_remove_change_handler(&output, stub_tdm_output_change_handler_cb,
+                                                                                 &user_data);
+
+       ASSERT_EQ(FREE_CALLED, 1);
+       ASSERT_TRUE(!LIST_IS_EMPTY(&output.change_handler_list_sub));
+       LIST_FOR_EACH_ENTRY(h, &output.change_handler_list_sub, link) {
+               if (h->func == NULL || h->user_data == NULL) {
+                       handler = h;
+                       break;
+               }
+       }
+       ASSERT_TRUE(handler);
+       LIST_DEL(&handler->link);
+       free(handler);
+       ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_sub));
+}
+
+TEST(tdm_output_remove_change_handler, success_handler_is_not_exist)
+{
+       tdm_private_output output;
+       int user_data = 10;
+       tdm_private_change_handler *change_handler;
+       tdm_private_change_handler *change_handler_2;
+       tdm_private_change_handler *h = NULL, *handler = NULL;
+
+       _init_test();
+
+       LIST_INITHEAD(&output.change_handler_list_main);
+       LIST_INITHEAD(&output.change_handler_list_sub);
+
+       change_handler = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler));
+
+       change_handler->func = NULL;
+       change_handler->user_data = NULL;
+
+       change_handler_2 = (tdm_private_change_handler *)calloc(1, sizeof(tdm_private_change_handler));
+
+       change_handler_2->func = NULL;
+       change_handler_2->user_data = NULL;
+
+       LIST_ADD(&change_handler->link, &output.change_handler_list_sub);
+       LIST_ADD(&change_handler_2->link, &output.change_handler_list_sub);
+
+       tdm_output_remove_change_handler(&output, stub_tdm_output_change_handler_cb,
+                                                                                 &user_data);
+
+       ASSERT_EQ(FREE_CALLED, 0);
+       ASSERT_TRUE(!LIST_IS_EMPTY(&output.change_handler_list_sub));
+       LIST_FOR_EACH_ENTRY(h, &output.change_handler_list_sub, link) {
+               if (h->func == NULL || h->user_data == NULL) {
+                       handler = h;
+                       break;
+               }
+       }
+       ASSERT_TRUE(handler);
+       LIST_DEL(&handler->link);
+       free(handler);
+       handler = NULL;
+       ASSERT_TRUE(!LIST_IS_EMPTY(&output.change_handler_list_sub));
+       LIST_FOR_EACH_ENTRY(h, &output.change_handler_list_sub, link) {
+               if (h->func == NULL || h->user_data == NULL) {
+                       handler = h;
+                       break;
+               }
+       }
+       ASSERT_TRUE(handler);
+       LIST_DEL(&handler->link);
+       free(handler);
+       ASSERT_TRUE(LIST_IS_EMPTY(&output.change_handler_list_sub));
+}
+
+/* tdm_output_get_cursor_available_size() */
+
+TEST(tdm_output_get_cursor_available_size, error_output_is_null)
+{
+       tdm_error error;
+
+       _init_test();
+
+       error = tdm_output_get_cursor_available_size(NULL, NULL, NULL, NULL, NULL, NULL);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_output_get_cursor_available_size, error_abi_version_is_1_4)
+{
+       tdm_error error;
+       tdm_private_output output;
+       tdm_private_display display;
+       tdm_backend_module module;
+       int min_w, min_h, max_w, max_h, preferred_align;
+
+       _init_test();
+
+       output.private_display = &display;
+
+       display.module_data = &module;
+       module.abi_version = 0x00010004;
+
+       output.caps.cursor_min_w = 200;
+       output.caps.cursor_min_h = 300;
+       output.caps.cursor_max_w = 1080;
+       output.caps.cursor_max_h = 1920;
+       output.caps.cursor_preferred_align = 256;
+
+       error = tdm_output_get_cursor_available_size(&output, &min_w, &min_h, &max_w,
+                                                                                                &max_h, &preferred_align);
+
+       ASSERT_EQ(error, TDM_ERROR_BAD_MODULE);
+       ASSERT_EQ(min_w, -1);
+       ASSERT_EQ(min_h, -1);
+       ASSERT_EQ(max_w, -1);
+       ASSERT_EQ(max_h, -1);
+       ASSERT_EQ(preferred_align, -1);
+}
+
+TEST(tdm_output_get_cursor_available_size, success_abi_version_is_1_5)
+{
+       tdm_error error;
+       tdm_private_output output;
+       tdm_private_display display;
+       tdm_backend_module module;
+       int min_w, min_h, max_w, max_h, preferred_align;
+
+       _init_test();
+
+       output.private_display = &display;
+
+       display.module_data = &module;
+       module.abi_version = 0x00010005;
+
+       output.caps.cursor_min_w = 200;
+       output.caps.cursor_min_h = 300;
+       output.caps.cursor_max_w = 1080;
+       output.caps.cursor_max_h = 1920;
+       output.caps.cursor_preferred_align = 256;
+
+       error = tdm_output_get_cursor_available_size(&output, &min_w, &min_h, &max_w,
+                                                                                                &max_h, &preferred_align);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+       ASSERT_EQ(min_w, output.caps.cursor_min_w);
+       ASSERT_EQ(min_h, output.caps.cursor_min_h);
+       ASSERT_EQ(max_w, output.caps.cursor_max_w);
+       ASSERT_EQ(max_h, output.caps.cursor_max_h);
+       ASSERT_EQ(preferred_align, output.caps.cursor_preferred_align);
+}
+
+/* tdm_output_get_primary_index() */
+
+TEST(tdm_output_get_primary_index, error_output_is_null)
+{
+       tdm_error error;
+       int index;
+
+       _init_test();
+
+       error = tdm_output_get_primary_index(NULL, &index);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_output_get_primary_index, error_index_is_null)
+{
+       tdm_error error;
+       tdm_private_output output;
+
+       _init_test();
+
+       error = tdm_output_get_primary_index(&output, NULL);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_output_get_primary_index, success_layer_list_is_empty)
+{
+       tdm_error error;
+       tdm_private_output output;
+       int index = 0;
+
+       _init_test();
+
+       LIST_INITHEAD(&output.layer_list);
+
+       error = tdm_output_get_primary_index(&output, &index);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+       ASSERT_EQ(index, 0);
+}
+
+TEST(tdm_output_get_primary_index, success_get_primary_index)
+{
+       tdm_error error;
+       tdm_private_output output;
+       tdm_private_layer private_layer_1;
+       tdm_private_layer private_layer_2;
+       int index;
+
+       _init_test();
+
+       LIST_INITHEAD(&output.layer_list);
+       LIST_ADD(&private_layer_1.link, &output.layer_list);
+       LIST_ADD(&private_layer_2.link, &output.layer_list);
+
+       private_layer_1.index = 25;
+       private_layer_2.index = 35;
+
+       private_layer_1.caps.capabilities = (tdm_layer_capability)(TDM_LAYER_CAPABILITY_GRAPHIC |
+                                                                               TDM_LAYER_CAPABILITY_PRIMARY);
+
+       private_layer_2.caps.capabilities = (tdm_layer_capability)(TDM_LAYER_CAPABILITY_GRAPHIC |
+                                                                               TDM_LAYER_CAPABILITY_OVERLAY);
+
+       error = tdm_output_get_primary_index(&output, &index);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+       ASSERT_EQ(index, private_layer_1.index);
+}
+
+/* tdm_output_cb_vblank() */
+
+TEST(tdm_output_cb_vblank, success_no_in_display_thread)
+{
+       tdm_private_vblank_handler vblank_handler;
+       tdm_private_output output;
+       tdm_private_display display;
+       unsigned int sequence = 17, tv_sec = 145, tv_usec = 874;
+       tdm_thread_cb_output_vblank *output_vblank;
+
+       _init_test();
+
+       vblank_handler.private_output = &output;
+       output.private_display = &display;
+       output.stamp = 10.11;
+       stub_syscall_return_value = 115;
+       vblank_handler.owner_tid = stub_syscall_return_value - 1;
+
+       tdm_output_cb_vblank(&output, sequence, tv_sec, tv_usec, &vblank_handler);
+
+       output_vblank = (tdm_thread_cb_output_vblank *)stub_tdm_thread_send_cb_buff;
+
+       ASSERT_EQ(output_vblank->base.type, TDM_THREAD_CB_OUTPUT_VBLANK);
+       ASSERT_EQ(output_vblank->base.length, sizeof * output_vblank);
+       ASSERT_DOUBLE_EQ(output_vblank->output_stamp, output.stamp);
+       ASSERT_EQ(output_vblank->sequence, sequence);
+       ASSERT_EQ(output_vblank->tv_sec, tv_sec);
+       ASSERT_EQ(output_vblank->tv_usec, tv_usec);
+       ASSERT_TRUE(output_vblank->user_data == &vblank_handler);
+}
+
+TEST(tdm_output_cb_vblank, success_in_display_thread)
+{
+       tdm_private_vblank_handler *vblank_handler;
+       tdm_private_output output;
+       tdm_private_display display;
+       unsigned int sequence = 17, tv_sec = 145, tv_usec = 874;
+       struct list_head list;
+
+       _init_test();
+
+       vblank_handler = (tdm_private_vblank_handler *)calloc(1, sizeof * vblank_handler);
+       vblank_handler->private_output = &output;
+       output.private_display = &display;
+
+       stub_syscall_return_value = 115;
+       stub_syscall_reset = 1;
+
+       vblank_handler->owner_tid = stub_syscall_return_value;
+       vblank_handler->func = stub_tdm_output_vblank_handler;
+
+       LIST_INITHEAD(&list);
+       LIST_ADD(&vblank_handler->link, &list);
+
+       tdm_output_cb_vblank(&output, sequence, tv_sec, tv_usec, vblank_handler);
+
+       ASSERT_EQ(stub_tdm_output_vblank_handler_count, 1);
+       ASSERT_EQ(FREE_CALLED, 1);
+       ASSERT_TRUE(LIST_IS_EMPTY(&list));
+}
+
+/* tdm_output_cb_commit() */
+
+TEST(tdm_output_cb_commit, success_no_in_display_thread)
+{
+       tdm_private_commit_handler commit_handler;
+       tdm_private_output output;
+       tdm_private_display display;
+       unsigned int sequence = 17, tv_sec = 145, tv_usec = 874;
+       tdm_thread_cb_output_commit *output_commit;
+
+       _init_test();
+
+       commit_handler.private_output = &output;
+       output.private_display = &display;
+       output.stamp = 10.11;
+       stub_syscall_return_value = 115;
+       commit_handler.owner_tid = stub_syscall_return_value - 1;
+
+       tdm_output_cb_commit(&output, sequence, tv_sec, tv_usec, &commit_handler);
+
+       output_commit = (tdm_thread_cb_output_commit *)stub_tdm_thread_send_cb_buff;
+
+       ASSERT_EQ(output_commit->base.type, TDM_THREAD_CB_OUTPUT_COMMIT);
+       ASSERT_EQ(output_commit->base.length, sizeof * output_commit);
+       ASSERT_DOUBLE_EQ(output_commit->output_stamp, output.stamp);
+       ASSERT_EQ(output_commit->sequence, sequence);
+       ASSERT_EQ(output_commit->tv_sec, tv_sec);
+       ASSERT_EQ(output_commit->tv_usec, tv_usec);
+       ASSERT_TRUE(output_commit->user_data == &commit_handler);
+}
+
+TEST(tdm_output_cb_commit, success_in_display_thread)
+{
+       tdm_private_commit_handler *commit_handler;
+       tdm_private_output output;
+       tdm_private_display display;
+       unsigned int sequence = 17, tv_sec = 145, tv_usec = 874;
+       tdm_private_layer private_layer_1;
+       tdm_private_layer private_layer_2;
+       tdm_private_layer private_layer_3;
+       struct _tbm_surface waiting_buffer;
+       struct _tbm_surface showing_buffer;
+       struct list_head list;
+       struct _tbm_surface_queue surface_queue;
+
+       _init_test();
+
+       commit_handler = (tdm_private_commit_handler *)calloc(1, sizeof * commit_handler);
+
+       private_layer_1.waiting_buffer = NULL;
+       private_layer_1.showing_buffer = NULL;
+
+       private_layer_2.waiting_buffer = &waiting_buffer;
+       private_layer_2.showing_buffer = &showing_buffer;
+       private_layer_2.buffer_queue = &surface_queue;
+
+       private_layer_3.waiting_buffer = &waiting_buffer;
+       private_layer_3.showing_buffer = NULL;
+
+       commit_handler->private_output = &output;
+       output.private_display = &display;
+       stub_syscall_return_value = 115;
+       commit_handler->owner_tid = stub_syscall_return_value;
+
+       LIST_INITHEAD(&output.layer_list);
+       LIST_ADD(&private_layer_1.link, &output.layer_list);
+       LIST_ADD(&private_layer_2.link, &output.layer_list);
+       LIST_ADD(&private_layer_3.link, &output.layer_list);
+
+       commit_handler->func = stub_tdm_output_commit_handler;
+
+       LIST_INITHEAD(&list);
+       LIST_ADD(&commit_handler->link, &list);
+
+       tdm_output_cb_commit(&output, sequence, tv_sec, tv_usec, commit_handler);
+
+       ASSERT_EQ(stub_tdm_buffer_unref_backend_count, 1);
+       ASSERT_EQ(tbm_surface_queue_release_count, 1);
+       ASSERT_TRUE(private_layer_1.showing_buffer == NULL);
+       ASSERT_TRUE(private_layer_2.showing_buffer == &waiting_buffer);
+       ASSERT_TRUE(private_layer_3.showing_buffer == &waiting_buffer);
+       ASSERT_TRUE(private_layer_1.waiting_buffer == NULL);
+       ASSERT_TRUE(private_layer_2.waiting_buffer == NULL);
+       ASSERT_TRUE(private_layer_3.waiting_buffer == NULL);
+       ASSERT_EQ(stub_tdm_output_commit_handler_count, 1);
+       ASSERT_EQ(FREE_CALLED, 1);
+       ASSERT_TRUE(LIST_IS_EMPTY(&list));
+}
+
+/* tdm_output_cb_dpms() */
+
+TEST(tdm_output_cb_dpms, success_no_in_display_thread)
+{
+       tdm_private_output output;
+       tdm_private_display display;
+       tdm_thread_cb_output_dpms *output_dpms;
+       tdm_output_dpms dpms = TDM_OUTPUT_DPMS_STANDBY;
+
+       _init_test();
+
+       output.private_display = &display;
+       output.stamp = 10.11;
+
+       LIST_INITHEAD(&output.change_handler_list_sub);
+       LIST_INITHEAD(&output.change_handler_list_main);
+
+       tdm_output_cb_dpms(&output, dpms, &output);
+
+       output_dpms = (tdm_thread_cb_output_dpms *)stub_tdm_thread_send_cb_buff;
+
+       ASSERT_EQ(output_dpms->base.type, TDM_THREAD_CB_OUTPUT_DPMS);
+       ASSERT_EQ(output_dpms->base.length, sizeof * output_dpms);
+       ASSERT_DOUBLE_EQ(output_dpms->output_stamp, output.stamp);
+       ASSERT_EQ(output_dpms->dpms, TDM_OUTPUT_DPMS_STANDBY);
+       ASSERT_TRUE(output_dpms->user_data == &output);
+}
+
+TEST(tdm_output_cb_dpms, success_in_display_thread)
+{
+       tdm_private_output output;
+       tdm_private_display display;
+       tdm_output_dpms dpms = TDM_OUTPUT_DPMS_STANDBY;
+       tdm_private_change_handler change_handler_1;
+       tdm_private_change_handler change_handler_2;
+
+       _init_test();
+
+       stub_tdm_thread_display_thread = 1;
+
+       output.private_display = &display;
+
+       LIST_INITHEAD(&output.change_handler_list_sub);
+       LIST_INITHEAD(&output.change_handler_list_main);
+       LIST_ADD(&change_handler_1.link, &output.change_handler_list_main);
+       LIST_ADD(&change_handler_2.link, &output.change_handler_list_main);
+
+       change_handler_1.func = stub_tdm_output_change_handler_cb;
+       change_handler_2.func = stub_tdm_output_change_handler_cb;
+
+       tdm_output_cb_dpms(&output, dpms, &output);
+
+       ASSERT_EQ(stub_tdm_output_change_handler_count, 2);
+       ASSERT_EQ(output.current_dpms_value, dpms);
+
+}
+
+/* tdm_layer_get_displaying_buffer() */
+
+TEST(tdm_layer_get_displaying_buffer, error_layer_is_null)
+{
+       tdm_error error;
+       tbm_surface_h buffer;
+
+       _init_test();
+
+       buffer = tdm_layer_get_displaying_buffer(NULL, &error);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+       ASSERT_EQ(buffer, NULL);
+}
+
+TEST(tdm_layer_get_displaying_buffer, error_showing_buffer_is_null)
+{
+       tdm_error error;
+       tbm_surface_h buffer;
+       tdm_private_layer layer;
+       tdm_private_output output;
+
+       _init_test();
+
+       layer.private_output = &output;
+
+       layer.showing_buffer = NULL;
+
+       buffer = tdm_layer_get_displaying_buffer(&layer, &error);
+
+       ASSERT_EQ(error, TDM_ERROR_OPERATION_FAILED);
+       ASSERT_EQ(buffer, NULL);
+}
+
+TEST(tdm_layer_get_displaying_buffer, success_get_displaying_buffer)
+{
+       tdm_error error;
+       tbm_surface_h buffer;
+       tdm_private_layer layer;
+       tdm_private_output output;
+       struct _tbm_surface showing_buffer;
+
+       _init_test();
+
+       layer.private_output = &output;
+
+       layer.showing_buffer = &showing_buffer;
+
+       buffer = tdm_layer_get_displaying_buffer(&layer, &error);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+       ASSERT_EQ(buffer, &showing_buffer);
+}
+
+/* tdm_layer_get_buffer_flags() */
+
+TEST(tdm_layer_get_buffer_flags, error_layer_is_null)
+{
+       tdm_error error;
+       unsigned int flags;
+
+       _init_test();
+
+       error = tdm_layer_get_buffer_flags(NULL, &flags);
+
+       ASSERT_EQ(error, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST(tdm_layer_get_buffer_flags, error_layer_get_buffer_flags_is_null)
+{
+       tdm_error error;
+       unsigned int flags;
+       tdm_private_layer layer;
+       tdm_private_output output;
+       tdm_private_display display;
+       tdm_func_layer func_layer;
+
+       _init_test();
+
+       layer.private_output = &output;
+       output.private_display = &display;
+
+       func_layer.layer_get_buffer_flags = NULL;
+
+       display.func_layer = func_layer;
+
+       error = tdm_layer_get_buffer_flags(&layer, &flags);
+
+       ASSERT_EQ(error, TDM_ERROR_NOT_IMPLEMENTED);
+}
+
+TEST(tdm_layer_get_buffer_flags, success_get_buffer_flags)
+{
+       tdm_error error;
+       unsigned int flags;
+       tdm_private_layer layer;
+       tdm_private_output output;
+       tdm_private_display display;
+       tdm_func_layer func_layer;
+
+       _init_test();
+
+       layer.private_output = &output;
+       output.private_display = &display;
+
+       func_layer.layer_get_buffer_flags = layer_get_buffer_flags;
+
+       display.func_layer = func_layer;
+
+       error = tdm_layer_get_buffer_flags(&layer, &flags);
+
+       ASSERT_EQ(error, TDM_ERROR_NONE);
+       ASSERT_EQ(flags, layer_get_buffer_flags_ret);
+}
index 3f3a200..3d28349 100644 (file)
@@ -24,6 +24,7 @@ int LAYER_UNSET_BUFFER_ERROR;
 int LAYER_SET_VIDEO_POS_ERROR;
 int PP_SET_INFO_ERROR;
 int PP_COMMIT_ERROR;
+unsigned int layer_get_buffer_flags_ret;
 
 void stub_backend_init()
 {
@@ -50,6 +51,7 @@ void stub_backend_init()
        LAYER_SET_VIDEO_POS_ERROR = 0;
        PP_SET_INFO_ERROR = 0;
        PP_COMMIT_ERROR = 0;
+       layer_get_buffer_flags_ret = 20;
 }
 
 tdm_capture *output_create_capture(tdm_output *output, tdm_error *error)
@@ -342,3 +344,19 @@ tdm_error pp_commit(tdm_pp *pp)
 
        return TDM_ERROR_NONE;
 }
+
+tdm_error output_set_dpms_handler(tdm_output *output,
+                                                                 tdm_output_dpms_handler func,
+                                                                 void *user_data)
+{
+       return TDM_ERROR_NONE;
+}
+
+tdm_error layer_get_buffer_flags(tdm_layer *layer, unsigned int *flags)
+{
+       (void)layer;
+
+       *flags = layer_get_buffer_flags_ret;
+
+       return TDM_ERROR_NONE;
+}
index 355e275..a47f1b3 100644 (file)
@@ -3,6 +3,8 @@
 
 #include "tdm_types.h"
 
+#include "tdm_backend.h"
+
 extern int OUTPUT_CREATE_CAPTURE_ERROR;
 extern int CAPTURE_SET_DONE_HANDLER_ERROR;
 extern int LAYER_CREATE_CAPTURE_ERROR;
@@ -26,6 +28,7 @@ extern int LAYER_UNSET_BUFFER_ERROR;
 extern int LAYER_SET_VIDEO_POS_ERROR;
 extern int PP_SET_INFO_ERROR;
 extern int PP_COMMIT_ERROR;
+extern unsigned int layer_get_buffer_flags_ret;
 
 void stub_backend_init();
 
@@ -82,5 +85,11 @@ tdm_error pp_set_info(tdm_pp *pp, tdm_info_pp *info);
 
 tdm_error pp_commit(tdm_pp *pp);
 
+tdm_error output_set_dpms_handler(tdm_output *output,
+                                                                 tdm_output_dpms_handler func,
+                                                                 void *user_data);
+
+tdm_error layer_get_buffer_flags(tdm_layer *layer, unsigned int *flags);
+
 
 #endif /* _TDM_CAPTURE_STUBS_H */
index 64a8125..b8c0527 100644 (file)
@@ -5,11 +5,15 @@
 
 static tdm_private_output stub_private_output;
 static int stub_tdm_vblank_handler_call_count;
+static int stub_tdm_output_change_handler_count;
+static int stub_tdm_output_commit_handler_count;
 
 static void
 stub_tdm_init()
 {
        stub_tdm_vblank_handler_call_count = 0;
+       stub_tdm_output_change_handler_count = 0;
+       stub_tdm_output_commit_handler_count = 0;
 }
 
 static tdm_private_output*
@@ -28,6 +32,31 @@ stub_tdm_vblank_handler(tdm_vblank *vblank, tdm_error error, unsigned int sequen
        stub_tdm_vblank_handler_call_count++;
 }
 
+static tdm_error
+stub_tdm_display_update_output(tdm_private_display *private_display,
+                                                 tdm_output *output_backend, int pipe)
+{
+       return TDM_ERROR_NONE;
+}
+
+static void
+stub_tdm_output_change_handler_cb(tdm_output *output,
+                                                                 tdm_output_change_type type,
+                                                                 tdm_value value,
+                                                                 void *user_data)
+{
+       stub_tdm_output_change_handler_count++;
+}
+
+static void
+stub_tdm_output_commit_handler(tdm_output *output, unsigned int sequence,
+                                                          unsigned int tv_sec, unsigned int tv_usec,
+                                                          void *user_data)
+{
+       stub_tdm_output_commit_handler_count++;
+}
+
 #define tdm_display_find_output_stamp stub_tdm_display_find_output_stamp
+#define tdm_display_update_output stub_tdm_display_update_output
 
 #endif // STUB_TDM_H
index f7135fc..43dee2a 100644 (file)
@@ -1,13 +1,28 @@
 #ifndef STUB_TDM_BUFFER_H
 #define STUB_TDM_BUFFER_H
 
-static tbm_surface_h ut_tdm_buffer_ref_backend(tbm_surface_h buffer)
+static int stub_tdm_buffer_unref_backend_count;
+
+static void stub_tdm_buffer_init()
+{
+       stub_tdm_buffer_unref_backend_count = 0;
+}
+
+static tbm_surface_h stub_tdm_buffer_ref_backend(tbm_surface_h buffer)
 {
        (void)buffer;
 
        return NULL;
 }
 
-#define tdm_buffer_ref_backend ut_tdm_buffer_ref_backend
+static void stub_tdm_buffer_unref_backend(tbm_surface_h buffer)
+{
+       (void)buffer;
+
+       stub_tdm_buffer_unref_backend_count++;
+}
+
+#define tdm_buffer_ref_backend stub_tdm_buffer_ref_backend
+#define tdm_buffer_unref_backend stub_tdm_buffer_unref_backend
 
 #endif // STUB_TDM_BUFFER_H
index e978acd..cfbd9c3 100644 (file)
@@ -6,12 +6,14 @@
 static int TDM_EVENT_LOOP_DISPATCH_ERROR;
 static tdm_event_loop_source *stub_tdm_event_loop_removed_source;
 static int stub_tdm_event_loop_source_timer_update_error;
+static int stub_tdm_event_loop_add_timer_handler_error;
 
 static void stub_tdm_event_loop_init()
 {
        stub_tdm_event_loop_removed_source = NULL;
        TDM_EVENT_LOOP_DISPATCH_ERROR = 0;
        stub_tdm_event_loop_source_timer_update_error = 0;
+       stub_tdm_event_loop_add_timer_handler_error = 0;
 }
 
 static int stub_tdm_event_loop_get_fd(tdm_private_display *private_display)
@@ -51,9 +53,20 @@ stub_tdm_event_loop_source_timer_update(tdm_event_loop_source *source, unsigned
        return TDM_ERROR_NONE;
 }
 
+static tdm_event_loop_source *
+stub_tdm_event_loop_add_timer_handler(tdm_display *dpy, tdm_event_loop_timer_handler func,
+                                                                         void *user_data, tdm_error *error)
+{
+       if (stub_tdm_event_loop_add_timer_handler_error)
+               return NULL;
+
+       return (tdm_event_loop_source *)56544545;
+}
+
 #define tdm_event_loop_get_fd stub_tdm_event_loop_get_fd
 #define tdm_event_loop_dispatch stub_tdm_event_loop_dispatch
 #define tdm_event_loop_source_remove stub_tdm_event_loop_source_remove
 #define tdm_event_loop_source_timer_update stub_tdm_event_loop_source_timer_update
+#define tdm_event_loop_add_timer_handler stub_tdm_event_loop_add_timer_handler
 
 #endif // STUB_TDM_EVENT_LOOP_H
index d1f6044..3754019 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef STUB_TDM_HELPER_H
 #define STUB_TDM_HELPER_H
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 static double stub_tdm_helper_get_time_ret_val;
 
 static void
@@ -20,7 +24,18 @@ stub_tdm_helper_get_time(void)
        return stub_tdm_helper_get_time_ret_val;
 }
 
+static void
+stub_tdm_helper_dump_buffer_str(tbm_surface_h buffer, char *dir, char *str)
+{
+
+}
+
+#ifdef __cplusplus
+}
+#endif
+
 #define tdm_helper_get_time_ret_val stub_tdm_helper_get_time_ret_val
 #define tdm_helper_get_time stub_tdm_helper_get_time
+#define tdm_helper_dump_buffer_str stub_tdm_helper_dump_buffer_str
 
 #endif // STUB_TDM_HELPER_H
index 0fc110a..4f8137e 100644 (file)
@@ -7,19 +7,27 @@
 static int TDM_THREAD_HANDLE_ERROR;
 static int stub_tdm_thread_send_cb_error;
 static char stub_tdm_thread_send_cb_buff[1024];
+static int stub_tdm_thread_is_run;
+static int stub_tdm_thread_ret_fd;
+static int stub_tdm_thread_display_thread;
+static int stub_tdm_output_vblank_handler_count;
 
 static void stub_tdm_thread_init()
 {
        TDM_THREAD_HANDLE_ERROR = 0;
        stub_tdm_thread_send_cb_error = 0;
        memset(stub_tdm_thread_send_cb_buff, 0, 1024);
+       stub_tdm_thread_is_run = 0;
+       stub_tdm_thread_ret_fd = 1;
+       stub_tdm_thread_display_thread = 0;
+       stub_tdm_output_vblank_handler_count = 0;
 }
 
 static int stub_tdm_thread_get_fd(tdm_private_loop *private_loop)
 {
        (void)private_loop;
 
-       return 1;
+       return stub_tdm_thread_ret_fd;
 }
 
 static tdm_error stub_tdm_thread_handle_cb(tdm_private_loop *private_loop)
@@ -44,8 +52,38 @@ stub_tdm_thread_send_cb(tdm_private_loop *private_loop, tdm_thread_cb_base *base
        return TDM_ERROR_NONE;
 }
 
+static int
+stub_tdm_thread_is_running(void)
+{
+       return (stub_tdm_thread_is_run) ? 1 : 0;
+}
+
+static int
+stub_tdm_thread_in_display_thread(pid_t tid)
+{
+       (void)tid;
+
+       return (stub_tdm_thread_display_thread) ? 1 : 0;
+}
+
+static void
+stub_tdm_output_vblank_handler(tdm_output *output, unsigned int sequence,
+                                                               unsigned int tv_sec, unsigned int tv_usec,
+                                                               void *user_data)
+{
+       (void)output;
+       (void)sequence;
+       (void)tv_sec;
+       (void)tv_usec;
+       (void)user_data;
+
+       stub_tdm_output_vblank_handler_count++;
+}
+
 #define tdm_thread_get_fd stub_tdm_thread_get_fd
 #define tdm_thread_handle_cb stub_tdm_thread_handle_cb
 #define tdm_thread_send_cb stub_tdm_thread_send_cb
+#define tdm_thread_is_running stub_tdm_thread_is_running
+#define tdm_thread_in_display_thread stub_tdm_thread_in_display_thread
 
 #endif // STUB_TDM_THREAD_H
index 3bb7e31..33fcf6e 100644 (file)
@@ -1,23 +1,30 @@
 #include "stub_unistd.h"
 
 #include <string.h>
+#include <errno.h>
 
 int stub_pipe_error;
 int stub_write_error;
 int stub_syscall_return_value;
+int stub_syscall_reset;
 short stub_unistd_closed_fds[STUB_UNISTD_SIZE_FDS];
 void *stub_read_buf;
 int stub_read_returned_size;
 int stub_dub_error = 0;
+int stub_poll_error;
+int stub_poll_eagain;
 
 void stub_unistd_init()
 {
        stub_pipe_error = 0;
        stub_syscall_return_value = 1;
+       stub_syscall_reset = 0;
        stub_write_error = 0;
        stub_read_buf = NULL;
        stub_read_returned_size = 0;
        stub_dub_error = 0;
+       stub_poll_error = 0;
+       stub_poll_eagain = 0;
        for(int i = 0; i < STUB_UNISTD_SIZE_FDS; ++i) {
                stub_unistd_closed_fds[i] = 0;
        }
@@ -34,8 +41,12 @@ int stub_pipe(int pipedes[2])
 long int stub_syscall(long int sysno, ...)
 {
        (void)sysno;
+       long int ret = stub_syscall_return_value;
 
-       return stub_syscall_return_value;
+       if (stub_syscall_reset)
+               stub_syscall_return_value = 1;
+
+       return ret;
 }
 
 int stub_close(int fd)
@@ -101,5 +112,15 @@ int stub_poll(struct pollfd *fds, nfds_t nfds, int timeout)
        (void)nfds;
        (void)timeout;
 
-       return 1;
+       if (stub_poll_eagain) {
+               stub_poll_eagain = 0;
+               errno = EAGAIN;
+               return -1;
+       }
+       if (stub_poll_error) {
+               errno = EPERM;
+               return -1;
+       }
+
+       return 0;
 }
index 10e2531..d245445 100644 (file)
@@ -2,17 +2,20 @@
 #define STUB_UNISTD_H
 
 #include <unistd.h>
-#include <sys/poll.h>"
+#include <sys/poll.h>
 
 #define STUB_UNISTD_SIZE_FDS 32
 
 extern int stub_pipe_error;
 extern int stub_syscall_return_value;
+extern int stub_syscall_reset;
 extern int stub_write_error;
 extern short stub_unistd_closed_fds[STUB_UNISTD_SIZE_FDS];
 extern void *stub_read_buf;
 extern int stub_read_returned_size;
 extern int stub_dub_error;
+extern int stub_poll_error;
+extern int stub_poll_eagain;
 
 void stub_unistd_init();
 
index ce98c5f..c19ec40 100644 (file)
@@ -4,6 +4,7 @@
 
 int TBM_BUFMGR_DEINIT_CALLED = 0;
 int TBM_BO_GET_USER_DATA_NULL = 0;
+int tbm_surface_queue_release_count;
 
 tbm_bufmgr tbm_bufmgr_init(int fd)
 {
@@ -91,6 +92,8 @@ tbm_surface_queue_error_e tbm_surface_queue_release(
        (void)surface_queue;
        (void)surface;
 
+       tbm_surface_queue_release_count++;
+
        return TBM_SURFACE_QUEUE_ERROR_NONE;
 }
 
@@ -225,4 +228,5 @@ void stub_tbm_init()
 {
        TBM_BUFMGR_DEINIT_CALLED = 0;
        TBM_BO_GET_USER_DATA_NULL = 0;
+       tbm_surface_queue_release_count = 0;
 }
index dcbde86..f5124d8 100644 (file)
@@ -7,6 +7,7 @@
 
 extern int TBM_BUFMGR_DEINIT_CALLED;
 extern int TBM_BO_GET_USER_DATA_NULL;
+extern int tbm_surface_queue_release_count;
 
 struct _tbm_surface {
        int temp;