[utest] Add 25 test cases. 05/159405/2
authorAndrii Sokolenko <a.sokolenko@samsung.com>
Wed, 8 Nov 2017 16:21:57 +0000 (18:21 +0200)
committerAndrii Sokolenko <a.sokolenko@samsung.com>
Wed, 8 Nov 2017 16:23:07 +0000 (18:23 +0200)
Change-Id: I98437b4ad61706df1c9548e178f04035f91562d3
Signed-off-by: Andrii Sokolenko <a.sokolenko@samsung.com>
utests/Makefile.am
utests/src/ut_common.h
utests/src/ut_main.cpp
utests/src/ut_tdm.cpp
utests/src/ut_tdm_capture.cpp
utests/src/ut_tdm_layer.cpp
utests/src/ut_tdm_output.cpp
utests/src/ut_tdm_pp.cpp

index 3357e0c..c95689c 100644 (file)
@@ -17,7 +17,7 @@ tdm_utests_CXXFLAGS = \
        -I$(includedir)/gtest \
        -fpermissive \
        -rdynamic \
-       -UFAIL_ON_UNSUPPORTED \
+       -DFAIL_ON_UNSUPPORTED \
        -w
 # The flag -w is used, because there are many warnings in libtdm's sources.
 # Warnings occur because we build project with g++.
index c30269d..7a6968b 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef UT_COMMON_H
 #define UT_COMMON_H
