[utest] Add 9 test cases. Fix Init/Deinit behavior. 65/159565/1
authorAndrii Sokolenko <a.sokolenko@samsung.com>
Thu, 9 Nov 2017 16:35:50 +0000 (18:35 +0200)
committerAndrii Sokolenko <a.sokolenko@samsung.com>
Thu, 9 Nov 2017 16:36:10 +0000 (18:36 +0200)
Change-Id: Ib77379ef55ecc145e9b87702ca2b99969718c677
Signed-off-by: Andrii Sokolenko <a.sokolenko@samsung.com>
utests/Makefile.am
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 c95689c..f44d3e0 100644 (file)
@@ -17,8 +17,7 @@ tdm_utests_CXXFLAGS = \
        -I$(includedir)/gtest \
        -fpermissive \
        -rdynamic \
-       -DFAIL_ON_UNSUPPORTED \
-       -w
+       -DFAIL_ON_UNSUPPORTED
 # The flag -w is used, because there are many warnings in libtdm's sources.
 # Warnings occur because we build project with g++.
 # In C++ we need to use explicit types conversion.
index 80979c4..fd5f526 100644 (file)
@@ -37,6 +37,7 @@ extern "C" {
 
 class TDMInit : public ::testing::Test {
 protected:
+       int master_fd = -42, tbm_fd = -42;
        void SetUp(void)
        {
                setenv("TDM_DLOG", "1", 1);
@@ -46,6 +47,20 @@ protected:
        }
        void TearDown(void)
        {
+               if (master_fd > -1) {
+                       int temp_master_fd = tbm_drm_helper_get_master_fd();
+                       EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
+                       if (temp_master_fd > -1)
+                               exit(1);
+                       close(master_fd);
+               }
+               if (tbm_fd > -1) {
+                       int temp_tbm_fd = tbm_drm_helper_get_fd();
+                       EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
+                       if (temp_tbm_fd > -1)
+                               exit(1);
+                       close(tbm_fd);
+               }
                unsetenv("TDM_DLOG");
                unsetenv("XDG_RUNTIME_DIR");
                unsetenv("TBM_DLOG");
@@ -57,6 +72,7 @@ class TDMDefault : public ::testing::Test {
 protected:
        tdm_display *dpy = NULL;
        tbm_bufmgr tbm_bufmgr = NULL;
+       int master_fd = -42, tbm_fd = -42;
        void SetUp(void)
        {
                setenv("TDM_DLOG", "1", 1);
@@ -69,6 +85,8 @@ protected:
                dpy = tdm_display_init(&error);
                ASSERT_TRUE(error == TDM_ERROR_NONE);
                ASSERT_FALSE(dpy == NULL);
+               master_fd = tbm_drm_helper_get_master_fd();
+               tbm_fd = tbm_drm_helper_get_fd();
        }
        void TearDown(void)
        {
@@ -76,6 +94,20 @@ protected:
                tbm_bufmgr_deinit(tbm_bufmgr);
                tbm_bufmgr = NULL;
                dpy = NULL;
+               if (master_fd > -1) {
+                       int temp_master_fd = tbm_drm_helper_get_master_fd();
+                       EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
+                       if (temp_master_fd > -1)
+                               exit(1);
+                       close(master_fd);
+               }
+               if (tbm_fd > -1) {
+                       int temp_tbm_fd = tbm_drm_helper_get_fd();
+                       EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
+                       if (temp_tbm_fd > -1)
+                               exit(1);
+                       close(tbm_fd);
+               }
                unsetenv("TDM_DLOG");
                unsetenv("XDG_RUNTIME_DIR");
                unsetenv("TBM_DLOG");
@@ -90,12 +122,31 @@ TEST_F(TDMInit, DisplayInitDeinitSuccessfulWithoutTBM)
        tdm_display *dpy = tdm_display_init(&error);
        ASSERT_TRUE(error == TDM_ERROR_NONE);
        ASSERT_FALSE(dpy == NULL);
+       master_fd = tbm_drm_helper_get_master_fd();
+       tbm_fd = tbm_drm_helper_get_fd();
        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, 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);
+       EXPECT_TRUE(error == TDM_ERROR_NONE);
+       EXPECT_FALSE(dpy == NULL);
+       master_fd = tbm_drm_helper_get_master_fd();
+       tbm_fd = tbm_drm_helper_get_fd();
+       if (dpy != NULL && error == TDM_ERROR_NONE)
+               tdm_display_deinit(dpy);
+       dpy = NULL;
+       tbm_bufmgr_deinit(tbm_bufmgr);
+       tbm_bufmgr = NULL;
+}
+
+
 TEST_F(TDMInit, DisplayInitFewTimesSuccessfulWithTBM)
 {
        tdm_error error = TDM_ERROR_NONE;
@@ -103,7 +154,12 @@ TEST_F(TDMInit, DisplayInitFewTimesSuccessfulWithTBM)
        tbm_bufmgr tbm_bufmgr = NULL;
        tbm_bufmgr = tbm_bufmgr_init(-1);
        ASSERT_FALSE(tbm_bufmgr == NULL);
-       for (int i = 0; i < 20; i++) {
+       dpy[0] = tdm_display_init(&error);
+       EXPECT_TRUE(error == TDM_ERROR_NONE);
+       EXPECT_FALSE(dpy[0] == NULL);
+       master_fd = tbm_drm_helper_get_master_fd();
+       tbm_fd = tbm_drm_helper_get_fd();
+       for (int i = 1; i < 20; i++) {
                dpy[i] = tdm_display_init(&error);
                EXPECT_TRUE(error == TDM_ERROR_NONE);
                EXPECT_FALSE(dpy[i] == NULL);
@@ -111,31 +167,22 @@ TEST_F(TDMInit, DisplayInitFewTimesSuccessfulWithTBM)
        }
        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);
+               if (master_fd > -1) {
+                       int temp_master_fd = tbm_drm_helper_get_master_fd();
+                       EXPECT_NE(temp_master_fd, -1);
+                       if (temp_master_fd > -1)
+                               close(temp_master_fd);
+               }
+               if (tbm_fd > -1) {
+                       int temp_tbm_fd = tbm_drm_helper_get_fd();
+                       EXPECT_NE(temp_tbm_fd, -1);
+                       if (temp_tbm_fd > -1)
+                               close(temp_tbm_fd);
+               }
        }
        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, DisplayInitDeinitSuccessfulNullErrorWithTBM)
@@ -143,16 +190,15 @@ 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);
+       EXPECT_FALSE(dpy == NULL);
+       master_fd = tbm_drm_helper_get_master_fd();
+       tbm_fd = tbm_drm_helper_get_fd();
+       if (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, DisplayInitDeinitSuccessfulFewTimesWithTBM)
@@ -163,43 +209,107 @@ TEST_F(TDMInit, DisplayInitDeinitSuccessfulFewTimesWithTBM)
                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);
