utest: fix all failed tests and add new tests
[platform/core/uifw/libtdm.git] / utests / src / ut_tdm_hwc_window.cpp
index 13b7cc2..544ddff 100644 (file)
@@ -28,6 +28,7 @@
  *
 **************************************************************************/
 
+#include <limits.h>
 #include "gtest/gtest.h"
 #include "ut_common.h"
 #include "stdint.h"
@@ -57,7 +58,7 @@ protected:
                setenv("TDM_COMMIT_PER_VBLANK", "1", 1);
                setenv("TDM_DLOG", "1", 1);
                setenv("TDM_HWC", "1", 1);
-               setenv("XDG_RUNTIME_DIR", ".", 1);
+               setenv("XDG_RUNTIME_DIR", "/run", 1);
                setenv("TBM_DLOG", "1", 1);
                setenv("TBM_DISPLAY_SERVER", "1", 1);
        }
@@ -94,6 +95,7 @@ protected:
                const tdm_output_mode *preferred_mode = NULL;
                tdm_error error = TDM_ERROR_NONE;
                int all_output_count = 0;
+               outputs = NULL;
 
                SetEnv();
 
@@ -192,11 +194,13 @@ class TDMOutputHwcWithoutHwcCap : public TDMOutputHwc {
 class TDMHwcWindow : public TDMOutputHwc {
 protected:
        tdm_hwc_window **hwc_wins;
+       tdm_hwc_window *video_hwc_win;
        int hwc_count;
 
        void SetUp(void)
        {
                hwc_count = 0;
+               video_hwc_win = NULL;
 
                TDMOutputHwc::SetUp();
                hwc_wins = (tdm_hwc_window **)calloc(output_count * HWC_WIN_NUM, sizeof(tdm_hwc_window *));
@@ -209,6 +213,9 @@ protected:
                                        ASSERT_EQ(TDM_ERROR_NONE, error);
                                        hwc_wins[hwc_count++] = hw;
                                }
+                               if (!video_hwc_win) {
+                                       video_hwc_win = tdm_output_hwc_create_video_window(outputs[i], &error);
+                               }
                        }
                }
        }
@@ -218,6 +225,10 @@ protected:
                for (int i = 0; i < hwc_count; i++) {
                        tdm_output_hwc_destroy_window(outputs[0], hwc_wins[i]);
                }
+
+               if (video_hwc_win)
+                       tdm_output_hwc_destroy_window(outputs[0], video_hwc_win);
+
                TDMOutputHwc::TearDown();
        }
 
@@ -284,7 +295,7 @@ TEST_F(TDMOutputHwc, DestroyWindowSuccessful)
 /* tdm_error tdm_output_hwc_set_client_target_buffer(tdm_output *output,
                                                                                 tbm_surface_h target_buffer, tdm_hwc_region damage,
                                                                                 tdm_hwc_window *composited_wnds, uint32_t num_wnds); */
-TEST_F(TDMOutputHwc, DISABLED_SetClientTargetBufferFailNullOutput)
+TEST_F(TDMOutputHwc, SetClientTargetBufferFailNullOutput)
 {
        tdm_hwc_region reg;
        tbm_surface_h target_buff = CreateBufferForOutput(0);
@@ -293,7 +304,7 @@ TEST_F(TDMOutputHwc, DISABLED_SetClientTargetBufferFailNullOutput)
        ASSERT_NE(TDM_ERROR_NONE, error);
 }
 
-TEST_F(TDMOutputHwcWithoutHwcCap, DISABLED_SetClientTargetBufferFailNoHwc)
+TEST_F(TDMOutputHwcWithoutHwcCap, SetClientTargetBufferFailNoHwc)
 {
        tdm_hwc_region damage;
 
@@ -307,7 +318,7 @@ TEST_F(TDMOutputHwcWithoutHwcCap, DISABLED_SetClientTargetBufferFailNoHwc)
        }
 }
 
-TEST_F(TDMOutputHwc, DISABLED_SetClientTargetBufferSuccessfulSetBuff)
+TEST_F(TDMOutputHwc, SetClientTargetBufferSuccessfulSetBuff)
 {
        tdm_hwc_region damage;
 
@@ -328,7 +339,7 @@ TEST_F(TDMOutputHwc, DISABLED_SetClientTargetBufferSuccessfulSetBuff)
        }
 }
 
