ut: improve code coverage 24/158224/2
authorKonstantin Drabeniuk <k.drabeniuk@samsung.com>
Fri, 2 Dec 2016 12:46:48 +0000 (14:46 +0200)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 30 Oct 2017 11:13:49 +0000 (20:13 +0900)
- write test for tdm_thread.c
- fix broken test
- refactoring stubs

Change-Id: I5c9be1d39dc1cc68b865a89698d94fc7ed52b463
Signed-off-by: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
Signed-off-by: SooChan Lim <sc1.lim@samsung.com>
40 files changed:
ut/Makefile.am
ut/src/ut_tdm.cpp
ut/src/ut_tdm_backend.cpp
ut/src/ut_tdm_buffer.cpp
ut/src/ut_tdm_capture.cpp
ut/src/ut_tdm_display.cpp
ut/src/ut_tdm_event_loop.cpp
ut/src/ut_tdm_helper.cpp
ut/src/ut_tdm_pp.cpp
ut/src/ut_tdm_thread.cpp [new file with mode: 0644]
ut/stubs/pthread_stubs.cpp [deleted file]
ut/stubs/pthread_stubs.h [deleted file]
ut/stubs/stdlib_stubs.cpp [deleted file]
ut/stubs/stdlib_stubs.h [deleted file]
ut/stubs/stub_backend.cpp [new file with mode: 0644]
ut/stubs/stub_backend.h [new file with mode: 0644]
ut/stubs/stub_fcntl.h [new file with mode: 0644]
ut/stubs/stub_pthread.cpp [new file with mode: 0644]
ut/stubs/stub_pthread.h [new file with mode: 0644]
ut/stubs/stub_stdio.h [new file with mode: 0644]
ut/stubs/stub_stdlib.cpp [new file with mode: 0644]
ut/stubs/stub_stdlib.h [new file with mode: 0644]
ut/stubs/stub_tdm.h [new file with mode: 0644]
ut/stubs/stub_tdm_buffer.h [new file with mode: 0644]
ut/stubs/stub_tdm_capture.h [new file with mode: 0644]
ut/stubs/stub_tdm_display.h [new file with mode: 0644]
ut/stubs/stub_tdm_event_loop.h [new file with mode: 0644]
ut/stubs/stub_tdm_pp.h [new file with mode: 0644]
ut/stubs/stub_tdm_thread.h [new file with mode: 0644]
ut/stubs/stub_tdm_vblank.h [new file with mode: 0644]
ut/stubs/stub_unistd.cpp [new file with mode: 0644]
ut/stubs/stub_unistd.h [new file with mode: 0644]
ut/stubs/tbm_stubs.cpp
ut/stubs/tbm_stubs.h
ut/stubs/tdm_capture_stubs.h [deleted file]
ut/stubs/tdm_display_stubs.h [deleted file]
ut/stubs/tdm_helper_stubs.h [deleted file]
ut/stubs/tdm_pp_stubs.h [deleted file]
ut/stubs/tdm_thread.cpp [deleted file]
ut/stubs/tdm_vblank.cpp

index 565fa81..01fe2c8 100644 (file)
@@ -10,13 +10,15 @@ tdm_utests_SOURCES = \
        src/ut_tdm_event_loop.cpp \
        src/ut_tdm_helper.cpp \
        src/ut_tdm_pp.cpp \
+       src/ut_tdm_thread.cpp \
        stubs/tbm_stubs.cpp \
        stubs/tdm_log.cpp \
-       stubs/tdm_thread.cpp \
        stubs/tdm_server.cpp \
        stubs/tdm_vblank.cpp \
-       stubs/pthread_stubs.cpp \
-       stubs/stdlib_stubs.cpp
+       stubs/stub_pthread.cpp \
+       stubs/stub_stdlib.cpp \
+       stubs/stub_unistd.cpp \
+       stubs/stub_backend.cpp
 
 tdm_utests_CXXFLAGS = \
        $(CXXFLAGS) \
index 11ef4f2..57a7aba 100644 (file)
 #include "gtest/gtest.h"
 
 #include "tbm_stubs.h"
-#include "pthread_stubs.h"
-#include "stdlib_stubs.h"
-
-#define pthread_mutex_lock ut_pthread_mutex_lock
-#define calloc ut_calloc
-#define free ut_free
-#define pthread_mutex_init ut_pthread_mutex_init
-#define pthread_mutex_unlock ut_pthread_mutex_unlock
+#include "stub_pthread.h"
+#include "stub_stdlib.h"
 
 #include "tdm.c"
 
@@ -46,12 +40,10 @@ static tdm_private_display ut_private_display;
 
 static void _init_test()
 {
-       TBM_BUFMGR_DEINIT_CALLED = 0;
-       TBM_BO_GET_USER_DATA_NULL = 0;
-       PTHREAD_MUTEX_INIT_ERROR = 0;
-       CALLOC_ERROR = 0;
-       CALLOC_RETURN_BUFFER = 0;
-       FREE_CALLED = 0;
+       stub_pthread_init();
+       stub_tbm_init();
+       stub_stdlib_init();
+
        g_private_display = NULL;
 }
 
index 79465d9..019dd3c 100644 (file)
 #include "gtest/gtest.h"
 
 #include "tbm_stubs.h"
-#include "pthread_stubs.h"
-#include "stdlib_stubs.h"
-
-#define pthread_mutex_lock ut_pthread_mutex_lock
-#define calloc ut_calloc
-#define free ut_free
-#define pthread_mutex_init ut_pthread_mutex_init
-#define pthread_mutex_unlock ut_pthread_mutex_unlock
+#include "stub_pthread.h"
+#include "stub_stdlib.h"
 
 #include "tdm_backend.c"
 
 static void _init_test()
 {
-       TBM_BUFMGR_DEINIT_CALLED = 0;
-       TBM_BO_GET_USER_DATA_NULL = 0;
-       PTHREAD_MUTEX_INIT_ERROR = 0;
-       CALLOC_ERROR = 0;
-       CALLOC_RETURN_BUFFER = 0;
-       FREE_CALLED = 0;
+       stub_pthread_init();
+       stub_tbm_init();
+       stub_stdlib_init();
 }
 
 /* tdm_backend_register_func_capture */
@@ -237,6 +228,7 @@ TEST(tdm_backend_register_func_display, work_flow_success_1)
        _init_test();
 
        dpy.module_data = &module;
+       module.abi_version = 0x00020000;
 
        error = tdm_backend_register_func_display(&dpy, &func_display);
 
index 05e69ee..2eab3d9 100644 (file)
 #include "gtest/gtest.h"
 
 #include "tbm_stubs.h"
-#include "pthread_stubs.h"
-#include "stdlib_stubs.h"
+#include "stub_pthread.h"
 #include "tdm_list_stubs.h"
-
-#define pthread_mutex_lock ut_pthread_mutex_lock
-#define calloc ut_calloc
-#define free ut_free
-#define pthread_mutex_init ut_pthread_mutex_init
-#define pthread_mutex_unlock ut_pthread_mutex_unlock
+#include "stub_stdlib.h"
 
 #include "tdm_buffer.c"
 
@@ -49,12 +43,9 @@ void tdm_buffer_release_handler_f(tbm_surface_h buffer, void *user_data)
 
 static void _init_test()
 {
-       TBM_BUFMGR_DEINIT_CALLED = 0;
-       TBM_BO_GET_USER_DATA_NULL = 0;
-       PTHREAD_MUTEX_INIT_ERROR = 0;
-       CALLOC_ERROR = 0;
-       CALLOC_RETURN_BUFFER = 0;
-       FREE_CALLED = 0;
+       stub_pthread_init();
+       stub_tbm_init();
+       stub_stdlib_init();
 }
 
 /* tdm_buffer_list_get_first_entry */
index 55d8ae2..62d4155 100644 (file)
 #include "gtest/gtest.h"
 
 #include "tbm_stubs.h"
-#include "pthread_stubs.h"
-#include "stdlib_stubs.h"
+#include "stub_pthread.h"
 #include "tdm_list_stubs.h"
-#include "tdm_capture_stubs.h"
-
-#define pthread_mutex_lock ut_pthread_mutex_lock
-#define calloc ut_calloc
-#define free ut_free
-#define pthread_mutex_init ut_pthread_mutex_init
-#define pthread_mutex_unlock ut_pthread_mutex_unlock
+#include "stub_stdlib.h"
+#include "stub_backend.h"
 
 #include "tdm_capture.c"
 
 
 static void _init_test()
 {
-       TBM_BUFMGR_DEINIT_CALLED = 0;
-       TBM_BO_GET_USER_DATA_NULL = 0;
-       PTHREAD_MUTEX_INIT_ERROR = 0;
-       CALLOC_ERROR = 0;
-       CALLOC_RETURN_BUFFER = 0;
-       FREE_CALLED = 0;
-       OUTPUT_CREATE_CAPTURE_ERROR = 0;
-       CAPTURE_SET_DONE_HANDLER_ERROR = 0;
-       LAYER_CREATE_CAPTURE_ERROR = 0;
-       CAPTURE_SET_INFO_ERROR = 0;
-       CAPTURE_ATTACH_ERROR = 0;
-       CAPTURE_COMMIT_ERROR = 0;
+       stub_pthread_init();
+       stub_backend_init();
+       stub_tbm_init();
+       stub_stdlib_init();
 }
 
 /* tdm_capture_commit */
@@ -268,6 +254,7 @@ TEST(tdm_capture_create_layer_internal, work_flow_success_4)
        private_display.func_layer.layer_create_capture = layer_create_capture;
        private_display.func_capture.capture_destroy = capture_destroy;
        private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE;
+       private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_LAYER;
 
        actual = tdm_capture_create_layer_internal(&private_layer, &error);
 
@@ -293,6 +280,7 @@ TEST(tdm_capture_create_layer_internal, work_flow_success_3)
        private_display.func_layer.layer_create_capture = layer_create_capture;
        private_display.func_capture.capture_destroy = capture_destroy;
        private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE;
+       private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_LAYER;
 
        CALLOC_ERROR = 1;
 
@@ -366,6 +354,7 @@ TEST(tdm_capture_create_output_internal, work_flow_success_5)
        private_display.func_capture.capture_set_done_handler =
                        capture_set_done_handler;
        private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE;
+       private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_OUTPUT;
 
        actual = tdm_capture_create_output_internal(&private_output, &error);
 
@@ -390,6 +379,7 @@ TEST(tdm_capture_create_output_internal, work_flow_success_4)
        private_display.func_capture.capture_destroy = capture_destroy;
        private_display.func_capture.capture_set_done_handler = capture_set_done_handler;
        private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE;
+       private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_OUTPUT;
        CAPTURE_SET_DONE_HANDLER_ERROR = 1;
 
        actual = tdm_capture_create_output_internal(&private_output, &error);
@@ -414,6 +404,7 @@ TEST(tdm_capture_create_output_internal, work_flow_success_3)
        private_display.func_capture.capture_destroy = capture_destroy;
        private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE;
        CALLOC_ERROR = 1;
+       private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_OUTPUT;
 
        actual = tdm_capture_create_output_internal(&private_output, &error);
 
@@ -435,6 +426,7 @@ TEST(tdm_capture_create_output_internal, work_flow_success_2)
        private_output.private_display = &private_display;
        private_display.func_output.output_create_capture = output_create_capture;
        private_display.capabilities = TDM_DISPLAY_CAPABILITY_CAPTURE;
+       private_display.caps_capture.capabilities = TDM_CAPTURE_CAPABILITY_OUTPUT;
        OUTPUT_CREATE_CAPTURE_ERROR = 1;
 
        actual = tdm_capture_create_output_internal(&private_output, &error);
index e30065b..e1d9184 100644 (file)
 #include "gtest/gtest.h"
 
 #include "tbm_stubs.h"