+               EXPECT_TRUE(error == TDM_ERROR_NONE);
+               EXPECT_FALSE(dpy == NULL);
+               master_fd = tbm_drm_helper_get_master_fd();
+               tbm_fd = tbm_drm_helper_get_fd();
+               if (dpy != NULL)
+                       tdm_display_deinit(dpy);
                dpy = NULL;
                tbm_bufmgr_deinit(tbm_bufmgr);
                tbm_bufmgr = NULL;
+               if (master_fd > -1) {
+                       int temp_master_fd = tbm_drm_helper_get_master_fd();
+                       EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
+                       if (temp_master_fd > -1)
+                               exit(1);
+                       close(master_fd);
+                       master_fd = -1;
+               }
+               if (tbm_fd > -1) {
+                       int temp_tbm_fd = tbm_drm_helper_get_fd();
+                       EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
+                       if (temp_tbm_fd > -1)
+                               exit(1);
+                       close(tbm_fd);
+                       tbm_fd = -1;
+               }
        }
-       ASSERT_TRUE(tbm_drm_helper_get_master_fd() == -1);
-       ASSERT_TRUE(tbm_drm_helper_get_fd() == -1);
 }
 
-TEST_F(TDMInit, DisplayDeinitSuccessfulNullDpy)
+TEST_F(TDMInit, DisplayDeinitSuccessfulNullDpyWithoutTBM)
 {
        tdm_error error = TDM_ERROR_NONE;
        tdm_display *dpy = tdm_display_init(&error);
        ASSERT_TRUE(error == TDM_ERROR_NONE);
        ASSERT_FALSE(dpy == NULL);
+       master_fd = tbm_drm_helper_get_master_fd();
+       tbm_fd = tbm_drm_helper_get_fd();
        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)