-#define CHECK_FLAG(FLAG) \
+#define SKIP_FLAG(FLAG) \
 do {\
   if(!FLAG) {\
         std::cout << "[  SKIPPED ]" << " not supported" << std::endl;\
index b6aeb4a..8d0544a 100644 (file)
@@ -33,6 +33,6 @@
 int main(int argc, char **argv)
 {
        ::testing::InitGoogleTest(&argc, argv);
-       ::testing::FLAGS_gtest_death_test_style = "threadsafe";
+       ::testing::FLAGS_gtest_death_test_style = "fast";
        return RUN_ALL_TESTS();
 }
index 6a6ead6..80979c4 100644 (file)
 **************************************************************************/
 
 #include "gtest/gtest.h"
+extern "C" {
 #include "tdm.h"
+#include "tbm_bufmgr.h"
+#include "tbm_drm_helper.h"
+}
 
 class TDMInit : public ::testing::Test {
 protected:
        void SetUp(void)
        {
                setenv("TDM_DLOG", "1", 1);
-               setenv("XDG_RUNTIME_DIR", ".", 1);
+               setenv("XDG_RUNTIME_DIR", "/tmp", 1);
                setenv("TBM_DLOG", "1", 1);
+               setenv("TBM_DISPLAY_SERVER", "1", 1);
        }
        void TearDown(void)
        {
+               unsetenv("TDM_DLOG");
+               unsetenv("XDG_RUNTIME_DIR");
+               unsetenv("TBM_DLOG");
+               unsetenv("TBM_DISPLAY_SERVER");
        }
 };
 
 class TDMDefault : public ::testing::Test {
 protected:
        tdm_display *dpy = NULL;
+       tbm_bufmgr tbm_bufmgr = NULL;
        void SetUp(void)
        {
                setenv("TDM_DLOG", "1", 1);
-               setenv("XDG_RUNTIME_DIR", ".", 1);
+               setenv("XDG_RUNTIME_DIR", "/tmp", 1);
                setenv("TBM_DLOG", "1", 1);
+               setenv("TBM_DISPLAY_SERVER", "1", 1);
+               tbm_bufmgr = tbm_bufmgr_init(-1);
+               ASSERT_FALSE(tbm_bufmgr == NULL);
                tdm_error error = TDM_ERROR_NONE;
                dpy = tdm_display_init(&error);
                ASSERT_TRUE(error == TDM_ERROR_NONE);
@@ -60,41 +73,105 @@ protected:
        void TearDown(void)
        {
                tdm_display_deinit(dpy);
+               tbm_bufmgr_deinit(tbm_bufmgr);
+               tbm_bufmgr = NULL;
                dpy = NULL;
+               unsetenv("TDM_DLOG");
+               unsetenv("XDG_RUNTIME_DIR");
+               unsetenv("TBM_DLOG");
+               unsetenv("TBM_DISPLAY_SERVER");
        }
 };
 
 
-TEST_F(TDMInit, DisplayInitDeinitSuccessful)
+TEST_F(TDMInit, DisplayInitDeinitSuccessfulWithoutTBM)
+{
+       tdm_error error = TDM_ERROR_NONE;
+       tdm_display *dpy = tdm_display_init(&error);
+       ASSERT_TRUE(error == TDM_ERROR_NONE);
+       ASSERT_FALSE(dpy == NULL);
+       tdm_display_deinit(dpy);
+       dpy = NULL;
+       ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+       ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
+}
+
+TEST_F(TDMInit, DisplayInitFewTimesSuccessfulWithTBM)
+{
+       tdm_error error = TDM_ERROR_NONE;
+       tdm_display *dpy[20] = {NULL};
+       tbm_bufmgr tbm_bufmgr = NULL;
+       tbm_bufmgr = tbm_bufmgr_init(-1);
+       ASSERT_FALSE(tbm_bufmgr == NULL);
+       for (int i = 0; i < 20; i++) {
+               dpy[i] = tdm_display_init(&error);
+               EXPECT_TRUE(error == TDM_ERROR_NONE);
+               EXPECT_FALSE(dpy[i] == NULL);
+               EXPECT_EQ(dpy[0], dpy[i]);
+       }
+       for (int i = 19; i > 0; i--) {
+               tdm_display_deinit(dpy[i]);
+               EXPECT_FALSE(tbm_drm_helper_get_master_fd() == -1);
+               EXPECT_FALSE(tbm_drm_helper_get_fd() == -1);
+       }
+       tdm_display_deinit(dpy[0]);
+       tbm_bufmgr_deinit(tbm_bufmgr);
+       tbm_bufmgr = NULL;
+       ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+       ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
+}
+
+TEST_F(TDMInit, DisplayInitDeinitSuccessfulWithTBM)
 {
+       tbm_bufmgr tbm_bufmgr = NULL;
+       tbm_bufmgr = tbm_bufmgr_init(-1);
+       ASSERT_FALSE(tbm_bufmgr == NULL);
        tdm_error error = TDM_ERROR_NONE;
        tdm_display *dpy = tdm_display_init(&error);
        ASSERT_TRUE(error == TDM_ERROR_NONE);
        ASSERT_FALSE(dpy == NULL);
        tdm_display_deinit(dpy);
        dpy = NULL;
+       tbm_bufmgr_deinit(tbm_bufmgr);
+       tbm_bufmgr = NULL;
+       ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+       ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
 }
 
-TEST_F(TDMInit, DisplayInitDeinitSuccessfulNullError)
+TEST_F(TDMInit, DisplayInitDeinitSuccessfulNullErrorWithTBM)
 {
+       tbm_bufmgr tbm_bufmgr = NULL;
+       tbm_bufmgr = tbm_bufmgr_init(-1);
+       ASSERT_FALSE(tbm_bufmgr == NULL);
        tdm_error error = TDM_ERROR_NONE;
        tdm_display *dpy = tdm_display_init(NULL);
        ASSERT_TRUE(error == TDM_ERROR_NONE);
        ASSERT_FALSE(dpy == NULL);
        tdm_display_deinit(dpy);
        dpy = NULL;
+       tbm_bufmgr_deinit(tbm_bufmgr);
+       tbm_bufmgr = NULL;
+       ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+       ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
 }
 
-TEST_F(TDMInit, DisplayInitDeinitSuccessfulFewTimes)
+TEST_F(TDMInit, DisplayInitDeinitSuccessfulFewTimesWithTBM)
 {
        for (int i = 0; i < 20; ++i) {
+               tbm_bufmgr tbm_bufmgr = NULL;
+               tbm_bufmgr = tbm_bufmgr_init(-1);
+               ASSERT_FALSE(tbm_bufmgr == NULL);
                tdm_error error = TDM_ERROR_NONE;
                tdm_display *dpy = tdm_display_init(&error);
                ASSERT_TRUE(error == TDM_ERROR_NONE);
                ASSERT_FALSE(dpy == NULL);
                tdm_display_deinit(dpy);
                dpy = NULL;
+               tbm_bufmgr_deinit(tbm_bufmgr);
+               tbm_bufmgr = NULL;
        }
+       ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+       ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
 }
 
 TEST_F(TDMInit, DisplayDeinitSuccessfulNullDpy)
@@ -106,6 +183,8 @@ TEST_F(TDMInit, DisplayDeinitSuccessfulNullDpy)
        tdm_display_deinit(NULL);
        tdm_display_deinit(dpy);
        dpy = NULL;
+       ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+       ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
 }
 
 TEST_F(TDMInit, DisplayDeinitDeathWrongDpy)
@@ -114,10 +193,13 @@ TEST_F(TDMInit, DisplayDeinitDeathWrongDpy)
        tdm_display *dpy = tdm_display_init(&error);
        ASSERT_TRUE(error == TDM_ERROR_NONE);
        ASSERT_FALSE(dpy == NULL);
-       tdm_display *wrong_dpy = 0xBEAF;
-       EXPECT_DEATH(tdm_display_deinit(wrong_dpy), "");
+       EXPECT_EXIT({tdm_display *wrong_dpy = 0xBEAF;
+                                tdm_display_deinit(wrong_dpy);
+                                exit(0); }, ::testing::ExitedWithCode(0), "");
        tdm_display_deinit(dpy);
        dpy = NULL;
+       ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
+       ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
 }
 
 TEST_F(TDMDefault, DisplayUpdateSuccessful)
@@ -125,6 +207,13 @@ TEST_F(TDMDefault, DisplayUpdateSuccessful)
        ASSERT_TRUE(tdm_display_update(dpy) == TDM_ERROR_NONE);
 }
 