-#include "pthread_stubs.h"
-#include "stdlib_stubs.h"
+#include "stub_pthread.h"
 #include "tdm_list_stubs.h"
-#include "tdm_display_stubs.h"
-
-#define pthread_mutex_lock ut_pthread_mutex_lock
-#define calloc ut_calloc
-#define free ut_free
-#define pthread_mutex_init ut_pthread_mutex_init
-#define pthread_mutex_unlock ut_pthread_mutex_unlock
-#define tdm_pp_create_internal ut_tdm_pp_create_internal
-#define tdm_capture_create_output_internal ut_tdm_capture_create_output_internal
-#define tdm_buffer_ref_backend ut_tdm_buffer_ref_backend
-#define tdm_thread_get_fd ut_tdm_thread_get_fd
-#define tdm_event_loop_get_fd ut_tdm_event_loop_get_fd
-#define tdm_capture_create_layer_internal ut_tdm_capture_create_layer_internal
-#define poll ut_poll
-#define tdm_thread_handle_cb ut_tdm_thread_handle_cb
-#define tdm_event_loop_dispatch ut_tdm_event_loop_dispatch
+#include "stub_stdlib.h"
+#include "stub_backend.h"
+#include "stub_tdm_pp.h"
+#include "stub_tdm_capture.h"
+#include "stub_tdm_thread.h"
+#include "stub_tdm_event_loop.h"
+#include "stub_tdm_buffer.h"
+#include "stub_unistd.h"
 
 #include "tdm_display.c"
 
 static void _init_test()
 {
-       TBM_BUFMGR_DEINIT_CALLED = 0;
-       TBM_BO_GET_USER_DATA_NULL = 0;
-       PTHREAD_MUTEX_INIT_ERROR = 0;
-       CALLOC_ERROR = 0;
-       CALLOC_RETURN_BUFFER = 0;
-       FREE_CALLED = 0;
-       TDM_PP_CREATE_INTERNAL_ERROR = 0;
-       OUTPUT_SET_PROPERTY_ERROR = 0;
-       OUTPUT_GET_PROPERTY_ERROR = 0;
-       OUTPUT_WAIT_VBLANK_ERROR = 0;
-       OUTPUT_SET_VBLANK_HANDLER = 0;
-       OUTPUT_COMMIT_ERROR = 0;
-       OUTPUT_SET_COMMIT_HANDLER = 0;
-       OUTPUT_SET_MODE_ERROR = 0;
-       OUTPUT_SET_DPMS_ERROR = 0;
-       OUTPUT_GET_DPMS_ERROR = 0;
-       TDM_CAPTURE_CREATE_OUTPUT_INTENAL_ERROR = 0;
-       LAYER_SET_PROPERTY_ERROR = 0;
-       LAYER_GET_PROPERTY_ERROR = 0;
-       LAYER_SET_INFO_ERROR = 0;
-       LAYER_SET_BUFFER_ERROR = 0;
-       LAYER_UNSET_BUFFER_ERROR = 0;
-       LAYER_SET_VIDEO_POS_ERROR = 0;
-       CAPTURE_CREATE_LAYER_INTERNAL_ERROR = 0;
-       TDM_THREAD_HANDLE_ERROR = 0;
-       TDM_EVENT_LOOP_DISPATCH_ERROR = 0;
+       stub_pthread_init();
+       stub_tdm_event_loop_init();
+       stub_tdm_thread_init();
+       stub_tdm_capture_init();
+       stub_tdm_pp_init();
+       stub_backend_init();
+       stub_tbm_init();
+       stub_stdlib_init();
+}
+
+static void ut_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;
 }
 
 /* UNIT TESTS */
@@ -1346,6 +1331,7 @@ TEST(tdm_output_set_dpms, work_flow_success_3)
 
        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);
 
@@ -1627,6 +1613,8 @@ TEST(tdm_output_commit, work_flow_success_3)
        private_display.func_output.output_commit = output_commit;
        OUTPUT_COMMIT_ERROR = 1;
        output.current_dpms_value = TDM_OUTPUT_DPMS_ON;
+       private_display.func_output.output_set_commit_handler =
+                       output_set_commit_handler;
 
        error = tdm_output_commit(&output, 0, NULL, NULL);
 
index c249c50..f85cd67 100644 (file)
 #include "gtest/gtest.h"
 
 #include "tbm_stubs.h"
-#include "pthread_stubs.h"
-#include "stdlib_stubs.h"
-
-#define pthread_mutex_lock ut_pthread_mutex_lock
-#define calloc ut_calloc
-#define free ut_free
-#define pthread_mutex_init ut_pthread_mutex_init
-#define pthread_mutex_unlock ut_pthread_mutex_unlock
+#include "stub_pthread.h"
+#include "stub_stdlib.h"
 
 #include "tdm_event_loop.c"
 
 static void _init_test()
 {
-       TBM_BUFMGR_DEINIT_CALLED = 0;
-       TBM_BO_GET_USER_DATA_NULL = 0;
-       PTHREAD_MUTEX_INIT_ERROR = 0;
-       CALLOC_ERROR = 0;
-       CALLOC_RETURN_BUFFER = 0;
-       FREE_CALLED = 0;
        WL_EVENT_LOOP_ADD_FD_ERROR = 0;
        WL_EVENT_SOURCE_FD_UPDATE_ERROR = 0;
        WL_EVENT_LOOP_ADD_TIMER_ERROR = 0;
        WL_EVENT_SOURCE_TIMER_UPDATE_ERROR = 0;
+
+       stub_pthread_init();
+       stub_tbm_init();
+       stub_stdlib_init();
 }
 
 /* HELPER FUNCTIONS */
index 5e69797..098da6f 100644 (file)
 #include "gtest/gtest.h"
 
 #include "tbm_stubs.h"
-#include "pthread_stubs.h"
-#include "stdlib_stubs.h"
-#include "tdm_helper_stubs.h"
-
-#define pthread_mutex_lock ut_pthread_mutex_lock
-#define calloc ut_calloc
-#define free ut_free
-#define pthread_mutex_init ut_pthread_mutex_init
-#define pthread_mutex_unlock ut_pthread_mutex_unlock
-#define getenv ut_getenv
-#define sscanf ut_sscanf
-#define fcntl ut_fcntl
-#define dup ut_dup
+#include "stub_pthread.h"
+#include "stub_stdlib.h"
+#include "stub_unistd.h"
+#include "stub_fcntl.h"
+#include "stub_stdio.h"
+
+#pragma GCC optimize(0)
 
 #include "tdm_helper.c"
 
 static void _init_test()
 {
-       TBM_BUFMGR_DEINIT_CALLED = 0;
-       TBM_BO_GET_USER_DATA_NULL = 0;
-       PTHREAD_MUTEX_INIT_ERROR = 0;
-       CALLOC_ERROR = 0;
-       CALLOC_RETURN_BUFFER = 0;
-       FREE_CALLED = 0;
-       GETENV_ERROR = 0;
-       SSCANF_ERROR = 0;
-       FCNTL_ERROR = 0;
-       DUP_ERROR = 0;
+       stub_stdio_init();
+       stub_fcntl_init();
+       stub_pthread_init();
+       stub_unistd_init();
+       stub_tbm_init();
+       stub_stdlib_init();
 }
 
 /* UNIT TESTS */
@@ -70,9 +60,12 @@ TEST(tdm_helper_get_fd, work_flow_success_5)
 
        _init_test();
 
+       stub_getenv_name = env;
+       stub_getenv_return_value = "getenv";
+
        fd = tdm_helper_get_fd(env);
 
-       ASSERT_GE(fd, 0);
+       ASSERT_EQ(fd, 5);
 }
 
 TEST(tdm_helper_get_fd, work_flow_success_4)
@@ -83,7 +76,10 @@ TEST(tdm_helper_get_fd, work_flow_success_4)
 
        _init_test();
 
-       DUP_ERROR = 1;
+       stub_dub_error = 1;
+
+       stub_getenv_name = env;
+       stub_getenv_return_value = "getenv";
 
        fd = tdm_helper_get_fd(env);
 
@@ -100,6 +96,9 @@ TEST(tdm_helper_get_fd, work_flow_success_3)
 
        FCNTL_ERROR = 1;
 
+       stub_getenv_name = env;
+       stub_getenv_return_value = "getenv";
+
        fd = tdm_helper_get_fd(env);
 
        ASSERT_EQ(fd, expected_fd);
@@ -115,6 +114,9 @@ TEST(tdm_helper_get_fd, work_flow_success_2)
 
        SSCANF_ERROR = 1;
 
+       stub_getenv_name = env;
+       stub_getenv_return_value = "getenv";
+
        fd = tdm_helper_get_fd(env);
 
        ASSERT_EQ(fd, expected_fd);
index f7bcca2..b03e35e 100644 (file)
 #include "gtest/gtest.h"
 
 #include "tbm_stubs.h"
-#include "pthread_stubs.h"
-#include "stdlib_stubs.h"
-#include "tdm_list_stubs.h"
-#include "tdm_pp_stubs.h"
-
-#define pthread_mutex_lock ut_pthread_mutex_lock
-#define calloc ut_calloc
-#define free ut_free
-#define pthread_mutex_init ut_pthread_mutex_init
-#define pthread_mutex_unlock ut_pthread_mutex_unlock
-#define tdm_buffer_ref_backend ut_tdm_buffer_ref_backend
+#include "stub_pthread.h"
+#include "stub_stdlib.h"
+#include "stub_backend.h"
+#include "stub_tdm_buffer.h"
 
 #include "tdm_pp.c"
 
 static void _init_test()
 {
-       TBM_BUFMGR_DEINIT_CALLED = 0;
-       TBM_BO_GET_USER_DATA_NULL = 0;
-       PTHREAD_MUTEX_INIT_ERROR = 0;
-       CALLOC_ERROR = 0;
-       CALLOC_RETURN_BUFFER = 0;
-       FREE_CALLED = 0;
-       PP_SET_INFO_ERROR = 0;
-       PP_ATACH_ERROR = 0;
-       PP_COMMIT_ERROR = 0;
+       stub_pthread_init();
+       stub_backend_init();
+       stub_tbm_init();
+       stub_stdlib_init();
 }
 
 /* UNIT TESTS */
@@ -72,6 +60,8 @@ TEST(tdm_pp_commit, work_flow_success_3)
        pp.private_display = &private_display;
        private_display.func_pp.pp_commit = pp_commit;
 
+       LIST_INITHEAD(&pp.pending_buffer_list);
+
        error = tdm_pp_commit(&pp);
 
        ASSERT_EQ(error, expected_error);
@@ -90,6 +80,8 @@ TEST(tdm_pp_commit, work_flow_success_2)
        private_display.func_pp.pp_commit = pp_commit;
        PP_COMMIT_ERROR = 1;
 
+       LIST_INITHEAD(&pp.pending_buffer_list);
+
        error = tdm_pp_commit(&pp);
 
        ASSERT_NE(error, not_expected_error);