+TEST_F(TDMInit, DisplayDeinitFailWrongDpyBadAddress)
 {
        tdm_error error = TDM_ERROR_NONE;
        tdm_display *dpy = tdm_display_init(&error);
        ASSERT_TRUE(error == TDM_ERROR_NONE);
        ASSERT_FALSE(dpy == NULL);
-       EXPECT_EXIT({tdm_display *wrong_dpy = 0xBEAF;
+       master_fd = tbm_drm_helper_get_master_fd();
+       tbm_fd = tbm_drm_helper_get_fd();
+       EXPECT_EXIT({tdm_display *wrong_dpy = (tdm_display *) 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(TDMInit, DisplayDeinitFailWrongDpyStackAddress)
+{
+       tdm_error error = TDM_ERROR_NONE;
+       tdm_display *dpy = tdm_display_init(&error);
+       ASSERT_TRUE(error == TDM_ERROR_NONE);
+       ASSERT_FALSE(dpy == NULL);
+       master_fd = tbm_drm_helper_get_master_fd();
+       tbm_fd = tbm_drm_helper_get_fd();
+       EXPECT_EXIT({tdm_display *wrong_dpy = &error;
+                                tdm_display_deinit(wrong_dpy);
+                                exit(0); }, ::testing::ExitedWithCode(0), "");
+       tdm_display_deinit(dpy);
+       dpy = NULL;
+}
+
+TEST_F(TDMInit, DisplayDeinitFailWrongDpyHeapAddress)
+{
+       tdm_error error = TDM_ERROR_NONE;
+       tdm_display *dpy = tdm_display_init(&error);
+       ASSERT_TRUE(error == TDM_ERROR_NONE);
+       ASSERT_FALSE(dpy == NULL);
+       master_fd = tbm_drm_helper_get_master_fd();
+       tbm_fd = tbm_drm_helper_get_fd();
+       EXPECT_EXIT({tdm_display *wrong_dpy = (tdm_display *) ((unsigned long) sbrk(0) - sizeof(unsigned long));
+                                tdm_display_deinit(wrong_dpy);
+                                exit(0); }, ::testing::ExitedWithCode(0), "");
+       tdm_display_deinit(dpy);
+       dpy = NULL;
+}
+
+TEST_F(TDMInit, DISABLED_DisplayDeinitFailRepeatWithSameDpy)
+{
+       EXPECT_EXIT({tdm_error error = TDM_ERROR_NONE;
+                                tdm_display *dpy = tdm_display_init(&error);
+                                if (error != TDM_ERROR_NONE) exit(1);
+                                tdm_display_deinit(dpy);
+                                if (tbm_drm_helper_get_master_fd() != -1) exit(1);
+                                if (tbm_drm_helper_get_fd() != -1) exit(1);
+                                tdm_display_deinit(dpy);
+                                tdm_display *dpy2 = malloc(2048);
+                                *((unsigned int *)dpy2) = 673282346;
+                                tdm_display_deinit(dpy2);
+                                tdm_display_deinit(dpy);
+                                tdm_display_deinit(dpy2);
+                                exit(0); }, ::testing::ExitedWithCode(0), "");
 }
 
 TEST_F(TDMDefault, DisplayUpdateSuccessful)
@@ -209,7 +319,7 @@ TEST_F(TDMDefault, DisplayUpdateSuccessful)
 
 TEST_F(TDMDefault, DisplayUpdateFailWrongDpy)
 {
-       ASSERT_EXIT({tdm_display *wrong_dpy = 0xBEAF;
+       ASSERT_EXIT({tdm_display *wrong_dpy = (tdm_display *)0xBEAF;
                                 tdm_display_update(wrong_dpy);
                                 exit(0);}, ::testing::ExitedWithCode(0), "");
 }
@@ -244,7 +354,7 @@ TEST_F(TDMDefault, DisplayGetFDFailNullDpy)
 
 TEST_F(TDMDefault, DisplayGetFDFailWrongDpy)
 {
-       ASSERT_EXIT({tdm_display *wrong_dpy = 0xBEAF; int fd = -42;
+       ASSERT_EXIT({tdm_display *wrong_dpy = (tdm_display *) 0xBEAF; int fd = -42;
                                 tdm_display_get_fd(wrong_dpy, &fd);
                                 exit(0);}, ::testing::ExitedWithCode(0), "");
 }
@@ -307,7 +417,7 @@ TEST_F(TDMDefault, DisplayGetBackendInfoSuccessfulSetOnlyMinor)
 
 TEST_F(TDMDefault, DisplayGetCapabilitiesSuccessful)
 {
-       tdm_display_capability capabilities = -42;
+       tdm_display_capability capabilities = (tdm_display_capability) -42;
        ASSERT_TRUE(tdm_display_get_capabilities(dpy, &capabilities) == TDM_ERROR_NONE);
        ASSERT_FALSE(capabilities == -1);
 }
@@ -324,7 +434,7 @@ TEST_F(TDMDefault, DisplayGetCapabilitiesFailSetOnlyDpy)
 
 TEST_F(TDMDefault, DisplayGetPPCapabilitiesSuccessful)
 {
-       tdm_pp_capability capabilities = -42;
+       tdm_pp_capability capabilities = (tdm_pp_capability) -42;
        tdm_error error = TDM_ERROR_NONE;
        error = tdm_display_get_pp_capabilities(dpy, &capabilities);
        ASSERT_TRUE(error == TDM_ERROR_NONE || error == TDM_ERROR_NO_CAPABILITY);
@@ -340,7 +450,7 @@ TEST_F(TDMDefault, DisplayGetPPCapabilitiesFailNullAll)
 
 TEST_F(TDMDefault, DisplayGetCaptureCapabilitiesSuccessful)
 {
-       tdm_capture_capability capabilities = -42;
+       tdm_capture_capability capabilities = (tdm_capture_capability) -42;
        tdm_error error = TDM_ERROR_NONE;
        error = tdm_display_get_capture_capabilities(dpy, &capabilities);
        ASSERT_TRUE(error == TDM_ERROR_NONE || error == TDM_ERROR_NO_CAPABILITY);
@@ -358,7 +468,7 @@ TEST_F(TDMDefault, DisplayGetMaxLayerCountSuccessful)
 {
        int max_count = -42;
        ASSERT_TRUE(TDM_ERROR_NONE == tdm_display_get_max_layer_count(dpy, &max_count));
-       ASSERT_FALSE(-42 == max_count);
+       ASSERT_NE(max_count, -42);
 }
 
 TEST_F(TDMDefault, DisplayGetMaxLayerCountFailNullAll)
index cffcc72..ad75d2a 100644 (file)
@@ -39,7 +39,7 @@ extern "C" {
 class TDMCapture : public ::testing::Test {
 protected:
        tdm_display *dpy = NULL;
-       tdm_capture_capability capture_capabilities = -42;
+       tdm_capture_capability capture_capabilities = (tdm_capture_capability) -42;
        bool has_capture = false;
        tbm_bufmgr tbm_bufmgr = NULL;
        void SetUp(void)
index 574fd08..98c148e 100644 (file)
@@ -41,8 +41,8 @@ class TDMLayer : public ::testing::Test {
 protected:
        tdm_display *dpy = NULL;
        tbm_bufmgr tbm_bufmgr = NULL;
-       int output_count = -42;
-       int layer_count = -42;
+       int master_fd = -42, tbm_fd = -42, layer_count = 0;
+       tdm_layer ** tdm_layer_array = NULL;
        bool has_layers = false;
        void SetUp(void)
        {
@@ -56,10 +56,37 @@ protected:
                dpy = tdm_display_init(&error);
                ASSERT_TRUE(error == TDM_ERROR_NONE);
                ASSERT_FALSE(dpy == NULL);
-               error = tdm_display_get_output_count(dpy, &output_count);
-               error = tdm_display_get_max_layer_count(dpy, &layer_count);
+               master_fd = tbm_drm_helper_get_master_fd();
+               tbm_fd = tbm_drm_helper_get_fd();
+               int output_count = 0;
+               if (tdm_display_get_output_count(dpy, &output_count) == TDM_ERROR_NONE) {
+                       for (int i = 0; i < output_count; i++) {
+                               tdm_output * output = tdm_display_get_output(dpy, i, &error);
+                               if (TDM_ERROR_NONE != error || NULL == output)
+                                       continue;
+                               tdm_output_conn_status status = TDM_OUTPUT_CONN_STATUS_DISCONNECTED;
+                               if (TDM_ERROR_NONE != tdm_output_get_conn_status(output, &status))
+                                       continue;
+                               if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
+                                       continue;
+                               int temp_layer_count = 0;
+                               if (TDM_ERROR_NONE != tdm_output_get_layer_count(output, &temp_layer_count))
+                                       continue;
+                               if (0 == temp_layer_count)
+                                       continue;
+                               tdm_layer_array = (tdm_layer **) realloc(tdm_layer_array,
+                                                                                 (layer_count + temp_layer_count)*sizeof(tdm_layer *));
+                               ASSERT_FALSE(NULL == tdm_layer_array);
+                               for (int k = layer_count; k < (layer_count + temp_layer_count); k++) {
+                                       tdm_layer_array[k] = tdm_output_get_layer(output, k, &error);
+                                       ASSERT_TRUE(TDM_ERROR_NONE == error);
+                                       ASSERT_FALSE(NULL == tdm_layer_array[k]);
+                               }
+                               layer_count+=temp_layer_count;
+                       }
+               }
+
 #ifdef FAIL_ON_UNSUPPORTED
-               ASSERT_GT(output_count, 0);
                ASSERT_GT(layer_count, 0);
 #endif
                if (layer_count > 0)
@@ -71,6 +98,22 @@ protected:
                dpy = NULL;
                tbm_bufmgr_deinit(tbm_bufmgr);
                tbm_bufmgr = NULL;
+               if (tdm_layer_array)
+                       free(tdm_layer_array);
+               if (master_fd > -1) {
+                       int temp_master_fd = tbm_drm_helper_get_master_fd();
+                       EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
+                       if (temp_master_fd > -1)
+                               exit(1);
+                       close(master_fd);
+               }
+               if (tbm_fd > -1) {
+                       int temp_tbm_fd = tbm_drm_helper_get_fd();
+                       EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
+                       if (temp_tbm_fd > -1)
+                               exit(1);
+                       close(tbm_fd);
+               }
                unsetenv("TDM_DLOG");
                unsetenv("XDG_RUNTIME_DIR");
                unsetenv("TBM_DLOG");
@@ -78,19 +121,12 @@ protected:
        }
 };
 
-TEST_F(TDMLayer, OutputGetLayerSuccessful)
+TEST_F(TDMLayer, LayerGetCapabilitiesSuccessful)
 {
        SKIP_FLAG(has_layers);
-       for (int i = 0; i < output_count; i++) {
-               tdm_error error_output = TDM_ERROR_NONE;
-               tdm_output * output = NULL;
-               output = tdm_display_get_output(dpy, i, &error_output);
-               ASSERT_FALSE(NULL == output);
-               ASSERT_TRUE(TDM_ERROR_NONE == error_output);
-               for (int k = 0; k < layer_count; k++) {
-                       tdm_error error_layer = TDM_ERROR_NONE;
-                       ASSERT_FALSE(NULL == tdm_output_get_layer(output, k, &error_layer));
-                       ASSERT_TRUE(TDM_ERROR_NONE == error_layer);
-               }
+       for (int i = 0; i < layer_count; i++) {
+               tdm_layer_capability capabilities = (tdm_layer_capability) -42;
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_layer_get_capabilities(tdm_layer_array[i], &capabilities));
+               ASSERT_NE(capabilities, -42);
        }
 }
index 460972c..f510e20 100644 (file)
@@ -40,7 +40,7 @@ extern "C" {
 class TDMOutput : public ::testing::Test {
 protected:
        tdm_display *dpy = NULL;
-       int output_count = -42;
+       int output_count = -42, master_fd = -42, tbm_fd = -42;
        bool has_output = false;
        tbm_bufmgr tbm_bufmgr = NULL;
        static unsigned int handle_call;
@@ -65,6 +65,8 @@ protected:
                dpy = tdm_display_init(&error);
                ASSERT_TRUE(error == TDM_ERROR_NONE);
                ASSERT_FALSE(dpy == NULL);
+               master_fd = tbm_drm_helper_get_master_fd();
+               tbm_fd = tbm_drm_helper_get_fd();
                error = tdm_display_get_output_count(dpy, &output_count);
 #ifdef FAIL_ON_UNSUPPORTED
                ASSERT_GT(output_count, 0);
@@ -79,6 +81,20 @@ protected:
                dpy = NULL;
                tbm_bufmgr_deinit(tbm_bufmgr);
                tbm_bufmgr = NULL;
+               if (master_fd > -1) {
+                       int temp_master_fd = tbm_drm_helper_get_master_fd();
+                       EXPECT_EQ(temp_master_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
+                       if (temp_master_fd > -1)
+                               exit(1);
+                       close(master_fd);
+               }
+               if (tbm_fd > -1) {
+                       int temp_tbm_fd = tbm_drm_helper_get_fd();
+                       EXPECT_EQ(temp_tbm_fd, -1) << "Fatal Error. Can't deinit tdm/tbm" << std::endl;
+                       if (temp_tbm_fd > -1)
+                               exit(1);
+                       close(tbm_fd);
+               }
                unsetenv("TDM_DLOG");
                unsetenv("XDG_RUNTIME_DIR");
                unsetenv("TBM_DLOG");
@@ -133,7 +149,7 @@ 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_capability capabilities = (tdm_output_capability) -42;
                tdm_output * output = tdm_display_get_output(dpy, i, &error);
                ASSERT_FALSE(NULL == output);
                ASSERT_TRUE(TDM_ERROR_NONE == error);
@@ -199,7 +215,7 @@ 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_conn_status status = (tdm_output_conn_status) -42;
                tdm_output * output = tdm_display_get_output(dpy, i, &error);
                ASSERT_FALSE(NULL == output);
                ASSERT_TRUE(TDM_ERROR_NONE == error);
@@ -231,9 +247,13 @@ TEST_F(TDMOutput, OutputSetDPMSSuccessful)
        SKIP_FLAG(has_output);
        for (int i = 0; i < output_count; i++) {
                tdm_error error = TDM_ERROR_NONE;
+               tdm_output_conn_status status;
                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));
+               if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
+                       continue;
                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));
@@ -249,9 +269,13 @@ TEST_F(TDMOutput, OutputAddChangeHandlerSuccessful)
                tdm_output * output = tdm_display_get_output(dpy, i, &error);
                ASSERT_FALSE(NULL == output);
                ASSERT_TRUE(TDM_ERROR_NONE == error);
+               tdm_output_conn_status status;
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
+               if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
+                       continue;
                ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
                                                                                                                                        tdm_output_change_handler_test_func,
-                                                                                                                                       -101));
+                                                                                                                                       (void *) -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);
@@ -266,10 +290,14 @@ TEST_F(TDMOutput, OutputAddChangeHandlerSuccessfulFewFuncs)
                tdm_output * output = tdm_display_get_output(dpy, i, &error);
                ASSERT_FALSE(NULL == output);
                ASSERT_TRUE(TDM_ERROR_NONE == error);
+               tdm_output_conn_status status;
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
+               if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
+                       continue;
                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)));
+                                                                                                                                               (void *) (-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));
@@ -281,7 +309,7 @@ TEST_F(TDMOutput, OutputAddChangeHandlerSuccessfulFewFuncs)
 TEST_F(TDMOutput, OutputAddChangeHandlerFailAllNull)
 {
        SKIP_FLAG(has_output);
-       ASSERT_FALSE(TDM_ERROR_NONE ==tdm_output_add_change_handler(NULL, NULL, NULL));
+       ASSERT_FALSE(TDM_ERROR_NONE == tdm_output_add_change_handler(NULL, NULL, NULL));
 }
 
 TEST_F(TDMOutput, OutputAddChangeHandlerFailOnlyOutput)
@@ -299,28 +327,33 @@ TEST_F(TDMOutput, OutputAddChangeHandlerFailOnlyOutput)
 TEST_F(TDMOutput, OutputAddChangeHandlerFailWrongOutput)
 {
        SKIP_FLAG(has_output);
-       ASSERT_EXIT({tdm_output *output = 0xBEAF;
+       ASSERT_EXIT({tdm_output *output = (tdm_output *) 0xBEAF;
                                 tdm_output_add_change_handler(output,
                                                                                           tdm_output_change_handler_test_func,
-                                                                                          -101);
+                                                                                          (void *) -101);
                                 exit(0);}, ::testing::ExitedWithCode(0), "");
 }
 
 TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessful)
 {
+       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);
+               tdm_output_conn_status status;
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
+               if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
+                       continue;
                ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_add_change_handler(output,
                                                                                                                                        tdm_output_change_handler_test_func,
-                                                                                                                                       -101));
+                                                                                                                                       (void *) -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);
+               tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, (void *) -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);
@@ -329,25 +362,107 @@ TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessful)
 
 TEST_F(TDMOutput, OutputRemoveChangeHandlerSuccessfulFewFuncs)
 {
+       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);
+               tdm_output_conn_status status;
+               ASSERT_TRUE(TDM_ERROR_NONE == tdm_output_get_conn_status(output, &status));
+               if (status == TDM_OUTPUT_CONN_STATUS_DISCONNECTED)
+                       continue;
                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)));