-TEST_F(TDMOutputHwc, DISABLED_SetClientTargetBufferSuccessfulResetBuff)
+TEST_F(TDMOutputHwc, SetClientTargetBufferSuccessfulResetBuff)
 {
        tdm_hwc_region damage = {.num_rects = 0, .rects = NULL};
 
@@ -575,7 +586,7 @@ TEST_F(TDMHwcWindow, SetFlagsSuccessful)
        for (int i = 0; i < hwc_count; i++) {
 
                error = tdm_hwc_window_set_flags(hwc_wins[i], flag);
-               ASSERT_EQ(TDM_ERROR_NONE, error);
+               ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
        }
 }
 
@@ -595,7 +606,7 @@ TEST_F(TDMHwcWindow, UnsetFlagsSuccessful)
        for (int i = 0; i < hwc_count; i++) {
 
                error = tdm_hwc_window_unset_flags(hwc_wins[i], flag);
-               ASSERT_EQ(TDM_ERROR_NONE, error);
+               ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
        }
 }
 
@@ -621,10 +632,13 @@ TEST_F(TDMHwcWindow, VideoGetCapabilitySuccessful)
 
        for (int i = 0; i < hwc_count; i++) {
                /* hwc_window with TDM_COMPOSITION_CLIENT dosn't support tdm_hwc_window_video_get_capability()*/
-               error = tdm_hwc_window_video_get_capability(hwc_wins[i],  &video_capability);
+               error = tdm_hwc_window_video_get_capability(hwc_wins[i], &video_capability);
                ASSERT_NE(TDM_ERROR_NONE, error);
 
-               /*TODO:: check video capability for TDM_COMPOSITION_VIDEO*/
+               if (video_hwc_win != NULL) {
+                       error = tdm_hwc_window_video_get_capability(video_hwc_win, &video_capability);
+                       ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
+               }
        }
 }
 
