virtual: client get voutput's output by tdm_client_get_output
[platform/core/uifw/libtdm.git] / haltests / src / tc_tdm_client.cpp
index 20aa27f..01668cb 100644 (file)
@@ -50,6 +50,15 @@ enum {
        TDM_UT_PIPE_MSG_TERMINATE_SERVER,
 };
 
+#define TDM_UT_WAIT(fmt, ...) \
+       do { \
+               char ch; \
+               do { \
+                       printf(fmt" [n]):next ", ##__VA_ARGS__); \
+                       ch = tc_tdm_getchar(); \
+               } while(ch != 'n'); \
+       } while (0)
+
 static int _tc_tdm_pipe_read_msg(int fd);
 static bool _tc_tdm_pipe_write_msg(int fd, int reply_fd, int msg);
 static pid_t _tc_tdm_client_server_fork(int *pipe_to_parent, int *pipe_to_child);
@@ -200,6 +209,23 @@ bool TDMClient::PrepareVblank(void)
        return true;
 }
 
+char
+tc_tdm_getchar(void)
+{
+       int c = getchar();
+       int ch = c;
+
+       if (ch == '\n' || ch == '\r')
+               ch = 'y';
+       else if (ch < 'a')
+               ch += ('a' - 'A');
+
+       while (c != '\n' && c != EOF)
+               c = getchar();
+
+       return ch;
+}
+
 static int
 _tc_tdm_pipe_read_msg(int fd)
 {
@@ -1386,7 +1412,7 @@ public:
 protected:
        static tdm_client *client;
        static tdm_client_voutput *voutput;
-       const int MODE_COUNT = 1;
+       const int MODE_COUNT = 2;
 
 private:
        static pid_t server_pid;
@@ -1457,6 +1483,8 @@ void TDMVirtualOutput::SetUpTestCase(void)
 
 void TDMVirtualOutput::TearDownTestCase(void)
 {
+//     TDM_UT_WAIT("check & press");
+
        if (voutput)
                tdm_client_voutput_destroy(voutput);
 
@@ -1478,27 +1506,47 @@ bool TDMVirtualOutput::PrepareVOutput(void)
        TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
        TDM_UT_RETURN_FALSE_IF_FAIL(client != NULL);
 
+
        voutput = tdm_client_create_voutput(client, name, &ret);
        TDM_UT_RETURN_FALSE_IF_FAIL(ret == TDM_ERROR_NONE);
        TDM_UT_RETURN_FALSE_IF_FAIL(voutput != NULL);
+
+//     TDM_UT_WAIT("check & press");
+
        return true;
 }
 
+static void
+_tc_tdm_client_virutual_make_available_mode(tdm_client_output_mode *modes, int count)
+{
+       int i;
+
+       for (i = 0; i < count; i++) {
+               modes[i].clock = 25200;
+               modes[i].hdisplay = 640;
+               modes[i].hsync_start = 656;
+               modes[i].hsync_end = 752;
+               modes[i].htotal = 800;
+               modes[i].hskew = 0;
+               modes[i].vdisplay = 480;
+               modes[i].vsync_start = 490;
+               modes[i].vsync_end = 492;
+               modes[i].vtotal = 525;
+               modes[i].vscan = 0;
+               modes[i].vrefresh = 30;
+               modes[i].flags = 0;
+               modes[i].type = 0;
+               snprintf(modes[i].name, TDM_NAME_LEN, "%dx%d_%d", modes[i].hdisplay, modes[i].vdisplay, i);
+       }
+}
+
 TEST_F(TDMVirtualOutput, SetAvailableModes)
 {
        tdm_error ret;
        tdm_client_output_mode modes[this->MODE_COUNT];
-       int i, count = this->MODE_COUNT;
-
-       for (i = 0; i < count; i++)
-       {
-               modes[i].mmHeight = 1234;
-               modes[i].mmWidth = 1234;
-               modes[i].mode_count = 0;
-               modes[i].prop_count = 0;
-               modes[i].subpixel = 0;
-               snprintf(modes[i].name, TDM_NAME_LEN, "TestModeSetting");
-       }
+       int count = this->MODE_COUNT;
+
+       _tc_tdm_client_virutual_make_available_mode(modes, count);
 
        ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
        ASSERT_EQ(ret, TDM_ERROR_NONE);
@@ -1515,16 +1563,13 @@ TEST_F(TDMVirtualOutput, FailTestSetAvailableModes)
 
        ret = tdm_client_voutput_set_available_modes(this->voutput, NULL, count);
        ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
-
-       ret = tdm_client_voutput_set_available_modes(this->voutput, modes, 0);
-       ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
 }
 
 TEST_F(TDMVirtualOutput, SetPhysicalSize)
 {
        tdm_error ret;
-       int mmWidth = 1234, mmHeight = 1234;
-       
+       unsigned int mmWidth = 1234, mmHeight = 1234;
+
        ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
        ASSERT_EQ(ret, TDM_ERROR_NONE);
 }
@@ -1532,12 +1577,44 @@ TEST_F(TDMVirtualOutput, SetPhysicalSize)
 TEST_F(TDMVirtualOutput, FailTestSetPhysicalSize)
 {
        tdm_error ret;
-       int invalid_mmWidth = -1, invalid_mmHeight = -1;
-       
+       unsigned int invalid_mmWidth = 0, invalid_mmHeight = 0;
+
        ret = tdm_client_voutput_set_physical_size(this->voutput, invalid_mmWidth, invalid_mmHeight);
        ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
 }
 
+static void
+_tc_tdm_client_voutput_commit_handler(tdm_client_voutput *voutput, tbm_surface_h buffer, void *user_data)
+{
+       int *flag;
+       flag = (int *)user_data;
+       *flag = 1;
+}
+
+TEST_F(TDMVirtualOutput, AddCommitHandler)
+{
+       tdm_error ret;
+       int flag_callback_called = 0;
+
+       ret = tdm_client_voutput_add_commit_handler(this->voutput,
+                                                                                               _tc_tdm_client_voutput_commit_handler,
+                                                                                               &flag_callback_called);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+//     ASSERT_EQ(flag_callback_called, 1);
+
+       tdm_client_voutput_remove_commit_handler(this->voutput,
+                                                                                        _tc_tdm_client_voutput_commit_handler,
+                                                                                        &flag_callback_called);
+}
+
+TEST_F(TDMVirtualOutput, CommitDone)
+{
+       tdm_error ret;
+
+       ret = tdm_client_voutput_commit_done(this->voutput);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+}
+
 TEST_F(TDMVirtualOutput, GetClientOutput)
 {
        tdm_error ret;
@@ -1548,6 +1625,48 @@ TEST_F(TDMVirtualOutput, GetClientOutput)
        ASSERT_NE(output, NULL);
 }
 
+TEST_F(TDMVirtualOutput, Connect)
+{
+       tdm_error ret;
+       tdm_client_output *output;
+       unsigned int mmWidth = 300, mmHeight = 150;
+       tdm_client_output_mode modes[this->MODE_COUNT];
+       int count = this->MODE_COUNT;
+
+       output = tdm_client_voutput_get_client_output(this->voutput, &ret);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+       ASSERT_NE(output, NULL);
+
+       ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+
+       _tc_tdm_client_virutual_make_available_mode(modes, count);
+       ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+
+       ret = tdm_client_output_connect(output);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+
+       tdm_client_handle_events_timeout(this->client, 0);
+}
+
+TEST_F(TDMVirtualOutput, Disconnect)
+{
+       tdm_error ret;
+       tdm_client_output *output;
+
+//     TDM_UT_WAIT("check & press");
+
+       output = tdm_client_voutput_get_client_output(this->voutput, &ret);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+       ASSERT_NE(output, NULL);
+
+       ret = tdm_client_output_disconnect(output);
+       ASSERT_EQ(ret, TDM_ERROR_NONE);
+
+       tdm_client_handle_events_timeout(this->client, 0);
+}
+
 #if 0
 TEST_F(TDMVirtualOutput, FailTestGetClientOutput)
 {