+                                                                                                                                               (void *) (-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));
+                       tdm_output_remove_change_handler(output, tdm_output_change_handler_test_func, (void *) (-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);
        }
 }
+
+TEST_F(TDMOutput, OutputRemoveChangeHandlerFailAllNull)
+{
+       SKIP_FLAG(has_output);
+       ASSERT_EXIT({tdm_output_remove_change_handler(NULL, NULL, NULL);
+                                exit(0);}, ::testing::ExitedWithCode(0), "");
+}
+
+TEST_F(TDMOutput, OutputRemoveChangeHandlerFailOnlyOutput)
+{
+       SKIP_FLAG(has_output);
+       ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
+                                        tdm_error error = TDM_ERROR_NONE;
+                                        tdm_output * output = tdm_display_get_output(dpy, i, &error);
+                                        if (NULL == output) exit(1);
+                                        if (TDM_ERROR_NONE != error) exit(1);
+                                        tdm_output_remove_change_handler(output, NULL, NULL);
+                                } exit(0);}, ::testing::ExitedWithCode(0), "");
+}
+
+TEST_F(TDMOutput, OutputRemoveChangeHandlerFailWrongOutput)
+{
+       SKIP_FLAG(has_output);
+       ASSERT_EXIT({tdm_output *output = (tdm_output *) 0xBEAF;
+                                tdm_output_remove_change_handler(output,
+                                                                                          tdm_output_change_handler_test_func,
+                                                                                          (void *) -101);
+                                exit(0);}, ::testing::ExitedWithCode(0), "");
+}
+
+TEST_F(TDMOutput, OutputGetOutputTypeSuccessful)
+{
+       SKIP_FLAG(has_output);
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               tdm_output_type type = (tdm_output_type) -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_output_type(output, &type));
+               ASSERT_NE(type, -42);
+       }
+}
+
+TEST_F(TDMOutput, OutputGetOutputTypeFailNullAll)
+{
+       SKIP_FLAG(has_output);
+       ASSERT_EXIT({if (tdm_output_get_output_type(NULL, NULL) == TDM_ERROR_NONE) exit(1);
+                                exit(0);}, ::testing::ExitedWithCode(0), "");
+}
+
+TEST_F(TDMOutput, OutputGetOutputTypeFailOnlyOutput)
+{
+       SKIP_FLAG(has_output);
+       ASSERT_EXIT({for (int i = 0; i < output_count; i++) {
+                                        tdm_error error = TDM_ERROR_NONE;
+                                        tdm_output * output = tdm_display_get_output(dpy, i, &error);
+                                        if (NULL == output) exit(1);
+                                        if (TDM_ERROR_NONE != error) exit(1);
+                                        if (tdm_output_get_output_type(output, NULL) == TDM_ERROR_NONE) exit(1);
+                               }
+                               exit(0);}, ::testing::ExitedWithCode(0), "");
+}
+
+TEST_F(TDMOutput, OutputGetLayerCountSuccessful)
+{
+       SKIP_FLAG(has_output);
+       for (int i = 0; i < output_count; i++) {
+               tdm_error error = TDM_ERROR_NONE;
+               int count = -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_layer_count(output, &count));
+               ASSERT_NE(count, -42);
+       }
+}
index 6fa99da..5ea127a 100644 (file)
@@ -39,7 +39,7 @@ extern "C" {
 class TDMPP : public testing::Test {
 protected:
        tdm_display *dpy = NULL;
-       tdm_pp_capability pp_capabilities = -42;
+       tdm_pp_capability pp_capabilities = (tdm_pp_capability) -42;
        bool has_pp = false;
        void SetUp(void)
        {