+TEST_F(TDMDefault, DisplayUpdateFailWrongDpy)
+{
+       ASSERT_EXIT({tdm_display *wrong_dpy = 0xBEAF;
+                                tdm_display_update(wrong_dpy);
+                                exit(0);}, ::testing::ExitedWithCode(0), "");
+}
+
 TEST_F(TDMDefault, DisplayUpdateFailNullDpy)
 {
        ASSERT_FALSE(tdm_display_update(NULL) == TDM_ERROR_NONE);
@@ -153,6 +242,13 @@ TEST_F(TDMDefault, DisplayGetFDFailNullDpy)
        ASSERT_FALSE(tdm_display_get_fd(NULL, &fd) == TDM_ERROR_NONE);
 }
 
+TEST_F(TDMDefault, DisplayGetFDFailWrongDpy)
+{
+       ASSERT_EXIT({tdm_display *wrong_dpy = 0xBEAF; int fd = -42;
+                                tdm_display_get_fd(wrong_dpy, &fd);
+                                exit(0);}, ::testing::ExitedWithCode(0), "");
+}
+
 TEST_F(TDMDefault, DISABLED_DisplayHandleEventsSuccessful)
 {
        /* TODO Generate events*/
index 9715d1a..cffcc72 100644 (file)
 **************************************************************************/
 
 #include "gtest/gtest.h"
-#include "tdm.h"
 #include "ut_common.h"
+extern "C" {
+#include "tdm.h"
+#include "tbm_bufmgr.h"
+#include "tbm_drm_helper.h"
+}
 
 class TDMCapture : public ::testing::Test {
 protected:
        tdm_display *dpy = NULL;
        tdm_capture_capability capture_capabilities = -42;
        bool has_capture = false;
+       tbm_bufmgr tbm_bufmgr = NULL;
        void SetUp(void)
        {
                setenv("TDM_DLOG", "1", 1);
                setenv("XDG_RUNTIME_DIR", ".", 1);
                setenv("TBM_DLOG", "1", 1);
+               setenv("TBM_DISPLAY_SERVER", "1", 1);
+               tbm_bufmgr = tbm_bufmgr_init(-1);
+               ASSERT_FALSE(tbm_bufmgr == NULL);
                tdm_error error = TDM_ERROR_NONE;
                dpy = tdm_display_init(&error);
                ASSERT_TRUE(error == TDM_ERROR_NONE);
@@ -57,12 +65,18 @@ protected:
        {
                tdm_display_deinit(dpy);
                dpy = NULL;
+               tbm_bufmgr_deinit(tbm_bufmgr);
+               tbm_bufmgr = NULL;
+               unsetenv("TDM_DLOG");
+               unsetenv("XDG_RUNTIME_DIR");
+               unsetenv("TBM_DLOG");
+               unsetenv("TBM_DISPLAY_SERVER");
        }
 };
 
 TEST_F(TDMCapture, DisplayGetCaptureAvailableFormatsSuccessful)
 {
-       CHECK_FLAG(has_capture);
+       SKIP_FLAG(has_capture);
        const tbm_format * formats = NULL;
        int count = -42;
        ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_catpure_available_formats(dpy, &formats, &count));
index 89064c0..574fd08 100644 (file)
 **************************************************************************/
 
 #include "gtest/gtest.h"
-#include "tdm.h"
 #include "ut_common.h"
 
+extern "C" {
+#include "tdm.h"
+#include "tbm_bufmgr.h"
+#include "tbm_drm_helper.h"
+}
+
 class TDMLayer : public ::testing::Test {
 protected:
        tdm_display *dpy = NULL;
+       tbm_bufmgr tbm_bufmgr = NULL;
        int output_count = -42;
        int layer_count = -42;
        bool has_layers = false;
@@ -43,6 +49,9 @@ protected:
                setenv("TDM_DLOG", "1", 1);
                setenv("XDG_RUNTIME_DIR", ".", 1);
                setenv("TBM_DLOG", "1", 1);
+               setenv("TBM_DISPLAY_SERVER", "1", 1);
+               tbm_bufmgr = tbm_bufmgr_init(-1);
+               ASSERT_FALSE(tbm_bufmgr == NULL);
                tdm_error error = TDM_ERROR_NONE;
                dpy = tdm_display_init(&error);
                ASSERT_TRUE(error == TDM_ERROR_NONE);
@@ -60,12 +69,18 @@ protected:
        {
                tdm_display_deinit(dpy);
                dpy = NULL;
+               tbm_bufmgr_deinit(tbm_bufmgr);
+               tbm_bufmgr = NULL;
+               unsetenv("TDM_DLOG");
+               unsetenv("XDG_RUNTIME_DIR");
+               unsetenv("TBM_DLOG");
+               unsetenv("TBM_DISPLAY_SERVER");
        }
 };
 
 TEST_F(TDMLayer, OutputGetLayerSuccessful)
 {
-       CHECK_FLAG(has_layers);
+       SKIP_FLAG(has_layers);
        for (int i = 0; i < output_count; i++) {
                tdm_error error_output = TDM_ERROR_NONE;
                tdm_output * output = NULL;
index 6ea9f21..460972c 100644 (file)
 **************************************************************************/
 
 #include "gtest/gtest.h"
-#include "tdm.h"
 #include "ut_common.h"
+#include <climits>
+extern "C" {
+#include "tdm.h"
+#include "tbm_bufmgr.h"
+#include "tbm_drm_helper.h"
+}
 
 class TDMOutput : public ::testing::Test {
 protected:
        tdm_display *dpy = NULL;
        int output_count = -42;
        bool has_output = false;
+       tbm_bufmgr tbm_bufmgr = NULL;
+       static unsigned int handle_call;
+       static void tdm_output_change_handler_test_func(tdm_output *output,
+                                                                                                       tdm_output_change_type type,
+                                                                                                       tdm_value value,
+                                                                                                       void *u_data)
+       {
+               if ( ((int) u_data) < -100) {
+                       TDMOutput::handle_call++;
+               }
+       }
        void SetUp(void)
        {
                setenv("TDM_DLOG", "1", 1);
                setenv("XDG_RUNTIME_DIR", ".", 1);
                setenv("TBM_DLOG", "1", 1);
+               setenv("TBM_DISPLAY_SERVER", "1", 1);
+               tbm_bufmgr = tbm_bufmgr_init(-1);
+               ASSERT_FALSE(tbm_bufmgr == NULL);
                tdm_error error = TDM_ERROR_NONE;
                dpy = tdm_display_init(&error);
                ASSERT_TRUE(error == TDM_ERROR_NONE);
@@ -52,20 +71,283 @@ protected:
 #endif
                if (output_count > 0)
                        has_output = true;
+               handle_call = 0;
        }
        void TearDown(void)
        {
                tdm_display_deinit(dpy);
                dpy = NULL;
+               tbm_bufmgr_deinit(tbm_bufmgr);
+               tbm_bufmgr = NULL;
+               unsetenv("TDM_DLOG");
+               unsetenv("XDG_RUNTIME_DIR");
+               unsetenv("TBM_DLOG");
+               unsetenv("TBM_DISPLAY_SERVER");
        }
 };
 
+unsigned int TDMOutput::handle_call = 0;
+
 TEST_F(TDMOutput, DisplayGetOutputSuccessful)
 {
-       CHECK_FLAG(has_output);
+       SKIP_FLAG(has_output);
        for (int i = 0; i < output_count; i++) {
                tdm_error error = TDM_ERROR_NONE;
                ASSERT_FALSE(NULL == tdm_display_get_output(dpy, i, &error));
                ASSERT_TRUE(TDM_ERROR_NONE == error);
        }
 }
+
+TEST_F(TDMOutput, DisplayGetOutputSuccessfulWrongIndex)
+{
+       SKIP_FLAG(has_output);
+       tdm_error error = TDM_ERROR_NONE;
+       ASSERT_TRUE(NULL == tdm_display_get_output(dpy, -1, &error));
+       ASSERT_TRUE(TDM_ERROR_NONE == error);
+}
+
+TEST_F(TDMOutput, DisplayGetOutputSuccessfulBigIndex)
+{
+       SKIP_FLAG(has_output);
+       tdm_error error = TDM_ERROR_NONE;
+       ASSERT_TRUE(NULL == tdm_display_get_output(dpy, INT_MAX, &error));
+       ASSERT_TRUE(TDM_ERROR_NONE == error);
+}
+
+TEST_F(TDMOutput, DisplayGetOutputSuccessfulSmallIndex)
+{
+       SKIP_FLAG(has_output);
+       tdm_error error = TDM_ERROR_NONE;
+       ASSERT_TRUE(NULL == tdm_display_get_output(dpy, INT_MIN, &error));
+       ASSERT_TRUE(TDM_ERROR_NONE == error);
+}
+
+TEST_F(TDMOutput, DisplayGetOutputSuccessfulErrorNull)
+{
+       SKIP_FLAG(has_output);
+       ASSERT_FALSE(NULL == tdm_display_get_output(dpy, 0, NULL));
+}
+
+TEST_F(TDMOutput, DisplayOutputGetCapabilitiesSuccessful)
+{
+       SKIP_FLAG(has_output);
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               tdm_output_capability capabilities = -42;
+               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+               ASSERT_FALSE(NULL == output);
+               ASSERT_TRUE(TDM_ERROR_NONE == error);
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_capabilities(output, &capabilities));
+               ASSERT_FALSE(-42 == capabilities);
+       }
+}
+
+TEST_F(TDMOutput, DisplayOutputGetCapabilitiesFailAllNull)
+{
+       SKIP_FLAG(has_output);
+       ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_capabilities(NULL, NULL));
+}
+
+TEST_F(TDMOutput, DisplayOutputGetCapabilitiesFailOnlyOutput)
+{
+       SKIP_FLAG(has_output);
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+               ASSERT_FALSE(NULL == output);
+               ASSERT_TRUE(TDM_ERROR_NONE == error);
+               ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_capabilities(output, NULL));
+       }
+}
+
+TEST_F(TDMOutput, OutputGetModelInfoSuccessful)
+{
+       SKIP_FLAG(has_output);
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               const char * maker = NULL, * model = NULL, * name = NULL;
+               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+               ASSERT_FALSE(NULL == output);
+               ASSERT_TRUE(TDM_ERROR_NONE == error);
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_model_info(output, &maker, &model, &name));
+               ASSERT_FALSE(NULL == maker);
+               ASSERT_FALSE(NULL == model);
+               ASSERT_FALSE(NULL == name);
+       }
+}
+
+TEST_F(TDMOutput, OutputGetModelInfoFailAllNull)
+{
+       SKIP_FLAG(has_output);
+       ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_model_info(NULL, NULL, NULL, NULL));
+}
+
+TEST_F(TDMOutput, OutputGetModelInfoSuccessfulOnlyOutput)
+{
+       SKIP_FLAG(has_output);
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+               ASSERT_FALSE(NULL == output);
+               ASSERT_TRUE(TDM_ERROR_NONE == error);
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_model_info(output, NULL, NULL, NULL));
+       }
+}
+
+TEST_F(TDMOutput, OutputGetConnStatusSuccessful)
+{
+       SKIP_FLAG(has_output);
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               tdm_output_conn_status status = -42;
+               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+               ASSERT_FALSE(NULL == output);
+               ASSERT_TRUE(TDM_ERROR_NONE == error);
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
+               ASSERT_FALSE(-42 == status);
+       }
+}
+
+TEST_F(TDMOutput, OutputGetConnStatusFailAllNull)
+{
+       SKIP_FLAG(has_output);
+       ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_conn_status(NULL, NULL));
+}
+
+TEST_F(TDMOutput, OutputGetConnStatusFailOnlyOutput)
+{
+       SKIP_FLAG(has_output);
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+               ASSERT_FALSE(NULL == output);
+               ASSERT_TRUE(TDM_ERROR_NONE == error);
+               ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, NULL));
+       }
+}
+
+TEST_F(TDMOutput, OutputSetDPMSSuccessful)
+{
+       SKIP_FLAG(has_output);
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+               ASSERT_FALSE(NULL == output);
+               ASSERT_TRUE(TDM_ERROR_NONE == error);
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_STANDBY));
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_SUSPEND));
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+       }
+}
+
+TEST_F(TDMOutput, OutputAddChangeHandlerSuccessful)
+{
+       SKIP_FLAG(has_output);
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+               ASSERT_FALSE(NULL == output);
+               ASSERT_TRUE(TDM_ERROR_NONE == error);
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
+                                                                                                                                       tdm_output_change_handler_test_func,
+                                                                                                                                       -101));
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+               ASSERT_GT(handle_call, 0);
+       }
+}
+
+TEST_F(TDMOutput, OutputAddChangeHandlerSuccessfulFewFuncs)
+{
+       SKIP_FLAG(has_output);
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+               ASSERT_FALSE(NULL == output);
+               ASSERT_TRUE(TDM_ERROR_NONE == error);
+               for (int k = 0; k < 20; k++) {
+                       ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
+                                                                                                                                               tdm_output_change_handler_test_func,
+                                                                                                                                               (-101-k)));
+               }
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+               ASSERT_GT(handle_call, 20);
+       }
+}
+
+
+TEST_F(TDMOutput, OutputAddChangeHandlerFailAllNull)
+{
+       SKIP_FLAG(has_output);
+       ASSERT_FALSE(TDM_ERROR_NONE ==tdm_output_add_change_handler(NULL, NULL, NULL));
+}
+
+TEST_F(TDMOutput, OutputAddChangeHandlerFailOnlyOutput)
+{
+       SKIP_FLAG(has_output);
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+               ASSERT_FALSE(NULL == output);
+               ASSERT_TRUE(TDM_ERROR_NONE == error);
+               ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_add_change_handler(output, NULL, NULL));
+       }
+}
+
+TEST_F(TDMOutput, OutputAddChangeHandlerFailWrongOutput)
+{
+       SKIP_FLAG(has_output);
+       ASSERT_EXIT({tdm_output *output = 0xBEAF;
+                                tdm_output_add_change_handler(output,
+                                                                                          tdm_output_change_handler_test_func,
+                                                                                          -101);
+                                exit(0);}, ::testing::ExitedWithCode(0), "");
+}
+
+TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessful)
+{
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+               ASSERT_FALSE(NULL == output);
+               ASSERT_TRUE(TDM_ERROR_NONE == error);
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
+                                                                                                                                       tdm_output_change_handler_test_func,
+                                                                                                                                       -101));
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+               ASSERT_GT(handle_call, 0);
+               handle_call = 0;
+               tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, -101);
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+               ASSERT_EQ(handle_call, 0);
+       }
+}
+
+TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessfulFewFuncs)
+{
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+               ASSERT_FALSE(NULL == output);
+               ASSERT_TRUE(TDM_ERROR_NONE == error);
+               for (int k = 0; k < 20; k++) {
+                       ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
+                                                                                                                                               tdm_output_change_handler_test_func,
+                                                                                                                                               (-101-k)));
+               }
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+               ASSERT_GT(handle_call, 20);
+               handle_call = 0;
+               for (int k = 0; k < 20; k++) {
+                       tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, (-101-k));
+               }
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_ON));
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_set_dpms(output, TDM_OUTPUT_DPMS_OFF));
+               ASSERT_EQ(handle_call, 0);
+       }
+}
index 18d9a96..6fa99da 100644 (file)
 **************************************************************************/
 
 #include "gtest/gtest.h"
-#include "tdm.h"
 #include "ut_common.h"
+extern "C" {
+#include "tdm.h"
+#include "tbm_bufmgr.h"
+#include "tbm_drm_helper.h"
+}
 
 class TDMPP : public testing::Test {
 protected:
@@ -57,12 +61,16 @@ protected:
        {
                tdm_display_deinit(dpy);
                dpy = NULL;
+               unsetenv("TDM_DLOG");
+               unsetenv("XDG_RUNTIME_DIR");
+               unsetenv("TBM_DLOG");
+               unsetenv("TBM_DISPLAY_SERVER");
        }
 };
 
 TEST_F(TDMPP, DisplayGetPPAvailableFormatsSuccessful)
 {
-       CHECK_FLAG(has_pp);
+       SKIP_FLAG(has_pp);
        const tbm_format * formats = NULL;
        int count = -42;
        ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_pp_available_formats(dpy, &formats, &count));