+TEST_P(TDMClient, ClientCreateVOutput)
+{
+ tdm_error ret;
+ const char name[TDM_NAME_LEN] = "Virtual Output";
+
+ ASSERT_EQ(PrepareClient(), true);
+
+ voutput = tdm_client_create_voutput(client, name, &ret);
+ ASSERT_EQ(ret, TDM_ERROR_NONE);
+ ASSERT_NE(voutput, NULL);
+
+ tdm_client_voutput_destroy(voutput);
+}
+
+class TDMVirtualOutput : public ::testing::Test
+{
+public:
+ TDMVirtualOutput() {};
+ ~TDMVirtualOutput() {};
+
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ static bool PrepareVOutput(void);
+
+protected:
+ static tdm_client *client;
+ static tdm_client_voutput *voutput;
+ const int MODE_COUNT = 1;
+
+private:
+ static pid_t server_pid;
+
+ /* 0: read, 1: write */
+ static int pipe_parent[2];
+ static int pipe_child[2];
+
+ static void ServerFork(void);
+ static void ServerKill(void);
+};
+
+pid_t TDMVirtualOutput::server_pid = -1;
+int TDMVirtualOutput::pipe_parent[2] = {-1, -1};
+int TDMVirtualOutput::pipe_child[2] = {-1, -1};
+tdm_client* TDMVirtualOutput::client = nullptr;
+tdm_client_voutput* TDMVirtualOutput::voutput = nullptr;
+
+void TDMVirtualOutput::ServerKill(void)
+{
+ if (pipe_child[0] >= 0)
+ close(pipe_child[0]);
+ if (pipe_child[1] >= 0) {
+ if (server_pid > 0) {
+ bool ret = _tc_tdm_pipe_write_msg(pipe_child[1], pipe_parent[0], TDM_UT_PIPE_MSG_TERMINATE_SERVER);
+ if (ret) {
+ if (waitpid(server_pid, NULL, 0) == server_pid)
+ TDM_INFO("*** server terminated ***");
+ else
+ TDM_ERR("*** failed to terminate server ***");
+ } else {
+ if (kill(server_pid, 9) < 0)
+ TDM_ERR("*** failed to kill server ***");
+ }
+ }
+ close(pipe_child[1]);
+ }
+
+ if (pipe_parent[0] >= 0)
+ close(pipe_parent[0]);
+ if (pipe_parent[1] >= 0)
+ close(pipe_parent[1]);
+
+ server_pid = -1;
+ pipe_parent[0] = pipe_parent[1] = -1;
+ pipe_child[0] = pipe_child[1] = -1;
+}
+
+void TDMVirtualOutput::ServerFork(void)
+{
+ if (server_pid > 0)
+ return;
+
+ server_pid = _tc_tdm_client_server_fork(pipe_parent, pipe_child);
+ ASSERT_GT(server_pid, 0);
+}
+
+void TDMVirtualOutput::SetUpTestCase(void)
+{
+ setenv("XDG_RUNTIME_DIR", "/run", 1);
+ setenv("TBM_DISPLAY_SERVER", "1", 1);
+
+ if (server_pid == -1)
+ ServerFork();
+
+ ASSERT_EQ(PrepareVOutput(), true);
+}
+
+void TDMVirtualOutput::TearDownTestCase(void)
+{
+ if (voutput)
+ tdm_client_voutput_destroy(voutput);
+
+ if (client)
+ tdm_client_destroy(client);
+
+ ServerKill();
+
+ unsetenv("XDG_RUNTIME_DIR");
+ unsetenv("TBM_DISPLAY_SERVER");
+}
+
+bool TDMVirtualOutput::PrepareVOutput(void)
+{
+ tdm_error ret;
+ const char name[TDM_NAME_LEN] = "Virtual Output";
+
+ client = tdm_client_create(&ret);
+ 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);
+ return true;
+}
+
+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");
+ }
+
+ ret = tdm_client_voutput_set_available_modes(this->voutput, modes, count);
+ ASSERT_EQ(ret, TDM_ERROR_NONE);
+}
+
+TEST_F(TDMVirtualOutput, FailTestSetAvailableModes)
+{
+ tdm_error ret;
+ tdm_client_output_mode modes[this->MODE_COUNT];
+ int count = this->MODE_COUNT;
+
+ ret = tdm_client_voutput_set_available_modes(NULL, modes, count);
+ ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
+
+ 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;
+
+ ret = tdm_client_voutput_set_physical_size(this->voutput, mmWidth, mmHeight);
+ ASSERT_EQ(ret, TDM_ERROR_NONE);
+}
+
+TEST_F(TDMVirtualOutput, FailTestSetPhysicalSize)
+{
+ tdm_error ret;
+ int invalid_mmWidth = -1, invalid_mmHeight = -1;
+
+ ret = tdm_client_voutput_set_physical_size(this->voutput, invalid_mmWidth, invalid_mmHeight);
+ ASSERT_EQ(ret, TDM_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(TDMVirtualOutput, GetClientOutput)
+{
+ tdm_error ret;
+ tdm_client_output *output;
+
+ output = tdm_client_voutput_get_client_output(this->voutput, &ret);
+ ASSERT_EQ(ret, TDM_ERROR_NONE);
+ ASSERT_NE(output, NULL);
+}
+
+#if 0
+TEST_F(TDMVirtualOutput, FailTestGetClientOutput)
+{
+ tdm_error ret;
+}
+
+TEST_F(TDMVirtualOutput, SetBufferQueue)
+{
+ tdm_error ret;
+}
+
+TEST_F(TDMVirtualOutput, FailTestSetBufferQueue)
+{
+ tdm_error ret;
+}
+
+#endif
+