diff --git a/ut/src/ut_tdm_thread.cpp b/ut/src/ut_tdm_thread.cpp
new file mode 100644 (file)
index 0000000..e6b062b
--- /dev/null
@@ -0,0 +1,822 @@
+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+**************************************************************************/
+
+#include "gtest/gtest.h"
+
+#include "tbm_stubs.h"
+#include "stub_pthread.h"
+#include "stub_stdlib.h"
+#include "stub_unistd.h"
+#include "stub_tdm.h"
+#include "stub_tdm_display.h"
+#include "stub_tdm_pp.h"
+#include "stub_tdm_capture.h"
+#include "stub_tdm_vblank.h"
+
+#include "tdm_thread.c"
+
+static void _init_test()
+{
+       keep_private_thread = NULL;
+       tdm_mutex_locked = 0;
+
+       stub_pthread_init();
+       stub_stdlib_init();
+       stub_unistd_init();
+       stub_tdm_display_init();
+       stub_tdm_pp_init();
+}
+
+/* UNIT TESTS */
+
+/* tdm_thread_init */
+
+TEST(tdm_thread_init, error_mutex_is_not_locked)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_OPERATION_FAILED;
+       tdm_private_loop private_loop;
+       tdm_private_thread private_thread;
+
+       _init_test();
+
+       keep_private_thread = &private_thread;
+
+       error = tdm_thread_init(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_thread_init, error_dpy_is_null)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_OPERATION_FAILED;
+       tdm_private_loop private_loop;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+
+       tdm_mutex_locked = 1;
+
+       error = tdm_thread_init(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_thread_init, error_dpy_private_loop_is_null)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_OPERATION_FAILED;
+       tdm_private_loop private_loop;
+       tdm_private_display private_display;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       memset(&private_display, 0, sizeof(tdm_private_display));
+
+       tdm_mutex_locked = 1;
+       private_loop.dpy = &private_display;
+
+       error = tdm_thread_init(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_thread_init, success_private_thread_is_not_null)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_private_display private_display;
+       tdm_private_loop dpy_private_loop;
+       tdm_private_thread private_thread;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       memset(&dpy_private_loop, 0, sizeof(tdm_private_loop));
+       memset(&private_display, 0, sizeof(tdm_private_display));
+
+       tdm_mutex_locked = 1;
+       private_loop.dpy = &private_display;
+       private_display.private_loop = &dpy_private_loop;
+       private_loop.private_thread = &private_thread;
+
+       error = tdm_thread_init(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_thread_init, success_getenv_return_null)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_private_display private_display;
+       tdm_private_loop dpy_private_loop;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       memset(&dpy_private_loop, 0, sizeof(tdm_private_loop));
+       memset(&private_display, 0, sizeof(tdm_private_display));
+
+       tdm_mutex_locked = 1;
+       private_loop.dpy = &private_display;
+       private_display.private_loop = &dpy_private_loop;
+
+       stub_getenv_name = "TDM_THREAD";
+       stub_getenv_return_value = NULL;
+
+       error = tdm_thread_init(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_thread_init, success_getenv_return_0)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_private_display private_display;
+       tdm_private_loop dpy_private_loop;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       memset(&dpy_private_loop, 0, sizeof(tdm_private_loop));
+       memset(&private_display, 0, sizeof(tdm_private_display));
+
+       tdm_mutex_locked = 1;
+       private_loop.dpy = &private_display;
+       private_display.private_loop = &dpy_private_loop;
+
+       stub_getenv_name = "TDM_THREAD";
+       stub_getenv_return_value = "0";
+
+       error = tdm_thread_init(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_thread_init, error_calloc_return_null)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_OUT_OF_MEMORY;
+       tdm_private_loop private_loop;
+       tdm_private_display private_display;
+       tdm_private_loop dpy_private_loop;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       memset(&dpy_private_loop, 0, sizeof(tdm_private_loop));
+       memset(&private_display, 0, sizeof(tdm_private_display));
+
+       tdm_mutex_locked = 1;
+       private_loop.dpy = &private_display;
+       private_display.private_loop = &dpy_private_loop;
+
+       stub_getenv_name = "TDM_THREAD";
+       stub_getenv_return_value = "1";
+       CALLOC_ERROR = 1;
+
+       error = tdm_thread_init(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_thread_init, error_pipe_return_error)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_OPERATION_FAILED;
+       tdm_private_loop private_loop;
+       tdm_private_display private_display;
+       tdm_private_loop dpy_private_loop;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       memset(&dpy_private_loop, 0, sizeof(tdm_private_loop));
+       memset(&private_display, 0, sizeof(tdm_private_display));
+
+       tdm_mutex_locked = 1;
+       private_loop.dpy = &private_display;
+       private_display.private_loop = &dpy_private_loop;
+
+       stub_getenv_name = "TDM_THREAD";
+       stub_getenv_return_value = "1";
+
+       stub_pipe_error = 1;
+
+       error = tdm_thread_init(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_thread_init, success_init)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_private_display private_display;
+       tdm_private_loop dpy_private_loop;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       memset(&dpy_private_loop, 0, sizeof(tdm_private_loop));
+       memset(&private_display, 0, sizeof(tdm_private_display));
+
+       tdm_mutex_locked = 1;
+       private_loop.dpy = &private_display;
+       private_display.private_loop = &dpy_private_loop;
+
+       stub_getenv_name = "TDM_THREAD";
+       stub_getenv_return_value = "1";
+       stub_syscall_return_value = 10;
+
+       error = tdm_thread_init(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_TRUE(keep_private_thread != NULL);
+       ASSERT_TRUE(keep_private_thread->private_loop == &private_loop);
+       ASSERT_TRUE(private_loop.private_thread != NULL);
+       ASSERT_EQ(private_loop.private_thread->display_tid, stub_syscall_return_value);
+       free(private_loop.private_thread);
+}
+
+/* tdm_thread_deinit */
+
+TEST(tdm_thread_deinit, error_mutex_is_not_locked)
+{
+       tdm_private_loop private_loop;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+
+       private_loop.private_thread = calloc(1, sizeof(tdm_private_thread));
+
+       keep_private_thread = private_loop.private_thread;
+
+       tdm_thread_deinit(&private_loop);
+
+       ASSERT_TRUE(keep_private_thread != NULL);
+}
+
+TEST(tdm_thread_deinit, error_private_thread_is_null)
+{
+       tdm_private_loop private_loop;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+
+       keep_private_thread = calloc(1, sizeof(tdm_private_thread));
+
+       tdm_thread_deinit(&private_loop);
+
+       ASSERT_TRUE(keep_private_thread != NULL);
+}
+
+TEST(tdm_thread_deinit, success_deinit)
+{
+       tdm_private_loop private_loop;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+
+       tdm_mutex_locked = 1;
+
+       private_loop.private_thread = calloc(1, sizeof(tdm_private_thread));
+
+       private_loop.private_thread->pipe[0] = 1;
+       private_loop.private_thread->pipe[1] = 2;
+
+       keep_private_thread = private_loop.private_thread;
+
+       tdm_thread_deinit(&private_loop);
+
+       ASSERT_TRUE(keep_private_thread == NULL);
+       ASSERT_EQ(FREE_CALLED, 1);
+       ASSERT_EQ(stub_unistd_closed_fds[1], 1);
+       ASSERT_EQ(stub_unistd_closed_fds[2], 1);
+       ASSERT_TRUE(private_loop.private_thread == NULL);
+}
+
+/* tdm_thread_get_fd */
+
+TEST(tdm_thread_get_fd, error_mutex_is_not_locked)
+{
+       int ret;
+       int expected_ret = TDM_ERROR_OPERATION_FAILED;
+       tdm_private_loop private_loop;
+       tdm_private_thread private_thread;
+
+       _init_test();
+
+       keep_private_thread = &private_thread;
+
+       ret = tdm_thread_get_fd(&private_loop);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tdm_thread_get_fd, error_private_loop_is_null)
+{
+       int ret;
+       int expected_ret = -1;
+
+       _init_test();
+
+       tdm_mutex_locked = 1;
+
+       ret = tdm_thread_get_fd(NULL);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tdm_thread_get_fd, error_private_thread_is_null)
+{
+       int ret;
+       int expected_ret = -1;
+       tdm_private_loop private_loop;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+
+       ret = tdm_thread_get_fd(&private_loop);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tdm_thread_get_fd, success_get_fd)
+{
+       int ret;
+       int expected_ret;
+       tdm_private_loop private_loop;
+       tdm_private_thread private_thread;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       private_loop.private_thread = &private_thread;
+       private_thread.pipe[0] = 15;
+
+       expected_ret = private_thread.pipe[0];
+
+       ret = tdm_thread_get_fd(&private_loop);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+/* tdm_thread_send_cb */
+
+TEST(tdm_thread_send_cb, error_mutex_is_not_locked)
+{
+       tdm_error ret;
+       tdm_error expected_ret = TDM_ERROR_OPERATION_FAILED;
+       tdm_private_loop private_loop;
+       tdm_thread_cb_base base;
+       tdm_private_thread private_thread;
+
+       _init_test();
+
+       keep_private_thread = &private_thread;
+
+       ret = tdm_thread_send_cb(&private_loop, &base);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tdm_thread_send_cb, error_base_is_null)
+{
+       tdm_error ret;
+       tdm_error expected_ret = TDM_ERROR_INVALID_PARAMETER;
+       tdm_private_loop private_loop;
+
+       _init_test();
+
+       ret = tdm_thread_send_cb(&private_loop, NULL);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tdm_thread_send_cb, error_private_loop_is_null)
+{
+       tdm_error ret;
+       tdm_error expected_ret = TDM_ERROR_INVALID_PARAMETER;
+       tdm_thread_cb_base base;
+
+       _init_test();
+
+       ret = tdm_thread_send_cb(NULL, &base);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tdm_thread_send_cb, error_private_thread_is_null)
+{
+       tdm_error ret;
+       tdm_error expected_ret = TDM_ERROR_INVALID_PARAMETER;
+       tdm_private_loop private_loop;
+       tdm_thread_cb_base base;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+
+       ret = tdm_thread_send_cb(&private_loop, &base);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tdm_thread_send_cb, error_write_error)
+{
+       tdm_error ret;
+       tdm_error expected_ret = TDM_ERROR_OPERATION_FAILED;
+       tdm_private_loop private_loop;
+       tdm_thread_cb_base base;
+       tdm_private_thread private_thread;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       private_loop.private_thread = &private_thread;
+       base.length = 256;
+
+       stub_write_error = 1;
+
+       ret = tdm_thread_send_cb(&private_loop, &base);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tdm_thread_send_cb, success_send_cb)
+{
+       tdm_error ret;
+       tdm_error expected_ret = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_thread_cb_base base;
+       tdm_private_thread private_thread;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       private_loop.private_thread = &private_thread;
+       base.length = 256;
+
+       ret = tdm_thread_send_cb(&private_loop, &base);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+/* tdm_thread_handle_cb */
+
+TEST(tdm_thread_handle_cb, error_private_loop_is_null)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER;
+
+       error = tdm_thread_handle_cb(NULL);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_thread_handle_cb, error_private_thread_is_null)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_INVALID_PARAMETER;
+       tdm_private_loop private_loop;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+
+       error = tdm_thread_handle_cb(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_thread_handle_cb, success_read_0_bytes)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_private_thread private_thread;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       private_loop.private_thread = &private_thread;
+
+       error = tdm_thread_handle_cb(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_thread_handle_cb, error_partial_reading)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_OPERATION_FAILED;
+       tdm_private_loop private_loop;
+       tdm_private_thread private_thread;
+       tdm_thread_cb_base base;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       private_loop.private_thread = &private_thread;
+
+       stub_read_buf = (void *)&base;
+       base.length = sizeof(tdm_thread_cb_base);
+
+       stub_read_returned_size = sizeof(tdm_thread_cb_base) - 1;
+
+       error = tdm_thread_handle_cb(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+}
+
+TEST(tdm_thread_handle_cb, success_case_thread_cb_output_commit)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_private_thread private_thread;
+       tdm_thread_cb_output_commit cb_output_commit;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       private_loop.private_thread = &private_thread;
+
+       stub_read_buf = (void *)&cb_output_commit;
+       cb_output_commit.base.type = TDM_THREAD_CB_OUTPUT_COMMIT;
+       cb_output_commit.base.length = sizeof(tdm_thread_cb_output_commit);
+
+       stub_read_returned_size = sizeof(tdm_thread_cb_output_commit);
+
+       error = tdm_thread_handle_cb(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(stub_tdm_output_cb_commit_called, 1);
+}
+
+TEST(tdm_thread_handle_cb, success_case_thread_cb_output_vblank)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_private_thread private_thread;
+       tdm_thread_cb_output_vblank cb_output_vblank;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       private_loop.private_thread = &private_thread;
+
+       stub_read_buf = (void *)&cb_output_vblank;
+       cb_output_vblank.base.type = TDM_THREAD_CB_OUTPUT_VBLANK;
+       cb_output_vblank.base.length = sizeof(tdm_thread_cb_output_vblank);
+
+       stub_read_returned_size = sizeof(tdm_thread_cb_output_vblank);
+
+       error = tdm_thread_handle_cb(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(stub_tdm_output_cb_vblank_called, 1);
+}
+
+TEST(tdm_thread_handle_cb, success_case_thread_cb_output_status)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_private_thread private_thread;
+       tdm_thread_cb_output_status cb_output_status;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       private_loop.private_thread = &private_thread;
+
+       stub_read_buf = (void *)&cb_output_status;
+       cb_output_status.base.type = TDM_THREAD_CB_OUTPUT_STATUS;
+       cb_output_status.base.length = sizeof(tdm_thread_cb_output_status);
+
+       stub_read_returned_size = sizeof(tdm_thread_cb_output_status);
+
+       error = tdm_thread_handle_cb(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(stub_tdm_output_cb_status_called, 1);
+}
+
+TEST(tdm_thread_handle_cb, success_case_thread_cb_output_dpms)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_private_thread private_thread;
+       tdm_thread_cb_output_dpms cb_output_dpms;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       private_loop.private_thread = &private_thread;
+
+       stub_read_buf = (void *)&cb_output_dpms;
+       cb_output_dpms.base.type = TDM_THREAD_CB_OUTPUT_DPMS;
+       cb_output_dpms.base.length = sizeof(tdm_thread_cb_output_dpms);
+
+       stub_read_returned_size = sizeof(tdm_thread_cb_output_dpms);
+
+       error = tdm_thread_handle_cb(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(stub_tdm_output_cb_dpms_called, 1);
+}
+
+TEST(tdm_thread_handle_cb, success_case_thread_cb_pp_done)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_private_thread private_thread;
+       tdm_thread_cb_pp_done cb_pp_done;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       private_loop.private_thread = &private_thread;
+
+       stub_read_buf = (void *)&cb_pp_done;
+       cb_pp_done.base.type = TDM_THREAD_CB_PP_DONE;
+       cb_pp_done.base.length = sizeof(tdm_thread_cb_pp_done);
+
+       stub_read_returned_size = sizeof(tdm_thread_cb_pp_done);
+
+       error = tdm_thread_handle_cb(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(stub_tdm_pp_cb_done_called, 1);
+}
+
+TEST(tdm_thread_handle_cb, success_case_thread_cb_capture_done)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_private_thread private_thread;
+       tdm_thread_cb_capture_done cb_capture_done;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       private_loop.private_thread = &private_thread;
+
+       stub_read_buf = (void *)&cb_capture_done;
+       cb_capture_done.base.type = TDM_THREAD_CB_CAPTURE_DONE;
+       cb_capture_done.base.length = sizeof(tdm_thread_cb_capture_done);
+
+       stub_read_returned_size = sizeof(tdm_thread_cb_capture_done);
+
+       error = tdm_thread_handle_cb(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(stub_tdm_capture_cb_done_called, 1);
+}
+
+TEST(tdm_thread_handle_cb, success_case_thread_cb_vblank_sw)
+{
+       tdm_error error;
+       tdm_error expected_error = TDM_ERROR_NONE;
+       tdm_private_loop private_loop;
+       tdm_private_thread private_thread;
+       tdm_thread_cb_vblank_sw cb_vblank_sw;
+
+       _init_test();
+
+       memset(&private_loop, 0, sizeof(tdm_private_loop));
+       private_loop.private_thread = &private_thread;
+
+       stub_read_buf = (void *)&cb_vblank_sw;
+       cb_vblank_sw.base.type = TDM_THREAD_CB_VBLANK_SW;
+       cb_vblank_sw.base.length = sizeof(tdm_thread_cb_vblank_sw);
+
+       stub_read_returned_size = sizeof(tdm_thread_cb_vblank_sw);
+
+       error = tdm_thread_handle_cb(&private_loop);
+
+       ASSERT_EQ(error, expected_error);
+       ASSERT_EQ(stub_tdm_vblank_cb_vblank_SW_called, 1);
+}
+
+/* tdm_thread_in_display_thread */
+
+TEST(tdm_thread_in_display_thread, success_keep_private_thread_is_null)
+{
+       int ret;
+       int expected_ret = 1;
+       pid_t tid;
+
+       _init_test();
+
+       ret = tdm_thread_in_display_thread(tid);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tdm_thread_in_display_thread, success_in_display_thread)
+{
+       int ret;
+       int expected_ret = 1;
+       pid_t tid = 20;
+       static tdm_private_thread private_thread;
+
+       _init_test();
+
+       private_thread.display_tid = tid;
+       keep_private_thread = &private_thread;
+
+       ret = tdm_thread_in_display_thread(tid);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tdm_thread_in_display_thread, success_no_in_display_thread)
+{
+       int ret;
+       int expected_ret = 0;
+       pid_t tid = 20;
+       static tdm_private_thread private_thread;
+
+       _init_test();
+
+       private_thread.display_tid = tid + 1;
+       keep_private_thread = &private_thread;
+
+       ret = tdm_thread_in_display_thread(tid);
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+/* tdm_thread_is_running */
+
+TEST(tdm_thread_is_running, success_no_is_running)
+{
+       int ret;
+       int expected_ret = 0;
+
+       _init_test();
+
+       ret = tdm_thread_is_running();
+
+       ASSERT_EQ(ret, expected_ret);
+}
+
+TEST(tdm_thread_is_running, success_is_running)
+{
+       int ret;
+       int expected_ret = 1;
+       static tdm_private_thread private_thread;
+
+       _init_test();
+
+       keep_private_thread = &private_thread;
+
+       ret = tdm_thread_is_running();
+
+       ASSERT_EQ(ret, expected_ret);
+}
diff --git a/ut/stubs/pthread_stubs.cpp b/ut/stubs/pthread_stubs.cpp
deleted file mode 100644 (file)
index cdcb943..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#include <pthread.h>
-
-int PTHREAD_MUTEX_INIT_ERROR;
-
-int ut_pthread_mutex_lock(pthread_mutex_t * __mutex)
-{
-       (void)__mutex;
-
-       return 0;
-}
-
-int ut_pthread_mutex_unlock(pthread_mutex_t * __mutex)
-{
-       (void)__mutex;
-
-       return 0;
-}
-
-int ut_pthread_mutex_init(pthread_mutex_t * __mutex,
-                                                                const pthread_mutexattr_t * __mutexattr)
-{
-       (void)__mutex;
-       (void)__mutexattr;
-
-       if (PTHREAD_MUTEX_INIT_ERROR) {
-               return PTHREAD_MUTEX_INIT_ERROR;
-       }
-
-       return 0;
-}
diff --git a/ut/stubs/pthread_stubs.h b/ut/stubs/pthread_stubs.h
deleted file mode 100644 (file)
index a2ddcb9..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef _PTHREAD_STUBS_H
-#define _PTHREAD_STUBS_H
-
-#include <pthread.h>
-#include <stdio.h>
-
-extern int PTHREAD_MUTEX_INIT_ERROR;
-
-int ut_pthread_mutex_lock(pthread_mutex_t * __mutex);
-
-int ut_pthread_mutex_unlock(pthread_mutex_t * __mutex);
-
-int ut_pthread_mutex_init(pthread_mutex_t * __mutex,
-                                                                const pthread_mutexattr_t * __mutexattr);
-
-#endif /* _PTHREAD_STUBS_H */
diff --git a/ut/stubs/stdlib_stubs.cpp b/ut/stubs/stdlib_stubs.cpp
deleted file mode 100644 (file)
index f20e856..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "stdlib_stubs.h"
-
-int CALLOC_ERROR;
-int CALLOC_RETURN_BUFFER;
-int FREE_CALLED;
-
-tdm_buffer_info buffer;
-
-void *ut_calloc(size_t nmemb, size_t size)
-{
-       if (CALLOC_ERROR) {
-               return NULL;
-       }
-
-       if (CALLOC_RETURN_BUFFER) {
-               return &buffer;
-       }
-
-       return calloc(nmemb, size);
-}
-
-void ut_free(void *ptr)
-{
-       FREE_CALLED = 1;
-       free(ptr);
-}
diff --git a/ut/stubs/stdlib_stubs.h b/ut/stubs/stdlib_stubs.h
deleted file mode 100644 (file)
index db59093..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef _STDLIB_STUBS_H
-#define _STDLIB_STUBS_H
-
-#include <stdlib.h>
-#include "tdm_list_stubs.h"
-#include "tdm.h"
-#include "tdm_private.h"
-
-extern int CALLOC_ERROR;
-extern int CALLOC_RETURN_BUFFER;
-extern int FREE_CALLED;
-
-extern tdm_buffer_info buffer;
-
-void *ut_calloc(size_t nmemb, size_t size);
-
-void ut_free(void *ptr);
-
-#endif /* _STDLIB_STUBS_H */
diff --git a/ut/stubs/stub_backend.cpp b/ut/stubs/stub_backend.cpp
new file mode 100644 (file)
index 0000000..3f3a200
--- /dev/null
@@ -0,0 +1,344 @@
+#include "stub_backend.h"
+#include <stdlib.h>
+
+int OUTPUT_CREATE_CAPTURE_ERROR;
+int CAPTURE_SET_DONE_HANDLER_ERROR;
+int LAYER_CREATE_CAPTURE_ERROR;
+int CAPTURE_SET_INFO_ERROR;
+int CAPTURE_ATTACH_ERROR;
+int CAPTURE_COMMIT_ERROR;
+int OUTPUT_SET_PROPERTY_ERROR;
+int OUTPUT_GET_PROPERTY_ERROR;
+int OUTPUT_WAIT_VBLANK_ERROR;
+int OUTPUT_SET_VBLANK_HANDLER;
+int OUTPUT_COMMIT_ERROR;
+int OUTPUT_SET_COMMIT_HANDLER;
+int OUTPUT_SET_MODE_ERROR;
+int OUTPUT_SET_DPMS_ERROR;
+int OUTPUT_GET_DPMS_ERROR;
+int LAYER_SET_PROPERTY_ERROR;
+int LAYER_GET_PROPERTY_ERROR;
+int LAYER_SET_INFO_ERROR;
+int LAYER_SET_BUFFER_ERROR;
+int LAYER_UNSET_BUFFER_ERROR;
+int LAYER_SET_VIDEO_POS_ERROR;
+int PP_SET_INFO_ERROR;
+int PP_COMMIT_ERROR;
+
+void stub_backend_init()
+{
+       OUTPUT_CREATE_CAPTURE_ERROR = 0;
+       CAPTURE_SET_DONE_HANDLER_ERROR = 0;
+       LAYER_CREATE_CAPTURE_ERROR = 0;
+       CAPTURE_SET_INFO_ERROR = 0;
+       CAPTURE_ATTACH_ERROR = 0;
+       CAPTURE_COMMIT_ERROR = 0;
+       OUTPUT_SET_PROPERTY_ERROR = 0;
+       OUTPUT_GET_PROPERTY_ERROR = 0;
+       OUTPUT_WAIT_VBLANK_ERROR = 0;
+       OUTPUT_SET_VBLANK_HANDLER = 0;
+       OUTPUT_COMMIT_ERROR = 0;
+       OUTPUT_SET_COMMIT_HANDLER = 0;
+       OUTPUT_SET_MODE_ERROR = 0;
+       OUTPUT_SET_DPMS_ERROR = 0;
+       OUTPUT_GET_DPMS_ERROR = 0;
+       LAYER_SET_PROPERTY_ERROR = 0;
+       LAYER_GET_PROPERTY_ERROR = 0;
+       LAYER_SET_INFO_ERROR = 0;
+       LAYER_SET_BUFFER_ERROR = 0;
+       LAYER_UNSET_BUFFER_ERROR = 0;
+       LAYER_SET_VIDEO_POS_ERROR = 0;
+       PP_SET_INFO_ERROR = 0;
+       PP_COMMIT_ERROR = 0;
+}
+
+tdm_capture *output_create_capture(tdm_output *output, tdm_error *error)
+{
+       (void)output;
+       (void)error;
+
+       if (OUTPUT_CREATE_CAPTURE_ERROR) {
+               *error = TDM_ERROR_OPERATION_FAILED;
+               return NULL;
+       }
+
+       *error = TDM_ERROR_NONE;
+
+       return NULL;
+}
+
+void capture_destroy(tdm_capture *capture)
+{
+       (void)capture;
+}
+
+tdm_error capture_set_done_handler(tdm_capture *capture,
+                                               tdm_capture_done_handler func, void *user_data)
+{
+       (void)capture;
+       (void)func;
+       (void)user_data;
+
+       if (CAPTURE_SET_DONE_HANDLER_ERROR) {
+               if (user_data) {
+                       free(user_data);
+               }
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_capture *layer_create_capture(tdm_layer *layer, tdm_error *error)
+{
+       (void)layer;
+       (void)error;
+
+       if (LAYER_CREATE_CAPTURE_ERROR) {
+               *error = TDM_ERROR_OPERATION_FAILED;
+               return NULL;
+       }
+
+       *error = TDM_ERROR_NONE;
+       return NULL;
+}
+
+tdm_error capture_set_info(tdm_capture *capture, tdm_info_capture *info)
+{
+       (void)capture;
+       (void)info;
+
+       if (CAPTURE_SET_INFO_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error capture_commit(tdm_capture *capture)
+{
+       (void)capture;
+
+       if (CAPTURE_COMMIT_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error output_set_property(tdm_output *output, unsigned int id,
+                                                                        tdm_value value)
+{
+       (void)output;
+       (void)id;
+       (void)value;
+
+       if (OUTPUT_SET_PROPERTY_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error output_get_property(tdm_output *output, unsigned int id,
+                                                                        tdm_value *value)
+{
+       (void)output;
+       (void)id;
+       (void)value;
+
+       if (OUTPUT_GET_PROPERTY_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error output_wait_vblank(tdm_output *output, int interval, int sync,
+                                                                       void *user_data)
+{
+       (void)output;
+       (void)interval;
+       (void)sync;
+       (void)user_data;
+
+       free(user_data);
+       if (OUTPUT_WAIT_VBLANK_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error output_set_vblank_handler(tdm_output *output,
+                                                                                  tdm_output_vblank_handler func)
+{
+       (void)output;
+       (void)func;
+
+       if (OUTPUT_SET_VBLANK_HANDLER) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error output_commit(tdm_output *output, int sync, void *user_data)
+{
+       (void)output;
+       (void)sync;
+
+       free(user_data);
+       if (OUTPUT_COMMIT_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error output_set_commit_handler(tdm_output *output,
+                                                                       tdm_output_commit_handler func)
+{
+       (void)output;
+       (void)func;
+
+       if (OUTPUT_SET_COMMIT_HANDLER) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error output_set_mode(tdm_output *output, const tdm_output_mode *mode)
+{
+       (void)output;
+       (void)mode;
+
+       if (OUTPUT_SET_MODE_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
+{
+       (void)output;
+       (void)dpms_value;
+
+       if (OUTPUT_SET_DPMS_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
+{
+       (void)output;
+       (void)dpms_value;
+
+       if (OUTPUT_GET_DPMS_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error layer_set_property(tdm_layer *layer, unsigned int id,
+                                                               tdm_value value)
+{
+       (void)layer;
+       (void)id;
+       (void)value;
+
+       if (LAYER_SET_PROPERTY_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error layer_get_property(tdm_layer *layer, unsigned int id,
+                                                               tdm_value *value)
+{
+       (void)layer;
+       (void)id;
+       (void)value;
+
+       if (LAYER_GET_PROPERTY_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error layer_set_info(tdm_layer *layer, tdm_info_layer *info)
+{
+       (void)layer;
+       (void)info;
+
+       if (LAYER_SET_INFO_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer)
+{
+       (void)layer;
+       (void)buffer;
+
+       if (LAYER_SET_BUFFER_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error layer_unset_buffer(tdm_layer *layer)
+{
+       (void)layer;
+
+       if (LAYER_UNSET_BUFFER_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error layer_set_video_pos(tdm_layer *layer, int zpos)
+{
+       (void)layer;
+       (void)zpos;
+
+       if (LAYER_SET_VIDEO_POS_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error pp_set_info(tdm_pp *pp, tdm_info_pp *info)
+{
+       (void)pp;
+       (void)info;
+
+       if (PP_SET_INFO_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+tdm_error pp_commit(tdm_pp *pp)
+{
+       (void)pp;
+
+       if (PP_COMMIT_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
diff --git a/ut/stubs/stub_backend.h b/ut/stubs/stub_backend.h
new file mode 100644 (file)
index 0000000..355e275
--- /dev/null
@@ -0,0 +1,86 @@
+#ifndef _TDM_BACKEND_STUBS_H
+#define _TDM_BACKEND_STUBS_H
+
+#include "tdm_types.h"
+
+extern int OUTPUT_CREATE_CAPTURE_ERROR;
+extern int CAPTURE_SET_DONE_HANDLER_ERROR;
+extern int LAYER_CREATE_CAPTURE_ERROR;
+extern int CAPTURE_SET_INFO_ERROR;
+extern int CAPTURE_ATTACH_ERROR;
+extern int CAPTURE_COMMIT_ERROR;
+extern int OUTPUT_SET_PROPERTY_ERROR;
+extern int OUTPUT_GET_PROPERTY_ERROR;
+extern int OUTPUT_WAIT_VBLANK_ERROR;
+extern int OUTPUT_SET_VBLANK_HANDLER;
+extern int OUTPUT_COMMIT_ERROR;
+extern int OUTPUT_SET_COMMIT_HANDLER;
+extern int OUTPUT_SET_MODE_ERROR;
+extern int OUTPUT_SET_DPMS_ERROR;
+extern int OUTPUT_GET_DPMS_ERROR;
+extern int LAYER_SET_PROPERTY_ERROR;
+extern int LAYER_GET_PROPERTY_ERROR;
+extern int LAYER_SET_INFO_ERROR;
+extern int LAYER_SET_BUFFER_ERROR;
+extern int LAYER_UNSET_BUFFER_ERROR;
+extern int LAYER_SET_VIDEO_POS_ERROR;
+extern int PP_SET_INFO_ERROR;
+extern int PP_COMMIT_ERROR;
+
+void stub_backend_init();
+
+tdm_capture *output_create_capture(tdm_output *output, tdm_error *error);
+
+void capture_destroy(tdm_capture *capture);
+
+tdm_error capture_set_done_handler(tdm_capture *capture,
+                                               tdm_capture_done_handler func, void *user_data);
+
+tdm_capture *layer_create_capture(tdm_layer *layer, tdm_error *error);
+
+tdm_error capture_set_info(tdm_capture *capture, tdm_info_capture *info);
+tdm_error capture_commit(tdm_capture *capture);
+
+tdm_error output_set_property(tdm_output *output, unsigned int id,
+                                                                        tdm_value value);
+
+tdm_error output_get_property(tdm_output *output, unsigned int id,
+                                                                        tdm_value *value);
+
+tdm_error output_wait_vblank(tdm_output *output, int interval, int sync,
+                                                                       void *user_data);
+
+tdm_error output_set_vblank_handler(tdm_output *output,
+                                                                                  tdm_output_vblank_handler func);
+
+tdm_error output_commit(tdm_output *output, int sync, void *user_data);
+
+tdm_error output_set_commit_handler(tdm_output *output,
+                                                                       tdm_output_commit_handler func);
+
+tdm_error output_set_mode(tdm_output *output, const tdm_output_mode *mode);
+
+tdm_error output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value);
+
+tdm_error output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value);
+
+tdm_error layer_set_property(tdm_layer *layer, unsigned int id,
+                                                        tdm_value value);
+
+tdm_error layer_get_property(tdm_layer *layer, unsigned int id,
+                                                               tdm_value *value);
+
+tdm_error layer_set_info(tdm_layer *layer, tdm_info_layer *info);
+
+tdm_error layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer);
+
+tdm_error layer_unset_buffer(tdm_layer *layer);
+
+tdm_error layer_set_video_pos(tdm_layer *layer, int zpos);
+
+tdm_error pp_set_info(tdm_pp *pp, tdm_info_pp *info);
+
+tdm_error pp_commit(tdm_pp *pp);
+
+
+#endif /* _TDM_CAPTURE_STUBS_H */
diff --git a/ut/stubs/stub_fcntl.h b/ut/stubs/stub_fcntl.h
new file mode 100644 (file)
index 0000000..dd1124e
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef STUB_FCNTL_H
+#define STUB_FCNTL_H
+
+static int FCNTL_ERROR;
+
+static stub_fcntl_init()
+{
+       FCNTL_ERROR = 0;
+}
+
+static int stub_fcntl(int fd, int cmd, ...)
+{
+       (void)fd;
+       (void)cmd;
+
+       if (FCNTL_ERROR) {
+               FCNTL_ERROR = 0;
+               return -1;
+       }
+
+       return 0;
+}
+
+#define fcntl stub_fcntl
+
+#endif // STUB_FCNTL_H
diff --git a/ut/stubs/stub_pthread.cpp b/ut/stubs/stub_pthread.cpp
new file mode 100644 (file)
index 0000000..becaf96
--- /dev/null
@@ -0,0 +1,61 @@
+#include <pthread.h>
+
+int PTHREAD_MUTEX_INIT_ERROR;
+
+void stub_pthread_init()
+{
+       PTHREAD_MUTEX_INIT_ERROR = 0;
+}
+
+int stub_pthread_mutex_lock(pthread_mutex_t * __mutex)
+{
+       (void)__mutex;
+
+       return 0;
+}
+
+int stub_pthread_mutex_unlock(pthread_mutex_t * __mutex)
+{
+       (void)__mutex;
+
+       return 0;
+}
+
+int stub_pthread_mutex_init(pthread_mutex_t * __mutex,
+                                                                const pthread_mutexattr_t * __mutexattr)
+{
+       (void)__mutex;
+       (void)__mutexattr;
+
+       if (PTHREAD_MUTEX_INIT_ERROR) {
+               return PTHREAD_MUTEX_INIT_ERROR;
+       }
+
+       return 0;
+}
+
+int stub_pthread_create(pthread_t *newthread, const pthread_attr_t *attr,
+                                  void *(*start_routine) (void *), void *arg)
+{
+       (void)newthread;
+       (void)attr;
+       (void)start_routine;
+       (void)arg;
+
+       return 0;
+}
+
+int stub_pthread_join(pthread_t th, void **thread_return)
+{
+       (void)th;
+       (void)thread_return;
+
+       return 0;
+}
+
+int stub_pthread_cancel(pthread_t th)
+{
+       (void)th;
+
+       return 0;
+}
diff --git a/ut/stubs/stub_pthread.h b/ut/stubs/stub_pthread.h
new file mode 100644 (file)
index 0000000..c5a9351
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef _PTHREAD_STUBS_H
+#define _PTHREAD_STUBS_H
+
+#include <pthread.h>
+#include <stdio.h>
+
+extern int PTHREAD_MUTEX_INIT_ERROR;
+
+void stub_pthread_init();
+
+int stub_pthread_mutex_lock(pthread_mutex_t * __mutex);
+
+int stub_pthread_mutex_unlock(pthread_mutex_t * __mutex);
+
+int stub_pthread_mutex_init(pthread_mutex_t * __mutex,
+                                                                const pthread_mutexattr_t * __mutexattr);
+
+int stub_pthread_create(pthread_t *newthread, const pthread_attr_t *attr,
+                                         void *(*start_routine)(void *), void *arg);
+
+int stub_pthread_join(pthread_t th, void **thread_return);
+
+int stub_pthread_cancel (pthread_t th);
+
+#define pthread_mutex_lock stub_pthread_mutex_lock
+#define pthread_mutex_init stub_pthread_mutex_init
+#define pthread_mutex_unlock stub_pthread_mutex_unlock
+#define pthread_create stub_pthread_create
+#define pthread_join stub_pthread_join
+#define pthread_cancel stub_pthread_cancel
+
+#endif /* _PTHREAD_STUBS_H */
diff --git a/ut/stubs/stub_stdio.h b/ut/stubs/stub_stdio.h
new file mode 100644 (file)
index 0000000..2bab4e8
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef STUB_STDIO_H
+#define STUB_STDIO_H
+
+static int SSCANF_ERROR;
+
+static stub_stdio_init()
+{
+       SSCANF_ERROR = 0;
+}
+
+static int stub_sscanf(const char *buf, const char *format, ...)
+{
+       (void)buf;
+       (void)format;
+
+       if (SSCANF_ERROR) {
+               return -1;
+       }
+
+       return 0;
+}
+
+#define sscanf stub_sscanf
+
+#endif // STUB_STDIO_H
diff --git a/ut/stubs/stub_stdlib.cpp b/ut/stubs/stub_stdlib.cpp
new file mode 100644 (file)
index 0000000..7f5c897
--- /dev/null
@@ -0,0 +1,59 @@
+#define STUB_STDLIB_IMPL
+
+#include "stub_stdlib.h"
+
+int CALLOC_ERROR;
+int CALLOC_RETURN_BUFFER;
+int FREE_CALLED;
+int GETENV_ERROR;
+
+char *stub_getenv_return_value;
+char *stub_getenv_name;
+
+tdm_buffer_info buffer;
+
+void *stub_calloc(size_t nmemb, size_t size)
+{
+       if (CALLOC_ERROR) {
+               return NULL;
+       }
+
+       if (CALLOC_RETURN_BUFFER) {
+               return &buffer;
+       }
+
+       return calloc(nmemb, size);
+}
+
+void stub_free(void *ptr)
+{
+       FREE_CALLED = 1;
+       free(ptr);
+}
+
+char *stub_getenv(const char *name)
+{
+       if (GETENV_ERROR) {
+               return NULL;
+       }
+
+       if(!stub_getenv_name || !name) {
+               return NULL;
+       }
+
+       if (!strcmp(stub_getenv_name, name)) {
+               return stub_getenv_return_value;
+       }
+
+       return NULL;
+}
+
+void stub_stdlib_init()
+{
+       CALLOC_ERROR = 0;
+       CALLOC_RETURN_BUFFER = 0;
+       FREE_CALLED = 0;
+       GETENV_ERROR = 0;
+       stub_getenv_return_value = NULL;
+       stub_getenv_name = NULL;
+}
diff --git a/ut/stubs/stub_stdlib.h b/ut/stubs/stub_stdlib.h
new file mode 100644 (file)
index 0000000..ac6f23c
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef _STDLIB_STUBS_H
+#define _STDLIB_STUBS_H
+
+#include <stdlib.h>
+#include "tdm.h"
+#include "tdm_private.h"
+
+extern int CALLOC_ERROR;
+extern int CALLOC_RETURN_BUFFER;
+extern int FREE_CALLED;
+extern int GETENV_ERROR;
+
+extern tdm_buffer_info buffer;
+extern char *stub_getenv_return_value;
+extern char *stub_getenv_name;
+
+void *stub_calloc(size_t nmemb, size_t size);
+
+void stub_free(void *ptr);
+
+char *stub_getenv(const char *name);
+
+void stub_stdlib_init();
+
+#ifndef STUB_STDLIB_IMPL
+#define calloc stub_calloc
+#define free stub_free
+#define getenv stub_getenv
+#endif
+
+#endif /* _STDLIB_STUBS_H */
diff --git a/ut/stubs/stub_tdm.h b/ut/stubs/stub_tdm.h
new file mode 100644 (file)
index 0000000..7530855
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef STUB_TDM_H
+#define STUB_TDM_H
+
+#include <tdm_private.h>
+
+tdm_private_output stub_private_output;
+
+tdm_private_output*
+stub_tdm_display_find_output_stamp(tdm_private_display *private_display, double stamp)
+{
+       (void)private_display;
+       (void)stamp;
+
+       return &stub_private_output;
+}
+
+#define tdm_display_find_output_stamp stub_tdm_display_find_output_stamp
+
+#endif // STUB_TDM_H
diff --git a/ut/stubs/stub_tdm_buffer.h b/ut/stubs/stub_tdm_buffer.h
new file mode 100644 (file)
index 0000000..f7135fc
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef STUB_TDM_BUFFER_H
+#define STUB_TDM_BUFFER_H
+
+static tbm_surface_h ut_tdm_buffer_ref_backend(tbm_surface_h buffer)
+{
+       (void)buffer;
+
+       return NULL;
+}
+
+#define tdm_buffer_ref_backend ut_tdm_buffer_ref_backend
+
+#endif // STUB_TDM_BUFFER_H
diff --git a/ut/stubs/stub_tdm_capture.h b/ut/stubs/stub_tdm_capture.h
new file mode 100644 (file)
index 0000000..f7bf741
--- /dev/null
@@ -0,0 +1,76 @@
+#ifndef STUB_TDM_CAPTURE_H
+#define STUB_TDM_CAPTURE_H
+
+#include "tdm.h"
+#include "tdm_private.h"
+
+static tdm_private_capture private_capture;
+static int TDM_CAPTURE_CREATE_OUTPUT_INTENAL_ERROR;
+static int CAPTURE_CREATE_LAYER_INTERNAL_ERROR;
+static int stub_tdm_capture_cb_done_called;
+
+static void stub_tdm_capture_init()
+{
+       stub_tdm_capture_cb_done_called = 0;
+       TDM_CAPTURE_CREATE_OUTPUT_INTENAL_ERROR = 0;
+       CAPTURE_CREATE_LAYER_INTERNAL_ERROR = 0;
+}
+
+static void
+stub_tdm_capture_cb_done(tdm_capture *capture_backend, tbm_surface_h buffer,
+                                       void *user_data)
+{
+       (void)capture_backend;
+       (void)buffer;
+       (void)user_data;
+
+       stub_tdm_capture_cb_done_called = 1;
+}
+
+static tdm_private_capture *
+stub_tdm_capture_find_stamp(tdm_private_display *private_display, double stamp)
+{
+       (void)private_display;
+       (void)stamp;
+
+       return &private_capture;
+}
+
+static tdm_private_capture *
+stub_tdm_capture_create_output_internal(tdm_private_output*private_output,
+                                                                          tdm_error *error)
+{
+       (void)private_output;
+       (void)error;
+
+       if (TDM_CAPTURE_CREATE_OUTPUT_INTENAL_ERROR) {
+               *error = TDM_ERROR_OPERATION_FAILED;
+               return NULL;
+       }
+
+       *error = TDM_ERROR_NONE;
+       return NULL;
+}
+
+static tdm_private_capture *
+stub_tdm_capture_create_layer_internal(tdm_private_layer *private_layer,
+                                                                 tdm_error *error)
+{
+       (void)private_layer;
+       (void)error;
+
+       if (CAPTURE_CREATE_LAYER_INTERNAL_ERROR) {
+               *error = TDM_ERROR_OPERATION_FAILED;
+               return NULL;
+       }
+
+       *error = TDM_ERROR_NONE;
+       return NULL;
+}
+
+#define tdm_capture_cb_done stub_tdm_capture_cb_done
+#define tdm_capture_find_stamp stub_tdm_capture_find_stamp
+#define tdm_capture_create_output_internal stub_tdm_capture_create_output_internal
+#define tdm_capture_create_layer_internal stub_tdm_capture_create_layer_internal
+
+#endif // STUB_TDM_CAPTURE_H
diff --git a/ut/stubs/stub_tdm_display.h b/ut/stubs/stub_tdm_display.h
new file mode 100644 (file)
index 0000000..a73dc90
--- /dev/null
@@ -0,0 +1,71 @@
+#ifndef STUB_TDM_DISPLAY_H
+#define STUB_TDM_DISPLAY_H
+
+#include "tdm.h"
+
+static int stub_tdm_output_cb_commit_called;
+static int stub_tdm_output_cb_vblank_called;
+static int stub_tdm_output_cb_status_called;
+static int  stub_tdm_output_cb_dpms_called;
+
+static void
+stub_tdm_display_init()
+{
+       stub_tdm_output_cb_commit_called = 0;
+       stub_tdm_output_cb_vblank_called = 0;
+       stub_tdm_output_cb_dpms_called = 0;
+}
+
+static void
+stub_tdm_output_cb_commit(tdm_output *output_backend, unsigned int sequence,
+                                        unsigned int tv_sec, unsigned int tv_usec, void *user_data)
+{
+       (void)output_backend;
+       (void)sequence;
+       (void)tv_sec;
+       (void)tv_usec;
+       (void)user_data;
+
+       stub_tdm_output_cb_commit_called = 1;
+}
+
+static void
+stub_tdm_output_cb_vblank(tdm_output *output_backend, unsigned int sequence,
+                                        unsigned int tv_sec, unsigned int tv_usec, void *user_data)
+{
+       (void)output_backend;
+       (void)sequence;
+       (void)tv_sec;
+       (void)tv_usec;
+       (void)user_data;
+
+       stub_tdm_output_cb_vblank_called = 1;
+}
+
+static void
+stub_tdm_output_cb_status(tdm_output *output_backend, tdm_output_conn_status status,
+                                        void *user_data)
+{
+       (void)output_backend;
+       (void)status;
+       (void)user_data;
+
+       stub_tdm_output_cb_status_called = 1;
+}
+
+static void
+stub_tdm_output_cb_dpms(tdm_output *output_backend, tdm_output_dpms dpms, void *user_data)
+{
+       (void)output_backend;
+       (void)dpms;
+       (void)user_data;
+
+       stub_tdm_output_cb_dpms_called = 1;
+}
+
+#define tdm_output_cb_commit stub_tdm_output_cb_commit
+#define tdm_output_cb_vblank stub_tdm_output_cb_vblank
+#define tdm_output_cb_status stub_tdm_output_cb_status
+#define tdm_output_cb_dpms stub_tdm_output_cb_dpms
+
+#endif // STUB_TDM_DISPLAY_H
diff --git a/ut/stubs/stub_tdm_event_loop.h b/ut/stubs/stub_tdm_event_loop.h
new file mode 100644 (file)
index 0000000..9d12527
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef STUB_TDM_EVENT_LOOP_H
+#define STUB_TDM_EVENT_LOOP_H
+
+static int TDM_EVENT_LOOP_DISPATCH_ERROR;
+
+static void stub_tdm_event_loop_init()
+{
+       TDM_EVENT_LOOP_DISPATCH_ERROR = 0;
+}
+
+static int stub_tdm_event_loop_get_fd(tdm_private_display *private_display)
+{
+       (void)private_display;
+
+       return 1;
+}
+
+static tdm_error stub_tdm_event_loop_dispatch(tdm_private_display *private_display)
+{
+       (void)private_display;
+
+       if (TDM_EVENT_LOOP_DISPATCH_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+#define tdm_event_loop_get_fd stub_tdm_event_loop_get_fd
+#define tdm_event_loop_dispatch stub_tdm_event_loop_dispatch
+
+#endif // STUB_TDM_EVENT_LOOP_H
diff --git a/ut/stubs/stub_tdm_pp.h b/ut/stubs/stub_tdm_pp.h
new file mode 100644 (file)
index 0000000..ae43a4c
--- /dev/null
@@ -0,0 +1,62 @@
+#ifndef STUB_TDM_PP_H
+#define STUB_TDM_PP_H
+
+#include "tdm.h"
+#include "tdm_private.h"
+
+static tdm_private_pp private_pp;
+
+static int TDM_PP_CREATE_INTERNAL_ERROR;
+static int stub_tdm_pp_cb_done_called;
+
+static void stub_tdm_pp_init()
+{
+       stub_tdm_pp_cb_done_called = 0;
+       TDM_PP_CREATE_INTERNAL_ERROR = 0;
+}
+
+static void
+stub_tdm_pp_cb_done(tdm_pp *pp_backend, tbm_surface_h src, tbm_surface_h dst,
+                          void *user_data)
+{
+       (void)pp_backend;
+       (void)src;
+       (void)dst;
+       (void)user_data;
+
+       stub_tdm_pp_cb_done_called = 1;
+}
+
+static tdm_private_pp *
+stub_tdm_pp_find_stamp(tdm_private_display *private_display, double stamp)
+{
+       (void)private_display;
+       (void)stamp;
+
+       return &private_pp;
+}
+
+static tdm_private_pp *
+stub_tdm_pp_create_internal(tdm_private_display *private_display,
+                                                  tdm_error *error)
+{
+       (void)private_display;
+
+       if (TDM_PP_CREATE_INTERNAL_ERROR) {
+               if (error) {
+                       *error = TDM_ERROR_OPERATION_FAILED;
+               }
+               return NULL;
+       }
+
+       if (error) {
+               *error = TDM_ERROR_NONE;
+       }
+       return NULL;
+}
+
+#define tdm_pp_cb_done stub_tdm_pp_cb_done
+#define tdm_pp_find_stamp stub_tdm_pp_find_stamp
+#define tdm_pp_create_internal stub_tdm_pp_create_internal
+
+#endif // STUB_TDM_PP_H
diff --git a/ut/stubs/stub_tdm_thread.h b/ut/stubs/stub_tdm_thread.h
new file mode 100644 (file)
index 0000000..38af02b
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef STUB_TDM_THREAD_H
+#define STUB_TDM_THREAD_H
+
+static int TDM_THREAD_HANDLE_ERROR;
+
+void stub_tdm_thread_init()
+{
+       TDM_THREAD_HANDLE_ERROR = 0;
+}
+
+static int stub_tdm_thread_get_fd(tdm_private_loop *private_loop)
+{
+       (void)private_loop;
+
+       return 1;
+}
+
+static tdm_error stub_tdm_thread_handle_cb(tdm_private_loop *private_loop)
+{
+       (void)private_loop;
+
+       if (TDM_THREAD_HANDLE_ERROR) {
+               return TDM_ERROR_OPERATION_FAILED;
+       }
+
+       return TDM_ERROR_NONE;
+}
+
+#define tdm_thread_get_fd stub_tdm_thread_get_fd
+#define tdm_thread_handle_cb stub_tdm_thread_handle_cb
+
+#endif // STUB_TDM_THREAD_H
diff --git a/ut/stubs/stub_tdm_vblank.h b/ut/stubs/stub_tdm_vblank.h
new file mode 100644 (file)
index 0000000..38627cb
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef STUB_TDM_VBLANK_H
+#define STUB_TDM_VBLANK_H
+
+#include "tdm.h"
+
+static int stub_tdm_vblank_cb_vblank_SW_called;
+
+void stub_tdm_vblank_init()
+{
+       stub_tdm_vblank_cb_vblank_SW_called = 0;
+}
+
+static tdm_error
+stub_tdm_vblank_cb_vblank_SW(tdm_vblank *vblank, double vblank_stamp)
+{
+       (void)vblank;
+       (void)vblank_stamp;
+
+       stub_tdm_vblank_cb_vblank_SW_called = 1;
+}
+
+#define tdm_vblank_cb_vblank_SW stub_tdm_vblank_cb_vblank_SW
+
+#endif // STUB_TDM_VBLANK_H
diff --git a/ut/stubs/stub_unistd.cpp b/ut/stubs/stub_unistd.cpp
new file mode 100644 (file)
index 0000000..0023fb0
--- /dev/null
@@ -0,0 +1,93 @@
+#include "stub_unistd.h"
+
+#include <string.h>
+
+int stub_pipe_error;
+int stub_write_error;
+int stub_syscall_return_value;
+short stub_unistd_closed_fds[STUB_UNISTD_SIZE_FDS];
+void *stub_read_buf;
+int stub_read_returned_size;
+int stub_dub_error = 0;
+
+void stub_unistd_init()
+{
+       stub_pipe_error = 0;
+       stub_syscall_return_value = 1;
+       stub_write_error = 0;
+       stub_read_buf = NULL;
+       stub_read_returned_size = 0;
+       stub_dub_error = 0;
+       for(int i = 0; i < STUB_UNISTD_SIZE_FDS; ++i) {
+               stub_unistd_closed_fds[i] = 0;
+       }
+}
+
+int stub_pipe(int pipedes[2])
+{
+       if (stub_pipe_error)
+               return -1;
+
+       return 0;
+}
+
+long int stub_syscall(long int sysno, ...)
+{
+       (void)sysno;
+
+       return stub_syscall_return_value;
+}
+
+int stub_close(int fd)
+{
+       if (fd >= STUB_UNISTD_SIZE_FDS) {
+               return -1;
+       }
+
+       stub_unistd_closed_fds[fd] = 1;
+
+       return 0;
+}
+
+ssize_t stub_write(int fd, const void *buf, size_t n)
+{
+       (void)fd;
+       (void)buf;
+
+       if (stub_write_error)
+               return 0;
+
+       return n;
+}
+
+ssize_t stub_read(int fd, void *buf, size_t nbytes)
+{
+       if (!stub_read_buf) {
+               buf = NULL;
+               return 0;
+       }
+
+       memcpy(buf, stub_read_buf, nbytes);
+
+       return stub_read_returned_size;
+}
+
+int stub_dup(int fd)
+{
+       (void)fd;
+
+       if (stub_dub_error) {
+               return -1;
+       }
+
+       return 5;
+}
+
+int stub_poll(struct pollfd *fds, nfds_t nfds, int timeout)
+{
+       (void)fds;
+       (void)nfds;
+       (void)timeout;
+
+       return 1;
+}
diff --git a/ut/stubs/stub_unistd.h b/ut/stubs/stub_unistd.h
new file mode 100644 (file)
index 0000000..43f10f9
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef STUB_UNISTD_H
+#define STUB_UNISTD_H
+
+#include <unistd.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_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;
+
+void stub_unistd_init();
+
+int stub_pipe(int pipedes[2]);
+
+long int stub_syscall (long int sysno, ...);
+
+int stub_close(int fd);
+
+ssize_t stub_write(int fd, const void *buf, size_t n);
+
+ssize_t stub_read(int fd, void *buf, size_t nbytes);
+
+int stub_dup(int fd);
+
+int stub_poll(struct pollfd *fds, nfds_t nfds, int timeout);
+
+#define pipe(p) stub_pipe(p)
+#define syscall(sysno, args...) stub_syscall(sysno, ##args)
+#define close(fd) stub_close(fd)
+#define write(fd, buf, n) stub_write(fd, buf, n)
+#define read(fd, buf, nbytes) stub_read(fd, buf, nbytes)
+#define dup(fd) stub_dup(fd)
+#define poll(fds, nfds, timeout) stub_poll(fds, nfds, timeout)
+
+#endif // STUB_UNISTD_H
index 0eec9c9..520e2d3 100644 (file)
@@ -2,6 +2,9 @@
 
 #include <stdlib.h>
 
+int TBM_BUFMGR_DEINIT_CALLED = 0;
+int TBM_BO_GET_USER_DATA_NULL = 0;
+
 tbm_bufmgr tbm_bufmgr_init(int fd)
 {
        (void)fd;
@@ -186,3 +189,25 @@ void tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
        (void)surface;
        (void)type;
 }
+
+int tbm_surface_internal_delete_user_data(tbm_surface_h surface,
+                                         unsigned long key)
+{
+       (void)surface;
+       (void)key;
+
+       return 0;
+}
+
+int tbm_surface_internal_get_num_bos(tbm_surface_h surface)
+{
+       (void)surface;
+
+       return 0;
+}
+
+void stub_tbm_init()
+{
+       TBM_BUFMGR_DEINIT_CALLED = 0;
+       TBM_BO_GET_USER_DATA_NULL = 0;
+}
index ede41e1..dcbde86 100644 (file)
@@ -5,8 +5,8 @@
 #include "tbm_bufmgr.h"
 #include "tbm_surface_queue.h"
 
-static int TBM_BUFMGR_DEINIT_CALLED;
-static int TBM_BO_GET_USER_DATA_NULL;
+extern int TBM_BUFMGR_DEINIT_CALLED;
+extern int TBM_BO_GET_USER_DATA_NULL;
 
 struct _tbm_surface {
        int temp;
@@ -33,4 +33,6 @@ void tbm_surface_internal_ref(tbm_surface_h surface);
 
 void tbm_surface_internal_unref(tbm_surface_h surface);
 
+void stub_tbm_init();
+
 #endif /* _TBM_STUBS_H */
diff --git a/ut/stubs/tdm_capture_stubs.h b/ut/stubs/tdm_capture_stubs.h
deleted file mode 100644 (file)
index 7e49f75..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#ifndef _TDM_CAPTURE_STUBS_H
-#define _TDM_CAPTURE_STUBS_H
-
-static int OUTPUT_CREATE_CAPTURE_ERROR;
-static int CAPTURE_SET_DONE_HANDLER_ERROR;
-static int LAYER_CREATE_CAPTURE_ERROR;
-static int CAPTURE_SET_INFO_ERROR;
-static int CAPTURE_ATTACH_ERROR;
-static int CAPTURE_COMMIT_ERROR;
-
-static tdm_capture *output_create_capture(tdm_output *output, tdm_error *error)
-{
-       (void)output;
-       (void)error;
-
-       if (OUTPUT_CREATE_CAPTURE_ERROR) {
-               *error = TDM_ERROR_OPERATION_FAILED;
-               return NULL;
-       }
-
-       *error = TDM_ERROR_NONE;
-
-       return NULL;
-}
-
-static void capture_destroy(tdm_capture *capture)
-{
-       (void)capture;
-}
-
-static tdm_error capture_set_done_handler(tdm_capture *capture,
-                                               tdm_capture_done_handler func, void *user_data)
-{
-       (void)capture;
-       (void)func;
-       (void)user_data;
-
-       if (CAPTURE_SET_DONE_HANDLER_ERROR) {
-               if (user_data) {
-                       free(user_data);
-               }
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_capture *layer_create_capture(tdm_layer *layer, tdm_error *error)
-{
-       (void)layer;
-       (void)error;
-
-       if (LAYER_CREATE_CAPTURE_ERROR) {
-               *error = TDM_ERROR_OPERATION_FAILED;
-               return NULL;
-       }
-
-       *error = TDM_ERROR_NONE;
-       return NULL;
-}
-
-static tdm_error capture_set_info(tdm_capture *capture, tdm_info_capture *info)
-{
-       (void)capture;
-       (void)info;
-
-       if (CAPTURE_SET_INFO_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_error capture_commit(tdm_capture *capture)
-{
-       (void)capture;
-
-       if (CAPTURE_COMMIT_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-#endif /* _TDM_CAPTURE_STUBS_H */
diff --git a/ut/stubs/tdm_display_stubs.h b/ut/stubs/tdm_display_stubs.h
deleted file mode 100644 (file)
index ac76eb7..0000000
+++ /dev/null
@@ -1,335 +0,0 @@
-#ifndef _TDM_DISPLAY_STUBS_H
-#define _TDM_DISPLAY_STUBS_H
-
-#include "tdm_private.h"
-
-static int TDM_PP_CREATE_INTERNAL_ERROR;
-static int OUTPUT_SET_PROPERTY_ERROR;
-static int OUTPUT_GET_PROPERTY_ERROR;
-static int OUTPUT_WAIT_VBLANK_ERROR;
-static int OUTPUT_SET_VBLANK_HANDLER;
-static int OUTPUT_COMMIT_ERROR;
-static int OUTPUT_SET_COMMIT_HANDLER;
-static int OUTPUT_SET_MODE_ERROR;
-static int OUTPUT_SET_DPMS_ERROR;
-static int OUTPUT_GET_DPMS_ERROR;
-static int TDM_CAPTURE_CREATE_OUTPUT_INTENAL_ERROR;
-static int LAYER_SET_PROPERTY_ERROR;
-static int LAYER_GET_PROPERTY_ERROR;
-static int LAYER_SET_INFO_ERROR;
-static int LAYER_SET_BUFFER_ERROR;
-static int LAYER_UNSET_BUFFER_ERROR;
-static int LAYER_SET_VIDEO_POS_ERROR;
-static int CAPTURE_CREATE_LAYER_INTERNAL_ERROR;
-static int TDM_THREAD_HANDLE_ERROR;
-static int TDM_EVENT_LOOP_DISPATCH_ERROR;
-
-static tdm_private_pp *
-ut_tdm_pp_create_internal(tdm_private_display *private_display,
-                                                  tdm_error *error)
-{
-       (void)private_display;
-
-       if (TDM_PP_CREATE_INTERNAL_ERROR) {
-               if (error) {
-                       *error = TDM_ERROR_OPERATION_FAILED;
-               }
-               return NULL;
-       }
-
-       if (error) {
-               *error = TDM_ERROR_NONE;
-       }
-       return NULL;
-}
-
-static tdm_error output_set_property(tdm_output *output, unsigned int id,
-                                                                        tdm_value value)
-{
-       (void)output;
-       (void)id;
-       (void)value;
-
-       if (OUTPUT_SET_PROPERTY_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_error output_get_property(tdm_output *output, unsigned int id,
-                                                                        tdm_value *value)
-{
-       (void)output;
-       (void)id;
-       (void)value;
-
-       if (OUTPUT_GET_PROPERTY_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static void ut_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;
-}
-
-static tdm_error output_wait_vblank(tdm_output *output, int interval, int sync,
-                                                                       void *user_data)
-{
-       (void)output;
-       (void)interval;
-       (void)sync;
-       (void)user_data;
-
-       free(user_data);
-       if (OUTPUT_WAIT_VBLANK_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_error output_set_vblank_handler(tdm_output *output,
-                                                                                  tdm_output_vblank_handler func)
-{
-       (void)output;
-       (void)func;
-
-       if (OUTPUT_SET_VBLANK_HANDLER) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_error output_commit(tdm_output *output, int sync, void *user_data)
-{
-       (void)output;
-       (void)sync;
-
-       free(user_data);
-       if (OUTPUT_COMMIT_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_error output_set_commit_handler(tdm_output *output,
-                                                                       tdm_output_commit_handler func)
-{
-       (void)output;
-       (void)func;
-
-       if (OUTPUT_SET_COMMIT_HANDLER) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_error output_set_mode(tdm_output *output, const tdm_output_mode *mode)
-{
-       (void)output;
-       (void)mode;
-
-       if (OUTPUT_SET_MODE_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_error output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
-{
-       (void)output;
-       (void)dpms_value;
-
-       if (OUTPUT_SET_DPMS_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_error output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
-{
-       (void)output;
-       (void)dpms_value;
-
-       if (OUTPUT_GET_DPMS_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_private_capture *
-ut_tdm_capture_create_output_internal(tdm_private_output*private_output,
-                                                                          tdm_error *error)
-{
-       (void)private_output;
-       (void)error;
-
-       if (TDM_CAPTURE_CREATE_OUTPUT_INTENAL_ERROR) {
-               *error = TDM_ERROR_OPERATION_FAILED;
-               return NULL;
-       }
-
-       *error = TDM_ERROR_NONE;
-       return NULL;
-}
-
-static tdm_error layer_set_property(tdm_layer *layer, unsigned int id,
-                                                               tdm_value value)
-{
-       (void)layer;
-       (void)id;
-       (void)value;
-
-       if (LAYER_SET_PROPERTY_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_error layer_get_property(tdm_layer *layer, unsigned int id,
-                                                               tdm_value *value)
-{
-       (void)layer;
-       (void)id;
-       (void)value;
-
-       if (LAYER_GET_PROPERTY_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_error layer_set_info(tdm_layer *layer, tdm_info_layer *info)
-{
-       (void)layer;
-       (void)info;
-
-       if (LAYER_SET_INFO_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-tdm_error layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer)
-{
-       (void)layer;
-       (void)buffer;
-
-       if (LAYER_SET_BUFFER_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-tbm_surface_h ut_tdm_buffer_ref_backend(tbm_surface_h buffer)
-{
-       (void)buffer;
-
-       return NULL;
-}
-
-tdm_error layer_unset_buffer(tdm_layer *layer)
-{
-       (void)layer;
-
-       if (LAYER_UNSET_BUFFER_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static int ut_tdm_thread_get_fd(tdm_private_loop *private_loop)
-{
-       (void)private_loop;
-
-       return 1;
-}
-
-static int ut_tdm_event_loop_get_fd(tdm_private_display *private_display)
-{
-       (void)private_display;
-
-       return 1;
-}
-
-static tdm_error layer_set_video_pos(tdm_layer *layer, int zpos)
-{
-       (void)layer;
-       (void)zpos;
-
-       if (LAYER_SET_VIDEO_POS_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_private_capture *
-ut_tdm_capture_create_layer_internal(tdm_private_layer *private_layer,
-                                                                 tdm_error *error)
-{
-       (void)private_layer;
-       (void)error;
-
-       if (CAPTURE_CREATE_LAYER_INTERNAL_ERROR) {
-               *error = TDM_ERROR_OPERATION_FAILED;
-               return NULL;
-       }
-
-       *error = TDM_ERROR_NONE;
-       return NULL;
-}
-
-static int ut_poll(struct pollfd *fds, nfds_t nfds, int timeout)
-{
-       (void)fds;
-       (void)nfds;
-       (void)timeout;
-
-       return 1;
-}
-
-static tdm_error ut_tdm_thread_handle_cb(tdm_private_loop *private_loop)
-{
-       (void)private_loop;
-
-       if (TDM_THREAD_HANDLE_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-static tdm_error ut_tdm_event_loop_dispatch(tdm_private_display *private_display)
-{
-       (void)private_display;
-
-       if (TDM_EVENT_LOOP_DISPATCH_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-#endif /* _TDM_DISPLAY_STUBS_H */
diff --git a/ut/stubs/tdm_helper_stubs.h b/ut/stubs/tdm_helper_stubs.h
deleted file mode 100644 (file)
index ae630ce..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-#ifndef _TDM_HELPER_STUBS_H
-#define _TDM_HELPER_STUBS_H
-
-/* HELPER FUNCTIONS */
-
-static int GETENV_ERROR;
-static int SSCANF_ERROR;
-static int FCNTL_ERROR;
-static int DUP_ERROR;
-
-static char *ut_getenv(const char *name)
-{
-       (void)name;
-
-       if (GETENV_ERROR) {
-               return NULL;
-       }
-
-       return (char*)"getenv";
-}
-
-static int ut_sscanf(const char *buf, const char *format, ...)
-{
-       (void)buf;
-       (void)format;
-
-       if (SSCANF_ERROR) {
-               return -1;
-       }
-
-       return 0;
-}
-
-static int ut_fcntl(int fd, int cmd, ...)
-{
-       (void)fd;
-       (void)cmd;
-
-       if (FCNTL_ERROR) {
-               return -1;
-       }
-
-       return 0;
-}
-
-static int ut_dup(int fd)
-{
-       (void)fd;
-
-       if (DUP_ERROR) {
-               return -1;
-       }
-
-       return 2;
-}
-
-#endif /* _TDM_HELPER_STUBS_H */
diff --git a/ut/stubs/tdm_pp_stubs.h b/ut/stubs/tdm_pp_stubs.h
deleted file mode 100644 (file)
index 79b56e6..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef _TDM_PP_STUBS_H
-#define _TDM_PP_STUBS_H
-
-static int PP_SET_INFO_ERROR;
-static int PP_ATACH_ERROR;
-static int PP_COMMIT_ERROR;
-
-static tbm_surface_h ut_tdm_buffer_ref_backend(tbm_surface_h buffer)
-{
-       (void)buffer;
-
-       return NULL;
-}
-
-static tdm_error pp_set_info(tdm_pp *pp, tdm_info_pp *info)
-{
-       (void)pp;
-       (void)info;
-
-       if (PP_SET_INFO_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-static tdm_error pp_commit(tdm_pp *pp)
-{
-       (void)pp;
-
-       if (PP_COMMIT_ERROR) {
-               return TDM_ERROR_OPERATION_FAILED;
-       }
-
-       return TDM_ERROR_NONE;
-}
-
-#endif /* _TDM_PP_STUBS_H */
diff --git a/ut/stubs/tdm_thread.cpp b/ut/stubs/tdm_thread.cpp
deleted file mode 100644 (file)
index 219b571..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#include "tdm.h"
-#include "tdm_private.h"
-
-int TDM_THREAD_IS_RUNNING = 0;
-
-tdm_error
-tdm_thread_init(tdm_private_loop *private_loop)
-{
-       (void)private_loop;
-
-       return TDM_ERROR_NONE;
-}
-
-void
-tdm_thread_deinit(tdm_private_loop *private_loop)
-{
-       (void)private_loop;
-}
-
-int
-tdm_thread_get_fd(tdm_private_loop *private_loop)
-{
-       (void)private_loop;
-
-       return 0;
-}
-tdm_error
-tdm_thread_send_cb(tdm_private_loop *private_loop, tdm_thread_cb_base *base)
-{
-       (void)private_loop;
-       (void)base;
-
-       return TDM_ERROR_NONE;
-}
-
-tdm_error
-tdm_thread_handle_cb(tdm_private_loop *private_loop)
-{
-       (void)private_loop;
-
-       return TDM_ERROR_NONE;
-}
-
-int
-tdm_thread_in_display_thread(pid_t tid)
-{
-       (void)tid;
-
-       return 0;
-}
-
-int
-tdm_thread_is_running()
-{
-       return TDM_THREAD_IS_RUNNING;
-}
index 43cdc78..fd83fc6 100644 (file)
@@ -150,3 +150,12 @@ tdm_vblank_wait_seq(tdm_vblank *vblank, unsigned int req_sec, unsigned int req_u
 
        return TDM_ERROR_NONE;
 }
+
+tdm_error
+tdm_vblank_cb_vblank_SW(tdm_vblank *vblank, double vblank_stamp)
+{
+       (void)vblank;
+       (void)vblank_stamp;
+
+       return TDM_ERROR_NONE;
+}