@@ -798,18 +812,14 @@ TEST_F(TDMOutputHwc, SetNeedValidateHandlerSuccessful)
 {
        for (int i = 0; i < output_count; i++) {
                if (IsHwcEnable(i)) {
+                       /*
+                        * This event can't be generated form user side.
+                        * So just check a set and double set
+                        */
+
                        /* test: first set*/
                        error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
                        ASSERT_EQ(TDM_ERROR_NONE, error);
-
-                       error = tdm_backend_trigger_need_validate_event(outputs[i]);
-                       ASSERT_EQ(TDM_ERROR_NONE, error);
-
-                       error = tdm_display_handle_events(dpy);
-                       ASSERT_EQ(TDM_ERROR_NONE, error);
-
-                       ASSERT_EQ(1, need_validate_handler_is_called);
-
                        /* test: second isn't allowed*/
                        error = tdm_output_hwc_set_need_validate_handler(outputs[i], &need_validate_handler);
                        ASSERT_NE(TDM_ERROR_NONE, error);
@@ -820,3 +830,134 @@ TEST_F(TDMOutputHwc, SetNeedValidateHandlerSuccessful)
        }
 }
 
+/* tdm_hwc_window * tdm_output_hwc_create_video_window(tdm_output *output, tdm_error *error); */
+TEST_F(TDMOutputHwc, CreateVideoWindowFailNull)
+{
+       ASSERT_EQ(NULL, tdm_output_hwc_create_video_window(NULL, &error));
+       ASSERT_NE(TDM_ERROR_NONE, error);
+}
+
+TEST_F(TDMOutputHwc, CreateVideoWindowSuccessful)
+{
+       for (int i = 0; i < output_count; i++) {
+               if (IsHwcEnable(i)) {
+                       tdm_hwc_window * hw = tdm_output_hwc_create_video_window(outputs[i], &error);
+                       if (error != TDM_ERROR_NOT_IMPLEMENTED) {
+                               ASSERT_EQ(TDM_ERROR_NONE, error);
+                               ASSERT_NE(NULL, hw);
+                               error = tdm_output_hwc_destroy_window(outputs[i], hw);
+                               ASSERT_EQ(TDM_ERROR_NONE, error);
+                       }
+               } else {
+                       ASSERT_EQ(NULL, tdm_output_hwc_create_video_window(outputs[i], &error));
+                       ASSERT_NE(TDM_ERROR_NONE, error);
+               }
+       }
+}
+
+/* tdm_output_hwc_get_video_supported_formats() */
+TEST_F(TDMOutputHwc, GetVideoSupportedFormatsFailNull)
+{
+       tdm_error error;
+
+       error = tdm_output_hwc_get_video_supported_formats(NULL, NULL, NULL);
+       ASSERT_NE(TDM_ERROR_NONE, error);
+}
+
+TEST_F(TDMOutputHwc, GetVideoSupportedFormatsSuccessful)
+{
+       tdm_error error;
+       const tbm_format *formats;
+       int count;
+
+       for (int i = 0; i < output_count; i++) {
+               if (IsHwcEnable(i)) {
+                       error = tdm_output_hwc_get_video_supported_formats(outputs[i], &formats, &count);
+                       if (error != TDM_ERROR_NOT_IMPLEMENTED) {
+                               ASSERT_EQ(TDM_ERROR_NONE, error);
+                               if (count > 0)
+                                       ASSERT_NE(NULL, formats);
+                       }
+               } else {
+                       error = tdm_output_hwc_get_video_supported_formats(outputs[i], &formats, &count);
+                       ASSERT_NE(TDM_ERROR_NONE, error);
+               }
+       }
+}
+
+/* tdm_hwc_window_video_get_available_properties() */
+TEST_F(TDMHwcWindow, GetAvailablePropertiesFailNullWin)
+{
+       SKIP_FLAG(video_hwc_win != NULL);
+       const tdm_prop *props;
+       int count;
+
+       error = tdm_hwc_window_video_get_available_properties(NULL, &props, &count);
+       ASSERT_NE(TDM_ERROR_NONE, error);
+
+       error = tdm_hwc_window_video_get_available_properties(video_hwc_win, NULL, &count);
+       ASSERT_NE(TDM_ERROR_NONE, error);
+
+       error = tdm_hwc_window_video_get_available_properties(video_hwc_win, &props, NULL);
+       ASSERT_NE(TDM_ERROR_NONE, error);
+}
+
+TEST_F(TDMHwcWindow, GetAvailablePropertiesSuccess)
+{
+       SKIP_FLAG(video_hwc_win != NULL);
+
+       const tdm_prop *props;
+       int count;
+
+       error = tdm_hwc_window_video_get_available_properties(video_hwc_win, &props, &count);
+       ASSERT_TRUE(TDM_ERROR_NONE == error || TDM_ERROR_NOT_IMPLEMENTED == error);
+}
+
+/* tdm_hwc_window_video_get_property() */
+TEST_F(TDMHwcWindow, GetPropertyFailNull)
+{
+       SKIP_FLAG(video_hwc_win != NULL);
+
+       tdm_value value;
+       int id = 1;
+
+       error = tdm_hwc_window_video_get_property(NULL, id, &value);
+       ASSERT_NE(TDM_ERROR_NONE, error);
+
+       error = tdm_hwc_window_video_get_property(video_hwc_win, id, NULL);
+       ASSERT_NE(TDM_ERROR_NONE, error);
+}
+
+TEST_F(TDMHwcWindow, GetPropertyFailWrongId)
+{
+       SKIP_FLAG(video_hwc_win != NULL);
+
+       tdm_value value;
+       int id = INT_MAX;
+
+       error = tdm_hwc_window_video_get_property(video_hwc_win, id, &value);
+       ASSERT_NE(TDM_ERROR_NONE, error);
+}
+
+/* tdm_hwc_window_video_set_property() */
+TEST_F(TDMHwcWindow, SetPropertyFailNull)
+{
+       SKIP_FLAG(video_hwc_win != NULL);
+       tdm_value value;
+       int id = 1;
+
+       error = tdm_hwc_window_video_set_property(NULL, id, value);
+       ASSERT_NE(TDM_ERROR_NONE, error);
+}
+
+TEST_F(TDMHwcWindow, SetPropertyFailWrongId)
+{
+       SKIP_FLAG(video_hwc_win != NULL);
+
+       tdm_value value;
+       int id = INT_MAX;
+
+       error = tdm_hwc_window_video_set_property(video_hwc_win, id, value);
+       ASSERT_NE(TDM_ERROR_NONE, error);
+}
+