+/**************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics co., Ltd. All Rights Reserved.
+ *
+ * Contact: Konstantin Drabeniuk <k.drabeniuk@samsung.com>
+ * Contact: Andrii Sokolenko <a.sokolenko@samsung.com>
+ * Contact: Roman Marchenko <r.marchenko@samsung.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+**************************************************************************/
+
+#include "ut_tdm.h"
+
+void TDMEnv::SetUp(void)
+{
+ const char *test_backend;
+
+ TDM_UT_ENTRY();
+
+ setenv("XDG_RUNTIME_DIR", "/run", 1);
+ setenv("TBM_DISPLAY_SERVER", "1", 1);
+
+ tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_THREAD, ::testing::get<0>(GetParam()));
+ tdm_config_set_int(TDM_CONFIG_KEY_GENERAL_COMMIT_PER_VBLANK, ::testing::get<1>(GetParam()));
+
+ const char *debug = getenv("TDM_DEBUG_MODULE");
+ if (debug && strstr(debug, "1"))
+ tdm_config_set_string(TDM_CONFIG_KEY_DEBUG_MODULE, "buffer,thread,event,vblank,commit,pp,capture");
+
+ test_backend = ::testing::get<2>(GetParam());
+ if (!test_backend)
+ test_backend = TDM_DEFAULT_MODULE;
+ tdm_config_set_string(TDM_CONFIG_KEY_GENERAL_BACKENDS, test_backend);
+}
+
+void TDMEnv::TearDown(void)
+{
+ unsetenv("XDG_RUNTIME_DIR");
+ unsetenv("TBM_DISPLAY_SERVER");
+}
+
+#ifdef UT_TDM_ENV_ENABLE
+
+TEST_P(TDMEnv, DisplayInitDeinit)
+{
+ tdm_display *dpy;
+ tdm_error ret;
+
+ dpy = tdm_display_init(&ret);
+ ASSERT_TRUE(ret == TDM_ERROR_NONE);
+ ASSERT_TRUE(dpy != NULL);
+
+ tdm_display_deinit(dpy);
+}
+
+TEST_P(TDMEnv, DisplayInitDeinitWithoutEnv)
+{
+ tdm_display *dpy;
+ tdm_error ret;
+
+ TDMEnv::TearDown();
+
+ dpy = tdm_display_init(&ret);
+ ASSERT_TRUE(ret == TDM_ERROR_OPERATION_FAILED);
+ ASSERT_TRUE(dpy == NULL);
+}
+
+TEST_P(TDMEnv, DisplayInitFewTimes)
+{
+ tdm_display *dpy[10];
+ int d;
+ tdm_error ret;
+
+ for (d = 0; d < 10; d++) {
+ dpy[d] = tdm_display_init(&ret);
+ ASSERT_TRUE(ret == TDM_ERROR_NONE);
+ ASSERT_TRUE(dpy[d] != NULL);
+ }
+
+ for (d = 0; d < 9; d++)
+ ASSERT_TRUE(dpy[d] == dpy[d + 1]);
+
+ for (d = 0; d < 10; d++)
+ tdm_display_deinit(dpy[d]);
+}
+
+TEST_P(TDMEnv, DisplayInitDeinitWithTBM)
+{
+ tdm_display *dpy;
+ tbm_bufmgr bufmgr;
+ tdm_error ret;
+
+ bufmgr = tbm_bufmgr_init(-1);
+ ASSERT_TRUE(bufmgr != NULL);
+
+ dpy = tdm_display_init(&ret);
+ ASSERT_TRUE(ret == TDM_ERROR_NONE);
+ ASSERT_TRUE(dpy != NULL);
+
+ tdm_display_deinit(dpy);
+ tbm_bufmgr_deinit(bufmgr);
+}
+
+TEST_P(TDMEnv, DisplayInitDeinitWithoutBackends)
+{
+ ASSERT_TRUE(1);
+}
+
+TEST_P(TDMEnv, DisplayInitDeinitWrongDpyBadAddress)
+{
+ tdm_display *dpy;
+ tdm_error ret;
+
+ dpy = tdm_display_init(&ret);
+ ASSERT_TRUE(ret == TDM_ERROR_NONE);
+ ASSERT_TRUE(dpy != NULL);
+
+ EXPECT_EXIT({
+ tdm_display *wrong_dpy = (tdm_display *)TDM_UT_INVALID_VALUE;
+ tdm_display_deinit(wrong_dpy);
+ exit(0);
+ }, ::testing::ExitedWithCode(0), "");
+
+ tdm_display_deinit(dpy);
+}
+
+TEST_P(TDMEnv, DisplayDeinitWithNULL)
+{
+ tdm_display_deinit(NULL);
+}
+
+TEST_P(TDMEnv, DisplayDeinitRepeatWithSameDpy)
+{
+ tdm_display *dpy;
+ tdm_error ret;
+
+ dpy = tdm_display_init(&ret);
+ ASSERT_TRUE(ret == TDM_ERROR_NONE);
+ ASSERT_TRUE(dpy != NULL);
+
+ EXPECT_EXIT({
+ tdm_display_deinit(dpy);
+ tdm_display_deinit(dpy);
+ exit(0);
+ }, ::testing::ExitedWithCode(0), "");
+
+ tdm_display_deinit(dpy);
+}
+
+INSTANTIATE_TEST_CASE_P(TDMEnvParams,
+ TDMEnv,
+ Combine(Bool(), Bool(), Values(TDM_DEFAULT_MODULE)));
+
+#endif